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_common.h>
12 : : #include <rte_ether.h>
13 : : #include <ethdev_driver.h>
14 : : #include <rte_flow.h>
15 : : #include <rte_flow_driver.h>
16 : : #include <rte_malloc.h>
17 : : #include <rte_cycles.h>
18 : : #include <bus_pci_driver.h>
19 : : #include <rte_ip.h>
20 : : #include <rte_gre.h>
21 : : #include <rte_vxlan.h>
22 : : #include <rte_gtp.h>
23 : : #include <rte_eal_paging.h>
24 : : #include <rte_mpls.h>
25 : : #include <rte_mtr.h>
26 : : #include <rte_mtr_driver.h>
27 : : #include <rte_tailq.h>
28 : :
29 : : #include <mlx5_glue.h>
30 : : #include <mlx5_devx_cmds.h>
31 : : #include <mlx5_prm.h>
32 : : #include <mlx5_malloc.h>
33 : :
34 : : #include "mlx5_defs.h"
35 : : #include "mlx5.h"
36 : : #include "mlx5_common_os.h"
37 : : #include "mlx5_flow.h"
38 : : #include "mlx5_flow_os.h"
39 : : #include "mlx5_rx.h"
40 : : #include "mlx5_tx.h"
41 : : #include "rte_pmd_mlx5.h"
42 : :
43 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
44 : :
45 : : #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
46 : : #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
47 : : #endif
48 : :
49 : : #ifndef HAVE_MLX5DV_DR_ESWITCH
50 : : #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
51 : : #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
52 : : #endif
53 : : #endif
54 : :
55 : : #ifndef HAVE_MLX5DV_DR
56 : : #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
57 : : #endif
58 : :
59 : : /* VLAN header definitions */
60 : : #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
61 : : #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
62 : : #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
63 : : #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
64 : : #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
65 : :
66 : : #define MLX5_ITEM_VALID(item, key_type) \
67 : : (((MLX5_SET_MATCHER_SW & (key_type)) && !((item)->spec)) || \
68 : : ((MLX5_SET_MATCHER_HS_V == (key_type)) && !((item)->spec)) || \
69 : : ((MLX5_SET_MATCHER_HS_M == (key_type)) && !((item)->mask)))
70 : :
71 : : #define MLX5_ITEM_UPDATE(item, key_type, v, m, gm) \
72 : : do { \
73 : : if ((key_type) == MLX5_SET_MATCHER_SW_V) { \
74 : : v = (item)->spec; \
75 : : m = (item)->mask ? (item)->mask : (gm); \
76 : : } else if ((key_type) == MLX5_SET_MATCHER_HS_V) { \
77 : : v = (item)->spec; \
78 : : m = (v); \
79 : : } else { \
80 : : v = (item)->mask ? (item)->mask : (gm); \
81 : : m = (v); \
82 : : } \
83 : : } while (0)
84 : :
85 : : union flow_dv_attr {
86 : : struct {
87 : : uint32_t valid:1;
88 : : uint32_t ipv4:1;
89 : : uint32_t ipv6:1;
90 : : uint32_t tcp:1;
91 : : uint32_t udp:1;
92 : : uint32_t reserved:27;
93 : : };
94 : : uint32_t attr;
95 : : };
96 : :
97 : : static int
98 : : flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
99 : : uint32_t encap_decap_idx);
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 : : static void
276 : : mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
277 : : uint8_t next_protocol, uint64_t *item_flags,
278 : : int *tunnel)
279 : : {
280 : : MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
281 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
282 : 0 : if (next_protocol == IPPROTO_IPIP) {
283 : 0 : *item_flags |= MLX5_FLOW_LAYER_IPIP;
284 : : *tunnel = 1;
285 : : }
286 [ # # # # : 0 : if (next_protocol == IPPROTO_IPV6) {
# # # # ]
287 : 0 : *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
288 : : *tunnel = 1;
289 : : }
290 : : }
291 : :
292 : : static inline struct mlx5_hlist *
293 : 0 : flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, struct mlx5_hlist **phl,
294 : : const char *name, uint32_t size, bool direct_key,
295 : : bool lcores_share, void *ctx,
296 : : mlx5_list_create_cb cb_create,
297 : : mlx5_list_match_cb cb_match,
298 : : mlx5_list_remove_cb cb_remove,
299 : : mlx5_list_clone_cb cb_clone,
300 : : mlx5_list_clone_free_cb cb_clone_free,
301 : : struct rte_flow_error *error)
302 : : {
303 : : struct mlx5_hlist *hl;
304 : : struct mlx5_hlist *expected = NULL;
305 : : char s[MLX5_NAME_SIZE];
306 : :
307 : 0 : hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
308 [ # # ]: 0 : if (likely(hl))
309 : : return hl;
310 : 0 : snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
311 : 0 : hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
312 : : ctx, cb_create, cb_match, cb_remove, cb_clone,
313 : : cb_clone_free);
314 [ # # ]: 0 : if (!hl) {
315 : 0 : DRV_LOG(ERR, "%s hash creation failed", name);
316 : 0 : rte_flow_error_set(error, ENOMEM,
317 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
318 : : "cannot allocate resource memory");
319 : 0 : return NULL;
320 : : }
321 [ # # ]: 0 : if (!__atomic_compare_exchange_n(phl, &expected, hl, false,
322 : : __ATOMIC_SEQ_CST,
323 : : __ATOMIC_SEQ_CST)) {
324 : 0 : mlx5_hlist_destroy(hl);
325 : 0 : hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
326 : : }
327 : : return hl;
328 : : }
329 : :
330 : : /* Update VLAN's VID/PCP based on input rte_flow_action.
331 : : *
332 : : * @param[in] action
333 : : * Pointer to struct rte_flow_action.
334 : : * @param[out] vlan
335 : : * Pointer to struct rte_vlan_hdr.
336 : : */
337 : : static void
338 : 0 : mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
339 : : struct rte_vlan_hdr *vlan)
340 : : {
341 : : uint16_t vlan_tci;
342 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
343 : 0 : vlan_tci =
344 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
345 : 0 : action->conf)->vlan_pcp;
346 : 0 : vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
347 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
348 : 0 : vlan->vlan_tci |= vlan_tci;
349 [ # # ]: 0 : } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
350 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
351 [ # # ]: 0 : vlan->vlan_tci |= rte_be_to_cpu_16
352 : : (((const struct rte_flow_action_of_set_vlan_vid *)
353 : : action->conf)->vlan_vid);
354 : : }
355 : 0 : }
356 : :
357 : : /**
358 : : * Convert modify-header action to DV specification.
359 : : *
360 : : * Data length of each action is determined by provided field description
361 : : * and the item mask. Data bit offset and width of each action is determined
362 : : * by provided item mask.
363 : : *
364 : : * @param[in] item
365 : : * Pointer to item specification.
366 : : * @param[in] field
367 : : * Pointer to field modification information.
368 : : * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
369 : : * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
370 : : * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
371 : : * For MLX5_MODIFICATION_TYPE_ADD_FIELD specifies source field.
372 : : * @param[in] dest
373 : : * Destination field info for MLX5_MODIFICATION_TYPE_COPY and
374 : : * MLX5_MODIFICATION_TYPE_ADD_FIELD in @type.
375 : : * Negative offset value sets the same offset as source offset.
376 : : * size field is ignored, value is taken from source field.
377 : : * @param[in,out] resource
378 : : * Pointer to the modify-header resource.
379 : : * @param[in] type
380 : : * Type of modification.
381 : : * @param[out] error
382 : : * Pointer to the error structure.
383 : : *
384 : : * @return
385 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
386 : : */
387 : : int
388 : 0 : flow_dv_convert_modify_action(struct rte_flow_item *item,
389 : : struct field_modify_info *field,
390 : : struct field_modify_info *dest,
391 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
392 : : uint32_t type, struct rte_flow_error *error)
393 : : {
394 : 0 : uint32_t i = resource->actions_num;
395 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
396 : : uint32_t carry_b = 0;
397 : : bool to_dest;
398 : :
399 : : /*
400 : : * The item and mask are provided in big-endian format.
401 : : * The fields should be presented as in big-endian format either.
402 : : * Mask must be always present, it defines the actual field width.
403 : : */
404 : : MLX5_ASSERT(item->mask);
405 : : MLX5_ASSERT(field->size);
406 : 0 : to_dest = type == MLX5_MODIFICATION_TYPE_COPY ||
407 : 0 : type == MLX5_MODIFICATION_TYPE_ADD_FIELD;
408 : : do {
409 : : uint32_t size_b;
410 : : uint32_t off_b;
411 : : uint32_t mask;
412 : : uint32_t data;
413 : : bool next_field = true;
414 : : bool next_dest = true;
415 : :
416 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
417 : 0 : return rte_flow_error_set(error, EINVAL,
418 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
419 : : "too many items to modify");
420 : : /* Fetch variable byte size mask from the array. */
421 : 0 : mask = flow_dv_fetch_field((const uint8_t *)item->mask +
422 : 0 : field->offset, field->size);
423 [ # # ]: 0 : if (!mask) {
424 : 0 : ++field;
425 : : continue;
426 : : }
427 [ # # # # ]: 0 : if (to_dest && field->is_flex) {
428 : 0 : off_b = 32 - field->shift + carry_b - field->size * CHAR_BIT;
429 : 0 : size_b = field->size * CHAR_BIT - carry_b;
430 : : } else {
431 : : /* Deduce actual data width in bits from mask value. */
432 : 0 : off_b = rte_bsf32(mask) + carry_b;
433 : 0 : size_b = sizeof(uint32_t) * CHAR_BIT -
434 : 0 : off_b - rte_clz32(mask);
435 : : }
436 : : MLX5_ASSERT(size_b);
437 : 0 : actions[i] = (struct mlx5_modification_cmd) {
438 : : .action_type = type,
439 : 0 : .field = field->id,
440 : : .offset = off_b,
441 : : .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
442 [ # # ]: 0 : 0 : size_b,
443 : : };
444 [ # # ]: 0 : if (to_dest) {
445 : : MLX5_ASSERT(dest);
446 : 0 : actions[i].dst_field = dest->id;
447 : 0 : actions[i].dst_offset =
448 [ # # ]: 0 : (int)dest->offset < 0 ? off_b : dest->offset;
449 : : /* Convert entire record to big-endian format. */
450 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
451 : : /*
452 : : * Destination field overflow. Copy leftovers of
453 : : * a source field to the next destination field.
454 : : */
455 [ # # # # ]: 0 : if ((size_b > dest->size * CHAR_BIT - dest->offset) &&
456 : : dest->size != 0) {
457 : 0 : actions[i].length =
458 : 0 : dest->size * CHAR_BIT - dest->offset;
459 : 0 : carry_b += actions[i].length;
460 : 0 : next_field = false;
461 : : } else {
462 : : carry_b = 0;
463 : : }
464 : : /*
465 : : * Not enough bits in a source filed to fill a
466 : : * destination field. Switch to the next source.
467 : : */
468 [ # # ]: 0 : if ((size_b < dest->size * CHAR_BIT - dest->offset) &&
469 [ # # ]: 0 : ((size_b == field->size * CHAR_BIT - off_b) ||
470 [ # # ]: 0 : field->is_flex)) {
471 : 0 : actions[i].length = size_b;
472 : 0 : dest->offset += actions[i].length;
473 : : next_dest = false;
474 : : }
475 : : } else {
476 : : MLX5_ASSERT(item->spec);
477 : 0 : data = flow_dv_fetch_field((const uint8_t *)item->spec +
478 : : field->offset, field->size);
479 : : /* Shift out the trailing masked bits from data. */
480 : 0 : data = (data & mask) >> off_b;
481 [ # # ]: 0 : if (field->is_flex)
482 : 0 : actions[i].offset = 32 - field->shift - field->size * CHAR_BIT;
483 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(data);
484 : : }
485 : : /* Convert entire record to expected big-endian format. */
486 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
487 [ # # ]: 0 : if ((!to_dest ||
488 [ # # # # ]: 0 : dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
489 : : field->id != (enum mlx5_modification_field)UINT32_MAX)
490 : 0 : ++i;
491 [ # # ]: 0 : if (next_dest && to_dest)
492 : 0 : ++dest;
493 [ # # ]: 0 : if (next_field)
494 : 0 : ++field;
495 [ # # ]: 0 : } while (field->size);
496 [ # # ]: 0 : if (resource->actions_num == i)
497 : 0 : return rte_flow_error_set(error, EINVAL,
498 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
499 : : "invalid modification flow item");
500 : 0 : resource->actions_num = i;
501 : 0 : return 0;
502 : : }
503 : :
504 : : /**
505 : : * Convert modify-header set IPv4 address action to DV specification.
506 : : *
507 : : * @param[in,out] resource
508 : : * Pointer to the modify-header resource.
509 : : * @param[in] action
510 : : * Pointer to action specification.
511 : : * @param[out] error
512 : : * Pointer to the error structure.
513 : : *
514 : : * @return
515 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
516 : : */
517 : : static int
518 : 0 : flow_dv_convert_action_modify_ipv4
519 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
520 : : const struct rte_flow_action *action,
521 : : struct rte_flow_error *error)
522 : : {
523 : 0 : const struct rte_flow_action_set_ipv4 *conf =
524 : : (const struct rte_flow_action_set_ipv4 *)(action->conf);
525 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
526 : : struct rte_flow_item_ipv4 ipv4;
527 : : struct rte_flow_item_ipv4 ipv4_mask;
528 : :
529 : : memset(&ipv4, 0, sizeof(ipv4));
530 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
531 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
532 : 0 : ipv4.hdr.src_addr = conf->ipv4_addr;
533 : 0 : ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
534 : : } else {
535 : 0 : ipv4.hdr.dst_addr = conf->ipv4_addr;
536 : 0 : ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
537 : : }
538 : 0 : item.spec = &ipv4;
539 : 0 : item.mask = &ipv4_mask;
540 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
541 : : MLX5_MODIFICATION_TYPE_SET, error);
542 : : }
543 : :
544 : : /**
545 : : * Convert modify-header set IPv6 address action to DV specification.
546 : : *
547 : : * @param[in,out] resource
548 : : * Pointer to the modify-header resource.
549 : : * @param[in] action
550 : : * Pointer to action specification.
551 : : * @param[out] error
552 : : * Pointer to the error structure.
553 : : *
554 : : * @return
555 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
556 : : */
557 : : static int
558 : 0 : flow_dv_convert_action_modify_ipv6
559 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
560 : : const struct rte_flow_action *action,
561 : : struct rte_flow_error *error)
562 : : {
563 : 0 : const struct rte_flow_action_set_ipv6 *conf =
564 : : (const struct rte_flow_action_set_ipv6 *)(action->conf);
565 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
566 : : struct rte_flow_item_ipv6 ipv6;
567 : : struct rte_flow_item_ipv6 ipv6_mask;
568 : :
569 : : memset(&ipv6, 0, sizeof(ipv6));
570 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
571 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
572 : : memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
573 : : sizeof(ipv6.hdr.src_addr));
574 : : memcpy(&ipv6_mask.hdr.src_addr,
575 : : &rte_flow_item_ipv6_mask.hdr.src_addr,
576 : : sizeof(ipv6.hdr.src_addr));
577 : : } else {
578 : : memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
579 : : sizeof(ipv6.hdr.dst_addr));
580 : : memcpy(&ipv6_mask.hdr.dst_addr,
581 : : &rte_flow_item_ipv6_mask.hdr.dst_addr,
582 : : sizeof(ipv6.hdr.dst_addr));
583 : : }
584 : 0 : item.spec = &ipv6;
585 : 0 : item.mask = &ipv6_mask;
586 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
587 : : MLX5_MODIFICATION_TYPE_SET, error);
588 : : }
589 : :
590 : : /**
591 : : * Convert modify-header set MAC address action to DV specification.
592 : : *
593 : : * @param[in,out] resource
594 : : * Pointer to the modify-header resource.
595 : : * @param[in] action
596 : : * Pointer to action specification.
597 : : * @param[out] error
598 : : * Pointer to the error structure.
599 : : *
600 : : * @return
601 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
602 : : */
603 : : static int
604 : 0 : flow_dv_convert_action_modify_mac
605 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
606 : : const struct rte_flow_action *action,
607 : : struct rte_flow_error *error)
608 : : {
609 : 0 : const struct rte_flow_action_set_mac *conf =
610 : : (const struct rte_flow_action_set_mac *)(action->conf);
611 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
612 : : struct rte_flow_item_eth eth;
613 : : struct rte_flow_item_eth eth_mask;
614 : :
615 : : memset(ð, 0, sizeof(eth));
616 : : memset(ð_mask, 0, sizeof(eth_mask));
617 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
618 : : memcpy(ð.hdr.src_addr.addr_bytes, &conf->mac_addr,
619 : : sizeof(eth.hdr.src_addr.addr_bytes));
620 : : memcpy(ð_mask.hdr.src_addr.addr_bytes,
621 : : &rte_flow_item_eth_mask.hdr.src_addr.addr_bytes,
622 : : sizeof(eth_mask.hdr.src_addr.addr_bytes));
623 : : } else {
624 : : memcpy(ð.hdr.dst_addr.addr_bytes, &conf->mac_addr,
625 : : sizeof(eth.hdr.dst_addr.addr_bytes));
626 : : memcpy(ð_mask.hdr.dst_addr.addr_bytes,
627 : : &rte_flow_item_eth_mask.hdr.dst_addr.addr_bytes,
628 : : sizeof(eth_mask.hdr.dst_addr.addr_bytes));
629 : : }
630 : 0 : item.spec = ð
631 : 0 : item.mask = ð_mask;
632 : 0 : return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
633 : : MLX5_MODIFICATION_TYPE_SET, error);
634 : : }
635 : :
636 : : /**
637 : : * Convert modify-header set VLAN VID action to DV specification.
638 : : *
639 : : * @param[in,out] resource
640 : : * Pointer to the modify-header resource.
641 : : * @param[in] action
642 : : * Pointer to action specification.
643 : : * @param[out] error
644 : : * Pointer to the error structure.
645 : : *
646 : : * @return
647 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
648 : : */
649 : : static int
650 : 0 : flow_dv_convert_action_modify_vlan_vid
651 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
652 : : const struct rte_flow_action *action,
653 : : struct rte_flow_error *error)
654 : : {
655 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
656 : : (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
657 : 0 : int i = resource->actions_num;
658 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
659 : : struct field_modify_info *field = modify_vlan_out_first_vid;
660 : :
661 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
662 : 0 : return rte_flow_error_set(error, EINVAL,
663 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
664 : : "too many items to modify");
665 : 0 : actions[i] = (struct mlx5_modification_cmd) {
666 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
667 : 0 : .field = field->id,
668 : 0 : .length = field->size,
669 : 0 : .offset = field->offset,
670 : : };
671 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
672 : 0 : actions[i].data1 = conf->vlan_vid;
673 : 0 : actions[i].data1 = actions[i].data1 << 16;
674 : 0 : resource->actions_num = ++i;
675 : 0 : return 0;
676 : : }
677 : :
678 : : /**
679 : : * Convert modify-header set TP action to DV specification.
680 : : *
681 : : * @param[in,out] resource
682 : : * Pointer to the modify-header resource.
683 : : * @param[in] action
684 : : * Pointer to action specification.
685 : : * @param[in] items
686 : : * Pointer to rte_flow_item objects list.
687 : : * @param[in] attr
688 : : * Pointer to flow attributes structure.
689 : : * @param[in] dev_flow
690 : : * Pointer to the sub flow.
691 : : * @param[in] tunnel_decap
692 : : * Whether action is after tunnel decapsulation.
693 : : * @param[out] error
694 : : * Pointer to the error structure.
695 : : *
696 : : * @return
697 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
698 : : */
699 : : static int
700 : 0 : flow_dv_convert_action_modify_tp
701 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
702 : : const struct rte_flow_action *action,
703 : : const struct rte_flow_item *items,
704 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
705 : : bool tunnel_decap, struct rte_flow_error *error)
706 : : {
707 : 0 : const struct rte_flow_action_set_tp *conf =
708 : : (const struct rte_flow_action_set_tp *)(action->conf);
709 : : struct rte_flow_item item;
710 : : struct rte_flow_item_udp udp;
711 : : struct rte_flow_item_udp udp_mask;
712 : : struct rte_flow_item_tcp tcp;
713 : : struct rte_flow_item_tcp tcp_mask;
714 : : struct field_modify_info *field;
715 : :
716 [ # # ]: 0 : if (!attr->valid)
717 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
718 [ # # ]: 0 : if (attr->udp) {
719 : : memset(&udp, 0, sizeof(udp));
720 : : memset(&udp_mask, 0, sizeof(udp_mask));
721 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
722 : 0 : udp.hdr.src_port = conf->port;
723 : 0 : udp_mask.hdr.src_port =
724 : : rte_flow_item_udp_mask.hdr.src_port;
725 : : } else {
726 : 0 : udp.hdr.dst_port = conf->port;
727 : 0 : udp_mask.hdr.dst_port =
728 : : rte_flow_item_udp_mask.hdr.dst_port;
729 : : }
730 : 0 : item.type = RTE_FLOW_ITEM_TYPE_UDP;
731 : 0 : item.spec = &udp;
732 : 0 : item.mask = &udp_mask;
733 : : field = modify_udp;
734 : : } else {
735 : : MLX5_ASSERT(attr->tcp);
736 : : memset(&tcp, 0, sizeof(tcp));
737 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
738 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
739 : 0 : tcp.hdr.src_port = conf->port;
740 : 0 : tcp_mask.hdr.src_port =
741 : : rte_flow_item_tcp_mask.hdr.src_port;
742 : : } else {
743 : 0 : tcp.hdr.dst_port = conf->port;
744 : 0 : tcp_mask.hdr.dst_port =
745 : : rte_flow_item_tcp_mask.hdr.dst_port;
746 : : }
747 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
748 : 0 : item.spec = &tcp;
749 : 0 : item.mask = &tcp_mask;
750 : : field = modify_tcp;
751 : : }
752 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
753 : : MLX5_MODIFICATION_TYPE_SET, error);
754 : : }
755 : :
756 : : /**
757 : : * Convert modify-header set TTL action to DV specification.
758 : : *
759 : : * @param[in,out] resource
760 : : * Pointer to the modify-header resource.
761 : : * @param[in] action
762 : : * Pointer to action specification.
763 : : * @param[in] items
764 : : * Pointer to rte_flow_item objects list.
765 : : * @param[in] attr
766 : : * Pointer to flow attributes structure.
767 : : * @param[in] dev_flow
768 : : * Pointer to the sub flow.
769 : : * @param[in] tunnel_decap
770 : : * Whether action is after tunnel decapsulation.
771 : : * @param[out] error
772 : : * Pointer to the error structure.
773 : : *
774 : : * @return
775 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
776 : : */
777 : : static int
778 : 0 : flow_dv_convert_action_modify_ttl
779 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
780 : : const struct rte_flow_action *action,
781 : : const struct rte_flow_item *items,
782 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
783 : : bool tunnel_decap, struct rte_flow_error *error)
784 : : {
785 : 0 : const struct rte_flow_action_set_ttl *conf =
786 : : (const struct rte_flow_action_set_ttl *)(action->conf);
787 : : struct rte_flow_item item;
788 : : struct rte_flow_item_ipv4 ipv4;
789 : : struct rte_flow_item_ipv4 ipv4_mask;
790 : : struct rte_flow_item_ipv6 ipv6;
791 : : struct rte_flow_item_ipv6 ipv6_mask;
792 : : struct field_modify_info *field;
793 : :
794 [ # # ]: 0 : if (!attr->valid)
795 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
796 [ # # ]: 0 : if (attr->ipv4) {
797 : : memset(&ipv4, 0, sizeof(ipv4));
798 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
799 : 0 : ipv4.hdr.time_to_live = conf->ttl_value;
800 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
801 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
802 : 0 : item.spec = &ipv4;
803 : 0 : item.mask = &ipv4_mask;
804 : : field = modify_ipv4;
805 : : } else {
806 : : MLX5_ASSERT(attr->ipv6);
807 : : memset(&ipv6, 0, sizeof(ipv6));
808 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
809 : 0 : ipv6.hdr.hop_limits = conf->ttl_value;
810 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
811 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
812 : 0 : item.spec = &ipv6;
813 : 0 : item.mask = &ipv6_mask;
814 : : field = modify_ipv6;
815 : : }
816 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
817 : : MLX5_MODIFICATION_TYPE_SET, error);
818 : : }
819 : :
820 : : /**
821 : : * Convert modify-header decrement TTL action to DV specification.
822 : : *
823 : : * @param[in,out] resource
824 : : * Pointer to the modify-header resource.
825 : : * @param[in] action
826 : : * Pointer to action specification.
827 : : * @param[in] items
828 : : * Pointer to rte_flow_item objects list.
829 : : * @param[in] attr
830 : : * Pointer to flow attributes structure.
831 : : * @param[in] dev_flow
832 : : * Pointer to the sub flow.
833 : : * @param[in] tunnel_decap
834 : : * Whether action is after tunnel decapsulation.
835 : : * @param[out] error
836 : : * Pointer to the error structure.
837 : : *
838 : : * @return
839 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
840 : : */
841 : : static int
842 : 0 : flow_dv_convert_action_modify_dec_ttl
843 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
844 : : const struct rte_flow_item *items,
845 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
846 : : bool tunnel_decap, struct rte_flow_error *error)
847 : : {
848 : : struct rte_flow_item item;
849 : : struct rte_flow_item_ipv4 ipv4;
850 : : struct rte_flow_item_ipv4 ipv4_mask;
851 : : struct rte_flow_item_ipv6 ipv6;
852 : : struct rte_flow_item_ipv6 ipv6_mask;
853 : : struct field_modify_info *field;
854 : :
855 [ # # ]: 0 : if (!attr->valid)
856 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
857 [ # # ]: 0 : if (attr->ipv4) {
858 : : memset(&ipv4, 0, sizeof(ipv4));
859 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
860 : 0 : ipv4.hdr.time_to_live = 0xFF;
861 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
862 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
863 : 0 : item.spec = &ipv4;
864 : 0 : item.mask = &ipv4_mask;
865 : : field = modify_ipv4;
866 : : } else {
867 : : MLX5_ASSERT(attr->ipv6);
868 : : memset(&ipv6, 0, sizeof(ipv6));
869 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
870 : 0 : ipv6.hdr.hop_limits = 0xFF;
871 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
872 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
873 : 0 : item.spec = &ipv6;
874 : 0 : item.mask = &ipv6_mask;
875 : : field = modify_ipv6;
876 : : }
877 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
878 : : MLX5_MODIFICATION_TYPE_ADD, error);
879 : : }
880 : :
881 : : /**
882 : : * Convert modify-header increment/decrement TCP Sequence number
883 : : * to DV specification.
884 : : *
885 : : * @param[in,out] resource
886 : : * Pointer to the modify-header resource.
887 : : * @param[in] action
888 : : * Pointer to action specification.
889 : : * @param[out] error
890 : : * Pointer to the error structure.
891 : : *
892 : : * @return
893 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
894 : : */
895 : : static int
896 : 0 : flow_dv_convert_action_modify_tcp_seq
897 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
898 : : const struct rte_flow_action *action,
899 : : struct rte_flow_error *error)
900 : : {
901 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
902 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
903 : : struct rte_flow_item item;
904 : : struct rte_flow_item_tcp tcp;
905 : : struct rte_flow_item_tcp tcp_mask;
906 : :
907 : : memset(&tcp, 0, sizeof(tcp));
908 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
909 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
910 : : /*
911 : : * The HW has no decrement operation, only increment operation.
912 : : * To simulate decrement X from Y using increment operation
913 : : * we need to add UINT32_MAX X times to Y.
914 : : * Each adding of UINT32_MAX decrements Y by 1.
915 : : */
916 : 0 : value *= UINT32_MAX;
917 [ # # ]: 0 : tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
918 : 0 : tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
919 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
920 : 0 : item.spec = &tcp;
921 : 0 : item.mask = &tcp_mask;
922 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
923 : : MLX5_MODIFICATION_TYPE_ADD, error);
924 : : }
925 : :
926 : : /**
927 : : * Convert modify-header increment/decrement TCP Acknowledgment number
928 : : * to DV specification.
929 : : *
930 : : * @param[in,out] resource
931 : : * Pointer to the modify-header resource.
932 : : * @param[in] action
933 : : * Pointer to action specification.
934 : : * @param[out] error
935 : : * Pointer to the error structure.
936 : : *
937 : : * @return
938 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
939 : : */
940 : : static int
941 : 0 : flow_dv_convert_action_modify_tcp_ack
942 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
943 : : const struct rte_flow_action *action,
944 : : struct rte_flow_error *error)
945 : : {
946 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
947 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
948 : : struct rte_flow_item item;
949 : : struct rte_flow_item_tcp tcp;
950 : : struct rte_flow_item_tcp tcp_mask;
951 : :
952 : : memset(&tcp, 0, sizeof(tcp));
953 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
954 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
955 : : /*
956 : : * The HW has no decrement operation, only increment operation.
957 : : * To simulate decrement X from Y using increment operation
958 : : * we need to add UINT32_MAX X times to Y.
959 : : * Each adding of UINT32_MAX decrements Y by 1.
960 : : */
961 : 0 : value *= UINT32_MAX;
962 [ # # ]: 0 : tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
963 : 0 : tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
964 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
965 : 0 : item.spec = &tcp;
966 : 0 : item.mask = &tcp_mask;
967 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
968 : : MLX5_MODIFICATION_TYPE_ADD, error);
969 : : }
970 : :
971 : : static enum mlx5_modification_field reg_to_field[] = {
972 : : [REG_NON] = MLX5_MODI_OUT_NONE,
973 : : [REG_A] = MLX5_MODI_META_DATA_REG_A,
974 : : [REG_B] = MLX5_MODI_META_DATA_REG_B,
975 : : [REG_C_0] = MLX5_MODI_META_REG_C_0,
976 : : [REG_C_1] = MLX5_MODI_META_REG_C_1,
977 : : [REG_C_2] = MLX5_MODI_META_REG_C_2,
978 : : [REG_C_3] = MLX5_MODI_META_REG_C_3,
979 : : [REG_C_4] = MLX5_MODI_META_REG_C_4,
980 : : [REG_C_5] = MLX5_MODI_META_REG_C_5,
981 : : [REG_C_6] = MLX5_MODI_META_REG_C_6,
982 : : [REG_C_7] = MLX5_MODI_META_REG_C_7,
983 : : [REG_C_8] = MLX5_MODI_META_REG_C_8,
984 : : [REG_C_9] = MLX5_MODI_META_REG_C_9,
985 : : [REG_C_10] = MLX5_MODI_META_REG_C_10,
986 : : [REG_C_11] = MLX5_MODI_META_REG_C_11,
987 : : };
988 : :
989 : : /**
990 : : * Convert register set to DV specification.
991 : : *
992 : : * @param[in,out] resource
993 : : * Pointer to the modify-header resource.
994 : : * @param[in] action
995 : : * Pointer to action specification.
996 : : * @param[out] error
997 : : * Pointer to the error structure.
998 : : *
999 : : * @return
1000 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1001 : : */
1002 : : static int
1003 : 0 : flow_dv_convert_action_set_reg
1004 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1005 : : const struct rte_flow_action *action,
1006 : : struct rte_flow_error *error)
1007 : : {
1008 : 0 : const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1009 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
1010 : 0 : uint32_t i = resource->actions_num;
1011 : :
1012 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
1013 : 0 : return rte_flow_error_set(error, EINVAL,
1014 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1015 : : "too many items to modify");
1016 : : MLX5_ASSERT(conf->id != REG_NON);
1017 : : MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1018 : 0 : actions[i] = (struct mlx5_modification_cmd) {
1019 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
1020 : 0 : .field = reg_to_field[conf->id],
1021 : 0 : .offset = conf->offset,
1022 : 0 : .length = conf->length,
1023 : : };
1024 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1025 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(conf->data);
1026 : : ++i;
1027 : 0 : resource->actions_num = i;
1028 : 0 : return 0;
1029 : : }
1030 : :
1031 : : /**
1032 : : * Convert SET_TAG action to DV specification.
1033 : : *
1034 : : * @param[in] dev
1035 : : * Pointer to the rte_eth_dev structure.
1036 : : * @param[in,out] resource
1037 : : * Pointer to the modify-header resource.
1038 : : * @param[in] conf
1039 : : * Pointer to action specification.
1040 : : * @param[out] error
1041 : : * Pointer to the error structure.
1042 : : *
1043 : : * @return
1044 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1045 : : */
1046 : : static int
1047 : 0 : flow_dv_convert_action_set_tag
1048 : : (struct rte_eth_dev *dev,
1049 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1050 : : const struct rte_flow_action_set_tag *conf,
1051 : : struct rte_flow_error *error)
1052 : : {
1053 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->data);
1054 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1055 : 0 : struct rte_flow_item item = {
1056 : : .spec = &data,
1057 : : .mask = &mask,
1058 : : };
1059 : 0 : struct field_modify_info reg_c_x[] = {
1060 : : [1] = {0, 0, 0},
1061 : : };
1062 : : enum mlx5_modification_field reg_type;
1063 : : int ret;
1064 : :
1065 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1066 [ # # ]: 0 : if (ret < 0)
1067 : : return ret;
1068 : : MLX5_ASSERT(ret != REG_NON);
1069 : : MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1070 : 0 : reg_type = reg_to_field[ret];
1071 : : MLX5_ASSERT(reg_type > 0);
1072 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1073 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1074 : : MLX5_MODIFICATION_TYPE_SET, error);
1075 : : }
1076 : :
1077 : : /**
1078 : : * Convert internal COPY_REG action to DV specification.
1079 : : *
1080 : : * @param[in] dev
1081 : : * Pointer to the rte_eth_dev structure.
1082 : : * @param[in,out] res
1083 : : * Pointer to the modify-header resource.
1084 : : * @param[in] action
1085 : : * Pointer to action specification.
1086 : : * @param[out] error
1087 : : * Pointer to the error structure.
1088 : : *
1089 : : * @return
1090 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1091 : : */
1092 : : static int
1093 : 0 : flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1094 : : struct mlx5_flow_dv_modify_hdr_resource *res,
1095 : : const struct rte_flow_action *action,
1096 : : struct rte_flow_error *error)
1097 : : {
1098 : 0 : const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1099 : 0 : rte_be32_t mask = RTE_BE32(UINT32_MAX);
1100 : 0 : struct rte_flow_item item = {
1101 : : .spec = NULL,
1102 : : .mask = &mask,
1103 : : };
1104 : 0 : struct field_modify_info reg_src[] = {
1105 : 0 : {4, 0, reg_to_field[conf->src]},
1106 : : {0, 0, 0},
1107 : : };
1108 : 0 : struct field_modify_info reg_dst = {
1109 : : .offset = 0,
1110 : 0 : .id = reg_to_field[conf->dst],
1111 : : };
1112 : : /* Adjust reg_c[0] usage according to reported mask. */
1113 [ # # # # ]: 0 : if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1114 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1115 : 0 : uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1116 : :
1117 : : MLX5_ASSERT(reg_c0);
1118 : : MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1119 : : MLX5_XMETA_MODE_LEGACY);
1120 [ # # ]: 0 : if (conf->dst == REG_C_0) {
1121 : : /* Copy to reg_c[0], within mask only. */
1122 : 0 : reg_dst.offset = rte_bsf32(reg_c0);
1123 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1124 : : } else {
1125 : : reg_dst.offset = 0;
1126 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0);
1127 : : }
1128 : : }
1129 : 0 : return flow_dv_convert_modify_action(&item,
1130 : : reg_src, ®_dst, res,
1131 : : MLX5_MODIFICATION_TYPE_COPY,
1132 : : error);
1133 : : }
1134 : :
1135 : : /**
1136 : : * Convert MARK action to DV specification. This routine is used
1137 : : * in extensive metadata only and requires metadata register to be
1138 : : * handled. In legacy mode hardware tag resource is engaged.
1139 : : *
1140 : : * @param[in] dev
1141 : : * Pointer to the rte_eth_dev structure.
1142 : : * @param[in] conf
1143 : : * Pointer to MARK action specification.
1144 : : * @param[in,out] resource
1145 : : * Pointer to the modify-header resource.
1146 : : * @param[out] error
1147 : : * Pointer to the error structure.
1148 : : *
1149 : : * @return
1150 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1151 : : */
1152 : : static int
1153 : 0 : flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1154 : : const struct rte_flow_action_mark *conf,
1155 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1156 : : struct rte_flow_error *error)
1157 : : {
1158 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1159 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1160 : : priv->sh->dv_mark_mask);
1161 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1162 : 0 : struct rte_flow_item item = {
1163 : : .spec = &data,
1164 : : .mask = &mask,
1165 : : };
1166 : 0 : struct field_modify_info reg_c_x[] = {
1167 : : [1] = {0, 0, 0},
1168 : : };
1169 : : int reg;
1170 : :
1171 [ # # ]: 0 : if (!mask)
1172 : 0 : return rte_flow_error_set(error, EINVAL,
1173 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1174 : : NULL, "zero mark action mask");
1175 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1176 [ # # ]: 0 : if (reg < 0)
1177 : : return reg;
1178 : : MLX5_ASSERT(reg > 0);
1179 [ # # ]: 0 : if (reg == REG_C_0) {
1180 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1181 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1182 : :
1183 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1184 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1185 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1186 : : }
1187 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1188 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1189 : : MLX5_MODIFICATION_TYPE_SET, error);
1190 : : }
1191 : :
1192 : : /**
1193 : : * Get metadata register index for specified steering domain.
1194 : : *
1195 : : * @param[in] dev
1196 : : * Pointer to the rte_eth_dev structure.
1197 : : * @param[in] attr
1198 : : * Attributes of flow to determine steering domain.
1199 : : * @param[out] error
1200 : : * Pointer to the error structure.
1201 : : *
1202 : : * @return
1203 : : * positive index on success, a negative errno value otherwise
1204 : : * and rte_errno is set.
1205 : : */
1206 : : static enum modify_reg
1207 : 0 : flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1208 : : const struct rte_flow_attr *attr,
1209 : : struct rte_flow_error *error)
1210 : : {
1211 : : int reg =
1212 [ # # ]: 0 : mlx5_flow_get_reg_id(dev, attr->transfer ?
1213 : 0 : MLX5_METADATA_FDB :
1214 [ # # ]: 0 : attr->egress ?
1215 : : MLX5_METADATA_TX :
1216 : : MLX5_METADATA_RX, 0, error);
1217 [ # # ]: 0 : if (reg < 0)
1218 : 0 : return rte_flow_error_set(error,
1219 : : ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1220 : : NULL, "unavailable "
1221 : : "metadata register");
1222 : 0 : return reg;
1223 : : }
1224 : :
1225 : : /**
1226 : : * Convert SET_META action to DV specification.
1227 : : *
1228 : : * @param[in] dev
1229 : : * Pointer to the rte_eth_dev structure.
1230 : : * @param[in,out] resource
1231 : : * Pointer to the modify-header resource.
1232 : : * @param[in] attr
1233 : : * Attributes of flow that includes this item.
1234 : : * @param[in] conf
1235 : : * Pointer to action specification.
1236 : : * @param[out] error
1237 : : * Pointer to the error structure.
1238 : : *
1239 : : * @return
1240 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1241 : : */
1242 : : static int
1243 : 0 : flow_dv_convert_action_set_meta
1244 : : (struct rte_eth_dev *dev,
1245 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1246 : : const struct rte_flow_attr *attr,
1247 : : const struct rte_flow_action_set_meta *conf,
1248 : : struct rte_flow_error *error)
1249 : : {
1250 [ # # ]: 0 : uint32_t mask = rte_cpu_to_be_32(conf->mask);
1251 [ # # ]: 0 : uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1252 : 0 : struct rte_flow_item item = {
1253 : : .spec = &data,
1254 : : .mask = &mask,
1255 : : };
1256 : 0 : struct field_modify_info reg_c_x[] = {
1257 : : [1] = {0, 0, 0},
1258 : : };
1259 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1260 : :
1261 [ # # ]: 0 : if (reg < 0)
1262 : : return reg;
1263 : : MLX5_ASSERT(reg != REG_NON);
1264 [ # # ]: 0 : if (reg == REG_C_0) {
1265 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1266 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1267 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1268 : :
1269 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1270 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1271 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1272 : : }
1273 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1274 : : /* The routine expects parameters in memory as big-endian ones. */
1275 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1276 : : MLX5_MODIFICATION_TYPE_SET, error);
1277 : : }
1278 : :
1279 : : /**
1280 : : * Convert modify-header set IPv4 DSCP action to DV specification.
1281 : : *
1282 : : * @param[in,out] resource
1283 : : * Pointer to the modify-header resource.
1284 : : * @param[in] action
1285 : : * Pointer to action specification.
1286 : : * @param[out] error
1287 : : * Pointer to the error structure.
1288 : : *
1289 : : * @return
1290 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1291 : : */
1292 : : static int
1293 : 0 : flow_dv_convert_action_modify_ipv4_dscp
1294 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1295 : : const struct rte_flow_action *action,
1296 : : struct rte_flow_error *error)
1297 : : {
1298 : 0 : const struct rte_flow_action_set_dscp *conf =
1299 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1300 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1301 : : struct rte_flow_item_ipv4 ipv4;
1302 : : struct rte_flow_item_ipv4 ipv4_mask;
1303 : :
1304 : : memset(&ipv4, 0, sizeof(ipv4));
1305 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1306 : 0 : ipv4.hdr.type_of_service = conf->dscp;
1307 : 0 : ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1308 : 0 : item.spec = &ipv4;
1309 : 0 : item.mask = &ipv4_mask;
1310 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1311 : : MLX5_MODIFICATION_TYPE_SET, error);
1312 : : }
1313 : :
1314 : : /**
1315 : : * Convert modify-header set IPv6 DSCP action to DV specification.
1316 : : *
1317 : : * @param[in,out] resource
1318 : : * Pointer to the modify-header resource.
1319 : : * @param[in] action
1320 : : * Pointer to action specification.
1321 : : * @param[out] error
1322 : : * Pointer to the error structure.
1323 : : *
1324 : : * @return
1325 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1326 : : */
1327 : : static int
1328 : 0 : flow_dv_convert_action_modify_ipv6_dscp
1329 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1330 : : const struct rte_flow_action *action,
1331 : : uint32_t ipv6_tc_off,
1332 : : struct rte_flow_error *error)
1333 : : {
1334 : 0 : const struct rte_flow_action_set_dscp *conf =
1335 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1336 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1337 : : struct rte_flow_item_ipv6 ipv6;
1338 : : struct rte_flow_item_ipv6 ipv6_mask;
1339 : : struct field_modify_info *modify_info;
1340 : :
1341 : : memset(&ipv6, 0, sizeof(ipv6));
1342 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1343 : : /*
1344 : : * Even though the DSCP bits offset of IPv6 is not byte aligned,
1345 : : * rdma-core only accept the DSCP bits byte aligned start from
1346 : : * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1347 : : * bits in IPv6 case as rdma-core requires byte aligned value.
1348 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1349 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1350 : : * it's needed to distinguish DSCP from ECN in data field construct
1351 : : */
1352 : 0 : ipv6.hdr.vtc_flow = conf->dscp << ipv6_tc_off;
1353 : 0 : ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> (22 - ipv6_tc_off);
1354 : 0 : item.spec = &ipv6;
1355 : 0 : item.mask = &ipv6_mask;
1356 [ # # ]: 0 : if (ipv6_tc_off)
1357 : : modify_info = modify_ipv6_traffic_class;
1358 : : else
1359 : : modify_info = modify_ipv6;
1360 : 0 : return flow_dv_convert_modify_action(&item, modify_info, NULL, resource,
1361 : : MLX5_MODIFICATION_TYPE_SET, error);
1362 : : }
1363 : :
1364 : : int
1365 : 0 : mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1366 : : enum rte_flow_field_id field, int inherit,
1367 : : const struct rte_flow_attr *attr,
1368 : : struct rte_flow_error *error)
1369 : : {
1370 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1371 : :
1372 [ # # # # : 0 : switch (field) {
# # # # #
# # # # #
# # # # #
# ]
1373 : : case RTE_FLOW_FIELD_START:
1374 : : return 32;
1375 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1376 : : case RTE_FLOW_FIELD_MAC_SRC:
1377 : 0 : return 48;
1378 : 0 : case RTE_FLOW_FIELD_VLAN_TYPE:
1379 : 0 : return 16;
1380 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1381 : 0 : return 12;
1382 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1383 : 0 : return 16;
1384 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1385 : 0 : return 6;
1386 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1387 : : case RTE_FLOW_FIELD_IPV4_PROTO:
1388 : 0 : return 8;
1389 : : case RTE_FLOW_FIELD_IPV4_SRC:
1390 : : case RTE_FLOW_FIELD_IPV4_DST:
1391 : : return 32;
1392 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1393 : 0 : return 6;
1394 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1395 : : case RTE_FLOW_FIELD_IPV6_PROTO:
1396 : 0 : return 8;
1397 : 0 : case RTE_FLOW_FIELD_IPV6_SRC:
1398 : : case RTE_FLOW_FIELD_IPV6_DST:
1399 : 0 : return 128;
1400 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1401 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
1402 : 0 : return 16;
1403 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1404 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1405 : : return 32;
1406 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1407 : 0 : return 9;
1408 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1409 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
1410 : 0 : return 16;
1411 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1412 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1413 : 0 : return 24;
1414 : : case RTE_FLOW_FIELD_GTP_TEID:
1415 : : case RTE_FLOW_FIELD_MPLS:
1416 : : case RTE_FLOW_FIELD_TAG:
1417 : : case RTE_FLOW_FIELD_ESP_SPI:
1418 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
1419 : : return 32;
1420 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
1421 : 0 : return 8;
1422 : 0 : case RTE_FLOW_FIELD_MARK:
1423 : 0 : return rte_popcount32(priv->sh->dv_mark_mask);
1424 : 0 : case RTE_FLOW_FIELD_META:
1425 : 0 : return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1426 [ # # ]: 0 : rte_popcount32(priv->sh->dv_meta_mask) : 32;
1427 : 0 : case RTE_FLOW_FIELD_POINTER:
1428 : : case RTE_FLOW_FIELD_VALUE:
1429 : 0 : return inherit < 0 ? 0 : inherit;
1430 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1431 : : case RTE_FLOW_FIELD_IPV6_ECN:
1432 : : case RTE_FLOW_FIELD_METER_COLOR:
1433 : 0 : return 2;
1434 : : case RTE_FLOW_FIELD_HASH_RESULT:
1435 : : return 32;
1436 : 0 : default:
1437 : : MLX5_ASSERT(false);
1438 : : }
1439 : 0 : return 0;
1440 : : }
1441 : :
1442 : : static __rte_always_inline uint8_t
1443 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1444 : : {
1445 : 0 : return (0xffu >> (8 - length)) << off;
1446 : : }
1447 : :
1448 : : static __rte_always_inline uint16_t
1449 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1450 : : {
1451 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # ]
1452 : : }
1453 : :
1454 : : static __rte_always_inline uint32_t
1455 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1456 : : {
1457 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1458 : : }
1459 : :
1460 : : static __rte_always_inline uint32_t
1461 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1462 : : {
1463 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1464 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1465 : : }
1466 : :
1467 : : static __rte_always_inline enum mlx5_modification_field
1468 : : mlx5_mpls_modi_field_get(const struct rte_flow_field_data *data)
1469 : : {
1470 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1471 : : }
1472 : :
1473 : : static __rte_always_inline int
1474 : : flow_geneve_opt_modi_field_get(struct mlx5_priv *priv,
1475 : : const struct rte_flow_field_data *data)
1476 : : {
1477 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1478 : 0 : return mlx5_geneve_opt_modi_field_get(priv, data);
1479 : : #else
1480 : : (void)priv;
1481 : : (void)data;
1482 : : DRV_LOG(ERR, "GENEVE option modification is not supported.");
1483 : : rte_errno = ENOTSUP;
1484 : : return -rte_errno;
1485 : : #endif
1486 : : }
1487 : :
1488 : : static void
1489 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1490 : : const struct mlx5_flex_item *flex,
1491 : : const struct rte_flow_field_data *data,
1492 : : struct field_modify_info *info,
1493 : : uint32_t *mask, uint32_t width)
1494 : : {
1495 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1496 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1497 : : uint32_t i, j;
1498 : : int id = 0;
1499 : 0 : uint32_t pos = 0;
1500 : : const struct mlx5_flex_pattern_field *map;
1501 : 0 : uint32_t offset = data->offset;
1502 : : uint32_t width_left = width;
1503 : : uint32_t def;
1504 : : uint32_t cur_width = 0;
1505 : : uint32_t tmp_ofs;
1506 : : uint32_t idx = 0;
1507 : : struct field_modify_info tmp;
1508 : : int tmp_id;
1509 : :
1510 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1511 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1512 : 0 : return;
1513 : : }
1514 : : /*
1515 : : * search for the mapping instance until Accumulated width is no
1516 : : * less than data->offset.
1517 : : */
1518 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1519 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1520 : : break;
1521 : 0 : pos += flex->map[i].width;
1522 : : }
1523 [ # # ]: 0 : if (i >= flex->mapnum)
1524 : : return;
1525 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1526 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1527 : 0 : map = flex->map + i;
1528 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false, &def);
1529 [ # # ]: 0 : if (id == -1) {
1530 : 0 : i++;
1531 : : /* All left length is dummy */
1532 [ # # ]: 0 : if (pos >= data->offset + width)
1533 : : return;
1534 : 0 : cur_width = map->width;
1535 : : /* One mapping instance covers the whole width. */
1536 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1537 : : cur_width = width_left;
1538 : : } else {
1539 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1540 : 0 : pos += map->width;
1541 : : /*
1542 : : * Continue to search next until:
1543 : : * 1. Another flex parser ID.
1544 : : * 2. Width has been covered.
1545 : : */
1546 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1547 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false, &def);
1548 [ # # ]: 0 : if (tmp_id == -1) {
1549 : : i = j;
1550 : 0 : pos -= flex->map[j].width;
1551 : 0 : break;
1552 : : }
1553 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1554 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1555 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1556 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1557 : : return;
1558 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1559 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1560 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1561 [ # # ]: 0 : flex->map[j - 1].shift) {
1562 : : i = j;
1563 : : break;
1564 : : }
1565 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1566 : : cur_width = width_left;
1567 : : break;
1568 : : }
1569 : 0 : pos += flex->map[j].width;
1570 : 0 : cur_width += flex->map[j].width;
1571 : : }
1572 : : }
1573 [ # # ]: 0 : if (cur_width > width_left)
1574 : : cur_width = width_left;
1575 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1576 : : return;
1577 : :
1578 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1579 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1580 : : return;
1581 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1582 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1583 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1584 : : (enum mlx5_modification_field)
1585 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1586 : 0 : map->shift + tmp_ofs, 1};
1587 : 0 : offset += cur_width;
1588 : 0 : width_left -= cur_width;
1589 [ # # ]: 0 : if (!mask) {
1590 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1591 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1592 : : }
1593 : : cur_width = 0;
1594 : : tmp_ofs = 0;
1595 : 0 : idx++;
1596 : : }
1597 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1598 : : MLX5_ASSERT(false);
1599 : : return;
1600 : : }
1601 [ # # ]: 0 : if (mask)
1602 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1603 : : /* Re-order the info to follow IPv6 address. */
1604 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1605 : 0 : tmp = info[i];
1606 : : MLX5_ASSERT(info[i].id);
1607 : : MLX5_ASSERT(info[idx - 1 - i].id);
1608 : 0 : info[i] = info[idx - 1 - i];
1609 : 0 : info[idx - 1 - i] = tmp;
1610 : : }
1611 : : }
1612 : :
1613 : : static inline bool
1614 : : mlx5_dv_modify_ipv6_traffic_class_supported(struct mlx5_priv *priv)
1615 : : {
1616 : 0 : return !priv->sh->ipv6_tc_fallback;
1617 : : }
1618 : :
1619 : : void
1620 : 0 : mlx5_flow_field_id_to_modify_info
1621 : : (const struct rte_flow_field_data *data,
1622 : : struct field_modify_info *info, uint32_t *mask,
1623 : : uint32_t width, struct rte_eth_dev *dev,
1624 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1625 : : {
1626 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1627 : : enum mlx5_modification_field modi_id;
1628 : : uint32_t idx = 0;
1629 : : uint32_t off_be = 0;
1630 : : uint32_t length = 0;
1631 : :
1632 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1633 : : case RTE_FLOW_FIELD_START:
1634 : : /* not supported yet */
1635 : : MLX5_ASSERT(false);
1636 : : break;
1637 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1638 : : MLX5_ASSERT(data->offset + width <= 48);
1639 : 0 : off_be = 48 - (data->offset + width);
1640 [ # # ]: 0 : if (off_be < 16) {
1641 : 0 : info[idx] = (struct field_modify_info){2, 4,
1642 : : MLX5_MODI_OUT_DMAC_15_0};
1643 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1644 [ # # ]: 0 : if (mask)
1645 : 0 : mask[1] = flow_modify_info_mask_16(length,
1646 : : off_be);
1647 : : else
1648 : 0 : info[idx].offset = off_be;
1649 : 0 : width -= length;
1650 [ # # ]: 0 : if (!width)
1651 : : break;
1652 : : off_be = 0;
1653 : : idx++;
1654 : : } else {
1655 : 0 : off_be -= 16;
1656 : : }
1657 : 0 : info[idx] = (struct field_modify_info){4, 0,
1658 : : MLX5_MODI_OUT_DMAC_47_16};
1659 [ # # ]: 0 : if (mask)
1660 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1661 : : else
1662 : 0 : info[idx].offset = off_be;
1663 : : break;
1664 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1665 : : MLX5_ASSERT(data->offset + width <= 48);
1666 : 0 : off_be = 48 - (data->offset + width);
1667 [ # # ]: 0 : if (off_be < 16) {
1668 : 0 : info[idx] = (struct field_modify_info){2, 4,
1669 : : MLX5_MODI_OUT_SMAC_15_0};
1670 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1671 [ # # ]: 0 : if (mask)
1672 : 0 : mask[1] = flow_modify_info_mask_16(length,
1673 : : off_be);
1674 : : else
1675 : 0 : info[idx].offset = off_be;
1676 : 0 : width -= length;
1677 [ # # ]: 0 : if (!width)
1678 : : break;
1679 : : off_be = 0;
1680 : : idx++;
1681 : : } else {
1682 : 0 : off_be -= 16;
1683 : : }
1684 : 0 : info[idx] = (struct field_modify_info){4, 0,
1685 : : MLX5_MODI_OUT_SMAC_47_16};
1686 [ # # ]: 0 : if (mask)
1687 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1688 : : else
1689 : 0 : info[idx].offset = off_be;
1690 : : break;
1691 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1692 : : /* not supported yet */
1693 : : break;
1694 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1695 : : MLX5_ASSERT(data->offset + width <= 12);
1696 : 0 : off_be = 12 - (data->offset + width);
1697 : 0 : info[idx] = (struct field_modify_info){2, 0,
1698 : : MLX5_MODI_OUT_FIRST_VID};
1699 [ # # ]: 0 : if (mask)
1700 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1701 : : else
1702 : 0 : info[idx].offset = off_be;
1703 : : break;
1704 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1705 : : MLX5_ASSERT(data->offset + width <= 16);
1706 : 0 : off_be = 16 - (data->offset + width);
1707 : 0 : info[idx] = (struct field_modify_info){2, 0,
1708 : : MLX5_MODI_OUT_ETHERTYPE};
1709 [ # # ]: 0 : if (mask)
1710 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1711 : : else
1712 : 0 : info[idx].offset = off_be;
1713 : : break;
1714 : 0 : case RTE_FLOW_FIELD_IPV4_IHL:
1715 : : MLX5_ASSERT(data->offset + width <= 4);
1716 : 0 : off_be = 4 - (data->offset + width);
1717 : 0 : info[idx] = (struct field_modify_info){1, 0,
1718 : : MLX5_MODI_OUT_IPV4_IHL};
1719 [ # # ]: 0 : if (mask)
1720 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1721 : : else
1722 : 0 : info[idx].offset = off_be;
1723 : : break;
1724 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1725 : : MLX5_ASSERT(data->offset + width <= 6);
1726 : 0 : off_be = 6 - (data->offset + width);
1727 : 0 : info[idx] = (struct field_modify_info){1, 0,
1728 : : MLX5_MODI_OUT_IP_DSCP};
1729 [ # # ]: 0 : if (mask)
1730 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1731 : : else
1732 : 0 : info[idx].offset = off_be;
1733 : : break;
1734 : 0 : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
1735 : : MLX5_ASSERT(data->offset + width <= 16);
1736 : 0 : off_be = 16 - (data->offset + width);
1737 : 0 : info[idx] = (struct field_modify_info){2, 0,
1738 : : MLX5_MODI_OUT_IPV4_TOTAL_LEN};
1739 [ # # ]: 0 : if (mask)
1740 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1741 : : else
1742 : 0 : info[idx].offset = off_be;
1743 : : break;
1744 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1745 : : MLX5_ASSERT(data->offset + width <= 8);
1746 : 0 : off_be = 8 - (data->offset + width);
1747 : 0 : info[idx] = (struct field_modify_info){1, 0,
1748 : : MLX5_MODI_OUT_IPV4_TTL};
1749 [ # # ]: 0 : if (mask)
1750 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1751 : : else
1752 : 0 : info[idx].offset = off_be;
1753 : : break;
1754 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1755 : : MLX5_ASSERT(data->offset + width <= 32);
1756 : 0 : off_be = 32 - (data->offset + width);
1757 : 0 : info[idx] = (struct field_modify_info){4, 0,
1758 : : MLX5_MODI_OUT_SIPV4};
1759 [ # # ]: 0 : if (mask)
1760 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1761 : : else
1762 : 0 : info[idx].offset = off_be;
1763 : : break;
1764 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1765 : : MLX5_ASSERT(data->offset + width <= 32);
1766 : 0 : off_be = 32 - (data->offset + width);
1767 : 0 : info[idx] = (struct field_modify_info){4, 0,
1768 : : MLX5_MODI_OUT_DIPV4};
1769 [ # # ]: 0 : if (mask)
1770 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1771 : : else
1772 : 0 : info[idx].offset = off_be;
1773 : : break;
1774 : : case RTE_FLOW_FIELD_IPV6_DSCP:
1775 : : MLX5_ASSERT(data->offset + width <= 6);
1776 : : /*
1777 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1778 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1779 : : * it's needed to distinguish DSCP from ECN in data field construct
1780 : : */
1781 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv)) {
1782 : 0 : off_be = 6 - (data->offset + width) + MLX5_IPV6_HDR_DSCP_SHIFT;
1783 : 0 : info[idx] = (struct field_modify_info){1, 0,
1784 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
1785 : : } else {
1786 : 0 : off_be = 6 - (data->offset + width);
1787 : 0 : info[idx] = (struct field_modify_info){1, 0,
1788 : : MLX5_MODI_OUT_IP_DSCP};
1789 : : }
1790 [ # # ]: 0 : if (mask)
1791 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1792 : : else
1793 : 0 : info[idx].offset = off_be;
1794 : : break;
1795 : 0 : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
1796 : : MLX5_ASSERT(data->offset + width <= 16);
1797 : 0 : off_be = 16 - (data->offset + width);
1798 : 0 : info[idx] = (struct field_modify_info){2, 0,
1799 : : MLX5_MODI_OUT_IPV6_PAYLOAD_LEN};
1800 [ # # ]: 0 : if (mask)
1801 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1802 : : else
1803 : 0 : info[idx].offset = off_be;
1804 : : break;
1805 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1806 : : MLX5_ASSERT(data->offset + width <= 8);
1807 : 0 : off_be = 8 - (data->offset + width);
1808 : 0 : info[idx] = (struct field_modify_info){1, 0,
1809 : : MLX5_MODI_OUT_IPV6_HOPLIMIT};
1810 [ # # ]: 0 : if (mask)
1811 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1812 : : else
1813 : 0 : info[idx].offset = off_be;
1814 : : break;
1815 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1816 : : /*
1817 : : * Fields corresponding to IPv6 source address bytes
1818 : : * arranged according to network byte ordering.
1819 : : */
1820 : 0 : struct field_modify_info fields[] = {
1821 : : { 4, 0, MLX5_MODI_OUT_SIPV6_127_96 },
1822 : : { 4, 4, MLX5_MODI_OUT_SIPV6_95_64 },
1823 : : { 4, 8, MLX5_MODI_OUT_SIPV6_63_32 },
1824 : : { 4, 12, MLX5_MODI_OUT_SIPV6_31_0 },
1825 : : };
1826 : : /* First mask to be modified is the mask of 4th address byte. */
1827 : : uint32_t midx = 3;
1828 : :
1829 : : MLX5_ASSERT(data->offset + width <= 128);
1830 : 0 : off_be = 128 - (data->offset + width);
1831 [ # # ]: 0 : while (width > 0 && midx > 0) {
1832 [ # # ]: 0 : if (off_be < 32) {
1833 : 0 : info[idx] = fields[midx];
1834 : 0 : length = off_be + width <= 32 ?
1835 [ # # ]: 0 : width : 32 - off_be;
1836 [ # # ]: 0 : if (mask)
1837 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1838 : : (length, off_be);
1839 : : else
1840 : 0 : info[idx].offset = off_be;
1841 : 0 : width -= length;
1842 : : off_be = 0;
1843 : 0 : idx++;
1844 : : } else {
1845 : 0 : off_be -= 32;
1846 : : }
1847 : 0 : midx--;
1848 : : }
1849 [ # # ]: 0 : if (!width)
1850 : : break;
1851 : 0 : info[idx] = fields[midx];
1852 [ # # ]: 0 : if (mask)
1853 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1854 : : else
1855 : 0 : info[idx].offset = off_be;
1856 : : break;
1857 : : }
1858 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1859 : : /*
1860 : : * Fields corresponding to IPv6 destination address bytes
1861 : : * arranged according to network byte ordering.
1862 : : */
1863 : 0 : struct field_modify_info fields[] = {
1864 : : { 4, 0, MLX5_MODI_OUT_DIPV6_127_96 },
1865 : : { 4, 4, MLX5_MODI_OUT_DIPV6_95_64 },
1866 : : { 4, 8, MLX5_MODI_OUT_DIPV6_63_32 },
1867 : : { 4, 12, MLX5_MODI_OUT_DIPV6_31_0 },
1868 : : };
1869 : : /* First mask to be modified is the mask of 4th address byte. */
1870 : : uint32_t midx = 3;
1871 : :
1872 : : MLX5_ASSERT(data->offset + width <= 128);
1873 : 0 : off_be = 128 - (data->offset + width);
1874 [ # # ]: 0 : while (width > 0 && midx > 0) {
1875 [ # # ]: 0 : if (off_be < 32) {
1876 : 0 : info[idx] = fields[midx];
1877 : 0 : length = off_be + width <= 32 ?
1878 [ # # ]: 0 : width : 32 - off_be;
1879 [ # # ]: 0 : if (mask)
1880 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1881 : : (length, off_be);
1882 : : else
1883 : 0 : info[idx].offset = off_be;
1884 : 0 : width -= length;
1885 : : off_be = 0;
1886 : 0 : idx++;
1887 : : } else {
1888 : 0 : off_be -= 32;
1889 : : }
1890 : 0 : midx--;
1891 : : }
1892 [ # # ]: 0 : if (!width)
1893 : : break;
1894 : 0 : info[idx] = fields[midx];
1895 [ # # ]: 0 : if (mask)
1896 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1897 : : else
1898 : 0 : info[idx].offset = off_be;
1899 : : break;
1900 : : }
1901 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1902 : : MLX5_ASSERT(data->offset + width <= 16);
1903 : 0 : off_be = 16 - (data->offset + width);
1904 : 0 : info[idx] = (struct field_modify_info){2, 0,
1905 : : MLX5_MODI_OUT_TCP_SPORT};
1906 [ # # ]: 0 : if (mask)
1907 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1908 : : else
1909 : 0 : info[idx].offset = off_be;
1910 : : break;
1911 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1912 : : MLX5_ASSERT(data->offset + width <= 16);
1913 : 0 : off_be = 16 - (data->offset + width);
1914 : 0 : info[idx] = (struct field_modify_info){2, 0,
1915 : : MLX5_MODI_OUT_TCP_DPORT};
1916 [ # # ]: 0 : if (mask)
1917 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1918 : : else
1919 : 0 : info[idx].offset = off_be;
1920 : : break;
1921 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1922 : : MLX5_ASSERT(data->offset + width <= 32);
1923 : 0 : off_be = 32 - (data->offset + width);
1924 : 0 : info[idx] = (struct field_modify_info){4, 0,
1925 : : MLX5_MODI_OUT_TCP_SEQ_NUM};
1926 [ # # ]: 0 : if (mask)
1927 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1928 : : else
1929 : 0 : info[idx].offset = off_be;
1930 : : break;
1931 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1932 : : MLX5_ASSERT(data->offset + width <= 32);
1933 : 0 : off_be = 32 - (data->offset + width);
1934 : 0 : info[idx] = (struct field_modify_info){4, 0,
1935 : : MLX5_MODI_OUT_TCP_ACK_NUM};
1936 [ # # ]: 0 : if (mask)
1937 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1938 : : else
1939 : 0 : info[idx].offset = off_be;
1940 : : break;
1941 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1942 : : MLX5_ASSERT(data->offset + width <= 9);
1943 : 0 : off_be = 9 - (data->offset + width);
1944 : 0 : info[idx] = (struct field_modify_info){2, 0,
1945 : : MLX5_MODI_OUT_TCP_FLAGS};
1946 [ # # ]: 0 : if (mask)
1947 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1948 : : else
1949 : 0 : info[idx].offset = off_be;
1950 : : break;
1951 : 0 : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
1952 : : MLX5_ASSERT(data->offset + width <= 4);
1953 : 0 : off_be = 4 - (data->offset + width);
1954 : 0 : info[idx] = (struct field_modify_info){1, 0,
1955 : : MLX5_MODI_OUT_TCP_DATA_OFFSET};
1956 [ # # ]: 0 : if (mask)
1957 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1958 : : else
1959 : 0 : info[idx].offset = off_be;
1960 : : break;
1961 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1962 : : MLX5_ASSERT(data->offset + width <= 16);
1963 : 0 : off_be = 16 - (data->offset + width);
1964 : 0 : info[idx] = (struct field_modify_info){2, 0,
1965 : : MLX5_MODI_OUT_UDP_SPORT};
1966 [ # # ]: 0 : if (mask)
1967 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1968 : : else
1969 : 0 : info[idx].offset = off_be;
1970 : : break;
1971 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
1972 : : MLX5_ASSERT(data->offset + width <= 16);
1973 : 0 : off_be = 16 - (data->offset + width);
1974 : 0 : info[idx] = (struct field_modify_info){2, 0,
1975 : : MLX5_MODI_OUT_UDP_DPORT};
1976 [ # # ]: 0 : if (mask)
1977 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1978 : : else
1979 : 0 : info[idx].offset = off_be;
1980 : : break;
1981 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1982 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1983 : : MLX5_ASSERT(data->offset + width <= 24);
1984 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
1985 : 0 : off_be = 24 - (data->offset + width) + 8;
1986 : 0 : info[idx] = (struct field_modify_info){4, 0,
1987 : : MLX5_MODI_TUNNEL_HDR_DW_1};
1988 [ # # ]: 0 : if (mask)
1989 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1990 : : else
1991 : 0 : info[idx].offset = off_be;
1992 : : break;
1993 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
1994 : : MLX5_ASSERT(data->offset + width <= 8);
1995 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
1996 [ # # ]: 0 : if (modi_id < 0)
1997 : : return;
1998 : : /* Type is on bits 16-8 of GENEVE option header (DW0). */
1999 : 0 : off_be = 32 - (16 + data->offset + width);
2000 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2001 [ # # ]: 0 : if (mask)
2002 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2003 : : else
2004 : 0 : info[idx].offset = off_be;
2005 : : break;
2006 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
2007 : : MLX5_ASSERT(data->offset + width <= 16);
2008 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2009 [ # # ]: 0 : if (modi_id < 0)
2010 : : return;
2011 : : /* Class is on bits 31-16 of GENEVE option header (DW0). */
2012 : 0 : off_be = 32 - (data->offset + width);
2013 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2014 [ # # ]: 0 : if (mask)
2015 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2016 : : else
2017 : 0 : info[idx].offset = off_be;
2018 : : break;
2019 : 0 : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
2020 [ # # ]: 0 : if ((data->offset % 32) + width > 32) {
2021 : 0 : DRV_LOG(ERR, "Geneve TLV option data is per DW.");
2022 : 0 : return;
2023 : : }
2024 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2025 [ # # ]: 0 : if (modi_id < 0)
2026 : : return;
2027 : : /* Use offset inside DW. */
2028 : 0 : off_be = 32 - ((data->offset % 32) + width);
2029 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2030 [ # # ]: 0 : if (mask)
2031 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2032 : : else
2033 : 0 : info[idx].offset = off_be;
2034 : : break;
2035 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
2036 : : MLX5_ASSERT(data->offset + width <= 32);
2037 : 0 : off_be = 32 - (data->offset + width);
2038 : 0 : info[idx] = (struct field_modify_info){4, 0,
2039 : : MLX5_MODI_GTP_TEID};
2040 [ # # ]: 0 : if (mask)
2041 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2042 : : else
2043 : 0 : info[idx].offset = off_be;
2044 : : break;
2045 : 0 : case RTE_FLOW_FIELD_MPLS:
2046 : : MLX5_ASSERT(data->offset + width <= 32);
2047 : 0 : off_be = 32 - (data->offset + width);
2048 : : modi_id = mlx5_mpls_modi_field_get(data);
2049 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2050 [ # # ]: 0 : if (mask)
2051 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2052 : : else
2053 : 0 : info[idx].offset = off_be;
2054 : : break;
2055 : : case RTE_FLOW_FIELD_TAG:
2056 : : {
2057 : : MLX5_ASSERT(data->offset + width <= 32);
2058 : : uint8_t tag_index = flow_tag_index_get(data);
2059 : : int reg;
2060 : :
2061 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
2062 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
2063 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2064 [ # # ]: 0 : reg = flow_hw_get_reg_id(dev,
2065 : : RTE_FLOW_ITEM_TYPE_TAG,
2066 : : tag_index);
2067 : : else
2068 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
2069 : : tag_index, error);
2070 [ # # ]: 0 : if (reg < 0)
2071 : : return;
2072 : : MLX5_ASSERT(reg != REG_NON);
2073 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2074 : 0 : info[idx] = (struct field_modify_info){4, 0,
2075 : 0 : reg_to_field[reg]};
2076 [ # # ]: 0 : if (mask)
2077 : 0 : mask[idx] = flow_modify_info_mask_32
2078 : : (width, off_be);
2079 : : else
2080 : 0 : info[idx].offset = off_be;
2081 : : }
2082 : : break;
2083 : 0 : case RTE_FLOW_FIELD_MARK:
2084 : : {
2085 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
2086 : : uint32_t mark_count = rte_popcount32(mark_mask);
2087 : : RTE_SET_USED(mark_count);
2088 : : MLX5_ASSERT(data->offset + width <= mark_count);
2089 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
2090 : : 0, error);
2091 [ # # ]: 0 : if (reg < 0)
2092 : : return;
2093 : : MLX5_ASSERT(reg != REG_NON);
2094 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2095 : 0 : info[idx] = (struct field_modify_info){4, 0,
2096 : 0 : reg_to_field[reg]};
2097 [ # # ]: 0 : if (mask)
2098 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2099 [ # # ]: 0 : (width, data->offset, mark_mask);
2100 : : else
2101 : 0 : info[idx].offset = data->offset;
2102 : : }
2103 : : break;
2104 : 0 : case RTE_FLOW_FIELD_META:
2105 : : {
2106 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2107 : : uint32_t meta_count = rte_popcount32(meta_mask);
2108 : : RTE_SET_USED(meta_count);
2109 : : MLX5_ASSERT(data->offset + width <= meta_count);
2110 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
2111 [ # # ]: 0 : if (reg < 0)
2112 : : return;
2113 : : MLX5_ASSERT(reg != REG_NON);
2114 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2115 : 0 : info[idx] = (struct field_modify_info){4, 0,
2116 : 0 : reg_to_field[reg]};
2117 [ # # ]: 0 : if (mask)
2118 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2119 [ # # ]: 0 : (width, data->offset, meta_mask);
2120 : : else
2121 : 0 : info[idx].offset = data->offset;
2122 : : }
2123 : : break;
2124 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
2125 : : MLX5_ASSERT(data->offset + width <= 2);
2126 : 0 : off_be = 2 - (data->offset + width);
2127 : 0 : info[idx] = (struct field_modify_info){1, 0,
2128 : : MLX5_MODI_OUT_IP_ECN};
2129 [ # # ]: 0 : if (mask)
2130 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2131 : : else
2132 : 0 : info[idx].offset = off_be;
2133 : : break;
2134 : 0 : case RTE_FLOW_FIELD_IPV6_ECN:
2135 : : MLX5_ASSERT(data->offset + width <= 2);
2136 : 0 : off_be = 2 - (data->offset + width);
2137 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
2138 : 0 : info[idx] = (struct field_modify_info){1, 0,
2139 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
2140 : : else
2141 : 0 : info[idx] = (struct field_modify_info){1, 0,
2142 : : MLX5_MODI_OUT_IP_ECN};
2143 [ # # ]: 0 : if (mask)
2144 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2145 : : else
2146 : 0 : info[idx].offset = off_be;
2147 : : break;
2148 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
2149 : : MLX5_ASSERT(data->offset + width <= 8);
2150 : 0 : off_be = data->offset + 8;
2151 : 0 : info[idx] = (struct field_modify_info){4, 0,
2152 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2153 [ # # ]: 0 : if (mask)
2154 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2155 : : else
2156 : 0 : info[idx].offset = off_be;
2157 : : break;
2158 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2159 : : {
2160 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2161 : : uint32_t meta_count = rte_popcount32(meta_mask);
2162 : : uint8_t reg = flow_tag_index_get(data);
2163 : :
2164 : : RTE_SET_USED(meta_count);
2165 : : MLX5_ASSERT(data->offset + width <= meta_count);
2166 : : MLX5_ASSERT(reg != REG_NON);
2167 : : MLX5_ASSERT(reg < RTE_DIM(reg_to_field));
2168 : 0 : info[idx] = (struct field_modify_info){4, 0, reg_to_field[reg]};
2169 [ # # ]: 0 : if (mask)
2170 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2171 [ # # ]: 0 : (width, data->offset, meta_mask);
2172 : : else
2173 : 0 : info[idx].offset = data->offset;
2174 : : }
2175 : : break;
2176 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2177 : : {
2178 : : const uint32_t color_mask =
2179 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2180 : : int reg;
2181 : :
2182 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2183 : : reg = flow_hw_get_reg_id
2184 : : (dev,
2185 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2186 : : else
2187 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2188 : : 0, error);
2189 [ # # ]: 0 : if (reg < 0)
2190 : : return;
2191 : : MLX5_ASSERT(reg != REG_NON);
2192 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2193 : 0 : info[idx] = (struct field_modify_info){4, 0,
2194 : 0 : reg_to_field[reg]};
2195 [ # # ]: 0 : if (mask)
2196 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2197 [ # # ]: 0 : (width, data->offset, color_mask);
2198 : : else
2199 : 0 : info[idx].offset = data->offset;
2200 : : }
2201 : : break;
2202 : 0 : case RTE_FLOW_FIELD_IPV4_PROTO: /* Fall-through. */
2203 : : case RTE_FLOW_FIELD_IPV6_PROTO:
2204 : : MLX5_ASSERT(data->offset + width <= 8);
2205 : 0 : off_be = 8 - (data->offset + width);
2206 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IP_PROTOCOL};
2207 [ # # ]: 0 : if (mask)
2208 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2209 : : else
2210 : 0 : info[idx].offset = off_be;
2211 : : break;
2212 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
2213 : : MLX5_ASSERT(data->offset + width <= 8);
2214 : 0 : off_be = 8 - (data->offset + width);
2215 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IPSEC_NEXT_HDR};
2216 [ # # ]: 0 : if (mask)
2217 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2218 : : else
2219 : 0 : info[idx].offset = off_be;
2220 : : break;
2221 : 0 : case RTE_FLOW_FIELD_ESP_SPI:
2222 : : MLX5_ASSERT(data->offset + width <= 32);
2223 : 0 : off_be = 32 - (data->offset + width);
2224 : 0 : info[idx] = (struct field_modify_info){4, 0, MLX5_MODI_OUT_ESP_SPI};
2225 [ # # ]: 0 : if (mask)
2226 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2227 : : else
2228 : 0 : info[idx].offset = off_be;
2229 : : break;
2230 : 0 : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
2231 : : MLX5_ASSERT(data->offset + width <= 32);
2232 : 0 : off_be = 32 - (data->offset + width);
2233 : 0 : info[idx] = (struct field_modify_info){4, 0, MLX5_MODI_OUT_ESP_SEQ_NUM};
2234 [ # # ]: 0 : if (mask)
2235 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2236 : : else
2237 : 0 : info[idx].offset = off_be;
2238 : : break;
2239 : 0 : case RTE_FLOW_FIELD_FLEX_ITEM:
2240 : : MLX5_ASSERT(data->flex_handle != NULL && !(data->offset & 0x7));
2241 : 0 : mlx5_modify_flex_item(dev, (const struct mlx5_flex_item *)data->flex_handle,
2242 : : data, info, mask, width);
2243 : 0 : break;
2244 : 0 : case RTE_FLOW_FIELD_HASH_RESULT:
2245 : : MLX5_ASSERT(data->offset + width <= 32);
2246 : 0 : off_be = 32 - (data->offset + width);
2247 : 0 : info[idx] = (struct field_modify_info){4, 0,
2248 : : MLX5_MODI_HASH_RESULT};
2249 [ # # ]: 0 : if (mask)
2250 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2251 : : else
2252 : 0 : info[idx].offset = off_be;
2253 : : break;
2254 : : case RTE_FLOW_FIELD_POINTER:
2255 : : case RTE_FLOW_FIELD_VALUE:
2256 : : default:
2257 : : MLX5_ASSERT(false);
2258 : : break;
2259 : : }
2260 : : }
2261 : :
2262 : : /**
2263 : : * Convert modify_field action to DV specification.
2264 : : *
2265 : : * @param[in] dev
2266 : : * Pointer to the rte_eth_dev structure.
2267 : : * @param[in,out] resource
2268 : : * Pointer to the modify-header resource.
2269 : : * @param[in] action
2270 : : * Pointer to action specification.
2271 : : * @param[in] attr
2272 : : * Attributes of flow that includes this item.
2273 : : * @param[out] error
2274 : : * Pointer to the error structure.
2275 : : *
2276 : : * @return
2277 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2278 : : */
2279 : : static int
2280 : 0 : flow_dv_convert_action_modify_field
2281 : : (struct rte_eth_dev *dev,
2282 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
2283 : : const struct rte_flow_action *action,
2284 : : const struct rte_flow_attr *attr,
2285 : : struct rte_flow_error *error)
2286 : : {
2287 : 0 : const struct rte_flow_action_modify_field *conf =
2288 : : (const struct rte_flow_action_modify_field *)(action->conf);
2289 : 0 : struct rte_flow_item item = {
2290 : : .spec = NULL,
2291 : : .mask = NULL
2292 : : };
2293 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
2294 : : {0, 0, 0} };
2295 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
2296 : : {0, 0, 0} };
2297 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
2298 : 0 : uint32_t type, meta = 0, dscp = 0;
2299 : :
2300 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
2301 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
2302 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
2303 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_SET : MLX5_MODIFICATION_TYPE_ADD;
2304 : : /** For SET fill the destination field (field) first. */
2305 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
2306 : 0 : conf->width, dev,
2307 : : attr, error);
2308 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
2309 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
2310 : : (void *)(uintptr_t)&conf->src.value;
2311 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
2312 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
2313 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR) {
2314 : 0 : meta = *(const unaligned_uint32_t *)item.spec;
2315 [ # # ]: 0 : meta = rte_cpu_to_be_32(meta);
2316 : 0 : item.spec = &meta;
2317 : : }
2318 [ # # # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private) &&
2319 : 0 : conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
2320 [ # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK)) {
2321 : 0 : dscp = *(const unaligned_uint32_t *)item.spec;
2322 : : /*
2323 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
2324 : : * bits left. Shift the data left for IPv6 DSCP
2325 : : */
2326 : 0 : dscp <<= MLX5_IPV6_HDR_DSCP_SHIFT;
2327 : 0 : item.spec = &dscp;
2328 : : }
2329 : : } else {
2330 : : type = MLX5_MODIFICATION_TYPE_COPY;
2331 : : /** For COPY fill the destination field (dcopy) without mask. */
2332 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
2333 : 0 : conf->width, dev,
2334 : : attr, error);
2335 : : /** Then construct the source field (field) with mask. */
2336 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
2337 : 0 : conf->width, dev,
2338 : : attr, error);
2339 : : }
2340 : 0 : item.mask = &mask;
2341 : 0 : return flow_dv_convert_modify_action(&item,
2342 : : field, dcopy, resource, type, error);
2343 : : }
2344 : :
2345 : : /**
2346 : : * Validate MARK item.
2347 : : *
2348 : : * @param[in] dev
2349 : : * Pointer to the rte_eth_dev structure.
2350 : : * @param[in] item
2351 : : * Item specification.
2352 : : * @param[in] attr
2353 : : * Attributes of flow that includes this item.
2354 : : * @param[out] error
2355 : : * Pointer to error structure.
2356 : : *
2357 : : * @return
2358 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2359 : : */
2360 : : static int
2361 : 0 : flow_dv_validate_item_mark(struct rte_eth_dev *dev,
2362 : : const struct rte_flow_item *item,
2363 : : const struct rte_flow_attr *attr __rte_unused,
2364 : : struct rte_flow_error *error)
2365 : : {
2366 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2367 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2368 : 0 : const struct rte_flow_item_mark *spec = item->spec;
2369 : 0 : const struct rte_flow_item_mark *mask = item->mask;
2370 : 0 : const struct rte_flow_item_mark nic_mask = {
2371 : 0 : .id = priv->sh->dv_mark_mask,
2372 : : };
2373 : : int ret;
2374 : :
2375 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2376 : 0 : return rte_flow_error_set(error, ENOTSUP,
2377 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2378 : : "extended metadata feature"
2379 : : " isn't enabled");
2380 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2381 : 0 : return rte_flow_error_set(error, ENOTSUP,
2382 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2383 : : "extended metadata register"
2384 : : " isn't supported");
2385 [ # # ]: 0 : if (!nic_mask.id)
2386 : 0 : return rte_flow_error_set(error, ENOTSUP,
2387 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2388 : : "extended metadata register"
2389 : : " isn't available");
2390 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2391 [ # # ]: 0 : if (ret < 0)
2392 : : return ret;
2393 [ # # ]: 0 : if (!spec)
2394 : 0 : return rte_flow_error_set(error, EINVAL,
2395 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2396 : 0 : item->spec,
2397 : : "data cannot be empty");
2398 [ # # ]: 0 : if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
2399 : 0 : return rte_flow_error_set(error, EINVAL,
2400 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2401 : 0 : &spec->id,
2402 : : "mark id exceeds the limit");
2403 [ # # ]: 0 : if (!mask)
2404 : : mask = &nic_mask;
2405 [ # # ]: 0 : if (!mask->id)
2406 : 0 : return rte_flow_error_set(error, EINVAL,
2407 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2408 : : "mask cannot be zero");
2409 : :
2410 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2411 : : (const uint8_t *)&nic_mask,
2412 : : sizeof(struct rte_flow_item_mark),
2413 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2414 : : if (ret < 0)
2415 : : return ret;
2416 : : return 0;
2417 : : }
2418 : :
2419 : : /**
2420 : : * Validate META item.
2421 : : *
2422 : : * @param[in] dev
2423 : : * Pointer to the rte_eth_dev structure.
2424 : : * @param[in] item
2425 : : * Item specification.
2426 : : * @param[in] attr
2427 : : * Attributes of flow that includes this item.
2428 : : * @param[out] error
2429 : : * Pointer to error structure.
2430 : : *
2431 : : * @return
2432 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2433 : : */
2434 : : static int
2435 : 0 : flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2436 : : const struct rte_flow_item *item,
2437 : : const struct rte_flow_attr *attr,
2438 : : struct rte_flow_error *error)
2439 : : {
2440 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2441 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2442 : 0 : const struct rte_flow_item_meta *spec = item->spec;
2443 : 0 : const struct rte_flow_item_meta *mask = item->mask;
2444 : 0 : struct rte_flow_item_meta nic_mask = {
2445 : : .data = UINT32_MAX
2446 : : };
2447 : : int reg;
2448 : : int ret;
2449 : :
2450 [ # # ]: 0 : if (!spec)
2451 : 0 : return rte_flow_error_set(error, EINVAL,
2452 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2453 : : item->spec,
2454 : : "data cannot be empty");
2455 [ # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2456 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2457 : 0 : return rte_flow_error_set(error, ENOTSUP,
2458 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2459 : : "extended metadata register"
2460 : : " isn't supported");
2461 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
2462 [ # # ]: 0 : if (reg < 0)
2463 : : return reg;
2464 [ # # ]: 0 : if (reg == REG_NON)
2465 : 0 : return rte_flow_error_set(error, ENOTSUP,
2466 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2467 : : "unavailable extended metadata register");
2468 [ # # ]: 0 : if (reg == REG_B)
2469 : 0 : return rte_flow_error_set(error, ENOTSUP,
2470 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2471 : : "match on reg_b "
2472 : : "isn't supported");
2473 [ # # ]: 0 : if (reg != REG_A)
2474 : 0 : nic_mask.data = priv->sh->dv_meta_mask;
2475 : : } else {
2476 [ # # ]: 0 : if (attr->transfer)
2477 : 0 : return rte_flow_error_set(error, ENOTSUP,
2478 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2479 : : "extended metadata feature "
2480 : : "should be enabled when "
2481 : : "meta item is requested "
2482 : : "with e-switch mode ");
2483 [ # # ]: 0 : if (attr->ingress)
2484 : 0 : return rte_flow_error_set(error, ENOTSUP,
2485 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2486 : : "match on metadata for ingress "
2487 : : "is not supported in legacy "
2488 : : "metadata mode");
2489 : : }
2490 [ # # ]: 0 : if (!mask)
2491 : : mask = &rte_flow_item_meta_mask;
2492 [ # # ]: 0 : if (!mask->data)
2493 : 0 : return rte_flow_error_set(error, EINVAL,
2494 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2495 : : "mask cannot be zero");
2496 : :
2497 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2498 : : (const uint8_t *)&nic_mask,
2499 : : sizeof(struct rte_flow_item_meta),
2500 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2501 : 0 : return ret;
2502 : : }
2503 : :
2504 : : /**
2505 : : * Validate TAG item.
2506 : : *
2507 : : * @param[in] dev
2508 : : * Pointer to the rte_eth_dev structure.
2509 : : * @param[in] item
2510 : : * Item specification.
2511 : : * @param[in] tag_bitmap
2512 : : * Tag index bitmap.
2513 : : * @param[in] attr
2514 : : * Attributes of flow that includes this item.
2515 : : * @param[out] error
2516 : : * Pointer to error structure.
2517 : : *
2518 : : * @return
2519 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2520 : : */
2521 : : static int
2522 : 0 : flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2523 : : const struct rte_flow_item *item,
2524 : : uint32_t *tag_bitmap,
2525 : : const struct rte_flow_attr *attr __rte_unused,
2526 : : struct rte_flow_error *error)
2527 : : {
2528 : 0 : const struct rte_flow_item_tag *spec = item->spec;
2529 : 0 : const struct rte_flow_item_tag *mask = item->mask;
2530 : 0 : const struct rte_flow_item_tag nic_mask = {
2531 : : .data = RTE_BE32(UINT32_MAX),
2532 : : .index = 0xff,
2533 : : };
2534 : : int ret;
2535 : :
2536 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2537 : 0 : return rte_flow_error_set(error, ENOTSUP,
2538 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2539 : : "extensive metadata register"
2540 : : " isn't supported");
2541 [ # # ]: 0 : if (!spec)
2542 : 0 : return rte_flow_error_set(error, EINVAL,
2543 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2544 : 0 : item->spec,
2545 : : "data cannot be empty");
2546 [ # # ]: 0 : if (!mask)
2547 : : mask = &rte_flow_item_tag_mask;
2548 [ # # ]: 0 : if (!mask->data)
2549 : 0 : return rte_flow_error_set(error, EINVAL,
2550 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2551 : : "mask cannot be zero");
2552 : :
2553 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2554 : : (const uint8_t *)&nic_mask,
2555 : : sizeof(struct rte_flow_item_tag),
2556 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2557 [ # # ]: 0 : if (ret < 0)
2558 : : return ret;
2559 [ # # ]: 0 : if (mask->index != 0xff)
2560 : 0 : return rte_flow_error_set(error, EINVAL,
2561 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2562 : : "partial mask for tag index"
2563 : : " is not supported");
2564 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2565 [ # # ]: 0 : if (ret < 0)
2566 : : return ret;
2567 : : MLX5_ASSERT(ret != REG_NON);
2568 [ # # ]: 0 : if (*tag_bitmap & (1 << ret))
2569 : 0 : return rte_flow_error_set(error, EINVAL,
2570 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2571 : 0 : item->spec,
2572 : : "Duplicated tag index");
2573 : 0 : *tag_bitmap |= 1 << ret;
2574 : 0 : return 0;
2575 : : }
2576 : :
2577 : : /**
2578 : : * Validate vport item.
2579 : : *
2580 : : * @param[in] dev
2581 : : * Pointer to the rte_eth_dev structure.
2582 : : * @param[in] item
2583 : : * Item specification.
2584 : : * @param[in] attr
2585 : : * Attributes of flow that includes this item.
2586 : : * @param[in] item_flags
2587 : : * Bit-fields that holds the items detected until now.
2588 : : * @param[out] error
2589 : : * Pointer to error structure.
2590 : : *
2591 : : * @return
2592 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2593 : : */
2594 : : static int
2595 : 0 : flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2596 : : const struct rte_flow_item *item,
2597 : : const struct rte_flow_attr *attr,
2598 : : uint64_t item_flags,
2599 : : struct mlx5_priv **act_priv,
2600 : : struct rte_flow_error *error)
2601 : : {
2602 : 0 : const struct rte_flow_item_port_id *spec = item->spec;
2603 : 0 : const struct rte_flow_item_port_id *mask = item->mask;
2604 : 0 : const struct rte_flow_item_port_id switch_mask = {
2605 : : .id = 0xffffffff,
2606 : : };
2607 : : struct mlx5_priv *esw_priv;
2608 : : struct mlx5_priv *dev_priv;
2609 : : int ret;
2610 : :
2611 [ # # ]: 0 : if (!attr->transfer)
2612 : 0 : return rte_flow_error_set(error, EINVAL,
2613 : : RTE_FLOW_ERROR_TYPE_ITEM,
2614 : : NULL,
2615 : : "match on port id is valid only"
2616 : : " when transfer flag is enabled");
2617 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2618 : 0 : return rte_flow_error_set(error, ENOTSUP,
2619 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2620 : : "multiple source ports are not"
2621 : : " supported");
2622 [ # # ]: 0 : if (!mask)
2623 : : mask = &switch_mask;
2624 [ # # ]: 0 : if (mask->id != 0xffffffff)
2625 : 0 : return rte_flow_error_set(error, ENOTSUP,
2626 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2627 : : mask,
2628 : : "no support for partial mask on"
2629 : : " \"id\" field");
2630 : 0 : ret = mlx5_flow_item_acceptable
2631 : : (item, (const uint8_t *)mask,
2632 : : (const uint8_t *)&rte_flow_item_port_id_mask,
2633 : : sizeof(struct rte_flow_item_port_id),
2634 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2635 [ # # ]: 0 : if (ret)
2636 : : return ret;
2637 [ # # ]: 0 : if (!spec)
2638 : : return 0;
2639 [ # # ]: 0 : if (spec->id == MLX5_PORT_ESW_MGR)
2640 : : return 0;
2641 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2642 [ # # ]: 0 : if (!esw_priv)
2643 : 0 : return rte_flow_error_set(error, rte_errno,
2644 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2645 : : "failed to obtain E-Switch info for"
2646 : : " port");
2647 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2648 [ # # ]: 0 : if (!dev_priv)
2649 : 0 : return rte_flow_error_set(error, rte_errno,
2650 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2651 : : NULL,
2652 : : "failed to obtain E-Switch info");
2653 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2654 : 0 : return rte_flow_error_set(error, EINVAL,
2655 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2656 : : "cannot match on a port from a"
2657 : : " different E-Switch");
2658 : 0 : *act_priv = esw_priv;
2659 : 0 : return 0;
2660 : : }
2661 : :
2662 : : /**
2663 : : * Validate represented port item.
2664 : : *
2665 : : * @param[in] dev
2666 : : * Pointer to the rte_eth_dev structure.
2667 : : * @param[in] item
2668 : : * Item specification.
2669 : : * @param[in] attr
2670 : : * Attributes of flow that includes this item.
2671 : : * @param[in] item_flags
2672 : : * Bit-fields that holds the items detected until now.
2673 : : * @param[out] error
2674 : : * Pointer to error structure.
2675 : : *
2676 : : * @return
2677 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2678 : : */
2679 : : static int
2680 : 0 : flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2681 : : const struct rte_flow_item *item,
2682 : : const struct rte_flow_attr *attr,
2683 : : uint64_t item_flags,
2684 : : struct mlx5_priv **act_priv,
2685 : : struct rte_flow_error *error)
2686 : : {
2687 : 0 : const struct rte_flow_item_ethdev *spec = item->spec;
2688 : 0 : const struct rte_flow_item_ethdev *mask = item->mask;
2689 : 0 : const struct rte_flow_item_ethdev switch_mask = {
2690 : : .port_id = UINT16_MAX,
2691 : : };
2692 : : struct mlx5_priv *esw_priv;
2693 : : struct mlx5_priv *dev_priv;
2694 : : int ret;
2695 : :
2696 [ # # ]: 0 : if (!attr->transfer)
2697 : 0 : return rte_flow_error_set(error, EINVAL,
2698 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2699 : : "match on port id is valid only when transfer flag is enabled");
2700 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2701 : 0 : return rte_flow_error_set(error, ENOTSUP,
2702 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2703 : : "multiple source ports are not supported");
2704 [ # # ]: 0 : if (!mask)
2705 : : mask = &switch_mask;
2706 [ # # ]: 0 : if (mask->port_id != UINT16_MAX)
2707 : 0 : return rte_flow_error_set(error, ENOTSUP,
2708 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2709 : : "no support for partial mask on \"id\" field");
2710 : 0 : ret = mlx5_flow_item_acceptable
2711 : : (item, (const uint8_t *)mask,
2712 : : (const uint8_t *)&rte_flow_item_ethdev_mask,
2713 : : sizeof(struct rte_flow_item_ethdev),
2714 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2715 [ # # ]: 0 : if (ret)
2716 : : return ret;
2717 [ # # # # ]: 0 : if (!spec || spec->port_id == UINT16_MAX)
2718 : : return 0;
2719 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2720 [ # # ]: 0 : if (!esw_priv)
2721 : 0 : return rte_flow_error_set(error, rte_errno,
2722 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2723 : : "failed to obtain E-Switch info for port");
2724 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2725 [ # # ]: 0 : if (!dev_priv)
2726 : 0 : return rte_flow_error_set(error, rte_errno,
2727 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2728 : : NULL,
2729 : : "failed to obtain E-Switch info");
2730 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2731 : 0 : return rte_flow_error_set(error, EINVAL,
2732 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2733 : : "cannot match on a port from a different E-Switch");
2734 : 0 : *act_priv = esw_priv;
2735 : 0 : return 0;
2736 : : }
2737 : :
2738 : : /**
2739 : : * Validate VLAN item.
2740 : : *
2741 : : * @param[in] item
2742 : : * Item specification.
2743 : : * @param[in] item_flags
2744 : : * Bit-fields that holds the items detected until now.
2745 : : * @param[in] dev
2746 : : * Ethernet device flow is being created on.
2747 : : * @param[out] error
2748 : : * Pointer to error structure.
2749 : : *
2750 : : * @return
2751 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2752 : : */
2753 : : static int
2754 : 0 : flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2755 : : uint64_t item_flags,
2756 : : struct rte_eth_dev *dev,
2757 : : struct rte_flow_error *error)
2758 : : {
2759 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2760 : 0 : const struct rte_flow_item_vlan nic_mask = {
2761 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2762 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2763 : : .has_more_vlan = 1,
2764 : : };
2765 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2766 : : int ret;
2767 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2768 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2769 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2770 : : MLX5_FLOW_LAYER_OUTER_L4);
2771 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2772 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2773 : :
2774 [ # # ]: 0 : if (item_flags & vlanm)
2775 : 0 : return rte_flow_error_set(error, EINVAL,
2776 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2777 : : "multiple VLAN layers not supported");
2778 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2779 : 0 : return rte_flow_error_set(error, EINVAL,
2780 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2781 : : "VLAN cannot follow L3/L4 layer");
2782 [ # # ]: 0 : if (!mask)
2783 : : mask = &rte_flow_item_vlan_mask;
2784 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2785 : : (const uint8_t *)&nic_mask,
2786 : : sizeof(struct rte_flow_item_vlan),
2787 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2788 [ # # ]: 0 : if (ret)
2789 : : return ret;
2790 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2791 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2792 : :
2793 [ # # ]: 0 : if (priv->vmwa_context) {
2794 : : /*
2795 : : * Non-NULL context means we have a virtual machine
2796 : : * and SR-IOV enabled, we have to create VLAN interface
2797 : : * to make hypervisor to setup E-Switch vport
2798 : : * context correctly. We avoid creating the multiple
2799 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2800 : : */
2801 : 0 : return rte_flow_error_set(error, EINVAL,
2802 : : RTE_FLOW_ERROR_TYPE_ITEM,
2803 : : item,
2804 : : "VLAN tag mask is not"
2805 : : " supported in virtual"
2806 : : " environment");
2807 : : }
2808 : : }
2809 : : return 0;
2810 : : }
2811 : :
2812 : : /*
2813 : : * GTP flags are contained in 1 byte of the format:
2814 : : * -------------------------------------------
2815 : : * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2816 : : * |-----------------------------------------|
2817 : : * | value | Version | PT | Res | E | S | PN |
2818 : : * -------------------------------------------
2819 : : *
2820 : : * Matching is supported only for GTP flags E, S, PN.
2821 : : */
2822 : : #define MLX5_GTP_FLAGS_MASK 0x07
2823 : :
2824 : : /**
2825 : : * Validate GTP item.
2826 : : *
2827 : : * @param[in] dev
2828 : : * Pointer to the rte_eth_dev structure.
2829 : : * @param[in] item
2830 : : * Item specification.
2831 : : * @param[in] item_flags
2832 : : * Bit-fields that holds the items detected until now.
2833 : : * @param[out] error
2834 : : * Pointer to error structure.
2835 : : *
2836 : : * @return
2837 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2838 : : */
2839 : : static int
2840 : 0 : flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2841 : : const struct rte_flow_item *item,
2842 : : uint64_t item_flags,
2843 : : struct rte_flow_error *error)
2844 : : {
2845 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2846 : 0 : const struct rte_flow_item_gtp *spec = item->spec;
2847 : 0 : const struct rte_flow_item_gtp *mask = item->mask;
2848 : 0 : const struct rte_flow_item_gtp nic_mask = {
2849 : : .hdr.gtp_hdr_info = MLX5_GTP_FLAGS_MASK,
2850 : : .hdr.msg_type = 0xff,
2851 : : .hdr.teid = RTE_BE32(0xffffffff),
2852 : : };
2853 : :
2854 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2855 : 0 : return rte_flow_error_set(error, ENOTSUP,
2856 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2857 : : "GTP support is not enabled");
2858 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2859 : 0 : return rte_flow_error_set(error, ENOTSUP,
2860 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2861 : : "multiple tunnel layers not"
2862 : : " supported");
2863 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2864 : 0 : return rte_flow_error_set(error, EINVAL,
2865 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2866 : : "no outer UDP layer found");
2867 [ # # ]: 0 : if (!mask)
2868 : : mask = &rte_flow_item_gtp_mask;
2869 [ # # # # ]: 0 : if (spec && spec->hdr.gtp_hdr_info & ~MLX5_GTP_FLAGS_MASK)
2870 : 0 : return rte_flow_error_set(error, ENOTSUP,
2871 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2872 : : "Match is supported for GTP"
2873 : : " flags only");
2874 : 0 : return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2875 : : (const uint8_t *)&nic_mask,
2876 : : sizeof(struct rte_flow_item_gtp),
2877 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2878 : : }
2879 : :
2880 : : /**
2881 : : * Validate GTP PSC item.
2882 : : *
2883 : : * @param[in] item
2884 : : * Item specification.
2885 : : * @param[in] last_item
2886 : : * Previous validated item in the pattern items.
2887 : : * @param[in] gtp_item
2888 : : * Previous GTP item specification.
2889 : : * @param root
2890 : : * Whether action is on root table.
2891 : : * @param[out] error
2892 : : * Pointer to error structure.
2893 : : *
2894 : : * @return
2895 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2896 : : */
2897 : : static int
2898 : 0 : flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2899 : : uint64_t last_item,
2900 : : const struct rte_flow_item *gtp_item,
2901 : : bool root,
2902 : : struct rte_flow_error *error)
2903 : : {
2904 : : const struct rte_flow_item_gtp *gtp_spec;
2905 : : const struct rte_flow_item_gtp *gtp_mask;
2906 : : const struct rte_flow_item_gtp_psc *mask;
2907 : 0 : const struct rte_flow_item_gtp_psc nic_mask = {
2908 : : .hdr.type = 0xF,
2909 : : .hdr.qfi = 0x3F,
2910 : : };
2911 : :
2912 [ # # # # ]: 0 : if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2913 : 0 : return rte_flow_error_set
2914 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 : : "GTP PSC item must be preceded with GTP item");
2916 : 0 : gtp_spec = gtp_item->spec;
2917 [ # # ]: 0 : gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2918 : : /* GTP spec and E flag is requested to match zero. */
2919 [ # # ]: 0 : if (gtp_spec &&
2920 : 0 : (gtp_mask->hdr.gtp_hdr_info &
2921 [ # # ]: 0 : ~gtp_spec->hdr.gtp_hdr_info & MLX5_GTP_EXT_HEADER_FLAG))
2922 : 0 : return rte_flow_error_set
2923 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2924 : : "GTP E flag must be 1 to match GTP PSC");
2925 : : /* Check the flow is not created in group zero. */
2926 [ # # ]: 0 : if (root)
2927 : 0 : return rte_flow_error_set
2928 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2929 : : "GTP PSC is not supported for group 0");
2930 : : /* GTP spec is here and E flag is requested to match zero. */
2931 [ # # ]: 0 : if (!item->spec)
2932 : : return 0;
2933 [ # # ]: 0 : mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2934 : 0 : return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2935 : : (const uint8_t *)&nic_mask,
2936 : : sizeof(struct rte_flow_item_gtp_psc),
2937 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2938 : : }
2939 : :
2940 : : /**
2941 : : * Validate IPV4 item.
2942 : : * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2943 : : * add specific validation of fragment_offset field,
2944 : : *
2945 : : * @param[in] item
2946 : : * Item specification.
2947 : : * @param[in] item_flags
2948 : : * Bit-fields that holds the items detected until now.
2949 : : * @param[out] error
2950 : : * Pointer to error structure.
2951 : : *
2952 : : * @return
2953 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2954 : : */
2955 : : static int
2956 : 0 : flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2957 : : const struct rte_flow_item *item,
2958 : : uint64_t item_flags, uint64_t last_item,
2959 : : uint16_t ether_type, struct rte_flow_error *error)
2960 : : {
2961 : : int ret;
2962 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2963 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
2964 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
2965 : 0 : const struct rte_flow_item_ipv4 *last = item->last;
2966 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
2967 : : rte_be16_t fragment_offset_spec = 0;
2968 : : rte_be16_t fragment_offset_last = 0;
2969 : 0 : struct rte_flow_item_ipv4 nic_ipv4_mask = {
2970 : : .hdr = {
2971 : : .src_addr = RTE_BE32(0xffffffff),
2972 : : .dst_addr = RTE_BE32(0xffffffff),
2973 : : .type_of_service = 0xff,
2974 : : .fragment_offset = RTE_BE16(0xffff),
2975 : : .next_proto_id = 0xff,
2976 : : .time_to_live = 0xff,
2977 : : },
2978 : : };
2979 : :
2980 [ # # # # ]: 0 : if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2981 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2982 : : bool ihl_cap = !tunnel ?
2983 [ # # ]: 0 : attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
2984 [ # # ]: 0 : if (!ihl_cap)
2985 : 0 : return rte_flow_error_set(error, ENOTSUP,
2986 : : RTE_FLOW_ERROR_TYPE_ITEM,
2987 : : item,
2988 : : "IPV4 ihl offload not supported");
2989 : 0 : nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2990 : : }
2991 : 0 : ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2992 : : ether_type, &nic_ipv4_mask,
2993 : : MLX5_ITEM_RANGE_ACCEPTED, error);
2994 [ # # ]: 0 : if (ret < 0)
2995 : : return ret;
2996 [ # # ]: 0 : if (spec && mask)
2997 : 0 : fragment_offset_spec = spec->hdr.fragment_offset &
2998 : 0 : mask->hdr.fragment_offset;
2999 [ # # ]: 0 : if (!fragment_offset_spec)
3000 : : return 0;
3001 : : /*
3002 : : * spec and mask are valid, enforce using full mask to make sure the
3003 : : * complete value is used correctly.
3004 : : */
3005 [ # # ]: 0 : if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3006 : : != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3007 : 0 : return rte_flow_error_set(error, EINVAL,
3008 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3009 : : item, "must use full mask for"
3010 : : " fragment_offset");
3011 : : /*
3012 : : * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
3013 : : * indicating this is 1st fragment of fragmented packet.
3014 : : * This is not yet supported in MLX5, return appropriate error message.
3015 : : */
3016 [ # # ]: 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
3017 : 0 : return rte_flow_error_set(error, ENOTSUP,
3018 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3019 : : "match on first fragment not "
3020 : : "supported");
3021 [ # # ]: 0 : if (fragment_offset_spec && !last)
3022 : 0 : return rte_flow_error_set(error, ENOTSUP,
3023 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3024 : : "specified value not supported");
3025 : : /* spec and last are valid, validate the specified range. */
3026 : 0 : fragment_offset_last = last->hdr.fragment_offset &
3027 : : mask->hdr.fragment_offset;
3028 : : /*
3029 : : * Match on fragment_offset spec 0x2001 and last 0x3fff
3030 : : * means MF is 1 and frag-offset is > 0.
3031 : : * This packet is fragment 2nd and onward, excluding last.
3032 : : * This is not yet supported in MLX5, return appropriate
3033 : : * error message.
3034 : : */
3035 : 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
3036 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3037 : 0 : return rte_flow_error_set(error, ENOTSUP,
3038 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3039 : : last, "match on following "
3040 : : "fragments not supported");
3041 : : /*
3042 : : * Match on fragment_offset spec 0x0001 and last 0x1fff
3043 : : * means MF is 0 and frag-offset is > 0.
3044 : : * This packet is last fragment of fragmented packet.
3045 : : * This is not yet supported in MLX5, return appropriate
3046 : : * error message.
3047 : : */
3048 : 0 : if (fragment_offset_spec == RTE_BE16(1) &&
3049 [ # # ]: 0 : fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
3050 : 0 : return rte_flow_error_set(error, ENOTSUP,
3051 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3052 : : last, "match on last "
3053 : : "fragment not supported");
3054 : : /*
3055 : : * Match on fragment_offset spec 0x0001 and last 0x3fff
3056 : : * means MF and/or frag-offset is not 0.
3057 : : * This is a fragmented packet.
3058 : : * Other range values are invalid and rejected.
3059 : : */
3060 : 0 : if (!(fragment_offset_spec == RTE_BE16(1) &&
3061 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
3062 : 0 : return rte_flow_error_set(error, ENOTSUP,
3063 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3064 : : "specified range not supported");
3065 : : return 0;
3066 : : }
3067 : :
3068 : : /**
3069 : : * Validate IPV6 fragment extension item.
3070 : : *
3071 : : * @param[in] item
3072 : : * Item specification.
3073 : : * @param[in] item_flags
3074 : : * Bit-fields that holds the items detected until now.
3075 : : * @param[out] error
3076 : : * Pointer to error structure.
3077 : : *
3078 : : * @return
3079 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3080 : : */
3081 : : static int
3082 : 0 : flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
3083 : : uint64_t item_flags,
3084 : : struct rte_flow_error *error)
3085 : : {
3086 : 0 : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
3087 : 0 : const struct rte_flow_item_ipv6_frag_ext *last = item->last;
3088 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
3089 : : rte_be16_t frag_data_spec = 0;
3090 : : rte_be16_t frag_data_last = 0;
3091 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3092 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3093 : : MLX5_FLOW_LAYER_OUTER_L4;
3094 : : int ret = 0;
3095 : 0 : struct rte_flow_item_ipv6_frag_ext nic_mask = {
3096 : : .hdr = {
3097 : : .next_header = 0xff,
3098 : : .frag_data = RTE_BE16(0xffff),
3099 : : },
3100 : : };
3101 : :
3102 [ # # ]: 0 : if (item_flags & l4m)
3103 : 0 : return rte_flow_error_set(error, EINVAL,
3104 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3105 : : "ipv6 fragment extension item cannot "
3106 : : "follow L4 item.");
3107 [ # # # # : 0 : if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
3108 [ # # ]: 0 : (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
3109 : 0 : return rte_flow_error_set(error, EINVAL,
3110 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3111 : : "ipv6 fragment extension item must "
3112 : : "follow ipv6 item");
3113 [ # # ]: 0 : if (spec && mask)
3114 : 0 : frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
3115 [ # # ]: 0 : if (!frag_data_spec)
3116 : : return 0;
3117 : : /*
3118 : : * spec and mask are valid, enforce using full mask to make sure the
3119 : : * complete value is used correctly.
3120 : : */
3121 [ # # ]: 0 : if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
3122 : : RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3123 : 0 : return rte_flow_error_set(error, EINVAL,
3124 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3125 : : item, "must use full mask for"
3126 : : " frag_data");
3127 : : /*
3128 : : * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
3129 : : * This is 1st fragment of fragmented packet.
3130 : : */
3131 [ # # ]: 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
3132 : 0 : return rte_flow_error_set(error, ENOTSUP,
3133 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3134 : : "match on first fragment not "
3135 : : "supported");
3136 [ # # ]: 0 : if (frag_data_spec && !last)
3137 : 0 : return rte_flow_error_set(error, EINVAL,
3138 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3139 : : "specified value not supported");
3140 : 0 : ret = mlx5_flow_item_acceptable
3141 : : (item, (const uint8_t *)mask,
3142 : : (const uint8_t *)&nic_mask,
3143 : : sizeof(struct rte_flow_item_ipv6_frag_ext),
3144 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3145 [ # # ]: 0 : if (ret)
3146 : : return ret;
3147 : : /* spec and last are valid, validate the specified range. */
3148 : 0 : frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
3149 : : /*
3150 : : * Match on frag_data spec 0x0009 and last 0xfff9
3151 : : * means M is 1 and frag-offset is > 0.
3152 : : * This packet is fragment 2nd and onward, excluding last.
3153 : : * This is not yet supported in MLX5, return appropriate
3154 : : * error message.
3155 : : */
3156 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
3157 : 0 : RTE_IPV6_EHDR_MF_MASK) &&
3158 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3159 : 0 : return rte_flow_error_set(error, ENOTSUP,
3160 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3161 : : last, "match on following "
3162 : : "fragments not supported");
3163 : : /*
3164 : : * Match on frag_data spec 0x0008 and last 0xfff8
3165 : : * means M is 0 and frag-offset is > 0.
3166 : : * This packet is last fragment of fragmented packet.
3167 : : * This is not yet supported in MLX5, return appropriate
3168 : : * error message.
3169 : : */
3170 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
3171 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
3172 : 0 : return rte_flow_error_set(error, ENOTSUP,
3173 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3174 : : last, "match on last "
3175 : : "fragment not supported");
3176 : : /* Other range values are invalid and rejected. */
3177 : 0 : return rte_flow_error_set(error, EINVAL,
3178 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3179 : : "specified range not supported");
3180 : : }
3181 : :
3182 : : /*
3183 : : * Validate ASO CT item.
3184 : : *
3185 : : * @param[in] dev
3186 : : * Pointer to the rte_eth_dev structure.
3187 : : * @param[in] item
3188 : : * Item specification.
3189 : : * @param[in] item_flags
3190 : : * Pointer to bit-fields that holds the items detected until now.
3191 : : * @param[out] error
3192 : : * Pointer to error structure.
3193 : : *
3194 : : * @return
3195 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3196 : : */
3197 : : static int
3198 : 0 : flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
3199 : : const struct rte_flow_item *item,
3200 : : uint64_t *item_flags,
3201 : : struct rte_flow_error *error)
3202 : : {
3203 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
3204 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
3205 : : RTE_SET_USED(dev);
3206 : : uint32_t flags;
3207 : :
3208 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
3209 : 0 : return rte_flow_error_set(error, EINVAL,
3210 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3211 : : "Only one CT is supported");
3212 [ # # ]: 0 : if (!mask)
3213 : : mask = &rte_flow_item_conntrack_mask;
3214 : 0 : flags = spec->flags & mask->flags;
3215 [ # # ]: 0 : if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
3216 : : ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
3217 [ # # ]: 0 : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
3218 : : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
3219 : 0 : return rte_flow_error_set(error, EINVAL,
3220 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3221 : : "Conflict status bits");
3222 : : /* State change also needs to be considered. */
3223 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3224 : 0 : return 0;
3225 : : }
3226 : :
3227 : : /**
3228 : : * Validate the pop VLAN action.
3229 : : *
3230 : : * @param[in] dev
3231 : : * Pointer to the rte_eth_dev structure.
3232 : : * @param[in] action_flags
3233 : : * Holds the actions detected until now.
3234 : : * @param[in] action
3235 : : * Pointer to the pop vlan action.
3236 : : * @param[in] item_flags
3237 : : * The items found in this flow rule.
3238 : : * @param[in] attr
3239 : : * Pointer to flow attributes.
3240 : : * @param[out] error
3241 : : * Pointer to error structure.
3242 : : *
3243 : : * @return
3244 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3245 : : */
3246 : : static int
3247 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3248 : : uint64_t action_flags,
3249 : : const struct rte_flow_action *action,
3250 : : uint64_t item_flags,
3251 : : const struct rte_flow_attr *attr,
3252 : : struct rte_flow_error *error)
3253 : : {
3254 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3255 : :
3256 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3257 : 0 : return rte_flow_error_set(error, ENOTSUP,
3258 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3259 : : NULL,
3260 : : "pop vlan action is not supported");
3261 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3262 : 0 : return rte_flow_error_set(error, ENOTSUP,
3263 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3264 : : "no support for multiple VLAN "
3265 : : "actions");
3266 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3267 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3268 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3269 : 0 : return rte_flow_error_set(error, ENOTSUP,
3270 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3271 : : NULL,
3272 : : "cannot pop vlan after decap without "
3273 : : "match on inner vlan in the flow");
3274 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3275 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3276 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3277 : 0 : return rte_flow_error_set(error, ENOTSUP,
3278 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3279 : : NULL,
3280 : : "cannot pop vlan without a "
3281 : : "match on (outer) vlan in the flow");
3282 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3283 : 0 : return rte_flow_error_set(error, EINVAL,
3284 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3285 : : "wrong action order, port_id should "
3286 : : "be after pop VLAN action");
3287 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3288 : 0 : return rte_flow_error_set(error, ENOTSUP,
3289 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3290 : : "pop vlan action for VF representor "
3291 : : "not supported on NIC table");
3292 : : return 0;
3293 : : }
3294 : :
3295 : : /**
3296 : : * Get VLAN default info from vlan match info.
3297 : : *
3298 : : * @param[in] items
3299 : : * the list of item specifications.
3300 : : * @param[out] vlan
3301 : : * pointer VLAN info to fill to.
3302 : : *
3303 : : * @return
3304 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3305 : : */
3306 : : static void
3307 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3308 : : struct rte_vlan_hdr *vlan)
3309 : : {
3310 : 0 : const struct rte_flow_item_vlan nic_mask = {
3311 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3312 : : MLX5DV_FLOW_VLAN_VID_MASK),
3313 : : .hdr.eth_proto = RTE_BE16(0xffff),
3314 : : };
3315 : :
3316 [ # # ]: 0 : if (items == NULL)
3317 : 0 : return;
3318 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3319 : 0 : int type = items->type;
3320 : :
3321 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3322 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3323 : : break;
3324 : : }
3325 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3326 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3327 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3328 : :
3329 : : /* If VLAN item in pattern doesn't contain data, return here. */
3330 [ # # ]: 0 : if (!vlan_v)
3331 : : return;
3332 [ # # ]: 0 : if (!vlan_m)
3333 : : vlan_m = &nic_mask;
3334 : : /* Only full match values are accepted */
3335 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3336 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3337 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3338 : 0 : vlan->vlan_tci |=
3339 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3340 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3341 : : }
3342 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3343 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3344 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3345 : 0 : vlan->vlan_tci |=
3346 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3347 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3348 : : }
3349 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3350 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3351 : : vlan_m->hdr.eth_proto);
3352 : : }
3353 : : }
3354 : :
3355 : : /**
3356 : : * Validate the push VLAN action.
3357 : : *
3358 : : * @param[in] dev
3359 : : * Pointer to the rte_eth_dev structure.
3360 : : * @param[in] action_flags
3361 : : * Holds the actions detected until now.
3362 : : * @param[in] item_flags
3363 : : * The items found in this flow rule.
3364 : : * @param[in] action
3365 : : * Pointer to the action structure.
3366 : : * @param[in] attr
3367 : : * Pointer to flow attributes
3368 : : * @param[out] error
3369 : : * Pointer to error structure.
3370 : : *
3371 : : * @return
3372 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3373 : : */
3374 : : static int
3375 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3376 : : uint64_t action_flags,
3377 : : const struct rte_flow_item_vlan *vlan_m,
3378 : : const struct rte_flow_action *action,
3379 : : const struct rte_flow_attr *attr,
3380 : : struct rte_flow_error *error)
3381 : : {
3382 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3383 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3384 : :
3385 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3386 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3387 : 0 : return rte_flow_error_set(error, EINVAL,
3388 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3389 : : "invalid vlan ethertype");
3390 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3391 : 0 : return rte_flow_error_set(error, EINVAL,
3392 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3393 : : "wrong action order, port_id should "
3394 : : "be after push VLAN");
3395 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3396 : 0 : return rte_flow_error_set(error, ENOTSUP,
3397 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3398 : : "push vlan action for VF representor "
3399 : : "not supported on NIC table");
3400 [ # # ]: 0 : if (vlan_m &&
3401 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3402 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3403 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3404 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3405 : 0 : !(mlx5_flow_find_action
3406 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3407 : 0 : return rte_flow_error_set(error, EINVAL,
3408 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3409 : : "not full match mask on VLAN PCP and "
3410 : : "there is no of_set_vlan_pcp action, "
3411 : : "push VLAN action cannot figure out "
3412 : : "PCP value");
3413 [ # # ]: 0 : if (vlan_m &&
3414 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3415 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3416 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3417 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3418 : 0 : !(mlx5_flow_find_action
3419 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3420 : 0 : return rte_flow_error_set(error, EINVAL,
3421 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3422 : : "not full match mask on VLAN VID and "
3423 : : "there is no of_set_vlan_vid action, "
3424 : : "push VLAN action cannot figure out "
3425 : : "VID value");
3426 : : (void)attr;
3427 : : return 0;
3428 : : }
3429 : :
3430 : : /**
3431 : : * Validate the set VLAN PCP.
3432 : : *
3433 : : * @param[in] action_flags
3434 : : * Holds the actions detected until now.
3435 : : * @param[in] actions
3436 : : * Pointer to the list of actions remaining in the flow rule.
3437 : : * @param[out] error
3438 : : * Pointer to error structure.
3439 : : *
3440 : : * @return
3441 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3442 : : */
3443 : : static int
3444 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3445 : : const struct rte_flow_action actions[],
3446 : : struct rte_flow_error *error)
3447 : : {
3448 : : const struct rte_flow_action *action = actions;
3449 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3450 : :
3451 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3452 : 0 : return rte_flow_error_set(error, EINVAL,
3453 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3454 : : "VLAN PCP value is too big");
3455 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3456 : 0 : return rte_flow_error_set(error, ENOTSUP,
3457 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3458 : : "set VLAN PCP action must follow "
3459 : : "the push VLAN action");
3460 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3461 : 0 : return rte_flow_error_set(error, ENOTSUP,
3462 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3463 : : "Multiple VLAN PCP modification are "
3464 : : "not supported");
3465 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3466 : 0 : return rte_flow_error_set(error, EINVAL,
3467 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3468 : : "wrong action order, port_id should "
3469 : : "be after set VLAN PCP");
3470 : : return 0;
3471 : : }
3472 : :
3473 : : /**
3474 : : * Validate the set VLAN VID.
3475 : : *
3476 : : * @param[in] item_flags
3477 : : * Holds the items detected in this rule.
3478 : : * @param[in] action_flags
3479 : : * Holds the actions detected until now.
3480 : : * @param[in] actions
3481 : : * Pointer to the list of actions remaining in the flow rule.
3482 : : * @param[out] error
3483 : : * Pointer to error structure.
3484 : : *
3485 : : * @return
3486 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3487 : : */
3488 : : static int
3489 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3490 : : uint64_t action_flags,
3491 : : const struct rte_flow_action actions[],
3492 : : struct rte_flow_error *error)
3493 : : {
3494 : : const struct rte_flow_action *action = actions;
3495 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3496 : :
3497 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3498 : 0 : return rte_flow_error_set(error, EINVAL,
3499 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3500 : : "VLAN VID value is too big");
3501 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3502 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3503 : 0 : return rte_flow_error_set(error, ENOTSUP,
3504 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3505 : : "set VLAN VID action must follow push"
3506 : : " VLAN action or match on VLAN item");
3507 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3508 : 0 : return rte_flow_error_set(error, ENOTSUP,
3509 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3510 : : "Multiple VLAN VID modifications are "
3511 : : "not supported");
3512 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3513 : 0 : return rte_flow_error_set(error, EINVAL,
3514 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3515 : : "wrong action order, port_id should "
3516 : : "be after set VLAN VID");
3517 : : return 0;
3518 : : }
3519 : :
3520 : : /*
3521 : : * Validate the FLAG action.
3522 : : *
3523 : : * @param[in] dev
3524 : : * Pointer to the rte_eth_dev structure.
3525 : : * @param[in] action_flags
3526 : : * Holds the actions detected until now.
3527 : : * @param[in] attr
3528 : : * Pointer to flow attributes
3529 : : * @param[out] error
3530 : : * Pointer to error structure.
3531 : : *
3532 : : * @return
3533 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3534 : : */
3535 : : static int
3536 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3537 : : uint64_t action_flags,
3538 : : const struct rte_flow_attr *attr,
3539 : : struct rte_flow_error *error)
3540 : : {
3541 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3542 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3543 : : int ret;
3544 : :
3545 : : /* Fall back if no extended metadata register support. */
3546 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3547 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3548 : : error);
3549 : : /* Extensive metadata mode requires registers. */
3550 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3551 : 0 : return rte_flow_error_set(error, ENOTSUP,
3552 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3553 : : "no metadata registers "
3554 : : "to support flag action");
3555 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3556 : 0 : return rte_flow_error_set(error, ENOTSUP,
3557 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3558 : : "extended metadata register"
3559 : : " isn't available");
3560 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3561 [ # # ]: 0 : if (ret < 0)
3562 : : return ret;
3563 : : MLX5_ASSERT(ret > 0);
3564 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3565 : 0 : return rte_flow_error_set(error, EINVAL,
3566 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3567 : : "can't mark and flag in same flow");
3568 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3569 : 0 : return rte_flow_error_set(error, EINVAL,
3570 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3571 : : "can't have 2 flag"
3572 : : " actions in same flow");
3573 : : return 0;
3574 : : }
3575 : :
3576 : : /**
3577 : : * Validate MARK action.
3578 : : *
3579 : : * @param[in] dev
3580 : : * Pointer to the rte_eth_dev structure.
3581 : : * @param[in] action
3582 : : * Pointer to action.
3583 : : * @param[in] action_flags
3584 : : * Holds the actions detected until now.
3585 : : * @param[in] attr
3586 : : * Pointer to flow attributes
3587 : : * @param[out] error
3588 : : * Pointer to error structure.
3589 : : *
3590 : : * @return
3591 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3592 : : */
3593 : : static int
3594 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3595 : : const struct rte_flow_action *action,
3596 : : uint64_t action_flags,
3597 : : const struct rte_flow_attr *attr,
3598 : : struct rte_flow_error *error)
3599 : : {
3600 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3601 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3602 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3603 : : int ret;
3604 : :
3605 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3606 : 0 : return rte_flow_error_set(error, ENOTSUP,
3607 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3608 : : "no mark action "
3609 : : "if tunnel offload active");
3610 : : /* Fall back if no extended metadata register support. */
3611 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3612 : 0 : return mlx5_flow_validate_action_mark(action, action_flags,
3613 : : attr, error);
3614 : : /* Extensive metadata mode requires registers. */
3615 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3616 : 0 : return rte_flow_error_set(error, ENOTSUP,
3617 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3618 : : "no metadata registers "
3619 : : "to support mark action");
3620 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3621 : 0 : return rte_flow_error_set(error, ENOTSUP,
3622 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3623 : : "extended metadata register"
3624 : : " isn't available");
3625 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3626 [ # # ]: 0 : if (ret < 0)
3627 : : return ret;
3628 : : MLX5_ASSERT(ret > 0);
3629 [ # # ]: 0 : if (!mark)
3630 : 0 : return rte_flow_error_set(error, EINVAL,
3631 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3632 : : "configuration cannot be null");
3633 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3634 : 0 : return rte_flow_error_set(error, EINVAL,
3635 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3636 : 0 : &mark->id,
3637 : : "mark id exceeds the limit");
3638 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3639 : 0 : return rte_flow_error_set(error, EINVAL,
3640 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3641 : : "can't flag and mark in same flow");
3642 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3643 : 0 : return rte_flow_error_set(error, EINVAL,
3644 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3645 : : "can't have 2 mark actions in same"
3646 : : " flow");
3647 : : return 0;
3648 : : }
3649 : :
3650 : : /**
3651 : : * Validate SET_META action.
3652 : : *
3653 : : * @param[in] dev
3654 : : * Pointer to the rte_eth_dev structure.
3655 : : * @param[in] action
3656 : : * Pointer to the action structure.
3657 : : * @param[in] action_flags
3658 : : * Holds the actions detected until now.
3659 : : * @param[in] attr
3660 : : * Pointer to flow attributes
3661 : : * @param[out] error
3662 : : * Pointer to error structure.
3663 : : *
3664 : : * @return
3665 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3666 : : */
3667 : : static int
3668 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3669 : : const struct rte_flow_action *action,
3670 : : uint64_t action_flags __rte_unused,
3671 : : const struct rte_flow_attr *attr,
3672 : : struct rte_flow_error *error)
3673 : : {
3674 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3675 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3676 : : const struct rte_flow_action_set_meta *conf;
3677 : : uint32_t nic_mask = UINT32_MAX;
3678 : : int reg;
3679 : :
3680 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3681 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3682 : 0 : return rte_flow_error_set(error, ENOTSUP,
3683 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3684 : : "extended metadata register"
3685 : : " isn't supported");
3686 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3687 [ # # ]: 0 : if (reg < 0)
3688 : : return reg;
3689 [ # # ]: 0 : if (reg == REG_NON)
3690 : 0 : return rte_flow_error_set(error, ENOTSUP,
3691 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3692 : : "unavailable extended metadata register");
3693 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3694 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3695 : :
3696 : 0 : nic_mask = priv->sh->dv_meta_mask;
3697 : : }
3698 [ # # ]: 0 : if (!(action->conf))
3699 : 0 : return rte_flow_error_set(error, EINVAL,
3700 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3701 : : "configuration cannot be null");
3702 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3703 [ # # ]: 0 : if (!conf->mask)
3704 : 0 : return rte_flow_error_set(error, EINVAL,
3705 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3706 : : "zero mask doesn't have any effect");
3707 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3708 : 0 : return rte_flow_error_set(error, EINVAL,
3709 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3710 : : "meta data must be within reg C0");
3711 : : return 0;
3712 : : }
3713 : :
3714 : : /**
3715 : : * Validate SET_TAG action.
3716 : : *
3717 : : * @param[in] dev
3718 : : * Pointer to the rte_eth_dev structure.
3719 : : * @param[in] action
3720 : : * Pointer to the action structure.
3721 : : * @param[in] action_flags
3722 : : * Holds the actions detected until now.
3723 : : * @param[in] attr
3724 : : * Pointer to flow attributes
3725 : : * @param[out] error
3726 : : * Pointer to error structure.
3727 : : *
3728 : : * @return
3729 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3730 : : */
3731 : : static int
3732 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3733 : : const struct rte_flow_action *action,
3734 : : uint64_t action_flags,
3735 : : const struct rte_flow_attr *attr,
3736 : : struct rte_flow_error *error)
3737 : : {
3738 : : const struct rte_flow_action_set_tag *conf;
3739 : : const uint64_t terminal_action_flags =
3740 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3741 : : MLX5_FLOW_ACTION_RSS;
3742 : : int ret;
3743 : :
3744 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3745 : 0 : return rte_flow_error_set(error, ENOTSUP,
3746 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3747 : : "extensive metadata register"
3748 : : " isn't supported");
3749 [ # # ]: 0 : if (!(action->conf))
3750 : 0 : return rte_flow_error_set(error, EINVAL,
3751 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3752 : : "configuration cannot be null");
3753 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3754 [ # # ]: 0 : if (!conf->mask)
3755 : 0 : return rte_flow_error_set(error, EINVAL,
3756 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3757 : : "zero mask doesn't have any effect");
3758 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3759 [ # # ]: 0 : if (ret < 0)
3760 : : return ret;
3761 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3762 : 0 : return rte_flow_error_set(error, EINVAL,
3763 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3764 : : "set_tag has no effect"
3765 : : " with terminal actions");
3766 : : return 0;
3767 : : }
3768 : :
3769 : : /**
3770 : : * Indicates whether ASO aging is supported.
3771 : : *
3772 : : * @param[in] priv
3773 : : * Pointer to device private context structure.
3774 : : * @param[in] root
3775 : : * Whether action is on root table.
3776 : : *
3777 : : * @return
3778 : : * True when ASO aging is supported, false otherwise.
3779 : : */
3780 : : static inline bool
3781 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3782 : : {
3783 : : MLX5_ASSERT(priv);
3784 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3785 : : }
3786 : :
3787 : : /**
3788 : : * Validate count action.
3789 : : *
3790 : : * @param[in] dev
3791 : : * Pointer to rte_eth_dev structure.
3792 : : * @param[in] shared
3793 : : * Indicator if action is shared.
3794 : : * @param[in] action_flags
3795 : : * Holds the actions detected until now.
3796 : : * @param[in] root
3797 : : * Whether action is on root table.
3798 : : * @param[out] error
3799 : : * Pointer to error structure.
3800 : : *
3801 : : * @return
3802 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3803 : : */
3804 : : static int
3805 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3806 : : uint64_t action_flags,
3807 : : bool root,
3808 : : struct rte_flow_error *error)
3809 : : {
3810 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3811 : :
3812 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3813 : 0 : goto notsup_err;
3814 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3815 : 0 : return rte_flow_error_set(error, EINVAL,
3816 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3817 : : "duplicate count actions set");
3818 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3819 : : !flow_hit_aso_supported(priv, root))
3820 : 0 : return rte_flow_error_set(error, EINVAL,
3821 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3822 : : "old age and indirect count combination is not supported");
3823 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3824 : : return 0;
3825 : : #endif
3826 : : notsup_err:
3827 : 0 : return rte_flow_error_set
3828 : : (error, ENOTSUP,
3829 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3830 : : NULL,
3831 : : "count action not supported");
3832 : : }
3833 : :
3834 : : /**
3835 : : * Validate the L2 encap action.
3836 : : *
3837 : : * @param[in] dev
3838 : : * Pointer to the rte_eth_dev structure.
3839 : : * @param[in] action_flags
3840 : : * Holds the actions detected until now.
3841 : : * @param[in] action
3842 : : * Pointer to the action structure.
3843 : : * @param[in] attr
3844 : : * Pointer to flow attributes.
3845 : : * @param[out] error
3846 : : * Pointer to error structure.
3847 : : *
3848 : : * @return
3849 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3850 : : */
3851 : : static int
3852 : 0 : flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3853 : : uint64_t action_flags,
3854 : : const struct rte_flow_action *action,
3855 : : const struct rte_flow_attr *attr,
3856 : : struct rte_flow_error *error)
3857 : : {
3858 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3859 : :
3860 [ # # ]: 0 : if (!(action->conf))
3861 : 0 : return rte_flow_error_set(error, EINVAL,
3862 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3863 : : "configuration cannot be null");
3864 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3865 : 0 : return rte_flow_error_set(error, EINVAL,
3866 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3867 : : "can only have a single encap action "
3868 : : "in a flow");
3869 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3870 : 0 : return rte_flow_error_set(error, ENOTSUP,
3871 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3872 : : "encap action for VF representor "
3873 : : "not supported on NIC table");
3874 : : return 0;
3875 : : }
3876 : :
3877 : : /**
3878 : : * Validate a decap action.
3879 : : *
3880 : : * @param[in] dev
3881 : : * Pointer to the rte_eth_dev structure.
3882 : : * @param[in] action_flags
3883 : : * Holds the actions detected until now.
3884 : : * @param[in] action
3885 : : * Pointer to the action structure.
3886 : : * @param[in] item_flags
3887 : : * Holds the items detected.
3888 : : * @param[in] attr
3889 : : * Pointer to flow attributes
3890 : : * @param[out] error
3891 : : * Pointer to error structure.
3892 : : *
3893 : : * @return
3894 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3895 : : */
3896 : : static int
3897 : 0 : flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3898 : : uint64_t action_flags,
3899 : : const struct rte_flow_action *action,
3900 : : const uint64_t item_flags,
3901 : : const struct rte_flow_attr *attr,
3902 : : struct rte_flow_error *error)
3903 : : {
3904 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3905 : :
3906 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3907 [ # # ]: 0 : !priv->sh->config.decap_en)
3908 : 0 : return rte_flow_error_set(error, ENOTSUP,
3909 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3910 : : "decap is not enabled");
3911 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3912 : 0 : return rte_flow_error_set(error, ENOTSUP,
3913 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3914 [ # # ]: 0 : action_flags &
3915 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3916 : : "have a single decap action" : "decap "
3917 : : "after encap is not supported");
3918 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3919 : 0 : return rte_flow_error_set(error, EINVAL,
3920 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3921 : : "can't have decap action after"
3922 : : " modify action");
3923 [ # # ]: 0 : if (attr->egress)
3924 : 0 : return rte_flow_error_set(error, ENOTSUP,
3925 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3926 : : NULL,
3927 : : "decap action not supported for "
3928 : : "egress");
3929 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3930 : 0 : return rte_flow_error_set(error, ENOTSUP,
3931 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3932 : : "decap action for VF representor "
3933 : : "not supported on NIC table");
3934 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3935 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3936 : 0 : return rte_flow_error_set(error, ENOTSUP,
3937 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3938 : : "VXLAN item should be present for VXLAN decap");
3939 : : return 0;
3940 : : }
3941 : :
3942 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3943 : :
3944 : : /**
3945 : : * Validate the raw encap and decap actions.
3946 : : *
3947 : : * @param[in] dev
3948 : : * Pointer to the rte_eth_dev structure.
3949 : : * @param[in] decap
3950 : : * Pointer to the decap action.
3951 : : * @param[in] encap
3952 : : * Pointer to the encap action.
3953 : : * @param[in] attr
3954 : : * Pointer to flow attributes
3955 : : * @param[in/out] action_flags
3956 : : * Holds the actions detected until now.
3957 : : * @param[out] actions_n
3958 : : * pointer to the number of actions counter.
3959 : : * @param[in] action
3960 : : * Pointer to the action structure.
3961 : : * @param[in] item_flags
3962 : : * Holds the items detected.
3963 : : * @param[out] error
3964 : : * Pointer to error structure.
3965 : : *
3966 : : * @return
3967 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3968 : : */
3969 : : static int
3970 : 0 : flow_dv_validate_action_raw_encap_decap
3971 : : (struct rte_eth_dev *dev,
3972 : : const struct rte_flow_action_raw_decap *decap,
3973 : : const struct rte_flow_action_raw_encap *encap,
3974 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
3975 : : int *actions_n, const struct rte_flow_action *action,
3976 : : uint64_t item_flags, struct rte_flow_error *error)
3977 : : {
3978 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3979 : : int ret;
3980 : :
3981 [ # # # # : 0 : if (encap && (!encap->size || !encap->data))
# # ]
3982 : 0 : return rte_flow_error_set(error, EINVAL,
3983 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3984 : : "raw encap data cannot be empty");
3985 [ # # ]: 0 : if (decap && encap) {
3986 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3987 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3988 : : /* L3 encap. */
3989 : : decap = NULL;
3990 [ # # ]: 0 : else if (encap->size <=
3991 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
3992 : : decap->size >
3993 : : MLX5_ENCAPSULATION_DECISION_SIZE)
3994 : : /* L3 decap. */
3995 : : encap = NULL;
3996 [ # # ]: 0 : else if (encap->size >
3997 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
3998 : : decap->size >
3999 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4000 : : /* 2 L2 actions: encap and decap. */
4001 : : ;
4002 : : else
4003 : 0 : return rte_flow_error_set(error,
4004 : : ENOTSUP,
4005 : : RTE_FLOW_ERROR_TYPE_ACTION,
4006 : : NULL, "unsupported too small "
4007 : : "raw decap and too small raw "
4008 : : "encap combination");
4009 : : }
4010 [ # # ]: 0 : if (decap) {
4011 : 0 : ret = flow_dv_validate_action_decap(dev, *action_flags, action,
4012 : : item_flags, attr, error);
4013 [ # # ]: 0 : if (ret < 0)
4014 : : return ret;
4015 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4016 : 0 : ++(*actions_n);
4017 : : }
4018 [ # # ]: 0 : if (encap) {
4019 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4020 : 0 : return rte_flow_error_set(error, ENOTSUP,
4021 : : RTE_FLOW_ERROR_TYPE_ACTION,
4022 : : NULL,
4023 : : "small raw encap size");
4024 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4025 : 0 : return rte_flow_error_set(error, EINVAL,
4026 : : RTE_FLOW_ERROR_TYPE_ACTION,
4027 : : NULL,
4028 : : "more than one encap action");
4029 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4030 : 0 : return rte_flow_error_set
4031 : : (error, ENOTSUP,
4032 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4033 : : "encap action for VF representor "
4034 : : "not supported on NIC table");
4035 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4036 : 0 : ++(*actions_n);
4037 : : }
4038 : : return 0;
4039 : : }
4040 : :
4041 : : /*
4042 : : * Validate the ASO CT action.
4043 : : *
4044 : : * @param[in] dev
4045 : : * Pointer to the rte_eth_dev structure.
4046 : : * @param[in] action_flags
4047 : : * Holds the actions detected until now.
4048 : : * @param[in] item_flags
4049 : : * The items found in this flow rule.
4050 : : * @param root
4051 : : * Whether action is on root table.
4052 : : * @param[out] error
4053 : : * Pointer to error structure.
4054 : : *
4055 : : * @return
4056 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4057 : : */
4058 : : static int
4059 : 0 : flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4060 : : uint64_t action_flags,
4061 : : uint64_t item_flags,
4062 : : bool root,
4063 : : struct rte_flow_error *error)
4064 : : {
4065 : : RTE_SET_USED(dev);
4066 : :
4067 [ # # ]: 0 : if (root)
4068 : 0 : return rte_flow_error_set(error, ENOTSUP,
4069 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4070 : : NULL,
4071 : : "Only support non-root table");
4072 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4073 : 0 : return rte_flow_error_set(error, ENOTSUP,
4074 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4075 : : "CT cannot follow a fate action");
4076 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4077 : : (action_flags & MLX5_FLOW_ACTION_AGE))
4078 : 0 : return rte_flow_error_set(error, EINVAL,
4079 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4080 : : "Only one ASO action is supported");
4081 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4082 : 0 : return rte_flow_error_set(error, EINVAL,
4083 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4084 : : "Encap cannot exist before CT");
4085 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4086 : 0 : return rte_flow_error_set(error, EINVAL,
4087 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4088 : : "Not a outer TCP packet");
4089 : : return 0;
4090 : : }
4091 : :
4092 : : /**
4093 : : * Validate METER_COLOR item.
4094 : : *
4095 : : * @param[in] dev
4096 : : * Pointer to the rte_eth_dev structure.
4097 : : * @param[in] item
4098 : : * Item specification.
4099 : : * @param[in] attr
4100 : : * Attributes of flow that includes this item.
4101 : : * @param[out] error
4102 : : * Pointer to error structure.
4103 : : *
4104 : : * @return
4105 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4106 : : */
4107 : : static int
4108 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4109 : : const struct rte_flow_item *item,
4110 : : const struct rte_flow_attr *attr __rte_unused,
4111 : : struct rte_flow_error *error)
4112 : : {
4113 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4114 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4115 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4116 : 0 : struct rte_flow_item_meter_color nic_mask = {
4117 : : .color = RTE_COLORS
4118 : : };
4119 : : int ret;
4120 : :
4121 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4122 : 0 : return rte_flow_error_set(error, ENOTSUP,
4123 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4124 : : "meter color register"
4125 : : " isn't available");
4126 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4127 [ # # ]: 0 : if (ret < 0)
4128 : : return ret;
4129 [ # # ]: 0 : if (!spec)
4130 : 0 : return rte_flow_error_set(error, EINVAL,
4131 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4132 : 0 : item->spec,
4133 : : "data cannot be empty");
4134 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4135 : 0 : return rte_flow_error_set(error, EINVAL,
4136 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4137 : 0 : &spec->color,
4138 : : "meter color is invalid");
4139 [ # # ]: 0 : if (!mask)
4140 : : mask = &rte_flow_item_meter_color_mask;
4141 [ # # ]: 0 : if (!mask->color)
4142 : 0 : return rte_flow_error_set(error, EINVAL,
4143 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4144 : : "mask cannot be zero");
4145 : :
4146 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
4147 : : (const uint8_t *)&nic_mask,
4148 : : sizeof(struct rte_flow_item_meter_color),
4149 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4150 : : if (ret < 0)
4151 : : return ret;
4152 : : return 0;
4153 : : }
4154 : :
4155 : : /**
4156 : : * Validate aggregated affinity item.
4157 : : *
4158 : : * @param[in] dev
4159 : : * Pointer to the rte_eth_dev structure.
4160 : : * @param[in] item
4161 : : * Item specification.
4162 : : * @param[in] attr
4163 : : * Attributes of flow that includes this item.
4164 : : * @param[out] error
4165 : : * Pointer to error structure.
4166 : : *
4167 : : * @return
4168 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4169 : : */
4170 : : static int
4171 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4172 : : const struct rte_flow_item *item,
4173 : : const struct rte_flow_attr *attr,
4174 : : struct rte_flow_error *error)
4175 : : {
4176 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4177 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4178 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4179 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4180 : : .affinity = UINT8_MAX
4181 : : };
4182 : : int ret;
4183 : :
4184 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4185 : 0 : return rte_flow_error_set(error, EINVAL,
4186 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4187 : : "Unsupported aggregated affinity with Older FW");
4188 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4189 [ # # ]: 0 : attr->egress || attr->group)
4190 : 0 : return rte_flow_error_set(error, ENOTSUP,
4191 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4192 : : item->spec,
4193 : : "aggregated affinity is not supported with egress or FDB on non root table");
4194 [ # # ]: 0 : if (!spec)
4195 : 0 : return rte_flow_error_set(error, EINVAL,
4196 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4197 : : item->spec,
4198 : : "data cannot be empty");
4199 [ # # ]: 0 : if (spec->affinity == 0)
4200 : 0 : return rte_flow_error_set(error, ENOTSUP,
4201 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4202 : : item->spec,
4203 : : "zero affinity number not supported");
4204 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4205 : 0 : return rte_flow_error_set(error, ENOTSUP,
4206 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4207 : : item->spec,
4208 : : "exceed max affinity number in lag ports");
4209 [ # # ]: 0 : if (!mask)
4210 : : mask = &rte_flow_item_aggr_affinity_mask;
4211 [ # # ]: 0 : if (!mask->affinity)
4212 : 0 : return rte_flow_error_set(error, EINVAL,
4213 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4214 : : "mask cannot be zero");
4215 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
4216 : : (const uint8_t *)&nic_mask,
4217 : : sizeof(struct rte_flow_item_aggr_affinity),
4218 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4219 : : if (ret < 0)
4220 : : return ret;
4221 : : return 0;
4222 : : }
4223 : :
4224 : : int
4225 : 0 : flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
4226 : : struct mlx5_list_entry *entry, void *cb_ctx)
4227 : : {
4228 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4229 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4230 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4231 : :
4232 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4233 : : entry);
4234 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4235 : 0 : resource->ft_type == ctx_resource->ft_type &&
4236 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4237 [ # # ]: 0 : resource->size == ctx_resource->size &&
4238 : 0 : !memcmp((const void *)resource->buf,
4239 [ # # ]: 0 : (const void *)ctx_resource->buf,
4240 : : resource->size))
4241 : 0 : return 0;
4242 : : return -1;
4243 : : }
4244 : :
4245 : : struct mlx5_list_entry *
4246 : 0 : flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4247 : : {
4248 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4249 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4250 : : struct mlx5dv_dr_domain *domain;
4251 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4252 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4253 : : uint32_t idx;
4254 : : int ret;
4255 : :
4256 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4257 : 0 : domain = sh->fdb_domain;
4258 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4259 : 0 : domain = sh->rx_domain;
4260 : : else
4261 : 0 : domain = sh->tx_domain;
4262 : : /* Register new encap/decap resource. */
4263 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4264 [ # # ]: 0 : if (!resource) {
4265 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4266 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4267 : : "cannot allocate resource memory");
4268 : 0 : return NULL;
4269 : : }
4270 : 0 : *resource = *ctx_resource;
4271 : 0 : resource->idx = idx;
4272 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4273 : : domain, resource,
4274 : : &resource->action);
4275 : : if (ret) {
4276 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4277 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4278 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4279 : : NULL, "cannot create action");
4280 : 0 : return NULL;
4281 : : }
4282 : :
4283 : 0 : return &resource->entry;
4284 : : }
4285 : :
4286 : : struct mlx5_list_entry *
4287 : 0 : flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4288 : : void *cb_ctx)
4289 : : {
4290 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4291 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4292 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4293 : : uint32_t idx;
4294 : :
4295 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4296 : : &idx);
4297 [ # # ]: 0 : if (!cache_resource) {
4298 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4299 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4300 : : "cannot allocate resource memory");
4301 : 0 : return NULL;
4302 : : }
4303 : : memcpy(cache_resource, oentry, sizeof(*cache_resource));
4304 : 0 : cache_resource->idx = idx;
4305 : 0 : return &cache_resource->entry;
4306 : : }
4307 : :
4308 : : void
4309 : 0 : flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4310 : : {
4311 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4312 : : struct mlx5_flow_dv_encap_decap_resource *res =
4313 : : container_of(entry, typeof(*res), entry);
4314 : :
4315 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4316 : 0 : }
4317 : :
4318 : : /**
4319 : : * Find existing encap/decap resource or create and register a new one.
4320 : : *
4321 : : * @param[in, out] dev
4322 : : * Pointer to rte_eth_dev structure.
4323 : : * @param[in, out] resource
4324 : : * Pointer to encap/decap resource.
4325 : : * @parm[in, out] dev_flow
4326 : : * Pointer to the dev_flow.
4327 : : * @param[out] error
4328 : : * pointer to error structure.
4329 : : *
4330 : : * @return
4331 : : * 0 on success otherwise -errno and errno is set.
4332 : : */
4333 : : static int
4334 : 0 : flow_dv_encap_decap_resource_register
4335 : : (struct rte_eth_dev *dev,
4336 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4337 : : struct mlx5_flow *dev_flow,
4338 : : struct rte_flow_error *error)
4339 : : {
4340 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4341 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4342 : : struct mlx5_list_entry *entry;
4343 : : union {
4344 : : struct {
4345 : : uint32_t ft_type:8;
4346 : : uint32_t refmt_type:8;
4347 : : /*
4348 : : * Header reformat actions can be shared between
4349 : : * non-root tables. One bit to indicate non-root
4350 : : * table or not.
4351 : : */
4352 : : uint32_t is_root:1;
4353 : : uint32_t reserve:15;
4354 : : };
4355 : : uint32_t v32;
4356 : 0 : } encap_decap_key = {
4357 : : {
4358 : 0 : .ft_type = resource->ft_type,
4359 : 0 : .refmt_type = resource->reformat_type,
4360 : 0 : .is_root = !!dev_flow->dv.group,
4361 : : .reserve = 0,
4362 : : }
4363 : : };
4364 : 0 : struct mlx5_flow_cb_ctx ctx = {
4365 : : .error = error,
4366 : : .data = resource,
4367 : : };
4368 : : struct mlx5_hlist *encaps_decaps;
4369 : : uint64_t key64;
4370 : :
4371 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4372 : : "encaps_decaps",
4373 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4374 : : true, true, sh,
4375 : : flow_dv_encap_decap_create_cb,
4376 : : flow_dv_encap_decap_match_cb,
4377 : : flow_dv_encap_decap_remove_cb,
4378 : : flow_dv_encap_decap_clone_cb,
4379 : : flow_dv_encap_decap_clone_free_cb,
4380 : : error);
4381 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4382 : 0 : return -rte_errno;
4383 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4384 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4385 : : sizeof(encap_decap_key.v32), 0);
4386 [ # # ]: 0 : if (resource->reformat_type !=
4387 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4388 [ # # ]: 0 : resource->size)
4389 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4390 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4391 [ # # ]: 0 : if (!entry)
4392 : 0 : return -rte_errno;
4393 : : resource = container_of(entry, typeof(*resource), entry);
4394 : 0 : dev_flow->dv.encap_decap = resource;
4395 : 0 : dev_flow->handle->dvh.rix_encap_decap = resource->idx;
4396 : 0 : return 0;
4397 : : }
4398 : :
4399 : : /**
4400 : : * Find existing table jump resource or create and register a new one.
4401 : : *
4402 : : * @param[in, out] dev
4403 : : * Pointer to rte_eth_dev structure.
4404 : : * @param[in, out] tbl
4405 : : * Pointer to flow table resource.
4406 : : * @parm[in, out] dev_flow
4407 : : * Pointer to the dev_flow.
4408 : : * @param[out] error
4409 : : * pointer to error structure.
4410 : : *
4411 : : * @return
4412 : : * 0 on success otherwise -errno and errno is set.
4413 : : */
4414 : : static int
4415 : : flow_dv_jump_tbl_resource_register
4416 : : (struct rte_eth_dev *dev __rte_unused,
4417 : : struct mlx5_flow_tbl_resource *tbl,
4418 : : struct mlx5_flow *dev_flow,
4419 : : struct rte_flow_error *error __rte_unused)
4420 : : {
4421 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4422 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4423 : :
4424 : : MLX5_ASSERT(tbl);
4425 : : MLX5_ASSERT(tbl_data->jump.action);
4426 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4427 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4428 : : return 0;
4429 : : }
4430 : :
4431 : : int
4432 : 0 : flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4433 : : struct mlx5_list_entry *entry, void *cb_ctx)
4434 : : {
4435 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4436 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4437 : : struct mlx5_flow_dv_port_id_action_resource *res =
4438 : : container_of(entry, typeof(*res), entry);
4439 : :
4440 : 0 : return ref->port_id != res->port_id;
4441 : : }
4442 : :
4443 : : struct mlx5_list_entry *
4444 : 0 : flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4445 : : {
4446 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4447 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4448 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4449 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4450 : : uint32_t idx;
4451 : : int ret;
4452 : :
4453 : : /* Register new port id action resource. */
4454 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4455 [ # # ]: 0 : if (!resource) {
4456 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4457 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4458 : : "cannot allocate port_id action memory");
4459 : 0 : return NULL;
4460 : : }
4461 : 0 : *resource = *ref;
4462 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4463 : : ref->port_id,
4464 : : &resource->action);
4465 : : if (ret) {
4466 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4467 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4468 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4469 : : "cannot create action");
4470 : 0 : return NULL;
4471 : : }
4472 : 0 : resource->idx = idx;
4473 : 0 : return &resource->entry;
4474 : : }
4475 : :
4476 : : struct mlx5_list_entry *
4477 : 0 : flow_dv_port_id_clone_cb(void *tool_ctx,
4478 : : struct mlx5_list_entry *entry __rte_unused,
4479 : : void *cb_ctx)
4480 : : {
4481 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4482 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4483 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4484 : : uint32_t idx;
4485 : :
4486 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4487 [ # # ]: 0 : if (!resource) {
4488 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4489 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4490 : : "cannot allocate port_id action memory");
4491 : 0 : return NULL;
4492 : : }
4493 : : memcpy(resource, entry, sizeof(*resource));
4494 : 0 : resource->idx = idx;
4495 : 0 : return &resource->entry;
4496 : : }
4497 : :
4498 : : void
4499 : 0 : flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4500 : : {
4501 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4502 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4503 : : container_of(entry, typeof(*resource), entry);
4504 : :
4505 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4506 : 0 : }
4507 : :
4508 : : /**
4509 : : * Find existing table port ID resource or create and register a new one.
4510 : : *
4511 : : * @param[in, out] dev
4512 : : * Pointer to rte_eth_dev structure.
4513 : : * @param[in, out] ref
4514 : : * Pointer to port ID action resource reference.
4515 : : * @parm[in, out] dev_flow
4516 : : * Pointer to the dev_flow.
4517 : : * @param[out] error
4518 : : * pointer to error structure.
4519 : : *
4520 : : * @return
4521 : : * 0 on success otherwise -errno and errno is set.
4522 : : */
4523 : : static int
4524 : 0 : flow_dv_port_id_action_resource_register
4525 : : (struct rte_eth_dev *dev,
4526 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4527 : : struct mlx5_flow *dev_flow,
4528 : : struct rte_flow_error *error)
4529 : : {
4530 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4531 : : struct mlx5_list_entry *entry;
4532 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4533 : 0 : struct mlx5_flow_cb_ctx ctx = {
4534 : : .error = error,
4535 : : .data = ref,
4536 : : };
4537 : :
4538 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4539 [ # # ]: 0 : if (!entry)
4540 : 0 : return -rte_errno;
4541 : : resource = container_of(entry, typeof(*resource), entry);
4542 : 0 : dev_flow->dv.port_id_action = resource;
4543 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4544 : 0 : return 0;
4545 : : }
4546 : :
4547 : : int
4548 : 0 : flow_dv_push_vlan_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_push_vlan_action_resource *ref = ctx->data;
4553 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4554 : : container_of(entry, typeof(*res), entry);
4555 : :
4556 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4557 : : }
4558 : :
4559 : : struct mlx5_list_entry *
4560 : 0 : flow_dv_push_vlan_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_push_vlan_action_resource *ref = ctx->data;
4565 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4566 : : struct mlx5dv_dr_domain *domain;
4567 : : uint32_t idx;
4568 : : int ret;
4569 : :
4570 : : /* Register new port id action resource. */
4571 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4572 [ # # ]: 0 : if (!resource) {
4573 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4574 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4575 : : "cannot allocate push_vlan action memory");
4576 : 0 : return NULL;
4577 : : }
4578 : 0 : *resource = *ref;
4579 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4580 : 0 : domain = sh->fdb_domain;
4581 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4582 : 0 : domain = sh->rx_domain;
4583 : : else
4584 : 0 : domain = sh->tx_domain;
4585 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4586 : : &resource->action);
4587 : : if (ret) {
4588 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4589 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4590 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4591 : : "cannot create push vlan action");
4592 : 0 : return NULL;
4593 : : }
4594 : 0 : resource->idx = idx;
4595 : 0 : return &resource->entry;
4596 : : }
4597 : :
4598 : : struct mlx5_list_entry *
4599 : 0 : flow_dv_push_vlan_clone_cb(void *tool_ctx,
4600 : : struct mlx5_list_entry *entry __rte_unused,
4601 : : void *cb_ctx)
4602 : : {
4603 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4604 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4605 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4606 : : uint32_t idx;
4607 : :
4608 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4609 [ # # ]: 0 : if (!resource) {
4610 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4611 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4612 : : "cannot allocate push_vlan action memory");
4613 : 0 : return NULL;
4614 : : }
4615 : : memcpy(resource, entry, sizeof(*resource));
4616 : 0 : resource->idx = idx;
4617 : 0 : return &resource->entry;
4618 : : }
4619 : :
4620 : : void
4621 : 0 : flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4622 : : {
4623 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4624 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4625 : : container_of(entry, typeof(*resource), entry);
4626 : :
4627 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4628 : 0 : }
4629 : :
4630 : : /**
4631 : : * Find existing push vlan resource or create and register a new one.
4632 : : *
4633 : : * @param [in, out] dev
4634 : : * Pointer to rte_eth_dev structure.
4635 : : * @param[in, out] ref
4636 : : * Pointer to port ID action resource reference.
4637 : : * @parm[in, out] dev_flow
4638 : : * Pointer to the dev_flow.
4639 : : * @param[out] error
4640 : : * pointer to error structure.
4641 : : *
4642 : : * @return
4643 : : * 0 on success otherwise -errno and errno is set.
4644 : : */
4645 : : static int
4646 : 0 : flow_dv_push_vlan_action_resource_register
4647 : : (struct rte_eth_dev *dev,
4648 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4649 : : struct mlx5_flow *dev_flow,
4650 : : struct rte_flow_error *error)
4651 : : {
4652 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4653 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4654 : : struct mlx5_list_entry *entry;
4655 : 0 : struct mlx5_flow_cb_ctx ctx = {
4656 : : .error = error,
4657 : : .data = ref,
4658 : : };
4659 : :
4660 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4661 [ # # ]: 0 : if (!entry)
4662 : 0 : return -rte_errno;
4663 : : resource = container_of(entry, typeof(*resource), entry);
4664 : :
4665 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4666 : 0 : dev_flow->dv.push_vlan_res = resource;
4667 : 0 : return 0;
4668 : : }
4669 : :
4670 : : /**
4671 : : * Get the size of specific rte_flow_item_type hdr size
4672 : : *
4673 : : * @param[in] item_type
4674 : : * Tested rte_flow_item_type.
4675 : : *
4676 : : * @return
4677 : : * sizeof struct item_type, 0 if void or irrelevant.
4678 : : */
4679 : : size_t
4680 [ # # ]: 0 : flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4681 : : {
4682 : : size_t retval;
4683 : :
4684 : : switch (item_type) {
4685 : : case RTE_FLOW_ITEM_TYPE_ETH:
4686 : : retval = sizeof(struct rte_ether_hdr);
4687 : : break;
4688 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4689 : : retval = sizeof(struct rte_vlan_hdr);
4690 : : break;
4691 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4692 : : retval = sizeof(struct rte_ipv4_hdr);
4693 : : break;
4694 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4695 : : retval = sizeof(struct rte_ipv6_hdr);
4696 : : break;
4697 : : case RTE_FLOW_ITEM_TYPE_UDP:
4698 : : retval = sizeof(struct rte_udp_hdr);
4699 : : break;
4700 : : case RTE_FLOW_ITEM_TYPE_TCP:
4701 : : retval = sizeof(struct rte_tcp_hdr);
4702 : : break;
4703 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4704 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4705 : : retval = sizeof(struct rte_vxlan_hdr);
4706 : : break;
4707 : : case RTE_FLOW_ITEM_TYPE_GRE:
4708 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4709 : : retval = sizeof(struct rte_gre_hdr);
4710 : : break;
4711 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4712 : : retval = sizeof(struct rte_mpls_hdr);
4713 : : break;
4714 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4715 : : default:
4716 : : retval = 0;
4717 : : break;
4718 : : }
4719 : 0 : return retval;
4720 : : }
4721 : :
4722 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4723 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4724 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4725 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4726 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4727 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4728 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4729 : :
4730 : : /**
4731 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4732 : : *
4733 : : * @param[in] items
4734 : : * Pointer to rte_flow_item objects list.
4735 : : * @param[out] buf
4736 : : * Pointer to the output buffer.
4737 : : * @param[out] size
4738 : : * Pointer to the output buffer size.
4739 : : * @param[out] error
4740 : : * Pointer to the error structure.
4741 : : *
4742 : : * @return
4743 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4744 : : */
4745 : : int
4746 : 0 : flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4747 : : size_t *size, struct rte_flow_error *error)
4748 : : {
4749 : : struct rte_ether_hdr *eth = NULL;
4750 : : struct rte_vlan_hdr *vlan = NULL;
4751 : : struct rte_ipv4_hdr *ipv4 = NULL;
4752 : : struct rte_ipv6_hdr *ipv6 = NULL;
4753 : : struct rte_udp_hdr *udp = NULL;
4754 : : struct rte_vxlan_hdr *vxlan = NULL;
4755 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4756 : : struct rte_gre_hdr *gre = NULL;
4757 : : size_t len;
4758 : : size_t temp_size = 0;
4759 : :
4760 [ # # ]: 0 : if (!items)
4761 : 0 : return rte_flow_error_set(error, EINVAL,
4762 : : RTE_FLOW_ERROR_TYPE_ACTION,
4763 : : NULL, "invalid empty data");
4764 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4765 : 0 : len = flow_dv_get_item_hdr_len(items->type);
4766 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4767 : 0 : return rte_flow_error_set(error, EINVAL,
4768 : : RTE_FLOW_ERROR_TYPE_ACTION,
4769 : 0 : (void *)items->type,
4770 : : "items total size is too big"
4771 : : " for encap action");
4772 [ # # ]: 0 : if (items->spec)
4773 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4774 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4775 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4776 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4777 : 0 : break;
4778 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4779 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4780 [ # # ]: 0 : if (!eth)
4781 : 0 : return rte_flow_error_set(error, EINVAL,
4782 : : RTE_FLOW_ERROR_TYPE_ACTION,
4783 : : (void *)items->type,
4784 : : "eth header not found");
4785 [ # # ]: 0 : if (!eth->ether_type)
4786 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4787 : : break;
4788 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4789 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4790 [ # # ]: 0 : if (!vlan && !eth)
4791 : 0 : return rte_flow_error_set(error, EINVAL,
4792 : : RTE_FLOW_ERROR_TYPE_ACTION,
4793 : : (void *)items->type,
4794 : : "neither eth nor vlan"
4795 : : " header found");
4796 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4797 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4798 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4799 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4800 [ # # ]: 0 : if (!ipv4->version_ihl)
4801 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4802 : : MLX5_ENCAP_IPV4_IHL_MIN;
4803 [ # # ]: 0 : if (!ipv4->time_to_live)
4804 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4805 : : break;
4806 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4807 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4808 [ # # ]: 0 : if (!vlan && !eth)
4809 : 0 : return rte_flow_error_set(error, EINVAL,
4810 : : RTE_FLOW_ERROR_TYPE_ACTION,
4811 : : (void *)items->type,
4812 : : "neither eth nor vlan"
4813 : : " header found");
4814 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4815 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4816 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4817 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4818 [ # # ]: 0 : if (!ipv6->vtc_flow)
4819 : 0 : ipv6->vtc_flow =
4820 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4821 [ # # ]: 0 : if (!ipv6->hop_limits)
4822 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4823 : : break;
4824 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4825 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4826 [ # # ]: 0 : if (!ipv4 && !ipv6)
4827 : 0 : return rte_flow_error_set(error, EINVAL,
4828 : : RTE_FLOW_ERROR_TYPE_ACTION,
4829 : : (void *)items->type,
4830 : : "ip header not found");
4831 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4832 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4833 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4834 : 0 : ipv6->proto = IPPROTO_UDP;
4835 : : break;
4836 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4837 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4838 [ # # ]: 0 : if (!udp)
4839 : 0 : return rte_flow_error_set(error, EINVAL,
4840 : : RTE_FLOW_ERROR_TYPE_ACTION,
4841 : : (void *)items->type,
4842 : : "udp header not found");
4843 [ # # ]: 0 : if (!udp->dst_port)
4844 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4845 [ # # ]: 0 : if (!vxlan->vx_flags)
4846 : 0 : vxlan->vx_flags =
4847 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4848 : : break;
4849 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4850 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4851 [ # # ]: 0 : if (!udp)
4852 : 0 : return rte_flow_error_set(error, EINVAL,
4853 : : RTE_FLOW_ERROR_TYPE_ACTION,
4854 : : (void *)items->type,
4855 : : "udp header not found");
4856 [ # # ]: 0 : if (!vxlan_gpe->proto)
4857 : 0 : return rte_flow_error_set(error, EINVAL,
4858 : : RTE_FLOW_ERROR_TYPE_ACTION,
4859 : : (void *)items->type,
4860 : : "next protocol not found");
4861 [ # # ]: 0 : if (!udp->dst_port)
4862 : 0 : udp->dst_port =
4863 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4864 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4865 : 0 : vxlan_gpe->vx_flags =
4866 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4867 : : break;
4868 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4869 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4870 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4871 [ # # ]: 0 : if (!gre->proto)
4872 : 0 : return rte_flow_error_set(error, EINVAL,
4873 : : RTE_FLOW_ERROR_TYPE_ACTION,
4874 : 0 : (void *)items->type,
4875 : : "next protocol not found");
4876 [ # # ]: 0 : if (!ipv4 && !ipv6)
4877 : 0 : return rte_flow_error_set(error, EINVAL,
4878 : : RTE_FLOW_ERROR_TYPE_ACTION,
4879 : 0 : (void *)items->type,
4880 : : "ip header not found");
4881 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4882 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
4883 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4884 : 0 : ipv6->proto = IPPROTO_GRE;
4885 : : break;
4886 : : case RTE_FLOW_ITEM_TYPE_VOID:
4887 : : break;
4888 : 0 : default:
4889 : 0 : return rte_flow_error_set(error, EINVAL,
4890 : : RTE_FLOW_ERROR_TYPE_ACTION,
4891 : 0 : (void *)items->type,
4892 : : "unsupported item type");
4893 : : break;
4894 : : }
4895 : : temp_size += len;
4896 : : }
4897 : 0 : *size = temp_size;
4898 : 0 : return 0;
4899 : : }
4900 : :
4901 : : static int
4902 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4903 : : {
4904 : : struct rte_ether_hdr *eth = NULL;
4905 : : struct rte_vlan_hdr *vlan = NULL;
4906 : : struct rte_ipv4_hdr *ipv4 = NULL;
4907 : : struct rte_ipv6_hdr *ipv6 = NULL;
4908 : : struct rte_udp_hdr *udp = NULL;
4909 : : char *next_hdr;
4910 : : uint16_t proto;
4911 : :
4912 : : eth = (struct rte_ether_hdr *)data;
4913 : 0 : next_hdr = (char *)(eth + 1);
4914 : 0 : proto = RTE_BE16(eth->ether_type);
4915 : :
4916 : : /* VLAN skipping */
4917 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4918 : : vlan = (struct rte_vlan_hdr *)next_hdr;
4919 : 0 : proto = RTE_BE16(vlan->eth_proto);
4920 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
4921 : : }
4922 : :
4923 : : /* non IPv4/IPv6 header. not supported */
4924 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
4925 : 0 : return rte_flow_error_set(error, ENOTSUP,
4926 : : RTE_FLOW_ERROR_TYPE_ACTION,
4927 : : NULL, "Cannot offload non IPv4/IPv6");
4928 : : }
4929 : :
4930 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
4931 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
4932 : : /* ignore non UDP */
4933 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
4934 : : return 0;
4935 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
4936 : : } else {
4937 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4938 : : /* ignore non UDP */
4939 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
4940 : : return 0;
4941 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
4942 : : }
4943 : :
4944 : 0 : udp->dgram_cksum = 0;
4945 : :
4946 : 0 : return 0;
4947 : : }
4948 : :
4949 : : /**
4950 : : * Convert L2 encap action to DV specification.
4951 : : *
4952 : : * @param[in] dev
4953 : : * Pointer to rte_eth_dev structure.
4954 : : * @param[in] action
4955 : : * Pointer to action structure.
4956 : : * @param[in, out] dev_flow
4957 : : * Pointer to the mlx5_flow.
4958 : : * @param[in] transfer
4959 : : * Mark if the flow is E-Switch flow.
4960 : : * @param[out] error
4961 : : * Pointer to the error structure.
4962 : : *
4963 : : * @return
4964 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4965 : : */
4966 : : static int
4967 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4968 : : const struct rte_flow_action *action,
4969 : : struct mlx5_flow *dev_flow,
4970 : : uint8_t transfer,
4971 : : struct rte_flow_error *error)
4972 : : {
4973 : : const struct rte_flow_item *encap_data;
4974 : : const struct rte_flow_action_raw_encap *raw_encap_data;
4975 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
4976 : : .reformat_type =
4977 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4978 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4979 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4980 : : };
4981 : :
4982 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4983 : 0 : raw_encap_data =
4984 : : (const struct rte_flow_action_raw_encap *)action->conf;
4985 : 0 : res.size = raw_encap_data->size;
4986 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
4987 : : } else {
4988 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4989 : 0 : encap_data =
4990 : : ((const struct rte_flow_action_vxlan_encap *)
4991 : 0 : action->conf)->definition;
4992 : : else
4993 : 0 : encap_data =
4994 : : ((const struct rte_flow_action_nvgre_encap *)
4995 : 0 : action->conf)->definition;
4996 [ # # ]: 0 : if (flow_dv_convert_encap_data(encap_data, res.buf,
4997 : : &res.size, error))
4998 : 0 : return -rte_errno;
4999 : : }
5000 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5001 : 0 : return -rte_errno;
5002 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5003 : 0 : return rte_flow_error_set(error, EINVAL,
5004 : : RTE_FLOW_ERROR_TYPE_ACTION,
5005 : : NULL, "can't create L2 encap action");
5006 : : return 0;
5007 : : }
5008 : :
5009 : : /**
5010 : : * Convert L2 decap action to DV specification.
5011 : : *
5012 : : * @param[in] dev
5013 : : * Pointer to rte_eth_dev structure.
5014 : : * @param[in, out] dev_flow
5015 : : * Pointer to the mlx5_flow.
5016 : : * @param[in] transfer
5017 : : * Mark if the flow is E-Switch flow.
5018 : : * @param[out] error
5019 : : * Pointer to the error structure.
5020 : : *
5021 : : * @return
5022 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5023 : : */
5024 : : static int
5025 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5026 : : struct mlx5_flow *dev_flow,
5027 : : uint8_t transfer,
5028 : : struct rte_flow_error *error)
5029 : : {
5030 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5031 : : .size = 0,
5032 : : .reformat_type =
5033 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5034 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5035 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5036 : : };
5037 : :
5038 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5039 : 0 : return rte_flow_error_set(error, EINVAL,
5040 : : RTE_FLOW_ERROR_TYPE_ACTION,
5041 : : NULL, "can't create L2 decap action");
5042 : : return 0;
5043 : : }
5044 : :
5045 : : /**
5046 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5047 : : *
5048 : : * @param[in] dev
5049 : : * Pointer to rte_eth_dev structure.
5050 : : * @param[in] action
5051 : : * Pointer to action structure.
5052 : : * @param[in, out] dev_flow
5053 : : * Pointer to the mlx5_flow.
5054 : : * @param[in] attr
5055 : : * Pointer to the flow attributes.
5056 : : * @param[out] error
5057 : : * Pointer to the error structure.
5058 : : *
5059 : : * @return
5060 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5061 : : */
5062 : : static int
5063 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5064 : : const struct rte_flow_action *action,
5065 : : struct mlx5_flow *dev_flow,
5066 : : const struct rte_flow_attr *attr,
5067 : : struct rte_flow_error *error)
5068 : : {
5069 : : const struct rte_flow_action_raw_encap *encap_data;
5070 : : struct mlx5_flow_dv_encap_decap_resource res;
5071 : :
5072 : : memset(&res, 0, sizeof(res));
5073 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5074 : 0 : res.size = encap_data->size;
5075 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5076 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5077 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5078 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5079 [ # # ]: 0 : if (attr->transfer)
5080 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5081 : : else
5082 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5083 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5084 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5085 : 0 : return rte_flow_error_set(error, EINVAL,
5086 : : RTE_FLOW_ERROR_TYPE_ACTION,
5087 : : NULL, "can't create encap action");
5088 : : return 0;
5089 : : }
5090 : :
5091 : : /**
5092 : : * Create action push VLAN.
5093 : : *
5094 : : * @param[in] dev
5095 : : * Pointer to rte_eth_dev structure.
5096 : : * @param[in] attr
5097 : : * Pointer to the flow attributes.
5098 : : * @param[in] vlan
5099 : : * Pointer to the vlan to push to the Ethernet header.
5100 : : * @param[in, out] dev_flow
5101 : : * Pointer to the mlx5_flow.
5102 : : * @param[out] error
5103 : : * Pointer to the error structure.
5104 : : *
5105 : : * @return
5106 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5107 : : */
5108 : : static int
5109 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5110 : : const struct rte_flow_attr *attr,
5111 : : const struct rte_vlan_hdr *vlan,
5112 : : struct mlx5_flow *dev_flow,
5113 : : struct rte_flow_error *error)
5114 : : {
5115 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5116 : :
5117 : : memset(&res, 0, sizeof(res));
5118 : 0 : res.vlan_tag =
5119 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5120 : : vlan->vlan_tci);
5121 [ # # ]: 0 : if (attr->transfer)
5122 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5123 : : else
5124 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5125 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5126 : 0 : return flow_dv_push_vlan_action_resource_register
5127 : : (dev, &res, dev_flow, error);
5128 : : }
5129 : :
5130 : : /**
5131 : : * Validate the modify-header actions.
5132 : : *
5133 : : * @param[in] action_flags
5134 : : * Holds the actions detected until now.
5135 : : * @param[in] action
5136 : : * Pointer to the modify action.
5137 : : * @param[out] error
5138 : : * Pointer to error structure.
5139 : : *
5140 : : * @return
5141 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5142 : : */
5143 : : static int
5144 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5145 : : const struct rte_flow_action *action,
5146 : : struct rte_flow_error *error)
5147 : : {
5148 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5149 : 0 : return rte_flow_error_set(error, EINVAL,
5150 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5151 : : NULL, "action configuration not set");
5152 : :
5153 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5154 : 0 : return rte_flow_error_set(error, EINVAL,
5155 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5156 : : "can't have encap action before"
5157 : : " modify action");
5158 : : return 0;
5159 : : }
5160 : :
5161 : : /**
5162 : : * Validate the modify-header MAC address actions.
5163 : : *
5164 : : * @param[in] action_flags
5165 : : * Holds the actions detected until now.
5166 : : * @param[in] action
5167 : : * Pointer to the modify action.
5168 : : * @param[in] item_flags
5169 : : * Holds the items detected.
5170 : : * @param[out] error
5171 : : * Pointer to error structure.
5172 : : *
5173 : : * @return
5174 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5175 : : */
5176 : : static int
5177 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5178 : : const struct rte_flow_action *action,
5179 : : const uint64_t item_flags,
5180 : : struct rte_flow_error *error)
5181 : : {
5182 : : int ret = 0;
5183 : :
5184 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5185 [ # # ]: 0 : if (!ret) {
5186 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5187 : 0 : return rte_flow_error_set(error, EINVAL,
5188 : : RTE_FLOW_ERROR_TYPE_ACTION,
5189 : : NULL,
5190 : : "no L2 item in pattern");
5191 : : }
5192 : : return ret;
5193 : : }
5194 : :
5195 : : /**
5196 : : * Validate the modify-header IPv4 address actions.
5197 : : *
5198 : : * @param[in] action_flags
5199 : : * Holds the actions detected until now.
5200 : : * @param[in] action
5201 : : * Pointer to the modify action.
5202 : : * @param[in] item_flags
5203 : : * Holds the items detected.
5204 : : * @param[out] error
5205 : : * Pointer to error structure.
5206 : : *
5207 : : * @return
5208 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5209 : : */
5210 : : static int
5211 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5212 : : const struct rte_flow_action *action,
5213 : : const uint64_t item_flags,
5214 : : struct rte_flow_error *error)
5215 : : {
5216 : : int ret = 0;
5217 : : uint64_t layer;
5218 : :
5219 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5220 [ # # ]: 0 : if (!ret) {
5221 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5222 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5223 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5224 [ # # ]: 0 : if (!(item_flags & layer))
5225 : 0 : return rte_flow_error_set(error, EINVAL,
5226 : : RTE_FLOW_ERROR_TYPE_ACTION,
5227 : : NULL,
5228 : : "no ipv4 item in pattern");
5229 : : }
5230 : : return ret;
5231 : : }
5232 : :
5233 : : /**
5234 : : * Validate the modify-header IPv6 address actions.
5235 : : *
5236 : : * @param[in] action_flags
5237 : : * Holds the actions detected until now.
5238 : : * @param[in] action
5239 : : * Pointer to the modify action.
5240 : : * @param[in] item_flags
5241 : : * Holds the items detected.
5242 : : * @param[out] error
5243 : : * Pointer to error structure.
5244 : : *
5245 : : * @return
5246 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5247 : : */
5248 : : static int
5249 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5250 : : const struct rte_flow_action *action,
5251 : : const uint64_t item_flags,
5252 : : struct rte_flow_error *error)
5253 : : {
5254 : : int ret = 0;
5255 : : uint64_t layer;
5256 : :
5257 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5258 [ # # ]: 0 : if (!ret) {
5259 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5260 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5261 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5262 [ # # ]: 0 : if (!(item_flags & layer))
5263 : 0 : return rte_flow_error_set(error, EINVAL,
5264 : : RTE_FLOW_ERROR_TYPE_ACTION,
5265 : : NULL,
5266 : : "no ipv6 item in pattern");
5267 : : }
5268 : : return ret;
5269 : : }
5270 : :
5271 : : /**
5272 : : * Validate the modify-header TP actions.
5273 : : *
5274 : : * @param[in] action_flags
5275 : : * Holds the actions detected until now.
5276 : : * @param[in] action
5277 : : * Pointer to the modify action.
5278 : : * @param[in] item_flags
5279 : : * Holds the items detected.
5280 : : * @param[out] error
5281 : : * Pointer to error structure.
5282 : : *
5283 : : * @return
5284 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5285 : : */
5286 : : static int
5287 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5288 : : const struct rte_flow_action *action,
5289 : : const uint64_t item_flags,
5290 : : struct rte_flow_error *error)
5291 : : {
5292 : : int ret = 0;
5293 : : uint64_t layer;
5294 : :
5295 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5296 [ # # ]: 0 : if (!ret) {
5297 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5298 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5299 : : MLX5_FLOW_LAYER_OUTER_L4;
5300 [ # # ]: 0 : if (!(item_flags & layer))
5301 : 0 : return rte_flow_error_set(error, EINVAL,
5302 : : RTE_FLOW_ERROR_TYPE_ACTION,
5303 : : NULL, "no transport layer "
5304 : : "in pattern");
5305 : : }
5306 : : return ret;
5307 : : }
5308 : :
5309 : : /**
5310 : : * Validate the modify-header actions of increment/decrement
5311 : : * TCP Sequence-number.
5312 : : *
5313 : : * @param[in] action_flags
5314 : : * Holds the actions detected until now.
5315 : : * @param[in] action
5316 : : * Pointer to the modify action.
5317 : : * @param[in] item_flags
5318 : : * Holds the items detected.
5319 : : * @param[out] error
5320 : : * Pointer to error structure.
5321 : : *
5322 : : * @return
5323 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5324 : : */
5325 : : static int
5326 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5327 : : const struct rte_flow_action *action,
5328 : : const uint64_t item_flags,
5329 : : struct rte_flow_error *error)
5330 : : {
5331 : : int ret = 0;
5332 : : uint64_t layer;
5333 : :
5334 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5335 [ # # ]: 0 : if (!ret) {
5336 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5337 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5338 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5339 [ # # ]: 0 : if (!(item_flags & layer))
5340 : 0 : return rte_flow_error_set(error, EINVAL,
5341 : : RTE_FLOW_ERROR_TYPE_ACTION,
5342 : : NULL, "no TCP item in"
5343 : : " pattern");
5344 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5345 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5346 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5347 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5348 : 0 : return rte_flow_error_set(error, EINVAL,
5349 : : RTE_FLOW_ERROR_TYPE_ACTION,
5350 : : NULL,
5351 : : "cannot decrease and increase"
5352 : : " TCP sequence number"
5353 : : " at the same time");
5354 : : }
5355 : : return ret;
5356 : : }
5357 : :
5358 : : /**
5359 : : * Validate the modify-header actions of increment/decrement
5360 : : * TCP Acknowledgment number.
5361 : : *
5362 : : * @param[in] action_flags
5363 : : * Holds the actions detected until now.
5364 : : * @param[in] action
5365 : : * Pointer to the modify action.
5366 : : * @param[in] item_flags
5367 : : * Holds the items detected.
5368 : : * @param[out] error
5369 : : * Pointer to error structure.
5370 : : *
5371 : : * @return
5372 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5373 : : */
5374 : : static int
5375 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5376 : : const struct rte_flow_action *action,
5377 : : const uint64_t item_flags,
5378 : : struct rte_flow_error *error)
5379 : : {
5380 : : int ret = 0;
5381 : : uint64_t layer;
5382 : :
5383 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5384 [ # # ]: 0 : if (!ret) {
5385 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5386 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5387 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5388 [ # # ]: 0 : if (!(item_flags & layer))
5389 : 0 : return rte_flow_error_set(error, EINVAL,
5390 : : RTE_FLOW_ERROR_TYPE_ACTION,
5391 : : NULL, "no TCP item in"
5392 : : " pattern");
5393 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5394 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5395 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5396 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5397 : 0 : return rte_flow_error_set(error, EINVAL,
5398 : : RTE_FLOW_ERROR_TYPE_ACTION,
5399 : : NULL,
5400 : : "cannot decrease and increase"
5401 : : " TCP acknowledgment number"
5402 : : " at the same time");
5403 : : }
5404 : : return ret;
5405 : : }
5406 : :
5407 : : /**
5408 : : * Validate the modify-header TTL actions.
5409 : : *
5410 : : * @param[in] action_flags
5411 : : * Holds the actions detected until now.
5412 : : * @param[in] action
5413 : : * Pointer to the modify action.
5414 : : * @param[in] item_flags
5415 : : * Holds the items detected.
5416 : : * @param[out] error
5417 : : * Pointer to error structure.
5418 : : *
5419 : : * @return
5420 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5421 : : */
5422 : : static int
5423 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5424 : : const struct rte_flow_action *action,
5425 : : const uint64_t item_flags,
5426 : : struct rte_flow_error *error)
5427 : : {
5428 : : int ret = 0;
5429 : : uint64_t layer;
5430 : :
5431 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5432 [ # # ]: 0 : if (!ret) {
5433 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5434 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5435 : : MLX5_FLOW_LAYER_OUTER_L3;
5436 [ # # ]: 0 : if (!(item_flags & layer))
5437 : 0 : return rte_flow_error_set(error, EINVAL,
5438 : : RTE_FLOW_ERROR_TYPE_ACTION,
5439 : : NULL,
5440 : : "no IP protocol in pattern");
5441 : : }
5442 : : return ret;
5443 : : }
5444 : :
5445 : : /**
5446 : : * Validate the generic modify field actions.
5447 : : * @param[in] dev
5448 : : * Pointer to the rte_eth_dev structure.
5449 : : * @param[in] action_flags
5450 : : * Holds the actions detected until now.
5451 : : * @param[in] action
5452 : : * Pointer to the modify action.
5453 : : * @param[in] attr
5454 : : * Pointer to the flow attributes.
5455 : : * @param root
5456 : : * Whether action is on root table.
5457 : : * @param[out] error
5458 : : * Pointer to error structure.
5459 : : *
5460 : : * @return
5461 : : * Number of header fields to modify (0 or more) on success,
5462 : : * a negative errno value otherwise and rte_errno is set.
5463 : : */
5464 : : static int
5465 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5466 : : const uint64_t action_flags,
5467 : : const struct rte_flow_action *action,
5468 : : const struct rte_flow_attr *attr,
5469 : : bool root,
5470 : : struct rte_flow_error *error)
5471 : : {
5472 : : int ret = 0;
5473 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5474 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5475 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5476 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5477 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5478 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5479 : 0 : uint32_t dst_width, src_width, width = conf->width;
5480 : :
5481 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5482 [ # # ]: 0 : if (ret)
5483 : : return ret;
5484 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5485 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5486 : 0 : return rte_flow_error_set(error, ENOTSUP,
5487 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5488 : : "flex item fields modification"
5489 : : " is not supported");
5490 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5491 : : -1, attr, error);
5492 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5493 : : dst_width, attr, error);
5494 [ # # ]: 0 : if (width == 0)
5495 : 0 : return rte_flow_error_set(error, EINVAL,
5496 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5497 : : "no bits are requested to be modified");
5498 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5499 : 0 : return rte_flow_error_set(error, EINVAL,
5500 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5501 : : "cannot modify more bits than"
5502 : : " the width of a field");
5503 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5504 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5505 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5506 : 0 : return rte_flow_error_set(error, EINVAL,
5507 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5508 : : "destination offset is too big");
5509 : 0 : ret = flow_validate_modify_field_level(dst_data, error);
5510 [ # # ]: 0 : if (ret)
5511 : : return ret;
5512 [ # # ]: 0 : if (dst_data->tag_index &&
5513 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5514 : 0 : return rte_flow_error_set(error, EINVAL,
5515 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5516 : : "destination tag index is not supported");
5517 [ # # ]: 0 : if (dst_data->class_id)
5518 : 0 : return rte_flow_error_set(error, EINVAL,
5519 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5520 : : "destination class ID is not supported");
5521 : : }
5522 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5523 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5524 [ # # ]: 0 : if (root)
5525 : 0 : return rte_flow_error_set(error, ENOTSUP,
5526 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5527 : : "modify field action is not"
5528 : : " supported for group 0");
5529 [ # # ]: 0 : if (src_data->offset + width > src_width)
5530 : 0 : return rte_flow_error_set(error, EINVAL,
5531 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5532 : : "source offset is too big");
5533 : 0 : ret = flow_validate_modify_field_level(src_data, error);
5534 [ # # ]: 0 : if (ret)
5535 : : return ret;
5536 [ # # ]: 0 : if (src_data->tag_index &&
5537 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5538 : 0 : return rte_flow_error_set(error, EINVAL,
5539 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5540 : : "source tag index is not supported");
5541 [ # # ]: 0 : if (src_data->class_id)
5542 : 0 : return rte_flow_error_set(error, EINVAL,
5543 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5544 : : "source class ID is not supported");
5545 : : }
5546 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5547 [ # # ]: 0 : (dst_data->level == src_data->level))
5548 : 0 : return rte_flow_error_set(error, EINVAL,
5549 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5550 : : "source and destination fields"
5551 : : " cannot be the same");
5552 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5553 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5554 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5555 : 0 : return rte_flow_error_set(error, EINVAL,
5556 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5557 : : "mark, immediate value or a pointer to it"
5558 : : " cannot be used as a destination");
5559 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5560 : : src_data->field == RTE_FLOW_FIELD_START)
5561 : 0 : return rte_flow_error_set(error, ENOTSUP,
5562 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5563 : : "modifications of an arbitrary"
5564 : : " place in a packet is not supported");
5565 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5566 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5567 : 0 : return rte_flow_error_set(error, ENOTSUP,
5568 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5569 : : "modifications of the 802.1Q Tag"
5570 : : " Identifier is not supported");
5571 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5572 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5573 : 0 : return rte_flow_error_set(error, ENOTSUP,
5574 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5575 : : "modifications of the VXLAN Network"
5576 : : " Identifier is not supported");
5577 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5578 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5579 : 0 : return rte_flow_error_set(error, ENOTSUP,
5580 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5581 : : "modifications of the GENEVE Network"
5582 : : " Identifier is not supported");
5583 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5584 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5585 : 0 : return rte_flow_error_set(error, ENOTSUP,
5586 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5587 : : "modifications of the GENEVE option type is not supported");
5588 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5589 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5590 : 0 : return rte_flow_error_set(error, ENOTSUP,
5591 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5592 : : "modifications of the GENEVE option class is not supported");
5593 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5594 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5595 : 0 : return rte_flow_error_set(error, ENOTSUP,
5596 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5597 : : "modifications of the GENEVE option data is not supported");
5598 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5599 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5600 : 0 : return rte_flow_error_set(error, ENOTSUP,
5601 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5602 : : "modifications of the MPLS header "
5603 : : "is not supported");
5604 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5605 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5606 : 0 : return rte_flow_error_set(error, ENOTSUP,
5607 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5608 : : "modifications of random value is not supported");
5609 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5610 : : src_data->field == RTE_FLOW_FIELD_MARK)
5611 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5612 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5613 : 0 : return rte_flow_error_set(error, ENOTSUP,
5614 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5615 : : "cannot modify mark in legacy mode"
5616 : : " or without extensive registers");
5617 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5618 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5619 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5620 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5621 : 0 : return rte_flow_error_set(error, ENOTSUP,
5622 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5623 : : "cannot modify meta without"
5624 : : " extensive registers support");
5625 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5626 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5627 : 0 : return rte_flow_error_set(error, ENOTSUP,
5628 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5629 : : "cannot modify meta without"
5630 : : " extensive registers available");
5631 : : }
5632 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5633 : 0 : return rte_flow_error_set(error, ENOTSUP,
5634 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5635 : : "sub operations are not supported");
5636 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5637 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5638 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5639 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5640 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5641 : 0 : return rte_flow_error_set(error, ENOTSUP,
5642 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5643 : : "modifications of the ECN for current firmware is not supported");
5644 : 0 : return (width / 32) + !!(width % 32);
5645 : : }
5646 : :
5647 : : /**
5648 : : * Validate jump action.
5649 : : *
5650 : : * @param[in] action
5651 : : * Pointer to the jump action.
5652 : : * @param[in] action_flags
5653 : : * Holds the actions detected until now.
5654 : : * @param[in] attributes
5655 : : * Pointer to flow attributes
5656 : : * @param[in] external
5657 : : * Action belongs to flow rule created by request external to PMD.
5658 : : * @param[out] error
5659 : : * Pointer to error structure.
5660 : : *
5661 : : * @return
5662 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5663 : : */
5664 : : static int
5665 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5666 : : const struct mlx5_flow_tunnel *tunnel,
5667 : : const struct rte_flow_action *action,
5668 : : uint64_t action_flags,
5669 : : const struct rte_flow_attr *attributes,
5670 : : bool external, struct rte_flow_error *error)
5671 : : {
5672 : 0 : uint32_t target_group, table = 0;
5673 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5674 : : int ret = 0;
5675 : 0 : struct flow_grp_info grp_info = {
5676 : : .external = !!external,
5677 : 0 : .transfer = !!attributes->transfer,
5678 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5679 : : .std_tbl_fix = 0
5680 : : };
5681 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5682 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5683 : 0 : return rte_flow_error_set(error, EINVAL,
5684 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5685 : : "can't have 2 fate actions in"
5686 : : " same flow");
5687 [ # # ]: 0 : if (!action->conf)
5688 : 0 : return rte_flow_error_set(error, EINVAL,
5689 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5690 : : NULL, "action configuration not set");
5691 : 0 : target_group =
5692 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5693 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5694 : : &grp_info, error);
5695 [ # # ]: 0 : if (ret)
5696 : : return ret;
5697 [ # # ]: 0 : if (table == 0)
5698 : 0 : return rte_flow_error_set(error, EINVAL,
5699 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5700 : : NULL, "root table shouldn't be destination");
5701 : : return 0;
5702 : : }
5703 : :
5704 : : /*
5705 : : * Validate action PORT_ID / REPRESENTED_PORT.
5706 : : *
5707 : : * @param[in] dev
5708 : : * Pointer to rte_eth_dev structure.
5709 : : * @param[in] action_flags
5710 : : * Bit-fields that holds the actions detected until now.
5711 : : * @param[in] action
5712 : : * PORT_ID / REPRESENTED_PORT action structure.
5713 : : * @param[in] attr
5714 : : * Attributes of flow that includes this action.
5715 : : * @param[out] error
5716 : : * Pointer to error structure.
5717 : : *
5718 : : * @return
5719 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5720 : : */
5721 : : static int
5722 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5723 : : uint64_t action_flags,
5724 : : const struct rte_flow_action *action,
5725 : : const struct rte_flow_attr *attr,
5726 : : struct rte_flow_error *error)
5727 : : {
5728 : : const struct rte_flow_action_port_id *port_id;
5729 : : const struct rte_flow_action_ethdev *ethdev;
5730 : : struct mlx5_priv *act_priv;
5731 : : struct mlx5_priv *dev_priv;
5732 : : uint16_t port;
5733 : :
5734 [ # # ]: 0 : if (!attr->transfer)
5735 : 0 : return rte_flow_error_set(error, ENOTSUP,
5736 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5737 : : NULL,
5738 : : "port action is valid in transfer"
5739 : : " mode only");
5740 [ # # # # ]: 0 : if (!action || !action->conf)
5741 : 0 : return rte_flow_error_set(error, ENOTSUP,
5742 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5743 : : NULL,
5744 : : "port action parameters must be"
5745 : : " specified");
5746 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5747 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5748 : 0 : return rte_flow_error_set(error, EINVAL,
5749 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5750 : : "can have only one fate actions in"
5751 : : " a flow");
5752 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5753 [ # # ]: 0 : if (!dev_priv)
5754 : 0 : return rte_flow_error_set(error, rte_errno,
5755 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5756 : : NULL,
5757 : : "failed to obtain E-Switch info");
5758 [ # # # ]: 0 : switch (action->type) {
5759 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5760 : 0 : port_id = action->conf;
5761 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5762 : : break;
5763 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5764 : 0 : ethdev = action->conf;
5765 : 0 : port = ethdev->port_id;
5766 : 0 : break;
5767 : 0 : default:
5768 : : MLX5_ASSERT(false);
5769 : 0 : return rte_flow_error_set
5770 : : (error, EINVAL,
5771 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5772 : : "unknown E-Switch action");
5773 : : }
5774 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5775 [ # # ]: 0 : if (!act_priv)
5776 : 0 : return rte_flow_error_set
5777 : : (error, rte_errno,
5778 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5779 : : "failed to obtain E-Switch port id for port");
5780 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5781 : 0 : return rte_flow_error_set
5782 : : (error, EINVAL,
5783 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5784 : : "port does not belong to"
5785 : : " E-Switch being configured");
5786 : : return 0;
5787 : : }
5788 : :
5789 : : /**
5790 : : * Get the maximum number of modify header actions.
5791 : : *
5792 : : * @param dev
5793 : : * Pointer to rte_eth_dev structure.
5794 : : * @param root
5795 : : * Whether action is on root table.
5796 : : *
5797 : : * @return
5798 : : * Max number of modify header actions device can support.
5799 : : */
5800 : : static inline unsigned int
5801 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5802 : : bool root)
5803 : : {
5804 : : /*
5805 : : * There's no way to directly query the max capacity from FW.
5806 : : * The maximal value on root table should be assumed to be supported.
5807 : : */
5808 [ # # ]: 0 : if (!root)
5809 : : return MLX5_MAX_MODIFY_NUM;
5810 : : else
5811 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5812 : : }
5813 : :
5814 : : /**
5815 : : * Validate the meter action.
5816 : : *
5817 : : * @param[in] dev
5818 : : * Pointer to rte_eth_dev structure.
5819 : : * @param[in] action_flags
5820 : : * Bit-fields that holds the actions detected until now.
5821 : : * @param[in] item_flags
5822 : : * Holds the items detected.
5823 : : * @param[in] action
5824 : : * Pointer to the meter action.
5825 : : * @param[in] attr
5826 : : * Attributes of flow that includes this action.
5827 : : * @param[in] port_id_item
5828 : : * Pointer to item indicating port id.
5829 : : * @param[out] error
5830 : : * Pointer to error structure.
5831 : : *
5832 : : * @return
5833 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5834 : : */
5835 : : static int
5836 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5837 : : uint64_t action_flags, uint64_t item_flags,
5838 : : const struct rte_flow_action *action,
5839 : : const struct rte_flow_attr *attr,
5840 : : const struct rte_flow_item *port_id_item,
5841 : : bool *def_policy,
5842 : : struct rte_flow_error *error)
5843 : : {
5844 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5845 : 0 : const struct rte_flow_action_meter *am = action->conf;
5846 : : struct mlx5_flow_meter_info *fm;
5847 : : struct mlx5_flow_meter_policy *mtr_policy;
5848 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5849 : 0 : uint16_t flow_src_port = priv->representor_id;
5850 : 0 : bool all_ports = false;
5851 : :
5852 [ # # ]: 0 : if (!am)
5853 : 0 : return rte_flow_error_set(error, EINVAL,
5854 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5855 : : "meter action conf is NULL");
5856 : :
5857 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5858 : 0 : return rte_flow_error_set(error, ENOTSUP,
5859 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5860 : : "meter chaining not support");
5861 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5862 : 0 : return rte_flow_error_set(error, ENOTSUP,
5863 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5864 : : "meter with jump not support");
5865 [ # # ]: 0 : if (!priv->mtr_en)
5866 : 0 : return rte_flow_error_set(error, ENOTSUP,
5867 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5868 : : NULL,
5869 : : "meter action not supported");
5870 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5871 [ # # ]: 0 : if (!fm)
5872 : 0 : return rte_flow_error_set(error, EINVAL,
5873 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5874 : : "Meter not found");
5875 : : /* aso meter can always be shared by different domains */
5876 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5877 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
5878 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
5879 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
5880 : 0 : return rte_flow_error_set(error, EINVAL,
5881 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5882 : : "Flow attributes domain are either invalid "
5883 : : "or have a domain conflict with current "
5884 : : "meter attributes");
5885 [ # # ]: 0 : if (fm->def_policy) {
5886 [ # # ]: 0 : if (!((attr->transfer &&
5887 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5888 [ # # ]: 0 : (attr->egress &&
5889 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5890 [ # # ]: 0 : (attr->ingress &&
5891 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5892 : 0 : return rte_flow_error_set(error, EINVAL,
5893 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5894 : : "Flow attributes domain "
5895 : : "have a conflict with current "
5896 : : "meter domain attributes");
5897 : 0 : *def_policy = true;
5898 : : } else {
5899 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
5900 : : fm->policy_id, NULL);
5901 [ # # ]: 0 : if (!mtr_policy)
5902 : 0 : return rte_flow_error_set(error, EINVAL,
5903 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5904 : : "Invalid policy id for meter ");
5905 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
5906 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
5907 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
5908 : 0 : return rte_flow_error_set(error, EINVAL,
5909 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5910 : : "Flow attributes domain "
5911 : : "have a conflict with current "
5912 : : "meter domain attributes");
5913 [ # # ]: 0 : if (port_id_item) {
5914 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
5915 : : &all_ports, error))
5916 : 0 : return -rte_errno;
5917 : : }
5918 [ # # ]: 0 : if (attr->transfer) {
5919 : : /* When flow matching all src ports, meter should not have drop count. */
5920 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
5921 : 0 : return rte_flow_error_set(error, EINVAL,
5922 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
5923 : : "Meter drop count or "
5924 : : "modify_field/set_tag in meter hierarchy "
5925 : : "not supported when matching all ports.");
5926 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
5927 : : struct mlx5_flow_meter_policy *fp;
5928 : : struct mlx5_meter_policy_action_container *acg;
5929 : : struct mlx5_meter_policy_action_container *acy;
5930 : : const struct rte_flow_action *rss_act;
5931 : : int ret;
5932 : :
5933 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
5934 : : mtr_policy);
5935 [ # # ]: 0 : if (fp == NULL)
5936 : 0 : return rte_flow_error_set(error, EINVAL,
5937 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5938 : : "Unable to get the final "
5939 : : "policy in the hierarchy");
5940 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
5941 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
5942 : : MLX5_ASSERT(acg->fate_action ==
5943 : : MLX5_FLOW_FATE_SHARED_RSS ||
5944 : : acy->fate_action ==
5945 : : MLX5_FLOW_FATE_SHARED_RSS);
5946 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
5947 : 0 : rss_act = acg->rss;
5948 : : else
5949 : 0 : rss_act = acy->rss;
5950 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
5951 : : action_flags, dev, attr,
5952 : : item_flags, error);
5953 [ # # ]: 0 : if (ret)
5954 : : return ret;
5955 : : }
5956 : 0 : *def_policy = false;
5957 : : }
5958 : : return 0;
5959 : : }
5960 : :
5961 : : /**
5962 : : * Validate the age action.
5963 : : *
5964 : : * @param[in] action_flags
5965 : : * Holds the actions detected until now.
5966 : : * @param[in] action
5967 : : * Pointer to the age action.
5968 : : * @param[in] dev
5969 : : * Pointer to the Ethernet device structure.
5970 : : * @param[out] error
5971 : : * Pointer to error structure.
5972 : : *
5973 : : * @return
5974 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5975 : : */
5976 : : static int
5977 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
5978 : : const struct rte_flow_action *action,
5979 : : struct rte_eth_dev *dev,
5980 : : struct rte_flow_error *error)
5981 : : {
5982 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5983 : 0 : const struct rte_flow_action_age *age = action->conf;
5984 : :
5985 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
5986 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
5987 : 0 : return rte_flow_error_set(error, ENOTSUP,
5988 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5989 : : NULL,
5990 : : "age action not supported");
5991 [ # # ]: 0 : if (!(action->conf))
5992 : 0 : return rte_flow_error_set(error, EINVAL,
5993 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5994 : : "configuration cannot be null");
5995 [ # # ]: 0 : if (!(age->timeout))
5996 : 0 : return rte_flow_error_set(error, EINVAL,
5997 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5998 : : "invalid timeout value 0");
5999 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6000 : 0 : return rte_flow_error_set(error, EINVAL,
6001 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6002 : : "duplicate age actions set");
6003 : : return 0;
6004 : : }
6005 : :
6006 : : /**
6007 : : * Validate the modify-header IPv4 DSCP actions.
6008 : : *
6009 : : * @param[in] action_flags
6010 : : * Holds the actions detected until now.
6011 : : * @param[in] action
6012 : : * Pointer to the modify action.
6013 : : * @param[in] item_flags
6014 : : * Holds the items detected.
6015 : : * @param[out] error
6016 : : * Pointer to error structure.
6017 : : *
6018 : : * @return
6019 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6020 : : */
6021 : : static int
6022 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6023 : : const struct rte_flow_action *action,
6024 : : const uint64_t item_flags,
6025 : : struct rte_flow_error *error)
6026 : : {
6027 : : int ret = 0;
6028 : :
6029 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6030 [ # # ]: 0 : if (!ret) {
6031 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6032 : 0 : return rte_flow_error_set(error, EINVAL,
6033 : : RTE_FLOW_ERROR_TYPE_ACTION,
6034 : : NULL,
6035 : : "no ipv4 item in pattern");
6036 : : }
6037 : : return ret;
6038 : : }
6039 : :
6040 : : /**
6041 : : * Validate the modify-header IPv6 DSCP actions.
6042 : : *
6043 : : * @param[in] action_flags
6044 : : * Holds the actions detected until now.
6045 : : * @param[in] action
6046 : : * Pointer to the modify action.
6047 : : * @param[in] item_flags
6048 : : * Holds the items detected.
6049 : : * @param[out] error
6050 : : * Pointer to error structure.
6051 : : *
6052 : : * @return
6053 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6054 : : */
6055 : : static int
6056 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6057 : : const struct rte_flow_action *action,
6058 : : const uint64_t item_flags,
6059 : : struct rte_flow_error *error)
6060 : : {
6061 : : int ret = 0;
6062 : :
6063 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6064 [ # # ]: 0 : if (!ret) {
6065 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6066 : 0 : return rte_flow_error_set(error, EINVAL,
6067 : : RTE_FLOW_ERROR_TYPE_ACTION,
6068 : : NULL,
6069 : : "no ipv6 item in pattern");
6070 : : }
6071 : : return ret;
6072 : : }
6073 : :
6074 : : int
6075 : 0 : flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
6076 : : struct mlx5_list_entry *entry, void *cb_ctx)
6077 : : {
6078 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6079 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6080 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6081 : : container_of(entry, typeof(*resource), entry);
6082 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6083 : :
6084 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6085 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6086 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6087 : : }
6088 : :
6089 : : static struct mlx5_indexed_pool *
6090 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6091 : : {
6092 : 0 : struct mlx5_indexed_pool *ipool = __atomic_load_n
6093 : 0 : (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
6094 : :
6095 [ # # ]: 0 : if (!ipool) {
6096 : : struct mlx5_indexed_pool *expected = NULL;
6097 : 0 : struct mlx5_indexed_pool_config cfg =
6098 : : (struct mlx5_indexed_pool_config) {
6099 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6100 : 0 : (index + 1) *
6101 : : sizeof(struct mlx5_modification_cmd),
6102 : : .trunk_size = 64,
6103 : : .grow_trunk = 3,
6104 : : .grow_shift = 2,
6105 : : .need_lock = 1,
6106 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6107 : : .per_core_cache =
6108 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6109 : : .malloc = mlx5_malloc,
6110 : : .free = mlx5_free,
6111 : : .type = "mlx5_modify_action_resource",
6112 : : };
6113 : :
6114 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6115 : 0 : ipool = mlx5_ipool_create(&cfg);
6116 [ # # ]: 0 : if (!ipool)
6117 : 0 : return NULL;
6118 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
6119 : : &expected, ipool, false,
6120 : : __ATOMIC_SEQ_CST,
6121 : : __ATOMIC_SEQ_CST)) {
6122 : 0 : mlx5_ipool_destroy(ipool);
6123 : 0 : ipool = __atomic_load_n(&sh->mdh_ipools[index],
6124 : : __ATOMIC_SEQ_CST);
6125 : : }
6126 : : }
6127 : : return ipool;
6128 : : }
6129 : :
6130 : : struct mlx5_list_entry *
6131 : 0 : flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
6132 : : {
6133 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6134 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6135 : : struct mlx5dv_dr_domain *ns;
6136 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6137 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6138 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6139 : 0 : ref->actions_num - 1);
6140 : : int ret;
6141 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6142 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6143 : : uint32_t idx;
6144 : :
6145 [ # # ]: 0 : if (unlikely(!ipool)) {
6146 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6147 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6148 : : NULL, "cannot allocate modify ipool");
6149 : 0 : return NULL;
6150 : : }
6151 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6152 [ # # ]: 0 : if (!entry) {
6153 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6154 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6155 : : "cannot allocate resource memory");
6156 : 0 : return NULL;
6157 : : }
6158 : 0 : rte_memcpy(&entry->ft_type,
6159 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6160 [ # # ]: 0 : key_len + data_len);
6161 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6162 : 0 : ns = sh->fdb_domain;
6163 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6164 : 0 : ns = sh->tx_domain;
6165 : : else
6166 : 0 : ns = sh->rx_domain;
6167 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6168 : 0 : (sh->cdev->ctx, ns, entry,
6169 : : data_len, &entry->action);
6170 : : if (ret) {
6171 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6172 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6173 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6174 : : NULL, "cannot create modification action");
6175 : 0 : return NULL;
6176 : : }
6177 : 0 : entry->idx = idx;
6178 : 0 : return &entry->entry;
6179 : : }
6180 : :
6181 : : struct mlx5_list_entry *
6182 : 0 : flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6183 : : void *cb_ctx)
6184 : : {
6185 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6186 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6187 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6188 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6189 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6190 : : uint32_t idx;
6191 : :
6192 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6193 : : &idx);
6194 [ # # ]: 0 : if (!entry) {
6195 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6196 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6197 : : "cannot allocate resource memory");
6198 : 0 : return NULL;
6199 : : }
6200 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6201 : 0 : entry->idx = idx;
6202 : 0 : return &entry->entry;
6203 : : }
6204 : :
6205 : : void
6206 : 0 : flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6207 : : {
6208 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6209 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6210 : : container_of(entry, typeof(*res), entry);
6211 : :
6212 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6213 : 0 : }
6214 : :
6215 : : /**
6216 : : * Validate the sample action.
6217 : : *
6218 : : * @param[in, out] action_flags
6219 : : * Holds the actions detected until now.
6220 : : * @param[in] action
6221 : : * Pointer to the sample action.
6222 : : * @param[in] dev
6223 : : * Pointer to the Ethernet device structure.
6224 : : * @param[in] attr
6225 : : * Attributes of flow that includes this action.
6226 : : * @param[in] item_flags
6227 : : * Holds the items detected.
6228 : : * @param[in] rss
6229 : : * Pointer to the RSS action.
6230 : : * @param[out] sample_rss
6231 : : * Pointer to the RSS action in sample action list.
6232 : : * @param[out] count
6233 : : * Pointer to the COUNT action in sample action list.
6234 : : * @param[out] fdb_mirror
6235 : : * Pointer to the FDB mirror flag.
6236 : : * @param root
6237 : : * Whether action is on root table.
6238 : : * @param[out] error
6239 : : * Pointer to error structure.
6240 : : *
6241 : : * @return
6242 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6243 : : */
6244 : : static int
6245 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6246 : : uint64_t *sub_action_flags,
6247 : : const struct rte_flow_action *action,
6248 : : struct rte_eth_dev *dev,
6249 : : const struct rte_flow_attr *attr,
6250 : : uint64_t item_flags,
6251 : : const struct rte_flow_action_rss *rss,
6252 : : const struct rte_flow_action_rss **sample_rss,
6253 : : const struct rte_flow_action_count **count,
6254 : : int *fdb_mirror,
6255 : : uint16_t *sample_port_id,
6256 : : bool root,
6257 : : struct rte_flow_error *error)
6258 : : {
6259 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6260 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6261 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6262 : : const struct rte_flow_action_port_id *port = NULL;
6263 : : const struct rte_flow_action *act;
6264 : : uint16_t queue_index = 0xFFFF;
6265 : 0 : int actions_n = 0;
6266 : : int ret;
6267 : :
6268 [ # # ]: 0 : if (!sample)
6269 : 0 : return rte_flow_error_set(error, EINVAL,
6270 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6271 : : "configuration cannot be NULL");
6272 [ # # ]: 0 : if (sample->ratio == 0)
6273 : 0 : return rte_flow_error_set(error, EINVAL,
6274 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6275 : : "ratio value starts from 1");
6276 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6277 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6278 : 0 : return rte_flow_error_set(error, ENOTSUP,
6279 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6280 : : NULL,
6281 : : "sample action not supported");
6282 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6283 : 0 : return rte_flow_error_set(error, EINVAL,
6284 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6285 : : "Multiple sample actions not "
6286 : : "supported");
6287 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6288 : 0 : return rte_flow_error_set(error, EINVAL,
6289 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6290 : : "wrong action order, meter should "
6291 : : "be after sample action");
6292 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6293 : 0 : return rte_flow_error_set(error, EINVAL,
6294 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6295 : : "wrong action order, jump should "
6296 : : "be after sample action");
6297 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6298 : 0 : return rte_flow_error_set(error, EINVAL,
6299 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6300 : : "Sample after CT not supported");
6301 : 0 : act = sample->actions;
6302 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6303 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6304 : 0 : return rte_flow_error_set(error, ENOTSUP,
6305 : : RTE_FLOW_ERROR_TYPE_ACTION,
6306 : : act, "too many actions");
6307 [ # # # # : 0 : switch (act->type) {
# # # # ]
6308 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6309 : 0 : ret = mlx5_flow_validate_action_queue(act,
6310 : : *sub_action_flags,
6311 : : dev,
6312 : : attr, error);
6313 [ # # ]: 0 : if (ret < 0)
6314 : 0 : return ret;
6315 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6316 : 0 : (act->conf))->index;
6317 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6318 : 0 : ++actions_n;
6319 : 0 : break;
6320 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6321 : 0 : *sample_rss = act->conf;
6322 : 0 : ret = mlx5_flow_validate_action_rss(act,
6323 : : *sub_action_flags,
6324 : : dev, attr,
6325 : : item_flags,
6326 : : error);
6327 [ # # ]: 0 : if (ret < 0)
6328 : 0 : return ret;
6329 [ # # # # ]: 0 : if (rss && *sample_rss &&
6330 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6331 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6332 : 0 : return rte_flow_error_set(error, ENOTSUP,
6333 : : RTE_FLOW_ERROR_TYPE_ACTION,
6334 : : NULL,
6335 : : "Can't use the different RSS types "
6336 : : "or level in the same flow");
6337 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6338 : 0 : queue_index = (*sample_rss)->queue[0];
6339 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6340 : 0 : ++actions_n;
6341 : 0 : break;
6342 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6343 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6344 : : *sub_action_flags,
6345 : : attr, error);
6346 [ # # ]: 0 : if (ret < 0)
6347 : 0 : return ret;
6348 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6349 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6350 : : MLX5_FLOW_ACTION_MARK_EXT;
6351 : : else
6352 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6353 : 0 : ++actions_n;
6354 : 0 : break;
6355 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6356 : 0 : ret = flow_dv_validate_action_count
6357 : 0 : (dev, false, *action_flags | *sub_action_flags,
6358 : : root, error);
6359 [ # # ]: 0 : if (ret < 0)
6360 : 0 : return ret;
6361 : 0 : *count = act->conf;
6362 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6363 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6364 : 0 : ++actions_n;
6365 : 0 : break;
6366 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6367 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6368 : 0 : ret = flow_dv_validate_action_port_id(dev,
6369 : : *sub_action_flags,
6370 : : act,
6371 : : attr,
6372 : : error);
6373 [ # # ]: 0 : if (ret)
6374 : 0 : return ret;
6375 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6376 : 0 : port = (const struct rte_flow_action_port_id *)
6377 : : act->conf;
6378 [ # # ]: 0 : *sample_port_id = port->original ?
6379 : 0 : dev->data->port_id : port->id;
6380 : : } else {
6381 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6382 : 0 : act->conf)->port_id;
6383 : : }
6384 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6385 : 0 : ++actions_n;
6386 : 0 : break;
6387 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6388 : 0 : ret = flow_dv_validate_action_raw_encap_decap
6389 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6390 : : &actions_n, action, item_flags, error);
6391 [ # # ]: 0 : if (ret < 0)
6392 : 0 : return ret;
6393 : 0 : ++actions_n;
6394 : 0 : break;
6395 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6396 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6397 : 0 : ret = flow_dv_validate_action_l2_encap(dev,
6398 : : *sub_action_flags,
6399 : : act, attr,
6400 : : error);
6401 [ # # ]: 0 : if (ret < 0)
6402 : 0 : return ret;
6403 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6404 : 0 : ++actions_n;
6405 : 0 : break;
6406 : 0 : default:
6407 : 0 : return rte_flow_error_set(error, ENOTSUP,
6408 : : RTE_FLOW_ERROR_TYPE_ACTION,
6409 : : NULL,
6410 : : "Doesn't support optional "
6411 : : "action");
6412 : : }
6413 : : }
6414 [ # # ]: 0 : if (attr->ingress) {
6415 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6416 : : MLX5_FLOW_ACTION_RSS)))
6417 : 0 : return rte_flow_error_set(error, EINVAL,
6418 : : RTE_FLOW_ERROR_TYPE_ACTION,
6419 : : NULL,
6420 : : "Ingress must has a dest "
6421 : : "QUEUE for Sample");
6422 [ # # ]: 0 : } else if (attr->egress) {
6423 : 0 : return rte_flow_error_set(error, ENOTSUP,
6424 : : RTE_FLOW_ERROR_TYPE_ACTION,
6425 : : NULL,
6426 : : "Sample Only support Ingress "
6427 : : "or E-Switch");
6428 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6429 : : MLX5_ASSERT(attr->transfer);
6430 [ # # ]: 0 : if (sample->ratio > 1)
6431 : 0 : return rte_flow_error_set(error, ENOTSUP,
6432 : : RTE_FLOW_ERROR_TYPE_ACTION,
6433 : : NULL,
6434 : : "E-Switch doesn't support "
6435 : : "any optional action "
6436 : : "for sampling");
6437 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6438 : 0 : return rte_flow_error_set(error, ENOTSUP,
6439 : : RTE_FLOW_ERROR_TYPE_ACTION,
6440 : : NULL,
6441 : : "unsupported action QUEUE");
6442 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6443 : 0 : return rte_flow_error_set(error, ENOTSUP,
6444 : : RTE_FLOW_ERROR_TYPE_ACTION,
6445 : : NULL,
6446 : : "unsupported action QUEUE");
6447 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6448 : 0 : return rte_flow_error_set(error, EINVAL,
6449 : : RTE_FLOW_ERROR_TYPE_ACTION,
6450 : : NULL,
6451 : : "E-Switch must has a dest "
6452 : : "port for mirroring");
6453 : 0 : *fdb_mirror = 1;
6454 : : }
6455 : : /* Continue validation for Xcap actions.*/
6456 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6457 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6458 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6459 : : MLX5_FLOW_XCAP_ACTIONS)
6460 : 0 : return rte_flow_error_set(error, ENOTSUP,
6461 : : RTE_FLOW_ERROR_TYPE_ACTION,
6462 : : NULL, "encap and decap "
6463 : : "combination aren't "
6464 : : "supported");
6465 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6466 : 0 : return rte_flow_error_set(error, ENOTSUP,
6467 : : RTE_FLOW_ERROR_TYPE_ACTION,
6468 : : NULL, "encap is not supported"
6469 : : " for ingress traffic");
6470 : : }
6471 : : return 0;
6472 : : }
6473 : :
6474 : : /**
6475 : : * Find existing modify-header resource or create and register a new one.
6476 : : *
6477 : : * @param dev[in, out]
6478 : : * Pointer to rte_eth_dev structure.
6479 : : * @param[in, out] resource
6480 : : * Pointer to modify-header resource.
6481 : : * @parm[in, out] dev_flow
6482 : : * Pointer to the dev_flow.
6483 : : * @param[out] error
6484 : : * pointer to error structure.
6485 : : *
6486 : : * @return
6487 : : * 0 on success otherwise -errno and errno is set.
6488 : : */
6489 : : static int
6490 : 0 : flow_dv_modify_hdr_resource_register
6491 : : (struct rte_eth_dev *dev,
6492 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6493 : : struct mlx5_flow *dev_flow,
6494 : : struct rte_flow_error *error)
6495 : : {
6496 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6497 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6498 : 0 : uint32_t key_len = sizeof(*resource) -
6499 : : offsetof(typeof(*resource), ft_type) +
6500 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6501 : : struct mlx5_list_entry *entry;
6502 : 0 : struct mlx5_flow_cb_ctx ctx = {
6503 : : .error = error,
6504 : : .data = resource,
6505 : : };
6506 : : struct mlx5_hlist *modify_cmds;
6507 : : uint64_t key64;
6508 : :
6509 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6510 : : "hdr_modify",
6511 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6512 : : true, false, sh,
6513 : : flow_dv_modify_create_cb,
6514 : : flow_dv_modify_match_cb,
6515 : : flow_dv_modify_remove_cb,
6516 : : flow_dv_modify_clone_cb,
6517 : : flow_dv_modify_clone_free_cb,
6518 : : error);
6519 [ # # ]: 0 : if (unlikely(!modify_cmds))
6520 : 0 : return -rte_errno;
6521 : 0 : resource->root = !dev_flow->dv.group;
6522 [ # # # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6523 : : resource->root))
6524 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6525 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6526 : : "too many modify header items");
6527 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6528 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6529 [ # # ]: 0 : if (!entry)
6530 : 0 : return -rte_errno;
6531 : : resource = container_of(entry, typeof(*resource), entry);
6532 : 0 : dev_flow->handle->dvh.modify_hdr = resource;
6533 : 0 : return 0;
6534 : : }
6535 : :
6536 : : /**
6537 : : * Get DV flow counter by index.
6538 : : *
6539 : : * @param[in] dev
6540 : : * Pointer to the Ethernet device structure.
6541 : : * @param[in] idx
6542 : : * mlx5 flow counter index in the container.
6543 : : * @param[out] ppool
6544 : : * mlx5 flow counter pool in the container.
6545 : : *
6546 : : * @return
6547 : : * Pointer to the counter, NULL otherwise.
6548 : : */
6549 : : static struct mlx5_flow_counter *
6550 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6551 : : uint32_t idx,
6552 : : struct mlx5_flow_counter_pool **ppool)
6553 : : {
6554 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6555 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6556 : : struct mlx5_flow_counter_pool *pool;
6557 : :
6558 : : /* Decrease to original index and clear shared bit. */
6559 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6560 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6561 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6562 : : MLX5_ASSERT(pool);
6563 : : if (ppool)
6564 : : *ppool = pool;
6565 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6566 : : }
6567 : :
6568 : : /**
6569 : : * Check the devx counter belongs to the pool.
6570 : : *
6571 : : * @param[in] pool
6572 : : * Pointer to the counter pool.
6573 : : * @param[in] id
6574 : : * The counter devx ID.
6575 : : *
6576 : : * @return
6577 : : * True if counter belongs to the pool, false otherwise.
6578 : : */
6579 : : static bool
6580 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6581 : : {
6582 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6583 : : MLX5_COUNTERS_PER_POOL;
6584 : :
6585 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6586 : : return true;
6587 : : return false;
6588 : : }
6589 : :
6590 : : /**
6591 : : * Get a pool by devx counter ID.
6592 : : *
6593 : : * @param[in] cmng
6594 : : * Pointer to the counter management.
6595 : : * @param[in] id
6596 : : * The counter devx ID.
6597 : : *
6598 : : * @return
6599 : : * The counter pool pointer if exists, NULL otherwise,
6600 : : */
6601 : : static struct mlx5_flow_counter_pool *
6602 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6603 : : {
6604 : : uint32_t i;
6605 : : struct mlx5_flow_counter_pool *pool = NULL;
6606 : :
6607 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6608 : : /* Check last used pool. */
6609 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6610 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6611 : : pool = cmng->pools[cmng->last_pool_idx];
6612 : 0 : goto out;
6613 : : }
6614 : : /* ID out of range means no suitable pool in the container. */
6615 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6616 : 0 : goto out;
6617 : : /*
6618 : : * Find the pool from the end of the container, since mostly counter
6619 : : * ID is sequence increasing, and the last pool should be the needed
6620 : : * one.
6621 : : */
6622 : 0 : i = cmng->n_valid;
6623 [ # # ]: 0 : while (i--) {
6624 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6625 : :
6626 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6627 : : pool = pool_tmp;
6628 : : break;
6629 : : }
6630 : : }
6631 : 0 : out:
6632 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6633 : 0 : return pool;
6634 : : }
6635 : :
6636 : : /**
6637 : : * Query a devx flow counter.
6638 : : *
6639 : : * @param[in] dev
6640 : : * Pointer to the Ethernet device structure.
6641 : : * @param[in] counter
6642 : : * Index to the flow counter.
6643 : : * @param[out] pkts
6644 : : * The statistics value of packets.
6645 : : * @param[out] bytes
6646 : : * The statistics value of bytes.
6647 : : *
6648 : : * @return
6649 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6650 : : */
6651 : : static inline int
6652 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6653 : : uint64_t *bytes)
6654 : : {
6655 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6656 : : struct mlx5_flow_counter_pool *pool = NULL;
6657 : : struct mlx5_flow_counter *cnt;
6658 : : int offset;
6659 : :
6660 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6661 : : MLX5_ASSERT(pool);
6662 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6663 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6664 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6665 : 0 : rte_spinlock_lock(&pool->sl);
6666 [ # # ]: 0 : if (!pool->raw) {
6667 : 0 : *pkts = 0;
6668 : 0 : *bytes = 0;
6669 : : } else {
6670 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6671 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6672 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6673 : : }
6674 : : rte_spinlock_unlock(&pool->sl);
6675 : 0 : return 0;
6676 : : }
6677 : :
6678 : : /**
6679 : : * Create and initialize a new counter pool.
6680 : : *
6681 : : * @param[in] dev
6682 : : * Pointer to the Ethernet device structure.
6683 : : * @param[out] dcs
6684 : : * The devX counter handle.
6685 : : * @param[in] age
6686 : : * Whether the pool is for counter that was allocated for aging.
6687 : : *
6688 : : * @return
6689 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6690 : : */
6691 : : static struct mlx5_flow_counter_pool *
6692 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6693 : : uint32_t age)
6694 : : {
6695 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6696 : : struct mlx5_flow_counter_pool *pool;
6697 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6698 : 0 : bool fallback = cmng->counter_fallback;
6699 : : uint32_t size = sizeof(*pool);
6700 : :
6701 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6702 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6703 : 0 : rte_errno = EAGAIN;
6704 : 0 : return NULL;
6705 : : }
6706 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6707 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6708 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6709 [ # # ]: 0 : if (!pool) {
6710 : 0 : rte_errno = ENOMEM;
6711 : 0 : return NULL;
6712 : : }
6713 : 0 : pool->raw = NULL;
6714 : 0 : pool->is_aged = !!age;
6715 : 0 : pool->query_gen = 0;
6716 : 0 : pool->min_dcs = dcs;
6717 : : rte_spinlock_init(&pool->sl);
6718 : : rte_spinlock_init(&pool->csl);
6719 : 0 : TAILQ_INIT(&pool->counters[0]);
6720 : 0 : TAILQ_INIT(&pool->counters[1]);
6721 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6722 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6723 : 0 : pool->index = cmng->n_valid;
6724 : 0 : cmng->pools[pool->index] = pool;
6725 : 0 : cmng->n_valid++;
6726 [ # # ]: 0 : if (unlikely(fallback)) {
6727 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6728 : :
6729 [ # # ]: 0 : if (base < cmng->min_id)
6730 : 0 : cmng->min_id = base;
6731 [ # # ]: 0 : if (base > cmng->max_id)
6732 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6733 : 0 : cmng->last_pool_idx = pool->index;
6734 : : }
6735 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6736 : 0 : return pool;
6737 : : }
6738 : :
6739 : : /**
6740 : : * Prepare a new counter and/or a new counter pool.
6741 : : *
6742 : : * @param[in] dev
6743 : : * Pointer to the Ethernet device structure.
6744 : : * @param[out] cnt_free
6745 : : * Where to put the pointer of a new counter.
6746 : : * @param[in] age
6747 : : * Whether the pool is for counter that was allocated for aging.
6748 : : *
6749 : : * @return
6750 : : * The counter pool pointer and @p cnt_free is set on success,
6751 : : * NULL otherwise and rte_errno is set.
6752 : : */
6753 : : static struct mlx5_flow_counter_pool *
6754 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6755 : : struct mlx5_flow_counter **cnt_free,
6756 : : uint32_t age)
6757 : : {
6758 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6759 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6760 : : struct mlx5_flow_counter_pool *pool;
6761 : : struct mlx5_counters tmp_tq;
6762 : : struct mlx5_devx_obj *dcs = NULL;
6763 : : struct mlx5_flow_counter *cnt;
6764 : 0 : enum mlx5_counter_type cnt_type =
6765 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6766 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6767 : : uint32_t i;
6768 : :
6769 [ # # ]: 0 : if (fallback) {
6770 : : /* bulk_bitmap must be 0 for single counter allocation. */
6771 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6772 [ # # ]: 0 : if (!dcs)
6773 : : return NULL;
6774 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6775 [ # # ]: 0 : if (!pool) {
6776 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6777 [ # # ]: 0 : if (!pool) {
6778 : 0 : mlx5_devx_cmd_destroy(dcs);
6779 : 0 : return NULL;
6780 : : }
6781 : : }
6782 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6783 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6784 : 0 : cnt->pool = pool;
6785 : 0 : cnt->dcs_when_free = dcs;
6786 : 0 : *cnt_free = cnt;
6787 : 0 : return pool;
6788 : : }
6789 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6790 [ # # ]: 0 : if (!dcs) {
6791 : 0 : rte_errno = ENODATA;
6792 : 0 : return NULL;
6793 : : }
6794 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6795 [ # # ]: 0 : if (!pool) {
6796 : 0 : mlx5_devx_cmd_destroy(dcs);
6797 : 0 : return NULL;
6798 : : }
6799 : 0 : TAILQ_INIT(&tmp_tq);
6800 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6801 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6802 : 0 : cnt->pool = pool;
6803 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6804 : : }
6805 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6806 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6807 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6808 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6809 : 0 : (*cnt_free)->pool = pool;
6810 : 0 : return pool;
6811 : : }
6812 : :
6813 : : /**
6814 : : * Allocate a flow counter.
6815 : : *
6816 : : * @param[in] dev
6817 : : * Pointer to the Ethernet device structure.
6818 : : * @param[in] age
6819 : : * Whether the counter was allocated for aging.
6820 : : *
6821 : : * @return
6822 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6823 : : */
6824 : : static uint32_t
6825 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6826 : : {
6827 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6828 : : struct mlx5_flow_counter_pool *pool = NULL;
6829 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6830 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6831 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6832 : 0 : enum mlx5_counter_type cnt_type =
6833 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6834 : : uint32_t cnt_idx;
6835 : :
6836 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6837 : 0 : rte_errno = ENOTSUP;
6838 : 0 : return 0;
6839 : : }
6840 : : /* Get free counters from container. */
6841 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6842 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6843 [ # # ]: 0 : if (cnt_free)
6844 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6845 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6846 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6847 : 0 : goto err;
6848 : 0 : pool = cnt_free->pool;
6849 [ # # ]: 0 : if (fallback)
6850 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6851 : : /* Create a DV counter action only in the first time usage. */
6852 [ # # ]: 0 : if (!cnt_free->action) {
6853 : : uint16_t offset;
6854 : : struct mlx5_devx_obj *dcs;
6855 : : int ret;
6856 : :
6857 [ # # ]: 0 : if (!fallback) {
6858 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6859 : 0 : dcs = pool->min_dcs;
6860 : : } else {
6861 : : offset = 0;
6862 : 0 : dcs = cnt_free->dcs_when_free;
6863 : : }
6864 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6865 : : &cnt_free->action);
6866 : : if (ret) {
6867 : 0 : rte_errno = errno;
6868 : 0 : goto err;
6869 : : }
6870 : : }
6871 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6872 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6873 : : /* Update the counter reset values. */
6874 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6875 : : &cnt_free->bytes))
6876 : 0 : goto err;
6877 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
6878 : : /* Start the asynchronous batch query by the host thread. */
6879 : 0 : mlx5_set_query_alarm(priv->sh);
6880 : : /*
6881 : : * When the count action isn't shared (by ID), shared_info field is
6882 : : * used for indirect action API's refcnt.
6883 : : * When the counter action is not shared neither by ID nor by indirect
6884 : : * action API, shared info must be 1.
6885 : : */
6886 : 0 : cnt_free->shared_info.refcnt = 1;
6887 : 0 : return cnt_idx;
6888 : 0 : err:
6889 [ # # ]: 0 : if (cnt_free) {
6890 : 0 : cnt_free->pool = pool;
6891 [ # # ]: 0 : if (fallback)
6892 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6893 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
6894 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6895 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6896 : : }
6897 : : return 0;
6898 : : }
6899 : :
6900 : : /**
6901 : : * Get age param from counter index.
6902 : : *
6903 : : * @param[in] dev
6904 : : * Pointer to the Ethernet device structure.
6905 : : * @param[in] counter
6906 : : * Index to the counter handler.
6907 : : *
6908 : : * @return
6909 : : * The aging parameter specified for the counter index.
6910 : : */
6911 : : static struct mlx5_age_param*
6912 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6913 : : uint32_t counter)
6914 : : {
6915 : : struct mlx5_flow_counter *cnt;
6916 : : struct mlx5_flow_counter_pool *pool = NULL;
6917 : :
6918 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
6919 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6920 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
6921 : 0 : return MLX5_CNT_TO_AGE(cnt);
6922 : : }
6923 : :
6924 : : /**
6925 : : * Remove a flow counter from aged counter list.
6926 : : *
6927 : : * @param[in] dev
6928 : : * Pointer to the Ethernet device structure.
6929 : : * @param[in] counter
6930 : : * Index to the counter handler.
6931 : : * @param[in] cnt
6932 : : * Pointer to the counter handler.
6933 : : */
6934 : : static void
6935 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6936 : : uint32_t counter, struct mlx5_flow_counter *cnt)
6937 : : {
6938 : : struct mlx5_age_info *age_info;
6939 : : struct mlx5_age_param *age_param;
6940 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6941 : : uint16_t expected = AGE_CANDIDATE;
6942 : :
6943 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
6944 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
6945 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6946 : : AGE_FREE, false, __ATOMIC_RELAXED,
6947 : : __ATOMIC_RELAXED)) {
6948 : : /**
6949 : : * We need the lock even it is age timeout,
6950 : : * since counter may still in process.
6951 : : */
6952 : 0 : rte_spinlock_lock(&age_info->aged_sl);
6953 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6954 : : rte_spinlock_unlock(&age_info->aged_sl);
6955 : 0 : __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6956 : : }
6957 : 0 : }
6958 : :
6959 : : /**
6960 : : * Release a flow counter.
6961 : : *
6962 : : * @param[in] dev
6963 : : * Pointer to the Ethernet device structure.
6964 : : * @param[in] counter
6965 : : * Index to the counter handler.
6966 : : */
6967 : : static void
6968 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6969 : : {
6970 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6971 : : struct mlx5_flow_counter_pool *pool = NULL;
6972 : : struct mlx5_flow_counter *cnt;
6973 : : enum mlx5_counter_type cnt_type;
6974 : :
6975 [ # # ]: 0 : if (!counter)
6976 : : return;
6977 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6978 : : MLX5_ASSERT(pool);
6979 [ # # ]: 0 : if (pool->is_aged) {
6980 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
6981 : : } else {
6982 : : /*
6983 : : * If the counter action is shared by indirect action API,
6984 : : * the atomic function reduces its references counter.
6985 : : * If after the reduction the action is still referenced, the
6986 : : * function returns here and does not release it.
6987 : : * When the counter action is not shared by
6988 : : * indirect action API, shared info is 1 before the reduction,
6989 : : * so this condition is failed and function doesn't return here.
6990 : : */
6991 [ # # ]: 0 : if (__atomic_fetch_sub(&cnt->shared_info.refcnt, 1,
6992 : : __ATOMIC_RELAXED) - 1)
6993 : : return;
6994 : : }
6995 : 0 : cnt->pool = pool;
6996 : : /*
6997 : : * Put the counter back to list to be updated in none fallback mode.
6998 : : * Currently, we are using two list alternately, while one is in query,
6999 : : * add the freed counter to the other list based on the pool query_gen
7000 : : * value. After query finishes, add counter the list to the global
7001 : : * container counter list. The list changes while query starts. In
7002 : : * this case, lock will not be needed as query callback and release
7003 : : * function both operate with the different list.
7004 : : */
7005 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7006 : 0 : rte_spinlock_lock(&pool->csl);
7007 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
7008 : : rte_spinlock_unlock(&pool->csl);
7009 : : } else {
7010 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7011 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7012 : : MLX5_COUNTER_TYPE_ORIGIN;
7013 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7014 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7015 : : cnt, next);
7016 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7017 : : }
7018 : : }
7019 : :
7020 : : /**
7021 : : * Resize a meter id container.
7022 : : *
7023 : : * @param[in] dev
7024 : : * Pointer to the Ethernet device structure.
7025 : : *
7026 : : * @return
7027 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7028 : : */
7029 : : static int
7030 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7031 : : {
7032 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7033 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7034 : 0 : &priv->sh->mtrmng->pools_mng;
7035 : 0 : void *old_pools = pools_mng->pools;
7036 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7037 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7038 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7039 : :
7040 [ # # ]: 0 : if (!pools) {
7041 : 0 : rte_errno = ENOMEM;
7042 : 0 : return -ENOMEM;
7043 : : }
7044 [ # # ]: 0 : if (!pools_mng->n)
7045 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7046 : 0 : mlx5_free(pools);
7047 : 0 : return -ENOMEM;
7048 : : }
7049 [ # # ]: 0 : if (old_pools)
7050 : 0 : memcpy(pools, old_pools, pools_mng->n *
7051 : : sizeof(struct mlx5_aso_mtr_pool *));
7052 : 0 : pools_mng->n = resize;
7053 : 0 : pools_mng->pools = pools;
7054 [ # # ]: 0 : if (old_pools)
7055 : 0 : mlx5_free(old_pools);
7056 : : return 0;
7057 : : }
7058 : :
7059 : : /**
7060 : : * Prepare a new meter and/or a new meter pool.
7061 : : *
7062 : : * @param[in] dev
7063 : : * Pointer to the Ethernet device structure.
7064 : : * @param[out] mtr_free
7065 : : * Where to put the pointer of a new meter.g.
7066 : : *
7067 : : * @return
7068 : : * The meter pool pointer and @mtr_free is set on success,
7069 : : * NULL otherwise and rte_errno is set.
7070 : : */
7071 : : static struct mlx5_aso_mtr_pool *
7072 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7073 : : {
7074 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7075 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7076 : : struct mlx5_aso_mtr_pool *pool = NULL;
7077 : : struct mlx5_devx_obj *dcs = NULL;
7078 : : uint32_t i;
7079 : : uint32_t log_obj_size;
7080 : :
7081 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7082 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7083 : 0 : priv->sh->cdev->pdn,
7084 : : log_obj_size);
7085 [ # # ]: 0 : if (!dcs) {
7086 : 0 : rte_errno = ENODATA;
7087 : 0 : return NULL;
7088 : : }
7089 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7090 [ # # ]: 0 : if (!pool) {
7091 : 0 : rte_errno = ENOMEM;
7092 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7093 : 0 : return NULL;
7094 : : }
7095 : 0 : pool->devx_obj = dcs;
7096 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7097 : 0 : pool->index = pools_mng->n_valid;
7098 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7099 : 0 : mlx5_free(pool);
7100 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7101 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7102 : 0 : return NULL;
7103 : : }
7104 : 0 : pools_mng->pools[pool->index] = pool;
7105 : 0 : pools_mng->n_valid++;
7106 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7107 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7108 : 0 : pool->mtrs[i].offset = i;
7109 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7110 : : }
7111 : 0 : pool->mtrs[0].offset = 0;
7112 : 0 : *mtr_free = &pool->mtrs[0];
7113 : 0 : return pool;
7114 : : }
7115 : :
7116 : : /**
7117 : : * Release a flow meter into pool.
7118 : : *
7119 : : * @param[in] dev
7120 : : * Pointer to the Ethernet device structure.
7121 : : * @param[in] mtr_idx
7122 : : * Index to aso flow meter.
7123 : : */
7124 : : static void
7125 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7126 : : {
7127 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7128 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7129 : 0 : &priv->sh->mtrmng->pools_mng;
7130 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7131 : :
7132 : : MLX5_ASSERT(aso_mtr);
7133 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7134 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7135 : 0 : aso_mtr->state = ASO_METER_FREE;
7136 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7137 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7138 : 0 : }
7139 : :
7140 : : /**
7141 : : * Allocate a aso flow meter.
7142 : : *
7143 : : * @param[in] dev
7144 : : * Pointer to the Ethernet device structure.
7145 : : *
7146 : : * @return
7147 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7148 : : */
7149 : : static uint32_t
7150 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7151 : : {
7152 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7153 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7154 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7155 : 0 : &priv->sh->mtrmng->pools_mng;
7156 : : struct mlx5_aso_mtr_pool *pool;
7157 : : uint32_t mtr_idx = 0;
7158 : :
7159 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7160 : 0 : rte_errno = ENOTSUP;
7161 : 0 : return 0;
7162 : : }
7163 : : /* Allocate the flow meter memory. */
7164 : : /* Get free meters from management. */
7165 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7166 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7167 [ # # ]: 0 : if (mtr_free)
7168 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7169 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7170 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7171 : 0 : return 0;
7172 : : }
7173 : 0 : mtr_free->state = ASO_METER_WAIT;
7174 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7175 : 0 : pool = container_of(mtr_free,
7176 : : struct mlx5_aso_mtr_pool,
7177 : : mtrs[mtr_free->offset]);
7178 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7179 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7180 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7181 : : struct rte_flow_error error;
7182 : : uint8_t reg_id;
7183 : :
7184 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7185 : 0 : mtr_free->fm.meter_action_g =
7186 : 0 : mlx5_glue->dv_create_flow_action_aso
7187 : 0 : (priv->sh->rx_domain,
7188 : 0 : pool->devx_obj->obj,
7189 : : mtr_free->offset,
7190 : : (1 << MLX5_FLOW_COLOR_GREEN),
7191 : 0 : reg_id - REG_C_0);
7192 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7193 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7194 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7195 : 0 : return 0;
7196 : : }
7197 : : }
7198 : : return mtr_idx;
7199 : : }
7200 : :
7201 : : /**
7202 : : * Verify the @p attributes will be correctly understood by the NIC and store
7203 : : * them in the @p flow if everything is correct.
7204 : : *
7205 : : * @param[in] dev
7206 : : * Pointer to dev struct.
7207 : : * @param[in] attributes
7208 : : * Pointer to flow attributes
7209 : : * @param[in] external
7210 : : * This flow rule is created by request external to PMD.
7211 : : * @param[out] error
7212 : : * Pointer to error structure.
7213 : : *
7214 : : * @return
7215 : : * - 0 on success and non root table.
7216 : : * - 1 on success and root table.
7217 : : * - a negative errno value otherwise and rte_errno is set.
7218 : : */
7219 : : static int
7220 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7221 : : const struct mlx5_flow_tunnel *tunnel,
7222 : : const struct rte_flow_attr *attributes,
7223 : : const struct flow_grp_info *grp_info,
7224 : : struct rte_flow_error *error)
7225 : : {
7226 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7227 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7228 : : int ret = 0;
7229 : :
7230 : : #ifndef HAVE_MLX5DV_DR
7231 : : RTE_SET_USED(tunnel);
7232 : : RTE_SET_USED(grp_info);
7233 : : if (attributes->group)
7234 : : return rte_flow_error_set(error, ENOTSUP,
7235 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7236 : : NULL,
7237 : : "groups are not supported");
7238 : : #else
7239 : 0 : uint32_t table = 0;
7240 : :
7241 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7242 : : grp_info, error);
7243 [ # # ]: 0 : if (ret)
7244 : : return ret;
7245 [ # # ]: 0 : if (!table)
7246 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7247 : : #endif
7248 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7249 : : attributes->priority > lowest_priority)
7250 : 0 : return rte_flow_error_set(error, ENOTSUP,
7251 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7252 : : NULL,
7253 : : "priority out of range");
7254 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7255 : 0 : return rte_flow_error_set(error, ENOTSUP,
7256 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7257 : : "E-Switch dr is not supported");
7258 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7259 : 0 : return rte_flow_error_set(error, EINVAL,
7260 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7261 : : "must specify exactly one of "
7262 : : "ingress, egress or transfer");
7263 : : }
7264 : : return ret;
7265 : : }
7266 : :
7267 : : static int
7268 : 0 : validate_integrity_bits(const struct rte_flow_item_integrity *mask,
7269 : : int64_t pattern_flags, uint64_t l3_flags,
7270 : : uint64_t l4_flags, uint64_t ip4_flag,
7271 : : struct rte_flow_error *error)
7272 : : {
7273 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7274 : 0 : return rte_flow_error_set(error, EINVAL,
7275 : : RTE_FLOW_ERROR_TYPE_ITEM,
7276 : : NULL, "missing L3 protocol");
7277 : :
7278 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7279 : 0 : return rte_flow_error_set(error, EINVAL,
7280 : : RTE_FLOW_ERROR_TYPE_ITEM,
7281 : : NULL, "missing IPv4 protocol");
7282 : :
7283 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7284 : 0 : return rte_flow_error_set(error, EINVAL,
7285 : : RTE_FLOW_ERROR_TYPE_ITEM,
7286 : : NULL, "missing L4 protocol");
7287 : :
7288 : : return 0;
7289 : : }
7290 : :
7291 : : static int
7292 : 0 : flow_dv_validate_item_integrity_post(const struct
7293 : : rte_flow_item *integrity_items[2],
7294 : : int64_t pattern_flags,
7295 : : struct rte_flow_error *error)
7296 : : {
7297 : : const struct rte_flow_item_integrity *mask;
7298 : : int ret;
7299 : :
7300 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7301 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7302 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7303 : : MLX5_FLOW_LAYER_OUTER_L3,
7304 : : MLX5_FLOW_LAYER_OUTER_L4,
7305 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7306 : : error);
7307 [ # # ]: 0 : if (ret)
7308 : : return ret;
7309 : : }
7310 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7311 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7312 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7313 : : MLX5_FLOW_LAYER_INNER_L3,
7314 : : MLX5_FLOW_LAYER_INNER_L4,
7315 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7316 : : error);
7317 [ # # ]: 0 : if (ret)
7318 : 0 : return ret;
7319 : : }
7320 : : return 0;
7321 : : }
7322 : :
7323 : : static int
7324 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7325 : : const struct rte_flow_item *integrity_item,
7326 : : uint64_t pattern_flags, uint64_t *last_item,
7327 : : const struct rte_flow_item *integrity_items[2],
7328 : : struct rte_flow_error *error)
7329 : : {
7330 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7331 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7332 : : integrity_item->mask;
7333 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7334 : : integrity_item->spec;
7335 : :
7336 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7337 : 0 : return rte_flow_error_set(error, ENOTSUP,
7338 : : RTE_FLOW_ERROR_TYPE_ITEM,
7339 : : integrity_item,
7340 : : "packet integrity integrity_item not supported");
7341 [ # # ]: 0 : if (!spec)
7342 : 0 : return rte_flow_error_set(error, ENOTSUP,
7343 : : RTE_FLOW_ERROR_TYPE_ITEM,
7344 : : integrity_item,
7345 : : "no spec for integrity item");
7346 [ # # ]: 0 : if (!mask)
7347 : : mask = &rte_flow_item_integrity_mask;
7348 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7349 : 0 : return rte_flow_error_set(error, ENOTSUP,
7350 : : RTE_FLOW_ERROR_TYPE_ITEM,
7351 : : integrity_item,
7352 : : "unsupported integrity filter");
7353 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7354 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7355 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7356 : 0 : return rte_flow_error_set(error, EINVAL,
7357 : : RTE_FLOW_ERROR_TYPE_ITEM,
7358 : : NULL, "negative integrity flow is not supported");
7359 [ # # ]: 0 : if (spec->level > 1) {
7360 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7361 : 0 : return rte_flow_error_set
7362 : : (error, ENOTSUP,
7363 : : RTE_FLOW_ERROR_TYPE_ITEM,
7364 : : NULL, "multiple inner integrity items not supported");
7365 : 0 : integrity_items[1] = integrity_item;
7366 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7367 : : } else {
7368 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7369 : 0 : return rte_flow_error_set
7370 : : (error, ENOTSUP,
7371 : : RTE_FLOW_ERROR_TYPE_ITEM,
7372 : : NULL, "multiple outer integrity items not supported");
7373 : 0 : integrity_items[0] = integrity_item;
7374 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7375 : : }
7376 : : return 0;
7377 : : }
7378 : :
7379 : : static int
7380 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7381 : : const struct rte_flow_item *item,
7382 : : uint64_t item_flags,
7383 : : uint64_t *last_item,
7384 : : bool is_inner,
7385 : : struct rte_flow_error *error)
7386 : : {
7387 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7388 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7389 : : struct mlx5_flex_item *flex;
7390 : :
7391 [ # # ]: 0 : if (!flow_spec)
7392 : 0 : return rte_flow_error_set(error, EINVAL,
7393 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7394 : : "flex flow item spec cannot be NULL");
7395 [ # # ]: 0 : if (!flow_mask)
7396 : 0 : return rte_flow_error_set(error, EINVAL,
7397 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7398 : : "flex flow item mask cannot be NULL");
7399 [ # # ]: 0 : if (item->last)
7400 : 0 : return rte_flow_error_set(error, ENOTSUP,
7401 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7402 : : "flex flow item last not supported");
7403 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7404 : 0 : return rte_flow_error_set(error, EINVAL,
7405 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7406 : : "invalid flex flow item handle");
7407 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7408 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7409 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7410 [ # # ]: 0 : if (item_flags &
7411 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7412 : 0 : rte_flow_error_set(error, EINVAL,
7413 : : RTE_FLOW_ERROR_TYPE_ITEM,
7414 : : NULL, "multiple flex items not supported");
7415 : : break;
7416 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7417 [ # # ]: 0 : if (is_inner)
7418 : 0 : rte_flow_error_set(error, EINVAL,
7419 : : RTE_FLOW_ERROR_TYPE_ITEM,
7420 : : NULL, "inner flex item was not configured");
7421 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7422 : 0 : rte_flow_error_set(error, ENOTSUP,
7423 : : RTE_FLOW_ERROR_TYPE_ITEM,
7424 : : NULL, "multiple flex items not supported");
7425 : : break;
7426 : 0 : case FLEX_TUNNEL_MODE_INNER:
7427 [ # # ]: 0 : if (!is_inner)
7428 : 0 : rte_flow_error_set(error, EINVAL,
7429 : : RTE_FLOW_ERROR_TYPE_ITEM,
7430 : : NULL, "outer flex item was not configured");
7431 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7432 : 0 : rte_flow_error_set(error, EINVAL,
7433 : : RTE_FLOW_ERROR_TYPE_ITEM,
7434 : : NULL, "multiple flex items not supported");
7435 : : break;
7436 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7437 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7438 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7439 : 0 : rte_flow_error_set(error, EINVAL,
7440 : : RTE_FLOW_ERROR_TYPE_ITEM,
7441 : : NULL, "multiple flex items not supported");
7442 : : }
7443 : : break;
7444 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7445 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7446 : 0 : rte_flow_error_set(error, EINVAL,
7447 : : RTE_FLOW_ERROR_TYPE_ITEM,
7448 : : NULL, "multiple flex tunnel items not supported");
7449 : : break;
7450 : 0 : default:
7451 : 0 : rte_flow_error_set(error, EINVAL,
7452 : : RTE_FLOW_ERROR_TYPE_ITEM,
7453 : : NULL, "invalid flex item configuration");
7454 : : }
7455 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7456 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7457 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7458 : 0 : return 0;
7459 : : }
7460 : :
7461 : : /**
7462 : : * Validate IB BTH item.
7463 : : *
7464 : : * @param[in] dev
7465 : : * Pointer to the rte_eth_dev structure.
7466 : : * @param[in] udp_dport
7467 : : * UDP destination port
7468 : : * @param[in] item
7469 : : * Item specification.
7470 : : * @param root
7471 : : * Whether action is on root table.
7472 : : * @param[out] error
7473 : : * Pointer to the error structure.
7474 : : *
7475 : : * @return
7476 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7477 : : */
7478 : : static int
7479 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7480 : : uint16_t udp_dport,
7481 : : const struct rte_flow_item *item,
7482 : : bool root,
7483 : : struct rte_flow_error *error)
7484 : : {
7485 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7486 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7487 : : const struct rte_flow_item_ib_bth *valid_mask;
7488 : : int ret;
7489 : :
7490 : : valid_mask = &rte_flow_item_ib_bth_mask;
7491 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7492 : 0 : return rte_flow_error_set(error, EINVAL,
7493 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7494 : : "protocol filtering not compatible"
7495 : : " with UDP layer");
7496 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7497 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7498 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7499 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7500 : 0 : return rte_flow_error_set(error, EINVAL,
7501 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7502 : : "only opcode and dst_qp are supported");
7503 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7504 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7505 : 0 : return rte_flow_error_set(error, EINVAL,
7506 : : RTE_FLOW_ERROR_TYPE_ITEM,
7507 : : item,
7508 : : "IB BTH item is not supported");
7509 [ # # ]: 0 : if (!mask)
7510 : : mask = &rte_flow_item_ib_bth_mask;
7511 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
7512 : : (const uint8_t *)valid_mask,
7513 : : sizeof(struct rte_flow_item_ib_bth),
7514 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7515 : : if (ret < 0)
7516 : : return ret;
7517 : : return 0;
7518 : : }
7519 : :
7520 : : /**
7521 : : * Internal validation function. For validating both actions and items.
7522 : : *
7523 : : * @param[in] dev
7524 : : * Pointer to the rte_eth_dev structure.
7525 : : * @param[in] attr
7526 : : * Pointer to the flow attributes.
7527 : : * @param[in] items
7528 : : * Pointer to the list of items.
7529 : : * @param[in] actions
7530 : : * Pointer to the list of actions.
7531 : : * @param[in] external
7532 : : * This flow rule is created by request external to PMD.
7533 : : * @param[in] hairpin
7534 : : * Number of hairpin TX actions, 0 means classic flow.
7535 : : * @param[out] error
7536 : : * Pointer to the error structure.
7537 : : *
7538 : : * @return
7539 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7540 : : */
7541 : : static int
7542 : 0 : flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7543 : : const struct rte_flow_item items[],
7544 : : const struct rte_flow_action actions[],
7545 : : bool external, int hairpin, struct rte_flow_error *error)
7546 : : {
7547 : : int ret;
7548 : 0 : uint64_t aso_mask, action_flags = 0;
7549 : 0 : uint64_t item_flags = 0;
7550 : 0 : uint64_t last_item = 0;
7551 : : uint8_t next_protocol = 0xff;
7552 : : uint16_t ether_type = 0;
7553 : 0 : int actions_n = 0;
7554 : : uint8_t item_ipv6_proto = 0;
7555 : 0 : int fdb_mirror = 0;
7556 : : int modify_after_mirror = 0;
7557 : : const struct rte_flow_item *geneve_item = NULL;
7558 : : const struct rte_flow_item *gre_item = NULL;
7559 : : const struct rte_flow_item *gtp_item = NULL;
7560 : : const struct rte_flow_action_raw_decap *decap;
7561 : : const struct rte_flow_action_raw_encap *encap;
7562 : : const struct rte_flow_action_rss *rss = NULL;
7563 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7564 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7565 : 0 : const struct rte_flow_item_tcp nic_tcp_mask = {
7566 : : .hdr = {
7567 : : .tcp_flags = 0xFF,
7568 : : .src_port = RTE_BE16(UINT16_MAX),
7569 : : .dst_port = RTE_BE16(UINT16_MAX),
7570 : : }
7571 : : };
7572 : 0 : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7573 : : .hdr = {
7574 : : .src_addr =
7575 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
7576 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
7577 : : .dst_addr =
7578 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
7579 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
7580 : : .vtc_flow = RTE_BE32(0xffffffff),
7581 : : .proto = 0xff,
7582 : : .hop_limits = 0xff,
7583 : : },
7584 : : .has_frag_ext = 1,
7585 : : };
7586 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7587 : : .hdr = {
7588 : : .common = {
7589 : : .u32 =
7590 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7591 : : .type = 0xFF,
7592 : : }).u32),
7593 : : },
7594 : : .dummy[0] = 0xffffffff,
7595 : : },
7596 : : };
7597 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7598 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7599 : : uint16_t queue_index = 0xFFFF;
7600 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7601 : : uint32_t rw_act_num = 0;
7602 : : uint64_t is_root;
7603 : : const struct mlx5_flow_tunnel *tunnel;
7604 : : enum mlx5_tof_rule_type tof_rule_type;
7605 : 0 : struct flow_grp_info grp_info = {
7606 : : .external = !!external,
7607 : 0 : .transfer = !!attr->transfer,
7608 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7609 : : .std_tbl_fix = true,
7610 : : };
7611 : : const struct rte_eth_hairpin_conf *conf;
7612 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7613 : : const struct rte_flow_item *port_id_item = NULL;
7614 : 0 : bool def_policy = false;
7615 : : bool shared_count = false;
7616 : : uint16_t udp_dport = 0;
7617 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7618 : : const struct rte_flow_action_age *non_shared_age = NULL;
7619 : : const struct rte_flow_action_count *count = NULL;
7620 : : const struct rte_flow_action_port_id *port = NULL;
7621 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7622 : 0 : struct mlx5_priv *act_priv = NULL;
7623 : : int aso_after_sample = 0;
7624 : : struct mlx5_priv *port_priv = NULL;
7625 : 0 : uint64_t sub_action_flags = 0;
7626 : 0 : uint16_t sample_port_id = 0;
7627 : : uint16_t port_id = 0;
7628 : :
7629 [ # # ]: 0 : if (items == NULL)
7630 : : return -1;
7631 : : tunnel = is_tunnel_offload_active(dev) ?
7632 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7633 [ # # ]: 0 : if (tunnel) {
7634 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7635 : 0 : return rte_flow_error_set
7636 : : (error, ENOTSUP,
7637 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7638 : : NULL, "tunnel offload requires DV flow interface");
7639 [ # # ]: 0 : if (priv->representor)
7640 : 0 : return rte_flow_error_set
7641 : : (error, ENOTSUP,
7642 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7643 : : NULL, "decap not supported for VF representor");
7644 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7645 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7646 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7647 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7648 : : MLX5_FLOW_ACTION_DECAP;
7649 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7650 : : (dev, attr, tunnel, tof_rule_type);
7651 : : }
7652 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7653 [ # # ]: 0 : if (ret < 0)
7654 : : return ret;
7655 : 0 : is_root = (uint64_t)ret;
7656 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7657 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7658 : 0 : int type = items->type;
7659 : :
7660 : : if (!mlx5_flow_os_item_supported(type))
7661 : : return rte_flow_error_set(error, ENOTSUP,
7662 : : RTE_FLOW_ERROR_TYPE_ITEM,
7663 : : NULL, "item not supported");
7664 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7665 : : case RTE_FLOW_ITEM_TYPE_VOID:
7666 : : break;
7667 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7668 : 0 : ret = mlx5_flow_os_validate_item_esp(items, item_flags,
7669 : : next_protocol,
7670 : : error);
7671 [ # # ]: 0 : if (ret < 0)
7672 : 0 : return ret;
7673 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7674 : 0 : break;
7675 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7676 : 0 : ret = flow_dv_validate_item_port_id
7677 : : (dev, items, attr, item_flags, &act_priv, error);
7678 [ # # ]: 0 : if (ret < 0)
7679 : 0 : return ret;
7680 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7681 : : port_id_item = items;
7682 : 0 : break;
7683 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7684 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7685 : 0 : ret = flow_dv_validate_item_represented_port
7686 : : (dev, items, attr, item_flags, &act_priv, error);
7687 [ # # ]: 0 : if (ret < 0)
7688 : 0 : return ret;
7689 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7690 : : port_id_item = items;
7691 : 0 : break;
7692 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7693 : 0 : ret = mlx5_flow_validate_item_eth(items, item_flags,
7694 : : true, error);
7695 [ # # ]: 0 : if (ret < 0)
7696 : 0 : return ret;
7697 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7698 : : MLX5_FLOW_LAYER_OUTER_L2;
7699 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7700 : 0 : ether_type =
7701 : : ((const struct rte_flow_item_eth *)
7702 : : items->spec)->hdr.ether_type;
7703 : 0 : ether_type &=
7704 : : ((const struct rte_flow_item_eth *)
7705 : 0 : items->mask)->hdr.ether_type;
7706 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7707 : : } else {
7708 : : ether_type = 0;
7709 : : }
7710 : : break;
7711 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7712 : 0 : ret = flow_dv_validate_item_vlan(items, item_flags,
7713 : : dev, error);
7714 [ # # ]: 0 : if (ret < 0)
7715 : 0 : return ret;
7716 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7717 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7718 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7719 : 0 : ether_type =
7720 : : ((const struct rte_flow_item_vlan *)
7721 : : items->spec)->hdr.eth_proto;
7722 : 0 : ether_type &=
7723 : : ((const struct rte_flow_item_vlan *)
7724 : 0 : items->mask)->hdr.eth_proto;
7725 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7726 : : } else {
7727 : : ether_type = 0;
7728 : : }
7729 : : /* Store outer VLAN mask for of_push_vlan action. */
7730 [ # # ]: 0 : if (!tunnel)
7731 : : vlan_m = items->mask;
7732 : : break;
7733 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
7734 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7735 : : &item_flags, &tunnel);
7736 : 0 : ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
7737 : : last_item, ether_type,
7738 : : error);
7739 [ # # ]: 0 : if (ret < 0)
7740 : 0 : return ret;
7741 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7742 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7743 [ # # ]: 0 : if (items->mask != NULL &&
7744 : : ((const struct rte_flow_item_ipv4 *)
7745 [ # # ]: 0 : items->mask)->hdr.next_proto_id) {
7746 : 0 : next_protocol =
7747 : : ((const struct rte_flow_item_ipv4 *)
7748 : 0 : (items->spec))->hdr.next_proto_id;
7749 : 0 : next_protocol &=
7750 : : ((const struct rte_flow_item_ipv4 *)
7751 : : (items->mask))->hdr.next_proto_id;
7752 : : } else {
7753 : : /* Reset for inner layer. */
7754 : : next_protocol = 0xff;
7755 : : }
7756 : : break;
7757 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
7758 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7759 : : &item_flags, &tunnel);
7760 : 0 : ret = mlx5_flow_validate_item_ipv6(items, item_flags,
7761 : : last_item,
7762 : : ether_type,
7763 : : &nic_ipv6_mask,
7764 : : error);
7765 [ # # ]: 0 : if (ret < 0)
7766 : 0 : return ret;
7767 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7768 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7769 [ # # ]: 0 : if (items->mask != NULL &&
7770 : : ((const struct rte_flow_item_ipv6 *)
7771 [ # # ]: 0 : items->mask)->hdr.proto) {
7772 : 0 : item_ipv6_proto =
7773 : : ((const struct rte_flow_item_ipv6 *)
7774 : 0 : items->spec)->hdr.proto;
7775 : : next_protocol =
7776 : : ((const struct rte_flow_item_ipv6 *)
7777 : : items->spec)->hdr.proto;
7778 : 0 : next_protocol &=
7779 : : ((const struct rte_flow_item_ipv6 *)
7780 : : items->mask)->hdr.proto;
7781 : : } else {
7782 : : /* Reset for inner layer. */
7783 : : next_protocol = 0xff;
7784 : : }
7785 : : break;
7786 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7787 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(items,
7788 : : item_flags,
7789 : : error);
7790 [ # # ]: 0 : if (ret < 0)
7791 : 0 : return ret;
7792 : 0 : last_item = tunnel ?
7793 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7794 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7795 [ # # ]: 0 : if (items->mask != NULL &&
7796 : : ((const struct rte_flow_item_ipv6_frag_ext *)
7797 [ # # ]: 0 : items->mask)->hdr.next_header) {
7798 : 0 : next_protocol =
7799 : : ((const struct rte_flow_item_ipv6_frag_ext *)
7800 : 0 : items->spec)->hdr.next_header;
7801 : 0 : next_protocol &=
7802 : : ((const struct rte_flow_item_ipv6_frag_ext *)
7803 : : items->mask)->hdr.next_header;
7804 : : } else {
7805 : : /* Reset for inner layer. */
7806 : : next_protocol = 0xff;
7807 : : }
7808 : : break;
7809 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
7810 : 0 : ret = mlx5_flow_validate_item_tcp
7811 : : (items, item_flags,
7812 : : next_protocol,
7813 : : &nic_tcp_mask,
7814 : : error);
7815 [ # # ]: 0 : if (ret < 0)
7816 : 0 : return ret;
7817 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7818 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
7819 : 0 : break;
7820 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
7821 : 0 : ret = mlx5_flow_validate_item_udp(items, item_flags,
7822 : : next_protocol,
7823 : : error);
7824 : 0 : const struct rte_flow_item_udp *spec = items->spec;
7825 : 0 : const struct rte_flow_item_udp *mask = items->mask;
7826 [ # # ]: 0 : if (!mask)
7827 : : mask = &rte_flow_item_udp_mask;
7828 [ # # ]: 0 : if (spec != NULL)
7829 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
7830 : : (spec->hdr.dst_port &
7831 : : mask->hdr.dst_port);
7832 [ # # ]: 0 : if (ret < 0)
7833 : 0 : return ret;
7834 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7835 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
7836 : 0 : break;
7837 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
7838 : 0 : ret = mlx5_flow_validate_item_gre(items, item_flags,
7839 : : next_protocol, error);
7840 [ # # ]: 0 : if (ret < 0)
7841 : 0 : return ret;
7842 : : gre_item = items;
7843 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
7844 : 0 : break;
7845 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
7846 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
7847 : : attr, gre_item, error);
7848 [ # # ]: 0 : if (ret < 0)
7849 : 0 : return ret;
7850 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
7851 : 0 : break;
7852 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
7853 : 0 : ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7854 : : next_protocol,
7855 : : error);
7856 [ # # ]: 0 : if (ret < 0)
7857 : 0 : return ret;
7858 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
7859 : 0 : break;
7860 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7861 : 0 : ret = mlx5_flow_validate_item_gre_key
7862 : : (items, item_flags, gre_item, error);
7863 [ # # ]: 0 : if (ret < 0)
7864 : 0 : return ret;
7865 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
7866 : 0 : break;
7867 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
7868 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7869 : : items, item_flags,
7870 : : is_root, error);
7871 [ # # ]: 0 : if (ret < 0)
7872 : 0 : return ret;
7873 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
7874 : 0 : break;
7875 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7876 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
7877 : : item_flags, dev,
7878 : : error);
7879 [ # # ]: 0 : if (ret < 0)
7880 : 0 : return ret;
7881 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7882 : 0 : break;
7883 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
7884 : 0 : ret = mlx5_flow_validate_item_geneve(items,
7885 : : item_flags, dev,
7886 : : error);
7887 [ # # ]: 0 : if (ret < 0)
7888 : 0 : return ret;
7889 : : geneve_item = items;
7890 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
7891 : 0 : break;
7892 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7893 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
7894 : : last_item,
7895 : : geneve_item,
7896 : : dev,
7897 : : error);
7898 [ # # ]: 0 : if (ret < 0)
7899 : 0 : return ret;
7900 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7901 : 0 : break;
7902 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
7903 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
7904 : : item_flags,
7905 : : last_item, error);
7906 [ # # ]: 0 : if (ret < 0)
7907 : 0 : return ret;
7908 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
7909 : 0 : break;
7910 : :
7911 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
7912 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
7913 : : error);
7914 [ # # ]: 0 : if (ret < 0)
7915 : 0 : return ret;
7916 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
7917 : 0 : break;
7918 : 0 : case RTE_FLOW_ITEM_TYPE_META:
7919 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
7920 : : error);
7921 [ # # ]: 0 : if (ret < 0)
7922 : 0 : return ret;
7923 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
7924 : 0 : break;
7925 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
7926 : 0 : ret = mlx5_flow_validate_item_icmp(items, item_flags,
7927 : : next_protocol,
7928 : : error);
7929 [ # # ]: 0 : if (ret < 0)
7930 : 0 : return ret;
7931 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
7932 : 0 : break;
7933 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
7934 : 0 : ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7935 : : next_protocol,
7936 : : error);
7937 [ # # ]: 0 : if (ret < 0)
7938 : 0 : return ret;
7939 : : item_ipv6_proto = IPPROTO_ICMPV6;
7940 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
7941 : 0 : break;
7942 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
7943 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
7944 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(items,
7945 : : item_flags,
7946 : : next_protocol,
7947 : : error);
7948 [ # # ]: 0 : if (ret < 0)
7949 : 0 : return ret;
7950 : : item_ipv6_proto = IPPROTO_ICMPV6;
7951 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
7952 : 0 : break;
7953 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
7954 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
7955 : : attr, error);
7956 [ # # ]: 0 : if (ret < 0)
7957 : 0 : return ret;
7958 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
7959 : 0 : break;
7960 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
7961 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
7962 : 0 : break;
7963 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7964 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
7965 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
7966 : 0 : return rte_flow_error_set(error, EINVAL,
7967 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
7968 : : items->spec,
7969 : : "Duplicated tag index");
7970 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
7971 : 0 : break;
7972 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
7973 : 0 : ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7974 : : error);
7975 [ # # ]: 0 : if (ret < 0)
7976 : 0 : return ret;
7977 : : gtp_item = items;
7978 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
7979 : 0 : break;
7980 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7981 : 0 : ret = flow_dv_validate_item_gtp_psc(items, last_item,
7982 : : gtp_item, is_root,
7983 : : error);
7984 [ # # ]: 0 : if (ret < 0)
7985 : 0 : return ret;
7986 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
7987 : 0 : break;
7988 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
7989 : : /* Capacity will be checked in the translate stage. */
7990 : 0 : ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7991 : : last_item,
7992 : : ether_type,
7993 : : &nic_ecpri_mask,
7994 : : error);
7995 [ # # ]: 0 : if (ret < 0)
7996 : 0 : return ret;
7997 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
7998 : 0 : break;
7999 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8000 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8001 : : item_flags,
8002 : : &last_item,
8003 : : integrity_items,
8004 : : error);
8005 [ # # ]: 0 : if (ret < 0)
8006 : 0 : return ret;
8007 : : break;
8008 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8009 : 0 : ret = flow_dv_validate_item_aso_ct(dev, items,
8010 : : &item_flags, error);
8011 [ # # ]: 0 : if (ret < 0)
8012 : 0 : return ret;
8013 : : break;
8014 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8015 : : /* tunnel offload item was processed before
8016 : : * list it here as a supported type
8017 : : */
8018 : : break;
8019 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8020 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8021 : : &last_item,
8022 : : tunnel != 0, error);
8023 [ # # ]: 0 : if (ret < 0)
8024 : 0 : return ret;
8025 : : break;
8026 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8027 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8028 : : attr, error);
8029 [ # # ]: 0 : if (ret < 0)
8030 : 0 : return ret;
8031 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8032 : 0 : break;
8033 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8034 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8035 : : attr, error);
8036 [ # # ]: 0 : if (ret < 0)
8037 : 0 : return ret;
8038 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8039 : 0 : break;
8040 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8041 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8042 : : items, is_root, error);
8043 [ # # ]: 0 : if (ret < 0)
8044 : 0 : return ret;
8045 : :
8046 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8047 : 0 : break;
8048 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8049 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8050 [ # # ]: 0 : if (ret < 0)
8051 : 0 : return ret;
8052 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8053 : 0 : break;
8054 : 0 : default:
8055 : 0 : return rte_flow_error_set(error, ENOTSUP,
8056 : : RTE_FLOW_ERROR_TYPE_ITEM,
8057 : : NULL, "item not supported");
8058 : : }
8059 : 0 : item_flags |= last_item;
8060 : : }
8061 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8062 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8063 : : item_flags, error);
8064 [ # # ]: 0 : if (ret)
8065 : : return ret;
8066 : : }
8067 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8068 : 0 : int type = actions->type;
8069 : :
8070 : : if (!mlx5_flow_os_action_supported(type))
8071 : : return rte_flow_error_set(error, ENOTSUP,
8072 : : RTE_FLOW_ERROR_TYPE_ACTION,
8073 : : actions,
8074 : : "action not supported");
8075 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8076 : 0 : return rte_flow_error_set(error, ENOTSUP,
8077 : : RTE_FLOW_ERROR_TYPE_ACTION,
8078 : : actions, "too many actions");
8079 [ # # ]: 0 : if (action_flags &
8080 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8081 : 0 : return rte_flow_error_set(error, ENOTSUP,
8082 : : RTE_FLOW_ERROR_TYPE_ACTION,
8083 : : NULL, "meter action with policy "
8084 : : "must be the last action");
8085 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8086 : : case RTE_FLOW_ACTION_TYPE_VOID:
8087 : : break;
8088 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8089 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8090 : 0 : ret = flow_dv_validate_action_port_id(dev,
8091 : : action_flags,
8092 : : actions,
8093 : : attr,
8094 : : error);
8095 [ # # ]: 0 : if (ret)
8096 : 0 : return ret;
8097 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8098 : 0 : port = (const struct rte_flow_action_port_id *)
8099 : : actions->conf;
8100 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8101 : : } else {
8102 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8103 : 0 : actions->conf)->port_id;
8104 : : }
8105 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8106 : 0 : ++actions_n;
8107 : 0 : break;
8108 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8109 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8110 : : attr, error);
8111 [ # # ]: 0 : if (ret < 0)
8112 : 0 : return ret;
8113 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8114 : : /* Count all modify-header actions as one. */
8115 [ # # ]: 0 : if (!(action_flags &
8116 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8117 : 0 : ++actions_n;
8118 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8119 : : MLX5_FLOW_ACTION_MARK_EXT;
8120 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8121 : : modify_after_mirror = 1;
8122 : :
8123 : : } else {
8124 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8125 : 0 : ++actions_n;
8126 : : }
8127 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8128 : 0 : break;
8129 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8130 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8131 : : action_flags,
8132 : : attr, error);
8133 [ # # ]: 0 : if (ret < 0)
8134 : 0 : return ret;
8135 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8136 : : /* Count all modify-header actions as one. */
8137 [ # # ]: 0 : if (!(action_flags &
8138 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8139 : 0 : ++actions_n;
8140 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
8141 : : MLX5_FLOW_ACTION_MARK_EXT;
8142 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8143 : : modify_after_mirror = 1;
8144 : : } else {
8145 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8146 : 0 : ++actions_n;
8147 : : }
8148 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8149 : 0 : break;
8150 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8151 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8152 : : action_flags,
8153 : : attr, error);
8154 [ # # ]: 0 : if (ret < 0)
8155 : 0 : return ret;
8156 : : /* Count all modify-header actions as one action. */
8157 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8158 : 0 : ++actions_n;
8159 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8160 : : modify_after_mirror = 1;
8161 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8162 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8163 : 0 : break;
8164 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8165 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8166 : : action_flags,
8167 : : attr, error);
8168 [ # # ]: 0 : if (ret < 0)
8169 : 0 : return ret;
8170 : : /* Count all modify-header actions as one action. */
8171 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8172 : 0 : ++actions_n;
8173 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8174 : : modify_after_mirror = 1;
8175 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8176 : 0 : actions->conf)->index;
8177 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8178 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8179 : 0 : break;
8180 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8181 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8182 : : attr, error);
8183 [ # # ]: 0 : if (ret < 0)
8184 : 0 : return ret;
8185 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8186 : 0 : ++actions_n;
8187 : 0 : break;
8188 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8189 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8190 : : action_flags, dev,
8191 : : attr, error);
8192 [ # # ]: 0 : if (ret < 0)
8193 : 0 : return ret;
8194 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8195 : 0 : (actions->conf))->index;
8196 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8197 : 0 : ++actions_n;
8198 : 0 : break;
8199 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8200 : 0 : rss = actions->conf;
8201 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8202 : : action_flags, dev,
8203 : : attr, item_flags,
8204 : : error);
8205 [ # # ]: 0 : if (ret < 0)
8206 : 0 : return ret;
8207 [ # # ]: 0 : if (rss && sample_rss &&
8208 [ # # ]: 0 : (sample_rss->level != rss->level ||
8209 [ # # ]: 0 : sample_rss->types != rss->types))
8210 : 0 : return rte_flow_error_set(error, ENOTSUP,
8211 : : RTE_FLOW_ERROR_TYPE_ACTION,
8212 : : NULL,
8213 : : "Can't use the different RSS types "
8214 : : "or level in the same flow");
8215 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8216 : 0 : queue_index = rss->queue[0];
8217 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8218 : 0 : ++actions_n;
8219 : 0 : break;
8220 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8221 : : ret =
8222 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8223 : : attr, error);
8224 [ # # ]: 0 : if (ret < 0)
8225 : 0 : return ret;
8226 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8227 : 0 : ++actions_n;
8228 : 0 : break;
8229 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8230 : : shared_count = true;
8231 : : /* fall-through. */
8232 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8233 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8234 : : action_flags,
8235 : : is_root, error);
8236 [ # # ]: 0 : if (ret < 0)
8237 : 0 : return ret;
8238 : 0 : count = actions->conf;
8239 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8240 : 0 : ++actions_n;
8241 : 0 : break;
8242 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8243 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8244 : : action_flags,
8245 : : actions,
8246 : : item_flags, attr,
8247 : : error))
8248 : 0 : return -rte_errno;
8249 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8250 : : modify_after_mirror = 1;
8251 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8252 : 0 : ++actions_n;
8253 : 0 : break;
8254 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8255 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8256 : : action_flags,
8257 : : vlan_m,
8258 : : actions, attr,
8259 : : error);
8260 [ # # ]: 0 : if (ret < 0)
8261 : 0 : return ret;
8262 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8263 : : modify_after_mirror = 1;
8264 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8265 : 0 : ++actions_n;
8266 : 0 : break;
8267 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8268 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8269 : : (action_flags, actions, error);
8270 [ # # ]: 0 : if (ret < 0)
8271 : 0 : return ret;
8272 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8273 : : modify_after_mirror = 1;
8274 : : /* Count PCP with push_vlan command. */
8275 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8276 : 0 : break;
8277 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8278 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8279 : : (item_flags, action_flags,
8280 : : actions, error);
8281 [ # # ]: 0 : if (ret < 0)
8282 : 0 : return ret;
8283 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8284 : : modify_after_mirror = 1;
8285 : : /* Count VID with push_vlan command. */
8286 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8287 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8288 : 0 : break;
8289 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8290 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8291 : 0 : ret = flow_dv_validate_action_l2_encap(dev,
8292 : : action_flags,
8293 : : actions, attr,
8294 : : error);
8295 [ # # ]: 0 : if (ret < 0)
8296 : 0 : return ret;
8297 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8298 : 0 : ++actions_n;
8299 : 0 : break;
8300 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8301 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8302 : 0 : ret = flow_dv_validate_action_decap(dev, action_flags,
8303 : : actions, item_flags,
8304 : : attr, error);
8305 [ # # ]: 0 : if (ret < 0)
8306 : 0 : return ret;
8307 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8308 : : modify_after_mirror = 1;
8309 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8310 : 0 : ++actions_n;
8311 : 0 : break;
8312 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8313 : 0 : ret = flow_dv_validate_action_raw_encap_decap
8314 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8315 : : &actions_n, actions, item_flags, error);
8316 [ # # ]: 0 : if (ret < 0)
8317 : 0 : return ret;
8318 : : break;
8319 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8320 : 0 : decap = actions->conf;
8321 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8322 : : ;
8323 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8324 : : encap = NULL;
8325 : : actions--;
8326 : : } else {
8327 : 0 : encap = actions->conf;
8328 : : }
8329 [ # # ]: 0 : ret = flow_dv_validate_action_raw_encap_decap
8330 : : (dev,
8331 : : decap ? decap : &empty_decap, encap,
8332 : : attr, &action_flags, &actions_n,
8333 : : actions, item_flags, error);
8334 [ # # ]: 0 : if (ret < 0)
8335 : 0 : return ret;
8336 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8337 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8338 : : modify_after_mirror = 1;
8339 : : break;
8340 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8341 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8342 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8343 : : actions,
8344 : : item_flags,
8345 : : error);
8346 [ # # ]: 0 : if (ret < 0)
8347 : 0 : return ret;
8348 : : /* Count all modify-header actions as one action. */
8349 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8350 : 0 : ++actions_n;
8351 : 0 : action_flags |= actions->type ==
8352 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8353 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8354 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8355 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8356 : : modify_after_mirror = 1;
8357 : : /*
8358 : : * Even if the source and destination MAC addresses have
8359 : : * overlap in the header with 4B alignment, the convert
8360 : : * function will handle them separately and 4 SW actions
8361 : : * will be created. And 2 actions will be added each
8362 : : * time no matter how many bytes of address will be set.
8363 : : */
8364 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8365 : 0 : break;
8366 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8367 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8368 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8369 : : actions,
8370 : : item_flags,
8371 : : error);
8372 [ # # ]: 0 : if (ret < 0)
8373 : 0 : return ret;
8374 : : /* Count all modify-header actions as one action. */
8375 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8376 : 0 : ++actions_n;
8377 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8378 : : modify_after_mirror = 1;
8379 : 0 : action_flags |= actions->type ==
8380 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8381 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8382 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8383 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8384 : 0 : break;
8385 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8386 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8387 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8388 : : actions,
8389 : : item_flags,
8390 : : error);
8391 [ # # ]: 0 : if (ret < 0)
8392 : 0 : return ret;
8393 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8394 : 0 : return rte_flow_error_set(error, ENOTSUP,
8395 : : RTE_FLOW_ERROR_TYPE_ACTION,
8396 : : actions,
8397 : : "Can't change header "
8398 : : "with ICMPv6 proto");
8399 : : /* Count all modify-header actions as one action. */
8400 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8401 : 0 : ++actions_n;
8402 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8403 : : modify_after_mirror = 1;
8404 : 0 : action_flags |= actions->type ==
8405 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8406 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8407 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8408 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8409 : 0 : break;
8410 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8411 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8412 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8413 : : actions,
8414 : : item_flags,
8415 : : error);
8416 [ # # ]: 0 : if (ret < 0)
8417 : 0 : return ret;
8418 : : /* Count all modify-header actions as one action. */
8419 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8420 : 0 : ++actions_n;
8421 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8422 : : modify_after_mirror = 1;
8423 : 0 : action_flags |= actions->type ==
8424 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8425 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8426 : : MLX5_FLOW_ACTION_SET_TP_DST;
8427 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8428 : 0 : break;
8429 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8430 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8431 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8432 : : actions,
8433 : : item_flags,
8434 : : error);
8435 [ # # ]: 0 : if (ret < 0)
8436 : 0 : return ret;
8437 : : /* Count all modify-header actions as one action. */
8438 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8439 : 0 : ++actions_n;
8440 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8441 : : modify_after_mirror = 1;
8442 : 0 : action_flags |= actions->type ==
8443 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8444 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8445 : : MLX5_FLOW_ACTION_DEC_TTL;
8446 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8447 : 0 : break;
8448 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8449 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8450 : : action_flags,
8451 : : attr, external,
8452 : : error);
8453 [ # # ]: 0 : if (ret)
8454 : 0 : return ret;
8455 : 0 : ++actions_n;
8456 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8457 : 0 : break;
8458 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8459 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8460 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8461 : : (action_flags,
8462 : : actions,
8463 : : item_flags,
8464 : : error);
8465 [ # # ]: 0 : if (ret < 0)
8466 : 0 : return ret;
8467 : : /* Count all modify-header actions as one action. */
8468 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8469 : 0 : ++actions_n;
8470 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8471 : : modify_after_mirror = 1;
8472 : 0 : action_flags |= actions->type ==
8473 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8474 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8475 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8476 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8477 : 0 : break;
8478 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8479 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8480 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8481 : : (action_flags,
8482 : : actions,
8483 : : item_flags,
8484 : : error);
8485 [ # # ]: 0 : if (ret < 0)
8486 : 0 : return ret;
8487 : : /* Count all modify-header actions as one action. */
8488 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8489 : 0 : ++actions_n;
8490 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8491 : : modify_after_mirror = 1;
8492 : 0 : action_flags |= actions->type ==
8493 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8494 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8495 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8496 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8497 : 0 : break;
8498 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8499 : : break;
8500 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8501 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8502 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8503 : 0 : break;
8504 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8505 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8506 : : action_flags,
8507 : : item_flags,
8508 : : actions, attr,
8509 : : port_id_item,
8510 : : &def_policy,
8511 : : error);
8512 [ # # ]: 0 : if (ret < 0)
8513 : 0 : return ret;
8514 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8515 [ # # ]: 0 : if (!def_policy)
8516 : 0 : action_flags |=
8517 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8518 : 0 : ++actions_n;
8519 : : /* Meter action will add one more TAG action. */
8520 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8521 : 0 : break;
8522 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8523 [ # # ]: 0 : if (is_root)
8524 : 0 : return rte_flow_error_set(error, ENOTSUP,
8525 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8526 : : NULL,
8527 : : "Shared ASO age action is not supported for group 0");
8528 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8529 : 0 : return rte_flow_error_set
8530 : : (error, EINVAL,
8531 : : RTE_FLOW_ERROR_TYPE_ACTION,
8532 : : NULL,
8533 : : "duplicate age actions set");
8534 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8535 : : aso_after_sample = 1;
8536 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8537 : 0 : ++actions_n;
8538 : 0 : break;
8539 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8540 : 0 : non_shared_age = actions->conf;
8541 : 0 : ret = flow_dv_validate_action_age(action_flags,
8542 : : actions, dev,
8543 : : error);
8544 [ # # ]: 0 : if (ret < 0)
8545 : 0 : return ret;
8546 : : /*
8547 : : * Validate the regular AGE action (using counter)
8548 : : * mutual exclusion with indirect counter actions.
8549 : : */
8550 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8551 [ # # ]: 0 : if (shared_count)
8552 : 0 : return rte_flow_error_set
8553 : : (error, EINVAL,
8554 : : RTE_FLOW_ERROR_TYPE_ACTION,
8555 : : NULL,
8556 : : "old age and indirect count combination is not supported");
8557 [ # # ]: 0 : if (sample_count)
8558 : 0 : return rte_flow_error_set
8559 : : (error, EINVAL,
8560 : : RTE_FLOW_ERROR_TYPE_ACTION,
8561 : : NULL,
8562 : : "old age action and count must be in the same sub flow");
8563 : : } else {
8564 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8565 : : aso_after_sample = 1;
8566 : : }
8567 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8568 : 0 : ++actions_n;
8569 : 0 : break;
8570 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8571 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8572 : : (action_flags,
8573 : : actions,
8574 : : item_flags,
8575 : : error);
8576 [ # # ]: 0 : if (ret < 0)
8577 : 0 : return ret;
8578 : : /* Count all modify-header actions as one action. */
8579 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8580 : 0 : ++actions_n;
8581 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8582 : : modify_after_mirror = 1;
8583 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8584 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8585 : 0 : break;
8586 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8587 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8588 : : (action_flags,
8589 : : actions,
8590 : : item_flags,
8591 : : error);
8592 [ # # ]: 0 : if (ret < 0)
8593 : 0 : return ret;
8594 : : /* Count all modify-header actions as one action. */
8595 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8596 : 0 : ++actions_n;
8597 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8598 : : modify_after_mirror = 1;
8599 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8600 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8601 : 0 : break;
8602 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8603 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8604 : : &sub_action_flags,
8605 : : actions, dev,
8606 : : attr, item_flags,
8607 : : rss, &sample_rss,
8608 : : &sample_count,
8609 : : &fdb_mirror,
8610 : : &sample_port_id,
8611 : : is_root,
8612 : : error);
8613 [ # # ]: 0 : if (ret < 0)
8614 : 0 : return ret;
8615 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8616 : 0 : tag_id == 0 &&
8617 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8618 : 0 : return rte_flow_error_set(error, EINVAL,
8619 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8620 : : "sample after tag action causes metadata tag index 0 corruption");
8621 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8622 : 0 : ++actions_n;
8623 : 0 : break;
8624 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8625 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8626 : : action_flags,
8627 : : actions,
8628 : : attr,
8629 : : is_root,
8630 : : error);
8631 [ # # ]: 0 : if (ret < 0)
8632 : 0 : return ret;
8633 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8634 : : modify_after_mirror = 1;
8635 : : /* Count all modify-header actions as one action. */
8636 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8637 : 0 : ++actions_n;
8638 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8639 : 0 : rw_act_num += ret;
8640 : 0 : break;
8641 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8642 : 0 : ret = flow_dv_validate_action_aso_ct(dev, action_flags,
8643 : : item_flags,
8644 : : is_root, error);
8645 [ # # ]: 0 : if (ret < 0)
8646 : 0 : return ret;
8647 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8648 : : aso_after_sample = 1;
8649 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8650 : 0 : break;
8651 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8652 : : /* tunnel offload action was processed before
8653 : : * list it here as a supported type
8654 : : */
8655 : : break;
8656 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8657 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8658 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8659 : : ++actions_n;
8660 : : break;
8661 : : #endif
8662 : 0 : default:
8663 : 0 : return rte_flow_error_set(error, ENOTSUP,
8664 : : RTE_FLOW_ERROR_TYPE_ACTION,
8665 : : actions,
8666 : : "action not supported");
8667 : : }
8668 : : }
8669 : : /*
8670 : : * Validate actions in flow rules
8671 : : * - Explicit decap action is prohibited by the tunnel offload API.
8672 : : * - Drop action in tunnel steer rule is prohibited by the API.
8673 : : * - Application cannot use MARK action because it's value can mask
8674 : : * tunnel default miss notification.
8675 : : * - JUMP in tunnel match rule has no support in current PMD
8676 : : * implementation.
8677 : : * - TAG & META are reserved for future uses.
8678 : : */
8679 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8680 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8681 : : MLX5_FLOW_ACTION_MARK |
8682 : : MLX5_FLOW_ACTION_SET_TAG |
8683 : : MLX5_FLOW_ACTION_SET_META |
8684 : : MLX5_FLOW_ACTION_DROP;
8685 : :
8686 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8687 : 0 : return rte_flow_error_set
8688 : : (error, EINVAL,
8689 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8690 : : "Invalid RTE action in tunnel "
8691 : : "set decap rule");
8692 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8693 : 0 : return rte_flow_error_set
8694 : : (error, EINVAL,
8695 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8696 : : "tunnel set decap rule must terminate "
8697 : : "with JUMP");
8698 [ # # ]: 0 : if (attr->egress)
8699 : 0 : return rte_flow_error_set
8700 : : (error, EINVAL,
8701 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8702 : : "tunnel flows for ingress and transfer traffic only");
8703 : : }
8704 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8705 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8706 : : MLX5_FLOW_ACTION_MARK |
8707 : : MLX5_FLOW_ACTION_SET_TAG |
8708 : : MLX5_FLOW_ACTION_SET_META;
8709 : :
8710 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8711 : 0 : return rte_flow_error_set
8712 : : (error, EINVAL,
8713 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8714 : : "Invalid RTE action in tunnel "
8715 : : "set match rule");
8716 : : }
8717 : : /*
8718 : : * Validate the drop action mutual exclusion with other actions.
8719 : : * Drop action is mutually-exclusive with any other action, except for
8720 : : * Count/Sample/Age actions.
8721 : : * Drop action compatibility with tunnel offload was already validated.
8722 : : */
8723 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8724 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8725 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8726 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8727 : 0 : return rte_flow_error_set(error, EINVAL,
8728 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8729 : : "Drop action is mutually-exclusive "
8730 : : "with any other action, except for "
8731 : : "Count/Sample/Age action");
8732 : : /* Eswitch has few restrictions on using items and actions */
8733 [ # # ]: 0 : if (attr->transfer) {
8734 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8735 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8736 : 0 : return rte_flow_error_set(error, ENOTSUP,
8737 : : RTE_FLOW_ERROR_TYPE_ACTION,
8738 : : NULL,
8739 : : "unsupported action FLAG");
8740 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8741 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8742 : 0 : return rte_flow_error_set(error, ENOTSUP,
8743 : : RTE_FLOW_ERROR_TYPE_ACTION,
8744 : : NULL,
8745 : : "unsupported action MARK");
8746 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8747 : 0 : return rte_flow_error_set(error, ENOTSUP,
8748 : : RTE_FLOW_ERROR_TYPE_ACTION,
8749 : : NULL,
8750 : : "unsupported action QUEUE");
8751 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8752 : 0 : return rte_flow_error_set(error, ENOTSUP,
8753 : : RTE_FLOW_ERROR_TYPE_ACTION,
8754 : : NULL,
8755 : : "unsupported action RSS");
8756 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8757 : 0 : return rte_flow_error_set(error, EINVAL,
8758 : : RTE_FLOW_ERROR_TYPE_ACTION,
8759 : : actions,
8760 : : "no fate action is found");
8761 : : } else {
8762 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8763 : 0 : return rte_flow_error_set(error, EINVAL,
8764 : : RTE_FLOW_ERROR_TYPE_ACTION,
8765 : : actions,
8766 : : "no fate action is found");
8767 : : }
8768 : : /*
8769 : : * Continue validation for Xcap and VLAN actions.
8770 : : * If hairpin is working in explicit TX rule mode, there is no actions
8771 : : * splitting and the validation of hairpin ingress flow should be the
8772 : : * same as other standard flows.
8773 : : */
8774 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8775 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
8776 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8777 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8778 [ # # ]: 0 : conf->tx_explicit != 0))) {
8779 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8780 : : MLX5_FLOW_XCAP_ACTIONS)
8781 : 0 : return rte_flow_error_set(error, ENOTSUP,
8782 : : RTE_FLOW_ERROR_TYPE_ACTION,
8783 : : NULL, "encap and decap "
8784 : : "combination aren't supported");
8785 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8786 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8787 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8788 : : bool direction_error = false;
8789 : :
8790 [ # # ]: 0 : if (attr->transfer) {
8791 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
8792 : 0 : bool is_cx5 = sh->steering_format_version ==
8793 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
8794 : :
8795 [ # # ]: 0 : if (!fdb_tx && is_cx5)
8796 : : direction_error = true;
8797 [ # # ]: 0 : } else if (attr->ingress) {
8798 : : direction_error = true;
8799 : : }
8800 : : if (direction_error)
8801 : 0 : return rte_flow_error_set(error, ENOTSUP,
8802 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
8803 : : NULL,
8804 : : "push VLAN action not supported "
8805 : : "for ingress");
8806 : : }
8807 [ # # ]: 0 : if (attr->ingress) {
8808 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8809 : 0 : return rte_flow_error_set
8810 : : (error, ENOTSUP,
8811 : : RTE_FLOW_ERROR_TYPE_ACTION,
8812 : : NULL, "encap is not supported"
8813 : : " for ingress traffic");
8814 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
8815 : : MLX5_FLOW_VLAN_ACTIONS)
8816 : 0 : return rte_flow_error_set
8817 : : (error, ENOTSUP,
8818 : : RTE_FLOW_ERROR_TYPE_ACTION,
8819 : : NULL, "no support for "
8820 : : "multiple VLAN actions");
8821 : : }
8822 : : }
8823 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
8824 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
8825 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8826 : : bool direction_error = false;
8827 : :
8828 [ # # ]: 0 : if (attr->transfer) {
8829 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
8830 : 0 : bool is_cx5 = sh->steering_format_version ==
8831 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
8832 : :
8833 [ # # ]: 0 : if (fdb_tx && is_cx5)
8834 : : direction_error = true;
8835 [ # # ]: 0 : } else if (attr->egress) {
8836 : : direction_error = true;
8837 : : }
8838 : : if (direction_error)
8839 : 0 : return rte_flow_error_set(error, ENOTSUP,
8840 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
8841 : : NULL,
8842 : : "pop vlan action not supported for egress");
8843 : : }
8844 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
8845 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
8846 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
8847 : : attr->ingress)
8848 : 0 : return rte_flow_error_set
8849 : : (error, ENOTSUP,
8850 : : RTE_FLOW_ERROR_TYPE_ACTION,
8851 : : NULL, "fate action not supported for "
8852 : : "meter with policy");
8853 [ # # ]: 0 : if (attr->egress) {
8854 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
8855 : 0 : return rte_flow_error_set
8856 : : (error, ENOTSUP,
8857 : : RTE_FLOW_ERROR_TYPE_ACTION,
8858 : : NULL, "modify header action in egress "
8859 : : "cannot be done before meter action");
8860 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8861 : 0 : return rte_flow_error_set
8862 : : (error, ENOTSUP,
8863 : : RTE_FLOW_ERROR_TYPE_ACTION,
8864 : : NULL, "encap action in egress "
8865 : : "cannot be done before meter action");
8866 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8867 : 0 : return rte_flow_error_set
8868 : : (error, ENOTSUP,
8869 : : RTE_FLOW_ERROR_TYPE_ACTION,
8870 : : NULL, "push vlan action in egress "
8871 : : "cannot be done before meter action");
8872 : : }
8873 : : }
8874 : : /*
8875 : : * Only support one ASO action in a single flow rule.
8876 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
8877 : : * Group 0 uses HW counter for AGE too even if no counter action.
8878 : : */
8879 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
8880 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
8881 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
8882 [ # # ]: 0 : !(non_shared_age && count) &&
8883 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
8884 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
8885 [ # # ]: 0 : if (__builtin_popcountl(aso_mask) > 1)
8886 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8887 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
8888 : : /*
8889 : : * Hairpin flow will add one more TAG action in TX implicit mode.
8890 : : * In TX explicit mode, there will be no hairpin flow ID.
8891 : : */
8892 [ # # ]: 0 : if (hairpin > 0)
8893 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8894 : : /* extra metadata enabled: one more TAG action will be add. */
8895 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
8896 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
8897 : 0 : mlx5_flow_ext_mreg_supported(dev))
8898 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8899 [ # # ]: 0 : if (rw_act_num >
8900 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
8901 : 0 : return rte_flow_error_set(error, ENOTSUP,
8902 : : RTE_FLOW_ERROR_TYPE_ACTION,
8903 : : NULL, "too many header modify"
8904 : : " actions to support");
8905 : : }
8906 [ # # ]: 0 : if (fdb_mirror) {
8907 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
8908 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
8909 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
8910 [ # # ]: 0 : if (modify_after_mirror)
8911 : 0 : return rte_flow_error_set(error, EINVAL,
8912 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8913 : : "sample before modify action is not supported");
8914 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
8915 : 0 : return rte_flow_error_set(error, EINVAL,
8916 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8917 : : "sample and jump action combination is not supported");
8918 : : }
8919 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
8920 : 0 : return rte_flow_error_set(error, ENOTSUP,
8921 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8922 : : "sample before ASO action is not supported");
8923 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
8924 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
8925 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
8926 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
8927 : 0 : return rte_flow_error_set(error, ENOTSUP,
8928 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8929 : : "mirror to rep port with encap is not supported");
8930 : : } else {
8931 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
8932 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
8933 : 0 : return rte_flow_error_set(error, ENOTSUP,
8934 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8935 : : "mirror to wire port without encap is not supported");
8936 : : }
8937 : : }
8938 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
8939 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
8940 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
8941 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
8942 : 0 : return rte_flow_error_set(error, ENOTSUP,
8943 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8944 : : "mirror to rep port with encap is not supported");
8945 : : }
8946 : : }
8947 : : /*
8948 : : * Validation the NIC Egress flow on representor, except implicit
8949 : : * hairpin default egress flow with TX_QUEUE item, other flows not
8950 : : * work due to metadata regC0 mismatch.
8951 : : */
8952 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
8953 : 0 : return rte_flow_error_set(error, EINVAL,
8954 : : RTE_FLOW_ERROR_TYPE_ITEM,
8955 : : NULL,
8956 : : "NIC egress rules on representors"
8957 : : " is not supported");
8958 : : return 0;
8959 : : }
8960 : :
8961 : : /**
8962 : : * Internal preparation function. Allocates the DV flow size,
8963 : : * this size is constant.
8964 : : *
8965 : : * @param[in] dev
8966 : : * Pointer to the rte_eth_dev structure.
8967 : : * @param[in] attr
8968 : : * Pointer to the flow attributes.
8969 : : * @param[in] items
8970 : : * Pointer to the list of items.
8971 : : * @param[in] actions
8972 : : * Pointer to the list of actions.
8973 : : * @param[out] error
8974 : : * Pointer to the error structure.
8975 : : *
8976 : : * @return
8977 : : * Pointer to mlx5_flow object on success,
8978 : : * otherwise NULL and rte_errno is set.
8979 : : */
8980 : : static struct mlx5_flow *
8981 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
8982 : : const struct rte_flow_attr *attr __rte_unused,
8983 : : const struct rte_flow_item items[] __rte_unused,
8984 : : const struct rte_flow_action actions[] __rte_unused,
8985 : : struct rte_flow_error *error)
8986 : : {
8987 : 0 : uint32_t handle_idx = 0;
8988 : : struct mlx5_flow *dev_flow;
8989 : : struct mlx5_flow_handle *dev_handle;
8990 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8991 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
8992 : :
8993 : : MLX5_ASSERT(wks);
8994 : 0 : wks->skip_matcher_reg = 0;
8995 : 0 : wks->policy = NULL;
8996 : 0 : wks->final_policy = NULL;
8997 : 0 : wks->vport_meta_tag = 0;
8998 : : /* In case of corrupting the memory. */
8999 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9000 : 0 : rte_flow_error_set(error, ENOSPC,
9001 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9002 : : "not free temporary device flow");
9003 : 0 : return NULL;
9004 : : }
9005 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9006 : : &handle_idx);
9007 [ # # ]: 0 : if (!dev_handle) {
9008 : 0 : rte_flow_error_set(error, ENOMEM,
9009 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9010 : : "not enough memory to create flow handle");
9011 : 0 : return NULL;
9012 : : }
9013 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9014 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9015 : : memset(dev_flow, 0, sizeof(*dev_flow));
9016 : 0 : dev_flow->handle = dev_handle;
9017 : 0 : dev_flow->handle_idx = handle_idx;
9018 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9019 : 0 : dev_flow->ingress = attr->ingress;
9020 : 0 : dev_flow->dv.transfer = attr->transfer;
9021 : 0 : return dev_flow;
9022 : : }
9023 : :
9024 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
9025 : : /**
9026 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9027 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9028 : : *
9029 : : * @param match_mask
9030 : : * pointer to match mask buffer.
9031 : : * @param match_value
9032 : : * pointer to match value buffer.
9033 : : *
9034 : : * @return
9035 : : * 0 if valid, -EINVAL otherwise.
9036 : : */
9037 : : static int
9038 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9039 : : {
9040 : : uint8_t *m = match_mask;
9041 : : uint8_t *v = match_value;
9042 : : unsigned int i;
9043 : :
9044 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9045 : : if (v[i] & ~m[i]) {
9046 : : DRV_LOG(ERR,
9047 : : "match_value differs from match_criteria"
9048 : : " %p[%u] != %p[%u]",
9049 : : match_value, i, match_mask, i);
9050 : : return -EINVAL;
9051 : : }
9052 : : }
9053 : : return 0;
9054 : : }
9055 : : #endif
9056 : :
9057 : : /**
9058 : : * Add match of ip_version.
9059 : : *
9060 : : * @param[in] group
9061 : : * Flow group.
9062 : : * @param[in] headers_v
9063 : : * Values header pointer.
9064 : : * @param[in] headers_m
9065 : : * Masks header pointer.
9066 : : * @param[in] ip_version
9067 : : * The IP version to set.
9068 : : */
9069 : : static inline void
9070 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9071 : : void *headers_v,
9072 : : uint32_t key_type,
9073 : : uint8_t ip_version)
9074 : : {
9075 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9076 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9077 : : else
9078 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9079 : : ip_version);
9080 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9081 : 0 : }
9082 : :
9083 : : /**
9084 : : * Add Ethernet item to the value.
9085 : : *
9086 : : * @param[in, out] key
9087 : : * Flow matcher value.
9088 : : * @param[in] item
9089 : : * Flow pattern to translate.
9090 : : * @param[in] inner
9091 : : * Item is inner pattern.
9092 : : * @param[in] grpup
9093 : : * Flow matcher group.
9094 : : * @param[in] key_type
9095 : : * Set flow matcher mask or value.
9096 : : */
9097 : : static void
9098 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9099 : : int inner, uint32_t group, uint32_t key_type)
9100 : : {
9101 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9102 : : const struct rte_flow_item_eth *eth_m;
9103 : : const struct rte_flow_item_eth *eth_v;
9104 : 0 : const struct rte_flow_item_eth nic_mask = {
9105 : : .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
9106 : : .hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
9107 : : .hdr.ether_type = RTE_BE16(0xffff),
9108 : : .has_vlan = 0,
9109 : : };
9110 : : void *hdrs_v;
9111 : : char *l24_v;
9112 : : unsigned int i;
9113 : :
9114 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9115 : 0 : return;
9116 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9117 [ # # ]: 0 : if (!eth_vv)
9118 : : eth_vv = eth_v;
9119 [ # # ]: 0 : if (inner)
9120 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9121 : : else
9122 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9123 : : /* The value must be in the range of the mask. */
9124 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9125 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9126 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9127 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9128 : : /* The value must be in the range of the mask. */
9129 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9130 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9131 : : /*
9132 : : * HW supports match on one Ethertype, the Ethertype following the last
9133 : : * VLAN tag of the packet (see PRM).
9134 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9135 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9136 : : * ethertype, and use ip_version field instead.
9137 : : * eCPRI over Ether layer will use type value 0xAEFE.
9138 : : */
9139 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9140 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9141 : :
9142 : : /*
9143 : : * When set the matcher mask, refer to the original spec
9144 : : * value.
9145 : : */
9146 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9147 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9148 : 0 : type = eth_vv->hdr.ether_type;
9149 : : }
9150 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9151 [ # # # # : 0 : switch (type) {
# ]
9152 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9153 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9154 : 0 : return;
9155 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9156 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9157 : 0 : return;
9158 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9159 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9160 : : 4);
9161 : 0 : return;
9162 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9163 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9164 : : 6);
9165 : 0 : return;
9166 : : default:
9167 : : break;
9168 : : }
9169 : : }
9170 : : /*
9171 : : * Only SW steering value should refer to the mask value.
9172 : : * Other cases are using the fake masks, just ignore the mask.
9173 : : */
9174 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9175 : : /*
9176 : : * Here, when also has_more_vlan field in VLAN item is
9177 : : * not set, only single-tagged packets will be matched.
9178 : : */
9179 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9180 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9181 : : return;
9182 : : }
9183 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9184 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9185 : : }
9186 : :
9187 : : /**
9188 : : * Add VLAN item to the value.
9189 : : *
9190 : : * @param[in, out] key
9191 : : * Flow matcher value.
9192 : : * @param[in] item
9193 : : * Flow pattern to translate.
9194 : : * @param[in] inner
9195 : : * Item is inner pattern.
9196 : : * @param[in] wks
9197 : : * Item workspace.
9198 : : * @param[in] key_type
9199 : : * Set flow matcher mask or value.
9200 : : */
9201 : : static void
9202 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9203 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9204 : : uint32_t key_type)
9205 : : {
9206 : : const struct rte_flow_item_vlan *vlan_m;
9207 : : const struct rte_flow_item_vlan *vlan_v;
9208 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9209 : : void *hdrs_v;
9210 : : uint16_t tci_v;
9211 : :
9212 [ # # ]: 0 : if (inner) {
9213 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9214 : : } else {
9215 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9216 : : /*
9217 : : * This is workaround, masks are not supported,
9218 : : * and pre-validated.
9219 : : */
9220 [ # # ]: 0 : if (vlan_vv)
9221 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9222 : : }
9223 : : /*
9224 : : * When VLAN item exists in flow, mark packet as tagged,
9225 : : * even if TCI is not specified.
9226 : : */
9227 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9228 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9229 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9230 : : return;
9231 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9232 : : &rte_flow_item_vlan_mask);
9233 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9234 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9235 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9236 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9237 : : /*
9238 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9239 : : * ethertype, and use ip_version field instead.
9240 : : */
9241 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9242 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9243 : :
9244 : : /*
9245 : : * When set the matcher mask, refer to the original spec
9246 : : * value.
9247 : : */
9248 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9249 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9250 [ # # # # ]: 0 : switch (inner_type) {
9251 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9252 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9253 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9254 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9255 : : cvlan_tag, 0);
9256 : 0 : return;
9257 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9258 : 0 : flow_dv_set_match_ip_version
9259 : : (wks->group, hdrs_v, key_type, 4);
9260 : 0 : return;
9261 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9262 : 0 : flow_dv_set_match_ip_version
9263 : : (wks->group, hdrs_v, key_type, 6);
9264 : 0 : return;
9265 : : default:
9266 : : break;
9267 : : }
9268 : : }
9269 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9270 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9271 : : /* Only one vlan_tag bit can be set. */
9272 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9273 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9274 : 0 : return;
9275 : : }
9276 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9277 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9278 : : }
9279 : :
9280 : : /**
9281 : : * Add IPV4 item to the value.
9282 : : *
9283 : : * @param[in, out] key
9284 : : * Flow matcher value.
9285 : : * @param[in] item
9286 : : * Flow pattern to translate.
9287 : : * @param[in] inner
9288 : : * Item is inner pattern.
9289 : : * @param[in] group
9290 : : * The group to insert the rule.
9291 : : * @param[in] key_type
9292 : : * Set flow matcher mask or value.
9293 : : */
9294 : : static void
9295 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9296 : : int inner, uint32_t group, uint32_t key_type)
9297 : : {
9298 : : const struct rte_flow_item_ipv4 *ipv4_m;
9299 : : const struct rte_flow_item_ipv4 *ipv4_v;
9300 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9301 : : .hdr = {
9302 : : .src_addr = RTE_BE32(0xffffffff),
9303 : : .dst_addr = RTE_BE32(0xffffffff),
9304 : : .type_of_service = 0xff,
9305 : : .next_proto_id = 0xff,
9306 : : .time_to_live = 0xff,
9307 : : },
9308 : : };
9309 : : void *headers_v;
9310 : : char *l24_v;
9311 : : uint8_t tos;
9312 : :
9313 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9314 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9315 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9316 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9317 : 0 : return;
9318 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9319 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9320 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9321 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9322 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9323 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9324 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9325 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9326 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9327 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9328 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9329 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9330 : : ipv4_v->hdr.type_of_service);
9331 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9332 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9333 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9334 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9335 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9336 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9337 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9338 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9339 : : }
9340 : :
9341 : : /**
9342 : : * Add IPV6 item to the value.
9343 : : *
9344 : : * @param[in, out] key
9345 : : * Flow matcher value.
9346 : : * @param[in] item
9347 : : * Flow pattern to translate.
9348 : : * @param[in] inner
9349 : : * Item is inner pattern.
9350 : : * @param[in] group
9351 : : * The group to insert the rule.
9352 : : * @param[in] key_type
9353 : : * Set flow matcher mask or value.
9354 : : */
9355 : : static void
9356 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9357 : : int inner, uint32_t group, uint32_t key_type)
9358 : : {
9359 : : const struct rte_flow_item_ipv6 *ipv6_m;
9360 : : const struct rte_flow_item_ipv6 *ipv6_v;
9361 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9362 : : .hdr = {
9363 : : .src_addr =
9364 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
9365 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
9366 : : .dst_addr =
9367 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
9368 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
9369 : : .vtc_flow = RTE_BE32(0xffffffff),
9370 : : .proto = 0xff,
9371 : : .hop_limits = 0xff,
9372 : : },
9373 : : };
9374 : : void *headers_v;
9375 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9376 : : char *l24_v;
9377 : : uint32_t vtc_v;
9378 : : int i;
9379 : : int size;
9380 : :
9381 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9382 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9383 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9384 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9385 : 0 : return;
9386 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9387 : : size = sizeof(ipv6_m->hdr.dst_addr);
9388 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9389 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9390 [ # # ]: 0 : for (i = 0; i < size; ++i)
9391 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr[i] & ipv6_v->hdr.dst_addr[i];
9392 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9393 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9394 [ # # ]: 0 : for (i = 0; i < size; ++i)
9395 : 0 : l24_v[i] = ipv6_m->hdr.src_addr[i] & ipv6_v->hdr.src_addr[i];
9396 : : /* TOS. */
9397 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9398 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9399 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9400 : : /* Label. */
9401 [ # # ]: 0 : if (inner)
9402 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9403 : : vtc_v);
9404 : : else
9405 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9406 : : vtc_v);
9407 : : /* Protocol. */
9408 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9409 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9410 : : /* Hop limit. */
9411 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9412 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9413 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9414 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9415 : : }
9416 : :
9417 : : /**
9418 : : * Add IPV6 fragment extension item to the value.
9419 : : *
9420 : : * @param[in, out] key
9421 : : * Flow matcher value.
9422 : : * @param[in] item
9423 : : * Flow pattern to translate.
9424 : : * @param[in] inner
9425 : : * Item is inner pattern.
9426 : : * @param[in] key_type
9427 : : * Set flow matcher mask or value.
9428 : : */
9429 : : static void
9430 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9431 : : const struct rte_flow_item *item,
9432 : : int inner, uint32_t key_type)
9433 : : {
9434 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9435 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9436 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9437 : : .hdr = {
9438 : : .next_header = 0xff,
9439 : : .frag_data = RTE_BE16(0xffff),
9440 : : },
9441 : : };
9442 : : void *headers_v;
9443 : :
9444 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9445 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9446 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9447 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9448 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9449 : 0 : return;
9450 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9451 : : ipv6_frag_ext_m, &nic_mask);
9452 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9453 : : ipv6_frag_ext_v->hdr.next_header &
9454 : : ipv6_frag_ext_m->hdr.next_header);
9455 : : }
9456 : :
9457 : : /**
9458 : : * Add TCP item to the value.
9459 : : *
9460 : : * @param[in, out] key
9461 : : * Flow matcher value.
9462 : : * @param[in] item
9463 : : * Flow pattern to translate.
9464 : : * @param[in] inner
9465 : : * Item is inner pattern.
9466 : : * @param[in] key_type
9467 : : * Set flow matcher mask or value.
9468 : : */
9469 : : static void
9470 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9471 : : int inner, uint32_t key_type)
9472 : : {
9473 : : const struct rte_flow_item_tcp *tcp_m;
9474 : : const struct rte_flow_item_tcp *tcp_v;
9475 : : void *headers_v;
9476 : :
9477 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9478 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9479 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9480 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9481 : : ip_protocol, 0xff);
9482 : : else
9483 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9484 : : ip_protocol, IPPROTO_TCP);
9485 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9486 : : return;
9487 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9488 : : &rte_flow_item_tcp_mask);
9489 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9490 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9491 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9492 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9493 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9494 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9495 : : }
9496 : :
9497 : : /**
9498 : : * Add ESP item to the value.
9499 : : *
9500 : : * @param[in, out] key
9501 : : * Flow matcher value.
9502 : : * @param[in] item
9503 : : * Flow pattern to translate.
9504 : : * @param[in] inner
9505 : : * Item is inner pattern.
9506 : : * @param[in] key_type
9507 : : * Set flow matcher mask or value.
9508 : : */
9509 : : static void
9510 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9511 : : int inner, uint32_t key_type)
9512 : : {
9513 : : const struct rte_flow_item_esp *esp_m;
9514 : : const struct rte_flow_item_esp *esp_v;
9515 : : void *headers_v;
9516 : : char *spi_v;
9517 : :
9518 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9519 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9520 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9521 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9522 : : ip_protocol, 0xff);
9523 : : else
9524 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9525 : : ip_protocol, IPPROTO_ESP);
9526 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9527 : : return;
9528 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m,
# # # # ]
9529 : : &rte_flow_item_esp_mask);
9530 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9531 : : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v,
9532 [ # # ]: 0 : inner_esp_spi) : MLX5_ADDR_OF(fte_match_set_misc
9533 : : , headers_v, outer_esp_spi);
9534 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9535 : : }
9536 : :
9537 : : /**
9538 : : * Add UDP item to the value.
9539 : : *
9540 : : * @param[in, out] key
9541 : : * Flow matcher value.
9542 : : * @param[in] item
9543 : : * Flow pattern to translate.
9544 : : * @param[in] inner
9545 : : * Item is inner pattern.
9546 : : * @param[in] key_type
9547 : : * Set flow matcher mask or value.
9548 : : */
9549 : : static void
9550 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9551 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9552 : : uint32_t key_type)
9553 : : {
9554 : : const struct rte_flow_item_udp *udp_m;
9555 : : const struct rte_flow_item_udp *udp_v;
9556 : : void *headers_v;
9557 : :
9558 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9559 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9560 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9561 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9562 : : ip_protocol, 0xff);
9563 : : else
9564 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9565 : : ip_protocol, IPPROTO_UDP);
9566 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9567 : : return;
9568 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9569 : : &rte_flow_item_udp_mask);
9570 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9571 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9572 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9573 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9574 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9575 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9576 : 0 : udp_v = item->spec;
9577 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9578 : : udp_m->hdr.dst_port);
9579 : : }
9580 : : }
9581 : :
9582 : : /**
9583 : : * Add GRE optional Key item to the value.
9584 : : *
9585 : : * @param[in, out] key
9586 : : * Flow matcher value.
9587 : : * @param[in] item
9588 : : * Flow pattern to translate.
9589 : : * @param[in] inner
9590 : : * Item is inner pattern.
9591 : : */
9592 : : static void
9593 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9594 : : uint32_t key_type)
9595 : : {
9596 : : const rte_be32_t *key_m;
9597 : : const rte_be32_t *key_v;
9598 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9599 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9600 : :
9601 : : /* GRE K bit must be on and should already be validated */
9602 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9603 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9604 : 0 : return;
9605 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9606 : : &gre_key_default_mask);
9607 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9608 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9609 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9610 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9611 : : }
9612 : :
9613 : : /**
9614 : : * Add GRE item to the value.
9615 : : *
9616 : : * @param[in, out] key
9617 : : * Flow matcher value.
9618 : : * @param[in] item
9619 : : * Flow pattern to translate.
9620 : : * @param[in] pattern_flags
9621 : : * Accumulated pattern flags.
9622 : : * @param[in] key_type
9623 : : * Set flow matcher mask or value.
9624 : : */
9625 : : static void
9626 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9627 : : uint64_t pattern_flags, uint32_t key_type)
9628 : : {
9629 : : static const struct rte_flow_item_gre empty_gre = {0,};
9630 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9631 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9632 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9633 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9634 : : struct {
9635 : : union {
9636 : : __extension__
9637 : : struct {
9638 : : uint16_t version:3;
9639 : : uint16_t rsvd0:9;
9640 : : uint16_t s_present:1;
9641 : : uint16_t k_present:1;
9642 : : uint16_t rsvd_bit1:1;
9643 : : uint16_t c_present:1;
9644 : : };
9645 : : uint16_t value;
9646 : : };
9647 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9648 : : uint16_t protocol_m, protocol_v;
9649 : :
9650 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9651 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9652 : : else
9653 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9654 : : IPPROTO_GRE);
9655 [ # # ]: 0 : if (!gre_v) {
9656 : : gre_v = &empty_gre;
9657 : : gre_m = &empty_gre;
9658 : : } else {
9659 [ # # ]: 0 : if (!gre_m)
9660 : : gre_m = &rte_flow_item_gre_mask;
9661 : : }
9662 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9663 : : gre_v = gre_m;
9664 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
9665 : : gre_m = gre_v;
9666 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9667 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9668 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9669 : : gre_crks_rsvd0_ver_v.c_present &
9670 : : gre_crks_rsvd0_ver_m.c_present);
9671 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9672 : : gre_crks_rsvd0_ver_v.k_present &
9673 : : gre_crks_rsvd0_ver_m.k_present);
9674 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9675 : : gre_crks_rsvd0_ver_v.s_present &
9676 : : gre_crks_rsvd0_ver_m.s_present);
9677 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9678 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9679 [ # # ]: 0 : if (!protocol_m) {
9680 : : /* Force next protocol to prevent matchers duplication */
9681 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9682 : : if (protocol_v)
9683 : : protocol_m = 0xFFFF;
9684 : : /* Restore the value to mask in mask case. */
9685 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9686 : : protocol_v = protocol_m;
9687 : : }
9688 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9689 : : protocol_m & protocol_v);
9690 : 0 : }
9691 : :
9692 : : /**
9693 : : * Add GRE optional items to the value.
9694 : : *
9695 : : * @param[in, out] key
9696 : : * Flow matcher value.
9697 : : * @param[in] item
9698 : : * Flow pattern to translate.
9699 : : * @param[in] gre_item
9700 : : * Pointer to gre_item.
9701 : : * @param[in] pattern_flags
9702 : : * Accumulated pattern flags.
9703 : : * @param[in] key_type
9704 : : * Set flow matcher mask or value.
9705 : : */
9706 : : static void
9707 : 0 : flow_dv_translate_item_gre_option(void *key,
9708 : : const struct rte_flow_item *item,
9709 : : const struct rte_flow_item *gre_item,
9710 : : uint64_t pattern_flags, uint32_t key_type)
9711 : : {
9712 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9713 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9714 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9715 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9716 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9717 : : static const struct rte_flow_item_gre empty_gre = {0};
9718 : : struct rte_flow_item gre_key_item;
9719 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9720 : : uint16_t protocol_m, protocol_v;
9721 : :
9722 : : /*
9723 : : * If only match key field, keep using misc for matching.
9724 : : * If need to match checksum or sequence, using misc5 and do
9725 : : * not need using misc.
9726 : : */
9727 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9728 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9729 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9730 : 0 : gre_key_item.spec = &option_v->key.key;
9731 : 0 : gre_key_item.mask = &option_m->key.key;
9732 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9733 : 0 : return;
9734 : : }
9735 [ # # ]: 0 : if (!gre_v) {
9736 : : gre_v = &empty_gre;
9737 : : gre_m = &empty_gre;
9738 : : } else {
9739 [ # # ]: 0 : if (!gre_m)
9740 : : gre_m = &rte_flow_item_gre_mask;
9741 : : }
9742 : 0 : protocol_v = gre_v->protocol;
9743 : 0 : protocol_m = gre_m->protocol;
9744 [ # # ]: 0 : if (!protocol_m) {
9745 : : /* Force next protocol to prevent matchers duplication */
9746 : : uint16_t ether_type =
9747 : : mlx5_translate_tunnel_etypes(pattern_flags);
9748 : : if (ether_type) {
9749 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9750 : : protocol_m = UINT16_MAX;
9751 : : }
9752 : : }
9753 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9754 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9755 [ # # ]: 0 : if (option_m->sequence.sequence) {
9756 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9757 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9758 : : }
9759 [ # # ]: 0 : if (option_m->key.key) {
9760 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9761 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9762 : : }
9763 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9764 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9765 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9766 : : }
9767 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9768 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
9769 : : protocol_v = protocol_m;
9770 : : option_v = option_m;
9771 : : }
9772 : : /*
9773 : : * Hardware parses GRE optional field into the fixed location,
9774 : : * do not need to adjust the tunnel dword indices.
9775 : : */
9776 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9777 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9778 : : (c_rsvd0_ver_m | protocol_m << 16)));
9779 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9780 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9781 : : option_m->checksum_rsvd.checksum));
9782 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9783 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
9784 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
9785 : : rte_be_to_cpu_32(option_v->sequence.sequence &
9786 : : option_m->sequence.sequence));
9787 : : }
9788 : :
9789 : : /**
9790 : : * Add NVGRE item to matcher and to the value.
9791 : : *
9792 : : * @param[in, out] key
9793 : : * Flow matcher value.
9794 : : * @param[in] item
9795 : : * Flow pattern to translate.
9796 : : * @param[in] pattern_flags
9797 : : * Accumulated pattern flags.
9798 : : * @param[in] key_type
9799 : : * Set flow matcher mask or value.
9800 : : */
9801 : : static void
9802 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
9803 : : unsigned long pattern_flags, uint32_t key_type)
9804 : : {
9805 : : const struct rte_flow_item_nvgre *nvgre_m;
9806 : : const struct rte_flow_item_nvgre *nvgre_v;
9807 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9808 : : const char *tni_flow_id_m;
9809 : : const char *tni_flow_id_v;
9810 : : char *gre_key_v;
9811 : : int size;
9812 : : int i;
9813 : :
9814 : : /* For NVGRE, GRE header fields must be set with defined values. */
9815 : 0 : const struct rte_flow_item_gre gre_spec = {
9816 : : .c_rsvd0_ver = RTE_BE16(0x2000),
9817 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
9818 : : };
9819 : 0 : const struct rte_flow_item_gre gre_mask = {
9820 : : .c_rsvd0_ver = RTE_BE16(0xB000),
9821 : : .protocol = RTE_BE16(UINT16_MAX),
9822 : : };
9823 : 0 : const struct rte_flow_item gre_item = {
9824 : : .spec = &gre_spec,
9825 : : .mask = &gre_mask,
9826 : : .last = NULL,
9827 : : };
9828 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
9829 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9830 : 0 : return;
9831 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
9832 : : &rte_flow_item_nvgre_mask);
9833 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
9834 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
9835 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
9836 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
9837 [ # # ]: 0 : for (i = 0; i < size; ++i)
9838 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
9839 : : }
9840 : :
9841 : : /**
9842 : : * Add VXLAN item to the value.
9843 : : *
9844 : : * @param[in] dev
9845 : : * Pointer to the Ethernet device structure.
9846 : : * @param[in] attr
9847 : : * Flow rule attributes.
9848 : : * @param[in, out] key
9849 : : * Flow matcher value.
9850 : : * @param[in] item
9851 : : * Flow pattern to translate.
9852 : : * @param[in] inner
9853 : : * Item is inner pattern.
9854 : : * @param[in] wks
9855 : : * Matcher workspace.
9856 : : * @param[in] key_type
9857 : : * Set flow matcher mask or value.
9858 : : */
9859 : : static void
9860 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
9861 : : const struct rte_flow_attr *attr,
9862 : : void *key, const struct rte_flow_item *item,
9863 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9864 : : uint32_t key_type)
9865 : : {
9866 : : const struct rte_flow_item_vxlan *vxlan_m;
9867 : : const struct rte_flow_item_vxlan *vxlan_v;
9868 : : void *headers_v;
9869 : : void *misc_v;
9870 : : void *misc5_v;
9871 : : uint32_t tunnel_v;
9872 : : char *vni_v;
9873 : : uint16_t dport;
9874 : : int size;
9875 : : int i;
9876 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9877 : 0 : const struct rte_flow_item_vxlan nic_mask = {
9878 : : .hdr.vni = "\xff\xff\xff",
9879 : : .hdr.rsvd1 = 0xff,
9880 : : };
9881 : :
9882 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9883 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9884 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9885 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
9886 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
9887 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9888 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9889 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9890 : : udp_dport, 0xFFFF);
9891 : : else
9892 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9893 : : udp_dport, dport);
9894 : : }
9895 : : /*
9896 : : * Read the UDP dport to check if the value satisfies the VXLAN
9897 : : * matching with MISC5 for CX5.
9898 : : */
9899 [ # # ]: 0 : if (wks->udp_dport)
9900 : : dport = wks->udp_dport;
9901 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9902 : 0 : return;
9903 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
9904 : : if ((item->mask == &nic_mask) &&
9905 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
9906 : : !priv->sh->tunnel_header_0_1) ||
9907 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
9908 : : !priv->sh->misc5_cap)))
9909 : : vxlan_m = &rte_flow_item_vxlan_mask;
9910 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
9911 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
9912 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
9913 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
9914 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
9915 [ # # ]: 0 : !priv->sh->misc5_cap)) {
9916 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9917 : : size = sizeof(vxlan_m->hdr.vni);
9918 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
9919 [ # # ]: 0 : for (i = 0; i < size; ++i)
9920 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
9921 : : return;
9922 : : }
9923 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
9924 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
9925 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
9926 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
9927 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
9928 : : }
9929 : :
9930 : : /**
9931 : : * Add VXLAN-GPE item to the value.
9932 : : *
9933 : : * @param[in, out] key
9934 : : * Flow matcher value.
9935 : : * @param[in] item
9936 : : * Flow pattern to translate.
9937 : : * @param[in] pattern_flags
9938 : : * Item pattern flags.
9939 : : * @param[in] key_type
9940 : : * Set flow matcher mask or value.
9941 : : */
9942 : :
9943 : : static void
9944 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
9945 : : const uint64_t pattern_flags,
9946 : : uint32_t key_type)
9947 : : {
9948 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
9949 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
9950 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
9951 : : /* The item was validated to be on the outer side */
9952 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9953 : : void *misc_v =
9954 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9955 : 0 : char *vni_v =
9956 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
9957 : : int i, size = sizeof(vxlan_m->hdr.vni);
9958 : : uint8_t flags_m = 0xff;
9959 : : uint8_t flags_v = 0xc;
9960 : : uint8_t m_protocol, v_protocol;
9961 : :
9962 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9963 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9964 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9965 : : 0xFFFF);
9966 : : else
9967 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9968 : : MLX5_UDP_PORT_VXLAN_GPE);
9969 : : }
9970 [ # # ]: 0 : if (!vxlan_v) {
9971 : : vxlan_v = &dummy_vxlan_gpe_hdr;
9972 : : vxlan_m = &dummy_vxlan_gpe_hdr;
9973 : : } else {
9974 [ # # ]: 0 : if (!vxlan_m)
9975 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
9976 : : }
9977 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9978 : : vxlan_v = vxlan_m;
9979 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
9980 : : vxlan_m = vxlan_v;
9981 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
9982 : : flags_m = vxlan_m->hdr.flags;
9983 : 0 : flags_v = vxlan_v->hdr.flags;
9984 : : }
9985 : 0 : m_protocol = vxlan_m->hdr.protocol;
9986 : 0 : v_protocol = vxlan_v->hdr.protocol;
9987 [ # # ]: 0 : if (!m_protocol) {
9988 : : /* Force next protocol to ensure next headers parsing. */
9989 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
9990 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
9991 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
9992 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
9993 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
9994 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
9995 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
9996 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
9997 [ # # ]: 0 : if (v_protocol)
9998 : : m_protocol = 0xFF;
9999 : : /* Restore the value to mask in mask case. */
10000 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10001 : : v_protocol = m_protocol;
10002 : : }
10003 : : /*
10004 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10005 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10006 : : */
10007 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10008 [ # # ]: 0 : for (i = 0; i < size; ++i)
10009 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10010 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10011 : : flags_m & flags_v);
10012 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10013 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10014 : : } else {
10015 : : uint32_t tunnel_v;
10016 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10017 : :
10018 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10019 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10020 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10021 : 0 : (m_protocol & v_protocol);
10022 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10023 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10024 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10025 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10026 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10027 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10028 : : }
10029 : 0 : }
10030 : :
10031 : : /**
10032 : : * Add Geneve item to the value.
10033 : : *
10034 : : * @param[in, out] key
10035 : : * Flow matcher value.
10036 : : * @param[in] item
10037 : : * Flow pattern to translate.
10038 : : * @param[in] pattern_flags
10039 : : * Item pattern flags.
10040 : : * @param[in] key_type
10041 : : * Set flow matcher mask or value.
10042 : : */
10043 : :
10044 : : static void
10045 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10046 : : uint64_t pattern_flags, uint32_t key_type)
10047 : : {
10048 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10049 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10050 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10051 : : /* GENEVE flow item validation allows single tunnel item */
10052 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10053 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10054 : : uint16_t gbhdr_m;
10055 : : uint16_t gbhdr_v;
10056 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10057 : : size_t size = sizeof(geneve_m->vni), i;
10058 : : uint16_t protocol_m, protocol_v;
10059 : :
10060 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10061 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10062 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10063 : : 0xFFFF);
10064 : : else
10065 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10066 : : MLX5_UDP_PORT_GENEVE);
10067 : : }
10068 [ # # ]: 0 : if (!geneve_v) {
10069 : : geneve_v = &empty_geneve;
10070 : : geneve_m = &empty_geneve;
10071 : : } else {
10072 [ # # ]: 0 : if (!geneve_m)
10073 : : geneve_m = &rte_flow_item_geneve_mask;
10074 : : }
10075 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10076 : : geneve_v = geneve_m;
10077 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10078 : : geneve_m = geneve_v;
10079 [ # # ]: 0 : for (i = 0; i < size; ++i)
10080 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10081 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10082 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10083 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10084 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10085 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10086 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10087 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10088 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10089 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10090 [ # # ]: 0 : if (!protocol_m) {
10091 : : /* Force next protocol to prevent matchers duplication */
10092 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10093 : : if (protocol_v)
10094 : : protocol_m = 0xFFFF;
10095 : : /* Restore the value to mask in mask case. */
10096 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10097 : : protocol_v = protocol_m;
10098 : : }
10099 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10100 : : protocol_m & protocol_v);
10101 : 0 : }
10102 : :
10103 : : /**
10104 : : * Create Geneve TLV option resource.
10105 : : *
10106 : : * @param[in, out] dev
10107 : : * Pointer to rte_eth_dev structure.
10108 : : * @param[in] item
10109 : : * Flow pattern to translate.
10110 : : * @param[out] error
10111 : : * pointer to error structure.
10112 : : *
10113 : : * @return
10114 : : * 0 on success otherwise -errno and errno is set.
10115 : : */
10116 : : static int
10117 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10118 : : const struct rte_flow_item *item,
10119 : : struct rte_flow_error *error)
10120 : : {
10121 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10122 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10123 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10124 : : sh->geneve_tlv_option_resource;
10125 : : struct mlx5_devx_obj *obj;
10126 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10127 : : int ret = 0;
10128 : :
10129 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10130 [ # # ]: 0 : if (!geneve_opt_v)
10131 : : return -1;
10132 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10133 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10134 : 0 : if (geneve_opt_resource->option_class ==
10135 : : geneve_opt_v->option_class &&
10136 : : geneve_opt_resource->option_type ==
10137 [ # # ]: 0 : geneve_opt_v->option_type &&
10138 : : geneve_opt_resource->length ==
10139 : : geneve_opt_v->option_len) {
10140 : 0 : __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
10141 : : __ATOMIC_RELAXED);
10142 : : } else {
10143 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10144 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10145 : : "Only one GENEVE TLV option supported");
10146 : 0 : goto exit;
10147 : : }
10148 : : } else {
10149 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10150 : 0 : .option_class = geneve_opt_v->option_class,
10151 : 0 : .option_type = geneve_opt_v->option_type,
10152 : 0 : .option_data_len = geneve_opt_v->option_len,
10153 : : };
10154 : :
10155 : : /* Create a GENEVE TLV object and resource. */
10156 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10157 : : &attr);
10158 [ # # ]: 0 : if (!obj) {
10159 : 0 : ret = rte_flow_error_set(error, ENODATA,
10160 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10161 : : "Failed to create GENEVE TLV Devx object");
10162 : 0 : goto exit;
10163 : : }
10164 : 0 : sh->geneve_tlv_option_resource =
10165 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10166 : : sizeof(*geneve_opt_resource),
10167 : : 0, SOCKET_ID_ANY);
10168 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10169 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10170 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10171 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10172 : : "GENEVE TLV object memory allocation failed");
10173 : 0 : goto exit;
10174 : : }
10175 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10176 : 0 : geneve_opt_resource->obj = obj;
10177 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10178 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10179 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10180 : 0 : __atomic_store_n(&geneve_opt_resource->refcnt, 1,
10181 : : __ATOMIC_RELAXED);
10182 : : }
10183 : 0 : exit:
10184 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10185 : 0 : return ret;
10186 : : }
10187 : :
10188 : : /**
10189 : : * Add Geneve TLV option item to value.
10190 : : *
10191 : : * @param[in, out] dev
10192 : : * Pointer to rte_eth_dev structure.
10193 : : * @param[in, out] key
10194 : : * Flow matcher value.
10195 : : * @param[in] item
10196 : : * Flow pattern to translate.
10197 : : * @param[in] key_type
10198 : : * Set flow matcher mask or value.
10199 : : * @param[out] error
10200 : : * Pointer to error structure.
10201 : : */
10202 : : static int
10203 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10204 : : const struct rte_flow_item *item,
10205 : : uint32_t key_type,
10206 : : struct rte_flow_error *error)
10207 : : {
10208 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10209 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10210 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10211 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10212 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10213 : : size_t option_byte_len;
10214 : : int ret = 0;
10215 : :
10216 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10217 : : return -1;
10218 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10219 : : &rte_flow_item_geneve_opt_mask);
10220 : : /*
10221 : : * Register resource requires item spec for SW steering,
10222 : : * for HW steering resources is registered explicitly by user.
10223 : : */
10224 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10225 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10226 : : error);
10227 [ # # ]: 0 : if (ret) {
10228 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10229 : 0 : return ret;
10230 : : }
10231 : : }
10232 : : /* Convert the option length from DW to bytes for using memcpy. */
10233 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10234 : : sizeof(rte_be32_t));
10235 [ # # ]: 0 : if (geneve_opt_v->data) {
10236 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10237 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10238 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10239 : : geneve_tlv_option_0_data,
10240 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10241 : : }
10242 : : return ret;
10243 : : }
10244 : :
10245 : : /**
10246 : : * Add MPLS item to the value.
10247 : : *
10248 : : * @param[in, out] key
10249 : : * Flow matcher value.
10250 : : * @param[in] item
10251 : : * Flow pattern to translate.
10252 : : * @param[in] prev_layer
10253 : : * The protocol layer indicated in previous item.
10254 : : * @param[in] inner
10255 : : * Item is inner pattern.
10256 : : * @param[in] key_type
10257 : : * Set flow matcher mask or value.
10258 : : */
10259 : : static void
10260 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10261 : : uint64_t prev_layer, int inner,
10262 : : uint32_t key_type)
10263 : : {
10264 : : const uint32_t *in_mpls_m;
10265 : : const uint32_t *in_mpls_v;
10266 : : uint32_t *out_mpls_v = 0;
10267 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10268 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10269 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10270 : :
10271 [ # # # ]: 0 : switch (prev_layer) {
10272 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10273 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10274 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10275 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10276 : : udp_dport, 0xffff);
10277 : : else
10278 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10279 : : udp_dport, MLX5_UDP_PORT_MPLS);
10280 : : }
10281 : : break;
10282 : 0 : case MLX5_FLOW_LAYER_GRE:
10283 : : /* Fall-through. */
10284 : : case MLX5_FLOW_LAYER_GRE_KEY:
10285 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10286 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10287 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10288 : : gre_protocol, 0xffff);
10289 : : else
10290 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10291 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10292 : : }
10293 : : break;
10294 : : default:
10295 : : break;
10296 : : }
10297 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10298 : : return;
10299 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10300 : : &rte_flow_item_mpls_mask);
10301 [ # # # ]: 0 : switch (prev_layer) {
10302 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10303 : 0 : out_mpls_v =
10304 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10305 : : outer_first_mpls_over_udp);
10306 : 0 : break;
10307 : 0 : case MLX5_FLOW_LAYER_GRE:
10308 : 0 : out_mpls_v =
10309 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10310 : : outer_first_mpls_over_gre);
10311 : 0 : break;
10312 : 0 : default:
10313 : : /* Inner MPLS not over GRE is not supported. */
10314 [ # # ]: 0 : if (!inner)
10315 : : out_mpls_v =
10316 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10317 : : misc2_v,
10318 : : outer_first_mpls);
10319 : : break;
10320 : : }
10321 : : if (out_mpls_v)
10322 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10323 : : }
10324 : :
10325 : : /**
10326 : : * Add metadata register item to matcher
10327 : : *
10328 : : * @param[in, out] key
10329 : : * Flow matcher value.
10330 : : * @param[in] reg_type
10331 : : * Type of device metadata register
10332 : : * @param[in] data
10333 : : * Register data
10334 : : * @param[in] mask
10335 : : * Register mask
10336 : : */
10337 : : static void
10338 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10339 : : uint32_t data, uint32_t mask)
10340 : : {
10341 : : void *misc2_v =
10342 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10343 : : uint32_t temp;
10344 : :
10345 : 0 : data &= mask;
10346 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # ]
10347 : 0 : case REG_A:
10348 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10349 : 0 : break;
10350 : 0 : case REG_B:
10351 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10352 : 0 : break;
10353 : 0 : case REG_C_0:
10354 : : /*
10355 : : * The metadata register C0 field might be divided into
10356 : : * source vport index and META item value, we should set
10357 : : * this field according to specified mask, not as whole one.
10358 : : */
10359 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10360 [ # # # # ]: 0 : if (mask)
10361 : 0 : temp &= ~mask;
10362 : 0 : temp |= data;
10363 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10364 : 0 : break;
10365 : 0 : case REG_C_1:
10366 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10367 : 0 : break;
10368 : 0 : case REG_C_2:
10369 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10370 : 0 : break;
10371 : 0 : case REG_C_3:
10372 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10373 : 0 : break;
10374 : 0 : case REG_C_4:
10375 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10376 : 0 : break;
10377 : 0 : case REG_C_5:
10378 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10379 : 0 : break;
10380 : 0 : case REG_C_6:
10381 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10382 : 0 : break;
10383 : 0 : case REG_C_7:
10384 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10385 : 0 : break;
10386 : : default:
10387 : : MLX5_ASSERT(false);
10388 : : break;
10389 : : }
10390 : 0 : }
10391 : :
10392 : : /**
10393 : : * Add metadata register item to matcher
10394 : : *
10395 : : * @param[in, out] matcher
10396 : : * Flow matcher.
10397 : : * @param[in, out] key
10398 : : * Flow matcher value.
10399 : : * @param[in] reg_type
10400 : : * Type of device metadata register
10401 : : * @param[in] value
10402 : : * Register value
10403 : : * @param[in] mask
10404 : : * Register mask
10405 : : */
10406 : : static void
10407 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10408 : : uint32_t data, uint32_t mask)
10409 : : {
10410 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10411 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10412 : : }
10413 : :
10414 : : /**
10415 : : * Add MARK item to matcher
10416 : : *
10417 : : * @param[in] dev
10418 : : * The device to configure through.
10419 : : * @param[in, out] key
10420 : : * Flow matcher value.
10421 : : * @param[in] item
10422 : : * Flow pattern to translate.
10423 : : * @param[in] key_type
10424 : : * Set flow matcher mask or value.
10425 : : */
10426 : : static void
10427 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10428 : : const struct rte_flow_item *item,
10429 : : uint32_t key_type)
10430 : : {
10431 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10432 : : const struct rte_flow_item_mark *mark;
10433 : : uint32_t value;
10434 : : uint32_t mask = 0;
10435 : :
10436 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10437 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10438 : : &rte_flow_item_mark_mask;
10439 : 0 : mask = mark->id;
10440 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10441 : : value = mask;
10442 : : } else {
10443 : 0 : mark = (const void *)item->spec;
10444 : : MLX5_ASSERT(mark);
10445 : 0 : value = mark->id;
10446 : : }
10447 : : } else {
10448 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10449 : : (const void *)item->spec : (const void *)item->mask;
10450 : : MLX5_ASSERT(mark);
10451 : 0 : value = mark->id;
10452 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10453 : : mask = value;
10454 : : }
10455 : 0 : mask &= priv->sh->dv_mark_mask;
10456 : 0 : value &= mask;
10457 [ # # ]: 0 : if (mask) {
10458 : : enum modify_reg reg;
10459 : :
10460 : : /* Get the metadata register index for the mark. */
10461 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10462 : : MLX5_ASSERT(reg > 0);
10463 [ # # ]: 0 : if (reg == REG_C_0) {
10464 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10465 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10466 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10467 : :
10468 : 0 : mask &= msk_c0;
10469 : 0 : mask <<= shl_c0;
10470 : 0 : value <<= shl_c0;
10471 : : }
10472 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10473 : : }
10474 : 0 : }
10475 : :
10476 : : /**
10477 : : * Add META item to matcher
10478 : : *
10479 : : * @param[in] dev
10480 : : * The devich to configure through.
10481 : : * @param[in, out] key
10482 : : * Flow matcher value.
10483 : : * @param[in] attr
10484 : : * Attributes of flow that includes this item.
10485 : : * @param[in] item
10486 : : * Flow pattern to translate.
10487 : : * @param[in] key_type
10488 : : * Set flow matcher mask or value.
10489 : : */
10490 : : static void
10491 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10492 : : void *key,
10493 : : const struct rte_flow_attr *attr,
10494 : : const struct rte_flow_item *item,
10495 : : uint32_t key_type)
10496 : : {
10497 : : const struct rte_flow_item_meta *meta_m;
10498 : : const struct rte_flow_item_meta *meta_v;
10499 : : uint32_t value;
10500 : : uint32_t mask = 0;
10501 : : int reg;
10502 : :
10503 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10504 : : return;
10505 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10506 : : &rte_flow_item_meta_mask);
10507 : 0 : value = meta_v->data;
10508 : 0 : mask = meta_m->data;
10509 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10510 : : mask = value;
10511 : : /*
10512 : : * In the current implementation, REG_B cannot be used to match.
10513 : : * Force to use REG_C_1 in HWS root table as other tables.
10514 : : * This map may change.
10515 : : * NIC: modify - REG_B to be present in SW
10516 : : * match - REG_C_1 when copied from FDB, different from SWS
10517 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10518 : : * match - REG_C_1 in FDB
10519 : : */
10520 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10521 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10522 : : else
10523 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10524 [ # # ]: 0 : if (reg < 0)
10525 : : return;
10526 : : MLX5_ASSERT(reg != REG_NON);
10527 [ # # ]: 0 : if (reg == REG_C_0) {
10528 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10529 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10530 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10531 : :
10532 : 0 : mask &= msk_c0;
10533 : 0 : mask <<= shl_c0;
10534 : 0 : value <<= shl_c0;
10535 : : }
10536 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10537 : : }
10538 : :
10539 : : /**
10540 : : * Add vport metadata Reg C0 item to matcher
10541 : : *
10542 : : * @param[in, out] key
10543 : : * Flow matcher value.
10544 : : * @param[in] value
10545 : : * Register value
10546 : : * @param[in] mask
10547 : : * Register mask
10548 : : */
10549 : : static void
10550 [ # # ]: 0 : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10551 : : {
10552 : : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10553 : 0 : }
10554 : :
10555 : : /**
10556 : : * Add tag item to matcher
10557 : : *
10558 : : * @param[in] dev
10559 : : * The devich to configure through.
10560 : : * @param[in, out] key
10561 : : * Flow matcher value.
10562 : : * @param[in] item
10563 : : * Flow pattern to translate.
10564 : : * @param[in] key_type
10565 : : * Set flow matcher mask or value.
10566 : : */
10567 : : static void
10568 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10569 : : const struct rte_flow_item *item,
10570 : : uint32_t key_type)
10571 : : {
10572 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10573 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10574 : : uint32_t mask, value;
10575 : :
10576 : : MLX5_ASSERT(tag_v);
10577 : 0 : value = tag_v->data;
10578 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10579 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10580 : : value = mask;
10581 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10582 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10583 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10584 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10585 : :
10586 : 0 : mask &= msk_c0;
10587 : 0 : mask <<= shl_c0;
10588 : 0 : value <<= shl_c0;
10589 : : }
10590 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10591 : 0 : }
10592 : :
10593 : : /**
10594 : : * Add TAG item to matcher
10595 : : *
10596 : : * @param[in] dev
10597 : : * The devich to configure through.
10598 : : * @param[in, out] key
10599 : : * Flow matcher value.
10600 : : * @param[in] item
10601 : : * Flow pattern to translate.
10602 : : * @param[in] key_type
10603 : : * Set flow matcher mask or value.
10604 : : */
10605 : : static void
10606 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10607 : : const struct rte_flow_item *item,
10608 : : uint32_t key_type)
10609 : : {
10610 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10611 : : const struct rte_flow_item_tag *tag_v;
10612 : : const struct rte_flow_item_tag *tag_m;
10613 : : int reg;
10614 : : uint32_t index;
10615 : :
10616 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10617 : : return;
10618 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10619 : : &rte_flow_item_tag_mask);
10620 : : /* When set mask, the index should be from spec. */
10621 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10622 : : /* Get the metadata register index for the tag. */
10623 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10624 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10625 : : else
10626 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10627 : : MLX5_ASSERT(reg > 0);
10628 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10629 : : }
10630 : :
10631 : : /**
10632 : : * Add source vport match to the specified matcher.
10633 : : *
10634 : : * @param[in, out] key
10635 : : * Flow matcher value.
10636 : : * @param[in] port
10637 : : * Source vport value to match
10638 : : */
10639 : : static void
10640 : : flow_dv_translate_item_source_vport(void *key,
10641 : : int16_t port)
10642 : : {
10643 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10644 : :
10645 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10646 : 0 : }
10647 : :
10648 : : /**
10649 : : * Translate port-id item to eswitch match on port-id.
10650 : : *
10651 : : * @param[in] dev
10652 : : * The devich to configure through.
10653 : : * @param[in, out] key
10654 : : * Flow matcher value.
10655 : : * @param[in] item
10656 : : * Flow pattern to translate.
10657 : : * @param[in] attr
10658 : : * Flow attributes.
10659 : : * @param[in] key_type
10660 : : * Set flow matcher mask or value.
10661 : : *
10662 : : * @return
10663 : : * 0 on success, a negative errno value otherwise.
10664 : : */
10665 : : static int
10666 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10667 : : const struct rte_flow_item *item,
10668 : : const struct rte_flow_attr *attr,
10669 : : uint32_t key_type)
10670 : : {
10671 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10672 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10673 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10674 : : struct mlx5_priv *priv;
10675 : : uint16_t mask, id;
10676 : : uint32_t vport_meta;
10677 : :
10678 : : MLX5_ASSERT(wks);
10679 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10680 : 0 : flow_dv_translate_item_source_vport(key,
10681 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10682 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10683 : 0 : return 0;
10684 : : }
10685 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10686 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10687 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10688 [ # # ]: 0 : if (!priv)
10689 : 0 : return -rte_errno;
10690 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10691 : : id = mask;
10692 : 0 : vport_meta = priv->vport_meta_mask;
10693 : : } else {
10694 : 0 : id = priv->vport_id;
10695 : 0 : vport_meta = priv->vport_meta_tag;
10696 : 0 : wks->vport_meta_tag = vport_meta;
10697 : : }
10698 : : /*
10699 : : * Translate to vport field or to metadata, depending on mode.
10700 : : * Kernel can use either misc.source_port or half of C0 metadata
10701 : : * register.
10702 : : */
10703 [ # # ]: 0 : if (priv->vport_meta_mask) {
10704 : : /*
10705 : : * Provide the hint for SW steering library
10706 : : * to insert the flow into ingress domain and
10707 : : * save the extra vport match.
10708 : : */
10709 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10710 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10711 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10712 : : /*
10713 : : * We should always set the vport metadata register,
10714 : : * otherwise the SW steering library can drop
10715 : : * the rule if wire vport metadata value is not zero,
10716 : : * it depends on kernel configuration.
10717 : : */
10718 : 0 : flow_dv_translate_item_meta_vport
10719 : : (key, vport_meta, priv->vport_meta_mask);
10720 : : } else {
10721 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10722 : : }
10723 : : return 0;
10724 : : }
10725 : :
10726 : : /**
10727 : : * Translate port representor item to eswitch match on port id.
10728 : : *
10729 : : * @param[in] dev
10730 : : * The devich to configure through.
10731 : : * @param[in, out] key
10732 : : * Flow matcher value.
10733 : : * @param[in] key_type
10734 : : * Set flow matcher mask or value.
10735 : : *
10736 : : * @return
10737 : : * 0 on success, a negative errno value otherwise.
10738 : : */
10739 : : static int
10740 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
10741 : : uint32_t key_type)
10742 : : {
10743 : 0 : flow_dv_translate_item_source_vport(key,
10744 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10745 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10746 : 0 : return 0;
10747 : : }
10748 : :
10749 : : /**
10750 : : * Translate represented port item to eswitch match on port id.
10751 : : *
10752 : : * @param[in] dev
10753 : : * The devich to configure through.
10754 : : * @param[in, out] key
10755 : : * Flow matcher value.
10756 : : * @param[in] item
10757 : : * Flow pattern to translate.
10758 : : * @param[in]
10759 : : * Flow attributes.
10760 : : *
10761 : : * @return
10762 : : * 0 on success, a negative errno value otherwise.
10763 : : */
10764 : : static int
10765 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
10766 : : const struct rte_flow_item *item,
10767 : : const struct rte_flow_attr *attr,
10768 : : uint32_t key_type)
10769 : : {
10770 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
10771 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
10772 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10773 : : struct mlx5_priv *priv;
10774 : : uint16_t mask, id;
10775 : : uint32_t vport_meta;
10776 : :
10777 : : MLX5_ASSERT(wks);
10778 [ # # ]: 0 : if (!pid_m && !pid_v)
10779 : : return 0;
10780 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
10781 : 0 : flow_dv_translate_item_source_vport(key,
10782 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10783 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10784 : 0 : return 0;
10785 : : }
10786 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
10787 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
10788 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10789 [ # # ]: 0 : if (!priv)
10790 : 0 : return -rte_errno;
10791 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10792 : : id = mask;
10793 : 0 : vport_meta = priv->vport_meta_mask;
10794 : : } else {
10795 : 0 : id = priv->vport_id;
10796 : 0 : vport_meta = priv->vport_meta_tag;
10797 : 0 : wks->vport_meta_tag = vport_meta;
10798 : : }
10799 : : /*
10800 : : * Translate to vport field or to metadata, depending on mode.
10801 : : * Kernel can use either misc.source_port or half of C0 metadata
10802 : : * register.
10803 : : */
10804 [ # # ]: 0 : if (priv->vport_meta_mask) {
10805 : : /*
10806 : : * Provide the hint for SW steering library
10807 : : * to insert the flow into ingress domain and
10808 : : * save the extra vport match.
10809 : : */
10810 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
10811 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
10812 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
10813 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10814 : : /*
10815 : : * We should always set the vport metadata register,
10816 : : * otherwise the SW steering library can drop
10817 : : * the rule if wire vport metadata value is not zero,
10818 : : * it depends on kernel configuration.
10819 : : */
10820 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
10821 : : priv->vport_meta_mask);
10822 : : } else {
10823 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10824 : : }
10825 : : return 0;
10826 : : }
10827 : :
10828 : : /**
10829 : : * Translate port-id item to eswitch match on port-id.
10830 : : *
10831 : : * @param[in] dev
10832 : : * The devich to configure through.
10833 : : * @param[in, out] matcher
10834 : : * Flow matcher.
10835 : : * @param[in, out] key
10836 : : * Flow matcher value.
10837 : : * @param[in] item
10838 : : * Flow pattern to translate.
10839 : : * @param[in] attr
10840 : : * Flow attributes.
10841 : : *
10842 : : * @return
10843 : : * 0 on success, a negative errno value otherwise.
10844 : : */
10845 : : static int
10846 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
10847 : : void *matcher, void *key,
10848 : : const struct rte_flow_item *item,
10849 : : const struct rte_flow_attr *attr)
10850 : : {
10851 : : int ret;
10852 : :
10853 : 0 : ret = flow_dv_translate_item_port_id
10854 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
10855 [ # # ]: 0 : if (ret)
10856 : : return ret;
10857 : 0 : ret = flow_dv_translate_item_port_id
10858 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
10859 : 0 : return ret;
10860 : : }
10861 : :
10862 : :
10863 : : /**
10864 : : * Add ICMP6 item to the value.
10865 : : *
10866 : : * @param[in, out] key
10867 : : * Flow matcher value.
10868 : : * @param[in] item
10869 : : * Flow pattern to translate.
10870 : : * @param[in] inner
10871 : : * Item is inner pattern.
10872 : : * @param[in] key_type
10873 : : * Set flow matcher mask or value.
10874 : : */
10875 : : static void
10876 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
10877 : : int inner, uint32_t key_type)
10878 : : {
10879 : : const struct rte_flow_item_icmp6 *icmp6_m;
10880 : : const struct rte_flow_item_icmp6 *icmp6_v;
10881 : : void *headers_v;
10882 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10883 : :
10884 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10885 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10886 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10887 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
10888 : : else
10889 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
10890 : : IPPROTO_ICMPV6);
10891 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10892 : : return;
10893 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
10894 : : &rte_flow_item_icmp6_mask);
10895 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
10896 : : icmp6_v->type & icmp6_m->type);
10897 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
10898 : : icmp6_v->code & icmp6_m->code);
10899 : : }
10900 : :
10901 : : /**
10902 : : * Add ICMP6 echo request/reply item to the value.
10903 : : *
10904 : : * @param[in, out] key
10905 : : * Flow matcher value.
10906 : : * @param[in] item
10907 : : * Flow pattern to translate.
10908 : : * @param[in] inner
10909 : : * Item is inner pattern.
10910 : : * @param[in] key_type
10911 : : * Set flow matcher mask or value.
10912 : : */
10913 : : static void
10914 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
10915 : : int inner, uint32_t key_type)
10916 : : {
10917 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
10918 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
10919 : : uint32_t icmp6_header_data_m = 0;
10920 : : uint32_t icmp6_header_data_v = 0;
10921 : : void *headers_v;
10922 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10923 : : uint8_t icmp6_type = 0;
10924 : : struct rte_flow_item_icmp6_echo zero_mask;
10925 : :
10926 : : memset(&zero_mask, 0, sizeof(zero_mask));
10927 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10928 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10929 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10930 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
10931 : : else
10932 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
10933 : : IPPROTO_ICMPV6);
10934 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
10935 : : /* Set fixed type and code for icmpv6 echo request or reply */
10936 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
10937 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
10938 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10939 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
10940 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
10941 : : } else {
10942 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
10943 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
10944 : : }
10945 [ # # ]: 0 : if (icmp6_v == NULL)
10946 : 0 : return;
10947 : : /* Set icmp6 header data (identifier & sequence) accordingly */
10948 : 0 : icmp6_header_data_m =
10949 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
10950 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
10951 [ # # ]: 0 : if (icmp6_header_data_m) {
10952 : 0 : icmp6_header_data_v =
10953 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
10954 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
10955 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
10956 : : icmp6_header_data_v & icmp6_header_data_m);
10957 : : }
10958 : : }
10959 : :
10960 : : /**
10961 : : * Add ICMP item to the value.
10962 : : *
10963 : : * @param[in, out] key
10964 : : * Flow matcher value.
10965 : : * @param[in] item
10966 : : * Flow pattern to translate.
10967 : : * @param[in] inner
10968 : : * Item is inner pattern.
10969 : : * @param[in] key_type
10970 : : * Set flow matcher mask or value.
10971 : : */
10972 : : static void
10973 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
10974 : : int inner, uint32_t key_type)
10975 : : {
10976 : : const struct rte_flow_item_icmp *icmp_m;
10977 : : const struct rte_flow_item_icmp *icmp_v;
10978 : : uint32_t icmp_header_data_m = 0;
10979 : : uint32_t icmp_header_data_v = 0;
10980 : : void *headers_v;
10981 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10982 : :
10983 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10984 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10985 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10986 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10987 : : ip_protocol, 0xFF);
10988 : : else
10989 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10990 : : ip_protocol, IPPROTO_ICMP);
10991 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10992 : : return;
10993 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
10994 : : &rte_flow_item_icmp_mask);
10995 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
10996 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
10997 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
10998 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
10999 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11000 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11001 [ # # ]: 0 : if (icmp_header_data_m) {
11002 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11003 : 0 : icmp_header_data_v |=
11004 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11005 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11006 : : icmp_header_data_v & icmp_header_data_m);
11007 : : }
11008 : : }
11009 : :
11010 : : /**
11011 : : * Add GTP item to the value.
11012 : : *
11013 : : * @param[in, out] key
11014 : : * Flow matcher value.
11015 : : * @param[in] item
11016 : : * Flow pattern to translate.
11017 : : * @param[in] inner
11018 : : * Item is inner pattern.
11019 : : * @param[in] key_type
11020 : : * Set flow matcher mask or value.
11021 : : */
11022 : : static void
11023 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11024 : : int inner, uint32_t key_type)
11025 : : {
11026 : : const struct rte_flow_item_gtp *gtp_m;
11027 : : const struct rte_flow_item_gtp *gtp_v;
11028 : : void *headers_v;
11029 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11030 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11031 : :
11032 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11033 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11034 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11035 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11036 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11037 : : udp_dport, 0xFFFF);
11038 : : else
11039 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11040 : : udp_dport, dport);
11041 : : }
11042 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11043 : : return;
11044 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11045 : : &rte_flow_item_gtp_mask);
11046 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11047 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11048 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11049 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11050 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11051 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11052 : : }
11053 : :
11054 : : /**
11055 : : * Add GTP PSC item to matcher.
11056 : : *
11057 : : * @param[in, out] key
11058 : : * Flow matcher value.
11059 : : * @param[in] item
11060 : : * Flow pattern to translate.
11061 : : * @param[in] key_type
11062 : : * Set flow matcher mask or value.
11063 : : */
11064 : : static int
11065 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11066 : : uint32_t key_type)
11067 : : {
11068 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11069 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11070 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11071 : : union {
11072 : : uint32_t w32;
11073 : : struct {
11074 : : uint16_t seq_num;
11075 : : uint8_t npdu_num;
11076 : : uint8_t next_ext_header_type;
11077 : : };
11078 : : } dw_2;
11079 : : union {
11080 : : uint32_t w32;
11081 : : struct {
11082 : : uint8_t len;
11083 : : uint8_t type_flags;
11084 : : uint8_t qfi;
11085 : : uint8_t reserved;
11086 : : };
11087 : : } dw_0;
11088 : : uint8_t gtp_flags;
11089 : :
11090 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11091 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11092 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11093 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11094 : : /*Set next extension header type. */
11095 : 0 : dw_2.seq_num = 0;
11096 : 0 : dw_2.npdu_num = 0;
11097 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11098 : 0 : dw_2.next_ext_header_type = 0xff;
11099 : : else
11100 : 0 : dw_2.next_ext_header_type = 0x85;
11101 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11102 : : rte_cpu_to_be_32(dw_2.w32));
11103 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11104 : : return 0;
11105 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11106 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11107 : 0 : dw_0.w32 = 0;
11108 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11109 : : gtp_psc_m->hdr.type);
11110 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11111 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11112 : : rte_cpu_to_be_32(dw_0.w32));
11113 : 0 : return 0;
11114 : : }
11115 : :
11116 : : /**
11117 : : * Add eCPRI item to matcher and to the value.
11118 : : *
11119 : : * @param[in] dev
11120 : : * The devich to configure through.
11121 : : * @param[in, out] key
11122 : : * Flow matcher value.
11123 : : * @param[in] item
11124 : : * Flow pattern to translate.
11125 : : * @param[in] last_item
11126 : : * Last item flags.
11127 : : * @param[in] key_type
11128 : : * Set flow matcher mask or value.
11129 : : */
11130 : : static void
11131 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11132 : : const struct rte_flow_item *item,
11133 : : uint64_t last_item, uint32_t key_type)
11134 : : {
11135 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11136 : : const struct rte_flow_item_ecpri *ecpri_m;
11137 : : const struct rte_flow_item_ecpri *ecpri_v;
11138 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11139 : : struct rte_ecpri_common_hdr common;
11140 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11141 : : uint32_t *samples;
11142 : : void *dw_v;
11143 : :
11144 : : /*
11145 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11146 : : * match on eCPRI EtherType implicitly.
11147 : : */
11148 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11149 : : void *hdrs_v, *l2v;
11150 : :
11151 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11152 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11153 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11154 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11155 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11156 : : else
11157 : 0 : *(uint16_t *)l2v =
11158 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11159 : : }
11160 : : }
11161 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11162 : 0 : return;
11163 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m,
# # # # ]
11164 : : &rte_flow_item_ecpri_mask);
11165 : : /*
11166 : : * Maximal four DW samples are supported in a single matching now.
11167 : : * Two are used now for a eCPRI matching:
11168 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11169 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11170 : : * if any.
11171 : : */
11172 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32)
11173 : : return;
11174 : 0 : samples = priv->sh->ecpri_parser.ids;
11175 : : /* Need to take the whole DW as the mask to fill the entry. */
11176 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11177 : : prog_sample_field_value_0);
11178 : : /* Already big endian (network order) in the header. */
11179 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11180 : : /* Sample#0, used for matching type, offset 0. */
11181 : : /* It makes no sense to set the sample ID in the mask field. */
11182 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11183 : : prog_sample_field_id_0, samples[0]);
11184 : : /*
11185 : : * Checking if message body part needs to be matched.
11186 : : * Some wildcard rules only matching type field should be supported.
11187 : : */
11188 [ # # ]: 0 : if (ecpri_m->hdr.dummy[0]) {
11189 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
11190 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11191 : : else
11192 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11193 [ # # ]: 0 : switch (common.type) {
11194 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11195 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11196 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11197 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11198 : : prog_sample_field_value_1);
11199 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
11200 : : ecpri_m->hdr.dummy[0];
11201 : : /* Sample#1, to match message body, offset 4. */
11202 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11203 : : prog_sample_field_id_1, samples[1]);
11204 : 0 : break;
11205 : : default:
11206 : : /* Others, do not match any sample ID. */
11207 : : break;
11208 : : }
11209 : : }
11210 : : }
11211 : :
11212 : : /*
11213 : : * Add connection tracking status item to matcher
11214 : : *
11215 : : * @param[in] dev
11216 : : * The devich to configure through.
11217 : : * @param[in, out] matcher
11218 : : * Flow matcher.
11219 : : * @param[in, out] key
11220 : : * Flow matcher value.
11221 : : * @param[in] item
11222 : : * Flow pattern to translate.
11223 : : */
11224 : : static void
11225 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11226 : : void *matcher, void *key,
11227 : : const struct rte_flow_item *item)
11228 : : {
11229 : : uint32_t reg_value = 0;
11230 : : int reg_id;
11231 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11232 : : uint32_t reg_mask = 0;
11233 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11234 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11235 : : uint32_t flags;
11236 : : struct rte_flow_error error;
11237 : :
11238 [ # # ]: 0 : if (!mask)
11239 : : mask = &rte_flow_item_conntrack_mask;
11240 [ # # # # ]: 0 : if (!spec || !mask->flags)
11241 : 0 : return;
11242 : 0 : flags = spec->flags & mask->flags;
11243 : : /* The conflict should be checked in the validation. */
11244 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11245 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11246 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11247 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11248 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11249 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11250 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11251 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11252 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11253 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11254 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11255 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11256 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11257 : : reg_mask |= 0xc0;
11258 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11259 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11260 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11261 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11262 : : /* The REG_C_x value could be saved during startup. */
11263 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11264 [ # # ]: 0 : if (reg_id == REG_NON)
11265 : : return;
11266 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11267 : : reg_value, reg_mask);
11268 : : }
11269 : :
11270 : : static void
11271 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11272 : : const struct rte_flow_item *item,
11273 : : struct mlx5_flow *dev_flow, bool is_inner)
11274 : : {
11275 : 0 : const struct rte_flow_item_flex *spec =
11276 : : (const struct rte_flow_item_flex *)item->spec;
11277 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11278 : :
11279 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11280 [ # # ]: 0 : if (index < 0)
11281 : : return;
11282 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11283 : : /* Don't count both inner and outer flex items in one rule. */
11284 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11285 : : MLX5_ASSERT(false);
11286 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11287 : : }
11288 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11289 : : }
11290 : :
11291 : : /**
11292 : : * Add METER_COLOR item to matcher
11293 : : *
11294 : : * @param[in] dev
11295 : : * The device to configure through.
11296 : : * @param[in, out] key
11297 : : * Flow matcher value.
11298 : : * @param[in] item
11299 : : * Flow pattern to translate.
11300 : : * @param[in] key_type
11301 : : * Set flow matcher mask or value.
11302 : : */
11303 : : static void
11304 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11305 : : const struct rte_flow_item *item,
11306 : : uint32_t key_type)
11307 : : {
11308 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11309 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11310 : : uint32_t value, mask;
11311 : : int reg = REG_NON;
11312 : :
11313 : : MLX5_ASSERT(color_v);
11314 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11315 : : return;
11316 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11317 : : &rte_flow_item_meter_color_mask);
11318 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11319 : : mask = color_m ?
11320 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11321 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11322 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11323 : : else
11324 : : reg = flow_hw_get_reg_id(dev,
11325 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11326 [ # # ]: 0 : if (reg == REG_NON)
11327 : : return;
11328 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11329 : : }
11330 : :
11331 : : static void
11332 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11333 : : const struct rte_flow_item *item,
11334 : : uint32_t key_type)
11335 : : {
11336 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11337 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11338 : : void *misc_v;
11339 : :
11340 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11341 : : &rte_flow_item_aggr_affinity_mask);
11342 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11343 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11344 : : affinity_v->affinity & affinity_m->affinity);
11345 : 0 : }
11346 : :
11347 : : static void
11348 : 0 : flow_dv_translate_item_ib_bth(void *key,
11349 : : const struct rte_flow_item *item,
11350 : : int inner, uint32_t key_type)
11351 : : {
11352 : : const struct rte_flow_item_ib_bth *bth_m;
11353 : : const struct rte_flow_item_ib_bth *bth_v;
11354 : : void *headers_v, *misc_v;
11355 : : uint16_t udp_dport;
11356 : : char *qpn_v;
11357 : : int i, size;
11358 : :
11359 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11360 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11361 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11362 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11363 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11364 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11365 : : }
11366 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11367 : : return;
11368 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11369 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11370 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11371 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11372 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11373 : : size = sizeof(bth_m->hdr.dst_qp);
11374 [ # # ]: 0 : for (i = 0; i < size; ++i)
11375 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11376 : : }
11377 : :
11378 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11379 : :
11380 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11381 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11382 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11383 : :
11384 : : /**
11385 : : * Calculate flow matcher enable bitmap.
11386 : : *
11387 : : * @param match_criteria
11388 : : * Pointer to flow matcher criteria.
11389 : : *
11390 : : * @return
11391 : : * Bitmap of enabled fields.
11392 : : */
11393 : : static uint8_t
11394 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11395 : : {
11396 : : uint8_t match_criteria_enable;
11397 : :
11398 : : match_criteria_enable =
11399 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11400 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11401 : 0 : match_criteria_enable |=
11402 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11403 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11404 : 0 : match_criteria_enable |=
11405 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11406 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11407 : 0 : match_criteria_enable |=
11408 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11409 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11410 : 0 : match_criteria_enable |=
11411 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11412 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11413 : 0 : match_criteria_enable |=
11414 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11415 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11416 : 0 : match_criteria_enable |=
11417 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11418 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11419 : 0 : return match_criteria_enable;
11420 : : }
11421 : :
11422 : : static void
11423 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11424 : : {
11425 : : /*
11426 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11427 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11428 : : * misc5/4 are not supported, and matcher creation failure is expected
11429 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11430 : : * misc5 is right after misc4.
11431 : : */
11432 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11433 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11434 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11435 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11436 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11437 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11438 : : }
11439 : : }
11440 : : }
11441 : :
11442 : : static struct mlx5_list_entry *
11443 : 0 : flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
11444 : : struct mlx5_list_entry *entry, void *cb_ctx)
11445 : : {
11446 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11447 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11448 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11449 : : typeof(*tbl), tbl);
11450 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11451 : : sizeof(*resource),
11452 : : 0, SOCKET_ID_ANY);
11453 : :
11454 [ # # ]: 0 : if (!resource) {
11455 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11456 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11457 : : "cannot create matcher");
11458 : 0 : return NULL;
11459 : : }
11460 : : memcpy(resource, entry, sizeof(*resource));
11461 : 0 : resource->tbl = &tbl->tbl;
11462 : 0 : return &resource->entry;
11463 : : }
11464 : :
11465 : : static void
11466 : 0 : flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11467 : : struct mlx5_list_entry *entry)
11468 : : {
11469 : 0 : mlx5_free(entry);
11470 : 0 : }
11471 : :
11472 : : struct mlx5_list_entry *
11473 : 0 : flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11474 : 0 : {
11475 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11476 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11477 : 0 : struct rte_eth_dev *dev = ctx->dev;
11478 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11479 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11480 : 0 : struct rte_flow_error *error = ctx->error;
11481 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11482 : : struct mlx5_flow_tbl_resource *tbl;
11483 : : void *domain;
11484 : 0 : uint32_t idx = 0;
11485 : : int ret;
11486 : :
11487 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11488 [ # # ]: 0 : if (!tbl_data) {
11489 : 0 : rte_flow_error_set(error, ENOMEM,
11490 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11491 : : NULL,
11492 : : "cannot allocate flow table data entry");
11493 : 0 : return NULL;
11494 : : }
11495 : 0 : tbl_data->idx = idx;
11496 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11497 : 0 : tbl_data->group_id = tt_prm->group_id;
11498 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11499 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11500 : 0 : tbl_data->is_egress = !!key.is_egress;
11501 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11502 : 0 : tbl_data->dummy = !!key.dummy;
11503 : 0 : tbl_data->level = key.level;
11504 : 0 : tbl_data->id = key.id;
11505 : : tbl = &tbl_data->tbl;
11506 [ # # ]: 0 : if (key.dummy)
11507 : 0 : return &tbl_data->entry;
11508 [ # # ]: 0 : if (key.is_fdb)
11509 : 0 : domain = sh->fdb_domain;
11510 [ # # ]: 0 : else if (key.is_egress)
11511 : 0 : domain = sh->tx_domain;
11512 : : else
11513 : 0 : domain = sh->rx_domain;
11514 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11515 : : if (ret) {
11516 : 0 : rte_flow_error_set(error, ENOMEM,
11517 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11518 : : NULL, "cannot create flow table object");
11519 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11520 : 0 : return NULL;
11521 : : }
11522 [ # # ]: 0 : if (key.level != 0) {
11523 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11524 : : (tbl->obj, &tbl_data->jump.action);
11525 : : if (ret) {
11526 : 0 : rte_flow_error_set(error, ENOMEM,
11527 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11528 : : NULL,
11529 : : "cannot create flow jump action");
11530 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11531 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11532 : 0 : return NULL;
11533 : : }
11534 : : }
11535 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11536 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11537 : : key.level, key.id);
11538 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11539 : : flow_dv_matcher_create_cb,
11540 : : flow_dv_matcher_match_cb,
11541 : : flow_dv_matcher_remove_cb,
11542 : : flow_dv_matcher_clone_cb,
11543 : : flow_dv_matcher_clone_free_cb);
11544 [ # # ]: 0 : if (!tbl_data->matchers) {
11545 : 0 : rte_flow_error_set(error, ENOMEM,
11546 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11547 : : NULL,
11548 : : "cannot create tbl matcher list");
11549 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11550 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11551 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11552 : 0 : return NULL;
11553 : : }
11554 : 0 : return &tbl_data->entry;
11555 : : }
11556 : :
11557 : : int
11558 : 0 : flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11559 : : void *cb_ctx)
11560 : : {
11561 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11562 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11563 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11564 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11565 : :
11566 : 0 : return tbl_data->level != key.level ||
11567 [ # # ]: 0 : tbl_data->id != key.id ||
11568 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11569 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11570 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11571 : : }
11572 : :
11573 : : struct mlx5_list_entry *
11574 : 0 : flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11575 : : void *cb_ctx)
11576 : : {
11577 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11578 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11579 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11580 : 0 : struct rte_flow_error *error = ctx->error;
11581 : 0 : uint32_t idx = 0;
11582 : :
11583 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11584 [ # # ]: 0 : if (!tbl_data) {
11585 : 0 : rte_flow_error_set(error, ENOMEM,
11586 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11587 : : NULL,
11588 : : "cannot allocate flow table data entry");
11589 : 0 : return NULL;
11590 : : }
11591 : : memcpy(tbl_data, oentry, sizeof(*tbl_data));
11592 : 0 : tbl_data->idx = idx;
11593 : 0 : return &tbl_data->entry;
11594 : : }
11595 : :
11596 : : void
11597 : 0 : flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11598 : : {
11599 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11600 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11601 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11602 : :
11603 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11604 : 0 : }
11605 : :
11606 : : /**
11607 : : * Get a flow table.
11608 : : *
11609 : : * @param[in, out] dev
11610 : : * Pointer to rte_eth_dev structure.
11611 : : * @param[in] table_level
11612 : : * Table level to use.
11613 : : * @param[in] egress
11614 : : * Direction of the table.
11615 : : * @param[in] transfer
11616 : : * E-Switch or NIC flow.
11617 : : * @param[in] dummy
11618 : : * Dummy entry for dv API.
11619 : : * @param[in] table_id
11620 : : * Table id to use.
11621 : : * @param[out] error
11622 : : * pointer to error structure.
11623 : : *
11624 : : * @return
11625 : : * Returns tables resource based on the index, NULL in case of failed.
11626 : : */
11627 : : struct mlx5_flow_tbl_resource *
11628 : 0 : flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11629 : : uint32_t table_level, uint8_t egress,
11630 : : uint8_t transfer,
11631 : : bool external,
11632 : : const struct mlx5_flow_tunnel *tunnel,
11633 : : uint32_t group_id, uint8_t dummy,
11634 : : uint32_t table_id,
11635 : : struct rte_flow_error *error)
11636 : : {
11637 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11638 : 0 : union mlx5_flow_tbl_key table_key = {
11639 : : {
11640 : : .level = table_level,
11641 : : .id = table_id,
11642 : : .reserved = 0,
11643 : 0 : .dummy = !!dummy,
11644 : 0 : .is_fdb = !!transfer,
11645 : 0 : .is_egress = !!egress,
11646 : : }
11647 : : };
11648 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11649 : : .tunnel = tunnel,
11650 : : .group_id = group_id,
11651 : : .external = external,
11652 : : };
11653 : 0 : struct mlx5_flow_cb_ctx ctx = {
11654 : : .dev = dev,
11655 : : .error = error,
11656 : : .data = &table_key.v64,
11657 : : .data2 = &tt_prm,
11658 : : };
11659 : : struct mlx5_list_entry *entry;
11660 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11661 : :
11662 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11663 [ # # ]: 0 : if (!entry) {
11664 : 0 : rte_flow_error_set(error, ENOMEM,
11665 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11666 : : "cannot get table");
11667 : 0 : return NULL;
11668 : : }
11669 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
11670 : : "tunnel %u group %u registered.",
11671 : : table_level, table_id,
11672 : : tunnel ? tunnel->tunnel_id : 0, group_id);
11673 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11674 : 0 : return &tbl_data->tbl;
11675 : : }
11676 : :
11677 : : void
11678 : 0 : flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11679 : : {
11680 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11681 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11682 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11683 : :
11684 : : MLX5_ASSERT(entry && sh);
11685 [ # # ]: 0 : if (tbl_data->jump.action)
11686 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11687 [ # # ]: 0 : if (tbl_data->tbl.obj)
11688 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
11689 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
11690 : : struct mlx5_list_entry *he;
11691 : : struct mlx5_hlist *tunnel_grp_hash;
11692 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11693 : 0 : union tunnel_tbl_key tunnel_key = {
11694 : 0 : .tunnel_id = tbl_data->tunnel ?
11695 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
11696 : 0 : .group = tbl_data->group_id
11697 : : };
11698 : 0 : uint32_t table_level = tbl_data->level;
11699 : 0 : struct mlx5_flow_cb_ctx ctx = {
11700 : : .data = (void *)&tunnel_key.val,
11701 : : };
11702 : :
11703 : : tunnel_grp_hash = tbl_data->tunnel ?
11704 [ # # ]: 0 : tbl_data->tunnel->groups :
11705 : : thub->groups;
11706 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
11707 [ # # ]: 0 : if (he)
11708 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
11709 [ # # ]: 0 : DRV_LOG(DEBUG,
11710 : : "table_level %u id %u tunnel %u group %u released.",
11711 : : table_level,
11712 : : tbl_data->id,
11713 : : tbl_data->tunnel ?
11714 : : tbl_data->tunnel->tunnel_id : 0,
11715 : : tbl_data->group_id);
11716 : : }
11717 [ # # ]: 0 : if (tbl_data->matchers)
11718 : 0 : mlx5_list_destroy(tbl_data->matchers);
11719 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11720 : 0 : }
11721 : :
11722 : : /**
11723 : : * Release a flow table.
11724 : : *
11725 : : * @param[in] sh
11726 : : * Pointer to device shared structure.
11727 : : * @param[in] tbl
11728 : : * Table resource to be released.
11729 : : *
11730 : : * @return
11731 : : * Returns 0 if table was released, else return 1;
11732 : : */
11733 : : int
11734 : 0 : flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
11735 : : struct mlx5_flow_tbl_resource *tbl)
11736 : : {
11737 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11738 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11739 : :
11740 [ # # ]: 0 : if (!tbl)
11741 : : return 0;
11742 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
11743 : : }
11744 : :
11745 : : int
11746 : 0 : flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
11747 : : struct mlx5_list_entry *entry, void *cb_ctx)
11748 : : {
11749 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11750 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11751 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
11752 : : entry);
11753 : :
11754 : 0 : return cur->crc != ref->crc ||
11755 [ # # ]: 0 : cur->priority != ref->priority ||
11756 : 0 : memcmp((const void *)cur->mask.buf,
11757 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
11758 : : }
11759 : :
11760 : : struct mlx5_list_entry *
11761 : 0 : flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
11762 : : {
11763 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11764 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11765 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11766 : : struct mlx5_flow_dv_matcher *resource;
11767 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
11768 : : .type = IBV_FLOW_ATTR_NORMAL,
11769 : 0 : .match_mask = (void *)&ref->mask,
11770 : : };
11771 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11772 : : typeof(*tbl), tbl);
11773 : : int ret;
11774 : :
11775 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
11776 : : SOCKET_ID_ANY);
11777 [ # # ]: 0 : if (!resource) {
11778 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11779 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11780 : : "cannot create matcher");
11781 : 0 : return NULL;
11782 : : }
11783 : 0 : *resource = *ref;
11784 : 0 : dv_attr.match_criteria_enable =
11785 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
11786 : : __flow_dv_adjust_buf_size(&ref->mask.size,
11787 : : dv_attr.match_criteria_enable);
11788 : 0 : dv_attr.priority = ref->priority;
11789 [ # # ]: 0 : if (tbl->is_egress)
11790 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
11791 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
11792 : : tbl->tbl.obj,
11793 : : &resource->matcher_object);
11794 : : if (ret) {
11795 : 0 : mlx5_free(resource);
11796 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11797 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11798 : : "cannot create matcher");
11799 : 0 : return NULL;
11800 : : }
11801 : 0 : return &resource->entry;
11802 : : }
11803 : :
11804 : : /**
11805 : : * Register the flow matcher.
11806 : : *
11807 : : * @param[in, out] dev
11808 : : * Pointer to rte_eth_dev structure.
11809 : : * @param[in, out] matcher
11810 : : * Pointer to flow matcher.
11811 : : * @param[in, out] key
11812 : : * Pointer to flow table key.
11813 : : * @parm[in, out] dev_flow
11814 : : * Pointer to the dev_flow.
11815 : : * @param[out] error
11816 : : * pointer to error structure.
11817 : : *
11818 : : * @return
11819 : : * 0 on success otherwise -errno and errno is set.
11820 : : */
11821 : : static int
11822 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
11823 : : struct mlx5_flow_dv_matcher *ref,
11824 : : union mlx5_flow_tbl_key *key,
11825 : : struct mlx5_flow *dev_flow,
11826 : : const struct mlx5_flow_tunnel *tunnel,
11827 : : uint32_t group_id,
11828 : : struct rte_flow_error *error)
11829 : : {
11830 : : struct mlx5_list_entry *entry;
11831 : : struct mlx5_flow_dv_matcher *resource;
11832 : : struct mlx5_flow_tbl_resource *tbl;
11833 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11834 : 0 : struct mlx5_flow_cb_ctx ctx = {
11835 : : .error = error,
11836 : : .data = ref,
11837 : : };
11838 : : /**
11839 : : * tunnel offload API requires this registration for cases when
11840 : : * tunnel match rule was inserted before tunnel set rule.
11841 : : */
11842 : 0 : tbl = flow_dv_tbl_resource_get(dev, key->level,
11843 : 0 : key->is_egress, key->is_fdb,
11844 : 0 : dev_flow->external, tunnel,
11845 : 0 : group_id, 0, key->id, error);
11846 [ # # ]: 0 : if (!tbl)
11847 : 0 : return -rte_errno; /* No need to refill the error info */
11848 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11849 : 0 : ref->tbl = tbl;
11850 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
11851 [ # # ]: 0 : if (!entry) {
11852 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
11853 : 0 : return rte_flow_error_set(error, ENOMEM,
11854 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11855 : : "cannot allocate ref memory");
11856 : : }
11857 : : resource = container_of(entry, typeof(*resource), entry);
11858 : 0 : dev_flow->handle->dvh.matcher = resource;
11859 : 0 : return 0;
11860 : : }
11861 : :
11862 : : struct mlx5_list_entry *
11863 : 0 : flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
11864 : : {
11865 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11866 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11867 : : struct mlx5_flow_dv_tag_resource *entry;
11868 : 0 : uint32_t idx = 0;
11869 : : int ret;
11870 : :
11871 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
11872 [ # # ]: 0 : if (!entry) {
11873 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11874 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11875 : : "cannot allocate resource memory");
11876 : 0 : return NULL;
11877 : : }
11878 : 0 : entry->idx = idx;
11879 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
11880 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
11881 : : &entry->action);
11882 : : if (ret) {
11883 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
11884 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11885 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11886 : : NULL, "cannot create action");
11887 : 0 : return NULL;
11888 : : }
11889 : 0 : return &entry->entry;
11890 : : }
11891 : :
11892 : : int
11893 : 0 : flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11894 : : void *cb_ctx)
11895 : : {
11896 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11897 : : struct mlx5_flow_dv_tag_resource *tag =
11898 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11899 : :
11900 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
11901 : : }
11902 : :
11903 : : struct mlx5_list_entry *
11904 : 0 : flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11905 : : void *cb_ctx)
11906 : : {
11907 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11908 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11909 : : struct mlx5_flow_dv_tag_resource *entry;
11910 : 0 : uint32_t idx = 0;
11911 : :
11912 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
11913 [ # # ]: 0 : if (!entry) {
11914 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11915 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11916 : : "cannot allocate tag resource memory");
11917 : 0 : return NULL;
11918 : : }
11919 : : memcpy(entry, oentry, sizeof(*entry));
11920 : 0 : entry->idx = idx;
11921 : 0 : return &entry->entry;
11922 : : }
11923 : :
11924 : : void
11925 : 0 : flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11926 : : {
11927 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11928 : : struct mlx5_flow_dv_tag_resource *tag =
11929 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11930 : :
11931 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
11932 : 0 : }
11933 : :
11934 : : /**
11935 : : * Find existing tag resource or create and register a new one.
11936 : : *
11937 : : * @param dev[in, out]
11938 : : * Pointer to rte_eth_dev structure.
11939 : : * @param[in, out] tag_be24
11940 : : * Tag value in big endian then R-shift 8.
11941 : : * @parm[in, out] dev_flow
11942 : : * Pointer to the dev_flow.
11943 : : * @param[out] error
11944 : : * pointer to error structure.
11945 : : *
11946 : : * @return
11947 : : * 0 on success otherwise -errno and errno is set.
11948 : : */
11949 : : static int
11950 : 0 : flow_dv_tag_resource_register
11951 : : (struct rte_eth_dev *dev,
11952 : : uint32_t tag_be24,
11953 : : struct mlx5_flow *dev_flow,
11954 : : struct rte_flow_error *error)
11955 : : {
11956 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11957 : : struct mlx5_flow_dv_tag_resource *resource;
11958 : : struct mlx5_list_entry *entry;
11959 : 0 : struct mlx5_flow_cb_ctx ctx = {
11960 : : .error = error,
11961 : : .data = &tag_be24,
11962 : : };
11963 : : struct mlx5_hlist *tag_table;
11964 : :
11965 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
11966 : : "tags",
11967 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
11968 : 0 : false, false, priv->sh,
11969 : : flow_dv_tag_create_cb,
11970 : : flow_dv_tag_match_cb,
11971 : : flow_dv_tag_remove_cb,
11972 : : flow_dv_tag_clone_cb,
11973 : : flow_dv_tag_clone_free_cb,
11974 : : error);
11975 [ # # ]: 0 : if (unlikely(!tag_table))
11976 : 0 : return -rte_errno;
11977 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
11978 [ # # ]: 0 : if (entry) {
11979 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
11980 : : entry);
11981 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
11982 : 0 : dev_flow->dv.tag_resource = resource;
11983 : 0 : return 0;
11984 : : }
11985 : 0 : return -rte_errno;
11986 : : }
11987 : :
11988 : : void
11989 : 0 : flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11990 : : {
11991 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11992 : : struct mlx5_flow_dv_tag_resource *tag =
11993 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11994 : :
11995 : : MLX5_ASSERT(tag && sh && tag->action);
11996 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
11997 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
11998 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
11999 : 0 : }
12000 : :
12001 : : /**
12002 : : * Release the tag.
12003 : : *
12004 : : * @param dev
12005 : : * Pointer to Ethernet device.
12006 : : * @param tag_idx
12007 : : * Tag index.
12008 : : *
12009 : : * @return
12010 : : * 1 while a reference on it exists, 0 when freed.
12011 : : */
12012 : : static int
12013 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12014 : : uint32_t tag_idx)
12015 : : {
12016 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12017 : : struct mlx5_flow_dv_tag_resource *tag;
12018 : :
12019 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12020 [ # # ]: 0 : if (!tag)
12021 : : return 0;
12022 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12023 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12024 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12025 : : }
12026 : :
12027 : : /**
12028 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12029 : : *
12030 : : * @param[in] dev
12031 : : * Pointer to rte_eth_dev structure.
12032 : : * @param[in] action
12033 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12034 : : * @param[out] dst_port_id
12035 : : * The target port ID.
12036 : : * @param[out] error
12037 : : * Pointer to the error structure.
12038 : : *
12039 : : * @return
12040 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12041 : : */
12042 : : static int
12043 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12044 : : const struct rte_flow_action *action,
12045 : : uint32_t *dst_port_id,
12046 : : struct rte_flow_error *error)
12047 : : {
12048 : : uint32_t port;
12049 : : struct mlx5_priv *priv;
12050 : :
12051 [ # # # ]: 0 : switch (action->type) {
12052 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12053 : : const struct rte_flow_action_port_id *conf;
12054 : :
12055 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12056 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12057 : : break;
12058 : : }
12059 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12060 : : const struct rte_flow_action_ethdev *ethdev;
12061 : :
12062 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12063 : 0 : port = ethdev->port_id;
12064 : 0 : break;
12065 : : }
12066 : 0 : default:
12067 : : MLX5_ASSERT(false);
12068 : 0 : return rte_flow_error_set(error, EINVAL,
12069 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12070 : : "unknown E-Switch action");
12071 : : }
12072 : :
12073 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12074 [ # # ]: 0 : if (!priv)
12075 : 0 : return rte_flow_error_set(error, -rte_errno,
12076 : : RTE_FLOW_ERROR_TYPE_ACTION,
12077 : : NULL,
12078 : : "No eswitch info was found for port");
12079 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12080 : : /*
12081 : : * This parameter is transferred to
12082 : : * mlx5dv_dr_action_create_dest_ib_port().
12083 : : */
12084 : 0 : *dst_port_id = priv->dev_port;
12085 : : #else
12086 : : /*
12087 : : * Legacy mode, no LAG configurations is supported.
12088 : : * This parameter is transferred to
12089 : : * mlx5dv_dr_action_create_dest_vport().
12090 : : */
12091 : : *dst_port_id = priv->vport_id;
12092 : : #endif
12093 : 0 : return 0;
12094 : : }
12095 : :
12096 : : /**
12097 : : * Create a counter with aging configuration.
12098 : : *
12099 : : * @param[in] dev
12100 : : * Pointer to rte_eth_dev structure.
12101 : : * @param[in] dev_flow
12102 : : * Pointer to the mlx5_flow.
12103 : : * @param[out] count
12104 : : * Pointer to the counter action configuration.
12105 : : * @param[in] age
12106 : : * Pointer to the aging action configuration.
12107 : : *
12108 : : * @return
12109 : : * Index to flow counter on success, 0 otherwise.
12110 : : */
12111 : : static uint32_t
12112 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12113 : : struct mlx5_flow *dev_flow,
12114 : : const struct rte_flow_action_count *count
12115 : : __rte_unused,
12116 : : const struct rte_flow_action_age *age)
12117 : : {
12118 : : uint32_t counter;
12119 : : struct mlx5_age_param *age_param;
12120 : :
12121 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12122 [ # # ]: 0 : if (!counter || age == NULL)
12123 : : return counter;
12124 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12125 [ # # ]: 0 : age_param->context = age->context ? age->context :
12126 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12127 : 0 : age_param->timeout = age->timeout;
12128 : 0 : age_param->port_id = dev->data->port_id;
12129 : 0 : __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
12130 : 0 : __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
12131 : 0 : return counter;
12132 : : }
12133 : :
12134 : : /**
12135 : : * Add SQ matcher
12136 : : *
12137 : : * @param[in, out] matcher
12138 : : * Flow matcher.
12139 : : * @param[in, out] key
12140 : : * Flow matcher value.
12141 : : * @param[in] item
12142 : : * Flow pattern to translate.
12143 : : * @param[in] key_type
12144 : : * Set flow matcher mask or value.
12145 : : */
12146 : : static void
12147 : 0 : flow_dv_translate_item_sq(void *key,
12148 : : const struct rte_flow_item *item,
12149 : : uint32_t key_type)
12150 : : {
12151 : : const struct mlx5_rte_flow_item_sq *queue_m;
12152 : : const struct mlx5_rte_flow_item_sq *queue_v;
12153 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12154 : : .queue = UINT32_MAX,
12155 : : };
12156 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12157 : : uint32_t queue;
12158 : :
12159 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12160 [ # # ]: 0 : if (!queue_m || !queue_v)
12161 : 0 : return;
12162 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12163 : 0 : queue = queue_v->queue;
12164 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12165 : 0 : queue &= queue_m->queue;
12166 : : } else {
12167 : 0 : queue = queue_m->queue;
12168 : : }
12169 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12170 : : }
12171 : :
12172 : : /**
12173 : : * Set the hash fields according to the @p flow information.
12174 : : *
12175 : : * @param[in] item_flags
12176 : : * The match pattern item flags.
12177 : : * @param[in] rss_desc
12178 : : * Pointer to the mlx5_flow_rss_desc.
12179 : : * @param[out] hash_fields
12180 : : * Pointer to the RSS hash fields.
12181 : : */
12182 : : void
12183 : 0 : flow_dv_hashfields_set(uint64_t item_flags,
12184 : : struct mlx5_flow_rss_desc *rss_desc,
12185 : : uint64_t *hash_fields)
12186 : : {
12187 : : uint64_t items = item_flags;
12188 : : uint64_t fields = 0;
12189 : : int rss_inner = 0;
12190 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12191 : :
12192 : : *hash_fields = 0;
12193 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12194 [ # # ]: 0 : if (rss_desc->level >= 2)
12195 : : rss_inner = 1;
12196 : : #endif
12197 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12198 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12199 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12200 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12201 : : fields |= IBV_RX_HASH_SRC_IPV4;
12202 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12203 : : fields |= IBV_RX_HASH_DST_IPV4;
12204 : : else
12205 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12206 : : }
12207 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12208 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12209 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12210 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12211 : : fields |= IBV_RX_HASH_SRC_IPV6;
12212 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12213 : : fields |= IBV_RX_HASH_DST_IPV6;
12214 : : else
12215 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12216 : : }
12217 : : }
12218 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12219 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12220 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12221 : : }
12222 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12223 : 0 : *hash_fields = fields;
12224 : : /*
12225 : : * There is no match between the RSS types and the
12226 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12227 : : */
12228 : 0 : return;
12229 : : }
12230 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12231 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12232 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12233 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12234 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12235 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12236 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12237 : : else
12238 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12239 : : }
12240 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12241 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12242 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12243 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12244 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12245 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12246 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12247 : : else
12248 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12249 : : }
12250 : : }
12251 [ # # ]: 0 : if (rss_inner)
12252 : 0 : fields |= IBV_RX_HASH_INNER;
12253 : 0 : *hash_fields = fields;
12254 : : }
12255 : :
12256 : : /**
12257 : : * Prepare an Rx Hash queue.
12258 : : *
12259 : : * @param dev
12260 : : * Pointer to Ethernet device.
12261 : : * @param[in] dev_flow
12262 : : * Pointer to the mlx5_flow.
12263 : : * @param[in] rss_desc
12264 : : * Pointer to the mlx5_flow_rss_desc.
12265 : : * @param[out] hrxq_idx
12266 : : * Hash Rx queue index.
12267 : : *
12268 : : * @return
12269 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12270 : : */
12271 : : static struct mlx5_hrxq *
12272 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12273 : : struct mlx5_flow *dev_flow,
12274 : : struct mlx5_flow_rss_desc *rss_desc,
12275 : : uint32_t *hrxq_idx)
12276 : : {
12277 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12278 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12279 : : struct mlx5_hrxq *hrxq;
12280 : :
12281 : : MLX5_ASSERT(rss_desc->queue_num);
12282 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12283 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12284 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12285 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12286 : 0 : rss_desc->shared_rss = 0;
12287 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12288 : 0 : rss_desc->queue_num = 1;
12289 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12290 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12291 : 0 : rss_desc->shared_rss = shared_rss;
12292 : 0 : return hrxq;
12293 : : }
12294 : :
12295 : : /**
12296 : : * Release sample sub action resource.
12297 : : *
12298 : : * @param[in, out] dev
12299 : : * Pointer to rte_eth_dev structure.
12300 : : * @param[in] act_res
12301 : : * Pointer to sample sub action resource.
12302 : : */
12303 : : static void
12304 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12305 : : struct mlx5_flow_sub_actions_idx *act_res)
12306 : : {
12307 [ # # ]: 0 : if (act_res->rix_hrxq) {
12308 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12309 : 0 : act_res->rix_hrxq = 0;
12310 : : }
12311 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12312 : 0 : flow_dv_encap_decap_resource_release(dev,
12313 : : act_res->rix_encap_decap);
12314 : 0 : act_res->rix_encap_decap = 0;
12315 : : }
12316 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12317 : 0 : flow_dv_port_id_action_resource_release(dev,
12318 : : act_res->rix_port_id_action);
12319 : 0 : act_res->rix_port_id_action = 0;
12320 : : }
12321 [ # # ]: 0 : if (act_res->rix_tag) {
12322 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12323 : 0 : act_res->rix_tag = 0;
12324 : : }
12325 [ # # ]: 0 : if (act_res->rix_jump) {
12326 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12327 : 0 : act_res->rix_jump = 0;
12328 : : }
12329 : 0 : }
12330 : :
12331 : : int
12332 : 0 : flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12333 : : struct mlx5_list_entry *entry, void *cb_ctx)
12334 : : {
12335 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12336 : 0 : struct rte_eth_dev *dev = ctx->dev;
12337 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12338 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12339 : : typeof(*resource),
12340 : : entry);
12341 : :
12342 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12343 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12344 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12345 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12346 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12347 [ # # ]: 0 : (void *)&resource->sample_act,
12348 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12349 : : /*
12350 : : * Existing sample action should release the prepared
12351 : : * sub-actions reference counter.
12352 : : */
12353 : 0 : flow_dv_sample_sub_actions_release(dev,
12354 : : &ctx_resource->sample_idx);
12355 : 0 : return 0;
12356 : : }
12357 : : return 1;
12358 : : }
12359 : :
12360 : : struct mlx5_list_entry *
12361 : 0 : flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12362 : : {
12363 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12364 : 0 : struct rte_eth_dev *dev = ctx->dev;
12365 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12366 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12367 : : struct mlx5_flow_dv_sample_resource *resource;
12368 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12369 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12370 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12371 : : struct mlx5_flow_tbl_resource *tbl;
12372 : 0 : uint32_t idx = 0;
12373 : : const uint32_t next_ft_step = 1;
12374 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12375 : : uint8_t is_egress = 0;
12376 : : uint8_t is_transfer = 0;
12377 : 0 : struct rte_flow_error *error = ctx->error;
12378 : :
12379 : : /* Register new sample resource. */
12380 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12381 [ # # ]: 0 : if (!resource) {
12382 : 0 : rte_flow_error_set(error, ENOMEM,
12383 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12384 : : NULL,
12385 : : "cannot allocate resource memory");
12386 : 0 : return NULL;
12387 : : }
12388 : 0 : *resource = *ctx_resource;
12389 : : /* Create normal path table level */
12390 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12391 : : is_transfer = 1;
12392 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12393 : : is_egress = 1;
12394 : 0 : tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
12395 : : is_egress, is_transfer,
12396 : : true, NULL, 0, 0, 0, error);
12397 [ # # ]: 0 : if (!tbl) {
12398 : 0 : rte_flow_error_set(error, ENOMEM,
12399 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12400 : : NULL,
12401 : : "fail to create normal path table "
12402 : : "for sample");
12403 : 0 : goto error;
12404 : : }
12405 : 0 : resource->normal_path_tbl = tbl;
12406 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12407 [ # # ]: 0 : if (!sh->default_miss_action) {
12408 : 0 : rte_flow_error_set(error, ENOMEM,
12409 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12410 : : NULL,
12411 : : "default miss action was not "
12412 : : "created");
12413 : 0 : goto error;
12414 : : }
12415 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12416 : : sh->default_miss_action;
12417 : : }
12418 : : /* Create a DR sample action */
12419 : 0 : sampler_attr.sample_ratio = resource->ratio;
12420 : 0 : sampler_attr.default_next_table = tbl->obj;
12421 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12422 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12423 : : &sample_dv_actions[0];
12424 : 0 : sampler_attr.action = resource->set_action;
12425 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12426 : : (&sampler_attr, &resource->verbs_action)) {
12427 : 0 : rte_flow_error_set(error, ENOMEM,
12428 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12429 : : NULL, "cannot create sample action");
12430 : 0 : goto error;
12431 : : }
12432 : 0 : resource->idx = idx;
12433 : 0 : resource->dev = dev;
12434 : 0 : return &resource->entry;
12435 : 0 : error:
12436 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12437 : 0 : flow_dv_sample_sub_actions_release(dev,
12438 : : &resource->sample_idx);
12439 [ # # ]: 0 : if (resource->normal_path_tbl)
12440 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
12441 : : resource->normal_path_tbl);
12442 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12443 : 0 : return NULL;
12444 : :
12445 : : }
12446 : :
12447 : : struct mlx5_list_entry *
12448 : 0 : flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12449 : : struct mlx5_list_entry *entry __rte_unused,
12450 : : void *cb_ctx)
12451 : : {
12452 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12453 : 0 : struct rte_eth_dev *dev = ctx->dev;
12454 : : struct mlx5_flow_dv_sample_resource *resource;
12455 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12456 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12457 : 0 : uint32_t idx = 0;
12458 : :
12459 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12460 [ # # ]: 0 : if (!resource) {
12461 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12462 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12463 : : NULL,
12464 : : "cannot allocate resource memory");
12465 : 0 : return NULL;
12466 : : }
12467 : : memcpy(resource, entry, sizeof(*resource));
12468 : 0 : resource->idx = idx;
12469 : 0 : resource->dev = dev;
12470 : 0 : return &resource->entry;
12471 : : }
12472 : :
12473 : : void
12474 : 0 : flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12475 : : struct mlx5_list_entry *entry)
12476 : : {
12477 : : struct mlx5_flow_dv_sample_resource *resource =
12478 : : container_of(entry, typeof(*resource), entry);
12479 : 0 : struct rte_eth_dev *dev = resource->dev;
12480 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12481 : :
12482 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12483 : 0 : }
12484 : :
12485 : : /**
12486 : : * Find existing sample resource or create and register a new one.
12487 : : *
12488 : : * @param[in, out] dev
12489 : : * Pointer to rte_eth_dev structure.
12490 : : * @param[in] ref
12491 : : * Pointer to sample resource reference.
12492 : : * @parm[in, out] dev_flow
12493 : : * Pointer to the dev_flow.
12494 : : * @param[out] error
12495 : : * pointer to error structure.
12496 : : *
12497 : : * @return
12498 : : * 0 on success otherwise -errno and errno is set.
12499 : : */
12500 : : static int
12501 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12502 : : struct mlx5_flow_dv_sample_resource *ref,
12503 : : struct mlx5_flow *dev_flow,
12504 : : struct rte_flow_error *error)
12505 : : {
12506 : : struct mlx5_flow_dv_sample_resource *resource;
12507 : : struct mlx5_list_entry *entry;
12508 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12509 : 0 : struct mlx5_flow_cb_ctx ctx = {
12510 : : .dev = dev,
12511 : : .error = error,
12512 : : .data = ref,
12513 : : };
12514 : :
12515 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12516 [ # # ]: 0 : if (!entry)
12517 : 0 : return -rte_errno;
12518 : : resource = container_of(entry, typeof(*resource), entry);
12519 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12520 : 0 : dev_flow->dv.sample_res = resource;
12521 : 0 : return 0;
12522 : : }
12523 : :
12524 : : int
12525 : 0 : flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12526 : : struct mlx5_list_entry *entry, void *cb_ctx)
12527 : : {
12528 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12529 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12530 : 0 : struct rte_eth_dev *dev = ctx->dev;
12531 : : struct mlx5_flow_dv_dest_array_resource *resource =
12532 : : container_of(entry, typeof(*resource), entry);
12533 : : uint32_t idx = 0;
12534 : :
12535 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12536 : 0 : ctx_resource->ft_type == resource->ft_type &&
12537 : 0 : !memcmp((void *)resource->sample_act,
12538 : 0 : (void *)ctx_resource->sample_act,
12539 [ # # ]: 0 : (ctx_resource->num_of_dest *
12540 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12541 : : /*
12542 : : * Existing sample action should release the prepared
12543 : : * sub-actions reference counter.
12544 : : */
12545 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12546 : 0 : flow_dv_sample_sub_actions_release(dev,
12547 : : &ctx_resource->sample_idx[idx]);
12548 : : return 0;
12549 : : }
12550 : : return 1;
12551 : : }
12552 : :
12553 : : struct mlx5_list_entry *
12554 : 0 : flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12555 : : {
12556 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12557 : 0 : struct rte_eth_dev *dev = ctx->dev;
12558 : : struct mlx5_flow_dv_dest_array_resource *resource;
12559 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12560 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12561 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12562 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12563 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12564 : : struct mlx5_flow_sub_actions_list *sample_act;
12565 : : struct mlx5dv_dr_domain *domain;
12566 : 0 : uint32_t idx = 0, res_idx = 0;
12567 : 0 : struct rte_flow_error *error = ctx->error;
12568 : : uint64_t action_flags;
12569 : : int ret;
12570 : :
12571 : : /* Register new destination array resource. */
12572 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12573 : : &res_idx);
12574 [ # # ]: 0 : if (!resource) {
12575 : 0 : rte_flow_error_set(error, ENOMEM,
12576 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12577 : : NULL,
12578 : : "cannot allocate resource memory");
12579 : 0 : return NULL;
12580 : : }
12581 : 0 : *resource = *ctx_resource;
12582 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12583 : 0 : domain = sh->fdb_domain;
12584 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12585 : 0 : domain = sh->rx_domain;
12586 : : else
12587 : 0 : domain = sh->tx_domain;
12588 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12589 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12590 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12591 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12592 : : 0, SOCKET_ID_ANY);
12593 [ # # ]: 0 : if (!dest_attr[idx]) {
12594 : 0 : rte_flow_error_set(error, ENOMEM,
12595 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12596 : : NULL,
12597 : : "cannot allocate resource memory");
12598 : 0 : goto error;
12599 : : }
12600 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
12601 : : sample_act = &ctx_resource->sample_act[idx];
12602 : 0 : action_flags = sample_act->action_flags;
12603 [ # # # # : 0 : switch (action_flags) {
# ]
12604 : 0 : case MLX5_FLOW_ACTION_QUEUE:
12605 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
12606 : 0 : break;
12607 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
12608 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
12609 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
12610 : 0 : dest_attr[idx]->dest_reformat->reformat =
12611 : 0 : sample_act->dr_encap_action;
12612 : 0 : dest_attr[idx]->dest_reformat->dest =
12613 : 0 : sample_act->dr_port_id_action;
12614 : 0 : break;
12615 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
12616 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
12617 : 0 : break;
12618 : 0 : case MLX5_FLOW_ACTION_JUMP:
12619 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
12620 : 0 : break;
12621 : 0 : default:
12622 : 0 : rte_flow_error_set(error, EINVAL,
12623 : : RTE_FLOW_ERROR_TYPE_ACTION,
12624 : : NULL,
12625 : : "unsupported actions type");
12626 : 0 : goto error;
12627 : : }
12628 : : }
12629 : : /* create a dest array action */
12630 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
12631 : : (domain,
12632 : 0 : resource->num_of_dest,
12633 : : dest_attr,
12634 : : &resource->action);
12635 : : if (ret) {
12636 : 0 : rte_flow_error_set(error, ENOMEM,
12637 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12638 : : NULL,
12639 : : "cannot create destination array action");
12640 : 0 : goto error;
12641 : : }
12642 : 0 : resource->idx = res_idx;
12643 : 0 : resource->dev = dev;
12644 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12645 : 0 : mlx5_free(dest_attr[idx]);
12646 : 0 : return &resource->entry;
12647 : : error:
12648 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12649 : 0 : flow_dv_sample_sub_actions_release(dev,
12650 : : &resource->sample_idx[idx]);
12651 [ # # ]: 0 : if (dest_attr[idx])
12652 : 0 : mlx5_free(dest_attr[idx]);
12653 : : }
12654 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
12655 : 0 : return NULL;
12656 : : }
12657 : :
12658 : : struct mlx5_list_entry *
12659 : 0 : flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
12660 : : struct mlx5_list_entry *entry __rte_unused,
12661 : : void *cb_ctx)
12662 : : {
12663 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12664 : 0 : struct rte_eth_dev *dev = ctx->dev;
12665 : : struct mlx5_flow_dv_dest_array_resource *resource;
12666 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12667 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12668 : 0 : uint32_t res_idx = 0;
12669 : 0 : struct rte_flow_error *error = ctx->error;
12670 : :
12671 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12672 : : &res_idx);
12673 [ # # ]: 0 : if (!resource) {
12674 : 0 : rte_flow_error_set(error, ENOMEM,
12675 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12676 : : NULL,
12677 : : "cannot allocate dest-array memory");
12678 : 0 : return NULL;
12679 : : }
12680 : : memcpy(resource, entry, sizeof(*resource));
12681 : 0 : resource->idx = res_idx;
12682 : 0 : resource->dev = dev;
12683 : 0 : return &resource->entry;
12684 : : }
12685 : :
12686 : : void
12687 : 0 : flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
12688 : : struct mlx5_list_entry *entry)
12689 : : {
12690 : : struct mlx5_flow_dv_dest_array_resource *resource =
12691 : : container_of(entry, typeof(*resource), entry);
12692 : 0 : struct rte_eth_dev *dev = resource->dev;
12693 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12694 : :
12695 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
12696 : 0 : }
12697 : :
12698 : : /**
12699 : : * Find existing destination array resource or create and register a new one.
12700 : : *
12701 : : * @param[in, out] dev
12702 : : * Pointer to rte_eth_dev structure.
12703 : : * @param[in] ref
12704 : : * Pointer to destination array resource reference.
12705 : : * @parm[in, out] dev_flow
12706 : : * Pointer to the dev_flow.
12707 : : * @param[out] error
12708 : : * pointer to error structure.
12709 : : *
12710 : : * @return
12711 : : * 0 on success otherwise -errno and errno is set.
12712 : : */
12713 : : static int
12714 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
12715 : : struct mlx5_flow_dv_dest_array_resource *ref,
12716 : : struct mlx5_flow *dev_flow,
12717 : : struct rte_flow_error *error)
12718 : : {
12719 : : struct mlx5_flow_dv_dest_array_resource *resource;
12720 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12721 : : struct mlx5_list_entry *entry;
12722 : 0 : struct mlx5_flow_cb_ctx ctx = {
12723 : : .dev = dev,
12724 : : .error = error,
12725 : : .data = ref,
12726 : : };
12727 : :
12728 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
12729 [ # # ]: 0 : if (!entry)
12730 : 0 : return -rte_errno;
12731 : : resource = container_of(entry, typeof(*resource), entry);
12732 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
12733 : 0 : dev_flow->dv.dest_array_res = resource;
12734 : 0 : return 0;
12735 : : }
12736 : :
12737 : : /**
12738 : : * Convert Sample action to DV specification.
12739 : : *
12740 : : * @param[in] dev
12741 : : * Pointer to rte_eth_dev structure.
12742 : : * @param[in] action
12743 : : * Pointer to sample action structure.
12744 : : * @param[in, out] dev_flow
12745 : : * Pointer to the mlx5_flow.
12746 : : * @param[in] attr
12747 : : * Pointer to the flow attributes.
12748 : : * @param[in, out] num_of_dest
12749 : : * Pointer to the num of destination.
12750 : : * @param[in, out] sample_actions
12751 : : * Pointer to sample actions list.
12752 : : * @param[in, out] res
12753 : : * Pointer to sample resource.
12754 : : * @param[out] error
12755 : : * Pointer to the error structure.
12756 : : *
12757 : : * @return
12758 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12759 : : */
12760 : : static int
12761 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
12762 : : const struct rte_flow_action_sample *action,
12763 : : struct mlx5_flow *dev_flow,
12764 : : const struct rte_flow_attr *attr,
12765 : : uint32_t *num_of_dest,
12766 : : void **sample_actions,
12767 : : struct mlx5_flow_dv_sample_resource *res,
12768 : : struct rte_flow_error *error)
12769 : : {
12770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12771 : : const struct rte_flow_action *sub_actions;
12772 : : struct mlx5_flow_sub_actions_list *sample_act;
12773 : : struct mlx5_flow_sub_actions_idx *sample_idx;
12774 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12775 : 0 : struct rte_flow *flow = dev_flow->flow;
12776 : : struct mlx5_flow_rss_desc *rss_desc;
12777 : : uint64_t action_flags = 0;
12778 : :
12779 : : MLX5_ASSERT(wks);
12780 : 0 : rss_desc = &wks->rss_desc;
12781 : : sample_act = &res->sample_act;
12782 : : sample_idx = &res->sample_idx;
12783 : 0 : res->ratio = action->ratio;
12784 : 0 : sub_actions = action->actions;
12785 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
12786 : : int type = sub_actions->type;
12787 : : uint32_t pre_rix = 0;
12788 : : void *pre_r;
12789 [ # # # # : 0 : switch (type) {
# # # ]
12790 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
12791 : : {
12792 : : const struct rte_flow_action_queue *queue;
12793 : : struct mlx5_hrxq *hrxq;
12794 : : uint32_t hrxq_idx;
12795 : :
12796 : 0 : queue = sub_actions->conf;
12797 : 0 : rss_desc->queue_num = 1;
12798 : 0 : rss_desc->queue[0] = queue->index;
12799 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12800 : : rss_desc, &hrxq_idx);
12801 [ # # ]: 0 : if (!hrxq)
12802 : 0 : return rte_flow_error_set
12803 : : (error, rte_errno,
12804 : : RTE_FLOW_ERROR_TYPE_ACTION,
12805 : : NULL,
12806 : : "cannot create fate queue");
12807 : 0 : sample_act->dr_queue_action = hrxq->action;
12808 : 0 : sample_idx->rix_hrxq = hrxq_idx;
12809 : 0 : sample_actions[sample_act->actions_num++] =
12810 : : hrxq->action;
12811 : 0 : (*num_of_dest)++;
12812 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
12813 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
12814 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
12815 : 0 : dev_flow->handle->fate_action =
12816 : : MLX5_FLOW_FATE_QUEUE;
12817 : 0 : break;
12818 : : }
12819 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
12820 : : {
12821 : : struct mlx5_hrxq *hrxq;
12822 : : uint32_t hrxq_idx;
12823 : : const struct rte_flow_action_rss *rss;
12824 : : const uint8_t *rss_key;
12825 : :
12826 : 0 : rss = sub_actions->conf;
12827 : 0 : rss_desc->symmetric_hash_function =
12828 : 0 : MLX5_RSS_IS_SYMM(rss->func);
12829 : 0 : memcpy(rss_desc->queue, rss->queue,
12830 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
12831 : 0 : rss_desc->queue_num = rss->queue_num;
12832 : : /* NULL RSS key indicates default RSS key. */
12833 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
12834 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12835 : : /*
12836 : : * rss->level and rss.types should be set in advance
12837 : : * when expanding items for RSS.
12838 : : */
12839 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
12840 : : rss_desc,
12841 : : &dev_flow->hash_fields);
12842 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12843 : : rss_desc, &hrxq_idx);
12844 [ # # ]: 0 : if (!hrxq)
12845 : 0 : return rte_flow_error_set
12846 : : (error, rte_errno,
12847 : : RTE_FLOW_ERROR_TYPE_ACTION,
12848 : : NULL,
12849 : : "cannot create fate queue");
12850 : 0 : sample_act->dr_queue_action = hrxq->action;
12851 : 0 : sample_idx->rix_hrxq = hrxq_idx;
12852 : 0 : sample_actions[sample_act->actions_num++] =
12853 : : hrxq->action;
12854 : 0 : (*num_of_dest)++;
12855 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
12856 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
12857 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
12858 : 0 : dev_flow->handle->fate_action =
12859 : : MLX5_FLOW_FATE_QUEUE;
12860 : 0 : break;
12861 : : }
12862 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
12863 : : {
12864 : : uint32_t tag_be = mlx5_flow_mark_set
12865 : : (((const struct rte_flow_action_mark *)
12866 [ # # ]: 0 : (sub_actions->conf))->id);
12867 : :
12868 : 0 : wks->mark = 1;
12869 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
12870 : : /* Save the mark resource before sample */
12871 : 0 : pre_r = dev_flow->dv.tag_resource;
12872 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
12873 : : dev_flow, error))
12874 : 0 : return -rte_errno;
12875 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
12876 : 0 : sample_act->dr_tag_action =
12877 : 0 : dev_flow->dv.tag_resource->action;
12878 : 0 : sample_idx->rix_tag =
12879 : 0 : dev_flow->handle->dvh.rix_tag;
12880 : 0 : sample_actions[sample_act->actions_num++] =
12881 : : sample_act->dr_tag_action;
12882 : : /* Recover the mark resource after sample */
12883 : 0 : dev_flow->dv.tag_resource = pre_r;
12884 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
12885 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
12886 : 0 : break;
12887 : : }
12888 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
12889 : : {
12890 [ # # ]: 0 : if (!flow->counter) {
12891 : 0 : flow->counter =
12892 : 0 : flow_dv_translate_create_counter(dev,
12893 : 0 : dev_flow, sub_actions->conf,
12894 : : 0);
12895 [ # # ]: 0 : if (!flow->counter)
12896 : 0 : return rte_flow_error_set
12897 : : (error, rte_errno,
12898 : : RTE_FLOW_ERROR_TYPE_ACTION,
12899 : : NULL,
12900 : : "cannot create counter"
12901 : : " object.");
12902 : : }
12903 : 0 : sample_act->dr_cnt_action =
12904 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
12905 : 0 : flow->counter, NULL))->action;
12906 : 0 : sample_actions[sample_act->actions_num++] =
12907 : : sample_act->dr_cnt_action;
12908 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
12909 : 0 : break;
12910 : : }
12911 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
12912 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12913 : : {
12914 : : struct mlx5_flow_dv_port_id_action_resource
12915 : : port_id_resource;
12916 : 0 : uint32_t port_id = 0;
12917 : :
12918 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
12919 : : /* Save the port id resource before sample */
12920 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
12921 : 0 : pre_r = dev_flow->dv.port_id_action;
12922 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
12923 : : &port_id, error))
12924 : 0 : return -rte_errno;
12925 : 0 : port_id_resource.port_id = port_id;
12926 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
12927 : : (dev, &port_id_resource, dev_flow, error))
12928 : 0 : return -rte_errno;
12929 : 0 : sample_act->dr_port_id_action =
12930 : 0 : dev_flow->dv.port_id_action->action;
12931 : 0 : sample_idx->rix_port_id_action =
12932 : 0 : dev_flow->handle->rix_port_id_action;
12933 : 0 : sample_actions[sample_act->actions_num++] =
12934 : : sample_act->dr_port_id_action;
12935 : : /* Recover the port id resource after sample */
12936 : 0 : dev_flow->dv.port_id_action = pre_r;
12937 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
12938 : 0 : (*num_of_dest)++;
12939 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12940 : 0 : break;
12941 : : }
12942 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12943 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12944 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12945 : : /* Save the encap resource before sample */
12946 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
12947 : 0 : pre_r = dev_flow->dv.encap_decap;
12948 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
12949 : : dev_flow,
12950 : 0 : attr->transfer,
12951 : : error))
12952 : 0 : return -rte_errno;
12953 : 0 : sample_act->dr_encap_action =
12954 : 0 : dev_flow->dv.encap_decap->action;
12955 : 0 : sample_idx->rix_encap_decap =
12956 : 0 : dev_flow->handle->dvh.rix_encap_decap;
12957 : 0 : sample_actions[sample_act->actions_num++] =
12958 : : sample_act->dr_encap_action;
12959 : : /* Recover the encap resource after sample */
12960 : 0 : dev_flow->dv.encap_decap = pre_r;
12961 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
12962 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
12963 : 0 : break;
12964 : 0 : default:
12965 : 0 : return rte_flow_error_set(error, EINVAL,
12966 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12967 : : NULL,
12968 : : "Not support for sampler action");
12969 : : }
12970 : : }
12971 : 0 : sample_act->action_flags = action_flags;
12972 : 0 : res->ft_id = dev_flow->dv.group;
12973 [ # # ]: 0 : if (attr->transfer) {
12974 : : union {
12975 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
12976 : : uint64_t set_action;
12977 : : } action_ctx = { .set_action = 0 };
12978 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
12979 [ # # ]: 0 : wks->vport_meta_tag :
12980 : : priv->vport_meta_tag;
12981 : :
12982 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12983 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
12984 : : MLX5_MODIFICATION_TYPE_SET);
12985 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
12986 : : MLX5_MODI_META_REG_C_0);
12987 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
12988 : : vport_meta_tag);
12989 : 0 : res->set_action = action_ctx.set_action;
12990 [ # # ]: 0 : } else if (attr->ingress) {
12991 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12992 : : } else {
12993 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
12994 : : }
12995 : : return 0;
12996 : : }
12997 : :
12998 : : static void *
12999 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13000 : : const struct rte_flow_attr *attr,
13001 : : struct rte_flow_error *error)
13002 : : {
13003 : : struct mlx5_flow_tbl_resource *tbl;
13004 : : struct mlx5_dev_ctx_shared *sh;
13005 : : uint32_t priority;
13006 : : void *action;
13007 : : int ft_type;
13008 : : int ret;
13009 : :
13010 : 0 : sh = MLX5_SH(dev);
13011 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13012 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13013 : : MLX5DR_TABLE_TYPE_NIC_TX);
13014 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13015 : : return sh->send_to_kernel_action[ft_type].action;
13016 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13017 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13018 : 0 : rte_flow_error_set(error, ENOTSUP,
13019 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13020 : : "required priority is not available");
13021 : 0 : return NULL;
13022 : : }
13023 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, false, NULL, 0, 0, 0,
13024 : : error);
13025 [ # # ]: 0 : if (!tbl) {
13026 : 0 : rte_flow_error_set(error, ENODATA,
13027 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13028 : : "cannot find destination root table");
13029 : 0 : return NULL;
13030 : : }
13031 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13032 : : priority, &action);
13033 : : if (ret) {
13034 : 0 : rte_flow_error_set(error, ENOMEM,
13035 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13036 : : "cannot create action");
13037 : 0 : goto err;
13038 : : }
13039 : : MLX5_ASSERT(action);
13040 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13041 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13042 : 0 : return action;
13043 : : err:
13044 : 0 : flow_dv_tbl_resource_release(sh, tbl);
13045 : 0 : return NULL;
13046 : : }
13047 : :
13048 : : /**
13049 : : * Convert Sample action to DV specification.
13050 : : *
13051 : : * @param[in] dev
13052 : : * Pointer to rte_eth_dev structure.
13053 : : * @param[in, out] dev_flow
13054 : : * Pointer to the mlx5_flow.
13055 : : * @param[in] num_of_dest
13056 : : * The num of destination.
13057 : : * @param[in, out] res
13058 : : * Pointer to sample resource.
13059 : : * @param[in, out] mdest_res
13060 : : * Pointer to destination array resource.
13061 : : * @param[in] sample_actions
13062 : : * Pointer to sample path actions list.
13063 : : * @param[in] action_flags
13064 : : * Holds the actions detected until now.
13065 : : * @param[out] error
13066 : : * Pointer to the error structure.
13067 : : *
13068 : : * @return
13069 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13070 : : */
13071 : : static int
13072 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13073 : : struct mlx5_flow *dev_flow,
13074 : : uint32_t num_of_dest,
13075 : : struct mlx5_flow_dv_sample_resource *res,
13076 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13077 : : void **sample_actions,
13078 : : uint64_t action_flags,
13079 : : struct rte_flow_error *error)
13080 : : {
13081 : : /* update normal path action resource into last index of array */
13082 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13083 : : struct mlx5_flow_sub_actions_list *sample_act =
13084 : : &mdest_res->sample_act[dest_index];
13085 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13086 : : struct mlx5_flow_rss_desc *rss_desc;
13087 : : uint32_t normal_idx = 0;
13088 : : struct mlx5_hrxq *hrxq;
13089 : : uint32_t hrxq_idx;
13090 : :
13091 : : MLX5_ASSERT(wks);
13092 : 0 : rss_desc = &wks->rss_desc;
13093 [ # # ]: 0 : if (num_of_dest > 1) {
13094 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13095 : : /* Handle QP action for mirroring */
13096 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13097 : : rss_desc, &hrxq_idx);
13098 [ # # ]: 0 : if (!hrxq)
13099 : 0 : return rte_flow_error_set
13100 : : (error, rte_errno,
13101 : : RTE_FLOW_ERROR_TYPE_ACTION,
13102 : : NULL,
13103 : : "cannot create rx queue");
13104 : : normal_idx++;
13105 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13106 : 0 : sample_act->dr_queue_action = hrxq->action;
13107 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13108 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13109 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13110 : : }
13111 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13112 : 0 : normal_idx++;
13113 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13114 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13115 : 0 : sample_act->dr_encap_action =
13116 : 0 : dev_flow->dv.encap_decap->action;
13117 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13118 : : }
13119 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13120 : 0 : normal_idx++;
13121 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13122 : 0 : dev_flow->handle->rix_port_id_action;
13123 : 0 : sample_act->dr_port_id_action =
13124 : 0 : dev_flow->dv.port_id_action->action;
13125 : 0 : dev_flow->handle->rix_port_id_action = 0;
13126 : : }
13127 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13128 : 0 : normal_idx++;
13129 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13130 : 0 : dev_flow->handle->rix_jump;
13131 : 0 : sample_act->dr_jump_action =
13132 : 0 : dev_flow->dv.jump->action;
13133 : 0 : dev_flow->handle->rix_jump = 0;
13134 : : }
13135 : 0 : sample_act->actions_num = normal_idx;
13136 : : /* update sample action resource into first index of array */
13137 : 0 : mdest_res->ft_type = res->ft_type;
13138 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13139 : : sizeof(struct mlx5_flow_sub_actions_idx));
13140 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13141 : : sizeof(struct mlx5_flow_sub_actions_list));
13142 : 0 : mdest_res->num_of_dest = num_of_dest;
13143 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13144 : : dev_flow, error))
13145 : 0 : return rte_flow_error_set(error, EINVAL,
13146 : : RTE_FLOW_ERROR_TYPE_ACTION,
13147 : : NULL, "can't create sample "
13148 : : "action");
13149 : : } else {
13150 : 0 : res->sub_actions = sample_actions;
13151 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13152 : 0 : return rte_flow_error_set(error, EINVAL,
13153 : : RTE_FLOW_ERROR_TYPE_ACTION,
13154 : : NULL,
13155 : : "can't create sample action");
13156 : : }
13157 : : return 0;
13158 : : }
13159 : :
13160 : : /**
13161 : : * Remove an ASO age action from age actions list.
13162 : : *
13163 : : * @param[in] dev
13164 : : * Pointer to the Ethernet device structure.
13165 : : * @param[in] age
13166 : : * Pointer to the aso age action handler.
13167 : : */
13168 : : static void
13169 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13170 : : struct mlx5_aso_age_action *age)
13171 : : {
13172 : : struct mlx5_age_info *age_info;
13173 : : struct mlx5_age_param *age_param = &age->age_params;
13174 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13175 : : uint16_t expected = AGE_CANDIDATE;
13176 : :
13177 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13178 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&age_param->state, &expected,
13179 : : AGE_FREE, false, __ATOMIC_RELAXED,
13180 : : __ATOMIC_RELAXED)) {
13181 : : /**
13182 : : * We need the lock even it is age timeout,
13183 : : * since age action may still in process.
13184 : : */
13185 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13186 [ # # ]: 0 : LIST_REMOVE(age, next);
13187 : : rte_spinlock_unlock(&age_info->aged_sl);
13188 : 0 : __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
13189 : : }
13190 : 0 : }
13191 : :
13192 : : /**
13193 : : * Release an ASO age action.
13194 : : *
13195 : : * @param[in] dev
13196 : : * Pointer to the Ethernet device structure.
13197 : : * @param[in] age_idx
13198 : : * Index of ASO age action to release.
13199 : : * @param[in] flow
13200 : : * True if the release operation is during flow destroy operation.
13201 : : * False if the release operation is during action destroy operation.
13202 : : *
13203 : : * @return
13204 : : * 0 when age action was removed, otherwise the number of references.
13205 : : */
13206 : : static int
13207 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13208 : : {
13209 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13210 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13211 : 0 : struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
13212 : 0 : uint32_t ret = __atomic_fetch_sub(&age->refcnt, 1, __ATOMIC_RELAXED) - 1;
13213 : :
13214 [ # # ]: 0 : if (!ret) {
13215 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13216 : 0 : rte_spinlock_lock(&mng->free_sl);
13217 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13218 : : rte_spinlock_unlock(&mng->free_sl);
13219 : : }
13220 : 0 : return ret;
13221 : : }
13222 : :
13223 : : /**
13224 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13225 : : *
13226 : : * @param[in] dev
13227 : : * Pointer to the Ethernet device structure.
13228 : : *
13229 : : * @return
13230 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13231 : : */
13232 : : static int
13233 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13234 : : {
13235 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13236 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13237 : 0 : void *old_pools = mng->pools;
13238 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13239 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13240 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13241 : :
13242 [ # # ]: 0 : if (!pools) {
13243 : 0 : rte_errno = ENOMEM;
13244 : 0 : return -ENOMEM;
13245 : : }
13246 [ # # ]: 0 : if (old_pools) {
13247 : 0 : memcpy(pools, old_pools,
13248 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13249 : 0 : mlx5_free(old_pools);
13250 : : } else {
13251 : : /* First ASO flow hit allocation - starting ASO data-path. */
13252 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13253 : :
13254 [ # # ]: 0 : if (ret) {
13255 : 0 : mlx5_free(pools);
13256 : 0 : return ret;
13257 : : }
13258 : : }
13259 : 0 : mng->n = resize;
13260 : 0 : mng->pools = pools;
13261 : 0 : return 0;
13262 : : }
13263 : :
13264 : : /**
13265 : : * Create and initialize a new ASO aging pool.
13266 : : *
13267 : : * @param[in] dev
13268 : : * Pointer to the Ethernet device structure.
13269 : : * @param[out] age_free
13270 : : * Where to put the pointer of a new age action.
13271 : : *
13272 : : * @return
13273 : : * The age actions pool pointer and @p age_free is set on success,
13274 : : * NULL otherwise and rte_errno is set.
13275 : : */
13276 : : static struct mlx5_aso_age_pool *
13277 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13278 : : struct mlx5_aso_age_action **age_free)
13279 : : {
13280 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13281 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13282 : : struct mlx5_aso_age_pool *pool = NULL;
13283 : : struct mlx5_devx_obj *obj = NULL;
13284 : : uint32_t i;
13285 : :
13286 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13287 : 0 : priv->sh->cdev->pdn);
13288 [ # # ]: 0 : if (!obj) {
13289 : 0 : rte_errno = ENODATA;
13290 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13291 : 0 : return NULL;
13292 : : }
13293 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13294 [ # # ]: 0 : if (!pool) {
13295 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13296 : 0 : rte_errno = ENOMEM;
13297 : 0 : return NULL;
13298 : : }
13299 : 0 : pool->flow_hit_aso_obj = obj;
13300 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13301 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13302 : 0 : pool->index = mng->next;
13303 : : /* Resize pools array if there is no room for the new pool in it. */
13304 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13305 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13306 : 0 : mlx5_free(pool);
13307 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13308 : 0 : return NULL;
13309 : : }
13310 : 0 : mng->pools[pool->index] = pool;
13311 : 0 : mng->next++;
13312 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13313 : : /* Assign the first action in the new pool, the rest go to free list. */
13314 : 0 : *age_free = &pool->actions[0];
13315 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13316 : 0 : pool->actions[i].offset = i;
13317 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13318 : : }
13319 : : return pool;
13320 : : }
13321 : :
13322 : : /**
13323 : : * Allocate a ASO aging bit.
13324 : : *
13325 : : * @param[in] dev
13326 : : * Pointer to the Ethernet device structure.
13327 : : * @param[out] error
13328 : : * Pointer to the error structure.
13329 : : *
13330 : : * @return
13331 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13332 : : */
13333 : : static uint32_t
13334 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13335 : : {
13336 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13337 : : const struct mlx5_aso_age_pool *pool;
13338 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13339 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13340 : :
13341 : : MLX5_ASSERT(mng);
13342 : : /* Try to get the next free age action bit. */
13343 : 0 : rte_spinlock_lock(&mng->free_sl);
13344 : 0 : age_free = LIST_FIRST(&mng->free);
13345 [ # # ]: 0 : if (age_free) {
13346 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13347 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13348 : : rte_spinlock_unlock(&mng->free_sl);
13349 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13350 : : NULL, "failed to create ASO age pool");
13351 : 0 : return 0; /* 0 is an error. */
13352 : : }
13353 : : rte_spinlock_unlock(&mng->free_sl);
13354 : 0 : pool = container_of
13355 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13356 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13357 : : actions);
13358 [ # # ]: 0 : if (!age_free->dr_action) {
13359 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13360 : : error);
13361 : :
13362 [ # # ]: 0 : if (reg_c < 0) {
13363 : 0 : rte_flow_error_set(error, rte_errno,
13364 : : RTE_FLOW_ERROR_TYPE_ACTION,
13365 : : NULL, "failed to get reg_c "
13366 : : "for ASO flow hit");
13367 : 0 : return 0; /* 0 is an error. */
13368 : : }
13369 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13370 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13371 : 0 : (priv->sh->rx_domain,
13372 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13373 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13374 : 0 : (reg_c - REG_C_0));
13375 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13376 [ # # ]: 0 : if (!age_free->dr_action) {
13377 : 0 : rte_errno = errno;
13378 : : rte_spinlock_lock(&mng->free_sl);
13379 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13380 : : rte_spinlock_unlock(&mng->free_sl);
13381 : 0 : rte_flow_error_set(error, rte_errno,
13382 : : RTE_FLOW_ERROR_TYPE_ACTION,
13383 : : NULL, "failed to create ASO "
13384 : : "flow hit action");
13385 : 0 : return 0; /* 0 is an error. */
13386 : : }
13387 : : }
13388 : 0 : __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
13389 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13390 : : }
13391 : :
13392 : : /**
13393 : : * Initialize flow ASO age parameters.
13394 : : *
13395 : : * @param[in] dev
13396 : : * Pointer to rte_eth_dev structure.
13397 : : * @param[in] age_idx
13398 : : * Index of ASO age action.
13399 : : * @param[in] context
13400 : : * Pointer to flow counter age context.
13401 : : * @param[in] timeout
13402 : : * Aging timeout in seconds.
13403 : : *
13404 : : */
13405 : : static void
13406 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13407 : : uint32_t age_idx,
13408 : : void *context,
13409 : : uint32_t timeout)
13410 : : {
13411 : : struct mlx5_aso_age_action *aso_age;
13412 : :
13413 : 0 : aso_age = flow_aso_age_get_by_idx(dev, age_idx);
13414 : : MLX5_ASSERT(aso_age);
13415 : 0 : aso_age->age_params.context = context;
13416 : 0 : aso_age->age_params.timeout = timeout;
13417 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13418 : 0 : __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
13419 : : __ATOMIC_RELAXED);
13420 : 0 : __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
13421 : : __ATOMIC_RELAXED);
13422 : 0 : }
13423 : :
13424 : : static void
13425 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13426 : : void *headers)
13427 : : {
13428 : : /*
13429 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13430 : : * both mask and value, therefore ether can be used.
13431 : : * In SWS SW_V mode mask points to item mask and value points to item
13432 : : * spec. Integrity item value is used only if matching mask is set.
13433 : : * Use mask reference here to keep SWS functionality.
13434 : : */
13435 [ # # ]: 0 : if (mask->l4_ok) {
13436 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13437 : : * l4_checksum_ok filters.
13438 : : * Positive RTE l4_ok match requires hardware match on both L4
13439 : : * hardware integrity bits.
13440 : : * PMD supports positive integrity item semantics only.
13441 : : */
13442 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13443 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13444 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13445 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13446 : : }
13447 : 0 : }
13448 : :
13449 : : static void
13450 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13451 : : void *headers, bool is_ipv4)
13452 : : {
13453 : : /*
13454 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13455 : : * both mask and value, therefore ether can be used.
13456 : : * In SWS SW_V mode mask points to item mask and value points to item
13457 : : * spec. Integrity item value used only if matching mask is set.
13458 : : * Use mask reference here to keep SWS functionality.
13459 : : */
13460 [ # # ]: 0 : if (mask->l3_ok) {
13461 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13462 : : * ipv4_csum_ok filters.
13463 : : * Positive RTE l3_ok match requires hardware match on both L3
13464 : : * hardware integrity bits.
13465 : : * PMD supports positive integrity item semantics only.
13466 : : */
13467 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13468 [ # # ]: 0 : if (is_ipv4) {
13469 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13470 : : ipv4_checksum_ok, 1);
13471 : : }
13472 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13473 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13474 : : }
13475 : 0 : }
13476 : :
13477 : : static void
13478 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13479 : : bool is_l3_ip4, uint32_t key_type)
13480 : : {
13481 : : const struct rte_flow_item_integrity *spec;
13482 : : const struct rte_flow_item_integrity *mask;
13483 : :
13484 : : /* Integrity bits validation cleared spec pointer */
13485 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13486 : : return;
13487 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13488 : : &rte_flow_item_integrity_mask);
13489 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13490 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13491 : : }
13492 : :
13493 : : static void
13494 : 0 : flow_dv_translate_item_integrity_post(void *key,
13495 : : const
13496 : : struct rte_flow_item *integrity_items[2],
13497 : : uint64_t pattern_flags, uint32_t key_type)
13498 : : {
13499 : : void *headers;
13500 : : bool is_l3_ip4;
13501 : :
13502 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13503 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13504 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13505 : : 0;
13506 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13507 : : key_type);
13508 : : }
13509 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13510 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13511 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13512 : : 0;
13513 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13514 : : key_type);
13515 : : }
13516 : 0 : }
13517 : :
13518 : : static uint64_t
13519 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13520 : : struct mlx5_dv_matcher_workspace *wks,
13521 : : uint64_t key_type)
13522 : : {
13523 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13524 : : const struct rte_flow_item_integrity
13525 : 0 : *spec = (typeof(spec))item->spec;
13526 : :
13527 : : /* SWS integrity bits validation cleared spec pointer */
13528 [ # # ]: 0 : if (spec->level > 1) {
13529 : 0 : wks->integrity_items[1] = item;
13530 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13531 : : } else {
13532 : 0 : wks->integrity_items[0] = item;
13533 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13534 : : }
13535 : : } else {
13536 : : /* HWS supports outer integrity only */
13537 : 0 : wks->integrity_items[0] = item;
13538 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13539 : : }
13540 : 0 : return wks->last_item;
13541 : : }
13542 : :
13543 : : /**
13544 : : * Prepares DV flow counter with aging configuration.
13545 : : * Gets it by index when exists, creates a new one when doesn't.
13546 : : *
13547 : : * @param[in] dev
13548 : : * Pointer to rte_eth_dev structure.
13549 : : * @param[in] dev_flow
13550 : : * Pointer to the mlx5_flow.
13551 : : * @param[in, out] flow
13552 : : * Pointer to the sub flow.
13553 : : * @param[in] count
13554 : : * Pointer to the counter action configuration.
13555 : : * @param[in] age
13556 : : * Pointer to the aging action configuration.
13557 : : * @param[out] error
13558 : : * Pointer to the error structure.
13559 : : *
13560 : : * @return
13561 : : * Pointer to the counter, NULL otherwise.
13562 : : */
13563 : : static struct mlx5_flow_counter *
13564 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13565 : : struct mlx5_flow *dev_flow,
13566 : : struct rte_flow *flow,
13567 : : const struct rte_flow_action_count *count,
13568 : : const struct rte_flow_action_age *age,
13569 : : struct rte_flow_error *error)
13570 : : {
13571 [ # # ]: 0 : if (!flow->counter) {
13572 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13573 : : count, age);
13574 [ # # ]: 0 : if (!flow->counter) {
13575 : 0 : rte_flow_error_set(error, rte_errno,
13576 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13577 : : "cannot create counter object.");
13578 : 0 : return NULL;
13579 : : }
13580 : : }
13581 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13582 : : }
13583 : :
13584 : : /*
13585 : : * Release an ASO CT action by its own device.
13586 : : *
13587 : : * @param[in] dev
13588 : : * Pointer to the Ethernet device structure.
13589 : : * @param[in] idx
13590 : : * Index of ASO CT action to release.
13591 : : *
13592 : : * @return
13593 : : * 0 when CT action was removed, otherwise the number of references.
13594 : : */
13595 : : static inline int
13596 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13597 : : {
13598 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13599 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13600 : : uint32_t ret;
13601 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13602 : : enum mlx5_aso_ct_state state =
13603 : 0 : __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
13604 : :
13605 : : /* Cannot release when CT is in the ASO SQ. */
13606 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
13607 : : return -1;
13608 : 0 : ret = __atomic_fetch_sub(&ct->refcnt, 1, __ATOMIC_RELAXED) - 1;
13609 [ # # ]: 0 : if (!ret) {
13610 [ # # ]: 0 : if (ct->dr_action_orig) {
13611 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13612 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13613 : : (ct->dr_action_orig));
13614 : : #endif
13615 : 0 : ct->dr_action_orig = NULL;
13616 : : }
13617 [ # # ]: 0 : if (ct->dr_action_rply) {
13618 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13619 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13620 : : (ct->dr_action_rply));
13621 : : #endif
13622 : 0 : ct->dr_action_rply = NULL;
13623 : : }
13624 : : /* Clear the state to free, no need in 1st allocation. */
13625 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
13626 : 0 : rte_spinlock_lock(&mng->ct_sl);
13627 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
13628 : : rte_spinlock_unlock(&mng->ct_sl);
13629 : : }
13630 : 0 : return (int)ret;
13631 : : }
13632 : :
13633 : : static inline int
13634 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
13635 : : struct rte_flow_error *error)
13636 : : {
13637 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
13638 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
13639 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
13640 : : int ret;
13641 : :
13642 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
13643 [ # # ]: 0 : if (dev->data->dev_started != 1)
13644 : 0 : return rte_flow_error_set(error, EAGAIN,
13645 : : RTE_FLOW_ERROR_TYPE_ACTION,
13646 : : NULL,
13647 : : "Indirect CT action cannot be destroyed when the port is stopped");
13648 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
13649 [ # # ]: 0 : if (ret < 0)
13650 : 0 : return rte_flow_error_set(error, EAGAIN,
13651 : : RTE_FLOW_ERROR_TYPE_ACTION,
13652 : : NULL,
13653 : : "Current state prevents indirect CT action from being destroyed");
13654 : : return ret;
13655 : : }
13656 : :
13657 : : /*
13658 : : * Resize the ASO CT pools array by 64 pools.
13659 : : *
13660 : : * @param[in] dev
13661 : : * Pointer to the Ethernet device structure.
13662 : : *
13663 : : * @return
13664 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13665 : : */
13666 : : static int
13667 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
13668 : : {
13669 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13670 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13671 : 0 : void *old_pools = mng->pools;
13672 : : /* Magic number now, need a macro. */
13673 : 0 : uint32_t resize = mng->n + 64;
13674 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
13675 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13676 : :
13677 [ # # ]: 0 : if (!pools) {
13678 : 0 : rte_errno = ENOMEM;
13679 : 0 : return -rte_errno;
13680 : : }
13681 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13682 : : /* ASO SQ/QP was already initialized in the startup. */
13683 [ # # ]: 0 : if (old_pools) {
13684 : : /* Realloc could be an alternative choice. */
13685 : 0 : rte_memcpy(pools, old_pools,
13686 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
13687 : 0 : mlx5_free(old_pools);
13688 : : }
13689 : 0 : mng->n = resize;
13690 : 0 : mng->pools = pools;
13691 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13692 : 0 : return 0;
13693 : : }
13694 : :
13695 : : /*
13696 : : * Create and initialize a new ASO CT pool.
13697 : : *
13698 : : * @param[in] dev
13699 : : * Pointer to the Ethernet device structure.
13700 : : * @param[out] ct_free
13701 : : * Where to put the pointer of a new CT action.
13702 : : *
13703 : : * @return
13704 : : * The CT actions pool pointer and @p ct_free is set on success,
13705 : : * NULL otherwise and rte_errno is set.
13706 : : */
13707 : : static struct mlx5_aso_ct_pool *
13708 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
13709 : : struct mlx5_aso_ct_action **ct_free)
13710 : : {
13711 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13712 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13713 : : struct mlx5_aso_ct_pool *pool = NULL;
13714 : : struct mlx5_devx_obj *obj = NULL;
13715 : : uint32_t i;
13716 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
13717 : : size_t mem_size;
13718 : :
13719 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
13720 : 0 : priv->sh->cdev->pdn,
13721 : : log_obj_size);
13722 [ # # ]: 0 : if (!obj) {
13723 : 0 : rte_errno = ENODATA;
13724 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
13725 : 0 : return NULL;
13726 : : }
13727 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
13728 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
13729 : : sizeof(*pool);
13730 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13731 [ # # ]: 0 : if (!pool) {
13732 : 0 : rte_errno = ENOMEM;
13733 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13734 : 0 : return NULL;
13735 : : }
13736 : 0 : pool->devx_obj = obj;
13737 : 0 : pool->index = mng->next;
13738 : : /* Resize pools array if there is no room for the new pool in it. */
13739 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
13740 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13741 : 0 : mlx5_free(pool);
13742 : 0 : return NULL;
13743 : : }
13744 : 0 : mng->pools[pool->index] = pool;
13745 : 0 : mng->next++;
13746 : : /* Assign the first action in the new pool, the rest go to free list. */
13747 : 0 : *ct_free = &pool->actions[0];
13748 : : /* Lock outside, the list operation is safe here. */
13749 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
13750 : : /* refcnt is 0 when allocating the memory. */
13751 : 0 : pool->actions[i].offset = i;
13752 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
13753 : : }
13754 : : return pool;
13755 : : }
13756 : :
13757 : : /*
13758 : : * Allocate a ASO CT action from free list.
13759 : : *
13760 : : * @param[in] dev
13761 : : * Pointer to the Ethernet device structure.
13762 : : * @param[out] error
13763 : : * Pointer to the error structure.
13764 : : *
13765 : : * @return
13766 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
13767 : : */
13768 : : static uint32_t
13769 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13770 : : {
13771 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13772 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13773 : 0 : struct mlx5_aso_ct_action *ct = NULL;
13774 : : struct mlx5_aso_ct_pool *pool;
13775 : : uint8_t reg_c;
13776 : : uint32_t ct_idx;
13777 : :
13778 : : MLX5_ASSERT(mng);
13779 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
13780 : 0 : rte_errno = ENOTSUP;
13781 : 0 : return 0;
13782 : : }
13783 : : /* Get a free CT action, if no, a new pool will be created. */
13784 : 0 : rte_spinlock_lock(&mng->ct_sl);
13785 : 0 : ct = LIST_FIRST(&mng->free_cts);
13786 [ # # ]: 0 : if (ct) {
13787 [ # # ]: 0 : LIST_REMOVE(ct, next);
13788 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
13789 : : rte_spinlock_unlock(&mng->ct_sl);
13790 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13791 : : NULL, "failed to create ASO CT pool");
13792 : 0 : return 0;
13793 : : }
13794 : : rte_spinlock_unlock(&mng->ct_sl);
13795 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
13796 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
13797 : : /* 0: inactive, 1: created, 2+: used by flows. */
13798 : 0 : __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
13799 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
13800 [ # # ]: 0 : if (!ct->dr_action_orig) {
13801 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13802 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
13803 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
13804 : : ct->offset,
13805 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
13806 : 0 : reg_c - REG_C_0);
13807 : : #else
13808 : : RTE_SET_USED(reg_c);
13809 : : #endif
13810 [ # # ]: 0 : if (!ct->dr_action_orig) {
13811 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
13812 : 0 : rte_flow_error_set(error, rte_errno,
13813 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13814 : : "failed to create ASO CT action");
13815 : 0 : return 0;
13816 : : }
13817 : : }
13818 [ # # ]: 0 : if (!ct->dr_action_rply) {
13819 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13820 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
13821 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
13822 : : ct->offset,
13823 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
13824 : 0 : reg_c - REG_C_0);
13825 : : #endif
13826 [ # # ]: 0 : if (!ct->dr_action_rply) {
13827 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
13828 : 0 : rte_flow_error_set(error, rte_errno,
13829 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13830 : : "failed to create ASO CT action");
13831 : 0 : return 0;
13832 : : }
13833 : : }
13834 : : return ct_idx;
13835 : : }
13836 : :
13837 : : /*
13838 : : * Create a conntrack object with context and actions by using ASO mechanism.
13839 : : *
13840 : : * @param[in] dev
13841 : : * Pointer to rte_eth_dev structure.
13842 : : * @param[in] pro
13843 : : * Pointer to conntrack information profile.
13844 : : * @param[out] error
13845 : : * Pointer to the error structure.
13846 : : *
13847 : : * @return
13848 : : * Index to conntrack object on success, 0 otherwise.
13849 : : */
13850 : : static uint32_t
13851 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
13852 : : const struct rte_flow_action_conntrack *pro,
13853 : : struct rte_flow_error *error)
13854 : : {
13855 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13856 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
13857 : : struct mlx5_aso_ct_action *ct;
13858 : : uint32_t idx;
13859 : :
13860 [ # # ]: 0 : if (!sh->ct_aso_en)
13861 : 0 : return rte_flow_error_set(error, ENOTSUP,
13862 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13863 : : "Connection is not supported");
13864 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
13865 [ # # ]: 0 : if (!idx)
13866 : 0 : return rte_flow_error_set(error, rte_errno,
13867 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13868 : : "Failed to allocate CT object");
13869 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13870 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
13871 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
13872 : 0 : rte_flow_error_set(error, EBUSY,
13873 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13874 : : "Failed to update CT");
13875 : 0 : return 0;
13876 : : }
13877 : 0 : ct->is_original = !!pro->is_original_dir;
13878 : 0 : ct->peer = pro->peer_port;
13879 : 0 : return idx;
13880 : : }
13881 : :
13882 : : /**
13883 : : * Fill the flow matcher with DV spec.
13884 : : *
13885 : : * @param[in] dev
13886 : : * Pointer to rte_eth_dev structure.
13887 : : * @param[in] items
13888 : : * Pointer to the list of items.
13889 : : * @param[in] wks
13890 : : * Pointer to the matcher workspace.
13891 : : * @param[in] key
13892 : : * Pointer to the flow matcher key.
13893 : : * @param[in] key_type
13894 : : * Key type.
13895 : : * @param[out] error
13896 : : * Pointer to the error structure.
13897 : : *
13898 : : * @return
13899 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13900 : : */
13901 : : static int
13902 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
13903 : : const struct rte_flow_item *items,
13904 : : struct mlx5_dv_matcher_workspace *wks,
13905 : : void *key, uint32_t key_type,
13906 : : struct rte_flow_error *error)
13907 : : {
13908 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
13909 : 0 : uint8_t next_protocol = wks->next_protocol;
13910 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
13911 : 0 : int item_type = items->type;
13912 : 0 : uint64_t last_item = wks->last_item;
13913 : : int ret;
13914 : :
13915 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
13916 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
13917 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type);
13918 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
13919 : : last_item = MLX5_FLOW_ITEM_ESP;
13920 : 0 : break;
13921 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
13922 : 0 : flow_dv_translate_item_port_id
13923 : : (dev, key, items, wks->attr, key_type);
13924 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
13925 : 0 : break;
13926 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
13927 : 0 : flow_dv_translate_item_port_representor
13928 : : (dev, key, key_type);
13929 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
13930 : 0 : break;
13931 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
13932 : 0 : flow_dv_translate_item_represented_port
13933 : : (dev, key, items, wks->attr, key_type);
13934 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
13935 : 0 : break;
13936 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
13937 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
13938 : : wks->group, key_type);
13939 [ # # ]: 0 : wks->priority = wks->action_flags &
13940 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
13941 [ # # ]: 0 : !wks->external ?
13942 : : MLX5_PRIORITY_MAP_L3 :
13943 : : MLX5_PRIORITY_MAP_L2;
13944 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13945 : : MLX5_FLOW_LAYER_OUTER_L2;
13946 : : break;
13947 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
13948 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
13949 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
13950 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13951 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
13952 : : (MLX5_FLOW_LAYER_OUTER_L2 |
13953 : : MLX5_FLOW_LAYER_OUTER_VLAN);
13954 : : break;
13955 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
13956 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
13957 : : &wks->item_flags, &tunnel);
13958 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
13959 : : wks->group, key_type);
13960 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
13961 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13962 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13963 [ # # ]: 0 : if (items->mask != NULL &&
13964 [ # # ]: 0 : items->spec != NULL &&
13965 : : ((const struct rte_flow_item_ipv4 *)
13966 [ # # ]: 0 : items->mask)->hdr.next_proto_id) {
13967 : 0 : next_protocol =
13968 : : ((const struct rte_flow_item_ipv4 *)
13969 : : (items->spec))->hdr.next_proto_id;
13970 : 0 : next_protocol &=
13971 : : ((const struct rte_flow_item_ipv4 *)
13972 : : (items->mask))->hdr.next_proto_id;
13973 [ # # # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M &&
13974 : : items->mask != NULL) {
13975 : 0 : next_protocol = ((const struct rte_flow_item_ipv4 *)
13976 : : (items->mask))->hdr.next_proto_id;
13977 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V &&
13978 [ # # ]: 0 : items->spec != NULL) {
13979 : 0 : next_protocol = ((const struct rte_flow_item_ipv4 *)
13980 : : (items->spec))->hdr.next_proto_id;
13981 : : } else {
13982 : : /* Reset for inner layer. */
13983 : : next_protocol = 0xff;
13984 : : }
13985 : : break;
13986 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
13987 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
13988 : : &wks->item_flags, &tunnel);
13989 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
13990 : : wks->group, key_type);
13991 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
13992 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13993 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13994 [ # # ]: 0 : if (items->mask != NULL &&
13995 [ # # ]: 0 : items->spec != NULL &&
13996 : : ((const struct rte_flow_item_ipv6 *)
13997 [ # # ]: 0 : items->mask)->hdr.proto) {
13998 : 0 : next_protocol =
13999 : : ((const struct rte_flow_item_ipv6 *)
14000 : : items->spec)->hdr.proto;
14001 : 0 : next_protocol &=
14002 : : ((const struct rte_flow_item_ipv6 *)
14003 : : items->mask)->hdr.proto;
14004 [ # # # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M &&
14005 : : items->mask != NULL) {
14006 : 0 : next_protocol = ((const struct rte_flow_item_ipv6 *)
14007 : : (items->mask))->hdr.proto;
14008 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V &&
14009 [ # # ]: 0 : items->spec != NULL) {
14010 : 0 : next_protocol = ((const struct rte_flow_item_ipv6 *)
14011 : : (items->spec))->hdr.proto;
14012 : : } else {
14013 : : /* Reset for inner layer. */
14014 : : next_protocol = 0xff;
14015 : : }
14016 : : break;
14017 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14018 : 0 : flow_dv_translate_item_ipv6_frag_ext
14019 : : (key, items, tunnel, key_type);
14020 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14021 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14022 [ # # ]: 0 : if (items->mask != NULL &&
14023 [ # # ]: 0 : items->spec != NULL &&
14024 : : ((const struct rte_flow_item_ipv6_frag_ext *)
14025 [ # # ]: 0 : items->mask)->hdr.next_header) {
14026 : 0 : next_protocol =
14027 : : ((const struct rte_flow_item_ipv6_frag_ext *)
14028 : : items->spec)->hdr.next_header;
14029 : 0 : next_protocol &=
14030 : : ((const struct rte_flow_item_ipv6_frag_ext *)
14031 : : items->mask)->hdr.next_header;
14032 [ # # # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M &&
14033 : : items->mask != NULL) {
14034 : 0 : next_protocol = ((const struct rte_flow_item_ipv6_frag_ext *)
14035 : : (items->mask))->hdr.next_header;
14036 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V &&
14037 [ # # ]: 0 : items->spec != NULL) {
14038 : 0 : next_protocol = ((const struct rte_flow_item_ipv6_frag_ext *)
14039 : : (items->spec))->hdr.next_header;
14040 : : } else {
14041 : : /* Reset for inner layer. */
14042 : : next_protocol = 0xff;
14043 : : }
14044 : : break;
14045 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14046 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14047 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14048 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14049 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14050 : : break;
14051 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14052 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14053 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14054 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14055 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14056 : : break;
14057 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14058 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14059 : 0 : wks->tunnel_item = items;
14060 : 0 : wks->gre_item = items;
14061 : : last_item = MLX5_FLOW_LAYER_GRE;
14062 : 0 : break;
14063 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14064 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14065 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14066 : 0 : break;
14067 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14068 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14069 : 0 : wks->tunnel_item = items;
14070 : : last_item = MLX5_FLOW_LAYER_GRE;
14071 : 0 : break;
14072 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
14073 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14074 : 0 : wks->tunnel_item = items;
14075 : : last_item = MLX5_FLOW_LAYER_GRE;
14076 : 0 : break;
14077 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
14078 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14079 : : items, tunnel, wks, key_type);
14080 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14081 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14082 : 0 : break;
14083 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14084 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14085 : 0 : wks->tunnel_item = items;
14086 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14087 : 0 : break;
14088 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14089 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14090 : 0 : wks->tunnel_item = items;
14091 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14092 : 0 : break;
14093 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14094 : 0 : ret = flow_dv_translate_item_geneve_opt
14095 : : (dev, key, items, key_type, error);
14096 [ # # ]: 0 : if (ret)
14097 : 0 : return rte_flow_error_set(error, -ret,
14098 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14099 : : "cannot create GENEVE TLV option");
14100 : 0 : wks->geneve_tlv_option = 1;
14101 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14102 : 0 : break;
14103 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14104 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14105 : : tunnel, key_type);
14106 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14107 : : last_item = MLX5_FLOW_LAYER_MPLS;
14108 : 0 : break;
14109 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14110 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14111 : : last_item = MLX5_FLOW_ITEM_MARK;
14112 : 0 : break;
14113 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14114 : 0 : flow_dv_translate_item_meta
14115 : : (dev, key, wks->attr, items, key_type);
14116 : : last_item = MLX5_FLOW_ITEM_METADATA;
14117 : 0 : break;
14118 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14119 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14120 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14121 : : last_item = MLX5_FLOW_LAYER_ICMP;
14122 : 0 : break;
14123 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14124 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14125 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14126 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14127 : 0 : break;
14128 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14129 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14130 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14131 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14132 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14133 : 0 : break;
14134 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14135 : 0 : flow_dv_translate_item_tag(dev, key, items, key_type);
14136 : : last_item = MLX5_FLOW_ITEM_TAG;
14137 : 0 : break;
14138 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14139 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14140 : : last_item = MLX5_FLOW_ITEM_TAG;
14141 : 0 : break;
14142 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14143 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14144 : : last_item = MLX5_FLOW_ITEM_SQ;
14145 : 0 : break;
14146 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14147 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14148 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14149 : : last_item = MLX5_FLOW_LAYER_GTP;
14150 : 0 : break;
14151 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14152 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14153 [ # # ]: 0 : if (ret)
14154 : 0 : return rte_flow_error_set(error, -ret,
14155 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14156 : : "cannot create GTP PSC item");
14157 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14158 : : break;
14159 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14160 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14161 : : /* Create it only the first time to be used. */
14162 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14163 [ # # ]: 0 : if (ret)
14164 : 0 : return rte_flow_error_set
14165 : : (error, -ret,
14166 : : RTE_FLOW_ERROR_TYPE_ITEM,
14167 : : NULL,
14168 : : "cannot create eCPRI parser");
14169 : : }
14170 : 0 : flow_dv_translate_item_ecpri
14171 : : (dev, key, items, last_item, key_type);
14172 : : /* No other protocol should follow eCPRI layer. */
14173 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14174 : 0 : break;
14175 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14176 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14177 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14178 : 0 : break;
14179 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14180 : : last_item = flow_dv_translate_item_integrity(items,
14181 : : wks, key_type);
14182 : 0 : break;
14183 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14184 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14185 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14186 : 0 : break;
14187 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14188 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14189 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14190 : 0 : break;
14191 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14192 : : last_item = MLX5_FLOW_ITEM_NSH;
14193 : 0 : break;
14194 : : default:
14195 : : break;
14196 : : }
14197 : 0 : wks->item_flags |= last_item;
14198 : 0 : wks->last_item = last_item;
14199 : 0 : wks->next_protocol = next_protocol;
14200 : 0 : return 0;
14201 : : }
14202 : :
14203 : : /**
14204 : : * Fill the HW steering flow with DV spec.
14205 : : *
14206 : : * @param[in] items
14207 : : * Pointer to the list of items.
14208 : : * @param[in] attr
14209 : : * Pointer to the flow attributes.
14210 : : * @param[in] key
14211 : : * Pointer to the flow matcher key.
14212 : : * @param[in] key_type
14213 : : * Key type.
14214 : : * @param[in, out] item_flags
14215 : : * Pointer to the flow item flags.
14216 : : * @param[out] error
14217 : : * Pointer to the error structure.
14218 : : *
14219 : : * @return
14220 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14221 : : */
14222 : : int
14223 : 0 : flow_dv_translate_items_hws(const struct rte_flow_item *items,
14224 : : struct mlx5_flow_attr *attr, void *key,
14225 : : uint32_t key_type, uint64_t *item_flags,
14226 : : uint8_t *match_criteria,
14227 : : struct rte_flow_error *error)
14228 : : {
14229 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14230 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14231 : 0 : struct rte_flow_attr rattr = {
14232 : 0 : .group = attr->group,
14233 : 0 : .priority = attr->priority,
14234 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14235 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14236 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14237 : : };
14238 : 0 : struct mlx5_dv_matcher_workspace wks = {
14239 : 0 : .action_flags = attr->act_flags,
14240 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14241 : : .external = 0,
14242 : : .next_protocol = 0xff,
14243 : : .attr = &rattr,
14244 : : .rss_desc = &rss_desc,
14245 : : };
14246 : : int ret = 0;
14247 : :
14248 : : RTE_SET_USED(flow_wks);
14249 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14250 : : if (!mlx5_flow_os_item_supported(items->type)) {
14251 : : ret = rte_flow_error_set(error, ENOTSUP,
14252 : : RTE_FLOW_ERROR_TYPE_ITEM,
14253 : : NULL, "item not supported");
14254 : : goto exit;
14255 : : }
14256 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14257 : : items, &wks, key, key_type, NULL);
14258 [ # # ]: 0 : if (ret)
14259 : 0 : goto exit;
14260 : : }
14261 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14262 : 0 : flow_dv_translate_item_integrity_post(key,
14263 : : wks.integrity_items,
14264 : : wks.item_flags,
14265 : : key_type);
14266 : : }
14267 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14268 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14269 : : wks.tunnel_item,
14270 : : wks.item_flags,
14271 : : key_type);
14272 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14273 : 0 : flow_dv_translate_item_geneve(key,
14274 : : wks.tunnel_item,
14275 : : wks.item_flags,
14276 : : key_type);
14277 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14278 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14279 : 0 : flow_dv_translate_item_gre(key,
14280 : : wks.tunnel_item,
14281 : : wks.item_flags,
14282 : : key_type);
14283 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14284 : 0 : flow_dv_translate_item_gre_option(key,
14285 : : wks.tunnel_item,
14286 : : wks.gre_item,
14287 : : wks.item_flags,
14288 : : key_type);
14289 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14290 : 0 : flow_dv_translate_item_nvgre(key,
14291 : : wks.tunnel_item,
14292 : : wks.item_flags,
14293 : : key_type);
14294 : : } else {
14295 : : MLX5_ASSERT(false);
14296 : : }
14297 : : }
14298 : :
14299 [ # # ]: 0 : if (match_criteria)
14300 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14301 [ # # ]: 0 : if (item_flags)
14302 : 0 : *item_flags = wks.item_flags;
14303 : 0 : exit:
14304 : 0 : mlx5_flow_pop_thread_workspace();
14305 : 0 : return ret;
14306 : : }
14307 : :
14308 : : /**
14309 : : * Fill the SW steering flow with DV spec.
14310 : : *
14311 : : * @param[in] dev
14312 : : * Pointer to rte_eth_dev structure.
14313 : : * @param[in, out] dev_flow
14314 : : * Pointer to the sub flow.
14315 : : * @param[in] attr
14316 : : * Pointer to the flow attributes.
14317 : : * @param[in] items
14318 : : * Pointer to the list of items.
14319 : : * @param[in, out] matcher
14320 : : * Pointer to the flow matcher.
14321 : : * @param[out] error
14322 : : * Pointer to the error structure.
14323 : : *
14324 : : * @return
14325 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14326 : : */
14327 : : static int
14328 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14329 : : struct mlx5_flow *dev_flow,
14330 : : const struct rte_flow_attr *attr,
14331 : : const struct rte_flow_item *items,
14332 : : struct mlx5_flow_dv_matcher *matcher,
14333 : : struct rte_flow_error *error)
14334 : : {
14335 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14336 : 0 : void *match_mask = matcher->mask.buf;
14337 : 0 : void *match_value = dev_flow->dv.value.buf;
14338 : 0 : struct mlx5_dv_matcher_workspace wks = {
14339 : 0 : .action_flags = dev_flow->act_flags,
14340 : : .item_flags = 0,
14341 : 0 : .external = dev_flow->external,
14342 : : .next_protocol = 0xff,
14343 : 0 : .group = dev_flow->dv.group,
14344 : : .attr = attr,
14345 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14346 : : mlx5_flow_get_thread_workspace())->rss_desc,
14347 : : };
14348 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14349 : : int item_type;
14350 : : int ret = 0;
14351 : : int tunnel;
14352 : :
14353 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14354 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14355 : : return rte_flow_error_set(error, ENOTSUP,
14356 : : RTE_FLOW_ERROR_TYPE_ITEM,
14357 : : NULL, "item not supported");
14358 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14359 : : item_type = items->type;
14360 [ # # # # ]: 0 : switch (item_type) {
14361 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14362 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14363 : : match_value, items);
14364 : 0 : break;
14365 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14366 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14367 : : match_value, items,
14368 : : dev_flow, tunnel != 0);
14369 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14370 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14371 : 0 : break;
14372 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14373 : 0 : flow_dv_translate_item_sq(match_value, items,
14374 : : MLX5_SET_MATCHER_SW_V);
14375 : 0 : flow_dv_translate_item_sq(match_mask, items,
14376 : : MLX5_SET_MATCHER_SW_M);
14377 : 0 : break;
14378 : 0 : default:
14379 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14380 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14381 [ # # ]: 0 : if (ret)
14382 : 0 : return ret;
14383 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14384 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14385 [ # # ]: 0 : if (ret)
14386 : 0 : return ret;
14387 : : break;
14388 : : }
14389 : 0 : wks.item_flags |= wks.last_item;
14390 : : }
14391 : : /*
14392 : : * When E-Switch mode is enabled, we have two cases where we need to
14393 : : * set the source port manually.
14394 : : * The first one, is in case of NIC ingress steering rule, and the
14395 : : * second is E-Switch rule where no port_id item was found.
14396 : : * In both cases the source port is set according the current port
14397 : : * in use.
14398 : : */
14399 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14400 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14401 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14402 [ # # ]: 0 : priv->sh->esw_mode &&
14403 [ # # ]: 0 : !attr->egress &&
14404 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14405 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14406 : : match_value, NULL, attr))
14407 : 0 : return -rte_errno;
14408 : : }
14409 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14410 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14411 : : wks_m.integrity_items,
14412 : : wks_m.item_flags,
14413 : : MLX5_SET_MATCHER_SW_M);
14414 : 0 : flow_dv_translate_item_integrity_post(match_value,
14415 : : wks.integrity_items,
14416 : : wks.item_flags,
14417 : : MLX5_SET_MATCHER_SW_V);
14418 : : }
14419 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14420 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14421 : : wks.tunnel_item,
14422 : : wks.item_flags,
14423 : : MLX5_SET_MATCHER_SW_M);
14424 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14425 : : wks.tunnel_item,
14426 : : wks.item_flags,
14427 : : MLX5_SET_MATCHER_SW_V);
14428 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14429 : 0 : flow_dv_translate_item_geneve(match_mask,
14430 : : wks.tunnel_item,
14431 : : wks.item_flags,
14432 : : MLX5_SET_MATCHER_SW_M);
14433 : 0 : flow_dv_translate_item_geneve(match_value,
14434 : : wks.tunnel_item,
14435 : : wks.item_flags,
14436 : : MLX5_SET_MATCHER_SW_V);
14437 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14438 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14439 : 0 : flow_dv_translate_item_gre(match_mask,
14440 : : wks.tunnel_item,
14441 : : wks.item_flags,
14442 : : MLX5_SET_MATCHER_SW_M);
14443 : 0 : flow_dv_translate_item_gre(match_value,
14444 : : wks.tunnel_item,
14445 : : wks.item_flags,
14446 : : MLX5_SET_MATCHER_SW_V);
14447 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14448 : 0 : flow_dv_translate_item_nvgre(match_mask,
14449 : : wks.tunnel_item,
14450 : : wks.item_flags,
14451 : : MLX5_SET_MATCHER_SW_M);
14452 : 0 : flow_dv_translate_item_nvgre(match_value,
14453 : : wks.tunnel_item,
14454 : : wks.item_flags,
14455 : : MLX5_SET_MATCHER_SW_V);
14456 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14457 : 0 : flow_dv_translate_item_gre_option(match_mask,
14458 : : wks.tunnel_item,
14459 : : wks.gre_item,
14460 : : wks.item_flags,
14461 : : MLX5_SET_MATCHER_SW_M);
14462 : 0 : flow_dv_translate_item_gre_option(match_value,
14463 : : wks.tunnel_item,
14464 : : wks.gre_item,
14465 : : wks.item_flags,
14466 : : MLX5_SET_MATCHER_SW_V);
14467 : : } else {
14468 : : MLX5_ASSERT(false);
14469 : : }
14470 : : }
14471 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
14472 : 0 : matcher->priority = wks.priority;
14473 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14474 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
14475 : : #endif
14476 : : /*
14477 : : * Layers may be already initialized from prefix flow if this dev_flow
14478 : : * is the suffix flow.
14479 : : */
14480 : 0 : dev_flow->handle->layers |= wks.item_flags;
14481 : : /*
14482 : : * Update geneve_tlv_option flag only it is set in workspace.
14483 : : * Avoid be overwritten by other sub mlx5_flows.
14484 : : */
14485 [ # # ]: 0 : if (wks.geneve_tlv_option)
14486 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
14487 : : return 0;
14488 : : }
14489 : :
14490 : : /**
14491 : : * Fill the flow with DV spec, lock free
14492 : : * (mutex should be acquired by caller).
14493 : : *
14494 : : * @param[in] dev
14495 : : * Pointer to rte_eth_dev structure.
14496 : : * @param[in, out] dev_flow
14497 : : * Pointer to the sub flow.
14498 : : * @param[in] attr
14499 : : * Pointer to the flow attributes.
14500 : : * @param[in] items
14501 : : * Pointer to the list of items.
14502 : : * @param[in] actions
14503 : : * Pointer to the list of actions.
14504 : : * @param[out] error
14505 : : * Pointer to the error structure.
14506 : : *
14507 : : * @return
14508 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14509 : : */
14510 : : static int
14511 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
14512 : : struct mlx5_flow *dev_flow,
14513 : : const struct rte_flow_attr *attr,
14514 : : const struct rte_flow_item items[],
14515 : : const struct rte_flow_action actions[],
14516 : : struct rte_flow_error *error)
14517 : : {
14518 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14519 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
14520 : 0 : struct rte_flow *flow = dev_flow->flow;
14521 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
14522 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14523 : : struct mlx5_flow_rss_desc *rss_desc;
14524 : : uint64_t action_flags = 0;
14525 : 0 : struct mlx5_flow_dv_matcher matcher = {
14526 : : .mask = {
14527 : : .size = sizeof(matcher.mask.buf),
14528 : : },
14529 : : };
14530 : : int actions_n = 0;
14531 : : bool actions_end = false;
14532 : : union {
14533 : : struct mlx5_flow_dv_modify_hdr_resource res;
14534 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14535 : : sizeof(struct mlx5_modification_cmd) *
14536 : : (MLX5_MAX_MODIFY_NUM + 1)];
14537 : : } mhdr_dummy;
14538 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
14539 : : const struct rte_flow_action_count *count = NULL;
14540 : : const struct rte_flow_action_age *non_shared_age = NULL;
14541 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
14542 : : uint32_t tag_be;
14543 : : union mlx5_flow_tbl_key tbl_key;
14544 : : uint32_t modify_action_position = UINT32_MAX;
14545 : 0 : struct rte_vlan_hdr vlan = { 0 };
14546 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
14547 : : struct mlx5_flow_dv_sample_resource sample_res;
14548 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
14549 : : const struct rte_flow_action_sample *sample = NULL;
14550 : : struct mlx5_flow_sub_actions_list *sample_act;
14551 : : uint32_t sample_act_pos = UINT32_MAX;
14552 : : uint32_t age_act_pos = UINT32_MAX;
14553 : : uint32_t ipv6_tc_off = 0;
14554 : 0 : uint32_t num_of_dest = 0;
14555 : : int tmp_actions_n = 0;
14556 : : uint32_t table;
14557 : : int ret = 0;
14558 : : const struct mlx5_flow_tunnel *tunnel = NULL;
14559 : 0 : struct flow_grp_info grp_info = {
14560 : 0 : .external = !!dev_flow->external,
14561 : 0 : .transfer = !!attr->transfer,
14562 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
14563 : 0 : .skip_scale = dev_flow->skip_scale &
14564 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
14565 : : .std_tbl_fix = true,
14566 : : };
14567 : :
14568 [ # # ]: 0 : if (!wks)
14569 : 0 : return rte_flow_error_set(error, ENOMEM,
14570 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14571 : : NULL,
14572 : : "failed to push flow workspace");
14573 [ # # ]: 0 : rss_desc = &wks->rss_desc;
14574 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
14575 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
14576 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14577 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14578 : : /* update normal path action resource into last index of array */
14579 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
14580 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
14581 [ # # ]: 0 : if (dev_flow->tunnel) {
14582 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
14583 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
14584 : : tunnel = dev_flow->tunnel;
14585 : : } else {
14586 : 0 : tunnel = mlx5_get_tof(items, actions,
14587 : : &dev_flow->tof_type);
14588 : 0 : dev_flow->tunnel = tunnel;
14589 : : }
14590 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
14591 : : (dev, attr, tunnel, dev_flow->tof_type);
14592 : : }
14593 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14594 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14595 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
14596 : : &grp_info, error);
14597 [ # # ]: 0 : if (ret)
14598 : : return ret;
14599 : 0 : dev_flow->dv.group = table;
14600 [ # # ]: 0 : if (attr->transfer)
14601 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
14602 : : /* number of actions must be set to 0 in case of dirty stack. */
14603 : 0 : mhdr_res->actions_num = 0;
14604 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
14605 : : /*
14606 : : * do not add decap action if match rule drops packet
14607 : : * HW rejects rules with decap & drop
14608 : : *
14609 : : * if tunnel match rule was inserted before matching tunnel set
14610 : : * rule flow table used in the match rule must be registered.
14611 : : * current implementation handles that in the
14612 : : * flow_dv_match_register() at the function end.
14613 : : */
14614 : : bool add_decap = true;
14615 : : const struct rte_flow_action *ptr = actions;
14616 : :
14617 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
14618 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
14619 : : add_decap = false;
14620 : : break;
14621 : : }
14622 : : }
14623 [ # # ]: 0 : if (add_decap) {
14624 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
14625 : 0 : attr->transfer,
14626 : : error))
14627 : 0 : return -rte_errno;
14628 : 0 : dev_flow->dv.actions[actions_n++] =
14629 : 0 : dev_flow->dv.encap_decap->action;
14630 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
14631 : : }
14632 : : }
14633 [ # # ]: 0 : for (; !actions_end ; actions++) {
14634 : : const struct rte_flow_action_queue *queue;
14635 : : const struct rte_flow_action_rss *rss;
14636 : : const struct rte_flow_action *action = actions;
14637 : : const uint8_t *rss_key;
14638 : : struct mlx5_flow_tbl_resource *tbl;
14639 : : struct mlx5_aso_age_action *age_act;
14640 : : struct mlx5_flow_counter *cnt_act;
14641 : 0 : uint32_t port_id = 0;
14642 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
14643 : 0 : int action_type = actions->type;
14644 : : const struct rte_flow_action *found_action = NULL;
14645 : : uint32_t jump_group = 0;
14646 : : uint32_t owner_idx;
14647 : : struct mlx5_aso_ct_action *ct;
14648 : :
14649 : : if (!mlx5_flow_os_action_supported(action_type))
14650 : 0 : return rte_flow_error_set(error, ENOTSUP,
14651 : : RTE_FLOW_ERROR_TYPE_ACTION,
14652 : : actions,
14653 : : "action not supported");
14654 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14655 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
14656 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
14657 : 0 : break;
14658 : : case RTE_FLOW_ACTION_TYPE_VOID:
14659 : : break;
14660 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
14661 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14662 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
14663 : : &port_id, error))
14664 : 0 : return -rte_errno;
14665 : 0 : port_id_resource.port_id = port_id;
14666 : : MLX5_ASSERT(!handle->rix_port_id_action);
14667 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
14668 : : (dev, &port_id_resource, dev_flow, error))
14669 : 0 : return -rte_errno;
14670 : 0 : dev_flow->dv.actions[actions_n++] =
14671 : 0 : dev_flow->dv.port_id_action->action;
14672 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
14673 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
14674 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
14675 : 0 : num_of_dest++;
14676 : 0 : break;
14677 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
14678 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
14679 : 0 : wks->mark = 1;
14680 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
14681 : 0 : struct rte_flow_action_mark mark = {
14682 : : .id = MLX5_FLOW_MARK_DEFAULT,
14683 : : };
14684 : :
14685 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
14686 : : mhdr_res,
14687 : : error))
14688 : 0 : return -rte_errno;
14689 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
14690 : 0 : break;
14691 : : }
14692 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
14693 : : /*
14694 : : * Only one FLAG or MARK is supported per device flow
14695 : : * right now. So the pointer to the tag resource must be
14696 : : * zero before the register process.
14697 : : */
14698 : : MLX5_ASSERT(!handle->dvh.rix_tag);
14699 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
14700 : : dev_flow, error))
14701 : 0 : return -rte_errno;
14702 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
14703 : 0 : dev_flow->dv.actions[actions_n++] =
14704 : 0 : dev_flow->dv.tag_resource->action;
14705 : 0 : break;
14706 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
14707 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
14708 : 0 : wks->mark = 1;
14709 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
14710 : 0 : const struct rte_flow_action_mark *mark =
14711 : : (const struct rte_flow_action_mark *)
14712 : : actions->conf;
14713 : :
14714 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
14715 : : mhdr_res,
14716 : : error))
14717 : 0 : return -rte_errno;
14718 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
14719 : 0 : break;
14720 : : }
14721 : : /* Fall-through */
14722 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
14723 : : /* Legacy (non-extensive) MARK action. */
14724 : : tag_be = mlx5_flow_mark_set
14725 : : (((const struct rte_flow_action_mark *)
14726 [ # # ]: 0 : (actions->conf))->id);
14727 : : MLX5_ASSERT(!handle->dvh.rix_tag);
14728 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
14729 : : dev_flow, error))
14730 : 0 : return -rte_errno;
14731 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
14732 : 0 : dev_flow->dv.actions[actions_n++] =
14733 : 0 : dev_flow->dv.tag_resource->action;
14734 : 0 : break;
14735 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
14736 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
14737 : : (dev, mhdr_res, attr,
14738 : : (const struct rte_flow_action_set_meta *)
14739 : 0 : actions->conf, error))
14740 : 0 : return -rte_errno;
14741 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
14742 : 0 : break;
14743 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
14744 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
14745 : : (dev, mhdr_res,
14746 : : (const struct rte_flow_action_set_tag *)
14747 : 0 : actions->conf, error))
14748 : 0 : return -rte_errno;
14749 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14750 : 0 : break;
14751 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
14752 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
14753 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
14754 : 0 : break;
14755 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
14756 : 0 : queue = actions->conf;
14757 : 0 : rss_desc->queue_num = 1;
14758 : 0 : rss_desc->queue[0] = queue->index;
14759 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
14760 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
14761 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
14762 : 0 : num_of_dest++;
14763 : 0 : break;
14764 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
14765 : 0 : rss = actions->conf;
14766 : 0 : rss_desc->symmetric_hash_function =
14767 : 0 : MLX5_RSS_IS_SYMM(rss->func);
14768 : 0 : memcpy(rss_desc->queue, rss->queue,
14769 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
14770 : 0 : rss_desc->queue_num = rss->queue_num;
14771 : : /* NULL RSS key indicates default RSS key. */
14772 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
14773 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14774 : : /*
14775 : : * rss->level and rss.types should be set in advance
14776 : : * when expanding items for RSS.
14777 : : */
14778 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
14779 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
14780 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
14781 : : MLX5_FLOW_FATE_QUEUE;
14782 : 0 : break;
14783 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
14784 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
14785 : 0 : age_act = flow_aso_age_get_by_idx(dev, owner_idx);
14786 [ # # ]: 0 : if (flow->age == 0) {
14787 : 0 : flow->age = owner_idx;
14788 : 0 : __atomic_fetch_add(&age_act->refcnt, 1,
14789 : : __ATOMIC_RELAXED);
14790 : : }
14791 : 0 : age_act_pos = actions_n++;
14792 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
14793 : 0 : break;
14794 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
14795 : 0 : dev_flow->dv.actions[actions_n] =
14796 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
14797 : : error);
14798 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
14799 : 0 : return -rte_errno;
14800 : 0 : actions_n++;
14801 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
14802 : 0 : dev_flow->handle->fate_action =
14803 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
14804 : 0 : break;
14805 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
14806 : 0 : non_shared_age = action->conf;
14807 : 0 : age_act_pos = actions_n++;
14808 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
14809 : 0 : break;
14810 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
14811 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
14812 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
14813 : : NULL);
14814 : : MLX5_ASSERT(cnt_act != NULL);
14815 : : /**
14816 : : * When creating meter drop flow in drop table, the
14817 : : * counter should not overwrite the rte flow counter.
14818 : : */
14819 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
14820 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
14821 : 0 : dev_flow->dv.actions[actions_n++] =
14822 : 0 : cnt_act->action;
14823 : : } else {
14824 [ # # ]: 0 : if (flow->counter == 0) {
14825 : 0 : flow->counter = owner_idx;
14826 : 0 : __atomic_fetch_add
14827 : 0 : (&cnt_act->shared_info.refcnt,
14828 : : 1, __ATOMIC_RELAXED);
14829 : : }
14830 : : /* Save information first, will apply later. */
14831 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
14832 : : }
14833 : : break;
14834 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
14835 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14836 : 0 : return rte_flow_error_set
14837 : : (error, ENOTSUP,
14838 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14839 : : NULL,
14840 : : "count action not supported");
14841 : : }
14842 : : /* Save information first, will apply later. */
14843 : 0 : count = action->conf;
14844 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
14845 : 0 : break;
14846 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
14847 : 0 : dev_flow->dv.actions[actions_n++] =
14848 : 0 : priv->sh->pop_vlan_action;
14849 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
14850 : 0 : break;
14851 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
14852 [ # # ]: 0 : if (!(action_flags &
14853 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
14854 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
14855 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
14856 : : ((((const struct rte_flow_action_of_push_vlan *)
14857 : : actions->conf)->ethertype));
14858 : 0 : found_action = mlx5_flow_find_action
14859 : : (actions + 1,
14860 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
14861 [ # # ]: 0 : if (found_action)
14862 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
14863 : 0 : found_action = mlx5_flow_find_action
14864 : : (actions + 1,
14865 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
14866 [ # # ]: 0 : if (found_action)
14867 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
14868 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
14869 : : (dev, attr, &vlan, dev_flow, error))
14870 : 0 : return -rte_errno;
14871 : 0 : dev_flow->dv.actions[actions_n++] =
14872 : 0 : dev_flow->dv.push_vlan_res->action;
14873 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
14874 : 0 : break;
14875 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
14876 : : /* of_vlan_push action handled this action */
14877 : : MLX5_ASSERT(action_flags &
14878 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
14879 : : break;
14880 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
14881 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
14882 : : break;
14883 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
14884 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
14885 : : /* If no VLAN push - this is a modify header action */
14886 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
14887 : : (mhdr_res, actions, error))
14888 : 0 : return -rte_errno;
14889 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
14890 : 0 : break;
14891 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14892 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14893 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
14894 : : dev_flow,
14895 : 0 : attr->transfer,
14896 : : error))
14897 : 0 : return -rte_errno;
14898 : 0 : dev_flow->dv.actions[actions_n++] =
14899 : 0 : dev_flow->dv.encap_decap->action;
14900 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
14901 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
14902 : 0 : sample_act->action_flags |=
14903 : : MLX5_FLOW_ACTION_ENCAP;
14904 : : break;
14905 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
14906 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
14907 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
14908 : 0 : attr->transfer,
14909 : : error))
14910 : 0 : return -rte_errno;
14911 : 0 : dev_flow->dv.actions[actions_n++] =
14912 : 0 : dev_flow->dv.encap_decap->action;
14913 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
14914 : 0 : break;
14915 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14916 : : /* Handle encap with preceding decap. */
14917 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
14918 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
14919 : : (dev, actions, dev_flow, attr, error))
14920 : 0 : return -rte_errno;
14921 : 0 : dev_flow->dv.actions[actions_n++] =
14922 : 0 : dev_flow->dv.encap_decap->action;
14923 : : } else {
14924 : : /* Handle encap without preceding decap. */
14925 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
14926 : 0 : (dev, actions, dev_flow, attr->transfer,
14927 : : error))
14928 : 0 : return -rte_errno;
14929 : 0 : dev_flow->dv.actions[actions_n++] =
14930 : 0 : dev_flow->dv.encap_decap->action;
14931 : : }
14932 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
14933 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
14934 : 0 : sample_act->action_flags |=
14935 : : MLX5_FLOW_ACTION_ENCAP;
14936 : : break;
14937 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14938 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
14939 : : ;
14940 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
14941 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
14942 : 0 : (dev, dev_flow, attr->transfer, error))
14943 : 0 : return -rte_errno;
14944 : 0 : dev_flow->dv.actions[actions_n++] =
14945 : 0 : dev_flow->dv.encap_decap->action;
14946 : : }
14947 : : /* If decap is followed by encap, handle it at encap. */
14948 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
14949 : 0 : break;
14950 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
14951 : 0 : dev_flow->dv.actions[actions_n++] =
14952 : 0 : (void *)(uintptr_t)action->conf;
14953 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
14954 : 0 : break;
14955 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
14956 : 0 : jump_group = ((const struct rte_flow_action_jump *)
14957 : 0 : action->conf)->group;
14958 : 0 : grp_info.std_tbl_fix = 0;
14959 [ # # ]: 0 : if (dev_flow->skip_scale &
14960 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
14961 : 0 : grp_info.skip_scale = 1;
14962 : : else
14963 : 0 : grp_info.skip_scale = 0;
14964 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
14965 : : jump_group,
14966 : : &table,
14967 : : &grp_info, error);
14968 [ # # ]: 0 : if (ret)
14969 : 0 : return ret;
14970 : 0 : tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
14971 : 0 : attr->transfer,
14972 : 0 : !!dev_flow->external,
14973 : : tunnel, jump_group, 0,
14974 : : 0, error);
14975 [ # # ]: 0 : if (!tbl)
14976 : 0 : return rte_flow_error_set
14977 : 0 : (error, errno,
14978 : : RTE_FLOW_ERROR_TYPE_ACTION,
14979 : : NULL,
14980 : : "cannot create jump action.");
14981 : : if (flow_dv_jump_tbl_resource_register
14982 : : (dev, tbl, dev_flow, error)) {
14983 : : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
14984 : : return rte_flow_error_set
14985 : : (error, errno,
14986 : : RTE_FLOW_ERROR_TYPE_ACTION,
14987 : : NULL,
14988 : : "cannot create jump action.");
14989 : : }
14990 : 0 : dev_flow->dv.actions[actions_n++] =
14991 : 0 : dev_flow->dv.jump->action;
14992 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
14993 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
14994 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
14995 : 0 : num_of_dest++;
14996 : 0 : break;
14997 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
14998 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
14999 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15000 : : (mhdr_res, actions, error))
15001 : 0 : return -rte_errno;
15002 : 0 : action_flags |= actions->type ==
15003 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15004 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15005 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15006 : 0 : break;
15007 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15008 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15009 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15010 : : (mhdr_res, actions, error))
15011 : 0 : return -rte_errno;
15012 : 0 : action_flags |= actions->type ==
15013 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15014 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15015 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15016 : 0 : break;
15017 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15018 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15019 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15020 : : (mhdr_res, actions, error))
15021 : 0 : return -rte_errno;
15022 : 0 : action_flags |= actions->type ==
15023 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15024 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15025 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15026 : 0 : break;
15027 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15028 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15029 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15030 : : (mhdr_res, actions, items,
15031 : 0 : &flow_attr, dev_flow, !!(action_flags &
15032 : : MLX5_FLOW_ACTION_DECAP), error))
15033 : 0 : return -rte_errno;
15034 : 0 : action_flags |= actions->type ==
15035 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15036 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15037 : : MLX5_FLOW_ACTION_SET_TP_DST;
15038 : 0 : break;
15039 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15040 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15041 : : (mhdr_res, items, &flow_attr, dev_flow,
15042 : 0 : !!(action_flags &
15043 : : MLX5_FLOW_ACTION_DECAP), error))
15044 : 0 : return -rte_errno;
15045 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15046 : 0 : break;
15047 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15048 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15049 : : (mhdr_res, actions, items, &flow_attr,
15050 : 0 : dev_flow, !!(action_flags &
15051 : : MLX5_FLOW_ACTION_DECAP), error))
15052 : 0 : return -rte_errno;
15053 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15054 : 0 : break;
15055 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15056 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15057 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15058 : : (mhdr_res, actions, error))
15059 : 0 : return -rte_errno;
15060 : 0 : action_flags |= actions->type ==
15061 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15062 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15063 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15064 : 0 : break;
15065 : :
15066 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15067 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15068 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15069 : : (mhdr_res, actions, error))
15070 : 0 : return -rte_errno;
15071 : 0 : action_flags |= actions->type ==
15072 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15073 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15074 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15075 : 0 : break;
15076 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15077 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15078 : : (mhdr_res, actions, error))
15079 : 0 : return -rte_errno;
15080 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15081 : 0 : break;
15082 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15083 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15084 : : (dev, mhdr_res, actions, error))
15085 : 0 : return -rte_errno;
15086 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15087 : 0 : break;
15088 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15089 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15090 : 0 : dev_flow->handle->fate_action =
15091 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15092 : 0 : break;
15093 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15094 [ # # ]: 0 : if (!wks->fm)
15095 : 0 : return rte_flow_error_set(error, rte_errno,
15096 : : RTE_FLOW_ERROR_TYPE_ACTION,
15097 : : NULL, "Failed to get meter in flow.");
15098 : : /* Set the meter action. */
15099 : 0 : dev_flow->dv.actions[actions_n++] =
15100 : 0 : wks->fm->meter_action_g;
15101 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15102 : 0 : break;
15103 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15104 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15105 : : actions, error))
15106 : 0 : return -rte_errno;
15107 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15108 : 0 : break;
15109 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15110 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15111 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15112 : : else
15113 : : ipv6_tc_off = 0;
15114 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15115 : : actions, ipv6_tc_off, error))
15116 : 0 : return -rte_errno;
15117 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15118 : 0 : break;
15119 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15120 : 0 : sample_act_pos = actions_n;
15121 : 0 : sample = (const struct rte_flow_action_sample *)
15122 : : action->conf;
15123 : 0 : actions_n++;
15124 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15125 : : /* put encap action into group if work with port id */
15126 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15127 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15128 : 0 : sample_act->action_flags |=
15129 : : MLX5_FLOW_ACTION_ENCAP;
15130 : : break;
15131 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15132 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15133 : : (dev, mhdr_res, actions, attr, error))
15134 : 0 : return -rte_errno;
15135 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15136 : 0 : break;
15137 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15138 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15139 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15140 [ # # ]: 0 : if (!ct)
15141 : 0 : return rte_flow_error_set(error, EINVAL,
15142 : : RTE_FLOW_ERROR_TYPE_ACTION,
15143 : : NULL,
15144 : : "Failed to get CT object.");
15145 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15146 : 0 : return rte_flow_error_set(error, rte_errno,
15147 : : RTE_FLOW_ERROR_TYPE_ACTION,
15148 : : NULL,
15149 : : "CT is unavailable.");
15150 [ # # ]: 0 : if (ct->is_original)
15151 : 0 : dev_flow->dv.actions[actions_n] =
15152 : 0 : ct->dr_action_orig;
15153 : : else
15154 : 0 : dev_flow->dv.actions[actions_n] =
15155 : 0 : ct->dr_action_rply;
15156 [ # # ]: 0 : if (flow->ct == 0) {
15157 : 0 : flow->indirect_type =
15158 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15159 : 0 : flow->ct = owner_idx;
15160 : 0 : __atomic_fetch_add(&ct->refcnt, 1,
15161 : : __ATOMIC_RELAXED);
15162 : : }
15163 : 0 : actions_n++;
15164 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15165 : 0 : break;
15166 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15167 : : actions_end = true;
15168 [ # # ]: 0 : if (mhdr_res->actions_num) {
15169 : : /* create modify action if needed. */
15170 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15171 : : (dev, mhdr_res, dev_flow, error))
15172 : 0 : return -rte_errno;
15173 : 0 : dev_flow->dv.actions[modify_action_position] =
15174 : 0 : handle->dvh.modify_hdr->action;
15175 : : }
15176 : : /*
15177 : : * Handle AGE and COUNT action by single HW counter
15178 : : * when they are not shared.
15179 : : */
15180 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15181 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15182 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15183 : : /* Creates age by counters. */
15184 : 0 : cnt_act = flow_dv_prepare_counter
15185 : : (dev, dev_flow,
15186 : : flow, count,
15187 : : non_shared_age,
15188 : : error);
15189 [ # # ]: 0 : if (!cnt_act)
15190 : 0 : return -rte_errno;
15191 : 0 : dev_flow->dv.actions[age_act_pos] =
15192 : 0 : cnt_act->action;
15193 : 0 : break;
15194 : : }
15195 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15196 : 0 : flow->age = flow_dv_aso_age_alloc
15197 : : (dev, error);
15198 [ # # ]: 0 : if (!flow->age)
15199 : 0 : return -rte_errno;
15200 : 0 : flow_dv_aso_age_params_init
15201 : : (dev, flow->age,
15202 : 0 : non_shared_age->context ?
15203 : : non_shared_age->context :
15204 : 0 : (void *)(uintptr_t)
15205 : 0 : (dev_flow->flow_idx),
15206 [ # # ]: 0 : non_shared_age->timeout);
15207 : : }
15208 : 0 : age_act = flow_aso_age_get_by_idx(dev,
15209 : : flow->age);
15210 : 0 : dev_flow->dv.actions[age_act_pos] =
15211 : 0 : age_act->dr_action;
15212 : : }
15213 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15214 : : /*
15215 : : * Create one count action, to be used
15216 : : * by all sub-flows.
15217 : : */
15218 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15219 : : flow, count,
15220 : : NULL, error);
15221 [ # # ]: 0 : if (!cnt_act)
15222 : 0 : return -rte_errno;
15223 : 0 : dev_flow->dv.actions[actions_n++] =
15224 : 0 : cnt_act->action;
15225 : : }
15226 : : default:
15227 : : break;
15228 : : }
15229 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15230 : : modify_action_position == UINT32_MAX)
15231 : 0 : modify_action_position = actions_n++;
15232 : : }
15233 : 0 : dev_flow->act_flags = action_flags;
15234 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15235 : : error);
15236 [ # # ]: 0 : if (ret)
15237 : 0 : return -rte_errno;
15238 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15239 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15240 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
15241 : : rss_desc,
15242 : : &dev_flow->hash_fields);
15243 : : }
15244 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15245 : : * should be registered after the hash filed be update.
15246 : : */
15247 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15248 : 0 : ret = flow_dv_translate_action_sample(dev,
15249 : : sample,
15250 : : dev_flow, attr,
15251 : : &num_of_dest,
15252 : : sample_actions,
15253 : : &sample_res,
15254 : : error);
15255 [ # # ]: 0 : if (ret < 0)
15256 : : return ret;
15257 : 0 : ret = flow_dv_create_action_sample(dev,
15258 : : dev_flow,
15259 : : num_of_dest,
15260 : : &sample_res,
15261 : : &mdest_res,
15262 : : sample_actions,
15263 : : action_flags,
15264 : : error);
15265 [ # # ]: 0 : if (ret < 0)
15266 : 0 : return rte_flow_error_set
15267 : : (error, rte_errno,
15268 : : RTE_FLOW_ERROR_TYPE_ACTION,
15269 : : NULL,
15270 : : "cannot create sample action");
15271 [ # # ]: 0 : if (num_of_dest > 1) {
15272 : 0 : dev_flow->dv.actions[sample_act_pos] =
15273 : 0 : dev_flow->dv.dest_array_res->action;
15274 : : } else {
15275 : 0 : dev_flow->dv.actions[sample_act_pos] =
15276 : 0 : dev_flow->dv.sample_res->verbs_action;
15277 : : }
15278 : : }
15279 : : /*
15280 : : * For multiple destination (sample action with ratio=1), the encap
15281 : : * action and port id action will be combined into group action.
15282 : : * So need remove the original these actions in the flow and only
15283 : : * use the sample action instead of.
15284 : : */
15285 [ # # ]: 0 : if (num_of_dest > 1 &&
15286 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15287 : : int i;
15288 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15289 : :
15290 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15291 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15292 : : sample_act->dr_encap_action ==
15293 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15294 : 0 : (sample_act->dr_port_id_action &&
15295 : : sample_act->dr_port_id_action ==
15296 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15297 [ # # ]: 0 : (sample_act->dr_jump_action &&
15298 : : sample_act->dr_jump_action ==
15299 [ # # ]: 0 : dev_flow->dv.actions[i]))
15300 : 0 : continue;
15301 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15302 : : }
15303 : 0 : memcpy((void *)dev_flow->dv.actions,
15304 : : (void *)temp_actions,
15305 : : tmp_actions_n * sizeof(void *));
15306 : : actions_n = tmp_actions_n;
15307 : : }
15308 : 0 : dev_flow->dv.actions_n = actions_n;
15309 [ # # ]: 0 : if (wks->skip_matcher_reg)
15310 : : return 0;
15311 : : /* Register matcher. */
15312 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15313 : : matcher.mask.size);
15314 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15315 : 0 : matcher.priority,
15316 : 0 : dev_flow->external);
15317 : : /**
15318 : : * When creating meter drop flow in drop table, using original
15319 : : * 5-tuple match, the matcher priority should be lower than
15320 : : * mtr_id matcher.
15321 : : */
15322 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15323 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15324 : : matcher.priority <= MLX5_REG_BITS)
15325 : 0 : matcher.priority += MLX5_REG_BITS;
15326 : : /* reserved field no needs to be set to 0 here. */
15327 : 0 : tbl_key.is_fdb = attr->transfer;
15328 : 0 : tbl_key.is_egress = attr->egress;
15329 : 0 : tbl_key.level = dev_flow->dv.group;
15330 : 0 : tbl_key.id = dev_flow->dv.table_id;
15331 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15332 : : tunnel, attr->group, error))
15333 : 0 : return -rte_errno;
15334 : : return 0;
15335 : : }
15336 : :
15337 : : /**
15338 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15339 : : * and tunnel.
15340 : : *
15341 : : * @param[in, out] action
15342 : : * Shred RSS action holding hash RX queue objects.
15343 : : * @param[in] hash_fields
15344 : : * Defines combination of packet fields to participate in RX hash.
15345 : : * @param[in] tunnel
15346 : : * Tunnel type
15347 : : * @param[in] hrxq_idx
15348 : : * Hash RX queue index to set.
15349 : : *
15350 : : * @return
15351 : : * 0 on success, otherwise negative errno value.
15352 : : */
15353 : : static int
15354 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
15355 : : const uint64_t hash_fields,
15356 : : uint32_t hrxq_idx)
15357 : : {
15358 : : uint32_t *hrxqs = action->hrxq;
15359 : :
15360 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15361 : 0 : case MLX5_RSS_HASH_IPV4:
15362 : : /* fall-through. */
15363 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15364 : : /* fall-through. */
15365 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15366 : 0 : hrxqs[0] = hrxq_idx;
15367 : 0 : return 0;
15368 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15369 : : /* fall-through. */
15370 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15371 : : /* fall-through. */
15372 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15373 : 0 : hrxqs[1] = hrxq_idx;
15374 : 0 : return 0;
15375 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15376 : : /* fall-through. */
15377 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15378 : : /* fall-through. */
15379 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15380 : 0 : hrxqs[2] = hrxq_idx;
15381 : 0 : return 0;
15382 : 0 : case MLX5_RSS_HASH_IPV6:
15383 : : /* fall-through. */
15384 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15385 : : /* fall-through. */
15386 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15387 : 0 : hrxqs[3] = hrxq_idx;
15388 : 0 : return 0;
15389 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15390 : : /* fall-through. */
15391 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15392 : : /* fall-through. */
15393 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15394 : 0 : hrxqs[4] = hrxq_idx;
15395 : 0 : return 0;
15396 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15397 : : /* fall-through. */
15398 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15399 : : /* fall-through. */
15400 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15401 : 0 : hrxqs[5] = hrxq_idx;
15402 : 0 : return 0;
15403 : 0 : case MLX5_RSS_HASH_NONE:
15404 : 0 : hrxqs[6] = hrxq_idx;
15405 : 0 : return 0;
15406 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15407 : 0 : hrxqs[7] = hrxq_idx;
15408 : 0 : return 0;
15409 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15410 : 0 : hrxqs[8] = hrxq_idx;
15411 : 0 : return 0;
15412 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15413 : 0 : hrxqs[9] = hrxq_idx;
15414 : 0 : return 0;
15415 : : default:
15416 : : return -1;
15417 : : }
15418 : : }
15419 : :
15420 : : /**
15421 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15422 : : * and tunnel.
15423 : : *
15424 : : * @param[in] dev
15425 : : * Pointer to the Ethernet device structure.
15426 : : * @param[in] idx
15427 : : * Shared RSS action ID holding hash RX queue objects.
15428 : : * @param[in] hash_fields
15429 : : * Defines combination of packet fields to participate in RX hash.
15430 : : * @param[in] tunnel
15431 : : * Tunnel type
15432 : : *
15433 : : * @return
15434 : : * Valid hash RX queue index, otherwise 0.
15435 : : */
15436 : : uint32_t
15437 : 0 : flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
15438 : : const uint64_t hash_fields)
15439 : : {
15440 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15441 : : struct mlx5_shared_action_rss *shared_rss =
15442 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15443 : : const uint32_t *hrxqs = shared_rss->hrxq;
15444 : :
15445 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15446 : 0 : case MLX5_RSS_HASH_IPV4:
15447 : : /* fall-through. */
15448 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15449 : : /* fall-through. */
15450 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15451 : 0 : return hrxqs[0];
15452 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15453 : : /* fall-through. */
15454 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15455 : : /* fall-through. */
15456 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15457 : 0 : return hrxqs[1];
15458 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15459 : : /* fall-through. */
15460 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15461 : : /* fall-through. */
15462 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15463 : 0 : return hrxqs[2];
15464 : 0 : case MLX5_RSS_HASH_IPV6:
15465 : : /* fall-through. */
15466 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15467 : : /* fall-through. */
15468 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15469 : 0 : return hrxqs[3];
15470 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15471 : : /* fall-through. */
15472 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15473 : : /* fall-through. */
15474 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15475 : 0 : return hrxqs[4];
15476 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15477 : : /* fall-through. */
15478 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15479 : : /* fall-through. */
15480 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15481 : 0 : return hrxqs[5];
15482 : 0 : case MLX5_RSS_HASH_NONE:
15483 : 0 : return hrxqs[6];
15484 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15485 : 0 : return hrxqs[7];
15486 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15487 : 0 : return hrxqs[8];
15488 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15489 : 0 : return hrxqs[9];
15490 : : default:
15491 : : return 0;
15492 : : }
15493 : :
15494 : : }
15495 : :
15496 : : /**
15497 : : * Apply the flow to the NIC, lock free,
15498 : : * (mutex should be acquired by caller).
15499 : : *
15500 : : * @param[in] dev
15501 : : * Pointer to the Ethernet device structure.
15502 : : * @param[in, out] flow
15503 : : * Pointer to flow structure.
15504 : : * @param[out] error
15505 : : * Pointer to error structure.
15506 : : *
15507 : : * @return
15508 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15509 : : */
15510 : : static int
15511 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
15512 : : struct rte_flow_error *error)
15513 : : {
15514 : : struct mlx5_flow_dv_workspace *dv;
15515 : : struct mlx5_flow_handle *dh;
15516 : : struct mlx5_flow_handle_dv *dv_h;
15517 : : struct mlx5_flow *dev_flow;
15518 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15519 : : uint32_t handle_idx;
15520 : : int n;
15521 : : int err;
15522 : : int idx;
15523 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15524 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
15525 : : uint8_t misc_mask;
15526 : :
15527 : : MLX5_ASSERT(wks);
15528 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
15529 : 0 : dev_flow = &wks->flows[idx];
15530 : : dv = &dev_flow->dv;
15531 : 0 : dh = dev_flow->handle;
15532 : : dv_h = &dh->dvh;
15533 : 0 : n = dv->actions_n;
15534 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
15535 [ # # ]: 0 : if (dv->transfer) {
15536 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15537 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
15538 : : } else {
15539 : : #ifdef HAVE_MLX5DV_DR
15540 : : /* DR supports drop action placeholder. */
15541 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15542 : 0 : dv->actions[n++] = dv->group ?
15543 [ # # ]: 0 : priv->sh->dr_drop_action :
15544 : : priv->root_drop_action;
15545 : : #else
15546 : : /* For DV we use the explicit drop queue. */
15547 : : MLX5_ASSERT(priv->drop_queue.hrxq);
15548 : : dv->actions[n++] =
15549 : : priv->drop_queue.hrxq->action;
15550 : : #endif
15551 : : }
15552 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
15553 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
15554 : : struct mlx5_hrxq *hrxq;
15555 : : uint32_t hrxq_idx;
15556 : :
15557 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
15558 : : &hrxq_idx);
15559 [ # # ]: 0 : if (!hrxq) {
15560 : 0 : rte_flow_error_set
15561 : : (error, rte_errno,
15562 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15563 : : "cannot get hash queue");
15564 : 0 : goto error;
15565 : : }
15566 : 0 : dh->rix_hrxq = hrxq_idx;
15567 : 0 : dv->actions[n++] = hrxq->action;
15568 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
15569 : : struct mlx5_hrxq *hrxq = NULL;
15570 : : uint32_t hrxq_idx;
15571 : :
15572 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
15573 : : rss_desc->shared_rss,
15574 : : dev_flow->hash_fields);
15575 [ # # ]: 0 : if (hrxq_idx)
15576 : 0 : hrxq = mlx5_ipool_get
15577 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
15578 : : hrxq_idx);
15579 [ # # ]: 0 : if (!hrxq) {
15580 : 0 : rte_flow_error_set
15581 : : (error, rte_errno,
15582 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15583 : : "cannot get hash queue");
15584 : 0 : goto error;
15585 : : }
15586 : 0 : dh->rix_srss = rss_desc->shared_rss;
15587 : 0 : dv->actions[n++] = hrxq->action;
15588 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
15589 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
15590 : 0 : rte_flow_error_set
15591 : : (error, rte_errno,
15592 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15593 : : "default miss action not be created.");
15594 : 0 : goto error;
15595 : : }
15596 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
15597 : : }
15598 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
15599 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
15600 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
15601 : 0 : (void *)&dv->value, n,
15602 : 0 : dv->actions, &dh->drv_flow);
15603 : : if (err) {
15604 : 0 : rte_flow_error_set
15605 : 0 : (error, errno,
15606 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15607 : : NULL,
15608 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
15609 [ # # ]: 0 : errno == EEXIST) ?
15610 : : "duplicating pattern is not allowed" :
15611 : : "hardware refuses to create flow");
15612 : 0 : goto error;
15613 : : }
15614 [ # # ]: 0 : if (priv->vmwa_context &&
15615 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
15616 : : /*
15617 : : * The rule contains the VLAN pattern.
15618 : : * For VF we are going to create VLAN
15619 : : * interface to make hypervisor set correct
15620 : : * e-Switch vport context.
15621 : : */
15622 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
15623 : : }
15624 : : }
15625 : : return 0;
15626 : 0 : error:
15627 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
15628 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
15629 : : handle_idx, dh, next) {
15630 : : /* hrxq is union, don't clear it if the flag is not set. */
15631 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
15632 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
15633 : 0 : dh->rix_hrxq = 0;
15634 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
15635 : 0 : dh->rix_srss = 0;
15636 : : }
15637 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
15638 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
15639 : : }
15640 : 0 : rte_errno = err; /* Restore rte_errno. */
15641 : 0 : return -rte_errno;
15642 : : }
15643 : :
15644 : : void
15645 : 0 : flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
15646 : : struct mlx5_list_entry *entry)
15647 : : {
15648 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
15649 : : typeof(*resource),
15650 : : entry);
15651 : :
15652 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
15653 : 0 : mlx5_free(resource);
15654 : 0 : }
15655 : :
15656 : : /**
15657 : : * Release the flow matcher.
15658 : : *
15659 : : * @param dev
15660 : : * Pointer to Ethernet device.
15661 : : * @param port_id
15662 : : * Index to port ID action resource.
15663 : : *
15664 : : * @return
15665 : : * 1 while a reference on it exists, 0 when freed.
15666 : : */
15667 : : static int
15668 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
15669 : : struct mlx5_flow_handle *handle)
15670 : : {
15671 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
15672 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
15673 : : typeof(*tbl), tbl);
15674 : : int ret;
15675 : :
15676 : : MLX5_ASSERT(matcher->matcher_object);
15677 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
15678 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
15679 : 0 : return ret;
15680 : : }
15681 : :
15682 : : void
15683 : 0 : flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15684 : : {
15685 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15686 : : struct mlx5_flow_dv_encap_decap_resource *res =
15687 : : container_of(entry, typeof(*res), entry);
15688 : :
15689 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
15690 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
15691 : 0 : }
15692 : :
15693 : : /**
15694 : : * Release an encap/decap resource.
15695 : : *
15696 : : * @param dev
15697 : : * Pointer to Ethernet device.
15698 : : * @param encap_decap_idx
15699 : : * Index of encap decap resource.
15700 : : *
15701 : : * @return
15702 : : * 1 while a reference on it exists, 0 when freed.
15703 : : */
15704 : : static int
15705 : 0 : flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
15706 : : uint32_t encap_decap_idx)
15707 : : {
15708 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15709 : : struct mlx5_flow_dv_encap_decap_resource *resource;
15710 : :
15711 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
15712 : : encap_decap_idx);
15713 [ # # ]: 0 : if (!resource)
15714 : : return 0;
15715 : : MLX5_ASSERT(resource->action);
15716 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
15717 : : }
15718 : :
15719 : : /**
15720 : : * Release an jump to table action resource.
15721 : : *
15722 : : * @param dev
15723 : : * Pointer to Ethernet device.
15724 : : * @param rix_jump
15725 : : * Index to the jump action resource.
15726 : : *
15727 : : * @return
15728 : : * 1 while a reference on it exists, 0 when freed.
15729 : : */
15730 : : static int
15731 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
15732 : : uint32_t rix_jump)
15733 : : {
15734 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15735 : : struct mlx5_flow_tbl_data_entry *tbl_data;
15736 : :
15737 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
15738 : : rix_jump);
15739 [ # # ]: 0 : if (!tbl_data)
15740 : : return 0;
15741 : 0 : return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
15742 : : }
15743 : :
15744 : : void
15745 : 0 : flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15746 : : {
15747 : : struct mlx5_flow_dv_modify_hdr_resource *res =
15748 : : container_of(entry, typeof(*res), entry);
15749 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15750 : :
15751 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
15752 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
15753 : 0 : }
15754 : :
15755 : : /**
15756 : : * Release a modify-header resource.
15757 : : *
15758 : : * @param dev
15759 : : * Pointer to Ethernet device.
15760 : : * @param handle
15761 : : * Pointer to mlx5_flow_handle.
15762 : : *
15763 : : * @return
15764 : : * 1 while a reference on it exists, 0 when freed.
15765 : : */
15766 : : static int
15767 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
15768 : : struct mlx5_flow_handle *handle)
15769 : : {
15770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15771 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
15772 : :
15773 : : MLX5_ASSERT(entry->action);
15774 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
15775 : : }
15776 : :
15777 : : void
15778 : 0 : flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15779 : : {
15780 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15781 : : struct mlx5_flow_dv_port_id_action_resource *resource =
15782 : : container_of(entry, typeof(*resource), entry);
15783 : :
15784 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
15785 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
15786 : 0 : }
15787 : :
15788 : : /**
15789 : : * Release port ID action resource.
15790 : : *
15791 : : * @param dev
15792 : : * Pointer to Ethernet device.
15793 : : * @param handle
15794 : : * Pointer to mlx5_flow_handle.
15795 : : *
15796 : : * @return
15797 : : * 1 while a reference on it exists, 0 when freed.
15798 : : */
15799 : : static int
15800 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
15801 : : uint32_t port_id)
15802 : : {
15803 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15804 : : struct mlx5_flow_dv_port_id_action_resource *resource;
15805 : :
15806 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
15807 [ # # ]: 0 : if (!resource)
15808 : : return 0;
15809 : : MLX5_ASSERT(resource->action);
15810 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
15811 : : &resource->entry);
15812 : : }
15813 : :
15814 : : /**
15815 : : * Release shared RSS action resource.
15816 : : *
15817 : : * @param dev
15818 : : * Pointer to Ethernet device.
15819 : : * @param srss
15820 : : * Shared RSS action index.
15821 : : */
15822 : : static void
15823 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
15824 : : {
15825 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15826 : : struct mlx5_shared_action_rss *shared_rss;
15827 : :
15828 : 0 : shared_rss = mlx5_ipool_get
15829 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
15830 : 0 : __atomic_fetch_sub(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
15831 : 0 : }
15832 : :
15833 : : void
15834 : 0 : flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15835 : : {
15836 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15837 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
15838 : : container_of(entry, typeof(*resource), entry);
15839 : :
15840 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
15841 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
15842 : 0 : }
15843 : :
15844 : : /**
15845 : : * Release push vlan action resource.
15846 : : *
15847 : : * @param dev
15848 : : * Pointer to Ethernet device.
15849 : : * @param handle
15850 : : * Pointer to mlx5_flow_handle.
15851 : : *
15852 : : * @return
15853 : : * 1 while a reference on it exists, 0 when freed.
15854 : : */
15855 : : static int
15856 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
15857 : : struct mlx5_flow_handle *handle)
15858 : : {
15859 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15860 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
15861 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
15862 : :
15863 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
15864 [ # # ]: 0 : if (!resource)
15865 : : return 0;
15866 : : MLX5_ASSERT(resource->action);
15867 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
15868 : : &resource->entry);
15869 : : }
15870 : :
15871 : : /**
15872 : : * Release the fate resource.
15873 : : *
15874 : : * @param dev
15875 : : * Pointer to Ethernet device.
15876 : : * @param handle
15877 : : * Pointer to mlx5_flow_handle.
15878 : : */
15879 : : static void
15880 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
15881 : : struct mlx5_flow_handle *handle)
15882 : : {
15883 [ # # ]: 0 : if (!handle->rix_fate)
15884 : : return;
15885 [ # # # # : 0 : switch (handle->fate_action) {
# ]
15886 : 0 : case MLX5_FLOW_FATE_QUEUE:
15887 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
15888 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
15889 : : break;
15890 : 0 : case MLX5_FLOW_FATE_JUMP:
15891 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
15892 : 0 : break;
15893 : 0 : case MLX5_FLOW_FATE_PORT_ID:
15894 : 0 : flow_dv_port_id_action_resource_release(dev,
15895 : : handle->rix_port_id_action);
15896 : 0 : break;
15897 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
15898 : : /* In case of send_to_kernel action the actual release of
15899 : : * resource is done when all shared DR resources are released
15900 : : * since this resource is created once and always reused.
15901 : : */
15902 : : break;
15903 : 0 : default:
15904 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
15905 : 0 : break;
15906 : : }
15907 : 0 : handle->rix_fate = 0;
15908 : : }
15909 : :
15910 : : void
15911 : 0 : flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
15912 : : struct mlx5_list_entry *entry)
15913 : : {
15914 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
15915 : : typeof(*resource),
15916 : : entry);
15917 : 0 : struct rte_eth_dev *dev = resource->dev;
15918 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15919 : :
15920 [ # # ]: 0 : if (resource->verbs_action)
15921 : : claim_zero(mlx5_flow_os_destroy_flow_action
15922 : : (resource->verbs_action));
15923 [ # # ]: 0 : if (resource->normal_path_tbl)
15924 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
15925 : : resource->normal_path_tbl);
15926 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
15927 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
15928 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
15929 : 0 : }
15930 : :
15931 : : /**
15932 : : * Release an sample resource.
15933 : : *
15934 : : * @param dev
15935 : : * Pointer to Ethernet device.
15936 : : * @param handle
15937 : : * Pointer to mlx5_flow_handle.
15938 : : *
15939 : : * @return
15940 : : * 1 while a reference on it exists, 0 when freed.
15941 : : */
15942 : : static int
15943 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
15944 : : struct mlx5_flow_handle *handle)
15945 : : {
15946 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15947 : : struct mlx5_flow_dv_sample_resource *resource;
15948 : :
15949 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
15950 : : handle->dvh.rix_sample);
15951 [ # # ]: 0 : if (!resource)
15952 : : return 0;
15953 : : MLX5_ASSERT(resource->verbs_action);
15954 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
15955 : : &resource->entry);
15956 : : }
15957 : :
15958 : : void
15959 : 0 : flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
15960 : : struct mlx5_list_entry *entry)
15961 : : {
15962 : : struct mlx5_flow_dv_dest_array_resource *resource =
15963 : : container_of(entry, typeof(*resource), entry);
15964 : 0 : struct rte_eth_dev *dev = resource->dev;
15965 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15966 : : uint32_t i = 0;
15967 : :
15968 : : MLX5_ASSERT(resource->action);
15969 [ # # ]: 0 : if (resource->action)
15970 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
15971 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
15972 : 0 : flow_dv_sample_sub_actions_release(dev,
15973 : : &resource->sample_idx[i]);
15974 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
15975 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
15976 : : (void *)resource);
15977 : 0 : }
15978 : :
15979 : : /**
15980 : : * Release an destination array resource.
15981 : : *
15982 : : * @param dev
15983 : : * Pointer to Ethernet device.
15984 : : * @param handle
15985 : : * Pointer to mlx5_flow_handle.
15986 : : *
15987 : : * @return
15988 : : * 1 while a reference on it exists, 0 when freed.
15989 : : */
15990 : : static int
15991 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
15992 : : struct mlx5_flow_handle *handle)
15993 : : {
15994 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15995 : : struct mlx5_flow_dv_dest_array_resource *resource;
15996 : :
15997 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
15998 : : handle->dvh.rix_dest_array);
15999 [ # # ]: 0 : if (!resource)
16000 : : return 0;
16001 : : MLX5_ASSERT(resource->action);
16002 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16003 : : &resource->entry);
16004 : : }
16005 : :
16006 : : static void
16007 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16008 : : {
16009 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16010 : : sh->geneve_tlv_option_resource;
16011 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16012 [ # # ]: 0 : if (geneve_opt_resource) {
16013 [ # # ]: 0 : if (!(__atomic_fetch_sub(&geneve_opt_resource->refcnt, 1,
16014 : : __ATOMIC_RELAXED) - 1)) {
16015 : 0 : claim_zero(mlx5_devx_cmd_destroy
16016 : : (geneve_opt_resource->obj));
16017 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16018 : 0 : sh->geneve_tlv_option_resource = NULL;
16019 : : }
16020 : : }
16021 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16022 : 0 : }
16023 : :
16024 : : /**
16025 : : * Remove the flow from the NIC but keeps it in memory.
16026 : : * Lock free, (mutex should be acquired by caller).
16027 : : *
16028 : : * @param[in] dev
16029 : : * Pointer to Ethernet device.
16030 : : * @param[in, out] flow
16031 : : * Pointer to flow structure.
16032 : : */
16033 : : static void
16034 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16035 : : {
16036 : : struct mlx5_flow_handle *dh;
16037 : : uint32_t handle_idx;
16038 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16039 : :
16040 [ # # ]: 0 : if (!flow)
16041 : : return;
16042 : 0 : handle_idx = flow->dev_handles;
16043 [ # # ]: 0 : while (handle_idx) {
16044 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16045 : : handle_idx);
16046 [ # # ]: 0 : if (!dh)
16047 : : return;
16048 [ # # ]: 0 : if (dh->drv_flow) {
16049 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16050 : 0 : dh->drv_flow = NULL;
16051 : : }
16052 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16053 : 0 : flow_dv_fate_resource_release(dev, dh);
16054 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16055 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16056 : 0 : handle_idx = dh->next.next;
16057 : : }
16058 : : }
16059 : :
16060 : : /**
16061 : : * Remove the flow from the NIC and the memory.
16062 : : * Lock free, (mutex should be acquired by caller).
16063 : : *
16064 : : * @param[in] dev
16065 : : * Pointer to the Ethernet device structure.
16066 : : * @param[in, out] flow
16067 : : * Pointer to flow structure.
16068 : : */
16069 : : static void
16070 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16071 : : {
16072 : : struct mlx5_flow_handle *dev_handle;
16073 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16074 : : struct mlx5_flow_meter_info *fm = NULL;
16075 : : uint32_t srss = 0;
16076 : :
16077 [ # # ]: 0 : if (!flow)
16078 : : return;
16079 : 0 : flow_dv_remove(dev, flow);
16080 [ # # ]: 0 : if (flow->counter) {
16081 : 0 : flow_dv_counter_free(dev, flow->counter);
16082 : 0 : flow->counter = 0;
16083 : : }
16084 [ # # ]: 0 : if (flow->meter) {
16085 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
16086 [ # # ]: 0 : if (fm)
16087 : 0 : mlx5_flow_meter_detach(priv, fm);
16088 : 0 : flow->meter = 0;
16089 : : }
16090 : : /* Keep the current age handling by default. */
16091 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16092 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16093 [ # # ]: 0 : else if (flow->age)
16094 : 0 : flow_dv_aso_age_release(dev, flow->age);
16095 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16096 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16097 : 0 : flow->geneve_tlv_option--;
16098 : : }
16099 [ # # ]: 0 : while (flow->dev_handles) {
16100 : : uint32_t tmp_idx = flow->dev_handles;
16101 : :
16102 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16103 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16104 [ # # ]: 0 : if (!dev_handle)
16105 : : return;
16106 : 0 : flow->dev_handles = dev_handle->next.next;
16107 [ # # ]: 0 : while (dev_handle->flex_item) {
16108 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16109 : :
16110 : 0 : mlx5_flex_release_index(dev, index);
16111 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16112 : : }
16113 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16114 : 0 : flow_dv_matcher_release(dev, dev_handle);
16115 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16116 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16117 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16118 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16119 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16120 : 0 : flow_dv_encap_decap_resource_release(dev,
16121 : : dev_handle->dvh.rix_encap_decap);
16122 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16123 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16124 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16125 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16126 : : dev_handle);
16127 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16128 : 0 : flow_dv_tag_release(dev,
16129 : : dev_handle->dvh.rix_tag);
16130 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16131 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16132 [ # # ]: 0 : else if (!srss)
16133 : 0 : srss = dev_handle->rix_srss;
16134 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16135 [ # # ]: 0 : dev_handle->split_flow_id)
16136 : 0 : mlx5_ipool_free(fm->flow_ipool,
16137 : : dev_handle->split_flow_id);
16138 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16139 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16140 : 0 : mlx5_ipool_free(priv->sh->ipool
16141 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16142 : : dev_handle->split_flow_id);
16143 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16144 : : tmp_idx);
16145 : : }
16146 [ # # ]: 0 : if (srss)
16147 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16148 : : }
16149 : :
16150 : : /**
16151 : : * Release array of hash RX queue objects.
16152 : : * Helper function.
16153 : : *
16154 : : * @param[in] dev
16155 : : * Pointer to the Ethernet device structure.
16156 : : * @param[in, out] hrxqs
16157 : : * Array of hash RX queue objects.
16158 : : *
16159 : : * @return
16160 : : * Total number of references to hash RX queue objects in *hrxqs* array
16161 : : * after this operation.
16162 : : */
16163 : : static int
16164 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16165 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
16166 : : {
16167 : : size_t i;
16168 : : int remaining = 0;
16169 : :
16170 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16171 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16172 : :
16173 [ # # ]: 0 : if (!ret)
16174 : 0 : (*hrxqs)[i] = 0;
16175 : 0 : remaining += ret;
16176 : : }
16177 : 0 : return remaining;
16178 : : }
16179 : :
16180 : : /**
16181 : : * Release all hash RX queue objects representing shared RSS action.
16182 : : *
16183 : : * @param[in] dev
16184 : : * Pointer to the Ethernet device structure.
16185 : : * @param[in, out] action
16186 : : * Shared RSS action to remove hash RX queue objects from.
16187 : : *
16188 : : * @return
16189 : : * Total number of references to hash RX queue objects stored in *action*
16190 : : * after this operation.
16191 : : * Expected to be 0 if no external references held.
16192 : : */
16193 : : static int
16194 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16195 : : struct mlx5_shared_action_rss *shared_rss)
16196 : : {
16197 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16198 : : }
16199 : :
16200 : : /**
16201 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16202 : : * user input.
16203 : : *
16204 : : * Only one hash value is available for one L3+L4 combination:
16205 : : * for example:
16206 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16207 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16208 : : * same slot in mlx5_rss_hash_fields.
16209 : : *
16210 : : * @param[in] orig_rss_types
16211 : : * RSS type as provided in shared RSS action.
16212 : : * @param[in, out] hash_field
16213 : : * hash_field variable needed to be adjusted.
16214 : : *
16215 : : * @return
16216 : : * void
16217 : : */
16218 : : void
16219 [ # # ]: 0 : flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16220 : : uint64_t *hash_field)
16221 : : {
16222 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16223 : :
16224 [ # # # # : 0 : switch (*hash_field & ~IBV_RX_HASH_INNER) {
# ]
16225 : 0 : case MLX5_RSS_HASH_IPV4:
16226 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16227 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV4;
16228 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16229 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV4;
16230 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16231 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV4;
16232 : : else
16233 : 0 : *hash_field |= MLX5_RSS_HASH_IPV4;
16234 : : }
16235 : : return;
16236 : 0 : case MLX5_RSS_HASH_IPV6:
16237 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16238 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV6;
16239 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16240 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV6;
16241 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16242 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV6;
16243 : : else
16244 : 0 : *hash_field |= MLX5_RSS_HASH_IPV6;
16245 : : }
16246 : : return;
16247 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
16248 : : /* fall-through. */
16249 : : case MLX5_RSS_HASH_IPV6_UDP:
16250 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16251 : 0 : *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
16252 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16253 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
16254 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16255 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
16256 : : else
16257 : 0 : *hash_field |= MLX5_UDP_IBV_RX_HASH;
16258 : : }
16259 : : return;
16260 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
16261 : : /* fall-through. */
16262 : : case MLX5_RSS_HASH_IPV6_TCP:
16263 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16264 : 0 : *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
16265 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16266 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
16267 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16268 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
16269 : : else
16270 : 0 : *hash_field |= MLX5_TCP_IBV_RX_HASH;
16271 : : }
16272 : : return;
16273 : : default:
16274 : : return;
16275 : : }
16276 : : }
16277 : :
16278 : : /**
16279 : : * Setup shared RSS action.
16280 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16281 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16282 : : *
16283 : : * @param[in] dev
16284 : : * Pointer to the Ethernet device structure.
16285 : : * @param[in] action_idx
16286 : : * Shared RSS action ipool index.
16287 : : * @param[in, out] action
16288 : : * Partially initialized shared RSS action.
16289 : : * @param[out] error
16290 : : * Perform verbose error reporting if not NULL. Initialized in case of
16291 : : * error only.
16292 : : *
16293 : : * @return
16294 : : * 0 on success, otherwise negative errno value.
16295 : : */
16296 : : static int
16297 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16298 : : uint32_t action_idx,
16299 : : struct mlx5_shared_action_rss *shared_rss,
16300 : : struct rte_flow_error *error)
16301 : : {
16302 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16303 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16304 : : size_t i;
16305 : : int err;
16306 : :
16307 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16308 : : (dev, shared_rss->origin.queue,
16309 : : shared_rss->origin.queue_num,
16310 : : true,
16311 : 0 : !!dev->data->dev_started);
16312 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16313 : 0 : return rte_flow_error_set(error, rte_errno,
16314 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16315 : : "cannot setup indirection table");
16316 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16317 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16318 : 0 : rss_desc.symmetric_hash_function =
16319 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16320 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16321 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16322 : : /* Set non-zero value to indicate a shared RSS. */
16323 : 0 : rss_desc.shared_rss = action_idx;
16324 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16325 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16326 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16327 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
16328 : : struct mlx5_hrxq *hrxq;
16329 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16330 : : int tunnel = 0;
16331 : :
16332 : 0 : flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16333 : : &hash_fields);
16334 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16335 : 0 : hash_fields |= IBV_RX_HASH_INNER;
16336 : : tunnel = 1;
16337 : : }
16338 : 0 : rss_desc.tunnel = tunnel;
16339 : 0 : rss_desc.hash_fields = hash_fields;
16340 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
16341 [ # # ]: 0 : if (!hrxq) {
16342 : 0 : rte_flow_error_set
16343 : : (error, rte_errno,
16344 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16345 : : "cannot get hash queue");
16346 : 0 : goto error_hrxq_new;
16347 : : }
16348 : 0 : err = __flow_dv_action_rss_hrxq_set
16349 : : (shared_rss, hash_fields, hrxq->idx);
16350 : : MLX5_ASSERT(!err);
16351 : : }
16352 : : return 0;
16353 : : error_hrxq_new:
16354 : 0 : err = rte_errno;
16355 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16356 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
16357 : 0 : shared_rss->ind_tbl = NULL;
16358 : 0 : rte_errno = err;
16359 : 0 : return -rte_errno;
16360 : : }
16361 : :
16362 : : /**
16363 : : * Create shared RSS action.
16364 : : *
16365 : : * @param[in] dev
16366 : : * Pointer to the Ethernet device structure.
16367 : : * @param[in] conf
16368 : : * Shared action configuration.
16369 : : * @param[in] rss
16370 : : * RSS action specification used to create shared action.
16371 : : * @param[out] error
16372 : : * Perform verbose error reporting if not NULL. Initialized in case of
16373 : : * error only.
16374 : : *
16375 : : * @return
16376 : : * A valid shared action ID in case of success, 0 otherwise and
16377 : : * rte_errno is set.
16378 : : */
16379 : : static uint32_t
16380 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
16381 : : const struct rte_flow_indir_action_conf *conf,
16382 : : const struct rte_flow_action_rss *rss,
16383 : : struct rte_flow_error *error)
16384 : : {
16385 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16386 : : struct mlx5_shared_action_rss *shared_rss = NULL;
16387 : : struct rte_flow_action_rss *origin;
16388 : : const uint8_t *rss_key;
16389 : : uint32_t idx;
16390 : :
16391 : : RTE_SET_USED(conf);
16392 : 0 : shared_rss = mlx5_ipool_zmalloc
16393 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
16394 [ # # ]: 0 : if (!shared_rss) {
16395 : 0 : rte_flow_error_set(error, ENOMEM,
16396 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16397 : : "cannot allocate resource memory");
16398 : 0 : goto error_rss_init;
16399 : : }
16400 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
16401 : 0 : rte_flow_error_set(error, E2BIG,
16402 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16403 : : "rss action number out of range");
16404 : 0 : goto error_rss_init;
16405 : : }
16406 : : origin = &shared_rss->origin;
16407 : 0 : origin->func = rss->func;
16408 : 0 : origin->level = rss->level;
16409 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
16410 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
16411 : : /* NULL RSS key indicates default RSS key. */
16412 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
16413 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
16414 : 0 : origin->key = &shared_rss->key[0];
16415 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
16416 : 0 : origin->queue = rss->queue;
16417 : 0 : origin->queue_num = rss->queue_num;
16418 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
16419 : 0 : goto error_rss_init;
16420 : : /* Update queue with indirect table queue memoyr. */
16421 : 0 : origin->queue = shared_rss->ind_tbl->queues;
16422 : : rte_spinlock_init(&shared_rss->action_rss_sl);
16423 : 0 : __atomic_fetch_add(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
16424 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16425 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16426 : : &priv->rss_shared_actions, idx, shared_rss, next);
16427 : : rte_spinlock_unlock(&priv->shared_act_sl);
16428 : 0 : return idx;
16429 : 0 : error_rss_init:
16430 [ # # ]: 0 : if (shared_rss) {
16431 [ # # ]: 0 : if (shared_rss->ind_tbl)
16432 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16433 : 0 : !!dev->data->dev_started);
16434 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16435 : : idx);
16436 : : }
16437 : : return 0;
16438 : : }
16439 : :
16440 : : /**
16441 : : * Destroy the shared RSS action.
16442 : : * Release related hash RX queue objects.
16443 : : *
16444 : : * @param[in] dev
16445 : : * Pointer to the Ethernet device structure.
16446 : : * @param[in] idx
16447 : : * The shared RSS action object ID to be removed.
16448 : : * @param[out] error
16449 : : * Perform verbose error reporting if not NULL. Initialized in case of
16450 : : * error only.
16451 : : *
16452 : : * @return
16453 : : * 0 on success, otherwise negative errno value.
16454 : : */
16455 : : static int
16456 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
16457 : : struct rte_flow_error *error)
16458 : : {
16459 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16460 : : struct mlx5_shared_action_rss *shared_rss =
16461 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16462 : : uint32_t old_refcnt = 1;
16463 : : int remaining;
16464 : :
16465 [ # # ]: 0 : if (!shared_rss)
16466 : 0 : return rte_flow_error_set(error, EINVAL,
16467 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16468 : : "invalid shared action");
16469 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
16470 : : 0, 0, __ATOMIC_ACQUIRE,
16471 : : __ATOMIC_RELAXED))
16472 : 0 : return rte_flow_error_set(error, EBUSY,
16473 : : RTE_FLOW_ERROR_TYPE_ACTION,
16474 : : NULL,
16475 : : "shared rss has references");
16476 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16477 [ # # ]: 0 : if (remaining)
16478 : 0 : return rte_flow_error_set(error, EBUSY,
16479 : : RTE_FLOW_ERROR_TYPE_ACTION,
16480 : : NULL,
16481 : : "shared rss hrxq has references");
16482 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16483 : 0 : !!dev->data->dev_started);
16484 [ # # ]: 0 : if (remaining)
16485 : 0 : return rte_flow_error_set(error, EBUSY,
16486 : : RTE_FLOW_ERROR_TYPE_ACTION,
16487 : : NULL,
16488 : : "shared rss indirection table has"
16489 : : " references");
16490 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16491 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
16492 : : &priv->rss_shared_actions, idx, shared_rss, next);
16493 : : rte_spinlock_unlock(&priv->shared_act_sl);
16494 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16495 : : idx);
16496 : 0 : return 0;
16497 : : }
16498 : :
16499 : : /**
16500 : : * Create indirect action, lock free,
16501 : : * (mutex should be acquired by caller).
16502 : : * Dispatcher for action type specific call.
16503 : : *
16504 : : * @param[in] dev
16505 : : * Pointer to the Ethernet device structure.
16506 : : * @param[in] conf
16507 : : * Shared action configuration.
16508 : : * @param[in] action
16509 : : * Action specification used to create indirect action.
16510 : : * @param[out] error
16511 : : * Perform verbose error reporting if not NULL. Initialized in case of
16512 : : * error only.
16513 : : *
16514 : : * @return
16515 : : * A valid shared action handle in case of success, NULL otherwise and
16516 : : * rte_errno is set.
16517 : : */
16518 : : struct rte_flow_action_handle *
16519 : 0 : flow_dv_action_create(struct rte_eth_dev *dev,
16520 : : const struct rte_flow_indir_action_conf *conf,
16521 : : const struct rte_flow_action *action,
16522 : : struct rte_flow_error *err)
16523 : : {
16524 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16525 : : uint32_t age_idx = 0;
16526 : : uint32_t idx = 0;
16527 : : uint32_t ret = 0;
16528 : :
16529 [ # # # # : 0 : switch (action->type) {
# ]
16530 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
16531 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
16532 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
16533 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16534 : 0 : break;
16535 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
16536 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
16537 [ # # ]: 0 : if (!age_idx) {
16538 : 0 : ret = -rte_errno;
16539 : 0 : break;
16540 : : }
16541 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
16542 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
16543 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
16544 : : ((const struct rte_flow_action_age *)
16545 : 0 : action->conf)->context ?
16546 : : ((const struct rte_flow_action_age *)
16547 : : action->conf)->context :
16548 : 0 : (void *)(uintptr_t)idx,
16549 : : ((const struct rte_flow_action_age *)
16550 [ # # ]: 0 : action->conf)->timeout);
16551 : : ret = age_idx;
16552 : 0 : break;
16553 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
16554 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
16555 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
16556 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16557 : 0 : break;
16558 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
16559 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
16560 : : err);
16561 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
16562 : 0 : break;
16563 : 0 : default:
16564 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
16565 : : NULL, "action type not supported");
16566 : : break;
16567 : : }
16568 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
16569 : : }
16570 : :
16571 : : /**
16572 : : * Destroy the indirect action.
16573 : : * Release action related resources on the NIC and the memory.
16574 : : * Lock free, (mutex should be acquired by caller).
16575 : : * Dispatcher for action type specific call.
16576 : : *
16577 : : * @param[in] dev
16578 : : * Pointer to the Ethernet device structure.
16579 : : * @param[in] handle
16580 : : * The indirect action object handle to be removed.
16581 : : * @param[out] error
16582 : : * Perform verbose error reporting if not NULL. Initialized in case of
16583 : : * error only.
16584 : : *
16585 : : * @return
16586 : : * 0 on success, otherwise negative errno value.
16587 : : */
16588 : : int
16589 : 0 : flow_dv_action_destroy(struct rte_eth_dev *dev,
16590 : : struct rte_flow_action_handle *handle,
16591 : : struct rte_flow_error *error)
16592 : : {
16593 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
16594 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
16595 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
16596 : : struct mlx5_flow_counter *cnt;
16597 : : uint32_t no_flow_refcnt = 1;
16598 : : int ret;
16599 : :
16600 [ # # # # : 0 : switch (type) {
# ]
16601 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
16602 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
16603 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
16604 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
16605 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
16606 : : &no_flow_refcnt, 1, false,
16607 : : __ATOMIC_ACQUIRE,
16608 : : __ATOMIC_RELAXED))
16609 : 0 : return rte_flow_error_set(error, EBUSY,
16610 : : RTE_FLOW_ERROR_TYPE_ACTION,
16611 : : NULL,
16612 : : "Indirect count action has references");
16613 : 0 : flow_dv_counter_free(dev, idx);
16614 : 0 : return 0;
16615 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
16616 : 0 : ret = flow_dv_aso_age_release(dev, idx);
16617 [ # # ]: 0 : if (ret)
16618 : : /*
16619 : : * In this case, the last flow has a reference will
16620 : : * actually release the age action.
16621 : : */
16622 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
16623 : : " released with references %d.", idx, ret);
16624 : : return 0;
16625 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
16626 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
16627 [ # # ]: 0 : if (ret < 0)
16628 : : return ret;
16629 [ # # ]: 0 : if (ret > 0)
16630 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
16631 : : "has references %d.", idx, ret);
16632 : : return 0;
16633 : 0 : default:
16634 : 0 : return rte_flow_error_set(error, ENOTSUP,
16635 : : RTE_FLOW_ERROR_TYPE_ACTION,
16636 : : NULL,
16637 : : "action type not supported");
16638 : : }
16639 : : }
16640 : :
16641 : : /**
16642 : : * Updates in place shared RSS action configuration.
16643 : : *
16644 : : * @param[in] dev
16645 : : * Pointer to the Ethernet device structure.
16646 : : * @param[in] idx
16647 : : * The shared RSS action object ID to be updated.
16648 : : * @param[in] action_conf
16649 : : * RSS action specification used to modify *shared_rss*.
16650 : : * @param[out] error
16651 : : * Perform verbose error reporting if not NULL. Initialized in case of
16652 : : * error only.
16653 : : *
16654 : : * @return
16655 : : * 0 on success, otherwise negative errno value.
16656 : : * @note: currently only support update of RSS queues.
16657 : : */
16658 : : static int
16659 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
16660 : : const struct rte_flow_action_rss *action_conf,
16661 : : struct rte_flow_error *error)
16662 : : {
16663 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16664 : : struct mlx5_shared_action_rss *shared_rss =
16665 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16666 : : int ret = 0;
16667 : : void *queue = NULL;
16668 : : void *queue_i = NULL;
16669 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
16670 : 0 : bool dev_started = !!dev->data->dev_started;
16671 : :
16672 [ # # ]: 0 : if (!shared_rss)
16673 : 0 : return rte_flow_error_set(error, EINVAL,
16674 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16675 : : "invalid shared action to update");
16676 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
16677 : 0 : return rte_flow_error_set(error, ENOTSUP,
16678 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16679 : : "cannot modify indirection table");
16680 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
16681 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
16682 : : 0, SOCKET_ID_ANY);
16683 [ # # ]: 0 : if (!queue)
16684 : 0 : return rte_flow_error_set(error, ENOMEM,
16685 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16686 : : NULL,
16687 : : "cannot allocate resource memory");
16688 : 0 : memcpy(queue, action_conf->queue, queue_size);
16689 : : MLX5_ASSERT(shared_rss->ind_tbl);
16690 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
16691 : 0 : queue_i = shared_rss->ind_tbl->queues;
16692 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
16693 : 0 : queue, action_conf->queue_num,
16694 : : true /* standalone */,
16695 : : dev_started /* ref_new_qs */,
16696 : : dev_started /* deref_old_qs */);
16697 [ # # ]: 0 : if (ret) {
16698 : 0 : ret = rte_flow_error_set(error, rte_errno,
16699 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16700 : : "cannot update indirection table");
16701 : : } else {
16702 : : /* Restore the queue to indirect table internal queue. */
16703 : : memcpy(queue_i, queue, queue_size);
16704 : 0 : shared_rss->ind_tbl->queues = queue_i;
16705 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
16706 : : }
16707 : 0 : mlx5_free(queue);
16708 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
16709 : 0 : return ret;
16710 : : }
16711 : :
16712 : : /*
16713 : : * Updates in place conntrack context or direction.
16714 : : * Context update should be synchronized.
16715 : : *
16716 : : * @param[in] dev
16717 : : * Pointer to the Ethernet device structure.
16718 : : * @param[in] idx
16719 : : * The conntrack object ID to be updated.
16720 : : * @param[in] update
16721 : : * Pointer to the structure of information to update.
16722 : : * @param[out] error
16723 : : * Perform verbose error reporting if not NULL. Initialized in case of
16724 : : * error only.
16725 : : *
16726 : : * @return
16727 : : * 0 on success, otherwise negative errno value.
16728 : : */
16729 : : static int
16730 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
16731 : : const struct rte_flow_modify_conntrack *update,
16732 : : struct rte_flow_error *error)
16733 : : {
16734 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16735 : : struct mlx5_aso_ct_action *ct;
16736 : : const struct rte_flow_action_conntrack *new_prf;
16737 : : int ret = 0;
16738 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
16739 : : uint32_t dev_idx;
16740 : :
16741 [ # # ]: 0 : if (PORT_ID(priv) != owner)
16742 : 0 : return rte_flow_error_set(error, EACCES,
16743 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16744 : : NULL,
16745 : : "CT object owned by another port");
16746 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
16747 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
16748 [ # # ]: 0 : if (!ct->refcnt)
16749 : 0 : return rte_flow_error_set(error, ENOMEM,
16750 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16751 : : NULL,
16752 : : "CT object is inactive");
16753 : 0 : new_prf = &update->new_ct;
16754 [ # # ]: 0 : if (update->direction)
16755 : 0 : ct->is_original = !!new_prf->is_original_dir;
16756 [ # # ]: 0 : if (update->state) {
16757 : : /* Only validate the profile when it needs to be updated. */
16758 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
16759 [ # # ]: 0 : if (ret)
16760 : : return ret;
16761 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
16762 : : ct, new_prf, NULL, true);
16763 [ # # ]: 0 : if (ret)
16764 : 0 : return rte_flow_error_set(error, EIO,
16765 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16766 : : NULL,
16767 : : "Failed to send CT context update WQE");
16768 : : /* Block until ready or a failure, default is asynchronous. */
16769 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
16770 [ # # ]: 0 : if (ret)
16771 : 0 : rte_flow_error_set(error, rte_errno,
16772 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16773 : : NULL,
16774 : : "Timeout to get the CT update");
16775 : : }
16776 : : return ret;
16777 : : }
16778 : :
16779 : : /**
16780 : : * Updates in place shared action configuration, lock free,
16781 : : * (mutex should be acquired by caller).
16782 : : *
16783 : : * @param[in] dev
16784 : : * Pointer to the Ethernet device structure.
16785 : : * @param[in] handle
16786 : : * The indirect action object handle to be updated.
16787 : : * @param[in] update
16788 : : * Action specification used to modify the action pointed by *handle*.
16789 : : * *update* could be of same type with the action pointed by the *handle*
16790 : : * handle argument, or some other structures like a wrapper, depending on
16791 : : * the indirect action type.
16792 : : * @param[out] error
16793 : : * Perform verbose error reporting if not NULL. Initialized in case of
16794 : : * error only.
16795 : : *
16796 : : * @return
16797 : : * 0 on success, otherwise negative errno value.
16798 : : */
16799 : : int
16800 : 0 : flow_dv_action_update(struct rte_eth_dev *dev,
16801 : : struct rte_flow_action_handle *handle,
16802 : : const void *update,
16803 : : struct rte_flow_error *err)
16804 : : {
16805 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
16806 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
16807 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
16808 : : const void *action_conf;
16809 : :
16810 [ # # # ]: 0 : switch (type) {
16811 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
16812 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
16813 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
16814 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
16815 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
16816 : 0 : default:
16817 : 0 : return rte_flow_error_set(err, ENOTSUP,
16818 : : RTE_FLOW_ERROR_TYPE_ACTION,
16819 : : NULL,
16820 : : "action type update not supported");
16821 : : }
16822 : : }
16823 : :
16824 : : /**
16825 : : * Destroy the meter sub policy table rules.
16826 : : * Lock free, (mutex should be acquired by caller).
16827 : : *
16828 : : * @param[in] dev
16829 : : * Pointer to Ethernet device.
16830 : : * @param[in] sub_policy
16831 : : * Pointer to meter sub policy table.
16832 : : */
16833 : : static void
16834 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
16835 : : struct mlx5_flow_meter_sub_policy *sub_policy)
16836 : : {
16837 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16838 : : struct mlx5_flow_tbl_data_entry *tbl;
16839 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
16840 : : struct mlx5_flow_meter_info *next_fm;
16841 : : struct mlx5_sub_policy_color_rule *color_rule;
16842 : : void *tmp;
16843 : : uint32_t i;
16844 : :
16845 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
16846 : : next_fm = NULL;
16847 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
16848 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
16849 : 0 : next_fm = mlx5_flow_meter_find(priv,
16850 : : policy->act_cnt[i].next_mtr_id, NULL);
16851 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
16852 : : next_port, tmp) {
16853 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
16854 : 0 : tbl = container_of(color_rule->matcher->tbl,
16855 : : typeof(*tbl), tbl);
16856 : 0 : mlx5_list_unregister(tbl->matchers,
16857 : : &color_rule->matcher->entry);
16858 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
16859 : : color_rule, next_port);
16860 : 0 : mlx5_free(color_rule);
16861 [ # # ]: 0 : if (next_fm)
16862 : 0 : mlx5_flow_meter_detach(priv, next_fm);
16863 : : }
16864 : : }
16865 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16866 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
16867 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
16868 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
16869 : 0 : sub_policy->rix_hrxq[i] = 0;
16870 : : }
16871 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
16872 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16873 : : sub_policy->jump_tbl[i]);
16874 : 0 : sub_policy->jump_tbl[i] = NULL;
16875 : : }
16876 : : }
16877 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
16878 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16879 : : sub_policy->tbl_rsc);
16880 : 0 : sub_policy->tbl_rsc = NULL;
16881 : : }
16882 : 0 : }
16883 : :
16884 : : /**
16885 : : * Destroy policy rules, lock free,
16886 : : * (mutex should be acquired by caller).
16887 : : * Dispatcher for action type specific call.
16888 : : *
16889 : : * @param[in] dev
16890 : : * Pointer to the Ethernet device structure.
16891 : : * @param[in] mtr_policy
16892 : : * Meter policy struct.
16893 : : */
16894 : : static void
16895 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
16896 : : struct mlx5_flow_meter_policy *mtr_policy)
16897 : : {
16898 : : uint32_t i, j;
16899 : : struct mlx5_flow_meter_sub_policy *sub_policy;
16900 : : uint16_t sub_policy_num;
16901 : :
16902 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16903 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
16904 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16905 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
16906 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
16907 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
16908 [ # # ]: 0 : if (sub_policy)
16909 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
16910 : : sub_policy);
16911 : : }
16912 : : }
16913 : 0 : }
16914 : :
16915 : : /**
16916 : : * Destroy policy action, lock free,
16917 : : * (mutex should be acquired by caller).
16918 : : * Dispatcher for action type specific call.
16919 : : *
16920 : : * @param[in] dev
16921 : : * Pointer to the Ethernet device structure.
16922 : : * @param[in] mtr_policy
16923 : : * Meter policy struct.
16924 : : */
16925 : : static void
16926 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
16927 : : struct mlx5_flow_meter_policy *mtr_policy)
16928 : : {
16929 : : struct rte_flow_action *rss_action;
16930 : : struct mlx5_flow_handle dev_handle;
16931 : : uint32_t i, j;
16932 : :
16933 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16934 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
16935 : 0 : flow_dv_tag_release(dev,
16936 : : mtr_policy->act_cnt[i].rix_mark);
16937 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
16938 : : }
16939 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
16940 : : dev_handle.dvh.modify_hdr =
16941 : : mtr_policy->act_cnt[i].modify_hdr;
16942 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
16943 : : }
16944 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
16945 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
16946 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
16947 : 0 : mlx5_free(rss_action);
16948 : 0 : break;
16949 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16950 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
16951 : 0 : flow_dv_port_id_action_resource_release(dev,
16952 : : mtr_policy->act_cnt[i].rix_port_id_action);
16953 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
16954 : : }
16955 : : break;
16956 : : case MLX5_FLOW_FATE_DROP:
16957 : : case MLX5_FLOW_FATE_JUMP:
16958 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
16959 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
16960 : : NULL;
16961 : : break;
16962 : : default:
16963 : : /*Queue action do nothing*/
16964 : : break;
16965 : : }
16966 : : }
16967 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
16968 : 0 : mtr_policy->dr_drop_action[j] = NULL;
16969 : 0 : }
16970 : :
16971 : : /**
16972 : : * Create yellow action for color aware meter.
16973 : : *
16974 : : * @param[in] dev
16975 : : * Pointer to the Ethernet device structure.
16976 : : * @param[in] fm
16977 : : * Meter information table.
16978 : : * @param[out] error
16979 : : * Perform verbose error reporting if not NULL. Initialized in case of
16980 : : * error only.
16981 : : *
16982 : : * @return
16983 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
16984 : : */
16985 : : static int
16986 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
16987 : : struct mlx5_flow_meter_info *fm,
16988 : : struct rte_mtr_error *error)
16989 : : {
16990 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
16991 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16992 : : struct rte_flow_error flow_err;
16993 : : struct mlx5_aso_mtr *aso_mtr;
16994 : : struct mlx5_aso_mtr_pool *pool;
16995 : : uint8_t reg_id;
16996 : :
16997 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
16998 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
16999 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17000 : 0 : fm->meter_action_y =
17001 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17002 : 0 : pool->devx_obj->obj,
17003 : : aso_mtr->offset,
17004 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17005 : 0 : reg_id - REG_C_0);
17006 : : #else
17007 : : RTE_SET_USED(dev);
17008 : : #endif
17009 [ # # ]: 0 : if (!fm->meter_action_y) {
17010 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17011 : : "Fail to create yellow meter action.");
17012 : : }
17013 : : return 0;
17014 : : }
17015 : :
17016 : : /**
17017 : : * Create policy action per domain, lock free,
17018 : : * (mutex should be acquired by caller).
17019 : : * Dispatcher for action type specific call.
17020 : : *
17021 : : * @param[in] dev
17022 : : * Pointer to the Ethernet device structure.
17023 : : * @param[in] mtr_policy
17024 : : * Meter policy struct.
17025 : : * @param[in] action
17026 : : * Action specification used to create meter actions.
17027 : : * @param[in] attr
17028 : : * Pointer to the flow attributes.
17029 : : * @param[out] error
17030 : : * Perform verbose error reporting if not NULL. Initialized in case of
17031 : : * error only.
17032 : : *
17033 : : * @return
17034 : : * 0 on success, otherwise negative errno value.
17035 : : */
17036 : : static int
17037 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17038 : : struct mlx5_flow_meter_policy *mtr_policy,
17039 : : const struct rte_flow_action *actions[RTE_COLORS],
17040 : : struct rte_flow_attr *attr,
17041 : : enum mlx5_meter_domain domain,
17042 : : struct rte_mtr_error *error)
17043 : : {
17044 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17045 : : struct rte_flow_error flow_err;
17046 : : const struct rte_flow_action *act;
17047 : : uint64_t action_flags;
17048 : : struct mlx5_flow_handle dh;
17049 : : struct mlx5_flow dev_flow;
17050 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17051 : : int i, ret;
17052 : : uint8_t egress, transfer;
17053 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17054 : : union {
17055 : : struct mlx5_flow_dv_modify_hdr_resource res;
17056 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17057 : : sizeof(struct mlx5_modification_cmd) *
17058 : : (MLX5_MAX_MODIFY_NUM + 1)];
17059 : : } mhdr_dummy;
17060 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17061 : :
17062 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17063 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17064 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17065 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17066 : : memset(&port_id_action, 0,
17067 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17068 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17069 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17070 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17071 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17072 : 0 : dev_flow.handle = &dh;
17073 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17074 : 0 : dev_flow.external = true;
17075 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17076 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17077 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17078 : : /* Skip the color policy actions creation. */
17079 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17080 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17081 : 0 : continue;
17082 : : action_flags = 0;
17083 : 0 : for (act = actions[i];
17084 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17085 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17086 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17087 : : {
17088 : : uint32_t tag_be = mlx5_flow_mark_set
17089 : : (((const struct rte_flow_action_mark *)
17090 [ # # ]: 0 : (act->conf))->id);
17091 : :
17092 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17093 : 0 : return -rte_mtr_error_set(error,
17094 : : ENOTSUP,
17095 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17096 : : NULL,
17097 : : "cannot create policy "
17098 : : "mark action for this color");
17099 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17100 : : &dev_flow, &flow_err))
17101 : 0 : return -rte_mtr_error_set(error,
17102 : : ENOTSUP,
17103 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17104 : : NULL,
17105 : : "cannot setup policy mark action");
17106 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17107 : 0 : act_cnt->rix_mark =
17108 : 0 : dev_flow.handle->dvh.rix_tag;
17109 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17110 : 0 : mtr_policy->mark = 1;
17111 : 0 : break;
17112 : : }
17113 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17114 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17115 : 0 : return -rte_mtr_error_set(error,
17116 : : ENOTSUP,
17117 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17118 : : NULL,
17119 : : "cannot create policy "
17120 : : "set tag action for this color");
17121 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17122 : : (dev, mhdr_res,
17123 : : (const struct rte_flow_action_set_tag *)
17124 : 0 : act->conf, &flow_err))
17125 : 0 : return -rte_mtr_error_set(error,
17126 : : ENOTSUP,
17127 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17128 : : NULL, "cannot convert policy "
17129 : : "set tag action");
17130 [ # # ]: 0 : if (!mhdr_res->actions_num)
17131 : 0 : return -rte_mtr_error_set(error,
17132 : : ENOTSUP,
17133 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17134 : : NULL, "cannot find policy "
17135 : : "set tag action");
17136 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17137 : 0 : break;
17138 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17139 : : {
17140 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17141 : 0 : priv->sh->mtrmng;
17142 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17143 : :
17144 : : /*
17145 : : * Create the drop table with
17146 : : * METER DROP level.
17147 : : */
17148 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17149 : 0 : mtrmng->drop_tbl[domain] =
17150 : 0 : flow_dv_tbl_resource_get(dev,
17151 : : MLX5_FLOW_TABLE_LEVEL_METER,
17152 : : egress, transfer, false, NULL, 0,
17153 : : 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
17154 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17155 : 0 : return -rte_mtr_error_set
17156 : : (error, ENOTSUP,
17157 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17158 : : NULL,
17159 : : "Failed to create meter drop table");
17160 : : }
17161 : 0 : tbl_data = container_of
17162 : : (mtrmng->drop_tbl[domain],
17163 : : struct mlx5_flow_tbl_data_entry, tbl);
17164 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17165 : 0 : act_cnt->dr_jump_action[domain] =
17166 : 0 : tbl_data->jump.action;
17167 : 0 : act_cnt->fate_action =
17168 : : MLX5_FLOW_FATE_DROP;
17169 : : }
17170 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17171 : 0 : mtr_policy->dr_drop_action[domain] =
17172 : 0 : tbl_data->jump.action;
17173 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17174 : 0 : break;
17175 : : }
17176 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17177 : : {
17178 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17179 : 0 : return -rte_mtr_error_set(error,
17180 : : ENOTSUP,
17181 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17182 : : NULL, "cannot create policy "
17183 : : "fate queue for this color");
17184 : 0 : act_cnt->queue =
17185 : : ((const struct rte_flow_action_queue *)
17186 : 0 : (act->conf))->index;
17187 : 0 : act_cnt->fate_action =
17188 : : MLX5_FLOW_FATE_QUEUE;
17189 : 0 : dev_flow.handle->fate_action =
17190 : : MLX5_FLOW_FATE_QUEUE;
17191 : 0 : mtr_policy->is_queue = 1;
17192 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17193 : 0 : break;
17194 : : }
17195 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17196 : : {
17197 : : int rss_size;
17198 : :
17199 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17200 : 0 : return -rte_mtr_error_set(error,
17201 : : ENOTSUP,
17202 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17203 : : NULL,
17204 : : "cannot create policy "
17205 : : "rss action for this color");
17206 : : /*
17207 : : * Save RSS conf into policy struct
17208 : : * for translate stage.
17209 : : */
17210 : 0 : rss_size = (int)rte_flow_conv
17211 : : (RTE_FLOW_CONV_OP_ACTION,
17212 : : NULL, 0, act, &flow_err);
17213 [ # # ]: 0 : if (rss_size <= 0)
17214 : 0 : return -rte_mtr_error_set(error,
17215 : : ENOTSUP,
17216 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17217 : : NULL, "Get the wrong "
17218 : : "rss action struct size");
17219 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17220 : : rss_size, 0, SOCKET_ID_ANY);
17221 [ # # ]: 0 : if (!act_cnt->rss)
17222 : 0 : return -rte_mtr_error_set(error,
17223 : : ENOTSUP,
17224 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17225 : : NULL,
17226 : : "Fail to malloc rss action memory");
17227 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17228 : : act_cnt->rss, rss_size,
17229 : : act, &flow_err);
17230 [ # # ]: 0 : if (ret < 0)
17231 : 0 : return -rte_mtr_error_set(error,
17232 : : ENOTSUP,
17233 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17234 : : NULL, "Fail to save "
17235 : : "rss action into policy struct");
17236 : 0 : act_cnt->fate_action =
17237 : : MLX5_FLOW_FATE_SHARED_RSS;
17238 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17239 : 0 : break;
17240 : : }
17241 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17242 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17243 : : {
17244 : : struct mlx5_flow_dv_port_id_action_resource
17245 : : port_id_resource;
17246 : 0 : uint32_t port_id = 0;
17247 : :
17248 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17249 : 0 : return -rte_mtr_error_set(error,
17250 : : ENOTSUP,
17251 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17252 : : NULL, "cannot create policy "
17253 : : "port action for this color");
17254 : : memset(&port_id_resource, 0,
17255 : : sizeof(port_id_resource));
17256 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17257 : : &port_id, &flow_err))
17258 : 0 : return -rte_mtr_error_set(error,
17259 : : ENOTSUP,
17260 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17261 : : NULL, "cannot translate "
17262 : : "policy port action");
17263 : 0 : port_id_resource.port_id = port_id;
17264 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17265 : : (dev, &port_id_resource,
17266 : : &dev_flow, &flow_err))
17267 : 0 : return -rte_mtr_error_set(error,
17268 : : ENOTSUP,
17269 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17270 : : NULL, "cannot setup "
17271 : : "policy port action");
17272 : 0 : act_cnt->rix_port_id_action =
17273 : 0 : dev_flow.handle->rix_port_id_action;
17274 : 0 : act_cnt->fate_action =
17275 : : MLX5_FLOW_FATE_PORT_ID;
17276 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17277 : 0 : break;
17278 : : }
17279 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17280 : : {
17281 : : uint32_t jump_group = 0;
17282 : 0 : uint32_t table = 0;
17283 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17284 : 0 : struct flow_grp_info grp_info = {
17285 : 0 : .external = !!dev_flow.external,
17286 : : .transfer = !!transfer,
17287 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17288 : : .std_tbl_fix = 0,
17289 : 0 : .skip_scale = dev_flow.skip_scale &
17290 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17291 : : };
17292 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17293 : 0 : mtr_policy->sub_policys[domain][0];
17294 : :
17295 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17296 : 0 : return -rte_mtr_error_set(error,
17297 : : ENOTSUP,
17298 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17299 : : NULL,
17300 : : "cannot create policy "
17301 : : "jump action for this color");
17302 : 0 : jump_group =
17303 : : ((const struct rte_flow_action_jump *)
17304 : 0 : act->conf)->group;
17305 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17306 : : jump_group,
17307 : : &table,
17308 : : &grp_info, &flow_err))
17309 : 0 : return -rte_mtr_error_set(error,
17310 : : ENOTSUP,
17311 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17312 : : NULL, "cannot setup "
17313 : : "policy jump action");
17314 : 0 : sub_policy->jump_tbl[i] =
17315 : 0 : flow_dv_tbl_resource_get(dev,
17316 : : table, egress,
17317 : : transfer,
17318 : : !!dev_flow.external,
17319 : : NULL, jump_group, 0,
17320 : : 0, &flow_err);
17321 : : if
17322 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17323 : 0 : return -rte_mtr_error_set(error,
17324 : : ENOTSUP,
17325 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17326 : : NULL, "cannot create jump action.");
17327 : 0 : tbl_data = container_of
17328 : : (sub_policy->jump_tbl[i],
17329 : : struct mlx5_flow_tbl_data_entry, tbl);
17330 : 0 : act_cnt->dr_jump_action[domain] =
17331 : 0 : tbl_data->jump.action;
17332 : 0 : act_cnt->fate_action =
17333 : : MLX5_FLOW_FATE_JUMP;
17334 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
17335 : 0 : break;
17336 : : }
17337 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17338 : : {
17339 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17340 : 0 : return -rte_mtr_error_set(error,
17341 : : ENOTSUP,
17342 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17343 : : NULL,
17344 : : "cannot create policy modify field for this color");
17345 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
17346 : : (dev, mhdr_res, act, attr, &flow_err))
17347 : 0 : return -rte_mtr_error_set(error,
17348 : : ENOTSUP,
17349 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17350 : : NULL, "cannot setup policy modify field action");
17351 [ # # ]: 0 : if (!mhdr_res->actions_num)
17352 : 0 : return -rte_mtr_error_set(error,
17353 : : ENOTSUP,
17354 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17355 : : NULL, "cannot find policy modify field action");
17356 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
17357 : 0 : break;
17358 : : }
17359 : : /*
17360 : : * No need to check meter hierarchy for R colors
17361 : : * here since it is done in the validation stage.
17362 : : */
17363 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
17364 : : {
17365 : : const struct rte_flow_action_meter *mtr;
17366 : : struct mlx5_flow_meter_info *next_fm;
17367 : : struct mlx5_flow_meter_policy *next_policy;
17368 : : struct rte_flow_action tag_action;
17369 : : struct mlx5_rte_flow_action_set_tag set_tag;
17370 : 0 : uint32_t next_mtr_idx = 0;
17371 : :
17372 : 0 : mtr = act->conf;
17373 : 0 : next_fm = mlx5_flow_meter_find(priv,
17374 : 0 : mtr->mtr_id,
17375 : : &next_mtr_idx);
17376 [ # # ]: 0 : if (!next_fm)
17377 : 0 : return -rte_mtr_error_set(error, EINVAL,
17378 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17379 : : "Fail to find next meter.");
17380 [ # # ]: 0 : if (next_fm->def_policy)
17381 : 0 : return -rte_mtr_error_set(error, EINVAL,
17382 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17383 : : "Hierarchy only supports termination meter.");
17384 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
17385 : : next_fm->policy_id, NULL);
17386 : : MLX5_ASSERT(next_policy);
17387 [ # # ]: 0 : if (next_fm->drop_cnt) {
17388 : 0 : set_tag.id =
17389 : 0 : (enum modify_reg)
17390 : 0 : mlx5_flow_get_reg_id(dev,
17391 : : MLX5_MTR_ID,
17392 : : 0,
17393 : : (struct rte_flow_error *)error);
17394 : 0 : set_tag.offset = (priv->mtr_reg_share ?
17395 : 0 : MLX5_MTR_COLOR_BITS : 0);
17396 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
17397 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
17398 : : MLX5_REG_BITS);
17399 : 0 : set_tag.data = next_mtr_idx;
17400 : 0 : tag_action.type =
17401 : : (enum rte_flow_action_type)
17402 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
17403 : 0 : tag_action.conf = &set_tag;
17404 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
17405 : : (mhdr_res, &tag_action,
17406 : : (struct rte_flow_error *)error))
17407 : 0 : return -rte_errno;
17408 : 0 : action_flags |=
17409 : : MLX5_FLOW_ACTION_SET_TAG;
17410 : : }
17411 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
17412 [ # # ]: 0 : !next_fm->meter_action_y)
17413 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
17414 : 0 : return -rte_errno;
17415 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
17416 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
17417 : 0 : act_cnt->next_sub_policy = NULL;
17418 : 0 : mtr_policy->is_hierarchy = 1;
17419 [ # # ]: 0 : if (next_policy->mark)
17420 : 0 : mtr_policy->mark = 1;
17421 : 0 : mtr_policy->hierarchy_match_port =
17422 : 0 : next_policy->hierarchy_match_port;
17423 : 0 : action_flags |=
17424 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17425 : 0 : break;
17426 : : }
17427 : : default:
17428 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
17429 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17430 : : NULL, "action type not supported");
17431 : : }
17432 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
17433 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
17434 : : /* create modify action if needed. */
17435 : 0 : dev_flow.dv.group = 1;
17436 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
17437 : : (dev, mhdr_res, &dev_flow, &flow_err))
17438 : 0 : return -rte_mtr_error_set(error,
17439 : : ENOTSUP,
17440 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17441 : : NULL, "cannot register policy set tag/modify field action");
17442 : 0 : act_cnt->modify_hdr =
17443 : 0 : dev_flow.handle->dvh.modify_hdr;
17444 : : }
17445 : : }
17446 : : }
17447 : : return 0;
17448 : : }
17449 : :
17450 : : /**
17451 : : * Create policy action per domain, lock free,
17452 : : * (mutex should be acquired by caller).
17453 : : * Dispatcher for action type specific call.
17454 : : *
17455 : : * @param[in] dev
17456 : : * Pointer to the Ethernet device structure.
17457 : : * @param[in] mtr_policy
17458 : : * Meter policy struct.
17459 : : * @param[in] action
17460 : : * Action specification used to create meter actions.
17461 : : * @param[in] attr
17462 : : * Pointer to the flow attributes.
17463 : : * @param[out] error
17464 : : * Perform verbose error reporting if not NULL. Initialized in case of
17465 : : * error only.
17466 : : *
17467 : : * @return
17468 : : * 0 on success, otherwise negative errno value.
17469 : : */
17470 : : static int
17471 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
17472 : : struct mlx5_flow_meter_policy *mtr_policy,
17473 : : const struct rte_flow_action *actions[RTE_COLORS],
17474 : : struct rte_flow_attr *attr,
17475 : : struct rte_mtr_error *error)
17476 : : {
17477 : : int ret, i;
17478 : : uint16_t sub_policy_num;
17479 : :
17480 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17481 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17482 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17483 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17484 [ # # ]: 0 : if (sub_policy_num) {
17485 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
17486 : : mtr_policy, actions, attr,
17487 : : (enum mlx5_meter_domain)i, error);
17488 : : /* Cleaning resource is done in the caller level. */
17489 [ # # ]: 0 : if (ret)
17490 : 0 : return ret;
17491 : : }
17492 : : }
17493 : : return 0;
17494 : : }
17495 : :
17496 : : /**
17497 : : * Query a DV flow rule for its statistics via DevX.
17498 : : *
17499 : : * @param[in] dev
17500 : : * Pointer to Ethernet device.
17501 : : * @param[in] cnt_idx
17502 : : * Index to the flow counter.
17503 : : * @param[out] data
17504 : : * Data retrieved by the query.
17505 : : * @param[out] error
17506 : : * Perform verbose error reporting if not NULL.
17507 : : *
17508 : : * @return
17509 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17510 : : */
17511 : : static int
17512 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
17513 : : struct rte_flow_error *error)
17514 : : {
17515 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17516 : : struct rte_flow_query_count *qc = data;
17517 : :
17518 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
17519 : 0 : return rte_flow_error_set(error, ENOTSUP,
17520 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17521 : : NULL,
17522 : : "counters are not supported");
17523 [ # # ]: 0 : if (cnt_idx) {
17524 : : uint64_t pkts, bytes;
17525 : : struct mlx5_flow_counter *cnt;
17526 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
17527 : :
17528 [ # # ]: 0 : if (err)
17529 : 0 : return rte_flow_error_set(error, -err,
17530 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17531 : : NULL, "cannot read counters");
17532 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
17533 : 0 : qc->hits_set = 1;
17534 : 0 : qc->bytes_set = 1;
17535 : 0 : qc->hits = pkts - cnt->hits;
17536 : 0 : qc->bytes = bytes - cnt->bytes;
17537 [ # # ]: 0 : if (qc->reset) {
17538 : 0 : cnt->hits = pkts;
17539 : 0 : cnt->bytes = bytes;
17540 : : }
17541 : 0 : return 0;
17542 : : }
17543 : 0 : return rte_flow_error_set(error, EINVAL,
17544 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17545 : : NULL,
17546 : : "counters are not available");
17547 : : }
17548 : :
17549 : : int
17550 : 0 : flow_dv_action_query(struct rte_eth_dev *dev,
17551 : : const struct rte_flow_action_handle *handle, void *data,
17552 : : struct rte_flow_error *error)
17553 : : {
17554 : : struct mlx5_age_param *age_param;
17555 : : struct rte_flow_query_age *resp;
17556 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17557 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17558 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17559 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17560 : : struct mlx5_aso_ct_action *ct;
17561 : : uint16_t owner;
17562 : : uint32_t dev_idx;
17563 : :
17564 [ # # # # ]: 0 : switch (type) {
17565 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17566 : 0 : age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
17567 : : resp = data;
17568 : 0 : resp->aged = __atomic_load_n(&age_param->state,
17569 : : __ATOMIC_RELAXED) == AGE_TMOUT ?
17570 : 0 : 1 : 0;
17571 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
17572 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
17573 : 0 : resp->sec_since_last_hit = __atomic_load_n
17574 : 0 : (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
17575 : : return 0;
17576 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17577 : 0 : return flow_dv_query_count(dev, idx, data, error);
17578 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17579 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17580 [ # # ]: 0 : if (owner != PORT_ID(priv))
17581 : 0 : return rte_flow_error_set(error, EACCES,
17582 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17583 : : NULL,
17584 : : "CT object owned by another port");
17585 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17586 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17587 : : MLX5_ASSERT(ct);
17588 [ # # ]: 0 : if (!ct->refcnt)
17589 : 0 : return rte_flow_error_set(error, EFAULT,
17590 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17591 : : NULL,
17592 : : "CT object is inactive");
17593 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
17594 : 0 : ct->peer;
17595 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
17596 : 0 : ct->is_original;
17597 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
17598 : : data, NULL, true))
17599 : 0 : return rte_flow_error_set(error, EIO,
17600 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17601 : : NULL,
17602 : : "Failed to query CT context");
17603 : : return 0;
17604 : 0 : default:
17605 : 0 : return rte_flow_error_set(error, ENOTSUP,
17606 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17607 : : "action type query not supported");
17608 : : }
17609 : : }
17610 : :
17611 : : /**
17612 : : * Query a flow rule AGE action for aging information.
17613 : : *
17614 : : * @param[in] dev
17615 : : * Pointer to Ethernet device.
17616 : : * @param[in] flow
17617 : : * Pointer to the sub flow.
17618 : : * @param[out] data
17619 : : * data retrieved by the query.
17620 : : * @param[out] error
17621 : : * Perform verbose error reporting if not NULL.
17622 : : *
17623 : : * @return
17624 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17625 : : */
17626 : : static int
17627 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
17628 : : void *data, struct rte_flow_error *error)
17629 : : {
17630 : : struct rte_flow_query_age *resp = data;
17631 : : struct mlx5_age_param *age_param;
17632 : :
17633 [ # # ]: 0 : if (flow->age) {
17634 : : struct mlx5_aso_age_action *act =
17635 : 0 : flow_aso_age_get_by_idx(dev, flow->age);
17636 : :
17637 : 0 : age_param = &act->age_params;
17638 [ # # ]: 0 : } else if (flow->counter) {
17639 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
17640 : :
17641 [ # # ]: 0 : if (!age_param || !age_param->timeout)
17642 : 0 : return rte_flow_error_set
17643 : : (error, EINVAL,
17644 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17645 : : NULL, "cannot read age data");
17646 : : } else {
17647 : 0 : return rte_flow_error_set(error, EINVAL,
17648 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17649 : : NULL, "age data not available");
17650 : : }
17651 : 0 : resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
17652 : 0 : AGE_TMOUT ? 1 : 0;
17653 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
17654 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
17655 : 0 : resp->sec_since_last_hit = __atomic_load_n
17656 : 0 : (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
17657 : : return 0;
17658 : : }
17659 : :
17660 : : /**
17661 : : * Query a flow.
17662 : : *
17663 : : * @see rte_flow_query()
17664 : : * @see rte_flow_ops
17665 : : */
17666 : : static int
17667 : 0 : flow_dv_query(struct rte_eth_dev *dev,
17668 : : struct rte_flow *flow __rte_unused,
17669 : : const struct rte_flow_action *actions __rte_unused,
17670 : : void *data __rte_unused,
17671 : : struct rte_flow_error *error __rte_unused)
17672 : : {
17673 : : int ret = -EINVAL;
17674 : :
17675 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
17676 [ # # # # ]: 0 : switch (actions->type) {
17677 : : case RTE_FLOW_ACTION_TYPE_VOID:
17678 : : break;
17679 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17680 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
17681 : : error);
17682 : 0 : break;
17683 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17684 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
17685 : 0 : break;
17686 : 0 : default:
17687 : 0 : return rte_flow_error_set(error, ENOTSUP,
17688 : : RTE_FLOW_ERROR_TYPE_ACTION,
17689 : : actions,
17690 : : "action not supported");
17691 : : }
17692 : : }
17693 : : return ret;
17694 : : }
17695 : :
17696 : : /**
17697 : : * Destroy the meter table set.
17698 : : * Lock free, (mutex should be acquired by caller).
17699 : : *
17700 : : * @param[in] dev
17701 : : * Pointer to Ethernet device.
17702 : : * @param[in] fm
17703 : : * Meter information table.
17704 : : */
17705 : : static void
17706 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
17707 : : struct mlx5_flow_meter_info *fm)
17708 : : {
17709 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17710 : : int i;
17711 : :
17712 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
17713 : : return;
17714 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17715 [ # # ]: 0 : if (fm->drop_rule[i]) {
17716 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
17717 : 0 : fm->drop_rule[i] = NULL;
17718 : : }
17719 : : }
17720 : : }
17721 : :
17722 : : static void
17723 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
17724 : : {
17725 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17726 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
17727 : : struct mlx5_flow_tbl_data_entry *tbl;
17728 : : int i, j;
17729 : :
17730 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17731 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
17732 : : claim_zero(mlx5_flow_os_destroy_flow
17733 : : (mtrmng->def_rule[i]));
17734 : 0 : mtrmng->def_rule[i] = NULL;
17735 : : }
17736 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
17737 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
17738 : : struct mlx5_flow_tbl_data_entry, tbl);
17739 : 0 : mlx5_list_unregister(tbl->matchers,
17740 : : &mtrmng->def_matcher[i]->entry);
17741 : 0 : mtrmng->def_matcher[i] = NULL;
17742 : : }
17743 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
17744 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
17745 : : tbl =
17746 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
17747 : : struct mlx5_flow_tbl_data_entry,
17748 : : tbl);
17749 : 0 : mlx5_list_unregister(tbl->matchers,
17750 : : &mtrmng->drop_matcher[i][j]->entry);
17751 : 0 : mtrmng->drop_matcher[i][j] = NULL;
17752 : : }
17753 : : }
17754 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
17755 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17756 : : mtrmng->drop_tbl[i]);
17757 : 0 : mtrmng->drop_tbl[i] = NULL;
17758 : : }
17759 : : }
17760 : 0 : }
17761 : :
17762 : : /* Number of meter flow actions, count and jump or count and drop. */
17763 : : #define METER_ACTIONS 2
17764 : :
17765 : : static void
17766 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
17767 : : enum mlx5_meter_domain domain)
17768 : : {
17769 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17770 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
17771 : 0 : priv->sh->mtrmng->def_policy[domain];
17772 : :
17773 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
17774 : 0 : mlx5_free(def_policy);
17775 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
17776 : 0 : }
17777 : :
17778 : : /**
17779 : : * Destroy the default policy table set.
17780 : : *
17781 : : * @param[in] dev
17782 : : * Pointer to Ethernet device.
17783 : : */
17784 : : static void
17785 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
17786 : : {
17787 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17788 : : int i;
17789 : :
17790 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
17791 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
17792 : 0 : __flow_dv_destroy_domain_def_policy(dev,
17793 : : (enum mlx5_meter_domain)i);
17794 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
17795 : 0 : }
17796 : :
17797 : : static int
17798 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
17799 : : uint32_t color_reg_c_idx,
17800 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
17801 : : int actions_n, void *actions,
17802 : : bool match_src_port, const struct rte_flow_item *item,
17803 : : void **rule, const struct rte_flow_attr *attr)
17804 : : {
17805 : : int ret;
17806 : 0 : struct mlx5_flow_dv_match_params value = {
17807 : : .size = sizeof(value.buf),
17808 : : };
17809 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17810 : : uint8_t misc_mask;
17811 : :
17812 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
17813 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
17814 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
17815 : : item, attr, MLX5_SET_MATCHER_SW_V);
17816 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
17817 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
17818 : : MLX5_SET_MATCHER_SW_V);
17819 : : else
17820 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
17821 : : item, attr, MLX5_SET_MATCHER_SW_V);
17822 [ # # ]: 0 : if (ret) {
17823 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
17824 : : " value with port.", color);
17825 : 0 : return -1;
17826 : : }
17827 : : }
17828 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
17829 : : rte_col_2_mlx5_col(color), UINT32_MAX);
17830 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
17831 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
17832 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
17833 : : actions_n, actions, rule);
17834 : : if (ret) {
17835 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
17836 : 0 : return -1;
17837 : : }
17838 : : return 0;
17839 : : }
17840 : :
17841 : : static int
17842 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
17843 : : uint32_t color_reg_c_idx,
17844 : : uint16_t priority,
17845 : : struct mlx5_flow_meter_sub_policy *sub_policy,
17846 : : const struct rte_flow_attr *attr,
17847 : : bool match_src_port,
17848 : : const struct rte_flow_item *item,
17849 : : struct mlx5_flow_dv_matcher **policy_matcher,
17850 : : struct rte_flow_error *error)
17851 : : {
17852 : : struct mlx5_list_entry *entry;
17853 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
17854 : 0 : struct mlx5_flow_dv_matcher matcher = {
17855 : : .mask = {
17856 : : .size = sizeof(matcher.mask.buf),
17857 : : },
17858 : : .tbl = tbl_rsc,
17859 : : };
17860 : 0 : struct mlx5_flow_cb_ctx ctx = {
17861 : : .error = error,
17862 : : .data = &matcher,
17863 : : };
17864 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17865 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17866 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
17867 : : int ret;
17868 : :
17869 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
17870 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
17871 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
17872 : : item, attr, MLX5_SET_MATCHER_SW_M);
17873 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
17874 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
17875 : : MLX5_SET_MATCHER_SW_M);
17876 : : else
17877 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
17878 : : item, attr, MLX5_SET_MATCHER_SW_M);
17879 [ # # ]: 0 : if (ret) {
17880 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
17881 : : " with port.", priority);
17882 : 0 : return -1;
17883 : : }
17884 : : }
17885 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
17886 [ # # ]: 0 : if (priority < RTE_COLOR_RED)
17887 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
17888 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
17889 : 0 : matcher.priority = priority;
17890 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
17891 : : matcher.mask.size);
17892 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
17893 [ # # ]: 0 : if (!entry) {
17894 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
17895 : 0 : return -1;
17896 : : }
17897 : 0 : *policy_matcher =
17898 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
17899 : 0 : return 0;
17900 : : }
17901 : :
17902 : : /**
17903 : : * Create the policy rules per domain.
17904 : : *
17905 : : * @param[in] dev
17906 : : * Pointer to Ethernet device.
17907 : : * @param[in] sub_policy
17908 : : * Pointer to sub policy table..
17909 : : * @param[in] egress
17910 : : * Direction of the table.
17911 : : * @param[in] transfer
17912 : : * E-Switch or NIC flow.
17913 : : * @param[in] acts
17914 : : * Pointer to policy action list per color.
17915 : : *
17916 : : * @return
17917 : : * 0 on success, -1 otherwise.
17918 : : */
17919 : : static int
17920 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
17921 : : struct mlx5_flow_meter_sub_policy *sub_policy,
17922 : : uint8_t egress, uint8_t transfer, bool match_src_port,
17923 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
17924 : : {
17925 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17926 : : struct rte_flow_error flow_err;
17927 : : uint32_t color_reg_c_idx;
17928 : 0 : struct rte_flow_attr attr = {
17929 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
17930 : : .priority = 0,
17931 : : .ingress = 0,
17932 : 0 : .egress = !!egress,
17933 : 0 : .transfer = !!transfer,
17934 : : .reserved = 0,
17935 : : };
17936 : : int i;
17937 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17938 : : struct mlx5_sub_policy_color_rule *color_rule;
17939 : : bool svport_match;
17940 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
17941 : :
17942 [ # # ]: 0 : if (ret < 0)
17943 : : return -1;
17944 : : /* Create policy table with POLICY level. */
17945 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
17946 : 0 : sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
17947 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
17948 : : egress, transfer, false, NULL, 0, 0,
17949 : 0 : sub_policy->idx, &flow_err);
17950 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
17951 : 0 : DRV_LOG(ERR,
17952 : : "Failed to create meter sub policy table.");
17953 : 0 : return -1;
17954 : : }
17955 : : /* Prepare matchers. */
17956 : 0 : color_reg_c_idx = ret;
17957 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17958 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
17959 [ # # ]: 0 : if (!acts[i].actions_n)
17960 : 0 : continue;
17961 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
17962 : : sizeof(struct mlx5_sub_policy_color_rule),
17963 : : 0, SOCKET_ID_ANY);
17964 [ # # ]: 0 : if (!color_rule) {
17965 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
17966 : 0 : goto err_exit;
17967 : : }
17968 : 0 : tmp_rules[i] = color_rule;
17969 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
17970 : : color_rule, next_port);
17971 : 0 : color_rule->src_port = priv->representor_id;
17972 : : /* No use. */
17973 : 0 : attr.priority = i;
17974 : : /* Create matchers for colors. */
17975 [ # # # # ]: 0 : svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
17976 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
17977 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
17978 : : &attr, svport_match, NULL,
17979 : : &color_rule->matcher, &flow_err)) {
17980 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
17981 : 0 : goto err_exit;
17982 : : }
17983 : : /* Create flow, matching color. */
17984 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
17985 : : color_reg_c_idx, (enum rte_color)i,
17986 : : color_rule->matcher,
17987 : 0 : acts[i].actions_n, acts[i].dv_actions,
17988 : : svport_match, NULL, &color_rule->rule,
17989 : : &attr)) {
17990 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
17991 : 0 : goto err_exit;
17992 : : }
17993 : : }
17994 : : return 0;
17995 : : err_exit:
17996 : : /* All the policy rules will be cleared. */
17997 : : do {
17998 : 0 : color_rule = tmp_rules[i];
17999 [ # # ]: 0 : if (color_rule) {
18000 [ # # ]: 0 : if (color_rule->rule)
18001 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18002 [ # # ]: 0 : if (color_rule->matcher) {
18003 : : struct mlx5_flow_tbl_data_entry *tbl =
18004 : 0 : container_of(color_rule->matcher->tbl,
18005 : : typeof(*tbl), tbl);
18006 : 0 : mlx5_list_unregister(tbl->matchers,
18007 : : &color_rule->matcher->entry);
18008 : : }
18009 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18010 : : color_rule, next_port);
18011 : 0 : mlx5_free(color_rule);
18012 : : }
18013 [ # # ]: 0 : } while (i--);
18014 : : return -1;
18015 : : }
18016 : :
18017 : : static int
18018 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18019 : : struct mlx5_flow_meter_policy *mtr_policy,
18020 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18021 : : uint32_t domain)
18022 : : {
18023 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18024 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18025 : : struct mlx5_flow_dv_tag_resource *tag;
18026 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18027 : : struct mlx5_hrxq *hrxq;
18028 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18029 : : struct mlx5_flow_meter_policy *next_policy;
18030 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18031 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18032 : : struct rte_flow_error error;
18033 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18034 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18035 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18036 : : bool match_src_port = false;
18037 : : int i;
18038 : :
18039 : : /* If RSS or Queue, no previous actions / rules is created. */
18040 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18041 : 0 : acts[i].actions_n = 0;
18042 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18043 : : /* Only support drop on red. */
18044 : 0 : acts[i].dv_actions[0] =
18045 : 0 : mtr_policy->dr_drop_action[domain];
18046 : 0 : acts[i].actions_n = 1;
18047 : 0 : continue;
18048 : : }
18049 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18050 : 0 : struct rte_flow_attr attr = {
18051 : : .transfer = transfer
18052 : : };
18053 : :
18054 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18055 : : mtr_policy->act_cnt[i].next_mtr_id,
18056 : : NULL);
18057 [ # # ]: 0 : if (!next_fm[i]) {
18058 : 0 : DRV_LOG(ERR,
18059 : : "Failed to get next hierarchy meter.");
18060 : 0 : goto err_exit;
18061 : : }
18062 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18063 : : &attr, &error)) {
18064 : 0 : DRV_LOG(ERR, "%s", error.message);
18065 : 0 : next_fm[i] = NULL;
18066 : 0 : goto err_exit;
18067 : : }
18068 : : /* Meter action must be the first for TX. */
18069 [ # # ]: 0 : if (mtr_first) {
18070 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18071 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18072 [ # # ]: 0 : next_fm[i]->meter_action_y :
18073 : : next_fm[i]->meter_action_g;
18074 : 0 : acts[i].actions_n++;
18075 : : }
18076 : : }
18077 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18078 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18079 : : mtr_policy->act_cnt[i].rix_mark);
18080 [ # # ]: 0 : if (!tag) {
18081 : 0 : DRV_LOG(ERR, "Failed to find "
18082 : : "mark action for policy.");
18083 : 0 : goto err_exit;
18084 : : }
18085 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18086 : 0 : acts[i].actions_n++;
18087 : : }
18088 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18089 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18090 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18091 : 0 : acts[i].actions_n++;
18092 : : }
18093 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18094 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18095 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18096 : 0 : port_action = mlx5_ipool_get
18097 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18098 : : mtr_policy->act_cnt[i].rix_port_id_action);
18099 [ # # ]: 0 : if (!port_action) {
18100 : 0 : DRV_LOG(ERR, "Failed to find "
18101 : : "port action for policy.");
18102 : 0 : goto err_exit;
18103 : : }
18104 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18105 : 0 : port_action->action;
18106 : 0 : acts[i].actions_n++;
18107 : : match_src_port = true;
18108 : 0 : break;
18109 : 0 : case MLX5_FLOW_FATE_DROP:
18110 : : case MLX5_FLOW_FATE_JUMP:
18111 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18112 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18113 : 0 : acts[i].actions_n++;
18114 : 0 : break;
18115 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18116 : : case MLX5_FLOW_FATE_QUEUE:
18117 : 0 : hrxq = mlx5_ipool_get
18118 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18119 : : sub_policy->rix_hrxq[i]);
18120 [ # # ]: 0 : if (!hrxq) {
18121 : 0 : DRV_LOG(ERR, "Failed to find "
18122 : : "queue action for policy.");
18123 : 0 : goto err_exit;
18124 : : }
18125 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18126 : 0 : hrxq->action;
18127 : 0 : acts[i].actions_n++;
18128 : 0 : break;
18129 : 0 : case MLX5_FLOW_FATE_MTR:
18130 [ # # ]: 0 : if (!next_fm[i]) {
18131 : 0 : DRV_LOG(ERR,
18132 : : "No next hierarchy meter.");
18133 : 0 : goto err_exit;
18134 : : }
18135 [ # # ]: 0 : if (!mtr_first) {
18136 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18137 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18138 [ # # ]: 0 : next_fm[i]->meter_action_y :
18139 : : next_fm[i]->meter_action_g;
18140 : 0 : acts[i].actions_n++;
18141 : : }
18142 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18143 : : next_sub_policy =
18144 : : mtr_policy->act_cnt[i].next_sub_policy;
18145 : : } else {
18146 : : next_policy =
18147 : 0 : mlx5_flow_meter_policy_find(dev,
18148 : : next_fm[i]->policy_id, NULL);
18149 : : MLX5_ASSERT(next_policy);
18150 : 0 : next_sub_policy =
18151 : 0 : next_policy->sub_policys[domain][0];
18152 : : }
18153 : : tbl_data =
18154 : 0 : container_of(next_sub_policy->tbl_rsc,
18155 : : struct mlx5_flow_tbl_data_entry, tbl);
18156 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18157 : 0 : tbl_data->jump.action;
18158 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18159 : : match_src_port = !!transfer;
18160 : : break;
18161 : : default:
18162 : : /*Queue action do nothing*/
18163 : : break;
18164 : : }
18165 : : }
18166 : : }
18167 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18168 : : egress, transfer, match_src_port, acts)) {
18169 : 0 : DRV_LOG(ERR,
18170 : : "Failed to create policy rules per domain.");
18171 : 0 : goto err_exit;
18172 : : }
18173 [ # # ]: 0 : if (match_src_port) {
18174 : 0 : mtr_policy->match_port = match_src_port;
18175 : 0 : mtr_policy->hierarchy_match_port = match_src_port;
18176 : : }
18177 : : return 0;
18178 : : err_exit:
18179 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18180 [ # # ]: 0 : if (next_fm[i])
18181 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18182 : : return -1;
18183 : : }
18184 : :
18185 : : /**
18186 : : * Create the policy rules.
18187 : : *
18188 : : * @param[in] dev
18189 : : * Pointer to Ethernet device.
18190 : : * @param[in,out] mtr_policy
18191 : : * Pointer to meter policy table.
18192 : : *
18193 : : * @return
18194 : : * 0 on success, -1 otherwise.
18195 : : */
18196 : : static int
18197 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18198 : : struct mlx5_flow_meter_policy *mtr_policy)
18199 : : {
18200 : : int i;
18201 : : int ret = 0;
18202 : : uint16_t sub_policy_num;
18203 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18204 : :
18205 : : RTE_SET_USED(wks);
18206 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18207 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18208 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18209 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18210 [ # # ]: 0 : if (!sub_policy_num)
18211 : 0 : continue;
18212 : : /* Prepare actions list and create policy rules. */
18213 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18214 : 0 : mtr_policy->sub_policys[i][0], i)) {
18215 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18216 : : "list per domain.");
18217 : : ret = -1;
18218 : 0 : goto exit;
18219 : : }
18220 : : }
18221 : 0 : exit:
18222 : 0 : mlx5_flow_pop_thread_workspace();
18223 : 0 : return ret;
18224 : : }
18225 : :
18226 : : static int
18227 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18228 : : {
18229 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18230 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18231 : : struct mlx5_flow_meter_def_policy *def_policy;
18232 : : struct mlx5_flow_tbl_resource *jump_tbl;
18233 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18234 : : uint8_t egress, transfer;
18235 : : struct rte_flow_error error;
18236 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18237 : : int ret;
18238 : :
18239 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18240 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18241 : 0 : def_policy = mtrmng->def_policy[domain];
18242 [ # # ]: 0 : if (!def_policy) {
18243 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18244 : : sizeof(struct mlx5_flow_meter_def_policy),
18245 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18246 [ # # ]: 0 : if (!def_policy) {
18247 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18248 : 0 : goto def_policy_error;
18249 : : }
18250 : 0 : mtrmng->def_policy[domain] = def_policy;
18251 : : /* Create the meter suffix table with SUFFIX level. */
18252 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18253 : : MLX5_FLOW_TABLE_LEVEL_METER,
18254 : : egress, transfer, false, NULL, 0,
18255 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18256 [ # # ]: 0 : if (!jump_tbl) {
18257 : 0 : DRV_LOG(ERR,
18258 : : "Failed to create meter suffix table.");
18259 : 0 : goto def_policy_error;
18260 : : }
18261 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18262 : 0 : tbl_data = container_of(jump_tbl,
18263 : : struct mlx5_flow_tbl_data_entry, tbl);
18264 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18265 : 0 : tbl_data->jump.action;
18266 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18267 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18268 : : /*
18269 : : * YELLOW has the same default policy as GREEN does.
18270 : : * G & Y share the same table and action. The 2nd time of table
18271 : : * resource getting is just to update the reference count for
18272 : : * the releasing stage.
18273 : : */
18274 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18275 : : MLX5_FLOW_TABLE_LEVEL_METER,
18276 : : egress, transfer, false, NULL, 0,
18277 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18278 [ # # ]: 0 : if (!jump_tbl) {
18279 : 0 : DRV_LOG(ERR,
18280 : : "Failed to get meter suffix table.");
18281 : 0 : goto def_policy_error;
18282 : : }
18283 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18284 : 0 : tbl_data = container_of(jump_tbl,
18285 : : struct mlx5_flow_tbl_data_entry, tbl);
18286 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18287 : 0 : tbl_data->jump.action;
18288 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18289 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18290 : : /* Create jump action to the drop table. */
18291 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18292 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
18293 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18294 : : egress, transfer, false, NULL, 0,
18295 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18296 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18297 : 0 : DRV_LOG(ERR, "Failed to create meter "
18298 : : "drop table for default policy.");
18299 : 0 : goto def_policy_error;
18300 : : }
18301 : : }
18302 : : /* all RED: unique Drop table for jump action. */
18303 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18304 : : struct mlx5_flow_tbl_data_entry, tbl);
18305 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18306 : 0 : tbl_data->jump.action;
18307 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18308 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18309 : : /* Create default policy rules. */
18310 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18311 : : &def_policy->sub_policy,
18312 : : egress, transfer, false, acts);
18313 [ # # ]: 0 : if (ret) {
18314 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18315 : 0 : goto def_policy_error;
18316 : : }
18317 : : }
18318 : : return 0;
18319 : 0 : def_policy_error:
18320 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18321 : : (enum mlx5_meter_domain)domain);
18322 : 0 : return -1;
18323 : : }
18324 : :
18325 : : /**
18326 : : * Create the default policy table set.
18327 : : *
18328 : : * @param[in] dev
18329 : : * Pointer to Ethernet device.
18330 : : * @return
18331 : : * 0 on success, -1 otherwise.
18332 : : */
18333 : : static int
18334 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
18335 : : {
18336 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18337 : : int i;
18338 : :
18339 : : /* Non-termination policy table. */
18340 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18341 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
18342 : : i == MLX5_MTR_DOMAIN_TRANSFER)
18343 : 0 : continue;
18344 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
18345 : 0 : DRV_LOG(ERR, "Failed to create default policy");
18346 : : /* Rollback the created default policies for others. */
18347 : 0 : flow_dv_destroy_def_policy(dev);
18348 : 0 : return -1;
18349 : : }
18350 : : }
18351 : : return 0;
18352 : : }
18353 : :
18354 : : /**
18355 : : * Create the needed meter tables.
18356 : : * Lock free, (mutex should be acquired by caller).
18357 : : *
18358 : : * @param[in] dev
18359 : : * Pointer to Ethernet device.
18360 : : * @param[in] fm
18361 : : * Meter information table.
18362 : : * @param[in] mtr_idx
18363 : : * Meter index.
18364 : : * @param[in] domain_bitmap
18365 : : * Domain bitmap.
18366 : : * @return
18367 : : * 0 on success, -1 otherwise.
18368 : : */
18369 : : static int
18370 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
18371 : : struct mlx5_flow_meter_info *fm,
18372 : : uint32_t mtr_idx,
18373 : : uint8_t domain_bitmap)
18374 : : {
18375 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18376 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18377 : : struct rte_flow_error error;
18378 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18379 : : uint8_t egress, transfer;
18380 : : void *actions[METER_ACTIONS];
18381 : : int domain, ret, i;
18382 : : struct mlx5_flow_counter *cnt;
18383 : 0 : struct mlx5_flow_dv_match_params value = {
18384 : : .size = sizeof(value.buf),
18385 : : };
18386 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
18387 : : .size = sizeof(matcher_para.buf),
18388 : : };
18389 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
18390 : : 0, &error);
18391 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
18392 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
18393 : : struct mlx5_list_entry *entry;
18394 : 0 : struct mlx5_flow_dv_matcher matcher = {
18395 : : .mask = {
18396 : : .size = sizeof(matcher.mask.buf),
18397 : : },
18398 : : };
18399 : : struct mlx5_flow_dv_matcher *drop_matcher;
18400 : 0 : struct mlx5_flow_cb_ctx ctx = {
18401 : : .error = &error,
18402 : : .data = &matcher,
18403 : : };
18404 : : uint8_t misc_mask;
18405 : :
18406 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
18407 : 0 : rte_errno = ENOTSUP;
18408 : 0 : return -1;
18409 : : }
18410 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
18411 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
18412 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
18413 : 0 : continue;
18414 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18415 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18416 : : /* Create the drop table with METER DROP level. */
18417 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18418 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
18419 : : MLX5_FLOW_TABLE_LEVEL_METER,
18420 : : egress, transfer, false, NULL, 0,
18421 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18422 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18423 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
18424 : 0 : goto policy_error;
18425 : : }
18426 : : }
18427 : : /* Create default matcher in drop table. */
18428 : 0 : matcher.tbl = mtrmng->drop_tbl[domain],
18429 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18430 : : struct mlx5_flow_tbl_data_entry, tbl);
18431 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
18432 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18433 : : (enum modify_reg)mtr_id_reg_c,
18434 : : 0, 0);
18435 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
18436 : 0 : matcher.crc = rte_raw_cksum
18437 : : ((const void *)matcher.mask.buf,
18438 : : matcher.mask.size);
18439 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18440 [ # # ]: 0 : if (!entry) {
18441 : 0 : DRV_LOG(ERR, "Failed to register meter "
18442 : : "drop default matcher.");
18443 : 0 : goto policy_error;
18444 : : }
18445 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
18446 : : struct mlx5_flow_dv_matcher, entry);
18447 : : }
18448 : : /* Create default rule in drop table. */
18449 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
18450 : : i = 0;
18451 : 0 : actions[i++] = priv->sh->dr_drop_action;
18452 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18453 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
18454 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
18455 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18456 : 0 : ret = mlx5_flow_os_create_flow
18457 : : (mtrmng->def_matcher[domain]->matcher_object,
18458 : : (void *)&value, i, actions,
18459 : : &mtrmng->def_rule[domain]);
18460 : : if (ret) {
18461 : 0 : DRV_LOG(ERR, "Failed to create meter "
18462 : : "default drop rule for drop table.");
18463 : 0 : goto policy_error;
18464 : : }
18465 : : }
18466 [ # # ]: 0 : if (!fm->drop_cnt)
18467 : 0 : continue;
18468 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
18469 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
18470 : : /* Create matchers for Drop. */
18471 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18472 : : (enum modify_reg)mtr_id_reg_c, 0,
18473 : : (mtr_id_mask << mtr_id_offset));
18474 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
18475 : 0 : matcher.crc = rte_raw_cksum
18476 : : ((const void *)matcher.mask.buf,
18477 : : matcher.mask.size);
18478 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18479 [ # # ]: 0 : if (!entry) {
18480 : 0 : DRV_LOG(ERR,
18481 : : "Failed to register meter drop matcher.");
18482 : 0 : goto policy_error;
18483 : : }
18484 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
18485 : : container_of(entry, struct mlx5_flow_dv_matcher,
18486 : : entry);
18487 : : }
18488 : 0 : drop_matcher =
18489 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
18490 : : /* Create drop rule, matching meter_id only. */
18491 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18492 : : (enum modify_reg)mtr_id_reg_c,
18493 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
18494 : : i = 0;
18495 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
18496 : : fm->drop_cnt, NULL);
18497 : 0 : actions[i++] = cnt->action;
18498 : 0 : actions[i++] = priv->sh->dr_drop_action;
18499 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
18500 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18501 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
18502 : : (void *)&value, i, actions,
18503 : : &fm->drop_rule[domain]);
18504 : : if (ret) {
18505 : 0 : DRV_LOG(ERR, "Failed to create meter "
18506 : : "drop rule for drop table.");
18507 : 0 : goto policy_error;
18508 : : }
18509 : : }
18510 : : return 0;
18511 : : policy_error:
18512 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18513 [ # # ]: 0 : if (fm->drop_rule[i]) {
18514 : : claim_zero(mlx5_flow_os_destroy_flow
18515 : : (fm->drop_rule[i]));
18516 : 0 : fm->drop_rule[i] = NULL;
18517 : : }
18518 : : }
18519 : : return -1;
18520 : : }
18521 : :
18522 : : static struct mlx5_flow_meter_sub_policy *
18523 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
18524 : : struct mlx5_flow_meter_policy *mtr_policy,
18525 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
18526 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
18527 : : bool *is_reuse)
18528 : : {
18529 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18530 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
18531 : 0 : uint32_t sub_policy_idx = 0;
18532 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
18533 : : uint32_t i, j;
18534 : : struct mlx5_hrxq *hrxq;
18535 : : struct mlx5_flow_handle dh;
18536 : : struct mlx5_meter_policy_action_container *act_cnt;
18537 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
18538 : : uint16_t sub_policy_num;
18539 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
18540 : :
18541 : : MLX5_ASSERT(wks);
18542 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18543 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18544 [ # # ]: 0 : if (!rss_desc[i])
18545 : 0 : continue;
18546 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
18547 [ # # ]: 0 : if (!hrxq) {
18548 : : rte_spinlock_unlock(&mtr_policy->sl);
18549 : 0 : return NULL;
18550 : : }
18551 : 0 : hrxq_idx[i] = hrxq->idx;
18552 : : }
18553 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18554 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18555 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18556 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
18557 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18558 [ # # ]: 0 : if (rss_desc[i] &&
18559 : 0 : hrxq_idx[i] !=
18560 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
18561 : : break;
18562 : : }
18563 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
18564 : : /*
18565 : : * Found the sub policy table with
18566 : : * the same queue per color.
18567 : : */
18568 : : rte_spinlock_unlock(&mtr_policy->sl);
18569 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
18570 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18571 : 0 : *is_reuse = true;
18572 : 0 : return mtr_policy->sub_policys[domain][j];
18573 : : }
18574 : : }
18575 : : /* Create sub policy. */
18576 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
18577 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
18578 : : /* Reuse the first pre-allocated sub_policy. */
18579 : : sub_policy = mtr_policy->sub_policys[domain][0];
18580 : 0 : sub_policy_idx = sub_policy->idx;
18581 : : } else {
18582 : 0 : sub_policy = mlx5_ipool_zmalloc
18583 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18584 : : &sub_policy_idx);
18585 [ # # ]: 0 : if (!sub_policy ||
18586 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
18587 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
18588 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18589 : 0 : goto rss_sub_policy_error;
18590 : : }
18591 : 0 : sub_policy->idx = sub_policy_idx;
18592 : 0 : sub_policy->main_policy = mtr_policy;
18593 : : }
18594 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18595 [ # # ]: 0 : if (!rss_desc[i])
18596 : 0 : continue;
18597 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
18598 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
18599 : : act_cnt = &mtr_policy->act_cnt[i];
18600 : 0 : act_cnt->next_sub_policy = next_sub_policy;
18601 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18602 : : } else {
18603 : : /*
18604 : : * Overwrite the last action from
18605 : : * RSS action to Queue action.
18606 : : */
18607 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
18608 : : hrxq_idx[i]);
18609 [ # # ]: 0 : if (!hrxq) {
18610 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
18611 : 0 : goto rss_sub_policy_error;
18612 : : }
18613 : : act_cnt = &mtr_policy->act_cnt[i];
18614 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
18615 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
18616 [ # # ]: 0 : if (act_cnt->rix_mark)
18617 : 0 : wks->mark = 1;
18618 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
18619 : 0 : dh.rix_hrxq = hrxq_idx[i];
18620 : 0 : flow_drv_rxq_flags_set(dev, &dh);
18621 : : }
18622 : : }
18623 : : }
18624 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18625 : : sub_policy, domain)) {
18626 : 0 : DRV_LOG(ERR, "Failed to create policy "
18627 : : "rules for ingress domain.");
18628 : 0 : goto rss_sub_policy_error;
18629 : : }
18630 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
18631 : 0 : i = (mtr_policy->sub_policy_num >>
18632 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18633 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18634 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
18635 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
18636 : 0 : goto rss_sub_policy_error;
18637 : : }
18638 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
18639 : 0 : i++;
18640 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
18641 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
18642 : 0 : mtr_policy->sub_policy_num |=
18643 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
18644 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
18645 : : }
18646 : : rte_spinlock_unlock(&mtr_policy->sl);
18647 : 0 : *is_reuse = false;
18648 : 0 : return sub_policy;
18649 : 0 : rss_sub_policy_error:
18650 [ # # ]: 0 : if (sub_policy) {
18651 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
18652 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
18653 : 0 : i = (mtr_policy->sub_policy_num >>
18654 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18655 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18656 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
18657 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18658 : 0 : sub_policy->idx);
18659 : : }
18660 : : }
18661 : : rte_spinlock_unlock(&mtr_policy->sl);
18662 : 0 : return NULL;
18663 : : }
18664 : :
18665 : : /**
18666 : : * Find the policy table for prefix table with RSS.
18667 : : *
18668 : : * @param[in] dev
18669 : : * Pointer to Ethernet device.
18670 : : * @param[in] mtr_policy
18671 : : * Pointer to meter policy table.
18672 : : * @param[in] rss_desc
18673 : : * Pointer to rss_desc
18674 : : * @return
18675 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
18676 : : */
18677 : : static struct mlx5_flow_meter_sub_policy *
18678 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
18679 : : struct mlx5_flow_meter_policy *mtr_policy,
18680 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
18681 : : {
18682 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18683 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
18684 : : struct mlx5_flow_meter_info *next_fm;
18685 : : struct mlx5_flow_meter_policy *next_policy;
18686 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
18687 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
18688 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
18689 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
18690 : : bool reuse_sub_policy;
18691 : : uint32_t i = 0;
18692 : : uint32_t j = 0;
18693 : :
18694 : : while (true) {
18695 : : /* Iterate hierarchy to get all policies in this hierarchy. */
18696 : 0 : policies[i++] = mtr_policy;
18697 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
18698 : : break;
18699 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
18700 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
18701 : 0 : return NULL;
18702 : : }
18703 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18704 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
18705 : : rte_spinlock_unlock(&mtr_policy->sl);
18706 [ # # ]: 0 : if (!next_fm) {
18707 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
18708 : 0 : return NULL;
18709 : : }
18710 : : next_policy =
18711 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
18712 : : NULL);
18713 : : MLX5_ASSERT(next_policy);
18714 : : mtr_policy = next_policy;
18715 : : }
18716 [ # # ]: 0 : while (i) {
18717 : : /**
18718 : : * From last policy to the first one in hierarchy,
18719 : : * create / get the sub policy for each of them.
18720 : : */
18721 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
18722 : : policies[--i],
18723 : : rss_desc,
18724 : : next_sub_policy,
18725 : : &reuse_sub_policy);
18726 [ # # ]: 0 : if (!sub_policy) {
18727 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
18728 : 0 : goto err_exit;
18729 : : }
18730 [ # # ]: 0 : if (!reuse_sub_policy)
18731 : 0 : sub_policies[j++] = sub_policy;
18732 : : next_sub_policy = sub_policy;
18733 : : }
18734 : : return sub_policy;
18735 : : err_exit:
18736 [ # # ]: 0 : while (j) {
18737 : : uint16_t sub_policy_num;
18738 : :
18739 : 0 : sub_policy = sub_policies[--j];
18740 : 0 : mtr_policy = sub_policy->main_policy;
18741 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
18742 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
18743 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18744 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18745 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18746 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
18747 : : NULL;
18748 : 0 : sub_policy_num--;
18749 : 0 : mtr_policy->sub_policy_num &=
18750 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
18751 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
18752 : 0 : mtr_policy->sub_policy_num |=
18753 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
18754 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
18755 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18756 : 0 : sub_policy->idx);
18757 : : }
18758 : : }
18759 : : return NULL;
18760 : : }
18761 : :
18762 : : /**
18763 : : * Check if need to create hierarchy tag rule.
18764 : : *
18765 : : * @param[in] priv
18766 : : * Pointer to mlx5_priv.
18767 : : * @param[in] mtr_policy
18768 : : * Pointer to current meter policy.
18769 : : * @param[in] src_port
18770 : : * The src port this extra rule should use.
18771 : : * @param[out] next_fm
18772 : : * Pointer to next meter in hierarchy.
18773 : : * @param[out] skip
18774 : : * Indicate if skip the tag rule creation.
18775 : : * @param[out] error
18776 : : * Perform verbose error reporting if not NULL.
18777 : : * @return
18778 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18779 : : */
18780 : : static int
18781 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
18782 : : struct mlx5_flow_meter_policy *mtr_policy,
18783 : : int32_t src_port,
18784 : : struct mlx5_flow_meter_info **next_fm,
18785 : : bool *skip,
18786 : : struct rte_flow_error *error)
18787 : : {
18788 : : struct mlx5_flow_meter_sub_policy *sub_policy;
18789 : : struct mlx5_sub_policy_color_rule *color_rule;
18790 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
18791 : : int ret = 0;
18792 : : int i;
18793 : :
18794 : 0 : *next_fm = NULL;
18795 : 0 : *skip = false;
18796 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18797 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
18798 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
18799 [ # # ]: 0 : if (!*next_fm) {
18800 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
18801 : : NULL, "Failed to find next meter in hierarchy.");
18802 : 0 : goto exit;
18803 : : }
18804 : : }
18805 [ # # ]: 0 : if (!mtr_policy->match_port) {
18806 : 0 : *skip = true;
18807 : 0 : goto exit;
18808 : : }
18809 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
18810 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18811 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
18812 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
18813 : 0 : continue;
18814 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
18815 [ # # ]: 0 : if (color_rule->src_port == src_port) {
18816 : 0 : *skip = true;
18817 : 0 : goto exit;
18818 : : }
18819 : : }
18820 : 0 : exit:
18821 : : rte_spinlock_unlock(&mtr_policy->sl);
18822 : 0 : return ret;
18823 : : }
18824 : :
18825 : : /**
18826 : : * Create the sub policy tag rule for all meters in hierarchy.
18827 : : *
18828 : : * @param[in] dev
18829 : : * Pointer to Ethernet device.
18830 : : * @param[in] fm
18831 : : * Meter information table.
18832 : : * @param[in] src_port
18833 : : * The src port this extra rule should use.
18834 : : * @param[in] item
18835 : : * The src port match item.
18836 : : * @param[out] error
18837 : : * Perform verbose error reporting if not NULL.
18838 : : * @return
18839 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18840 : : */
18841 : : static int
18842 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
18843 : : struct mlx5_flow_meter_info *fm,
18844 : : int32_t src_port,
18845 : : const struct rte_flow_item *item,
18846 : : struct rte_flow_error *error)
18847 : : {
18848 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18849 : : struct mlx5_flow_meter_policy *mtr_policy;
18850 : : struct mlx5_flow_meter_sub_policy *sub_policy;
18851 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
18852 : : struct mlx5_flow_meter_policy *next_policy;
18853 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18854 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18855 : : struct mlx5_sub_policy_color_rule *color_rule;
18856 : : struct mlx5_meter_policy_acts acts;
18857 : : uint32_t color_reg_c_idx;
18858 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
18859 : 0 : struct rte_flow_attr attr = {
18860 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18861 : : .priority = 0,
18862 : : .ingress = 0,
18863 : : .egress = 0,
18864 : : .transfer = 1,
18865 : : .reserved = 0,
18866 : : };
18867 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
18868 : : struct {
18869 : : struct mlx5_flow_meter_policy *fm_policy;
18870 : : struct mlx5_flow_meter_info *next_fm;
18871 : : struct mlx5_sub_policy_color_rule *tag_rule[MLX5_MTR_RTE_COLORS];
18872 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
18873 : : uint32_t fm_cnt = 0;
18874 : : uint32_t i, j;
18875 : :
18876 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
18877 : : /* Get all fms who need to create the tag color rule. */
18878 : : do {
18879 : 0 : bool skip = false;
18880 : :
18881 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
18882 : : MLX5_ASSERT(mtr_policy);
18883 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
18884 : : &next_fm, &skip, error))
18885 : 0 : goto err_exit;
18886 [ # # ]: 0 : if (!skip) {
18887 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
18888 : 0 : fm_info[fm_cnt].next_fm = next_fm;
18889 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
18890 : 0 : rte_flow_error_set(error, errno,
18891 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
18892 : : "Exceed max meter number in hierarchy.");
18893 : 0 : goto err_exit;
18894 : : }
18895 : : }
18896 : 0 : fm = next_fm;
18897 [ # # ]: 0 : } while (fm);
18898 : : /* Create tag color rules for all needed fms. */
18899 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
18900 : : void *mtr_action;
18901 : :
18902 : 0 : mtr_policy = fm_info[i].fm_policy;
18903 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18904 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
18905 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
18906 : : uint8_t act_n = 0;
18907 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
18908 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18909 : :
18910 [ # # ]: 0 : if (mtr_policy->act_cnt[j].fate_action != MLX5_FLOW_FATE_MTR &&
18911 : : mtr_policy->act_cnt[j].fate_action != MLX5_FLOW_FATE_PORT_ID)
18912 : 0 : continue;
18913 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18914 : : sizeof(struct mlx5_sub_policy_color_rule),
18915 : : 0, SOCKET_ID_ANY);
18916 [ # # ]: 0 : if (!color_rule) {
18917 : : rte_spinlock_unlock(&mtr_policy->sl);
18918 : 0 : rte_flow_error_set(error, ENOMEM,
18919 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18920 : : "No memory to create tag color rule.");
18921 : 0 : goto err_exit;
18922 : : }
18923 : 0 : color_rule->src_port = src_port;
18924 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
18925 : : /* Prepare to create color rule. */
18926 [ # # ]: 0 : if (mtr_policy->act_cnt[j].fate_action == MLX5_FLOW_FATE_MTR) {
18927 : 0 : next_fm = fm_info[i].next_fm;
18928 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
18929 : 0 : mlx5_free(color_rule);
18930 : : rte_spinlock_unlock(&mtr_policy->sl);
18931 : 0 : goto err_exit;
18932 : : }
18933 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
18934 [ # # ]: 0 : next_fm->meter_action_y :
18935 : : next_fm->meter_action_g;
18936 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
18937 : : NULL);
18938 : : MLX5_ASSERT(next_policy);
18939 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
18940 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
18941 : : struct mlx5_flow_tbl_data_entry, tbl);
18942 [ # # ]: 0 : if (mtr_first) {
18943 : 0 : acts.dv_actions[act_n++] = mtr_action;
18944 [ # # ]: 0 : if (modify_hdr)
18945 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
18946 : : } else {
18947 [ # # ]: 0 : if (modify_hdr)
18948 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
18949 : 0 : acts.dv_actions[act_n++] = mtr_action;
18950 : : }
18951 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
18952 : 0 : acts.actions_n = act_n;
18953 : : } else {
18954 : : port_action =
18955 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18956 : : mtr_policy->act_cnt[j].rix_port_id_action);
18957 [ # # ]: 0 : if (!port_action) {
18958 : 0 : mlx5_free(color_rule);
18959 : : rte_spinlock_unlock(&mtr_policy->sl);
18960 : 0 : goto err_exit;
18961 : : }
18962 [ # # ]: 0 : if (modify_hdr)
18963 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
18964 : 0 : acts.dv_actions[act_n++] = port_action->action;
18965 : 0 : acts.actions_n = act_n;
18966 : : }
18967 : 0 : fm_info[i].tag_rule[j] = color_rule;
18968 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
18969 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18970 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
18971 : : &attr, true, item, &color_rule->matcher, error)) {
18972 : : rte_spinlock_unlock(&mtr_policy->sl);
18973 : 0 : rte_flow_error_set(error, errno,
18974 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
18975 : : "Failed to create hierarchy meter matcher.");
18976 : 0 : goto err_exit;
18977 : : }
18978 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
18979 : : color_rule->matcher,
18980 : 0 : acts.actions_n, acts.dv_actions,
18981 : : true, item, &color_rule->rule, &attr)) {
18982 : : rte_spinlock_unlock(&mtr_policy->sl);
18983 : 0 : rte_flow_error_set(error, errno,
18984 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
18985 : : "Failed to create hierarchy meter rule.");
18986 : 0 : goto err_exit;
18987 : : }
18988 : : }
18989 : : rte_spinlock_unlock(&mtr_policy->sl);
18990 : : }
18991 : : return 0;
18992 : 0 : err_exit:
18993 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
18994 : 0 : mtr_policy = fm_info[i].fm_policy;
18995 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18996 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
18997 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
18998 : 0 : color_rule = fm_info[i].tag_rule[j];
18999 [ # # ]: 0 : if (!color_rule)
19000 : 0 : continue;
19001 [ # # ]: 0 : if (color_rule->rule)
19002 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19003 [ # # ]: 0 : if (color_rule->matcher) {
19004 : : struct mlx5_flow_tbl_data_entry *tbl =
19005 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19006 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19007 : : }
19008 [ # # ]: 0 : if (fm_info[i].next_fm)
19009 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19010 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19011 : 0 : mlx5_free(color_rule);
19012 : : }
19013 : : rte_spinlock_unlock(&mtr_policy->sl);
19014 : : }
19015 : 0 : return -rte_errno;
19016 : : }
19017 : :
19018 : : /**
19019 : : * Destroy the sub policy table with RX queue.
19020 : : *
19021 : : * @param[in] dev
19022 : : * Pointer to Ethernet device.
19023 : : * @param[in] mtr_policy
19024 : : * Pointer to meter policy table.
19025 : : */
19026 : : static void
19027 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19028 : : struct mlx5_flow_meter_policy *mtr_policy)
19029 : : {
19030 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19031 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19032 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19033 : : uint32_t i, j;
19034 : : uint16_t sub_policy_num, new_policy_num;
19035 : :
19036 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19037 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19038 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19039 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19040 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19041 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19042 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19043 : : new_policy_num = sub_policy_num;
19044 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19045 : 0 : sub_policy =
19046 : 0 : mtr_policy->sub_policys[domain][j];
19047 [ # # ]: 0 : if (sub_policy) {
19048 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19049 : : sub_policy);
19050 : 0 : if (sub_policy !=
19051 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19052 : 0 : mtr_policy->sub_policys[domain][j] =
19053 : : NULL;
19054 : 0 : mlx5_ipool_free
19055 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19056 : 0 : sub_policy->idx);
19057 : 0 : new_policy_num--;
19058 : : }
19059 : : }
19060 : : }
19061 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19062 : 0 : mtr_policy->sub_policy_num &=
19063 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19064 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19065 : 0 : mtr_policy->sub_policy_num |=
19066 : : (new_policy_num &
19067 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19068 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19069 : : }
19070 : : break;
19071 : 0 : case MLX5_FLOW_FATE_QUEUE:
19072 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19073 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19074 : : sub_policy);
19075 : 0 : break;
19076 : : default:
19077 : : /*Other actions without queue and do nothing*/
19078 : : break;
19079 : : }
19080 : : }
19081 : : rte_spinlock_unlock(&mtr_policy->sl);
19082 : 0 : }
19083 : : /**
19084 : : * Check whether the DR drop action is supported on the root table or not.
19085 : : *
19086 : : * Create a simple flow with DR drop action on root table to validate
19087 : : * if DR drop action on root table is supported or not.
19088 : : *
19089 : : * @param[in] dev
19090 : : * Pointer to rte_eth_dev structure.
19091 : : *
19092 : : * @return
19093 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19094 : : */
19095 : : int
19096 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19097 : : {
19098 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19099 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19100 : 0 : struct mlx5_flow_dv_match_params mask = {
19101 : : .size = sizeof(mask.buf),
19102 : : };
19103 : 0 : struct mlx5_flow_dv_match_params value = {
19104 : : .size = sizeof(value.buf),
19105 : : };
19106 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19107 : : .type = IBV_FLOW_ATTR_NORMAL,
19108 : : .priority = 0,
19109 : : .match_criteria_enable = 0,
19110 : : .match_mask = (void *)&mask,
19111 : : };
19112 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19113 : : void *matcher = NULL;
19114 : : void *flow = NULL;
19115 : : int ret = -1;
19116 : :
19117 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19118 : : 0, 0, 0, NULL);
19119 [ # # ]: 0 : if (!tbl)
19120 : 0 : goto err;
19121 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19122 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19123 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19124 : : tbl->obj, &matcher);
19125 : : if (ret)
19126 : 0 : goto err;
19127 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19128 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19129 : : &sh->dr_drop_action, &flow);
19130 : 0 : err:
19131 : : /*
19132 : : * If DR drop action is not supported on root table, flow create will
19133 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19134 : : */
19135 [ # # ]: 0 : if (!flow) {
19136 [ # # ]: 0 : if (matcher &&
19137 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19138 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19139 : : else
19140 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19141 : : ret = -1;
19142 : : } else {
19143 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19144 : : }
19145 [ # # ]: 0 : if (matcher)
19146 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19147 [ # # ]: 0 : if (tbl)
19148 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19149 : 0 : return ret;
19150 : : }
19151 : :
19152 : : /**
19153 : : * Validate the batch counter support in root table.
19154 : : *
19155 : : * Create a simple flow with invalid counter and drop action on root table to
19156 : : * validate if batch counter with offset on root table is supported or not.
19157 : : *
19158 : : * @param[in] dev
19159 : : * Pointer to rte_eth_dev structure.
19160 : : *
19161 : : * @return
19162 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19163 : : */
19164 : : int
19165 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19166 : : {
19167 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19168 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19169 : 0 : struct mlx5_flow_dv_match_params mask = {
19170 : : .size = sizeof(mask.buf),
19171 : : };
19172 : 0 : struct mlx5_flow_dv_match_params value = {
19173 : : .size = sizeof(value.buf),
19174 : : };
19175 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19176 : : .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
19177 : : .priority = 0,
19178 : : .match_criteria_enable = 0,
19179 : : .match_mask = (void *)&mask,
19180 : : };
19181 : 0 : void *actions[2] = { 0 };
19182 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19183 : : struct mlx5_devx_obj *dcs = NULL;
19184 : : void *matcher = NULL;
19185 : : void *flow = NULL;
19186 : : int ret = -1;
19187 : :
19188 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19189 : : 0, 0, 0, NULL);
19190 [ # # ]: 0 : if (!tbl)
19191 : 0 : goto err;
19192 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19193 [ # # ]: 0 : if (!dcs)
19194 : 0 : goto err;
19195 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19196 : : &actions[0]);
19197 : : if (ret)
19198 : 0 : goto err;
19199 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19200 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19201 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19202 : : tbl->obj, &matcher);
19203 : : if (ret)
19204 : 0 : goto err;
19205 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19206 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19207 : : actions, &flow);
19208 : 0 : err:
19209 : : /*
19210 : : * If batch counter with offset is not supported, the driver will not
19211 : : * validate the invalid offset value, flow create should success.
19212 : : * In this case, it means batch counter is not supported in root table.
19213 : : *
19214 : : * Otherwise, if flow create is failed, counter offset is supported.
19215 : : */
19216 [ # # ]: 0 : if (flow) {
19217 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19218 : : "table. Switch to fallback mode.");
19219 : 0 : rte_errno = ENOTSUP;
19220 : : ret = -rte_errno;
19221 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19222 : : } else {
19223 : : /* Check matcher to make sure validate fail at flow create. */
19224 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19225 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19226 : : "support detection");
19227 : : ret = 0;
19228 : : }
19229 [ # # ]: 0 : if (actions[0])
19230 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19231 [ # # ]: 0 : if (matcher)
19232 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19233 [ # # ]: 0 : if (tbl)
19234 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19235 [ # # ]: 0 : if (dcs)
19236 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19237 : 0 : return ret;
19238 : : }
19239 : :
19240 : : /**
19241 : : * Query a devx counter.
19242 : : *
19243 : : * @param[in] dev
19244 : : * Pointer to the Ethernet device structure.
19245 : : * @param[in] cnt
19246 : : * Index to the flow counter.
19247 : : * @param[in] clear
19248 : : * Set to clear the counter statistics.
19249 : : * @param[out] pkts
19250 : : * The statistics value of packets.
19251 : : * @param[out] bytes
19252 : : * The statistics value of bytes.
19253 : : *
19254 : : * @return
19255 : : * 0 on success, otherwise return -1.
19256 : : */
19257 : : static int
19258 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19259 : : uint64_t *pkts, uint64_t *bytes, void **action)
19260 : : {
19261 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19262 : : struct mlx5_flow_counter *cnt;
19263 : : uint64_t inn_pkts, inn_bytes;
19264 : : int ret;
19265 : :
19266 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19267 : : return -1;
19268 : :
19269 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19270 [ # # ]: 0 : if (ret)
19271 : : return -1;
19272 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19273 [ # # ]: 0 : if (cnt && action)
19274 : 0 : *action = cnt->action;
19275 : :
19276 : 0 : *pkts = inn_pkts - cnt->hits;
19277 : 0 : *bytes = inn_bytes - cnt->bytes;
19278 [ # # ]: 0 : if (clear) {
19279 : 0 : cnt->hits = inn_pkts;
19280 : 0 : cnt->bytes = inn_bytes;
19281 : : }
19282 : : return 0;
19283 : : }
19284 : :
19285 : : /**
19286 : : * Get aged-out flows.
19287 : : *
19288 : : * @param[in] dev
19289 : : * Pointer to the Ethernet device structure.
19290 : : * @param[in] context
19291 : : * The address of an array of pointers to the aged-out flows contexts.
19292 : : * @param[in] nb_contexts
19293 : : * The length of context array pointers.
19294 : : * @param[out] error
19295 : : * Perform verbose error reporting if not NULL. Initialized in case of
19296 : : * error only.
19297 : : *
19298 : : * @return
19299 : : * how many contexts get in success, otherwise negative errno value.
19300 : : * if nb_contexts is 0, return the amount of all aged contexts.
19301 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19302 : : * in the context array.
19303 : : * @note: only stub for now
19304 : : */
19305 : : static int
19306 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19307 : : void **context,
19308 : : uint32_t nb_contexts,
19309 : : struct rte_flow_error *error)
19310 : : {
19311 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19312 : : struct mlx5_age_info *age_info;
19313 : : struct mlx5_age_param *age_param;
19314 : : struct mlx5_flow_counter *counter;
19315 : : struct mlx5_aso_age_action *act;
19316 : : int nb_flows = 0;
19317 : :
19318 [ # # ]: 0 : if (nb_contexts && !context)
19319 : 0 : return rte_flow_error_set(error, EINVAL,
19320 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19321 : : NULL, "empty context");
19322 : 0 : age_info = GET_PORT_AGE_INFO(priv);
19323 : 0 : rte_spinlock_lock(&age_info->aged_sl);
19324 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
19325 : 0 : nb_flows++;
19326 [ # # ]: 0 : if (nb_contexts) {
19327 : 0 : context[nb_flows - 1] =
19328 : 0 : act->age_params.context;
19329 [ # # ]: 0 : if (!(--nb_contexts))
19330 : : break;
19331 : : }
19332 : : }
19333 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
19334 : 0 : nb_flows++;
19335 [ # # ]: 0 : if (nb_contexts) {
19336 : : age_param = MLX5_CNT_TO_AGE(counter);
19337 : 0 : context[nb_flows - 1] = age_param->context;
19338 [ # # ]: 0 : if (!(--nb_contexts))
19339 : : break;
19340 : : }
19341 : : }
19342 : : rte_spinlock_unlock(&age_info->aged_sl);
19343 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
19344 : 0 : return nb_flows;
19345 : : }
19346 : :
19347 : : /*
19348 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
19349 : : */
19350 : : static uint32_t
19351 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
19352 : : {
19353 : 0 : return flow_dv_counter_alloc(dev, 0);
19354 : : }
19355 : :
19356 : : /**
19357 : : * Validate indirect action.
19358 : : * Dispatcher for action type specific validation.
19359 : : *
19360 : : * @param[in] dev
19361 : : * Pointer to the Ethernet device structure.
19362 : : * @param[in] conf
19363 : : * Indirect action configuration.
19364 : : * @param[in] action
19365 : : * The indirect action object to validate.
19366 : : * @param[out] error
19367 : : * Perform verbose error reporting if not NULL. Initialized in case of
19368 : : * error only.
19369 : : *
19370 : : * @return
19371 : : * 0 on success, otherwise negative errno value.
19372 : : */
19373 : : int
19374 : 0 : flow_dv_action_validate(struct rte_eth_dev *dev,
19375 : : const struct rte_flow_indir_action_conf *conf,
19376 : : const struct rte_flow_action *action,
19377 : : struct rte_flow_error *err)
19378 : : {
19379 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19380 : : /* called from RTE API */
19381 : :
19382 : : RTE_SET_USED(conf);
19383 [ # # # # : 0 : switch (action->type) {
# ]
19384 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19385 : : /*
19386 : : * priv->obj_ops is set according to driver capabilities.
19387 : : * When DevX capabilities are
19388 : : * sufficient, it is set to devx_obj_ops.
19389 : : * Otherwise, it is set to ibv_obj_ops.
19390 : : * ibv_obj_ops doesn't support ind_table_modify operation.
19391 : : * In this case the indirect RSS action can't be used.
19392 : : */
19393 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
19394 : 0 : return rte_flow_error_set
19395 : : (err, ENOTSUP,
19396 : : RTE_FLOW_ERROR_TYPE_ACTION,
19397 : : NULL,
19398 : : "Indirect RSS action not supported");
19399 : 0 : return mlx5_validate_action_rss(dev, action, err);
19400 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
19401 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
19402 : 0 : return rte_flow_error_set(err, ENOTSUP,
19403 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19404 : : NULL,
19405 : : "Indirect age action not supported");
19406 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
19407 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
19408 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
19409 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
19410 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
19411 : 0 : return rte_flow_error_set(err, ENOTSUP,
19412 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19413 : : "ASO CT is not supported");
19414 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
19415 : 0 : default:
19416 : 0 : return rte_flow_error_set(err, ENOTSUP,
19417 : : RTE_FLOW_ERROR_TYPE_ACTION,
19418 : : NULL,
19419 : : "action type not supported");
19420 : : }
19421 : : }
19422 : :
19423 : : /*
19424 : : * Check if the RSS configurations for colors of a meter policy match
19425 : : * each other, except the queues.
19426 : : *
19427 : : * @param[in] r1
19428 : : * Pointer to the first RSS flow action.
19429 : : * @param[in] r2
19430 : : * Pointer to the second RSS flow action.
19431 : : *
19432 : : * @return
19433 : : * 0 on match, 1 on conflict.
19434 : : */
19435 : : static inline int
19436 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
19437 : : const struct rte_flow_action_rss *r2)
19438 : : {
19439 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
19440 : : return 0;
19441 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
19442 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
19443 : : return 1;
19444 [ # # ]: 0 : if (r1->func != r2->func)
19445 : : return 1;
19446 [ # # ]: 0 : if (r1->types != r2->types &&
19447 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
19448 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
19449 : : return 1;
19450 [ # # # # ]: 0 : if (r1->key || r2->key) {
19451 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : rss_hash_default_key;
19452 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : rss_hash_default_key;
19453 : :
19454 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
19455 : 0 : return 1;
19456 : : }
19457 : : return 0;
19458 : : }
19459 : :
19460 : : /**
19461 : : * Validate the meter hierarchy chain for meter policy.
19462 : : *
19463 : : * @param[in] dev
19464 : : * Pointer to the Ethernet device structure.
19465 : : * @param[in] meter_id
19466 : : * Meter id.
19467 : : * @param[in] action_flags
19468 : : * Holds the actions detected until now.
19469 : : * @param[out] is_rss
19470 : : * Is RSS or not.
19471 : : * @param[out] hierarchy_domain
19472 : : * The domain bitmap for hierarchy policy.
19473 : : * @param[out] error
19474 : : * Perform verbose error reporting if not NULL. Initialized in case of
19475 : : * error only.
19476 : : *
19477 : : * @return
19478 : : * 0 on success, otherwise negative errno value with error set.
19479 : : */
19480 : : static int
19481 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
19482 : : uint32_t meter_id,
19483 : : uint64_t action_flags,
19484 : : bool *is_rss,
19485 : : uint8_t *hierarchy_domain,
19486 : : struct rte_mtr_error *error)
19487 : : {
19488 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19489 : : struct mlx5_flow_meter_info *fm;
19490 : : struct mlx5_flow_meter_policy *policy;
19491 : : uint8_t cnt = 1;
19492 : :
19493 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
19494 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19495 : 0 : return -rte_mtr_error_set(error, EINVAL,
19496 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
19497 : : NULL,
19498 : : "Multiple fate actions not supported.");
19499 : 0 : *hierarchy_domain = 0;
19500 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
19501 : : while (true) {
19502 [ # # ]: 0 : if (!fm)
19503 : 0 : return -rte_mtr_error_set(error, EINVAL,
19504 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19505 : : "Meter not found in meter hierarchy.");
19506 [ # # ]: 0 : if (fm->def_policy)
19507 : 0 : return -rte_mtr_error_set(error, EINVAL,
19508 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19509 : : "Non termination meter not supported in hierarchy.");
19510 [ # # ]: 0 : if (!fm->shared)
19511 : 0 : return -rte_mtr_error_set(error, EINVAL,
19512 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19513 : : "Only shared meter supported in hierarchy.");
19514 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19515 : : MLX5_ASSERT(policy);
19516 : : /**
19517 : : * Only inherit the supported domains of the first meter in
19518 : : * hierarchy.
19519 : : * One meter supports at least one domain.
19520 : : */
19521 [ # # ]: 0 : if (!*hierarchy_domain) {
19522 [ # # ]: 0 : if (policy->transfer)
19523 : 0 : *hierarchy_domain |=
19524 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
19525 [ # # ]: 0 : if (policy->ingress)
19526 : 0 : *hierarchy_domain |=
19527 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
19528 [ # # ]: 0 : if (policy->egress)
19529 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
19530 : : }
19531 [ # # ]: 0 : if (!policy->is_hierarchy) {
19532 : 0 : *is_rss = policy->is_rss;
19533 : : break;
19534 : : }
19535 : 0 : rte_spinlock_lock(&policy->sl);
19536 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
19537 : : rte_spinlock_unlock(&policy->sl);
19538 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
19539 : 0 : return -rte_mtr_error_set(error, EINVAL,
19540 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
19541 : : "Exceed max hierarchy meter number.");
19542 : : }
19543 : 0 : return 0;
19544 : : }
19545 : :
19546 : : /**
19547 : : * Validate meter policy actions.
19548 : : * Dispatcher for action type specific validation.
19549 : : *
19550 : : * @param[in] dev
19551 : : * Pointer to the Ethernet device structure.
19552 : : * @param[in] action
19553 : : * The meter policy action object to validate.
19554 : : * @param[in] attr
19555 : : * Attributes of flow to determine steering domain.
19556 : : * @param[out] error
19557 : : * Perform verbose error reporting if not NULL. Initialized in case of
19558 : : * error only.
19559 : : *
19560 : : * @return
19561 : : * 0 on success, otherwise negative errno value.
19562 : : */
19563 : : static int
19564 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
19565 : : const struct rte_flow_action *actions[RTE_COLORS],
19566 : : struct rte_flow_attr *attr,
19567 : : bool *is_rss,
19568 : : uint8_t *domain_bitmap,
19569 : : uint8_t *policy_mode,
19570 : : struct rte_mtr_error *error)
19571 : : {
19572 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19573 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
19574 : : const struct rte_flow_action *act;
19575 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
19576 : : int actions_n;
19577 : : int i, ret;
19578 : : struct rte_flow_error flow_err;
19579 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
19580 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
19581 : 0 : uint8_t hierarchy_domain = 0;
19582 : : const struct rte_flow_action_meter *mtr;
19583 : : const struct rte_flow_action_meter *next_mtr = NULL;
19584 : : bool def_green = false;
19585 : : bool def_yellow = false;
19586 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
19587 : : /* Called from RTE API */
19588 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
19589 : :
19590 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
19591 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
19592 : 0 : *domain_bitmap = def_domain;
19593 : : /* Red color could only support DROP action. */
19594 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
19595 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
19596 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19597 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19598 : : NULL, "Red color only supports drop action.");
19599 : : /*
19600 : : * Check default policy actions:
19601 : : * Green / Yellow: no action, Red: drop action
19602 : : * Either G or Y will trigger default policy actions to be created.
19603 : : */
19604 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
19605 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
19606 : : def_green = true;
19607 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
19608 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
19609 : : def_yellow = true;
19610 [ # # ]: 0 : if (def_green && def_yellow) {
19611 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
19612 : 0 : return 0;
19613 [ # # ]: 0 : } else if (!def_green && def_yellow) {
19614 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
19615 [ # # ]: 0 : } else if (def_green && !def_yellow) {
19616 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
19617 : : } else {
19618 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
19619 : : }
19620 : : /* Set to empty string in case of NULL pointer access by user. */
19621 : 0 : flow_err.message = "";
19622 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
19623 : 0 : act = actions[i];
19624 : 0 : for (action_flags[i] = 0, actions_n = 0;
19625 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
19626 : 0 : act++) {
19627 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
19628 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19629 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19630 : : NULL, "too many actions");
19631 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
19632 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
19633 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
19634 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
19635 : 0 : return -rte_mtr_error_set(error,
19636 : : ENOTSUP,
19637 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19638 : : NULL, "PORT action validate check"
19639 : : " fail for ESW disable");
19640 : 0 : ret = flow_dv_validate_action_port_id(dev,
19641 : : action_flags[i],
19642 : : act, attr, &flow_err);
19643 [ # # ]: 0 : if (ret)
19644 : 0 : return -rte_mtr_error_set(error,
19645 : : ENOTSUP,
19646 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19647 [ # # ]: 0 : NULL, flow_err.message ?
19648 : : flow_err.message :
19649 : : "PORT action validate check fail");
19650 : 0 : ++actions_n;
19651 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
19652 : 0 : break;
19653 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
19654 : 0 : ret = flow_dv_validate_action_mark(dev, act,
19655 : : action_flags[i],
19656 : : attr, &flow_err);
19657 [ # # ]: 0 : if (ret < 0)
19658 : 0 : return -rte_mtr_error_set(error,
19659 : : ENOTSUP,
19660 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19661 [ # # ]: 0 : NULL, flow_err.message ?
19662 : : flow_err.message :
19663 : : "Mark action validate check fail");
19664 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
19665 : : MLX5_XMETA_MODE_LEGACY)
19666 : 0 : return -rte_mtr_error_set(error,
19667 : : ENOTSUP,
19668 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19669 : : NULL, "Extend MARK action is "
19670 : : "not supported. Please try use "
19671 : : "default policy for meter.");
19672 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
19673 : 0 : ++actions_n;
19674 : 0 : break;
19675 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
19676 : 0 : ret = flow_dv_validate_action_set_tag(dev,
19677 : : act, action_flags[i],
19678 : : attr, &flow_err);
19679 [ # # ]: 0 : if (ret)
19680 : 0 : return -rte_mtr_error_set(error,
19681 : : ENOTSUP,
19682 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19683 [ # # ]: 0 : NULL, flow_err.message ?
19684 : : flow_err.message :
19685 : : "Set tag action validate check fail");
19686 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
19687 : 0 : ++actions_n;
19688 : 0 : break;
19689 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
19690 : 0 : ret = mlx5_flow_validate_action_drop
19691 : : (dev, false, attr, &flow_err);
19692 [ # # ]: 0 : if (ret < 0)
19693 : 0 : return -rte_mtr_error_set(error,
19694 : : ENOTSUP,
19695 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19696 [ # # ]: 0 : NULL, flow_err.message ?
19697 : : flow_err.message :
19698 : : "Drop action validate check fail");
19699 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
19700 : 0 : ++actions_n;
19701 : 0 : break;
19702 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
19703 : : /*
19704 : : * Check whether extensive
19705 : : * metadata feature is engaged.
19706 : : */
19707 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
19708 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
19709 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
19710 : 0 : mlx5_flow_ext_mreg_supported(dev))
19711 : 0 : return -rte_mtr_error_set(error,
19712 : : ENOTSUP,
19713 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19714 : : NULL, "Queue action with meta "
19715 : : "is not supported. Please try use "
19716 : : "default policy for meter.");
19717 : 0 : ret = mlx5_flow_validate_action_queue(act,
19718 : : action_flags[i], dev,
19719 : : attr, &flow_err);
19720 [ # # ]: 0 : if (ret < 0)
19721 : 0 : return -rte_mtr_error_set(error,
19722 : : ENOTSUP,
19723 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19724 [ # # ]: 0 : NULL, flow_err.message ?
19725 : : flow_err.message :
19726 : : "Queue action validate check fail");
19727 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
19728 : 0 : ++actions_n;
19729 : 0 : break;
19730 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19731 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
19732 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
19733 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
19734 : 0 : mlx5_flow_ext_mreg_supported(dev))
19735 : 0 : return -rte_mtr_error_set(error,
19736 : : ENOTSUP,
19737 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19738 : : NULL, "RSS action with meta "
19739 : : "is not supported. Please try use "
19740 : : "default policy for meter.");
19741 : 0 : ret = mlx5_validate_action_rss(dev, act,
19742 : : &flow_err);
19743 [ # # ]: 0 : if (ret < 0)
19744 : 0 : return -rte_mtr_error_set(error,
19745 : : ENOTSUP,
19746 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19747 [ # # ]: 0 : NULL, flow_err.message ?
19748 : : flow_err.message :
19749 : : "RSS action validate check fail");
19750 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
19751 : 0 : ++actions_n;
19752 : : /* Either G or Y will set the RSS. */
19753 : 0 : rss_color[i] = act->conf;
19754 : 0 : break;
19755 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
19756 : 0 : ret = flow_dv_validate_action_jump(dev,
19757 : : NULL, act, action_flags[i],
19758 : : attr, true, &flow_err);
19759 [ # # ]: 0 : if (ret)
19760 : 0 : return -rte_mtr_error_set(error,
19761 : : ENOTSUP,
19762 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19763 [ # # ]: 0 : NULL, flow_err.message ?
19764 : : flow_err.message :
19765 : : "Jump action validate check fail");
19766 : 0 : ++actions_n;
19767 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
19768 : 0 : break;
19769 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
19770 : 0 : mtr = act->conf;
19771 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
19772 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19773 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
19774 : : "Green and Yellow must use the same meter.");
19775 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
19776 : 0 : mtr->mtr_id,
19777 : : action_flags[i],
19778 : : is_rss,
19779 : : &hierarchy_domain,
19780 : : error);
19781 [ # # ]: 0 : if (ret)
19782 : 0 : return ret;
19783 : 0 : ++actions_n;
19784 : 0 : action_flags[i] |=
19785 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
19786 : : next_mtr = mtr;
19787 : 0 : break;
19788 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
19789 : 0 : ret = flow_dv_validate_action_modify_field(dev,
19790 : : action_flags[i], act, attr, is_root, &flow_err);
19791 [ # # ]: 0 : if (ret < 0)
19792 : 0 : return -rte_mtr_error_set(error,
19793 : : ENOTSUP,
19794 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19795 [ # # ]: 0 : NULL, flow_err.message ?
19796 : : flow_err.message :
19797 : : "Modify field action validate check fail");
19798 : 0 : ++actions_n;
19799 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
19800 : 0 : break;
19801 : : default:
19802 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19803 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19804 : : NULL,
19805 : : "Doesn't support optional action");
19806 : : }
19807 : : }
19808 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
19809 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
19810 [ # # ]: 0 : } else if ((action_flags[i] &
19811 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
19812 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
19813 : : /*
19814 : : * Only support MLX5_XMETA_MODE_LEGACY
19815 : : * so MARK action is only in ingress domain.
19816 : : */
19817 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
19818 : : } else {
19819 : 0 : domain_color[i] = def_domain;
19820 [ # # ]: 0 : if (action_flags[i] &&
19821 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19822 : 0 : domain_color[i] &=
19823 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
19824 : : }
19825 [ # # ]: 0 : if (action_flags[i] &
19826 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
19827 : 0 : domain_color[i] &= hierarchy_domain;
19828 : : /*
19829 : : * Non-termination actions only support NIC Tx domain.
19830 : : * The adjustion should be skipped when there is no
19831 : : * action or only END is provided. The default domains
19832 : : * bit-mask is set to find the MIN intersection.
19833 : : * The action flags checking should also be skipped.
19834 : : */
19835 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
19836 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
19837 : 0 : continue;
19838 : : /*
19839 : : * Validate the drop action mutual exclusion
19840 : : * with other actions. Drop action is mutually-exclusive
19841 : : * with any other action, except for Count action.
19842 : : */
19843 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
19844 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
19845 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19846 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19847 : : NULL, "Drop action is mutually-exclusive "
19848 : : "with any other action");
19849 : : }
19850 : : /* Eswitch has few restrictions on using items and actions */
19851 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
19852 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
19853 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
19854 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19855 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19856 : : NULL, "unsupported action MARK");
19857 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
19858 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19859 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19860 : : NULL, "unsupported action QUEUE");
19861 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
19862 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19863 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19864 : : NULL, "unsupported action RSS");
19865 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19866 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19867 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19868 : : NULL, "no fate action is found");
19869 : : } else {
19870 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
19871 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
19872 [ # # ]: 0 : if ((domain_color[i] &
19873 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
19874 : 0 : domain_color[i] =
19875 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
19876 : : else
19877 : 0 : return -rte_mtr_error_set(error,
19878 : : ENOTSUP,
19879 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19880 : : NULL,
19881 : : "no fate action is found");
19882 : : }
19883 : : }
19884 : : }
19885 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
19886 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & action_flags[RTE_COLOR_YELLOW] &
19887 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY))
19888 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
19889 : : NULL,
19890 : : "Meter hierarchy supports meter action only.");
19891 : : }
19892 : : /* If both colors have RSS, the attributes should be the same. */
19893 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
19894 : : rss_color[RTE_COLOR_YELLOW]))
19895 : 0 : return -rte_mtr_error_set(error, EINVAL,
19896 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19897 : : NULL, "policy RSS attr conflict");
19898 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
19899 : 0 : *is_rss = true;
19900 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
19901 [ # # ]: 0 : if (!def_green && !def_yellow &&
19902 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
19903 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
19904 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
19905 : 0 : return -rte_mtr_error_set(error, EINVAL,
19906 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19907 : : NULL, "policy domains conflict");
19908 : : /*
19909 : : * At least one color policy is listed in the actions, the domains
19910 : : * to be supported should be the intersection.
19911 : : */
19912 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
19913 : 0 : domain_color[RTE_COLOR_YELLOW];
19914 : 0 : return 0;
19915 : : }
19916 : :
19917 : : static int
19918 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
19919 : : {
19920 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19921 : : int ret = 0;
19922 : :
19923 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
19924 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
19925 : : flags);
19926 [ # # ]: 0 : if (ret != 0)
19927 : : return ret;
19928 : : }
19929 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
19930 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
19931 [ # # ]: 0 : if (ret != 0)
19932 : : return ret;
19933 : : }
19934 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
19935 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
19936 [ # # ]: 0 : if (ret != 0)
19937 : 0 : return ret;
19938 : : }
19939 : : return 0;
19940 : : }
19941 : :
19942 : : /**
19943 : : * Discover the number of available flow priorities
19944 : : * by trying to create a flow with the highest priority value
19945 : : * for each possible number.
19946 : : *
19947 : : * @param[in] dev
19948 : : * Ethernet device.
19949 : : * @param[in] vprio
19950 : : * List of possible number of available priorities.
19951 : : * @param[in] vprio_n
19952 : : * Size of @p vprio array.
19953 : : * @return
19954 : : * On success, number of available flow priorities.
19955 : : * On failure, a negative errno-style code and rte_errno is set.
19956 : : */
19957 : : static int
19958 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
19959 : : const uint16_t *vprio, int vprio_n)
19960 : : {
19961 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19962 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
19963 : : struct rte_flow_item_eth eth;
19964 : 0 : struct rte_flow_item item = {
19965 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
19966 : : .spec = ð,
19967 : : .mask = ð,
19968 : : };
19969 : 0 : struct mlx5_flow_dv_matcher matcher = {
19970 : : .mask = {
19971 : : .size = sizeof(matcher.mask.buf),
19972 : : },
19973 : : };
19974 : : union mlx5_flow_tbl_key tbl_key;
19975 : : struct mlx5_flow flow;
19976 : : void *action;
19977 : : struct rte_flow_error error;
19978 : : uint8_t misc_mask;
19979 : : int i, err, ret = -ENOTSUP;
19980 : :
19981 : : /*
19982 : : * Prepare a flow with a catch-all pattern and a drop action.
19983 : : * Use drop queue, because shared drop action may be unavailable.
19984 : : */
19985 : 0 : action = priv->drop_queue.hrxq->action;
19986 [ # # ]: 0 : if (action == NULL) {
19987 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
19988 : 0 : rte_errno = ENOTSUP;
19989 : 0 : return -rte_errno;
19990 : : }
19991 : : memset(&flow, 0, sizeof(flow));
19992 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
19993 [ # # ]: 0 : if (flow.handle == NULL) {
19994 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
19995 : 0 : rte_errno = ENOMEM;
19996 : 0 : return -rte_errno;
19997 : : }
19998 : 0 : flow.ingress = true;
19999 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20000 : 0 : flow.dv.actions[0] = action;
20001 : 0 : flow.dv.actions_n = 1;
20002 : : memset(ð, 0, sizeof(eth));
20003 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20004 : : /* inner */ false, /* group */ 0,
20005 : : MLX5_SET_MATCHER_SW_M);
20006 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20007 : : /* inner */ false, /* group */ 0,
20008 : : MLX5_SET_MATCHER_SW_V);
20009 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20010 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20011 : : /* Configure the next proposed maximum priority. */
20012 : 0 : matcher.priority = vprio[i] - 1;
20013 : : memset(&tbl_key, 0, sizeof(tbl_key));
20014 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20015 : : /* tunnel */ NULL,
20016 : : /* group */ 0,
20017 : : &error);
20018 [ # # ]: 0 : if (err != 0) {
20019 : : /* This action is pure SW and must always succeed. */
20020 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20021 : 0 : ret = -rte_errno;
20022 : 0 : break;
20023 : : }
20024 : : /* Try to apply the flow to HW. */
20025 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20026 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20027 : 0 : err = mlx5_flow_os_create_flow
20028 : : (flow.handle->dvh.matcher->matcher_object,
20029 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20030 : : flow.dv.actions, &flow.handle->drv_flow);
20031 : : if (err == 0) {
20032 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20033 : : (flow.handle->drv_flow));
20034 : 0 : flow.handle->drv_flow = NULL;
20035 : : }
20036 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20037 [ # # ]: 0 : if (err != 0)
20038 : : break;
20039 : 0 : ret = vprio[i];
20040 : : }
20041 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20042 : : /* Set rte_errno if no expected priority value matched. */
20043 [ # # ]: 0 : if (ret < 0)
20044 : 0 : rte_errno = -ret;
20045 : : return ret;
20046 : : }
20047 : :
20048 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20049 : : .validate = flow_dv_validate,
20050 : : .prepare = flow_dv_prepare,
20051 : : .translate = flow_dv_translate,
20052 : : .apply = flow_dv_apply,
20053 : : .remove = flow_dv_remove,
20054 : : .destroy = flow_dv_destroy,
20055 : : .query = flow_dv_query,
20056 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20057 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20058 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20059 : : .create_meter = flow_dv_mtr_alloc,
20060 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20061 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20062 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20063 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20064 : : .create_policy_rules = flow_dv_create_policy_rules,
20065 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20066 : : .create_def_policy = flow_dv_create_def_policy,
20067 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20068 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20069 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20070 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20071 : : .counter_alloc = flow_dv_counter_allocate,
20072 : : .counter_free = flow_dv_counter_free,
20073 : : .counter_query = flow_dv_counter_query,
20074 : : .get_aged_flows = flow_dv_get_aged_flows,
20075 : : .action_validate = flow_dv_action_validate,
20076 : : .action_create = flow_dv_action_create,
20077 : : .action_destroy = flow_dv_action_destroy,
20078 : : .action_update = flow_dv_action_update,
20079 : : .action_query = flow_dv_action_query,
20080 : : .sync_domain = flow_dv_sync_domain,
20081 : : .discover_priorities = flow_dv_discover_priorities,
20082 : : .item_create = flow_dv_item_create,
20083 : : .item_release = flow_dv_item_release,
20084 : : };
20085 : :
20086 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|