Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2022 NVIDIA Corporation & Affiliates
3 : : */
4 : :
5 : : #include <rte_flow.h>
6 : : #include <rte_flow_driver.h>
7 : :
8 : : #include <mlx5_malloc.h>
9 : :
10 : : #include "mlx5.h"
11 : : #include "mlx5_defs.h"
12 : : #include "mlx5_flow.h"
13 : : #include "mlx5_rx.h"
14 : :
15 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
16 : : #include "mlx5_hws_cnt.h"
17 : :
18 : : /** Fast path async flow API functions. */
19 : : static struct rte_flow_fp_ops mlx5_flow_hw_fp_ops;
20 : :
21 : : /* The maximum actions support in the flow. */
22 : : #define MLX5_HW_MAX_ACTS 16
23 : :
24 : : /*
25 : : * The default ipool threshold value indicates which per_core_cache
26 : : * value to set.
27 : : */
28 : : #define MLX5_HW_IPOOL_SIZE_THRESHOLD (1 << 19)
29 : : /* The default min local cache size. */
30 : : #define MLX5_HW_IPOOL_CACHE_MIN (1 << 9)
31 : :
32 : : /* Default push burst threshold. */
33 : : #define BURST_THR 32u
34 : :
35 : : /* Default queue to flush the flows. */
36 : : #define MLX5_DEFAULT_FLUSH_QUEUE 0
37 : :
38 : : /* Maximum number of rules in control flow tables. */
39 : : #define MLX5_HW_CTRL_FLOW_NB_RULES (4096)
40 : :
41 : : /* Lowest flow group usable by an application if group translation is done. */
42 : : #define MLX5_HW_LOWEST_USABLE_GROUP (1)
43 : :
44 : : /* Maximum group index usable by user applications for transfer flows. */
45 : : #define MLX5_HW_MAX_TRANSFER_GROUP (UINT32_MAX - 1)
46 : :
47 : : /* Maximum group index usable by user applications for egress flows. */
48 : : #define MLX5_HW_MAX_EGRESS_GROUP (UINT32_MAX - 1)
49 : :
50 : : /* Lowest priority for HW root table. */
51 : : #define MLX5_HW_LOWEST_PRIO_ROOT 15
52 : :
53 : : /* Lowest priority for HW non-root table. */
54 : : #define MLX5_HW_LOWEST_PRIO_NON_ROOT (UINT32_MAX)
55 : :
56 : : /* Priorities for Rx control flow rules. */
57 : : #define MLX5_HW_CTRL_RX_PRIO_L2 (MLX5_HW_LOWEST_PRIO_ROOT)
58 : : #define MLX5_HW_CTRL_RX_PRIO_L3 (MLX5_HW_LOWEST_PRIO_ROOT - 1)
59 : : #define MLX5_HW_CTRL_RX_PRIO_L4 (MLX5_HW_LOWEST_PRIO_ROOT - 2)
60 : :
61 : : #define MLX5_HW_VLAN_PUSH_TYPE_IDX 0
62 : : #define MLX5_HW_VLAN_PUSH_VID_IDX 1
63 : : #define MLX5_HW_VLAN_PUSH_PCP_IDX 2
64 : :
65 : : #define MLX5_MIRROR_MAX_CLONES_NUM 3
66 : : #define MLX5_MIRROR_MAX_SAMPLE_ACTIONS_LEN 4
67 : :
68 : : #define MLX5_HW_PORT_IS_PROXY(priv) \
69 : : (!!((priv)->sh->esw_mode && (priv)->master))
70 : :
71 : :
72 : : struct mlx5_indlst_legacy {
73 : : struct mlx5_indirect_list indirect;
74 : : struct rte_flow_action_handle *handle;
75 : : enum rte_flow_action_type legacy_type;
76 : : };
77 : :
78 : : #define MLX5_CONST_ENCAP_ITEM(encap_type, ptr) \
79 : : (((const struct encap_type *)(ptr))->definition)
80 : :
81 : : struct mlx5_multi_pattern_ctx {
82 : : union {
83 : : struct mlx5dr_action_reformat_header reformat_hdr;
84 : : struct mlx5dr_action_mh_pattern mh_pattern;
85 : : };
86 : : union {
87 : : /* action template auxiliary structures for object destruction */
88 : : struct mlx5_hw_encap_decap_action *encap;
89 : : struct mlx5_hw_modify_header_action *mhdr;
90 : : };
91 : : /* multi pattern action */
92 : : struct mlx5dr_rule_action *rule_action;
93 : : };
94 : :
95 : : #define MLX5_MULTIPATTERN_ENCAP_NUM 4
96 : :
97 : : struct mlx5_tbl_multi_pattern_ctx {
98 : : struct {
99 : : uint32_t elements_num;
100 : : struct mlx5_multi_pattern_ctx ctx[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
101 : : } reformat[MLX5_MULTIPATTERN_ENCAP_NUM];
102 : :
103 : : struct {
104 : : uint32_t elements_num;
105 : : struct mlx5_multi_pattern_ctx ctx[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
106 : : } mh;
107 : : };
108 : :
109 : : #define MLX5_EMPTY_MULTI_PATTERN_CTX {{{0,}},}
110 : :
111 : : static int
112 : : mlx5_tbl_multi_pattern_process(struct rte_eth_dev *dev,
113 : : struct rte_flow_template_table *tbl,
114 : : struct mlx5_tbl_multi_pattern_ctx *mpat,
115 : : struct rte_flow_error *error);
116 : :
117 : : static __rte_always_inline int
118 : : mlx5_multi_pattern_reformat_to_index(enum mlx5dr_action_type type)
119 : : {
120 : : switch (type) {
121 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
122 : : return 0;
123 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
124 : : return 1;
125 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
126 : : return 2;
127 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
128 : : return 3;
129 : : default:
130 : : break;
131 : : }
132 : : return -1;
133 : : }
134 : :
135 : : static __rte_always_inline enum mlx5dr_action_type
136 : : mlx5_multi_pattern_reformat_index_to_type(uint32_t ix)
137 : : {
138 : : switch (ix) {
139 : : case 0:
140 : : return MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
141 : : case 1:
142 : : return MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
143 : : case 2:
144 : : return MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2;
145 : : case 3:
146 : : return MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
147 : : default:
148 : : break;
149 : : }
150 : : return MLX5DR_ACTION_TYP_MAX;
151 : : }
152 : :
153 : : static inline enum mlx5dr_table_type
154 : : get_mlx5dr_table_type(const struct rte_flow_attr *attr)
155 : : {
156 : : enum mlx5dr_table_type type;
157 : :
158 [ # # # # ]: 0 : if (attr->transfer)
159 : : type = MLX5DR_TABLE_TYPE_FDB;
160 [ # # # # : 0 : else if (attr->egress)
# # # # #
# # # ]
161 : : type = MLX5DR_TABLE_TYPE_NIC_TX;
162 : : else
163 : : type = MLX5DR_TABLE_TYPE_NIC_RX;
164 : : return type;
165 : : }
166 : :
167 : : struct mlx5_mirror_clone {
168 : : enum rte_flow_action_type type;
169 : : void *action_ctx;
170 : : };
171 : :
172 : : struct mlx5_mirror {
173 : : struct mlx5_indirect_list indirect;
174 : : uint32_t clones_num;
175 : : struct mlx5dr_action *mirror_action;
176 : : struct mlx5_mirror_clone clone[MLX5_MIRROR_MAX_CLONES_NUM];
177 : : };
178 : :
179 : : static int flow_hw_flush_all_ctrl_flows(struct rte_eth_dev *dev);
180 : : static int flow_hw_translate_group(struct rte_eth_dev *dev,
181 : : const struct mlx5_flow_template_table_cfg *cfg,
182 : : uint32_t group,
183 : : uint32_t *table_group,
184 : : struct rte_flow_error *error);
185 : : static __rte_always_inline int
186 : : flow_hw_set_vlan_vid_construct(struct rte_eth_dev *dev,
187 : : struct mlx5_hw_q_job *job,
188 : : struct mlx5_action_construct_data *act_data,
189 : : const struct mlx5_hw_actions *hw_acts,
190 : : const struct rte_flow_action *action);
191 : : static void
192 : : flow_hw_construct_quota(struct mlx5_priv *priv,
193 : : struct mlx5dr_rule_action *rule_act, uint32_t qid);
194 : :
195 : : static __rte_always_inline uint32_t flow_hw_tx_tag_regc_mask(struct rte_eth_dev *dev);
196 : : static __rte_always_inline uint32_t flow_hw_tx_tag_regc_value(struct rte_eth_dev *dev);
197 : :
198 : : const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops;
199 : :
200 : : /* DR action flags with different table. */
201 : : static uint32_t mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_MAX]
202 : : [MLX5DR_TABLE_TYPE_MAX] = {
203 : : {
204 : : MLX5DR_ACTION_FLAG_ROOT_RX,
205 : : MLX5DR_ACTION_FLAG_ROOT_TX,
206 : : MLX5DR_ACTION_FLAG_ROOT_FDB,
207 : : },
208 : : {
209 : : MLX5DR_ACTION_FLAG_HWS_RX,
210 : : MLX5DR_ACTION_FLAG_HWS_TX,
211 : : MLX5DR_ACTION_FLAG_HWS_FDB,
212 : : },
213 : : };
214 : :
215 : : /* Ethernet item spec for promiscuous mode. */
216 : : static const struct rte_flow_item_eth ctrl_rx_eth_promisc_spec = {
217 : : .hdr.dst_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
218 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
219 : : .hdr.ether_type = 0,
220 : : };
221 : : /* Ethernet item mask for promiscuous mode. */
222 : : static const struct rte_flow_item_eth ctrl_rx_eth_promisc_mask = {
223 : : .hdr.dst_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
224 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
225 : : .hdr.ether_type = 0,
226 : : };
227 : :
228 : : /* Ethernet item spec for all multicast mode. */
229 : : static const struct rte_flow_item_eth ctrl_rx_eth_mcast_spec = {
230 : : .hdr.dst_addr.addr_bytes = "\x01\x00\x00\x00\x00\x00",
231 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
232 : : .hdr.ether_type = 0,
233 : : };
234 : : /* Ethernet item mask for all multicast mode. */
235 : : static const struct rte_flow_item_eth ctrl_rx_eth_mcast_mask = {
236 : : .hdr.dst_addr.addr_bytes = "\x01\x00\x00\x00\x00\x00",
237 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
238 : : .hdr.ether_type = 0,
239 : : };
240 : :
241 : : /* Ethernet item spec for IPv4 multicast traffic. */
242 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv4_mcast_spec = {
243 : : .hdr.dst_addr.addr_bytes = "\x01\x00\x5e\x00\x00\x00",
244 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
245 : : .hdr.ether_type = 0,
246 : : };
247 : : /* Ethernet item mask for IPv4 multicast traffic. */
248 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv4_mcast_mask = {
249 : : .hdr.dst_addr.addr_bytes = "\xff\xff\xff\x00\x00\x00",
250 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
251 : : .hdr.ether_type = 0,
252 : : };
253 : :
254 : : /* Ethernet item spec for IPv6 multicast traffic. */
255 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv6_mcast_spec = {
256 : : .hdr.dst_addr.addr_bytes = "\x33\x33\x00\x00\x00\x00",
257 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
258 : : .hdr.ether_type = 0,
259 : : };
260 : : /* Ethernet item mask for IPv6 multicast traffic. */
261 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv6_mcast_mask = {
262 : : .hdr.dst_addr.addr_bytes = "\xff\xff\x00\x00\x00\x00",
263 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
264 : : .hdr.ether_type = 0,
265 : : };
266 : :
267 : : /* Ethernet item mask for unicast traffic. */
268 : : static const struct rte_flow_item_eth ctrl_rx_eth_dmac_mask = {
269 : : .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
270 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
271 : : .hdr.ether_type = 0,
272 : : };
273 : :
274 : : /* Ethernet item spec for broadcast. */
275 : : static const struct rte_flow_item_eth ctrl_rx_eth_bcast_spec = {
276 : : .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
277 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
278 : : .hdr.ether_type = 0,
279 : : };
280 : :
281 : : static __rte_always_inline struct mlx5_hw_q_job *
282 : : flow_hw_job_get(struct mlx5_priv *priv, uint32_t queue)
283 : : {
284 : : MLX5_ASSERT(priv->hw_q[queue].job_idx <= priv->hw_q[queue].size);
285 : 0 : return priv->hw_q[queue].job_idx ?
286 [ # # # # : 0 : priv->hw_q[queue].job[--priv->hw_q[queue].job_idx] : NULL;
# # # # #
# # # # #
# # # # ]
287 : : }
288 : :
289 : : static __rte_always_inline void
290 : : flow_hw_job_put(struct mlx5_priv *priv, struct mlx5_hw_q_job *job, uint32_t queue)
291 : : {
292 : : MLX5_ASSERT(priv->hw_q[queue].job_idx < priv->hw_q[queue].size);
293 : 0 : priv->hw_q[queue].job[priv->hw_q[queue].job_idx++] = job;
294 : 0 : }
295 : :
296 : : static inline enum mlx5dr_matcher_insert_mode
297 : : flow_hw_matcher_insert_mode_get(enum rte_flow_table_insertion_type insert_type)
298 : : {
299 : 0 : if (insert_type == RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN)
300 : : return MLX5DR_MATCHER_INSERT_BY_HASH;
301 : : else
302 : 0 : return MLX5DR_MATCHER_INSERT_BY_INDEX;
303 : : }
304 : :
305 : : static inline enum mlx5dr_matcher_distribute_mode
306 : : flow_hw_matcher_distribute_mode_get(enum rte_flow_table_hash_func hash_func)
307 : : {
308 [ # # ]: 0 : if (hash_func == RTE_FLOW_TABLE_HASH_FUNC_LINEAR)
309 : : return MLX5DR_MATCHER_DISTRIBUTE_BY_LINEAR;
310 : : else
311 : 0 : return MLX5DR_MATCHER_DISTRIBUTE_BY_HASH;
312 : : }
313 : :
314 : : /**
315 : : * Set the hash fields according to the @p rss_desc information.
316 : : *
317 : : * @param[in] rss_desc
318 : : * Pointer to the mlx5_flow_rss_desc.
319 : : * @param[out] hash_fields
320 : : * Pointer to the RSS hash fields.
321 : : */
322 : : static void
323 : 0 : flow_hw_hashfields_set(struct mlx5_flow_rss_desc *rss_desc,
324 : : uint64_t *hash_fields)
325 : : {
326 : : uint64_t fields = 0;
327 : : int rss_inner = 0;
328 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
329 : :
330 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
331 [ # # ]: 0 : if (rss_desc->level >= 2)
332 : : rss_inner = 1;
333 : : #endif
334 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
335 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
336 : : fields |= IBV_RX_HASH_SRC_IPV4;
337 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
338 : : fields |= IBV_RX_HASH_DST_IPV4;
339 : : else
340 : : fields |= MLX5_IPV4_IBV_RX_HASH;
341 [ # # ]: 0 : } else if (rss_types & MLX5_IPV6_LAYER_TYPES) {
342 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
343 : : fields |= IBV_RX_HASH_SRC_IPV6;
344 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
345 : : fields |= IBV_RX_HASH_DST_IPV6;
346 : : else
347 : : fields |= MLX5_IPV6_IBV_RX_HASH;
348 : : }
349 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
350 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
351 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
352 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
353 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
354 : : else
355 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
356 [ # # ]: 0 : } else if (rss_types & RTE_ETH_RSS_TCP) {
357 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
358 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
359 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
360 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
361 : : else
362 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
363 : : }
364 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
365 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
366 [ # # ]: 0 : if (rss_inner)
367 : 0 : fields |= IBV_RX_HASH_INNER;
368 : 0 : *hash_fields = fields;
369 : 0 : }
370 : :
371 : : /**
372 : : * Generate the matching pattern item flags.
373 : : *
374 : : * @param[in] items
375 : : * Pointer to the list of items.
376 : : *
377 : : * @return
378 : : * Matching item flags. RSS hash field function
379 : : * silently ignores the flags which are unsupported.
380 : : */
381 : : static uint64_t
382 : 0 : flow_hw_matching_item_flags_get(const struct rte_flow_item items[])
383 : : {
384 : : uint64_t item_flags = 0;
385 : : uint64_t last_item = 0;
386 : :
387 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
388 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
389 : : int item_type = items->type;
390 : :
391 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # #
# ]
392 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
393 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
394 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
395 : : break;
396 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
397 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
398 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
399 : : break;
400 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
401 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
402 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
403 : : break;
404 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
405 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
406 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
407 : : break;
408 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_ROUTING_EXT:
409 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT :
410 : : MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT;
411 : : break;
412 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
413 : : last_item = MLX5_FLOW_LAYER_GRE;
414 : 0 : break;
415 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
416 : : last_item = MLX5_FLOW_LAYER_GRE;
417 : 0 : break;
418 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
419 : : last_item = MLX5_FLOW_LAYER_VXLAN;
420 : 0 : break;
421 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
422 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
423 : 0 : break;
424 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
425 : : last_item = MLX5_FLOW_LAYER_GENEVE;
426 : 0 : break;
427 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
428 : : last_item = MLX5_FLOW_LAYER_MPLS;
429 : 0 : break;
430 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
431 : : last_item = MLX5_FLOW_LAYER_GTP;
432 : 0 : break;
433 : 0 : case RTE_FLOW_ITEM_TYPE_COMPARE:
434 : : last_item = MLX5_FLOW_ITEM_COMPARE;
435 : 0 : break;
436 : : default:
437 : : break;
438 : : }
439 : 0 : item_flags |= last_item;
440 : : }
441 : 0 : return item_flags;
442 : : }
443 : :
444 : : /**
445 : : * Register destination table DR jump action.
446 : : *
447 : : * @param[in] dev
448 : : * Pointer to the rte_eth_dev structure.
449 : : * @param[in] table_attr
450 : : * Pointer to the flow attributes.
451 : : * @param[in] dest_group
452 : : * The destination group ID.
453 : : * @param[out] error
454 : : * Pointer to error structure.
455 : : *
456 : : * @return
457 : : * Table on success, NULL otherwise and rte_errno is set.
458 : : */
459 : : static struct mlx5_hw_jump_action *
460 : 0 : flow_hw_jump_action_register(struct rte_eth_dev *dev,
461 : : const struct mlx5_flow_template_table_cfg *cfg,
462 : : uint32_t dest_group,
463 : : struct rte_flow_error *error)
464 : : {
465 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
466 : 0 : struct rte_flow_attr jattr = cfg->attr.flow_attr;
467 : : struct mlx5_flow_group *grp;
468 : 0 : struct mlx5_flow_cb_ctx ctx = {
469 : : .dev = dev,
470 : : .error = error,
471 : : .data = &jattr,
472 : : };
473 : : struct mlx5_list_entry *ge;
474 : : uint32_t target_group;
475 : :
476 : 0 : target_group = dest_group;
477 [ # # ]: 0 : if (flow_hw_translate_group(dev, cfg, dest_group, &target_group, error))
478 : : return NULL;
479 : 0 : jattr.group = target_group;
480 : 0 : ge = mlx5_hlist_register(priv->sh->flow_tbls, target_group, &ctx);
481 [ # # ]: 0 : if (!ge)
482 : : return NULL;
483 : : grp = container_of(ge, struct mlx5_flow_group, entry);
484 : 0 : return &grp->jump;
485 : : }
486 : :
487 : : /**
488 : : * Release jump action.
489 : : *
490 : : * @param[in] dev
491 : : * Pointer to the rte_eth_dev structure.
492 : : * @param[in] jump
493 : : * Pointer to the jump action.
494 : : */
495 : :
496 : : static void
497 : : flow_hw_jump_release(struct rte_eth_dev *dev, struct mlx5_hw_jump_action *jump)
498 : : {
499 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
500 : : struct mlx5_flow_group *grp;
501 : :
502 : 0 : grp = container_of
503 : : (jump, struct mlx5_flow_group, jump);
504 : 0 : mlx5_hlist_unregister(priv->sh->flow_tbls, &grp->entry);
505 : 0 : }
506 : :
507 : : /**
508 : : * Register queue/RSS action.
509 : : *
510 : : * @param[in] dev
511 : : * Pointer to the rte_eth_dev structure.
512 : : * @param[in] hws_flags
513 : : * DR action flags.
514 : : * @param[in] action
515 : : * rte flow action.
516 : : *
517 : : * @return
518 : : * Table on success, NULL otherwise and rte_errno is set.
519 : : */
520 : : static inline struct mlx5_hrxq*
521 : 0 : flow_hw_tir_action_register(struct rte_eth_dev *dev,
522 : : uint32_t hws_flags,
523 : : const struct rte_flow_action *action)
524 : : {
525 : 0 : struct mlx5_flow_rss_desc rss_desc = {
526 : : .hws_flags = hws_flags,
527 : : };
528 : : struct mlx5_hrxq *hrxq;
529 : :
530 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
531 : 0 : const struct rte_flow_action_queue *queue = action->conf;
532 : :
533 : 0 : rss_desc.const_q = &queue->index;
534 : 0 : rss_desc.queue_num = 1;
535 : : } else {
536 : 0 : const struct rte_flow_action_rss *rss = action->conf;
537 : :
538 : 0 : rss_desc.queue_num = rss->queue_num;
539 : 0 : rss_desc.const_q = rss->queue;
540 : 0 : memcpy(rss_desc.key,
541 [ # # ]: 0 : !rss->key ? rss_hash_default_key : rss->key,
542 : : MLX5_RSS_HASH_KEY_LEN);
543 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
544 [ # # ]: 0 : rss_desc.types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
545 : 0 : rss_desc.symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
546 : 0 : flow_hw_hashfields_set(&rss_desc, &rss_desc.hash_fields);
547 : 0 : flow_dv_action_rss_l34_hash_adjust(rss->types,
548 : : &rss_desc.hash_fields);
549 [ # # ]: 0 : if (rss->level > 1) {
550 : 0 : rss_desc.hash_fields |= IBV_RX_HASH_INNER;
551 : 0 : rss_desc.tunnel = 1;
552 : : }
553 : : }
554 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
555 : 0 : return hrxq;
556 : : }
557 : :
558 : : static __rte_always_inline int
559 : : flow_hw_ct_compile(struct rte_eth_dev *dev,
560 : : uint32_t queue, uint32_t idx,
561 : : struct mlx5dr_rule_action *rule_act)
562 : : {
563 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
564 : : struct mlx5_aso_ct_action *ct;
565 : :
566 : 0 : ct = mlx5_ipool_get(priv->hws_ctpool->cts, MLX5_ACTION_CTX_CT_GET_IDX(idx));
567 [ # # # # : 0 : if (!ct || mlx5_aso_ct_available(priv->sh, queue, ct))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
568 : : return -1;
569 : 0 : rule_act->action = priv->hws_ctpool->dr_action;
570 : 0 : rule_act->aso_ct.offset = ct->offset;
571 : 0 : rule_act->aso_ct.direction = ct->is_original ?
572 : 0 : MLX5DR_ACTION_ASO_CT_DIRECTION_INITIATOR :
573 : : MLX5DR_ACTION_ASO_CT_DIRECTION_RESPONDER;
574 : : return 0;
575 : : }
576 : :
577 : : static void
578 : 0 : flow_hw_template_destroy_reformat_action(struct mlx5_hw_encap_decap_action *encap_decap)
579 : : {
580 [ # # ]: 0 : if (encap_decap->multi_pattern) {
581 : 0 : uint32_t refcnt = __atomic_sub_fetch(encap_decap->multi_pattern_refcnt,
582 : : 1, __ATOMIC_RELAXED);
583 [ # # ]: 0 : if (refcnt)
584 : : return;
585 : 0 : mlx5_free((void *)(uintptr_t)encap_decap->multi_pattern_refcnt);
586 : : }
587 [ # # ]: 0 : if (encap_decap->action)
588 : 0 : mlx5dr_action_destroy(encap_decap->action);
589 : : }
590 : :
591 : : static void
592 : 0 : flow_hw_template_destroy_mhdr_action(struct mlx5_hw_modify_header_action *mhdr)
593 : : {
594 [ # # ]: 0 : if (mhdr->multi_pattern) {
595 : 0 : uint32_t refcnt = __atomic_sub_fetch(mhdr->multi_pattern_refcnt,
596 : : 1, __ATOMIC_RELAXED);
597 [ # # ]: 0 : if (refcnt)
598 : : return;
599 : 0 : mlx5_free((void *)(uintptr_t)mhdr->multi_pattern_refcnt);
600 : : }
601 [ # # ]: 0 : if (mhdr->action)
602 : 0 : mlx5dr_action_destroy(mhdr->action);
603 : : }
604 : :
605 : : /**
606 : : * Destroy DR actions created by action template.
607 : : *
608 : : * For DR actions created during table creation's action translate.
609 : : * Need to destroy the DR action when destroying the table.
610 : : *
611 : : * @param[in] dev
612 : : * Pointer to the rte_eth_dev structure.
613 : : * @param[in] acts
614 : : * Pointer to the template HW steering DR actions.
615 : : */
616 : : static void
617 : 0 : __flow_hw_action_template_destroy(struct rte_eth_dev *dev,
618 : : struct mlx5_hw_actions *acts)
619 : : {
620 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
621 : : struct mlx5_action_construct_data *data;
622 : :
623 [ # # ]: 0 : while (!LIST_EMPTY(&acts->act_list)) {
624 : : data = LIST_FIRST(&acts->act_list);
625 [ # # ]: 0 : LIST_REMOVE(data, next);
626 : 0 : mlx5_ipool_free(priv->acts_ipool, data->idx);
627 : : }
628 : :
629 [ # # ]: 0 : if (acts->mark)
630 [ # # ]: 0 : if (!(__atomic_fetch_sub(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED) - 1))
631 : 0 : flow_hw_rxq_flag_set(dev, false);
632 : :
633 [ # # ]: 0 : if (acts->jump) {
634 : : struct mlx5_flow_group *grp;
635 : :
636 : 0 : grp = container_of
637 : : (acts->jump, struct mlx5_flow_group, jump);
638 : 0 : mlx5_hlist_unregister(priv->sh->flow_tbls, &grp->entry);
639 : 0 : acts->jump = NULL;
640 : : }
641 [ # # ]: 0 : if (acts->tir) {
642 : 0 : mlx5_hrxq_release(dev, acts->tir->idx);
643 : 0 : acts->tir = NULL;
644 : : }
645 [ # # ]: 0 : if (acts->encap_decap) {
646 : 0 : flow_hw_template_destroy_reformat_action(acts->encap_decap);
647 : 0 : mlx5_free(acts->encap_decap);
648 : 0 : acts->encap_decap = NULL;
649 : : }
650 [ # # ]: 0 : if (acts->push_remove) {
651 [ # # ]: 0 : if (acts->push_remove->action)
652 : 0 : mlx5dr_action_destroy(acts->push_remove->action);
653 : 0 : mlx5_free(acts->push_remove);
654 : 0 : acts->push_remove = NULL;
655 : : }
656 [ # # ]: 0 : if (acts->mhdr) {
657 : 0 : flow_hw_template_destroy_mhdr_action(acts->mhdr);
658 : 0 : mlx5_free(acts->mhdr);
659 : 0 : acts->mhdr = NULL;
660 : : }
661 [ # # ]: 0 : if (mlx5_hws_cnt_id_valid(acts->cnt_id)) {
662 [ # # ]: 0 : mlx5_hws_cnt_shared_put(priv->hws_cpool, &acts->cnt_id);
663 : 0 : acts->cnt_id = 0;
664 : : }
665 [ # # ]: 0 : if (acts->mtr_id) {
666 : 0 : mlx5_ipool_free(priv->hws_mpool->idx_pool, acts->mtr_id);
667 : 0 : acts->mtr_id = 0;
668 : : }
669 : 0 : }
670 : :
671 : : /**
672 : : * Append dynamic action to the dynamic action list.
673 : : *
674 : : * @param[in] priv
675 : : * Pointer to the port private data structure.
676 : : * @param[in] acts
677 : : * Pointer to the template HW steering DR actions.
678 : : * @param[in] type
679 : : * Action type.
680 : : * @param[in] action_src
681 : : * Offset of source rte flow action.
682 : : * @param[in] action_dst
683 : : * Offset of destination DR action.
684 : : *
685 : : * @return
686 : : * 0 on success, negative value otherwise and rte_errno is set.
687 : : */
688 : : static __rte_always_inline struct mlx5_action_construct_data *
689 : : __flow_hw_act_data_alloc(struct mlx5_priv *priv,
690 : : enum rte_flow_action_type type,
691 : : uint16_t action_src,
692 : : uint16_t action_dst)
693 : : {
694 : : struct mlx5_action_construct_data *act_data;
695 : 0 : uint32_t idx = 0;
696 : :
697 : 0 : act_data = mlx5_ipool_zmalloc(priv->acts_ipool, &idx);
698 [ # # # # : 0 : if (!act_data)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
699 : : return NULL;
700 : 0 : act_data->idx = idx;
701 : 0 : act_data->type = type;
702 : 0 : act_data->action_src = action_src;
703 : 0 : act_data->action_dst = action_dst;
704 : : return act_data;
705 : : }
706 : :
707 : : /**
708 : : * Append dynamic action to the dynamic action list.
709 : : *
710 : : * @param[in] priv
711 : : * Pointer to the port private data structure.
712 : : * @param[in] acts
713 : : * Pointer to the template HW steering DR actions.
714 : : * @param[in] type
715 : : * Action type.
716 : : * @param[in] action_src
717 : : * Offset of source rte flow action.
718 : : * @param[in] action_dst
719 : : * Offset of destination DR action.
720 : : *
721 : : * @return
722 : : * 0 on success, negative value otherwise and rte_errno is set.
723 : : */
724 : : static __rte_always_inline int
725 : : __flow_hw_act_data_general_append(struct mlx5_priv *priv,
726 : : struct mlx5_hw_actions *acts,
727 : : enum rte_flow_action_type type,
728 : : uint16_t action_src,
729 : : uint16_t action_dst)
730 : : {
731 : : struct mlx5_action_construct_data *act_data;
732 : :
733 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
734 : : if (!act_data)
735 : : return -1;
736 [ # # # # : 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
# # # # #
# # # # #
# # # # #
# # # #
# ]
737 : : return 0;
738 : : }
739 : :
740 : : static __rte_always_inline int
741 : : flow_hw_act_data_indirect_list_append(struct mlx5_priv *priv,
742 : : struct mlx5_hw_actions *acts,
743 : : enum rte_flow_action_type type,
744 : : uint16_t action_src, uint16_t action_dst,
745 : : indirect_list_callback_t cb)
746 : : {
747 : : struct mlx5_action_construct_data *act_data;
748 : :
749 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
750 : : if (!act_data)
751 : 0 : return -1;
752 : 0 : act_data->indirect_list_cb = cb;
753 [ # # # # : 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
# # ]
754 : 0 : return 0;
755 : : }
756 : : /**
757 : : * Append dynamic encap action to the dynamic action list.
758 : : *
759 : : * @param[in] priv
760 : : * Pointer to the port private data structure.
761 : : * @param[in] acts
762 : : * Pointer to the template HW steering DR actions.
763 : : * @param[in] type
764 : : * Action type.
765 : : * @param[in] action_src
766 : : * Offset of source rte flow action.
767 : : * @param[in] action_dst
768 : : * Offset of destination DR action.
769 : : * @param[in] len
770 : : * Length of the data to be updated.
771 : : *
772 : : * @return
773 : : * 0 on success, negative value otherwise and rte_errno is set.
774 : : */
775 : : static __rte_always_inline int
776 : : __flow_hw_act_data_encap_append(struct mlx5_priv *priv,
777 : : struct mlx5_hw_actions *acts,
778 : : enum rte_flow_action_type type,
779 : : uint16_t action_src,
780 : : uint16_t action_dst,
781 : : uint16_t len)
782 : : {
783 : : struct mlx5_action_construct_data *act_data;
784 : :
785 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
786 : : if (!act_data)
787 : : return -1;
788 : 0 : act_data->encap.len = len;
789 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
790 : : return 0;
791 : : }
792 : :
793 : : /**
794 : : * Append dynamic push action to the dynamic action list.
795 : : *
796 : : * @param[in] dev
797 : : * Pointer to the port.
798 : : * @param[in] acts
799 : : * Pointer to the template HW steering DR actions.
800 : : * @param[in] type
801 : : * Action type.
802 : : * @param[in] action_src
803 : : * Offset of source rte flow action.
804 : : * @param[in] action_dst
805 : : * Offset of destination DR action.
806 : : * @param[in] len
807 : : * Length of the data to be updated.
808 : : *
809 : : * @return
810 : : * Data pointer on success, NULL otherwise and rte_errno is set.
811 : : */
812 : : static __rte_always_inline void *
813 : : __flow_hw_act_data_push_append(struct rte_eth_dev *dev,
814 : : struct mlx5_hw_actions *acts,
815 : : enum rte_flow_action_type type,
816 : : uint16_t action_src,
817 : : uint16_t action_dst,
818 : : uint16_t len)
819 : : {
820 : : struct mlx5_action_construct_data *act_data;
821 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
822 : :
823 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
824 : : if (!act_data)
825 : : return NULL;
826 : 0 : act_data->ipv6_ext.len = len;
827 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
828 : : return act_data;
829 : : }
830 : :
831 : : static __rte_always_inline int
832 : : __flow_hw_act_data_hdr_modify_append(struct mlx5_priv *priv,
833 : : struct mlx5_hw_actions *acts,
834 : : enum rte_flow_action_type type,
835 : : uint16_t action_src,
836 : : uint16_t action_dst,
837 : : uint16_t mhdr_cmds_off,
838 : : uint16_t mhdr_cmds_end,
839 : : bool shared,
840 : : struct field_modify_info *field,
841 : : struct field_modify_info *dcopy,
842 : : uint32_t *mask)
843 : : {
844 : : struct mlx5_action_construct_data *act_data;
845 : :
846 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
847 : : if (!act_data)
848 : : return -1;
849 : 0 : act_data->modify_header.mhdr_cmds_off = mhdr_cmds_off;
850 : 0 : act_data->modify_header.mhdr_cmds_end = mhdr_cmds_end;
851 : 0 : act_data->modify_header.shared = shared;
852 [ # # ]: 0 : rte_memcpy(act_data->modify_header.field, field,
853 : : sizeof(*field) * MLX5_ACT_MAX_MOD_FIELDS);
854 [ # # ]: 0 : rte_memcpy(act_data->modify_header.dcopy, dcopy,
855 : : sizeof(*dcopy) * MLX5_ACT_MAX_MOD_FIELDS);
856 [ # # ]: 0 : rte_memcpy(act_data->modify_header.mask, mask,
857 : : sizeof(*mask) * MLX5_ACT_MAX_MOD_FIELDS);
858 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
859 : : return 0;
860 : : }
861 : :
862 : : /**
863 : : * Append shared RSS action to the dynamic action list.
864 : : *
865 : : * @param[in] priv
866 : : * Pointer to the port private data structure.
867 : : * @param[in] acts
868 : : * Pointer to the template HW steering DR actions.
869 : : * @param[in] type
870 : : * Action type.
871 : : * @param[in] action_src
872 : : * Offset of source rte flow action.
873 : : * @param[in] action_dst
874 : : * Offset of destination DR action.
875 : : * @param[in] idx
876 : : * Shared RSS index.
877 : : * @param[in] rss
878 : : * Pointer to the shared RSS info.
879 : : *
880 : : * @return
881 : : * 0 on success, negative value otherwise and rte_errno is set.
882 : : */
883 : : static __rte_always_inline int
884 : : __flow_hw_act_data_shared_rss_append(struct mlx5_priv *priv,
885 : : struct mlx5_hw_actions *acts,
886 : : enum rte_flow_action_type type,
887 : : uint16_t action_src,
888 : : uint16_t action_dst,
889 : : uint32_t idx,
890 : : struct mlx5_shared_action_rss *rss)
891 : : {
892 : : struct mlx5_action_construct_data *act_data;
893 : :
894 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
895 : : if (!act_data)
896 : : return -1;
897 : 0 : act_data->shared_rss.level = rss->origin.level;
898 [ # # ]: 0 : act_data->shared_rss.types = !rss->origin.types ? RTE_ETH_RSS_IP :
899 : : rss->origin.types;
900 : 0 : act_data->shared_rss.idx = idx;
901 : 0 : act_data->shared_rss.symmetric_hash_function =
902 : 0 : MLX5_RSS_IS_SYMM(rss->origin.func);
903 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
904 : : return 0;
905 : : }
906 : :
907 : : /**
908 : : * Append shared counter action to the dynamic action list.
909 : : *
910 : : * @param[in] priv
911 : : * Pointer to the port private data structure.
912 : : * @param[in] acts
913 : : * Pointer to the template HW steering DR actions.
914 : : * @param[in] type
915 : : * Action type.
916 : : * @param[in] action_src
917 : : * Offset of source rte flow action.
918 : : * @param[in] action_dst
919 : : * Offset of destination DR action.
920 : : * @param[in] cnt_id
921 : : * Shared counter id.
922 : : *
923 : : * @return
924 : : * 0 on success, negative value otherwise and rte_errno is set.
925 : : */
926 : : static __rte_always_inline int
927 : : __flow_hw_act_data_shared_cnt_append(struct mlx5_priv *priv,
928 : : struct mlx5_hw_actions *acts,
929 : : enum rte_flow_action_type type,
930 : : uint16_t action_src,
931 : : uint16_t action_dst,
932 : : cnt_id_t cnt_id)
933 : : {
934 : : struct mlx5_action_construct_data *act_data;
935 : :
936 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
937 : : if (!act_data)
938 : : return -1;
939 : : act_data->type = type;
940 : 0 : act_data->shared_counter.id = cnt_id;
941 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
942 : : return 0;
943 : : }
944 : :
945 : : /**
946 : : * Append shared meter_mark action to the dynamic action list.
947 : : *
948 : : * @param[in] priv
949 : : * Pointer to the port private data structure.
950 : : * @param[in] acts
951 : : * Pointer to the template HW steering DR actions.
952 : : * @param[in] type
953 : : * Action type.
954 : : * @param[in] action_src
955 : : * Offset of source rte flow action.
956 : : * @param[in] action_dst
957 : : * Offset of destination DR action.
958 : : * @param[in] mtr_id
959 : : * Shared meter id.
960 : : *
961 : : * @return
962 : : * 0 on success, negative value otherwise and rte_errno is set.
963 : : */
964 : : static __rte_always_inline int
965 : : __flow_hw_act_data_shared_mtr_append(struct mlx5_priv *priv,
966 : : struct mlx5_hw_actions *acts,
967 : : enum rte_flow_action_type type,
968 : : uint16_t action_src,
969 : : uint16_t action_dst,
970 : : cnt_id_t mtr_id)
971 : : { struct mlx5_action_construct_data *act_data;
972 : :
973 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
974 : : if (!act_data)
975 : : return -1;
976 : : act_data->type = type;
977 : 0 : act_data->shared_meter.id = mtr_id;
978 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
979 : : return 0;
980 : : }
981 : :
982 : : /**
983 : : * Translate shared indirect action.
984 : : *
985 : : * @param[in] dev
986 : : * Pointer to the rte_eth_dev data structure.
987 : : * @param[in] action
988 : : * Pointer to the shared indirect rte_flow action.
989 : : * @param[in] acts
990 : : * Pointer to the template HW steering DR actions.
991 : : * @param[in] action_src
992 : : * Offset of source rte flow action.
993 : : * @param[in] action_dst
994 : : * Offset of destination DR action.
995 : : *
996 : : * @return
997 : : * 0 on success, negative value otherwise and rte_errno is set.
998 : : */
999 : : static __rte_always_inline int
1000 : : flow_hw_shared_action_translate(struct rte_eth_dev *dev,
1001 : : const struct rte_flow_action *action,
1002 : : struct mlx5_hw_actions *acts,
1003 : : uint16_t action_src,
1004 : : uint16_t action_dst)
1005 : : {
1006 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1007 : : struct mlx5_shared_action_rss *shared_rss;
1008 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)action->conf;
1009 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
1010 : 0 : uint32_t idx = act_idx &
1011 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
1012 : :
1013 : 0 : switch (type) {
1014 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
1015 : 0 : shared_rss = mlx5_ipool_get
1016 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
1017 [ # # ]: 0 : if (!shared_rss || __flow_hw_act_data_shared_rss_append
1018 : : (priv, acts,
1019 : : (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_RSS,
1020 : : action_src, action_dst, idx, shared_rss))
1021 : : return -1;
1022 : : break;
1023 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
1024 : : if (__flow_hw_act_data_shared_cnt_append(priv, acts,
1025 : : (enum rte_flow_action_type)
1026 : : MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
1027 : : action_src, action_dst, act_idx))
1028 : : return -1;
1029 : : break;
1030 : : case MLX5_INDIRECT_ACTION_TYPE_AGE:
1031 : : /* Not supported, prevent by validate function. */
1032 : : MLX5_ASSERT(0);
1033 : : break;
1034 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
1035 : : if (flow_hw_ct_compile(dev, MLX5_HW_INV_QUEUE,
1036 : : idx, &acts->rule_acts[action_dst]))
1037 : : return -1;
1038 : : break;
1039 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
1040 : : if (__flow_hw_act_data_shared_mtr_append(priv, acts,
1041 : : (enum rte_flow_action_type)
1042 : : MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK,
1043 : : action_src, action_dst, idx))
1044 : : return -1;
1045 : : break;
1046 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
1047 : : flow_hw_construct_quota(priv, &acts->rule_acts[action_dst], idx);
1048 : : break;
1049 : 0 : default:
1050 : 0 : DRV_LOG(WARNING, "Unsupported shared action type:%d", type);
1051 : : break;
1052 : : }
1053 : : return 0;
1054 : : }
1055 : :
1056 : : static __rte_always_inline bool
1057 : : flow_hw_action_modify_field_is_shared(const struct rte_flow_action *action,
1058 : : const struct rte_flow_action *mask)
1059 : : {
1060 : : const struct rte_flow_action_modify_field *v = action->conf;
1061 : 0 : const struct rte_flow_action_modify_field *m = mask->conf;
1062 : :
1063 : 0 : if (v->src.field == RTE_FLOW_FIELD_VALUE) {
1064 : : uint32_t j;
1065 : :
1066 [ # # ]: 0 : for (j = 0; j < RTE_DIM(m->src.value); ++j) {
1067 : : /*
1068 : : * Immediate value is considered to be masked
1069 : : * (and thus shared by all flow rules), if mask
1070 : : * is non-zero. Partial mask over immediate value
1071 : : * is not allowed.
1072 : : */
1073 [ # # ]: 0 : if (m->src.value[j])
1074 : : return true;
1075 : : }
1076 : : return false;
1077 : : }
1078 [ # # ]: 0 : if (v->src.field == RTE_FLOW_FIELD_POINTER)
1079 : 0 : return m->src.pvalue != NULL;
1080 : : /*
1081 : : * Source field types other than VALUE and
1082 : : * POINTER are always shared.
1083 : : */
1084 : : return true;
1085 : : }
1086 : :
1087 : : static __rte_always_inline bool
1088 : : flow_hw_should_insert_nop(const struct mlx5_hw_modify_header_action *mhdr,
1089 : : const struct mlx5_modification_cmd *cmd)
1090 : : {
1091 : : struct mlx5_modification_cmd last_cmd = { { 0 } };
1092 : : struct mlx5_modification_cmd new_cmd = { { 0 } };
1093 : 0 : const uint32_t cmds_num = mhdr->mhdr_cmds_num;
1094 : : unsigned int last_type;
1095 : : bool should_insert = false;
1096 : :
1097 [ # # # # ]: 0 : if (cmds_num == 0)
1098 : : return false;
1099 : 0 : last_cmd = *(&mhdr->mhdr_cmds[cmds_num - 1]);
1100 [ # # # # ]: 0 : last_cmd.data0 = rte_be_to_cpu_32(last_cmd.data0);
1101 [ # # # # ]: 0 : last_cmd.data1 = rte_be_to_cpu_32(last_cmd.data1);
1102 : 0 : last_type = last_cmd.action_type;
1103 : 0 : new_cmd = *cmd;
1104 [ # # # # ]: 0 : new_cmd.data0 = rte_be_to_cpu_32(new_cmd.data0);
1105 [ # # # # ]: 0 : new_cmd.data1 = rte_be_to_cpu_32(new_cmd.data1);
1106 [ # # # # : 0 : switch (new_cmd.action_type) {
# # ]
1107 : 0 : case MLX5_MODIFICATION_TYPE_SET:
1108 : : case MLX5_MODIFICATION_TYPE_ADD:
1109 [ # # # # ]: 0 : if (last_type == MLX5_MODIFICATION_TYPE_SET ||
1110 : : last_type == MLX5_MODIFICATION_TYPE_ADD)
1111 : 0 : should_insert = new_cmd.field == last_cmd.field;
1112 : 0 : else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
1113 [ # # # # ]: 0 : last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
1114 : 0 : should_insert = new_cmd.field == last_cmd.dst_field;
1115 : : else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
1116 : : should_insert = false;
1117 : : else
1118 : : MLX5_ASSERT(false); /* Other types are not supported. */
1119 : : break;
1120 : 0 : case MLX5_MODIFICATION_TYPE_COPY:
1121 : : case MLX5_MODIFICATION_TYPE_ADD_FIELD:
1122 [ # # # # ]: 0 : if (last_type == MLX5_MODIFICATION_TYPE_SET ||
1123 : : last_type == MLX5_MODIFICATION_TYPE_ADD)
1124 [ # # # # ]: 0 : should_insert = (new_cmd.field == last_cmd.field ||
1125 [ # # # # ]: 0 : new_cmd.dst_field == last_cmd.field);
1126 : 0 : else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
1127 [ # # # # ]: 0 : last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
1128 [ # # # # ]: 0 : should_insert = (new_cmd.field == last_cmd.dst_field ||
1129 [ # # # # ]: 0 : new_cmd.dst_field == last_cmd.dst_field);
1130 : : else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
1131 : : should_insert = false;
1132 : : else
1133 : : MLX5_ASSERT(false); /* Other types are not supported. */
1134 : : break;
1135 : : default:
1136 : : /* Other action types should be rejected on AT validation. */
1137 : : MLX5_ASSERT(false);
1138 : : break;
1139 : : }
1140 : : return should_insert;
1141 : : }
1142 : :
1143 : : static __rte_always_inline int
1144 : : flow_hw_mhdr_cmd_nop_append(struct mlx5_hw_modify_header_action *mhdr)
1145 : : {
1146 : : struct mlx5_modification_cmd *nop;
1147 : : uint32_t num = mhdr->mhdr_cmds_num;
1148 : :
1149 [ # # # # ]: 0 : if (num + 1 >= MLX5_MHDR_MAX_CMD)
1150 : : return -ENOMEM;
1151 : 0 : nop = mhdr->mhdr_cmds + num;
1152 : : nop->data0 = 0;
1153 : : nop->action_type = MLX5_MODIFICATION_TYPE_NOP;
1154 : 0 : nop->data0 = rte_cpu_to_be_32(nop->data0);
1155 : 0 : nop->data1 = 0;
1156 : 0 : mhdr->mhdr_cmds_num = num + 1;
1157 : : return 0;
1158 : : }
1159 : :
1160 : : static __rte_always_inline int
1161 : : flow_hw_mhdr_cmd_append(struct mlx5_hw_modify_header_action *mhdr,
1162 : : struct mlx5_modification_cmd *cmd)
1163 : : {
1164 : 0 : uint32_t num = mhdr->mhdr_cmds_num;
1165 : :
1166 [ # # ]: 0 : if (num + 1 >= MLX5_MHDR_MAX_CMD)
1167 : : return -ENOMEM;
1168 : 0 : mhdr->mhdr_cmds[num] = *cmd;
1169 : 0 : mhdr->mhdr_cmds_num = num + 1;
1170 : : return 0;
1171 : : }
1172 : :
1173 : : static __rte_always_inline int
1174 : : flow_hw_converted_mhdr_cmds_append(struct mlx5_hw_modify_header_action *mhdr,
1175 : : struct mlx5_flow_dv_modify_hdr_resource *resource)
1176 : : {
1177 : : uint32_t idx;
1178 : : int ret;
1179 : :
1180 [ # # ]: 0 : for (idx = 0; idx < resource->actions_num; ++idx) {
1181 : : struct mlx5_modification_cmd *src = &resource->actions[idx];
1182 : :
1183 [ # # ]: 0 : if (flow_hw_should_insert_nop(mhdr, src)) {
1184 : : ret = flow_hw_mhdr_cmd_nop_append(mhdr);
1185 : : if (ret)
1186 : : return ret;
1187 : : }
1188 : : ret = flow_hw_mhdr_cmd_append(mhdr, src);
1189 : : if (ret)
1190 : : return ret;
1191 : : }
1192 : : return 0;
1193 : : }
1194 : :
1195 : : static __rte_always_inline void
1196 : : flow_hw_modify_field_init(struct mlx5_hw_modify_header_action *mhdr,
1197 : : struct rte_flow_actions_template *at)
1198 : : {
1199 : : memset(mhdr, 0, sizeof(*mhdr));
1200 : : /* Modify header action without any commands is shared by default. */
1201 : 0 : mhdr->shared = true;
1202 : 0 : mhdr->pos = at->mhdr_off;
1203 : : }
1204 : :
1205 : : static __rte_always_inline int
1206 : : flow_hw_modify_field_compile(struct rte_eth_dev *dev,
1207 : : const struct rte_flow_attr *attr,
1208 : : const struct rte_flow_action *action, /* Current action from AT. */
1209 : : const struct rte_flow_action *action_mask, /* Current mask from AT. */
1210 : : struct mlx5_hw_actions *acts,
1211 : : struct mlx5_hw_modify_header_action *mhdr,
1212 : : uint16_t src_pos,
1213 : : struct rte_flow_error *error)
1214 : : {
1215 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1216 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
1217 : : union {
1218 : : struct mlx5_flow_dv_modify_hdr_resource resource;
1219 : : uint8_t data[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
1220 : : sizeof(struct mlx5_modification_cmd) * MLX5_MHDR_MAX_CMD];
1221 : : } dummy;
1222 : : struct mlx5_flow_dv_modify_hdr_resource *resource;
1223 : 0 : struct rte_flow_item item = {
1224 : : .spec = NULL,
1225 : : .mask = NULL
1226 : : };
1227 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1228 : : {0, 0, MLX5_MODI_OUT_NONE} };
1229 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1230 : : {0, 0, MLX5_MODI_OUT_NONE} };
1231 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = { 0 };
1232 : 0 : uint32_t type, value = 0;
1233 : : uint16_t cmds_start, cmds_end;
1234 : : bool shared;
1235 : : int ret;
1236 : :
1237 : : /*
1238 : : * Modify header action is shared if previous modify_field actions
1239 : : * are shared and currently compiled action is shared.
1240 : : */
1241 : : shared = flow_hw_action_modify_field_is_shared(action, action_mask);
1242 : 0 : mhdr->shared &= shared;
1243 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1244 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
1245 [ # # ]: 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ? MLX5_MODIFICATION_TYPE_SET :
1246 : : MLX5_MODIFICATION_TYPE_ADD;
1247 : : /* For SET/ADD fill the destination field (field) first. */
1248 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1249 : 0 : conf->width, dev,
1250 : : attr, error);
1251 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1252 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
1253 : : (void *)(uintptr_t)&conf->src.value;
1254 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
1255 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
1256 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR ||
1257 : 0 : conf->dst.field == (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
1258 : : uint8_t tag_index = flow_tag_index_get(&conf->dst);
1259 : :
1260 : 0 : value = *(const unaligned_uint32_t *)item.spec;
1261 [ # # # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_TAG &&
1262 : : tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
1263 [ # # ]: 0 : value = rte_cpu_to_be_32(value << 16);
1264 : : else
1265 [ # # ]: 0 : value = rte_cpu_to_be_32(value);
1266 : 0 : item.spec = &value;
1267 [ # # ]: 0 : } else if (conf->dst.field == RTE_FLOW_FIELD_GTP_PSC_QFI ||
1268 : : conf->dst.field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE) {
1269 : : /*
1270 : : * Both QFI and Geneve option type are passed as an uint8_t integer,
1271 : : * but it is accessed through a 2nd least significant byte of a 32-bit
1272 : : * field in modify header command.
1273 : : */
1274 : 0 : value = *(const uint8_t *)item.spec;
1275 [ # # ]: 0 : value = rte_cpu_to_be_32(value << 8);
1276 : 0 : item.spec = &value;
1277 : : }
1278 : : } else {
1279 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
1280 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_COPY : MLX5_MODIFICATION_TYPE_ADD_FIELD;
1281 : : /* For COPY fill the destination field (dcopy) without mask. */
1282 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1283 : 0 : conf->width, dev,
1284 : : attr, error);
1285 : : /* Then construct the source field (field) with mask. */
1286 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1287 : 0 : conf->width, dev,
1288 : : attr, error);
1289 : : }
1290 : 0 : item.mask = &mask;
1291 : : memset(&dummy, 0, sizeof(dummy));
1292 : : resource = &dummy.resource;
1293 : 0 : ret = flow_dv_convert_modify_action(&item, field, dcopy, resource, type, error);
1294 [ # # ]: 0 : if (ret)
1295 : : return ret;
1296 : : MLX5_ASSERT(resource->actions_num > 0);
1297 : : /*
1298 : : * If previous modify field action collide with this one, then insert NOP command.
1299 : : * This NOP command will not be a part of action's command range used to update commands
1300 : : * on rule creation.
1301 : : */
1302 [ # # ]: 0 : if (flow_hw_should_insert_nop(mhdr, &resource->actions[0])) {
1303 : : ret = flow_hw_mhdr_cmd_nop_append(mhdr);
1304 : : if (ret)
1305 : 0 : return rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1306 : : NULL, "too many modify field operations specified");
1307 : : }
1308 : 0 : cmds_start = mhdr->mhdr_cmds_num;
1309 : : ret = flow_hw_converted_mhdr_cmds_append(mhdr, resource);
1310 [ # # ]: 0 : if (ret)
1311 : 0 : return rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1312 : : NULL, "too many modify field operations specified");
1313 : :
1314 : 0 : cmds_end = mhdr->mhdr_cmds_num;
1315 [ # # ]: 0 : if (shared)
1316 : : return 0;
1317 : : ret = __flow_hw_act_data_hdr_modify_append(priv, acts, RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
1318 : 0 : src_pos, mhdr->pos,
1319 : : cmds_start, cmds_end, shared,
1320 : : field, dcopy, mask);
1321 : : if (ret)
1322 : 0 : return rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1323 : : NULL, "not enough memory to store modify field metadata");
1324 : : return 0;
1325 : : }
1326 : :
1327 : : static uint32_t
1328 : 0 : flow_hw_count_nop_modify_field(struct mlx5_hw_modify_header_action *mhdr)
1329 : : {
1330 : : uint32_t i;
1331 : : uint32_t nops = 0;
1332 : :
1333 [ # # ]: 0 : for (i = 0; i < mhdr->mhdr_cmds_num; ++i) {
1334 : 0 : struct mlx5_modification_cmd cmd = mhdr->mhdr_cmds[i];
1335 : :
1336 [ # # ]: 0 : cmd.data0 = rte_be_to_cpu_32(cmd.data0);
1337 [ # # ]: 0 : if (cmd.action_type == MLX5_MODIFICATION_TYPE_NOP)
1338 : 0 : ++nops;
1339 : : }
1340 : 0 : return nops;
1341 : : }
1342 : :
1343 : : static int
1344 : 0 : flow_hw_validate_compiled_modify_field(struct rte_eth_dev *dev,
1345 : : const struct mlx5_flow_template_table_cfg *cfg,
1346 : : struct mlx5_hw_modify_header_action *mhdr,
1347 : : struct rte_flow_error *error)
1348 : : {
1349 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1350 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
1351 : :
1352 : : /*
1353 : : * Header modify pattern length limitation is only valid for HWS groups, i.e. groups > 0.
1354 : : * In group 0, MODIFY_FIELD actions are handled with header modify actions
1355 : : * managed by rdma-core.
1356 : : */
1357 [ # # ]: 0 : if (cfg->attr.flow_attr.group != 0 &&
1358 [ # # ]: 0 : mhdr->mhdr_cmds_num > hca_attr->max_header_modify_pattern_length) {
1359 : 0 : uint32_t nops = flow_hw_count_nop_modify_field(mhdr);
1360 : :
1361 : 0 : DRV_LOG(ERR, "Too many modify header commands generated from "
1362 : : "MODIFY_FIELD actions. "
1363 : : "Generated HW commands = %u (amount of NOP commands = %u). "
1364 : : "Maximum supported = %u.",
1365 : : mhdr->mhdr_cmds_num, nops,
1366 : : hca_attr->max_header_modify_pattern_length);
1367 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1368 : : "Number of MODIFY_FIELD actions exceeds maximum "
1369 : : "supported limit of actions");
1370 : : }
1371 : : return 0;
1372 : : }
1373 : :
1374 : : static int
1375 : 0 : flow_hw_represented_port_compile(struct rte_eth_dev *dev,
1376 : : const struct rte_flow_attr *attr,
1377 : : const struct rte_flow_action *action,
1378 : : const struct rte_flow_action *action_mask,
1379 : : struct mlx5_hw_actions *acts,
1380 : : uint16_t action_src, uint16_t action_dst,
1381 : : struct rte_flow_error *error)
1382 : : {
1383 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1384 : 0 : const struct rte_flow_action_ethdev *v = action->conf;
1385 : 0 : const struct rte_flow_action_ethdev *m = action_mask->conf;
1386 : : int ret;
1387 : :
1388 [ # # ]: 0 : if (!attr->group)
1389 : 0 : return rte_flow_error_set(error, EINVAL,
1390 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1391 : : "represented_port action cannot"
1392 : : " be used on group 0");
1393 [ # # ]: 0 : if (!attr->transfer)
1394 : 0 : return rte_flow_error_set(error, EINVAL,
1395 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1396 : : NULL,
1397 : : "represented_port action requires"
1398 : : " transfer attribute");
1399 [ # # ]: 0 : if (attr->ingress || attr->egress)
1400 : 0 : return rte_flow_error_set(error, EINVAL,
1401 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1402 : : "represented_port action cannot"
1403 : : " be used with direction attributes");
1404 [ # # ]: 0 : if (!priv->master)
1405 : 0 : return rte_flow_error_set(error, EINVAL,
1406 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1407 : : "represented_port action must"
1408 : : " be used on proxy port");
1409 [ # # # # ]: 0 : if (m && !!m->port_id) {
1410 : : struct mlx5_priv *port_priv;
1411 : :
1412 [ # # ]: 0 : if (!v)
1413 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1414 : : action, "port index was not provided");
1415 : 0 : port_priv = mlx5_port_to_eswitch_info(v->port_id, false);
1416 [ # # ]: 0 : if (port_priv == NULL)
1417 : 0 : return rte_flow_error_set
1418 : : (error, EINVAL,
1419 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1420 : : "port does not exist or unable to"
1421 : : " obtain E-Switch info for port");
1422 : : MLX5_ASSERT(priv->hw_vport != NULL);
1423 [ # # ]: 0 : if (priv->hw_vport[v->port_id]) {
1424 : 0 : acts->rule_acts[action_dst].action =
1425 : : priv->hw_vport[v->port_id];
1426 : : } else {
1427 : 0 : return rte_flow_error_set
1428 : : (error, EINVAL,
1429 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1430 : : "cannot use represented_port action"
1431 : : " with this port");
1432 : : }
1433 : : } else {
1434 : : ret = __flow_hw_act_data_general_append
1435 : 0 : (priv, acts, action->type,
1436 : : action_src, action_dst);
1437 : : if (ret)
1438 : 0 : return rte_flow_error_set
1439 : : (error, ENOMEM,
1440 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1441 : : "not enough memory to store"
1442 : : " vport action");
1443 : : }
1444 : : return 0;
1445 : : }
1446 : :
1447 : : static __rte_always_inline int
1448 : : flow_hw_meter_compile(struct rte_eth_dev *dev,
1449 : : const struct mlx5_flow_template_table_cfg *cfg,
1450 : : uint16_t aso_mtr_pos,
1451 : : uint16_t jump_pos,
1452 : : const struct rte_flow_action *action,
1453 : : struct mlx5_hw_actions *acts,
1454 : : struct rte_flow_error *error)
1455 : : {
1456 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1457 : : struct mlx5_aso_mtr *aso_mtr;
1458 : : const struct rte_flow_action_meter *meter = action->conf;
1459 : 0 : uint32_t group = cfg->attr.flow_attr.group;
1460 : :
1461 : 0 : aso_mtr = mlx5_aso_meter_by_idx(priv, meter->mtr_id);
1462 : 0 : acts->rule_acts[aso_mtr_pos].action = priv->mtr_bulk.action;
1463 : 0 : acts->rule_acts[aso_mtr_pos].aso_meter.offset = aso_mtr->offset;
1464 : 0 : acts->jump = flow_hw_jump_action_register
1465 : 0 : (dev, cfg, aso_mtr->fm.group, error);
1466 [ # # ]: 0 : if (!acts->jump)
1467 : : return -ENOMEM;
1468 : 0 : acts->rule_acts[jump_pos].action = (!!group) ?
1469 [ # # ]: 0 : acts->jump->hws_action :
1470 : : acts->jump->root_action;
1471 [ # # ]: 0 : if (mlx5_aso_mtr_wait(priv->sh, MLX5_HW_INV_QUEUE, aso_mtr))
1472 : : return -ENOMEM;
1473 : : return 0;
1474 : : }
1475 : :
1476 : : static __rte_always_inline int
1477 : : flow_hw_cnt_compile(struct rte_eth_dev *dev, uint32_t start_pos,
1478 : : struct mlx5_hw_actions *acts)
1479 : : {
1480 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1481 : : uint32_t pos = start_pos;
1482 : : cnt_id_t cnt_id;
1483 : : int ret;
1484 : :
1485 : 0 : ret = mlx5_hws_cnt_shared_get(priv->hws_cpool, &cnt_id, 0);
1486 : : if (ret != 0)
1487 : : return ret;
1488 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
1489 : : (priv->hws_cpool,
1490 : : cnt_id,
1491 : : &acts->rule_acts[pos].action,
1492 : : &acts->rule_acts[pos].counter.offset);
1493 : : if (ret != 0)
1494 : : return ret;
1495 : 0 : acts->cnt_id = cnt_id;
1496 : : return 0;
1497 : : }
1498 : :
1499 : : static __rte_always_inline bool
1500 : : is_of_vlan_pcp_present(const struct rte_flow_action *actions)
1501 : : {
1502 : : /*
1503 : : * Order of RTE VLAN push actions is
1504 : : * OF_PUSH_VLAN / OF_SET_VLAN_VID [ / OF_SET_VLAN_PCP ]
1505 : : */
1506 : 0 : return actions[MLX5_HW_VLAN_PUSH_PCP_IDX].type ==
1507 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP;
1508 : : }
1509 : :
1510 : : static __rte_always_inline bool
1511 : : is_template_masked_push_vlan(const struct rte_flow_action_of_push_vlan *mask)
1512 : : {
1513 : : /*
1514 : : * In masked push VLAN template all RTE push actions are masked.
1515 : : */
1516 [ # # ]: 0 : return mask && mask->ethertype != 0;
1517 : : }
1518 : :
1519 : 0 : static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
1520 : : {
1521 : : /*
1522 : : * OpenFlow Switch Specification defines 801.1q VID as 12+1 bits.
1523 : : */
1524 : : rte_be32_t type, vid, pcp;
1525 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1526 : : rte_be32_t vid_lo, vid_hi;
1527 : : #endif
1528 : :
1529 : 0 : type = ((const struct rte_flow_action_of_push_vlan *)
1530 : 0 : actions[MLX5_HW_VLAN_PUSH_TYPE_IDX].conf)->ethertype;
1531 : 0 : vid = ((const struct rte_flow_action_of_set_vlan_vid *)
1532 : 0 : actions[MLX5_HW_VLAN_PUSH_VID_IDX].conf)->vlan_vid;
1533 : : pcp = is_of_vlan_pcp_present(actions) ?
1534 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
1535 [ # # # # ]: 0 : actions[MLX5_HW_VLAN_PUSH_PCP_IDX].conf)->vlan_pcp : 0;
1536 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1537 : 0 : vid_hi = vid & 0xff;
1538 : : vid_lo = vid >> 8;
1539 : 0 : return (((vid_lo << 8) | (pcp << 5) | vid_hi) << 16) | type;
1540 : : #else
1541 : : return (type << 16) | (pcp << 13) | vid;
1542 : : #endif
1543 : : }
1544 : :
1545 : : static __rte_always_inline struct mlx5_aso_mtr *
1546 : : flow_hw_meter_mark_alloc(struct rte_eth_dev *dev, uint32_t queue,
1547 : : const struct rte_flow_action *action,
1548 : : void *user_data, bool push)
1549 : : {
1550 : : struct mlx5_priv *priv = dev->data->dev_private;
1551 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
1552 : 0 : const struct rte_flow_action_meter_mark *meter_mark = action->conf;
1553 : : struct mlx5_aso_mtr *aso_mtr;
1554 : : struct mlx5_flow_meter_info *fm;
1555 : : uint32_t mtr_id;
1556 : :
1557 : 0 : if (meter_mark->profile == NULL)
1558 : : return NULL;
1559 : 0 : aso_mtr = mlx5_ipool_malloc(priv->hws_mpool->idx_pool, &mtr_id);
1560 [ # # # # : 0 : if (!aso_mtr)
# # # # #
# ]
1561 : : return NULL;
1562 : : /* Fill the flow meter parameters. */
1563 : 0 : aso_mtr->type = ASO_METER_INDIRECT;
1564 : : fm = &aso_mtr->fm;
1565 : 0 : fm->meter_id = mtr_id;
1566 : 0 : fm->profile = (struct mlx5_flow_meter_profile *)(meter_mark->profile);
1567 : 0 : fm->is_enable = meter_mark->state;
1568 : 0 : fm->color_aware = meter_mark->color_mode;
1569 : 0 : aso_mtr->pool = pool;
1570 [ # # ]: 0 : aso_mtr->state = (queue == MLX5_HW_INV_QUEUE) ?
1571 : : ASO_METER_WAIT : ASO_METER_WAIT_ASYNC;
1572 : 0 : aso_mtr->offset = mtr_id - 1;
1573 [ # # # # : 0 : aso_mtr->init_color = fm->color_aware ? RTE_COLORS : RTE_COLOR_GREEN;
# # # # #
# ]
1574 : : /* Update ASO flow meter by wqe. */
1575 [ # # # # : 0 : if (mlx5_aso_meter_update_by_wqe(priv->sh, queue, aso_mtr,
# # # # #
# ]
1576 : : &priv->mtr_bulk, user_data, push)) {
1577 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
1578 : : return NULL;
1579 : : }
1580 : : /* Wait for ASO object completion. */
1581 [ # # # # : 0 : if (queue == MLX5_HW_INV_QUEUE &&
# # # # #
# # # ]
1582 : 0 : mlx5_aso_mtr_wait(priv->sh, MLX5_HW_INV_QUEUE, aso_mtr)) {
1583 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
1584 : : return NULL;
1585 : : }
1586 : : return aso_mtr;
1587 : : }
1588 : :
1589 : : static __rte_always_inline int
1590 : : flow_hw_meter_mark_compile(struct rte_eth_dev *dev,
1591 : : uint16_t aso_mtr_pos,
1592 : : const struct rte_flow_action *action,
1593 : : struct mlx5dr_rule_action *acts,
1594 : : uint32_t *index,
1595 : : uint32_t queue)
1596 : : {
1597 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1598 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
1599 : : struct mlx5_aso_mtr *aso_mtr;
1600 : :
1601 : : aso_mtr = flow_hw_meter_mark_alloc(dev, queue, action, NULL, true);
1602 : : if (!aso_mtr)
1603 : : return -1;
1604 : :
1605 : : /* Compile METER_MARK action */
1606 : 0 : acts[aso_mtr_pos].action = pool->action;
1607 : 0 : acts[aso_mtr_pos].aso_meter.offset = aso_mtr->offset;
1608 : 0 : *index = aso_mtr->fm.meter_id;
1609 : : return 0;
1610 : : }
1611 : :
1612 : : static int
1613 : 0 : flow_hw_translate_indirect_mirror(__rte_unused struct rte_eth_dev *dev,
1614 : : __rte_unused const struct mlx5_action_construct_data *act_data,
1615 : : const struct rte_flow_action *action,
1616 : : struct mlx5dr_rule_action *dr_rule)
1617 : : {
1618 : 0 : const struct rte_flow_action_indirect_list *list_conf = action->conf;
1619 : 0 : const struct mlx5_mirror *mirror = (typeof(mirror))list_conf->handle;
1620 : :
1621 : 0 : dr_rule->action = mirror->mirror_action;
1622 : 0 : return 0;
1623 : : }
1624 : :
1625 : : /**
1626 : : * HWS mirror implemented as FW island.
1627 : : * The action does not support indirect list flow configuration.
1628 : : * If template handle was masked, use handle mirror action in flow rules.
1629 : : * Otherwise let flow rule specify mirror handle.
1630 : : */
1631 : : static int
1632 : 0 : hws_table_tmpl_translate_indirect_mirror(struct rte_eth_dev *dev,
1633 : : const struct rte_flow_action *action,
1634 : : const struct rte_flow_action *mask,
1635 : : struct mlx5_hw_actions *acts,
1636 : : uint16_t action_src, uint16_t action_dst)
1637 : : {
1638 : : int ret = 0;
1639 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
1640 : :
1641 [ # # # # ]: 0 : if (mask_conf && mask_conf->handle) {
1642 : : /**
1643 : : * If mirror handle was masked, assign fixed DR5 mirror action.
1644 : : */
1645 : : flow_hw_translate_indirect_mirror(dev, NULL, action,
1646 : 0 : &acts->rule_acts[action_dst]);
1647 : : } else {
1648 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1649 : : ret = flow_hw_act_data_indirect_list_append
1650 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
1651 : : action_src, action_dst,
1652 : : flow_hw_translate_indirect_mirror);
1653 : : }
1654 : 0 : return ret;
1655 : : }
1656 : :
1657 : : static int
1658 : 0 : flow_hw_reformat_action(__rte_unused struct rte_eth_dev *dev,
1659 : : __rte_unused const struct mlx5_action_construct_data *data,
1660 : : const struct rte_flow_action *action,
1661 : : struct mlx5dr_rule_action *dr_rule)
1662 : : {
1663 : 0 : const struct rte_flow_action_indirect_list *indlst_conf = action->conf;
1664 : :
1665 : 0 : dr_rule->action = ((struct mlx5_hw_encap_decap_action *)
1666 : 0 : (indlst_conf->handle))->action;
1667 [ # # ]: 0 : if (!dr_rule->action)
1668 : 0 : return -EINVAL;
1669 : : return 0;
1670 : : }
1671 : :
1672 : : /**
1673 : : * Template conf must not be masked. If handle is masked, use the one in template,
1674 : : * otherwise update per flow rule.
1675 : : */
1676 : : static int
1677 : 0 : hws_table_tmpl_translate_indirect_reformat(struct rte_eth_dev *dev,
1678 : : const struct rte_flow_action *action,
1679 : : const struct rte_flow_action *mask,
1680 : : struct mlx5_hw_actions *acts,
1681 : : uint16_t action_src, uint16_t action_dst)
1682 : : {
1683 : : int ret = -1;
1684 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
1685 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1686 : :
1687 [ # # # # : 0 : if (mask_conf && mask_conf->handle && !mask_conf->conf)
# # ]
1688 : : /**
1689 : : * If handle was masked, assign fixed DR action.
1690 : : */
1691 : : ret = flow_hw_reformat_action(dev, NULL, action,
1692 [ # # ]: 0 : &acts->rule_acts[action_dst]);
1693 [ # # # # : 0 : else if (mask_conf && !mask_conf->handle && !mask_conf->conf)
# # ]
1694 : : ret = flow_hw_act_data_indirect_list_append
1695 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
1696 : : action_src, action_dst, flow_hw_reformat_action);
1697 : 0 : return ret;
1698 : : }
1699 : :
1700 : : static int
1701 : 0 : flow_dr_set_meter(struct mlx5_priv *priv,
1702 : : struct mlx5dr_rule_action *dr_rule,
1703 : : const struct rte_flow_action_indirect_list *action_conf)
1704 : : {
1705 : 0 : const struct mlx5_indlst_legacy *legacy_obj =
1706 : : (typeof(legacy_obj))action_conf->handle;
1707 : 0 : struct mlx5_aso_mtr_pool *mtr_pool = priv->hws_mpool;
1708 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)legacy_obj->handle;
1709 : 0 : uint32_t mtr_id = act_idx & (RTE_BIT32(MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
1710 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_ipool_get(mtr_pool->idx_pool, mtr_id);
1711 : :
1712 [ # # ]: 0 : if (!aso_mtr)
1713 : : return -EINVAL;
1714 : 0 : dr_rule->action = mtr_pool->action;
1715 : 0 : dr_rule->aso_meter.offset = aso_mtr->offset;
1716 : 0 : return 0;
1717 : : }
1718 : :
1719 : : __rte_always_inline static void
1720 : : flow_dr_mtr_flow_color(struct mlx5dr_rule_action *dr_rule, enum rte_color init_color)
1721 : : {
1722 : 0 : dr_rule->aso_meter.init_color =
1723 : 0 : (enum mlx5dr_action_aso_meter_color)rte_col_2_mlx5_col(init_color);
1724 : 0 : }
1725 : :
1726 : : static int
1727 : 0 : flow_hw_translate_indirect_meter(struct rte_eth_dev *dev,
1728 : : const struct mlx5_action_construct_data *act_data,
1729 : : const struct rte_flow_action *action,
1730 : : struct mlx5dr_rule_action *dr_rule)
1731 : : {
1732 : : int ret;
1733 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1734 : 0 : const struct rte_flow_action_indirect_list *action_conf = action->conf;
1735 : 0 : const struct rte_flow_indirect_update_flow_meter_mark **flow_conf =
1736 : : (typeof(flow_conf))action_conf->conf;
1737 : :
1738 : : /*
1739 : : * Masked indirect handle set dr5 action during template table
1740 : : * translation.
1741 : : */
1742 [ # # ]: 0 : if (!dr_rule->action) {
1743 : 0 : ret = flow_dr_set_meter(priv, dr_rule, action_conf);
1744 [ # # ]: 0 : if (ret)
1745 : : return ret;
1746 : : }
1747 [ # # ]: 0 : if (!act_data->shared_meter.conf_masked) {
1748 [ # # # # : 0 : if (flow_conf && flow_conf[0] && flow_conf[0]->init_color < RTE_COLORS)
# # ]
1749 : : flow_dr_mtr_flow_color(dr_rule, flow_conf[0]->init_color);
1750 : : }
1751 : : return 0;
1752 : : }
1753 : :
1754 : : static int
1755 : 0 : hws_table_tmpl_translate_indirect_meter(struct rte_eth_dev *dev,
1756 : : const struct rte_flow_action *action,
1757 : : const struct rte_flow_action *mask,
1758 : : struct mlx5_hw_actions *acts,
1759 : : uint16_t action_src, uint16_t action_dst)
1760 : : {
1761 : : int ret;
1762 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1763 : 0 : const struct rte_flow_action_indirect_list *action_conf = action->conf;
1764 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
1765 [ # # # # ]: 0 : bool is_handle_masked = mask_conf && mask_conf->handle;
1766 [ # # # # : 0 : bool is_conf_masked = mask_conf && mask_conf->conf && mask_conf->conf[0];
# # ]
1767 : 0 : struct mlx5dr_rule_action *dr_rule = &acts->rule_acts[action_dst];
1768 : :
1769 [ # # ]: 0 : if (is_handle_masked) {
1770 : 0 : ret = flow_dr_set_meter(priv, dr_rule, action->conf);
1771 [ # # ]: 0 : if (ret)
1772 : : return ret;
1773 : : }
1774 [ # # ]: 0 : if (is_conf_masked) {
1775 : : const struct
1776 : 0 : rte_flow_indirect_update_flow_meter_mark **flow_conf =
1777 : : (typeof(flow_conf))action_conf->conf;
1778 : : flow_dr_mtr_flow_color(dr_rule,
1779 [ # # ]: 0 : flow_conf[0]->init_color);
1780 : : }
1781 [ # # ]: 0 : if (!is_handle_masked || !is_conf_masked) {
1782 : : struct mlx5_action_construct_data *act_data;
1783 : :
1784 : : ret = flow_hw_act_data_indirect_list_append
1785 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
1786 : : action_src, action_dst, flow_hw_translate_indirect_meter);
1787 : : if (ret)
1788 : 0 : return ret;
1789 : : act_data = LIST_FIRST(&acts->act_list);
1790 : 0 : act_data->shared_meter.conf_masked = is_conf_masked;
1791 : : }
1792 : : return 0;
1793 : : }
1794 : :
1795 : : static int
1796 : : hws_table_tmpl_translate_indirect_legacy(struct rte_eth_dev *dev,
1797 : : const struct rte_flow_action *action,
1798 : : const struct rte_flow_action *mask,
1799 : : struct mlx5_hw_actions *acts,
1800 : : uint16_t action_src, uint16_t action_dst)
1801 : : {
1802 : : int ret;
1803 : : const struct rte_flow_action_indirect_list *indlst_conf = action->conf;
1804 : : struct mlx5_indlst_legacy *indlst_obj = (typeof(indlst_obj))indlst_conf->handle;
1805 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)indlst_obj->handle;
1806 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
1807 : :
1808 : 0 : switch (type) {
1809 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
1810 : 0 : ret = hws_table_tmpl_translate_indirect_meter(dev, action, mask,
1811 : : acts, action_src,
1812 : : action_dst);
1813 : 0 : break;
1814 : : default:
1815 : : ret = -EINVAL;
1816 : : break;
1817 : : }
1818 : : return ret;
1819 : : }
1820 : :
1821 : : /*
1822 : : * template .. indirect_list handle Ht conf Ct ..
1823 : : * mask .. indirect_list handle Hm conf Cm ..
1824 : : *
1825 : : * PMD requires Ht != 0 to resolve handle type.
1826 : : * If Ht was masked (Hm != 0) DR5 action will be set according to Ht and will
1827 : : * not change. Otherwise, DR5 action will be resolved during flow rule build.
1828 : : * If Ct was masked (Cm != 0), table template processing updates base
1829 : : * indirect action configuration with Ct parameters.
1830 : : */
1831 : : static int
1832 : 0 : table_template_translate_indirect_list(struct rte_eth_dev *dev,
1833 : : const struct rte_flow_action *action,
1834 : : const struct rte_flow_action *mask,
1835 : : struct mlx5_hw_actions *acts,
1836 : : uint16_t action_src, uint16_t action_dst)
1837 : : {
1838 : : int ret = 0;
1839 : : enum mlx5_indirect_list_type type;
1840 : 0 : const struct rte_flow_action_indirect_list *list_conf = action->conf;
1841 : :
1842 [ # # # # ]: 0 : if (!list_conf || !list_conf->handle)
1843 : : return -EINVAL;
1844 : : type = mlx5_get_indirect_list_type(list_conf->handle);
1845 [ # # # # ]: 0 : switch (type) {
1846 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
1847 [ # # ]: 0 : ret = hws_table_tmpl_translate_indirect_legacy(dev, action, mask,
1848 : : acts, action_src,
1849 : : action_dst);
1850 : : break;
1851 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
1852 : 0 : ret = hws_table_tmpl_translate_indirect_mirror(dev, action, mask,
1853 : : acts, action_src,
1854 : : action_dst);
1855 : 0 : break;
1856 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
1857 [ # # ]: 0 : if (list_conf->conf)
1858 : : return -EINVAL;
1859 : 0 : ret = hws_table_tmpl_translate_indirect_reformat(dev, action, mask,
1860 : : acts, action_src,
1861 : : action_dst);
1862 : 0 : break;
1863 : : default:
1864 : : return -EINVAL;
1865 : : }
1866 : : return ret;
1867 : : }
1868 : :
1869 : : static int
1870 [ # # ]: 0 : mlx5_tbl_translate_reformat(struct mlx5_priv *priv,
1871 : : const struct rte_flow_template_table_attr *table_attr,
1872 : : struct mlx5_hw_actions *acts,
1873 : : struct rte_flow_actions_template *at,
1874 : : const struct rte_flow_item *enc_item,
1875 : : const struct rte_flow_item *enc_item_m,
1876 : : uint8_t *encap_data, uint8_t *encap_data_m,
1877 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
1878 : : size_t data_size, uint16_t reformat_src,
1879 : : enum mlx5dr_action_type refmt_type,
1880 : : struct rte_flow_error *error)
1881 : : {
1882 : : int mp_reformat_ix = mlx5_multi_pattern_reformat_to_index(refmt_type);
1883 : : const struct rte_flow_attr *attr = &table_attr->flow_attr;
1884 : : enum mlx5dr_table_type tbl_type = get_mlx5dr_table_type(attr);
1885 : : struct mlx5dr_action_reformat_header hdr;
1886 : : uint8_t buf[MLX5_ENCAP_MAX_LEN];
1887 : : bool shared_rfmt = false;
1888 : : int ret;
1889 : :
1890 : : MLX5_ASSERT(at->reformat_off != UINT16_MAX);
1891 [ # # ]: 0 : if (enc_item) {
1892 : : MLX5_ASSERT(!encap_data);
1893 : 0 : ret = flow_dv_convert_encap_data(enc_item, buf, &data_size, error);
1894 [ # # ]: 0 : if (ret)
1895 : : return ret;
1896 : : encap_data = buf;
1897 [ # # ]: 0 : if (enc_item_m)
1898 : : shared_rfmt = true;
1899 [ # # ]: 0 : } else if (encap_data && encap_data_m) {
1900 : : shared_rfmt = true;
1901 : : }
1902 : 0 : acts->encap_decap = mlx5_malloc(MLX5_MEM_ZERO,
1903 : : sizeof(*acts->encap_decap) + data_size,
1904 : : 0, SOCKET_ID_ANY);
1905 [ # # ]: 0 : if (!acts->encap_decap)
1906 : 0 : return rte_flow_error_set(error, ENOMEM,
1907 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1908 : : NULL, "no memory for reformat context");
1909 : 0 : hdr.sz = data_size;
1910 : 0 : hdr.data = encap_data;
1911 [ # # ]: 0 : if (shared_rfmt || mp_reformat_ix < 0) {
1912 : 0 : uint16_t reformat_ix = at->reformat_off;
1913 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][tbl_type] |
1914 : : MLX5DR_ACTION_FLAG_SHARED;
1915 : :
1916 : 0 : acts->encap_decap->action =
1917 : 0 : mlx5dr_action_create_reformat(priv->dr_ctx, refmt_type,
1918 : : 1, &hdr, 0, flags);
1919 [ # # ]: 0 : if (!acts->encap_decap->action)
1920 : 0 : return -rte_errno;
1921 : 0 : acts->rule_acts[reformat_ix].action = acts->encap_decap->action;
1922 : 0 : acts->rule_acts[reformat_ix].reformat.data = acts->encap_decap->data;
1923 : 0 : acts->rule_acts[reformat_ix].reformat.offset = 0;
1924 : 0 : acts->encap_decap->shared = true;
1925 : : } else {
1926 : : uint32_t ix;
1927 : 0 : typeof(mp_ctx->reformat[0]) *reformat_ctx = mp_ctx->reformat +
1928 : : mp_reformat_ix;
1929 : :
1930 : 0 : ix = reformat_ctx->elements_num++;
1931 : 0 : reformat_ctx->ctx[ix].reformat_hdr = hdr;
1932 : 0 : reformat_ctx->ctx[ix].rule_action = &acts->rule_acts[at->reformat_off];
1933 : 0 : reformat_ctx->ctx[ix].encap = acts->encap_decap;
1934 : 0 : acts->rule_acts[at->reformat_off].reformat.hdr_idx = ix;
1935 : 0 : acts->encap_decap_pos = at->reformat_off;
1936 : 0 : acts->encap_decap->data_size = data_size;
1937 : 0 : ret = __flow_hw_act_data_encap_append
1938 : 0 : (priv, acts, (at->actions + reformat_src)->type,
1939 : : reformat_src, at->reformat_off, data_size);
1940 : : if (ret)
1941 : 0 : return -rte_errno;
1942 : : }
1943 : : return 0;
1944 : : }
1945 : :
1946 : : static int
1947 : 0 : mlx5_tbl_translate_modify_header(struct rte_eth_dev *dev,
1948 : : const struct mlx5_flow_template_table_cfg *cfg,
1949 : : struct mlx5_hw_actions *acts,
1950 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
1951 : : struct mlx5_hw_modify_header_action *mhdr,
1952 : : struct rte_flow_error *error)
1953 : : {
1954 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
1955 : : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
1956 : : const struct rte_flow_attr *attr = &table_attr->flow_attr;
1957 : : enum mlx5dr_table_type tbl_type = get_mlx5dr_table_type(attr);
1958 : 0 : uint16_t mhdr_ix = mhdr->pos;
1959 : 0 : struct mlx5dr_action_mh_pattern pattern = {
1960 : 0 : .sz = sizeof(struct mlx5_modification_cmd) * mhdr->mhdr_cmds_num
1961 : : };
1962 : :
1963 [ # # ]: 0 : if (flow_hw_validate_compiled_modify_field(dev, cfg, mhdr, error)) {
1964 : 0 : __flow_hw_action_template_destroy(dev, acts);
1965 : 0 : return -rte_errno;
1966 : : }
1967 : 0 : acts->mhdr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*acts->mhdr),
1968 : : 0, SOCKET_ID_ANY);
1969 [ # # ]: 0 : if (!acts->mhdr)
1970 : 0 : return rte_flow_error_set(error, ENOMEM,
1971 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1972 : : NULL, "translate modify_header: no memory for modify header context");
1973 : : rte_memcpy(acts->mhdr, mhdr, sizeof(*mhdr));
1974 : 0 : pattern.data = (__be64 *)acts->mhdr->mhdr_cmds;
1975 [ # # ]: 0 : if (mhdr->shared) {
1976 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][tbl_type] |
1977 : : MLX5DR_ACTION_FLAG_SHARED;
1978 : :
1979 : 0 : acts->mhdr->action = mlx5dr_action_create_modify_header
1980 : : (priv->dr_ctx, 1, &pattern, 0,
1981 : : flags);
1982 [ # # ]: 0 : if (!acts->mhdr->action)
1983 : 0 : return rte_flow_error_set(error, rte_errno,
1984 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1985 : : NULL, "translate modify_header: failed to create DR action");
1986 : 0 : acts->rule_acts[mhdr_ix].action = acts->mhdr->action;
1987 : : } else {
1988 : : typeof(mp_ctx->mh) *mh = &mp_ctx->mh;
1989 : 0 : uint32_t idx = mh->elements_num;
1990 : 0 : struct mlx5_multi_pattern_ctx *mh_ctx = mh->ctx + mh->elements_num++;
1991 : :
1992 : 0 : mh_ctx->mh_pattern = pattern;
1993 : 0 : mh_ctx->mhdr = acts->mhdr;
1994 : 0 : mh_ctx->rule_action = &acts->rule_acts[mhdr_ix];
1995 : 0 : acts->rule_acts[mhdr_ix].modify_header.pattern_idx = idx;
1996 : : }
1997 : : return 0;
1998 : : }
1999 : :
2000 : :
2001 : : static int
2002 : 0 : mlx5_create_ipv6_ext_reformat(struct rte_eth_dev *dev,
2003 : : const struct mlx5_flow_template_table_cfg *cfg,
2004 : : struct mlx5_hw_actions *acts,
2005 : : struct rte_flow_actions_template *at,
2006 : : uint8_t *push_data, uint8_t *push_data_m,
2007 : : size_t push_size, uint16_t recom_src,
2008 : : enum mlx5dr_action_type recom_type)
2009 : : {
2010 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2011 : : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2012 : : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2013 : : enum mlx5dr_table_type type = get_mlx5dr_table_type(attr);
2014 : : struct mlx5_action_construct_data *act_data;
2015 : 0 : struct mlx5dr_action_reformat_header hdr = {0};
2016 : : uint32_t flag, bulk = 0;
2017 : :
2018 : 0 : flag = mlx5_hw_act_flag[!!attr->group][type];
2019 : 0 : acts->push_remove = mlx5_malloc(MLX5_MEM_ZERO,
2020 : : sizeof(*acts->push_remove) + push_size,
2021 : : 0, SOCKET_ID_ANY);
2022 [ # # ]: 0 : if (!acts->push_remove)
2023 : : return -ENOMEM;
2024 : :
2025 [ # # # ]: 0 : switch (recom_type) {
2026 : 0 : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
2027 [ # # ]: 0 : if (!push_data || !push_size)
2028 : 0 : goto err1;
2029 [ # # ]: 0 : if (!push_data_m) {
2030 [ # # ]: 0 : bulk = rte_log2_u32(table_attr->nb_flows);
2031 : : } else {
2032 : 0 : flag |= MLX5DR_ACTION_FLAG_SHARED;
2033 : 0 : acts->push_remove->shared = 1;
2034 : : }
2035 : 0 : acts->push_remove->data_size = push_size;
2036 : 0 : memcpy(acts->push_remove->data, push_data, push_size);
2037 : 0 : hdr.data = push_data;
2038 : 0 : hdr.sz = push_size;
2039 : 0 : break;
2040 : 0 : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
2041 : 0 : flag |= MLX5DR_ACTION_FLAG_SHARED;
2042 : 0 : acts->push_remove->shared = 1;
2043 : 0 : break;
2044 : : default:
2045 : : break;
2046 : : }
2047 : :
2048 : 0 : acts->push_remove->action =
2049 : 0 : mlx5dr_action_create_reformat_ipv6_ext(priv->dr_ctx,
2050 : : recom_type, &hdr, bulk, flag);
2051 [ # # ]: 0 : if (!acts->push_remove->action)
2052 : 0 : goto err1;
2053 : 0 : acts->rule_acts[at->recom_off].action = acts->push_remove->action;
2054 : 0 : acts->rule_acts[at->recom_off].ipv6_ext.header = acts->push_remove->data;
2055 : 0 : acts->rule_acts[at->recom_off].ipv6_ext.offset = 0;
2056 : 0 : acts->push_remove_pos = at->recom_off;
2057 [ # # ]: 0 : if (!acts->push_remove->shared) {
2058 : 0 : act_data = __flow_hw_act_data_push_append(dev, acts,
2059 : : RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH,
2060 : : recom_src, at->recom_off, push_size);
2061 : : if (!act_data)
2062 : 0 : goto err;
2063 : : }
2064 : : return 0;
2065 : : err:
2066 [ # # ]: 0 : if (acts->push_remove->action)
2067 : 0 : mlx5dr_action_destroy(acts->push_remove->action);
2068 : 0 : err1:
2069 [ # # ]: 0 : if (acts->push_remove) {
2070 : 0 : mlx5_free(acts->push_remove);
2071 : 0 : acts->push_remove = NULL;
2072 : : }
2073 : : return -EINVAL;
2074 : : }
2075 : :
2076 : : /**
2077 : : * Translate rte_flow actions to DR action.
2078 : : *
2079 : : * As the action template has already indicated the actions. Translate
2080 : : * the rte_flow actions to DR action if possbile. So in flow create
2081 : : * stage we will save cycles from handing the actions' organizing.
2082 : : * For the actions with limited information, need to add these to a
2083 : : * list.
2084 : : *
2085 : : * @param[in] dev
2086 : : * Pointer to the rte_eth_dev structure.
2087 : : * @param[in] cfg
2088 : : * Pointer to the table configuration.
2089 : : * @param[in/out] acts
2090 : : * Pointer to the template HW steering DR actions.
2091 : : * @param[in] at
2092 : : * Action template.
2093 : : * @param[out] error
2094 : : * Pointer to error structure.
2095 : : *
2096 : : * @return
2097 : : * 0 on success, a negative errno otherwise and rte_errno is set.
2098 : : */
2099 : : static int
2100 : 0 : __flow_hw_actions_translate(struct rte_eth_dev *dev,
2101 : : const struct mlx5_flow_template_table_cfg *cfg,
2102 : : struct mlx5_hw_actions *acts,
2103 : : struct rte_flow_actions_template *at,
2104 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
2105 : : struct rte_flow_error *error)
2106 : : {
2107 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2108 : 0 : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2109 : 0 : struct mlx5_hca_flex_attr *hca_attr = &priv->sh->cdev->config.hca_attr.flex;
2110 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2111 : 0 : struct rte_flow_action *actions = at->actions;
2112 : 0 : struct rte_flow_action *masks = at->masks;
2113 : : enum mlx5dr_action_type refmt_type = MLX5DR_ACTION_TYP_LAST;
2114 : : enum mlx5dr_action_type recom_type = MLX5DR_ACTION_TYP_LAST;
2115 : : const struct rte_flow_action_raw_encap *raw_encap_data;
2116 : : const struct rte_flow_action_ipv6_ext_push *ipv6_ext_data;
2117 : : const struct rte_flow_item *enc_item = NULL, *enc_item_m = NULL;
2118 : : uint16_t reformat_src = 0, recom_src = 0;
2119 : : uint8_t *encap_data = NULL, *encap_data_m = NULL;
2120 : : uint8_t *push_data = NULL, *push_data_m = NULL;
2121 : : size_t data_size = 0, push_size = 0;
2122 : : struct mlx5_hw_modify_header_action mhdr = { 0 };
2123 : : bool actions_end = false;
2124 : : uint32_t type;
2125 : : bool reformat_used = false;
2126 : : bool recom_used = false;
2127 : : unsigned int of_vlan_offset;
2128 : : uint16_t jump_pos;
2129 : : uint32_t ct_idx;
2130 : : int ret, err;
2131 [ # # ]: 0 : uint32_t target_grp = 0;
2132 : : int table_type;
2133 : :
2134 : : flow_hw_modify_field_init(&mhdr, at);
2135 [ # # ]: 0 : if (attr->transfer)
2136 : : type = MLX5DR_TABLE_TYPE_FDB;
2137 [ # # ]: 0 : else if (attr->egress)
2138 : : type = MLX5DR_TABLE_TYPE_NIC_TX;
2139 : : else
2140 : : type = MLX5DR_TABLE_TYPE_NIC_RX;
2141 [ # # ]: 0 : for (; !actions_end; actions++, masks++) {
2142 : 0 : uint64_t pos = actions - at->actions;
2143 : 0 : uint16_t src_pos = pos - at->src_off[pos];
2144 : 0 : uint16_t dr_pos = at->dr_off[pos];
2145 : :
2146 [ # # # # : 0 : switch ((int)actions->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2147 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
2148 [ # # ]: 0 : if (!attr->group) {
2149 : 0 : DRV_LOG(ERR, "Indirect action is not supported in root table.");
2150 : 0 : goto err;
2151 : : }
2152 : 0 : ret = table_template_translate_indirect_list
2153 : : (dev, actions, masks, acts, src_pos, dr_pos);
2154 [ # # ]: 0 : if (ret)
2155 : 0 : goto err;
2156 : : break;
2157 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
2158 [ # # ]: 0 : if (!attr->group) {
2159 : 0 : DRV_LOG(ERR, "Indirect action is not supported in root table.");
2160 : 0 : goto err;
2161 : : }
2162 [ # # # # ]: 0 : if (actions->conf && masks->conf) {
2163 [ # # # # : 0 : if (flow_hw_shared_action_translate
# # # ]
2164 : : (dev, actions, acts, src_pos, dr_pos))
2165 : 0 : goto err;
2166 : : } else if (__flow_hw_act_data_general_append
2167 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT,
2168 : : src_pos, dr_pos)){
2169 : 0 : goto err;
2170 : : }
2171 : : break;
2172 : : case RTE_FLOW_ACTION_TYPE_VOID:
2173 : : break;
2174 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
2175 : 0 : acts->rule_acts[dr_pos].action =
2176 : 0 : priv->hw_drop[!!attr->group];
2177 : 0 : break;
2178 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
2179 [ # # ]: 0 : if (!attr->group) {
2180 : 0 : DRV_LOG(ERR, "Port representor is not supported in root table.");
2181 : 0 : goto err;
2182 : : }
2183 : 0 : acts->rule_acts[dr_pos].action = priv->hw_def_miss;
2184 : 0 : break;
2185 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
2186 : 0 : acts->mark = true;
2187 [ # # ]: 0 : if (masks->conf &&
2188 : : ((const struct rte_flow_action_mark *)
2189 [ # # ]: 0 : masks->conf)->id)
2190 : 0 : acts->rule_acts[dr_pos].tag.value =
2191 : : mlx5_flow_mark_set
2192 : : (((const struct rte_flow_action_mark *)
2193 [ # # ]: 0 : (actions->conf))->id);
2194 : : else if (__flow_hw_act_data_general_append(priv, acts,
2195 : : actions->type,
2196 : : src_pos, dr_pos))
2197 : 0 : goto err;
2198 : 0 : acts->rule_acts[dr_pos].action =
2199 : 0 : priv->hw_tag[!!attr->group];
2200 : 0 : __atomic_fetch_add(&priv->hws_mark_refcnt, 1, __ATOMIC_RELAXED);
2201 : 0 : flow_hw_rxq_flag_set(dev, true);
2202 : 0 : break;
2203 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
2204 : 0 : acts->rule_acts[dr_pos].action =
2205 : 0 : priv->hw_push_vlan[type];
2206 [ # # # # ]: 0 : if (is_template_masked_push_vlan(masks->conf))
2207 : 0 : acts->rule_acts[dr_pos].push_vlan.vlan_hdr =
2208 : : vlan_hdr_to_be32(actions);
2209 : : else if (__flow_hw_act_data_general_append
2210 : : (priv, acts, actions->type,
2211 : : src_pos, dr_pos))
2212 : 0 : goto err;
2213 : : of_vlan_offset = is_of_vlan_pcp_present(actions) ?
2214 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
2215 : : MLX5_HW_VLAN_PUSH_VID_IDX;
2216 : 0 : actions += of_vlan_offset;
2217 : 0 : masks += of_vlan_offset;
2218 : 0 : break;
2219 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
2220 : 0 : acts->rule_acts[dr_pos].action =
2221 : 0 : priv->hw_pop_vlan[type];
2222 : 0 : break;
2223 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
2224 [ # # ]: 0 : if (masks->conf &&
2225 : : ((const struct rte_flow_action_jump *)
2226 [ # # ]: 0 : masks->conf)->group) {
2227 : 0 : uint32_t jump_group =
2228 : : ((const struct rte_flow_action_jump *)
2229 : 0 : actions->conf)->group;
2230 : 0 : acts->jump = flow_hw_jump_action_register
2231 : : (dev, cfg, jump_group, error);
2232 [ # # ]: 0 : if (!acts->jump)
2233 : 0 : goto err;
2234 : 0 : acts->rule_acts[dr_pos].action = (!!attr->group) ?
2235 [ # # ]: 0 : acts->jump->hws_action :
2236 : : acts->jump->root_action;
2237 : : } else if (__flow_hw_act_data_general_append
2238 : : (priv, acts, actions->type,
2239 : : src_pos, dr_pos)){
2240 : 0 : goto err;
2241 : : }
2242 : : break;
2243 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
2244 [ # # ]: 0 : if (masks->conf &&
2245 : : ((const struct rte_flow_action_queue *)
2246 [ # # ]: 0 : masks->conf)->index) {
2247 : 0 : acts->tir = flow_hw_tir_action_register
2248 : : (dev,
2249 : 0 : mlx5_hw_act_flag[!!attr->group][type],
2250 : : actions);
2251 [ # # ]: 0 : if (!acts->tir)
2252 : 0 : goto err;
2253 : 0 : acts->rule_acts[dr_pos].action =
2254 : 0 : acts->tir->action;
2255 : : } else if (__flow_hw_act_data_general_append
2256 : : (priv, acts, actions->type,
2257 : : src_pos, dr_pos)) {
2258 : 0 : goto err;
2259 : : }
2260 : : break;
2261 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
2262 [ # # # # ]: 0 : if (actions->conf && masks->conf) {
2263 : 0 : acts->tir = flow_hw_tir_action_register
2264 : : (dev,
2265 : 0 : mlx5_hw_act_flag[!!attr->group][type],
2266 : : actions);
2267 [ # # ]: 0 : if (!acts->tir)
2268 : 0 : goto err;
2269 : 0 : acts->rule_acts[dr_pos].action =
2270 : 0 : acts->tir->action;
2271 : : } else if (__flow_hw_act_data_general_append
2272 : : (priv, acts, actions->type,
2273 : : src_pos, dr_pos)) {
2274 : 0 : goto err;
2275 : : }
2276 : : break;
2277 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2278 : : MLX5_ASSERT(!reformat_used);
2279 : 0 : enc_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_vxlan_encap,
2280 : : actions->conf);
2281 [ # # ]: 0 : if (masks->conf)
2282 : 0 : enc_item_m = MLX5_CONST_ENCAP_ITEM(rte_flow_action_vxlan_encap,
2283 : : masks->conf);
2284 : : reformat_used = true;
2285 : : reformat_src = src_pos;
2286 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
2287 : : break;
2288 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2289 : : MLX5_ASSERT(!reformat_used);
2290 : 0 : enc_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_nvgre_encap,
2291 : : actions->conf);
2292 [ # # ]: 0 : if (masks->conf)
2293 : 0 : enc_item_m = MLX5_CONST_ENCAP_ITEM(rte_flow_action_nvgre_encap,
2294 : : masks->conf);
2295 : : reformat_used = true;
2296 : : reformat_src = src_pos;
2297 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
2298 : : break;
2299 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2300 : 0 : raw_encap_data =
2301 : : (const struct rte_flow_action_raw_encap *)
2302 : : masks->conf;
2303 [ # # ]: 0 : if (raw_encap_data)
2304 : 0 : encap_data_m = raw_encap_data->data;
2305 : 0 : raw_encap_data =
2306 : : (const struct rte_flow_action_raw_encap *)
2307 : : actions->conf;
2308 : 0 : encap_data = raw_encap_data->data;
2309 : 0 : data_size = raw_encap_data->size;
2310 [ # # ]: 0 : if (reformat_used) {
2311 : : refmt_type = data_size <
2312 : : MLX5_ENCAPSULATION_DECISION_SIZE ?
2313 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2 :
2314 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
2315 : : } else {
2316 : : reformat_used = true;
2317 : : refmt_type =
2318 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
2319 : : }
2320 : : reformat_src = src_pos;
2321 : : break;
2322 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
2323 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
2324 : : MLX5_ASSERT(!reformat_used);
2325 : : reformat_used = true;
2326 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
2327 : 0 : break;
2328 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
2329 : : reformat_used = true;
2330 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
2331 : 0 : break;
2332 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
2333 [ # # ]: 0 : if (!hca_attr->query_match_sample_info || !hca_attr->parse_graph_anchor ||
2334 [ # # ]: 0 : !priv->sh->srh_flex_parser.flex.mapnum) {
2335 : 0 : DRV_LOG(ERR, "SRv6 anchor is not supported.");
2336 : 0 : goto err;
2337 : : }
2338 : : MLX5_ASSERT(!recom_used && !recom_type);
2339 : : recom_used = true;
2340 : : recom_type = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT;
2341 : 0 : ipv6_ext_data =
2342 : : (const struct rte_flow_action_ipv6_ext_push *)masks->conf;
2343 [ # # ]: 0 : if (ipv6_ext_data)
2344 : 0 : push_data_m = ipv6_ext_data->data;
2345 : 0 : ipv6_ext_data =
2346 : : (const struct rte_flow_action_ipv6_ext_push *)actions->conf;
2347 [ # # ]: 0 : if (ipv6_ext_data) {
2348 : 0 : push_data = ipv6_ext_data->data;
2349 : 0 : push_size = ipv6_ext_data->size;
2350 : : }
2351 : : recom_src = src_pos;
2352 : : break;
2353 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE:
2354 [ # # ]: 0 : if (!hca_attr->query_match_sample_info || !hca_attr->parse_graph_anchor ||
2355 [ # # ]: 0 : !priv->sh->srh_flex_parser.flex.mapnum) {
2356 : 0 : DRV_LOG(ERR, "SRv6 anchor is not supported.");
2357 : 0 : goto err;
2358 : : }
2359 : : recom_used = true;
2360 : : recom_type = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT;
2361 : : break;
2362 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
2363 : 0 : flow_hw_translate_group(dev, cfg, attr->group,
2364 : : &target_grp, error);
2365 [ # # ]: 0 : if (target_grp == 0) {
2366 : 0 : __flow_hw_action_template_destroy(dev, acts);
2367 : 0 : return rte_flow_error_set(error, ENOTSUP,
2368 : : RTE_FLOW_ERROR_TYPE_ACTION,
2369 : : NULL,
2370 : : "Send to kernel action on root table is not supported in HW steering mode");
2371 : : }
2372 [ # # ]: 0 : table_type = attr->ingress ? MLX5DR_TABLE_TYPE_NIC_RX :
2373 [ # # ]: 0 : ((attr->egress) ? MLX5DR_TABLE_TYPE_NIC_TX :
2374 : : MLX5DR_TABLE_TYPE_FDB);
2375 : 0 : acts->rule_acts[dr_pos].action = priv->hw_send_to_kernel[table_type];
2376 : 0 : break;
2377 [ # # ]: 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
2378 : : err = flow_hw_modify_field_compile(dev, attr, actions,
2379 : : masks, acts, &mhdr,
2380 : : src_pos, error);
2381 [ # # ]: 0 : if (err)
2382 : 0 : goto err;
2383 : : break;
2384 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
2385 [ # # ]: 0 : if (flow_hw_represented_port_compile
2386 : : (dev, attr, actions,
2387 : : masks, acts, src_pos, dr_pos, error))
2388 : 0 : goto err;
2389 : : break;
2390 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
2391 : : /*
2392 : : * METER action is compiled to 2 DR actions - ASO_METER and FT.
2393 : : * Calculated DR offset is stored only for ASO_METER and FT
2394 : : * is assumed to be the next action.
2395 : : */
2396 : 0 : jump_pos = dr_pos + 1;
2397 [ # # # # ]: 0 : if (actions->conf && masks->conf &&
2398 : : ((const struct rte_flow_action_meter *)
2399 [ # # ]: 0 : masks->conf)->mtr_id) {
2400 : 0 : err = flow_hw_meter_compile(dev, cfg,
2401 : : dr_pos, jump_pos, actions, acts, error);
2402 : : if (err)
2403 : 0 : goto err;
2404 : : } else if (__flow_hw_act_data_general_append(priv, acts,
2405 : : actions->type,
2406 : : src_pos,
2407 : : dr_pos))
2408 : 0 : goto err;
2409 : : break;
2410 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
2411 : 0 : flow_hw_translate_group(dev, cfg, attr->group,
2412 : : &target_grp, error);
2413 [ # # ]: 0 : if (target_grp == 0) {
2414 : 0 : __flow_hw_action_template_destroy(dev, acts);
2415 : 0 : return rte_flow_error_set(error, ENOTSUP,
2416 : : RTE_FLOW_ERROR_TYPE_ACTION,
2417 : : NULL,
2418 : : "Age action on root table is not supported in HW steering mode");
2419 : : }
2420 : 0 : if (__flow_hw_act_data_general_append(priv, acts,
2421 : : actions->type,
2422 : : src_pos,
2423 : : dr_pos))
2424 : 0 : goto err;
2425 : : break;
2426 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
2427 : 0 : flow_hw_translate_group(dev, cfg, attr->group,
2428 : : &target_grp, error);
2429 [ # # ]: 0 : if (target_grp == 0) {
2430 : 0 : __flow_hw_action_template_destroy(dev, acts);
2431 : 0 : return rte_flow_error_set(error, ENOTSUP,
2432 : : RTE_FLOW_ERROR_TYPE_ACTION,
2433 : : NULL,
2434 : : "Counter action on root table is not supported in HW steering mode");
2435 : : }
2436 [ # # ]: 0 : if ((at->action_flags & MLX5_FLOW_ACTION_AGE) ||
2437 : : (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE))
2438 : : /*
2439 : : * When both COUNT and AGE are requested, it is
2440 : : * saved as AGE action which creates also the
2441 : : * counter.
2442 : : */
2443 : : break;
2444 [ # # ]: 0 : if (masks->conf &&
2445 : : ((const struct rte_flow_action_count *)
2446 [ # # ]: 0 : masks->conf)->id) {
2447 [ # # ]: 0 : err = flow_hw_cnt_compile(dev, dr_pos, acts);
2448 : : if (err)
2449 : 0 : goto err;
2450 : 0 : } else if (__flow_hw_act_data_general_append
2451 : : (priv, acts, actions->type,
2452 : : src_pos, dr_pos)) {
2453 : 0 : goto err;
2454 : : }
2455 : : break;
2456 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
2457 [ # # ]: 0 : if (masks->conf) {
2458 : 0 : ct_idx = MLX5_ACTION_CTX_CT_GET_IDX
2459 : : ((uint32_t)(uintptr_t)actions->conf);
2460 : : if (flow_hw_ct_compile(dev, MLX5_HW_INV_QUEUE, ct_idx,
2461 : 0 : &acts->rule_acts[dr_pos]))
2462 : 0 : goto err;
2463 : : } else if (__flow_hw_act_data_general_append
2464 : : (priv, acts, actions->type,
2465 : : src_pos, dr_pos)) {
2466 : 0 : goto err;
2467 : : }
2468 : : break;
2469 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
2470 [ # # # # ]: 0 : if (actions->conf && masks->conf &&
2471 : : ((const struct rte_flow_action_meter_mark *)
2472 [ # # ]: 0 : masks->conf)->profile) {
2473 : : err = flow_hw_meter_mark_compile(dev,
2474 : : dr_pos, actions,
2475 [ # # ]: 0 : acts->rule_acts,
2476 : : &acts->mtr_id,
2477 : : MLX5_HW_INV_QUEUE);
2478 : : if (err)
2479 : 0 : goto err;
2480 : : } else if (__flow_hw_act_data_general_append(priv, acts,
2481 : : actions->type,
2482 : : src_pos,
2483 : : dr_pos))
2484 : 0 : goto err;
2485 : : break;
2486 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
2487 : : /* Internal, can be skipped. */
2488 [ # # ]: 0 : if (!!attr->group) {
2489 : 0 : DRV_LOG(ERR, "DEFAULT MISS action is only"
2490 : : " supported in root table.");
2491 : 0 : goto err;
2492 : : }
2493 : 0 : acts->rule_acts[dr_pos].action = priv->hw_def_miss;
2494 : 0 : break;
2495 : 0 : case RTE_FLOW_ACTION_TYPE_END:
2496 : : actions_end = true;
2497 : 0 : break;
2498 : : default:
2499 : : break;
2500 : : }
2501 : : }
2502 [ # # ]: 0 : if (mhdr.pos != UINT16_MAX) {
2503 : 0 : ret = mlx5_tbl_translate_modify_header(dev, cfg, acts, mp_ctx,
2504 : : &mhdr, error);
2505 [ # # ]: 0 : if (ret)
2506 : 0 : goto err;
2507 : : }
2508 [ # # ]: 0 : if (reformat_used) {
2509 : 0 : ret = mlx5_tbl_translate_reformat(priv, table_attr, acts, at,
2510 : : enc_item, enc_item_m,
2511 : : encap_data, encap_data_m,
2512 : : mp_ctx, data_size,
2513 : : reformat_src,
2514 : : refmt_type, error);
2515 [ # # ]: 0 : if (ret)
2516 : 0 : goto err;
2517 : : }
2518 [ # # ]: 0 : if (recom_used) {
2519 : : MLX5_ASSERT(at->recom_off != UINT16_MAX);
2520 : 0 : ret = mlx5_create_ipv6_ext_reformat(dev, cfg, acts, at, push_data,
2521 : : push_data_m, push_size, recom_src,
2522 : : recom_type);
2523 [ # # ]: 0 : if (ret)
2524 : 0 : goto err;
2525 : : }
2526 : : return 0;
2527 : 0 : err:
2528 : 0 : err = rte_errno;
2529 : 0 : __flow_hw_action_template_destroy(dev, acts);
2530 : 0 : return rte_flow_error_set(error, err,
2531 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2532 : : "fail to create rte table");
2533 : : }
2534 : :
2535 : : /**
2536 : : * Translate rte_flow actions to DR action.
2537 : : *
2538 : : * @param[in] dev
2539 : : * Pointer to the rte_eth_dev structure.
2540 : : * @param[in] tbl
2541 : : * Pointer to the flow template table.
2542 : : * @param[out] error
2543 : : * Pointer to error structure.
2544 : : *
2545 : : * @return
2546 : : * 0 on success, negative value otherwise and rte_errno is set.
2547 : : */
2548 : : static int
2549 : 0 : flow_hw_actions_translate(struct rte_eth_dev *dev,
2550 : : struct rte_flow_template_table *tbl,
2551 : : struct rte_flow_error *error)
2552 : : {
2553 : : int ret;
2554 : : uint32_t i;
2555 : 0 : struct mlx5_tbl_multi_pattern_ctx mpat = MLX5_EMPTY_MULTI_PATTERN_CTX;
2556 : :
2557 [ # # ]: 0 : for (i = 0; i < tbl->nb_action_templates; i++) {
2558 [ # # ]: 0 : if (__flow_hw_actions_translate(dev, &tbl->cfg,
2559 : : &tbl->ats[i].acts,
2560 : : tbl->ats[i].action_template,
2561 : : &mpat, error))
2562 : 0 : goto err;
2563 : : }
2564 : 0 : ret = mlx5_tbl_multi_pattern_process(dev, tbl, &mpat, error);
2565 [ # # ]: 0 : if (ret)
2566 : 0 : goto err;
2567 : : return 0;
2568 : : err:
2569 [ # # ]: 0 : while (i--)
2570 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
2571 : : return -1;
2572 : : }
2573 : :
2574 : : /**
2575 : : * Get shared indirect action.
2576 : : *
2577 : : * @param[in] dev
2578 : : * Pointer to the rte_eth_dev data structure.
2579 : : * @param[in] act_data
2580 : : * Pointer to the recorded action construct data.
2581 : : * @param[in] item_flags
2582 : : * The matcher itme_flags used for RSS lookup.
2583 : : * @param[in] rule_act
2584 : : * Pointer to the shared action's destination rule DR action.
2585 : : *
2586 : : * @return
2587 : : * 0 on success, negative value otherwise and rte_errno is set.
2588 : : */
2589 : : static __rte_always_inline int
2590 : : flow_hw_shared_action_get(struct rte_eth_dev *dev,
2591 : : struct mlx5_action_construct_data *act_data,
2592 : : const uint64_t item_flags,
2593 : : struct mlx5dr_rule_action *rule_act)
2594 : : {
2595 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2596 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
2597 : 0 : uint64_t hash_fields = 0;
2598 : : uint32_t hrxq_idx = 0;
2599 : : struct mlx5_hrxq *hrxq = NULL;
2600 : : int act_type = act_data->type;
2601 : :
2602 : : switch (act_type) {
2603 : : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
2604 : 0 : rss_desc.level = act_data->shared_rss.level;
2605 : 0 : rss_desc.types = act_data->shared_rss.types;
2606 : 0 : rss_desc.symmetric_hash_function = act_data->shared_rss.symmetric_hash_function;
2607 : 0 : flow_dv_hashfields_set(item_flags, &rss_desc, &hash_fields);
2608 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup
2609 : : (dev, act_data->shared_rss.idx, hash_fields);
2610 [ # # # # : 0 : if (hrxq_idx)
# # # # #
# # # ]
2611 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
2612 : : hrxq_idx);
2613 [ # # # # : 0 : if (hrxq) {
# # # # #
# # # ]
2614 : 0 : rule_act->action = hrxq->action;
2615 : : return 0;
2616 : : }
2617 : : break;
2618 : : default:
2619 : : DRV_LOG(WARNING, "Unsupported shared action type:%d",
2620 : : act_data->type);
2621 : : break;
2622 : : }
2623 : : return -1;
2624 : : }
2625 : :
2626 : : static void
2627 : 0 : flow_hw_construct_quota(struct mlx5_priv *priv,
2628 : : struct mlx5dr_rule_action *rule_act, uint32_t qid)
2629 : : {
2630 : 0 : rule_act->action = priv->quota_ctx.dr_action;
2631 : 0 : rule_act->aso_meter.offset = qid - 1;
2632 : 0 : rule_act->aso_meter.init_color =
2633 : : MLX5DR_ACTION_ASO_METER_COLOR_GREEN;
2634 : 0 : }
2635 : :
2636 : : /**
2637 : : * Construct shared indirect action.
2638 : : *
2639 : : * @param[in] dev
2640 : : * Pointer to the rte_eth_dev data structure.
2641 : : * @param[in] queue
2642 : : * The flow creation queue index.
2643 : : * @param[in] action
2644 : : * Pointer to the shared indirect rte_flow action.
2645 : : * @param[in] table
2646 : : * Pointer to the flow table.
2647 : : * @param[in] it_idx
2648 : : * Item template index the action template refer to.
2649 : : * @param[in] action_flags
2650 : : * Actions bit-map detected in this template.
2651 : : * @param[in, out] flow
2652 : : * Pointer to the flow containing the counter.
2653 : : * @param[in] rule_act
2654 : : * Pointer to the shared action's destination rule DR action.
2655 : : *
2656 : : * @return
2657 : : * 0 on success, negative value otherwise and rte_errno is set.
2658 : : */
2659 : : static __rte_always_inline int
2660 : : flow_hw_shared_action_construct(struct rte_eth_dev *dev, uint32_t queue,
2661 : : const struct rte_flow_action *action,
2662 : : struct rte_flow_template_table *table,
2663 : : const uint8_t it_idx, uint64_t action_flags,
2664 : : struct rte_flow_hw *flow,
2665 : : struct mlx5dr_rule_action *rule_act)
2666 : : {
2667 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2668 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
2669 : : struct mlx5_action_construct_data act_data;
2670 : : struct mlx5_shared_action_rss *shared_rss;
2671 : : struct mlx5_aso_mtr *aso_mtr;
2672 : : struct mlx5_age_info *age_info;
2673 : : struct mlx5_hws_age_param *param;
2674 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)action->conf;
2675 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
2676 : 0 : uint32_t idx = act_idx &
2677 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
2678 : : uint64_t item_flags;
2679 : : cnt_id_t age_cnt;
2680 : :
2681 : : memset(&act_data, 0, sizeof(act_data));
2682 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # ]
2683 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
2684 : 0 : act_data.type = MLX5_RTE_FLOW_ACTION_TYPE_RSS;
2685 : 0 : shared_rss = mlx5_ipool_get
2686 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
2687 [ # # # # : 0 : if (!shared_rss)
# # ]
2688 : : return -1;
2689 : 0 : act_data.shared_rss.idx = idx;
2690 : 0 : act_data.shared_rss.level = shared_rss->origin.level;
2691 : 0 : act_data.shared_rss.types = !shared_rss->origin.types ?
2692 [ # # # # : 0 : RTE_ETH_RSS_IP :
# # ]
2693 : : shared_rss->origin.types;
2694 : 0 : act_data.shared_rss.symmetric_hash_function =
2695 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
2696 : :
2697 : 0 : item_flags = table->its[it_idx]->item_flags;
2698 : : if (flow_hw_shared_action_get
2699 : : (dev, &act_data, item_flags, rule_act))
2700 : : return -1;
2701 : : break;
2702 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
2703 : 0 : if (mlx5_hws_cnt_pool_get_action_offset(priv->hws_cpool,
2704 : : act_idx,
2705 : : &rule_act->action,
2706 : : &rule_act->counter.offset))
2707 : : return -1;
2708 : 0 : flow->cnt_id = act_idx;
2709 : : break;
2710 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
2711 : : /*
2712 : : * Save the index with the indirect type, to recognize
2713 : : * it in flow destroy.
2714 : : */
2715 : 0 : flow->age_idx = act_idx;
2716 [ # # # # : 0 : if (action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT)
# # ]
2717 : : /*
2718 : : * The mutual update for idirect AGE & COUNT will be
2719 : : * performed later after we have ID for both of them.
2720 : : */
2721 : : break;
2722 : 0 : age_info = GET_PORT_AGE_INFO(priv);
2723 : 0 : param = mlx5_ipool_get(age_info->ages_ipool, idx);
2724 [ # # # # : 0 : if (param == NULL)
# # ]
2725 : : return -1;
2726 [ # # # # : 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
# # ]
2727 [ # # # # : 0 : if (mlx5_hws_cnt_pool_get(priv->hws_cpool,
# # # # #
# # # ]
2728 : : ¶m->queue_id, &age_cnt,
2729 : : idx) < 0)
2730 : : return -1;
2731 : 0 : flow->cnt_id = age_cnt;
2732 : 0 : param->nb_cnts++;
2733 : : } else {
2734 : : /*
2735 : : * Get the counter of this indirect AGE or create one
2736 : : * if doesn't exist.
2737 : : */
2738 : : age_cnt = mlx5_hws_age_cnt_get(priv, param, idx);
2739 [ # # # # : 0 : if (age_cnt == 0)
# # ]
2740 : : return -1;
2741 : : }
2742 : 0 : if (mlx5_hws_cnt_pool_get_action_offset(priv->hws_cpool,
2743 : : age_cnt, &rule_act->action,
2744 : : &rule_act->counter.offset))
2745 : : return -1;
2746 : : break;
2747 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
2748 : : if (flow_hw_ct_compile(dev, queue, idx, rule_act))
2749 : : return -1;
2750 : : break;
2751 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
2752 : : /* Find ASO object. */
2753 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
2754 [ # # # # : 0 : if (!aso_mtr)
# # ]
2755 : : return -1;
2756 : 0 : rule_act->action = pool->action;
2757 : 0 : rule_act->aso_meter.offset = aso_mtr->offset;
2758 : : break;
2759 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
2760 : 0 : flow_hw_construct_quota(priv, rule_act, idx);
2761 : : break;
2762 : 0 : default:
2763 : 0 : DRV_LOG(WARNING, "Unsupported shared action type:%d", type);
2764 : : break;
2765 : : }
2766 : : return 0;
2767 : : }
2768 : :
2769 : : static __rte_always_inline int
2770 : : flow_hw_mhdr_cmd_is_nop(const struct mlx5_modification_cmd *cmd)
2771 : : {
2772 : : struct mlx5_modification_cmd cmd_he = {
2773 : 0 : .data0 = rte_be_to_cpu_32(cmd->data0),
2774 : : .data1 = 0,
2775 : : };
2776 : :
2777 : 0 : return cmd_he.action_type == MLX5_MODIFICATION_TYPE_NOP;
2778 : : }
2779 : :
2780 : : /**
2781 : : * Construct flow action array.
2782 : : *
2783 : : * For action template contains dynamic actions, these actions need to
2784 : : * be updated according to the rte_flow action during flow creation.
2785 : : *
2786 : : * @param[in] dev
2787 : : * Pointer to the rte_eth_dev structure.
2788 : : * @param[in] job
2789 : : * Pointer to job descriptor.
2790 : : * @param[in] hw_acts
2791 : : * Pointer to translated actions from template.
2792 : : * @param[in] it_idx
2793 : : * Item template index the action template refer to.
2794 : : * @param[in] actions
2795 : : * Array of rte_flow action need to be checked.
2796 : : * @param[in] rule_acts
2797 : : * Array of DR rule actions to be used during flow creation..
2798 : : * @param[in] acts_num
2799 : : * Pointer to the real acts_num flow has.
2800 : : *
2801 : : * @return
2802 : : * 0 on success, negative value otherwise and rte_errno is set.
2803 : : */
2804 : : static __rte_always_inline int
2805 : : flow_hw_modify_field_construct(struct mlx5_hw_q_job *job,
2806 : : struct mlx5_action_construct_data *act_data,
2807 : : const struct mlx5_hw_actions *hw_acts,
2808 : : const struct rte_flow_action *action)
2809 : : {
2810 : 0 : const struct rte_flow_action_modify_field *mhdr_action = action->conf;
2811 : 0 : uint8_t values[16] = { 0 };
2812 : : unaligned_uint32_t *value_p;
2813 : : uint32_t i;
2814 : : struct field_modify_info *field;
2815 : :
2816 [ # # # # : 0 : if (!hw_acts->mhdr)
# # ]
2817 : : return -1;
2818 [ # # # # : 0 : if (hw_acts->mhdr->shared || act_data->modify_header.shared)
# # # # #
# # # # #
# # # # #
# # # #
# ]
2819 : : return 0;
2820 : : MLX5_ASSERT(mhdr_action->operation == RTE_FLOW_MODIFY_SET ||
2821 : : mhdr_action->operation == RTE_FLOW_MODIFY_ADD);
2822 [ # # # # : 0 : if (mhdr_action->src.field != RTE_FLOW_FIELD_VALUE &&
# # ]
2823 : : mhdr_action->src.field != RTE_FLOW_FIELD_POINTER)
2824 : : return 0;
2825 [ # # # # : 0 : if (mhdr_action->src.field == RTE_FLOW_FIELD_VALUE)
# # ]
2826 [ # # # # : 0 : rte_memcpy(values, &mhdr_action->src.value, sizeof(values));
# # ]
2827 : : else
2828 [ # # # # : 0 : rte_memcpy(values, mhdr_action->src.pvalue, sizeof(values));
# # ]
2829 [ # # # # : 0 : if (mhdr_action->dst.field == RTE_FLOW_FIELD_META ||
# # ]
2830 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_TAG ||
# # ]
2831 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_METER_COLOR ||
# # ]
2832 : : mhdr_action->dst.field == (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
2833 : 0 : uint8_t tag_index = flow_tag_index_get(&mhdr_action->dst);
2834 : :
2835 : : value_p = (unaligned_uint32_t *)values;
2836 [ # # # # : 0 : if (mhdr_action->dst.field == RTE_FLOW_FIELD_TAG &&
# # # # #
# # # ]
2837 : : tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
2838 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(*value_p << 16);
# # ]
2839 : : else
2840 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(*value_p);
# # ]
2841 [ # # # # : 0 : } else if (mhdr_action->dst.field == RTE_FLOW_FIELD_GTP_PSC_QFI ||
# # ]
2842 : : mhdr_action->dst.field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE) {
2843 : : uint32_t tmp;
2844 : :
2845 : : /*
2846 : : * Both QFI and Geneve option type are passed as an uint8_t integer,
2847 : : * but it is accessed through a 2nd least significant byte of a 32-bit
2848 : : * field in modify header command.
2849 : : */
2850 : 0 : tmp = values[0];
2851 : : value_p = (unaligned_uint32_t *)values;
2852 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(tmp << 8);
# # ]
2853 : : }
2854 : 0 : i = act_data->modify_header.mhdr_cmds_off;
2855 : 0 : field = act_data->modify_header.field;
2856 : : do {
2857 : : uint32_t off_b;
2858 : : uint32_t mask;
2859 : : uint32_t data;
2860 : : const uint8_t *mask_src;
2861 : :
2862 [ # # # # : 0 : if (i >= act_data->modify_header.mhdr_cmds_end)
# # # # #
# # # ]
2863 : : return -1;
2864 [ # # # # : 0 : if (flow_hw_mhdr_cmd_is_nop(&job->mhdr_cmd[i])) {
# # # # #
# # # # #
# # # # #
# # # #
# ]
2865 : 0 : ++i;
2866 : 0 : continue;
2867 : : }
2868 : 0 : mask_src = (const uint8_t *)act_data->modify_header.mask;
2869 : 0 : mask = flow_dv_fetch_field(mask_src + field->offset, field->size);
2870 [ # # # # : 0 : if (!mask) {
# # # # #
# # # ]
2871 : 0 : ++field;
2872 : 0 : continue;
2873 : : }
2874 : 0 : off_b = rte_bsf32(mask);
2875 : 0 : data = flow_dv_fetch_field(values + field->offset, field->size);
2876 : : /*
2877 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
2878 : : * bits left. Shift the data left for IPv6 DSCP
2879 : : */
2880 [ # # # # : 0 : if (field->id == MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS &&
# # # # #
# # # ]
2881 [ # # # # : 0 : !(mask & MLX5_IPV6_HDR_ECN_MASK))
# # # # #
# # # ]
2882 : 0 : data <<= MLX5_IPV6_HDR_DSCP_SHIFT;
2883 : 0 : data = (data & mask) >> off_b;
2884 [ # # # # : 0 : job->mhdr_cmd[i++].data1 = rte_cpu_to_be_32(data);
# # # # #
# # # ]
2885 : 0 : ++field;
2886 [ # # # # : 0 : } while (field->size);
# # # # #
# # # ]
2887 : : return 0;
2888 : : }
2889 : :
2890 : : /**
2891 : : * Construct flow action array.
2892 : : *
2893 : : * For action template contains dynamic actions, these actions need to
2894 : : * be updated according to the rte_flow action during flow creation.
2895 : : *
2896 : : * @param[in] dev
2897 : : * Pointer to the rte_eth_dev structure.
2898 : : * @param[in] job
2899 : : * Pointer to job descriptor.
2900 : : * @param[in] hw_acts
2901 : : * Pointer to translated actions from template.
2902 : : * @param[in] it_idx
2903 : : * Item template index the action template refer to.
2904 : : * @param[in] actions
2905 : : * Array of rte_flow action need to be checked.
2906 : : * @param[in] rule_acts
2907 : : * Array of DR rule actions to be used during flow creation..
2908 : : * @param[in] acts_num
2909 : : * Pointer to the real acts_num flow has.
2910 : : *
2911 : : * @return
2912 : : * 0 on success, negative value otherwise and rte_errno is set.
2913 : : */
2914 : : static __rte_always_inline int
2915 : : flow_hw_actions_construct(struct rte_eth_dev *dev,
2916 : : struct mlx5_hw_q_job *job,
2917 : : const struct mlx5_hw_action_template *hw_at,
2918 : : const uint8_t it_idx,
2919 : : const struct rte_flow_action actions[],
2920 : : struct mlx5dr_rule_action *rule_acts,
2921 : : uint32_t queue,
2922 : : struct rte_flow_error *error)
2923 : : {
2924 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2925 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
2926 : : struct rte_flow_template_table *table = job->flow->table;
2927 : : struct mlx5_action_construct_data *act_data;
2928 : 0 : const struct rte_flow_actions_template *at = hw_at->action_template;
2929 : : const struct mlx5_hw_actions *hw_acts = &hw_at->acts;
2930 : : const struct rte_flow_action *action;
2931 : : const struct rte_flow_action_raw_encap *raw_encap_data;
2932 : : const struct rte_flow_action_ipv6_ext_push *ipv6_push;
2933 : : const struct rte_flow_item *enc_item = NULL;
2934 : : const struct rte_flow_action_ethdev *port_action = NULL;
2935 : : const struct rte_flow_action_meter *meter = NULL;
2936 : : const struct rte_flow_action_age *age = NULL;
2937 : 0 : uint8_t *buf = job->encap_data;
2938 : 0 : uint8_t *push_buf = job->push_data;
2939 : 0 : struct rte_flow_attr attr = {
2940 : : .ingress = 1,
2941 : : };
2942 : : uint32_t ft_flag;
2943 : 0 : size_t encap_len = 0;
2944 : : int ret;
2945 : : uint32_t age_idx = 0;
2946 : : struct mlx5_aso_mtr *aso_mtr;
2947 : :
2948 : 0 : rte_memcpy(rule_acts, hw_acts->rule_acts, sizeof(*rule_acts) * at->dr_actions_num);
2949 : 0 : attr.group = table->grp->group_id;
2950 : 0 : ft_flag = mlx5_hw_act_flag[!!table->grp->group_id][table->type];
2951 [ # # # # : 0 : if (table->type == MLX5DR_TABLE_TYPE_FDB) {
# # ]
2952 : 0 : attr.transfer = 1;
2953 : : attr.ingress = 1;
2954 [ # # # # : 0 : } else if (table->type == MLX5DR_TABLE_TYPE_NIC_TX) {
# # ]
2955 : 0 : attr.egress = 1;
2956 : 0 : attr.ingress = 0;
2957 : : } else {
2958 : : attr.ingress = 1;
2959 : : }
2960 [ # # # # : 0 : if (hw_acts->mhdr && hw_acts->mhdr->mhdr_cmds_num > 0) {
# # # # #
# # # ]
2961 : 0 : uint16_t pos = hw_acts->mhdr->pos;
2962 : :
2963 [ # # # # : 0 : if (!hw_acts->mhdr->shared) {
# # ]
2964 : 0 : rule_acts[pos].modify_header.offset =
2965 : 0 : job->flow->res_idx - 1;
2966 : 0 : rule_acts[pos].modify_header.data =
2967 : 0 : (uint8_t *)job->mhdr_cmd;
2968 : 0 : rte_memcpy(job->mhdr_cmd, hw_acts->mhdr->mhdr_cmds,
2969 [ # # # # : 0 : sizeof(*job->mhdr_cmd) * hw_acts->mhdr->mhdr_cmds_num);
# # ]
2970 : : }
2971 : : }
2972 [ # # # # : 0 : LIST_FOREACH(act_data, &hw_acts->act_list, next) {
# # ]
2973 : : uint32_t jump_group;
2974 : : uint32_t tag;
2975 : : uint64_t item_flags;
2976 : : struct mlx5_hw_jump_action *jump;
2977 : : struct mlx5_hrxq *hrxq;
2978 : : uint32_t ct_idx;
2979 : : cnt_id_t cnt_id;
2980 : : uint32_t *cnt_queue;
2981 : : uint32_t mtr_id;
2982 : :
2983 : 0 : action = &actions[act_data->action_src];
2984 : : /*
2985 : : * action template construction replaces
2986 : : * OF_SET_VLAN_VID with MODIFY_FIELD
2987 : : */
2988 : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
2989 : : MLX5_ASSERT(act_data->type ==
2990 : : RTE_FLOW_ACTION_TYPE_MODIFY_FIELD);
2991 : : else
2992 : : MLX5_ASSERT(action->type ==
2993 : : RTE_FLOW_ACTION_TYPE_INDIRECT ||
2994 : : (int)action->type == act_data->type);
2995 [ # # # # : 0 : switch ((int)act_data->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2996 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
2997 : 0 : act_data->indirect_list_cb(dev, act_data, actions,
2998 : 0 : &rule_acts[act_data->action_dst]);
2999 : 0 : break;
3000 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
3001 : 0 : if (flow_hw_shared_action_construct
3002 : : (dev, queue, action, table, it_idx,
3003 : 0 : at->action_flags, job->flow,
3004 [ # # # # : 0 : &rule_acts[act_data->action_dst]))
# # # # #
# # # # #
# # # # #
# # ]
3005 : : return -1;
3006 : : break;
3007 : : case RTE_FLOW_ACTION_TYPE_VOID:
3008 : : break;
3009 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
3010 : 0 : tag = mlx5_flow_mark_set
3011 : : (((const struct rte_flow_action_mark *)
3012 : 0 : (action->conf))->id);
3013 : 0 : rule_acts[act_data->action_dst].tag.value = tag;
3014 : 0 : break;
3015 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3016 : 0 : rule_acts[act_data->action_dst].push_vlan.vlan_hdr =
3017 : 0 : vlan_hdr_to_be32(action);
3018 : 0 : break;
3019 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
3020 : 0 : jump_group = ((const struct rte_flow_action_jump *)
3021 : 0 : action->conf)->group;
3022 : 0 : jump = flow_hw_jump_action_register
3023 : 0 : (dev, &table->cfg, jump_group, NULL);
3024 [ # # # # : 0 : if (!jump)
# # ]
3025 : : return -1;
3026 : 0 : rule_acts[act_data->action_dst].action =
3027 [ # # # # : 0 : (!!attr.group) ? jump->hws_action : jump->root_action;
# # ]
3028 : 0 : job->flow->jump = jump;
3029 : 0 : job->flow->fate_type = MLX5_FLOW_FATE_JUMP;
3030 : 0 : break;
3031 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
3032 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
3033 : 0 : hrxq = flow_hw_tir_action_register(dev,
3034 : : ft_flag,
3035 : : action);
3036 [ # # # # : 0 : if (!hrxq)
# # ]
3037 : : return -1;
3038 : 0 : rule_acts[act_data->action_dst].action = hrxq->action;
3039 : 0 : job->flow->hrxq = hrxq;
3040 : 0 : job->flow->fate_type = MLX5_FLOW_FATE_QUEUE;
3041 : 0 : break;
3042 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
3043 : 0 : item_flags = table->its[it_idx]->item_flags;
3044 : 0 : if (flow_hw_shared_action_get
3045 : : (dev, act_data, item_flags,
3046 : 0 : &rule_acts[act_data->action_dst]))
3047 : : return -1;
3048 : : break;
3049 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3050 : 0 : enc_item = ((const struct rte_flow_action_vxlan_encap *)
3051 : 0 : action->conf)->definition;
3052 [ # # # # : 0 : if (flow_dv_convert_encap_data(enc_item, buf, &encap_len, NULL))
# # ]
3053 : : return -1;
3054 : : break;
3055 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3056 : 0 : enc_item = ((const struct rte_flow_action_nvgre_encap *)
3057 : 0 : action->conf)->definition;
3058 [ # # # # : 0 : if (flow_dv_convert_encap_data(enc_item, buf, &encap_len, NULL))
# # ]
3059 : : return -1;
3060 : : break;
3061 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3062 : 0 : raw_encap_data =
3063 : : (const struct rte_flow_action_raw_encap *)
3064 : : action->conf;
3065 [ # # # # : 0 : rte_memcpy((void *)buf, raw_encap_data->data, act_data->encap.len);
# # ]
3066 : : MLX5_ASSERT(raw_encap_data->size ==
3067 : : act_data->encap.len);
3068 : : break;
3069 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
3070 : 0 : ipv6_push =
3071 : : (const struct rte_flow_action_ipv6_ext_push *)action->conf;
3072 : 0 : rte_memcpy((void *)push_buf, ipv6_push->data,
3073 [ # # # # : 0 : act_data->ipv6_ext.len);
# # ]
3074 : : MLX5_ASSERT(ipv6_push->size == act_data->ipv6_ext.len);
3075 : : break;
3076 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3077 [ # # # # : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
# # ]
3078 : : ret = flow_hw_set_vlan_vid_construct(dev, job,
3079 : : act_data,
3080 : : hw_acts,
3081 : : action);
3082 : : else
3083 : : ret = flow_hw_modify_field_construct(job,
3084 : : act_data,
3085 : : hw_acts,
3086 : : action);
3087 [ # # # # : 0 : if (ret)
# # ]
3088 : : return -1;
3089 : : break;
3090 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3091 : 0 : port_action = action->conf;
3092 [ # # # # : 0 : if (!priv->hw_vport[port_action->port_id])
# # ]
3093 : : return -1;
3094 : 0 : rule_acts[act_data->action_dst].action =
3095 : : priv->hw_vport[port_action->port_id];
3096 : 0 : break;
3097 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
3098 : 0 : flow_hw_construct_quota(priv,
3099 : 0 : rule_acts + act_data->action_dst,
3100 : : act_data->shared_meter.id);
3101 : 0 : break;
3102 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
3103 : 0 : meter = action->conf;
3104 : 0 : mtr_id = meter->mtr_id;
3105 : 0 : aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_id);
3106 : 0 : rule_acts[act_data->action_dst].action =
3107 : 0 : priv->mtr_bulk.action;
3108 : 0 : rule_acts[act_data->action_dst].aso_meter.offset =
3109 : 0 : aso_mtr->offset;
3110 : 0 : jump = flow_hw_jump_action_register
3111 : 0 : (dev, &table->cfg, aso_mtr->fm.group, NULL);
3112 [ # # # # : 0 : if (!jump)
# # ]
3113 : : return -1;
3114 : : MLX5_ASSERT
3115 : : (!rule_acts[act_data->action_dst + 1].action);
3116 : 0 : rule_acts[act_data->action_dst + 1].action =
3117 [ # # # # : 0 : (!!attr.group) ? jump->hws_action :
# # ]
3118 : : jump->root_action;
3119 : 0 : job->flow->jump = jump;
3120 : 0 : job->flow->fate_type = MLX5_FLOW_FATE_JUMP;
3121 [ # # # # : 0 : if (mlx5_aso_mtr_wait(priv->sh, MLX5_HW_INV_QUEUE, aso_mtr))
# # ]
3122 : : return -1;
3123 : : break;
3124 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
3125 : 0 : age = action->conf;
3126 : : /*
3127 : : * First, create the AGE parameter, then create its
3128 : : * counter later:
3129 : : * Regular counter - in next case.
3130 : : * Indirect counter - update it after the loop.
3131 : : */
3132 : 0 : age_idx = mlx5_hws_age_action_create(priv, queue, 0,
3133 : : age,
3134 : 0 : job->flow->res_idx,
3135 : : error);
3136 [ # # # # : 0 : if (age_idx == 0)
# # ]
3137 : 0 : return -rte_errno;
3138 : 0 : job->flow->age_idx = age_idx;
3139 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT)
# # ]
3140 : : /*
3141 : : * When AGE uses indirect counter, no need to
3142 : : * create counter but need to update it with the
3143 : : * AGE parameter, will be done after the loop.
3144 : : */
3145 : : break;
3146 : : /* Fall-through. */
3147 : : case RTE_FLOW_ACTION_TYPE_COUNT:
3148 : : /* If the port is engaged in resource sharing, do not use queue cache. */
3149 [ # # # # : 0 : cnt_queue = mlx5_hws_cnt_is_pool_shared(priv) ? NULL : &queue;
# # ]
3150 : : ret = mlx5_hws_cnt_pool_get(priv->hws_cpool, cnt_queue, &cnt_id, age_idx);
3151 [ # # # # : 0 : if (ret != 0)
# # ]
3152 : : return ret;
3153 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
3154 : : (priv->hws_cpool,
3155 : : cnt_id,
3156 : : &rule_acts[act_data->action_dst].action,
3157 : 0 : &rule_acts[act_data->action_dst].counter.offset
3158 : : );
3159 : : if (ret != 0)
3160 : : return ret;
3161 : 0 : job->flow->cnt_id = cnt_id;
3162 : 0 : break;
3163 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
3164 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
3165 : : (priv->hws_cpool,
3166 : : act_data->shared_counter.id,
3167 : : &rule_acts[act_data->action_dst].action,
3168 : 0 : &rule_acts[act_data->action_dst].counter.offset
3169 : : );
3170 : : if (ret != 0)
3171 : : return ret;
3172 : 0 : job->flow->cnt_id = act_data->shared_counter.id;
3173 : 0 : break;
3174 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
3175 : 0 : ct_idx = MLX5_ACTION_CTX_CT_GET_IDX
3176 : : ((uint32_t)(uintptr_t)action->conf);
3177 : 0 : if (flow_hw_ct_compile(dev, queue, ct_idx,
3178 : 0 : &rule_acts[act_data->action_dst]))
3179 : : return -1;
3180 : : break;
3181 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK:
3182 : 0 : mtr_id = act_data->shared_meter.id &
3183 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3184 : : /* Find ASO object. */
3185 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, mtr_id);
3186 [ # # # # : 0 : if (!aso_mtr)
# # ]
3187 : : return -1;
3188 : 0 : rule_acts[act_data->action_dst].action =
3189 : 0 : pool->action;
3190 : 0 : rule_acts[act_data->action_dst].aso_meter.offset =
3191 : 0 : aso_mtr->offset;
3192 : 0 : break;
3193 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
3194 : : /*
3195 : : * Allocate meter directly will slow down flow
3196 : : * insertion rate.
3197 : : */
3198 : : ret = flow_hw_meter_mark_compile(dev,
3199 : 0 : act_data->action_dst, action,
3200 [ # # # # : 0 : rule_acts, &job->flow->mtr_id, MLX5_HW_INV_QUEUE);
# # ]
3201 : : if (ret != 0)
3202 : : return ret;
3203 : : break;
3204 : : default:
3205 : : break;
3206 : : }
3207 : : }
3208 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT) {
# # ]
3209 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE) {
# # ]
3210 : 0 : age_idx = job->flow->age_idx & MLX5_HWS_AGE_IDX_MASK;
3211 [ # # # # : 0 : if (mlx5_hws_cnt_age_get(priv->hws_cpool,
# # # # #
# # # ]
3212 : : job->flow->cnt_id) != age_idx)
3213 : : /*
3214 : : * This is first use of this indirect counter
3215 : : * for this indirect AGE, need to increase the
3216 : : * number of counters.
3217 : : */
3218 : : mlx5_hws_age_nb_cnt_increase(priv, age_idx);
3219 : : }
3220 : : /*
3221 : : * Update this indirect counter the indirect/direct AGE in which
3222 : : * using it.
3223 : : */
3224 [ # # # # : 0 : mlx5_hws_cnt_age_set(priv->hws_cpool, job->flow->cnt_id,
# # ]
3225 : : age_idx);
3226 : : }
3227 [ # # # # : 0 : if (hw_acts->encap_decap && !hw_acts->encap_decap->shared) {
# # # # #
# # # ]
3228 : 0 : rule_acts[hw_acts->encap_decap_pos].reformat.offset =
3229 : 0 : job->flow->res_idx - 1;
3230 : 0 : rule_acts[hw_acts->encap_decap_pos].reformat.data = buf;
3231 : : }
3232 [ # # # # : 0 : if (hw_acts->push_remove && !hw_acts->push_remove->shared) {
# # # # #
# # # ]
3233 : 0 : rule_acts[hw_acts->push_remove_pos].ipv6_ext.offset =
3234 : 0 : job->flow->res_idx - 1;
3235 : 0 : rule_acts[hw_acts->push_remove_pos].ipv6_ext.header = push_buf;
3236 : : }
3237 [ # # # # : 0 : if (mlx5_hws_cnt_id_valid(hw_acts->cnt_id))
# # ]
3238 : 0 : job->flow->cnt_id = hw_acts->cnt_id;
3239 : : return 0;
3240 : : }
3241 : :
3242 : : static const struct rte_flow_item *
3243 : 0 : flow_hw_get_rule_items(struct rte_eth_dev *dev,
3244 : : const struct rte_flow_template_table *table,
3245 : : const struct rte_flow_item items[],
3246 : : uint8_t pattern_template_index,
3247 : : struct mlx5_hw_q_job *job)
3248 : : {
3249 : 0 : struct rte_flow_pattern_template *pt = table->its[pattern_template_index];
3250 : :
3251 : : /* Only one implicit item can be added to flow rule pattern. */
3252 : : MLX5_ASSERT(!pt->implicit_port || !pt->implicit_tag);
3253 : : /* At least one item was allocated in job descriptor for items. */
3254 : : MLX5_ASSERT(MLX5_HW_MAX_ITEMS >= 1);
3255 [ # # ]: 0 : if (pt->implicit_port) {
3256 [ # # ]: 0 : if (pt->orig_item_nb + 1 > MLX5_HW_MAX_ITEMS) {
3257 : 0 : rte_errno = ENOMEM;
3258 : 0 : return NULL;
3259 : : }
3260 : : /* Set up represented port item in job descriptor. */
3261 : 0 : job->port_spec = (struct rte_flow_item_ethdev){
3262 : 0 : .port_id = dev->data->port_id,
3263 : : };
3264 : 0 : job->items[0] = (struct rte_flow_item){
3265 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
3266 : 0 : .spec = &job->port_spec,
3267 : : };
3268 [ # # ]: 0 : rte_memcpy(&job->items[1], items, sizeof(*items) * pt->orig_item_nb);
3269 : 0 : return job->items;
3270 [ # # ]: 0 : } else if (pt->implicit_tag) {
3271 [ # # ]: 0 : if (pt->orig_item_nb + 1 > MLX5_HW_MAX_ITEMS) {
3272 : 0 : rte_errno = ENOMEM;
3273 : 0 : return NULL;
3274 : : }
3275 : : /* Set up tag item in job descriptor. */
3276 : 0 : job->tag_spec = (struct rte_flow_item_tag){
3277 : : .data = flow_hw_tx_tag_regc_value(dev),
3278 : : };
3279 : 0 : job->items[0] = (struct rte_flow_item){
3280 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3281 : 0 : .spec = &job->tag_spec,
3282 : : };
3283 : 0 : rte_memcpy(&job->items[1], items, sizeof(*items) * pt->orig_item_nb);
3284 : 0 : return job->items;
3285 : : } else {
3286 : : return items;
3287 : : }
3288 : : }
3289 : :
3290 : : /**
3291 : : * Enqueue HW steering flow creation.
3292 : : *
3293 : : * The flow will be applied to the HW only if the postpone bit is not set or
3294 : : * the extra push function is called.
3295 : : * The flow creation status should be checked from dequeue result.
3296 : : *
3297 : : * @param[in] dev
3298 : : * Pointer to the rte_eth_dev structure.
3299 : : * @param[in] queue
3300 : : * The queue to create the flow.
3301 : : * @param[in] attr
3302 : : * Pointer to the flow operation attributes.
3303 : : * @param[in] items
3304 : : * Items with flow spec value.
3305 : : * @param[in] pattern_template_index
3306 : : * The item pattern flow follows from the table.
3307 : : * @param[in] actions
3308 : : * Action with flow spec value.
3309 : : * @param[in] action_template_index
3310 : : * The action pattern flow follows from the table.
3311 : : * @param[in] user_data
3312 : : * Pointer to the user_data.
3313 : : * @param[out] error
3314 : : * Pointer to error structure.
3315 : : *
3316 : : * @return
3317 : : * Flow pointer on success, NULL otherwise and rte_errno is set.
3318 : : */
3319 : : static struct rte_flow *
3320 : 0 : flow_hw_async_flow_create(struct rte_eth_dev *dev,
3321 : : uint32_t queue,
3322 : : const struct rte_flow_op_attr *attr,
3323 : : struct rte_flow_template_table *table,
3324 : : const struct rte_flow_item items[],
3325 : : uint8_t pattern_template_index,
3326 : : const struct rte_flow_action actions[],
3327 : : uint8_t action_template_index,
3328 : : void *user_data,
3329 : : struct rte_flow_error *error)
3330 : : {
3331 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3332 : 0 : struct mlx5dr_rule_attr rule_attr = {
3333 : : .queue_id = queue,
3334 : : .user_data = user_data,
3335 : 0 : .burst = attr->postpone,
3336 : : };
3337 : : struct mlx5dr_rule_action rule_acts[MLX5_HW_MAX_ACTS];
3338 : : struct rte_flow_hw *flow = NULL;
3339 : : struct mlx5_hw_q_job *job = NULL;
3340 : : const struct rte_flow_item *rule_items;
3341 : 0 : uint32_t flow_idx = 0;
3342 : 0 : uint32_t res_idx = 0;
3343 : : int ret;
3344 : :
3345 [ # # ]: 0 : if (unlikely((!dev->data->dev_started))) {
3346 : 0 : rte_errno = EINVAL;
3347 : 0 : goto error;
3348 : : }
3349 : : job = flow_hw_job_get(priv, queue);
3350 [ # # ]: 0 : if (!job) {
3351 : 0 : rte_errno = ENOMEM;
3352 : 0 : goto error;
3353 : : }
3354 : 0 : flow = mlx5_ipool_zmalloc(table->flow, &flow_idx);
3355 [ # # ]: 0 : if (!flow)
3356 : 0 : goto error;
3357 : 0 : mlx5_ipool_malloc(table->resource, &res_idx);
3358 [ # # ]: 0 : if (!res_idx)
3359 : 0 : goto error;
3360 : : /*
3361 : : * Set the table here in order to know the destination table
3362 : : * when free the flow afterward.
3363 : : */
3364 : 0 : flow->table = table;
3365 : 0 : flow->mt_idx = pattern_template_index;
3366 : 0 : flow->idx = flow_idx;
3367 : 0 : flow->res_idx = res_idx;
3368 : : /*
3369 : : * Set the job type here in order to know if the flow memory
3370 : : * should be freed or not when get the result from dequeue.
3371 : : */
3372 : 0 : job->type = MLX5_HW_Q_JOB_TYPE_CREATE;
3373 : 0 : job->flow = flow;
3374 : 0 : job->user_data = user_data;
3375 : 0 : rule_attr.user_data = job;
3376 : : /*
3377 : : * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices for rule
3378 : : * insertion hints.
3379 : : */
3380 : : MLX5_ASSERT(res_idx > 0);
3381 : 0 : flow->rule_idx = res_idx - 1;
3382 : 0 : rule_attr.rule_idx = flow->rule_idx;
3383 : : /*
3384 : : * Construct the flow actions based on the input actions.
3385 : : * The implicitly appended action is always fixed, like metadata
3386 : : * copy action from FDB to NIC Rx.
3387 : : * No need to copy and contrust a new "actions" list based on the
3388 : : * user's input, in order to save the cost.
3389 : : */
3390 [ # # ]: 0 : if (flow_hw_actions_construct(dev, job,
3391 [ # # ]: 0 : &table->ats[action_template_index],
3392 : : pattern_template_index, actions,
3393 : : rule_acts, queue, error)) {
3394 : 0 : rte_errno = EINVAL;
3395 : 0 : goto error;
3396 : : }
3397 : 0 : rule_items = flow_hw_get_rule_items(dev, table, items,
3398 : : pattern_template_index, job);
3399 [ # # ]: 0 : if (!rule_items)
3400 : 0 : goto error;
3401 : 0 : ret = mlx5dr_rule_create(table->matcher,
3402 : : pattern_template_index, rule_items,
3403 : : action_template_index, rule_acts,
3404 : 0 : &rule_attr, (struct mlx5dr_rule *)flow->rule);
3405 [ # # ]: 0 : if (likely(!ret))
3406 : : return (struct rte_flow *)flow;
3407 : 0 : error:
3408 [ # # ]: 0 : if (job)
3409 : : flow_hw_job_put(priv, job, queue);
3410 [ # # ]: 0 : if (flow_idx)
3411 : 0 : mlx5_ipool_free(table->flow, flow_idx);
3412 [ # # ]: 0 : if (res_idx)
3413 : 0 : mlx5_ipool_free(table->resource, res_idx);
3414 : 0 : rte_flow_error_set(error, rte_errno,
3415 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3416 : : "fail to create rte flow");
3417 : 0 : return NULL;
3418 : : }
3419 : :
3420 : : /**
3421 : : * Enqueue HW steering flow creation by index.
3422 : : *
3423 : : * The flow will be applied to the HW only if the postpone bit is not set or
3424 : : * the extra push function is called.
3425 : : * The flow creation status should be checked from dequeue result.
3426 : : *
3427 : : * @param[in] dev
3428 : : * Pointer to the rte_eth_dev structure.
3429 : : * @param[in] queue
3430 : : * The queue to create the flow.
3431 : : * @param[in] attr
3432 : : * Pointer to the flow operation attributes.
3433 : : * @param[in] rule_index
3434 : : * The item pattern flow follows from the table.
3435 : : * @param[in] actions
3436 : : * Action with flow spec value.
3437 : : * @param[in] action_template_index
3438 : : * The action pattern flow follows from the table.
3439 : : * @param[in] user_data
3440 : : * Pointer to the user_data.
3441 : : * @param[out] error
3442 : : * Pointer to error structure.
3443 : : *
3444 : : * @return
3445 : : * Flow pointer on success, NULL otherwise and rte_errno is set.
3446 : : */
3447 : : static struct rte_flow *
3448 : 0 : flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
3449 : : uint32_t queue,
3450 : : const struct rte_flow_op_attr *attr,
3451 : : struct rte_flow_template_table *table,
3452 : : uint32_t rule_index,
3453 : : const struct rte_flow_action actions[],
3454 : : uint8_t action_template_index,
3455 : : void *user_data,
3456 : : struct rte_flow_error *error)
3457 : : {
3458 : 0 : struct rte_flow_item items[] = {{.type = RTE_FLOW_ITEM_TYPE_END,}};
3459 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3460 : 0 : struct mlx5dr_rule_attr rule_attr = {
3461 : : .queue_id = queue,
3462 : : .user_data = user_data,
3463 : 0 : .burst = attr->postpone,
3464 : : };
3465 : : struct mlx5dr_rule_action rule_acts[MLX5_HW_MAX_ACTS];
3466 : : struct rte_flow_hw *flow = NULL;
3467 : : struct mlx5_hw_q_job *job = NULL;
3468 : 0 : uint32_t flow_idx = 0;
3469 : 0 : uint32_t res_idx = 0;
3470 : : int ret;
3471 : :
3472 [ # # ]: 0 : if (unlikely(rule_index >= table->cfg.attr.nb_flows)) {
3473 : 0 : rte_errno = EINVAL;
3474 : 0 : goto error;
3475 : : }
3476 : : job = flow_hw_job_get(priv, queue);
3477 [ # # ]: 0 : if (!job) {
3478 : 0 : rte_errno = ENOMEM;
3479 : 0 : goto error;
3480 : : }
3481 : 0 : flow = mlx5_ipool_zmalloc(table->flow, &flow_idx);
3482 [ # # ]: 0 : if (!flow)
3483 : 0 : goto error;
3484 : 0 : mlx5_ipool_malloc(table->resource, &res_idx);
3485 [ # # ]: 0 : if (!res_idx)
3486 : 0 : goto error;
3487 : : /*
3488 : : * Set the table here in order to know the destination table
3489 : : * when free the flow afterwards.
3490 : : */
3491 : 0 : flow->table = table;
3492 : 0 : flow->mt_idx = 0;
3493 : 0 : flow->idx = flow_idx;
3494 : 0 : flow->res_idx = res_idx;
3495 : : /*
3496 : : * Set the job type here in order to know if the flow memory
3497 : : * should be freed or not when get the result from dequeue.
3498 : : */
3499 : 0 : job->type = MLX5_HW_Q_JOB_TYPE_CREATE;
3500 : 0 : job->flow = flow;
3501 : 0 : job->user_data = user_data;
3502 : 0 : rule_attr.user_data = job;
3503 : : /*
3504 : : * Set the rule index.
3505 : : */
3506 : 0 : flow->rule_idx = rule_index;
3507 : 0 : rule_attr.rule_idx = flow->rule_idx;
3508 : : /*
3509 : : * Construct the flow actions based on the input actions.
3510 : : * The implicitly appended action is always fixed, like metadata
3511 : : * copy action from FDB to NIC Rx.
3512 : : * No need to copy and contrust a new "actions" list based on the
3513 : : * user's input, in order to save the cost.
3514 : : */
3515 [ # # ]: 0 : if (flow_hw_actions_construct(dev, job,
3516 [ # # ]: 0 : &table->ats[action_template_index],
3517 : : 0, actions, rule_acts, queue, error)) {
3518 : 0 : rte_errno = EINVAL;
3519 : 0 : goto error;
3520 : : }
3521 : 0 : ret = mlx5dr_rule_create(table->matcher,
3522 : : 0, items, action_template_index, rule_acts,
3523 : 0 : &rule_attr, (struct mlx5dr_rule *)flow->rule);
3524 [ # # ]: 0 : if (likely(!ret))
3525 : : return (struct rte_flow *)flow;
3526 : 0 : error:
3527 [ # # ]: 0 : if (job)
3528 : : flow_hw_job_put(priv, job, queue);
3529 [ # # ]: 0 : if (res_idx)
3530 : 0 : mlx5_ipool_free(table->resource, res_idx);
3531 [ # # ]: 0 : if (flow_idx)
3532 : 0 : mlx5_ipool_free(table->flow, flow_idx);
3533 : 0 : rte_flow_error_set(error, rte_errno,
3534 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3535 : : "fail to create rte flow");
3536 : 0 : return NULL;
3537 : : }
3538 : :
3539 : : /**
3540 : : * Enqueue HW steering flow update.
3541 : : *
3542 : : * The flow will be applied to the HW only if the postpone bit is not set or
3543 : : * the extra push function is called.
3544 : : * The flow destruction status should be checked from dequeue result.
3545 : : *
3546 : : * @param[in] dev
3547 : : * Pointer to the rte_eth_dev structure.
3548 : : * @param[in] queue
3549 : : * The queue to destroy the flow.
3550 : : * @param[in] attr
3551 : : * Pointer to the flow operation attributes.
3552 : : * @param[in] flow
3553 : : * Pointer to the flow to be destroyed.
3554 : : * @param[in] actions
3555 : : * Action with flow spec value.
3556 : : * @param[in] action_template_index
3557 : : * The action pattern flow follows from the table.
3558 : : * @param[in] user_data
3559 : : * Pointer to the user_data.
3560 : : * @param[out] error
3561 : : * Pointer to error structure.
3562 : : *
3563 : : * @return
3564 : : * 0 on success, negative value otherwise and rte_errno is set.
3565 : : */
3566 : : static int
3567 : 0 : flow_hw_async_flow_update(struct rte_eth_dev *dev,
3568 : : uint32_t queue,
3569 : : const struct rte_flow_op_attr *attr,
3570 : : struct rte_flow *flow,
3571 : : const struct rte_flow_action actions[],
3572 : : uint8_t action_template_index,
3573 : : void *user_data,
3574 : : struct rte_flow_error *error)
3575 : : {
3576 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3577 : 0 : struct mlx5dr_rule_attr rule_attr = {
3578 : : .queue_id = queue,
3579 : : .user_data = user_data,
3580 : 0 : .burst = attr->postpone,
3581 : : };
3582 : : struct mlx5dr_rule_action rule_acts[MLX5_HW_MAX_ACTS];
3583 : : struct rte_flow_hw *of = (struct rte_flow_hw *)flow;
3584 : : struct rte_flow_hw *nf;
3585 : 0 : struct rte_flow_template_table *table = of->table;
3586 : : struct mlx5_hw_q_job *job = NULL;
3587 [ # # ]: 0 : uint32_t res_idx = 0;
3588 : : int ret;
3589 : :
3590 : : job = flow_hw_job_get(priv, queue);
3591 [ # # ]: 0 : if (!job) {
3592 : 0 : rte_errno = ENOMEM;
3593 : 0 : goto error;
3594 : : }
3595 : 0 : mlx5_ipool_malloc(table->resource, &res_idx);
3596 [ # # ]: 0 : if (!res_idx)
3597 : 0 : goto error;
3598 [ # # ]: 0 : nf = job->upd_flow;
3599 : : memset(nf, 0, sizeof(struct rte_flow_hw));
3600 : : /*
3601 : : * Set the table here in order to know the destination table
3602 : : * when free the flow afterwards.
3603 : : */
3604 : 0 : nf->table = table;
3605 : 0 : nf->mt_idx = of->mt_idx;
3606 : 0 : nf->idx = of->idx;
3607 : 0 : nf->res_idx = res_idx;
3608 : : /*
3609 : : * Set the job type here in order to know if the flow memory
3610 : : * should be freed or not when get the result from dequeue.
3611 : : */
3612 : 0 : job->type = MLX5_HW_Q_JOB_TYPE_UPDATE;
3613 : 0 : job->flow = nf;
3614 : 0 : job->user_data = user_data;
3615 : 0 : rule_attr.user_data = job;
3616 : : /*
3617 : : * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices for rule
3618 : : * insertion hints.
3619 : : */
3620 : : MLX5_ASSERT(res_idx > 0);
3621 : 0 : nf->rule_idx = res_idx - 1;
3622 : 0 : rule_attr.rule_idx = nf->rule_idx;
3623 : : /*
3624 : : * Construct the flow actions based on the input actions.
3625 : : * The implicitly appended action is always fixed, like metadata
3626 : : * copy action from FDB to NIC Rx.
3627 : : * No need to copy and contrust a new "actions" list based on the
3628 : : * user's input, in order to save the cost.
3629 : : */
3630 [ # # ]: 0 : if (flow_hw_actions_construct(dev, job,
3631 [ # # ]: 0 : &table->ats[action_template_index],
3632 : : nf->mt_idx, actions,
3633 : : rule_acts, queue, error)) {
3634 : 0 : rte_errno = EINVAL;
3635 : 0 : goto error;
3636 : : }
3637 : : /*
3638 : : * Switch the old flow and the new flow.
3639 : : */
3640 : 0 : job->flow = of;
3641 : 0 : job->upd_flow = nf;
3642 : 0 : ret = mlx5dr_rule_action_update((struct mlx5dr_rule *)of->rule,
3643 : : action_template_index, rule_acts, &rule_attr);
3644 [ # # ]: 0 : if (likely(!ret))
3645 : : return 0;
3646 : 0 : error:
3647 : : /* Flow created fail, return the descriptor and flow memory. */
3648 [ # # ]: 0 : if (job)
3649 : : flow_hw_job_put(priv, job, queue);
3650 [ # # ]: 0 : if (res_idx)
3651 : 0 : mlx5_ipool_free(table->resource, res_idx);
3652 : 0 : return rte_flow_error_set(error, rte_errno,
3653 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3654 : : "fail to update rte flow");
3655 : : }
3656 : :
3657 : : /**
3658 : : * Enqueue HW steering flow destruction.
3659 : : *
3660 : : * The flow will be applied to the HW only if the postpone bit is not set or
3661 : : * the extra push function is called.
3662 : : * The flow destruction status should be checked from dequeue result.
3663 : : *
3664 : : * @param[in] dev
3665 : : * Pointer to the rte_eth_dev structure.
3666 : : * @param[in] queue
3667 : : * The queue to destroy the flow.
3668 : : * @param[in] attr
3669 : : * Pointer to the flow operation attributes.
3670 : : * @param[in] flow
3671 : : * Pointer to the flow to be destroyed.
3672 : : * @param[in] user_data
3673 : : * Pointer to the user_data.
3674 : : * @param[out] error
3675 : : * Pointer to error structure.
3676 : : *
3677 : : * @return
3678 : : * 0 on success, negative value otherwise and rte_errno is set.
3679 : : */
3680 : : static int
3681 : 0 : flow_hw_async_flow_destroy(struct rte_eth_dev *dev,
3682 : : uint32_t queue,
3683 : : const struct rte_flow_op_attr *attr,
3684 : : struct rte_flow *flow,
3685 : : void *user_data,
3686 : : struct rte_flow_error *error)
3687 : : {
3688 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3689 : 0 : struct mlx5dr_rule_attr rule_attr = {
3690 : : .queue_id = queue,
3691 : : .user_data = user_data,
3692 [ # # ]: 0 : .burst = attr->postpone,
3693 : : };
3694 : : struct rte_flow_hw *fh = (struct rte_flow_hw *)flow;
3695 : : struct mlx5_hw_q_job *job;
3696 : : int ret;
3697 : :
3698 : : job = flow_hw_job_get(priv, queue);
3699 [ # # ]: 0 : if (!job)
3700 : 0 : return rte_flow_error_set(error, ENOMEM,
3701 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3702 : : "fail to destroy rte flow: flow queue full");
3703 : 0 : job->type = MLX5_HW_Q_JOB_TYPE_DESTROY;
3704 : 0 : job->user_data = user_data;
3705 : 0 : job->flow = fh;
3706 : 0 : rule_attr.user_data = job;
3707 : 0 : rule_attr.rule_idx = fh->rule_idx;
3708 : 0 : ret = mlx5dr_rule_destroy((struct mlx5dr_rule *)fh->rule, &rule_attr);
3709 [ # # ]: 0 : if (ret) {
3710 : : flow_hw_job_put(priv, job, queue);
3711 : 0 : return rte_flow_error_set(error, rte_errno,
3712 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3713 : : "fail to destroy rte flow");
3714 : : }
3715 : : return 0;
3716 : : }
3717 : :
3718 : : /**
3719 : : * Release the AGE and counter for given flow.
3720 : : *
3721 : : * @param[in] priv
3722 : : * Pointer to the port private data structure.
3723 : : * @param[in] queue
3724 : : * The queue to release the counter.
3725 : : * @param[in, out] flow
3726 : : * Pointer to the flow containing the counter.
3727 : : * @param[out] error
3728 : : * Pointer to error structure.
3729 : : */
3730 : : static void
3731 : 0 : flow_hw_age_count_release(struct mlx5_priv *priv, uint32_t queue,
3732 : : struct rte_flow_hw *flow,
3733 : : struct rte_flow_error *error)
3734 : : {
3735 : : uint32_t *cnt_queue;
3736 : :
3737 [ # # # # ]: 0 : if (mlx5_hws_cnt_is_shared(priv->hws_cpool, flow->cnt_id)) {
3738 [ # # # # ]: 0 : if (flow->age_idx && !mlx5_hws_age_is_indirect(flow->age_idx)) {
3739 : : /* Remove this AGE parameter from indirect counter. */
3740 : : mlx5_hws_cnt_age_set(priv->hws_cpool, flow->cnt_id, 0);
3741 : : /* Release the AGE parameter. */
3742 : 0 : mlx5_hws_age_action_destroy(priv, flow->age_idx, error);
3743 : 0 : flow->age_idx = 0;
3744 : : }
3745 : 0 : return;
3746 : : }
3747 : : /* If the port is engaged in resource sharing, do not use queue cache. */
3748 [ # # ]: 0 : cnt_queue = mlx5_hws_cnt_is_pool_shared(priv) ? NULL : &queue;
3749 : : /* Put the counter first to reduce the race risk in BG thread. */
3750 [ # # ]: 0 : mlx5_hws_cnt_pool_put(priv->hws_cpool, cnt_queue, &flow->cnt_id);
3751 : 0 : flow->cnt_id = 0;
3752 [ # # ]: 0 : if (flow->age_idx) {
3753 [ # # ]: 0 : if (mlx5_hws_age_is_indirect(flow->age_idx)) {
3754 : 0 : uint32_t idx = flow->age_idx & MLX5_HWS_AGE_IDX_MASK;
3755 : :
3756 : : mlx5_hws_age_nb_cnt_decrease(priv, idx);
3757 : : } else {
3758 : : /* Release the AGE parameter. */
3759 : 0 : mlx5_hws_age_action_destroy(priv, flow->age_idx, error);
3760 : : }
3761 : 0 : flow->age_idx = 0;
3762 : : }
3763 : : }
3764 : :
3765 : : static __rte_always_inline void
3766 : : flow_hw_pull_legacy_indirect_comp(struct rte_eth_dev *dev, struct mlx5_hw_q_job *job,
3767 : : uint32_t queue)
3768 : : {
3769 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3770 : : struct mlx5_aso_ct_action *aso_ct;
3771 : : struct mlx5_aso_mtr *aso_mtr;
3772 : : uint32_t type, idx;
3773 : :
3774 [ # # ]: 0 : if (MLX5_INDIRECT_ACTION_TYPE_GET(job->action) ==
3775 : : MLX5_INDIRECT_ACTION_TYPE_QUOTA) {
3776 : 0 : mlx5_quota_async_completion(dev, queue, job);
3777 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_DESTROY) {
3778 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
3779 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK) {
3780 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
3781 : 0 : mlx5_ipool_free(priv->hws_mpool->idx_pool, idx);
3782 : : }
3783 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_CREATE) {
3784 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
3785 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK) {
3786 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
3787 : 0 : aso_mtr = mlx5_ipool_get(priv->hws_mpool->idx_pool, idx);
3788 : 0 : aso_mtr->state = ASO_METER_READY;
3789 [ # # ]: 0 : } else if (type == MLX5_INDIRECT_ACTION_TYPE_CT) {
3790 : 0 : idx = MLX5_ACTION_CTX_CT_GET_IDX
3791 : : ((uint32_t)(uintptr_t)job->action);
3792 : 0 : aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
3793 : 0 : aso_ct->state = ASO_CONNTRACK_READY;
3794 : : }
3795 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_QUERY) {
3796 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
3797 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_CT) {
3798 : 0 : idx = MLX5_ACTION_CTX_CT_GET_IDX
3799 : : ((uint32_t)(uintptr_t)job->action);
3800 : 0 : aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
3801 : 0 : mlx5_aso_ct_obj_analyze(job->query.user,
3802 : 0 : job->query.hw);
3803 : 0 : aso_ct->state = ASO_CONNTRACK_READY;
3804 : : }
3805 : : } else {
3806 : : /*
3807 : : * rte_flow_op_result::user data can point to
3808 : : * struct mlx5_aso_mtr object as well
3809 : : */
3810 : : if (queue != CTRL_QUEUE_ID(priv))
3811 : : MLX5_ASSERT(false);
3812 : : }
3813 : : }
3814 : :
3815 : : static inline int
3816 : 0 : __flow_hw_pull_indir_action_comp(struct rte_eth_dev *dev,
3817 : : uint32_t queue,
3818 : : struct rte_flow_op_result res[],
3819 : : uint16_t n_res)
3820 : :
3821 : : {
3822 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3823 : 0 : struct rte_ring *r = priv->hw_q[queue].indir_cq;
3824 : 0 : void *user_data = NULL;
3825 : : int ret_comp, i;
3826 : :
3827 : 0 : ret_comp = (int)rte_ring_count(r);
3828 : 0 : if (ret_comp > n_res)
3829 : : ret_comp = n_res;
3830 [ # # ]: 0 : for (i = 0; i < ret_comp; i++) {
3831 : : rte_ring_dequeue(r, &user_data);
3832 : 0 : res[i].user_data = user_data;
3833 : 0 : res[i].status = RTE_FLOW_OP_SUCCESS;
3834 : : }
3835 [ # # # # ]: 0 : if (ret_comp < n_res && priv->hws_mpool)
3836 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->hws_mpool->sq[queue],
3837 : 0 : &res[ret_comp], n_res - ret_comp);
3838 [ # # # # ]: 0 : if (ret_comp < n_res && priv->hws_ctpool)
3839 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->ct_mng->aso_sqs[queue],
3840 : 0 : &res[ret_comp], n_res - ret_comp);
3841 [ # # # # ]: 0 : if (ret_comp < n_res && priv->quota_ctx.sq)
3842 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->quota_ctx.sq[queue],
3843 : 0 : &res[ret_comp],
3844 : 0 : n_res - ret_comp);
3845 [ # # ]: 0 : for (i = 0; i < ret_comp; i++) {
3846 : 0 : struct mlx5_hw_q_job *job = (struct mlx5_hw_q_job *)res[i].user_data;
3847 : :
3848 : : /* Restore user data. */
3849 : 0 : res[i].user_data = job->user_data;
3850 [ # # ]: 0 : if (job->indirect_type == MLX5_HW_INDIRECT_TYPE_LEGACY)
3851 : : flow_hw_pull_legacy_indirect_comp(dev, job, queue);
3852 : : /*
3853 : : * Current PMD supports 2 indirect action list types - MIRROR and REFORMAT.
3854 : : * These indirect list types do not post WQE to create action.
3855 : : * Future indirect list types that do post WQE will add
3856 : : * completion handlers here.
3857 : : */
3858 : : flow_hw_job_put(priv, job, queue);
3859 : : }
3860 : 0 : return ret_comp;
3861 : : }
3862 : :
3863 : : /**
3864 : : * Pull the enqueued flows.
3865 : : *
3866 : : * For flows enqueued from creation/destruction, the status should be
3867 : : * checked from the dequeue result.
3868 : : *
3869 : : * @param[in] dev
3870 : : * Pointer to the rte_eth_dev structure.
3871 : : * @param[in] queue
3872 : : * The queue to pull the result.
3873 : : * @param[in/out] res
3874 : : * Array to save the results.
3875 : : * @param[in] n_res
3876 : : * Available result with the array.
3877 : : * @param[out] error
3878 : : * Pointer to error structure.
3879 : : *
3880 : : * @return
3881 : : * Result number on success, negative value otherwise and rte_errno is set.
3882 : : */
3883 : : static int
3884 : 0 : flow_hw_pull(struct rte_eth_dev *dev,
3885 : : uint32_t queue,
3886 : : struct rte_flow_op_result res[],
3887 : : uint16_t n_res,
3888 : : struct rte_flow_error *error)
3889 : : {
3890 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3891 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
3892 : : struct mlx5_hw_q_job *job;
3893 : : uint32_t res_idx;
3894 : : int ret, i;
3895 : :
3896 : : /* 1. Pull the flow completion. */
3897 : 0 : ret = mlx5dr_send_queue_poll(priv->dr_ctx, queue, res, n_res);
3898 [ # # ]: 0 : if (ret < 0)
3899 : 0 : return rte_flow_error_set(error, rte_errno,
3900 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3901 : : "fail to query flow queue");
3902 [ # # ]: 0 : for (i = 0; i < ret; i++) {
3903 : 0 : job = (struct mlx5_hw_q_job *)res[i].user_data;
3904 : : /* Release the original resource index in case of update. */
3905 : 0 : res_idx = job->flow->res_idx;
3906 : : /* Restore user data. */
3907 : 0 : res[i].user_data = job->user_data;
3908 [ # # ]: 0 : if (job->type == MLX5_HW_Q_JOB_TYPE_DESTROY ||
3909 : : job->type == MLX5_HW_Q_JOB_TYPE_UPDATE) {
3910 [ # # ]: 0 : if (job->flow->fate_type == MLX5_FLOW_FATE_JUMP)
3911 : 0 : flow_hw_jump_release(dev, job->flow->jump);
3912 [ # # ]: 0 : else if (job->flow->fate_type == MLX5_FLOW_FATE_QUEUE)
3913 : 0 : mlx5_hrxq_obj_release(dev, job->flow->hrxq);
3914 [ # # ]: 0 : if (mlx5_hws_cnt_id_valid(job->flow->cnt_id))
3915 : 0 : flow_hw_age_count_release(priv, queue,
3916 : : job->flow, error);
3917 [ # # ]: 0 : if (job->flow->mtr_id) {
3918 : 0 : mlx5_ipool_free(pool->idx_pool, job->flow->mtr_id);
3919 : 0 : job->flow->mtr_id = 0;
3920 : : }
3921 [ # # ]: 0 : if (job->type == MLX5_HW_Q_JOB_TYPE_DESTROY) {
3922 : 0 : mlx5_ipool_free(job->flow->table->resource, res_idx);
3923 : 0 : mlx5_ipool_free(job->flow->table->flow, job->flow->idx);
3924 : : } else {
3925 [ # # ]: 0 : rte_memcpy(job->flow, job->upd_flow,
3926 : : offsetof(struct rte_flow_hw, rule));
3927 : 0 : mlx5_ipool_free(job->flow->table->resource, res_idx);
3928 : : }
3929 : : }
3930 : : flow_hw_job_put(priv, job, queue);
3931 : : }
3932 : : /* 2. Pull indirect action comp. */
3933 [ # # ]: 0 : if (ret < n_res)
3934 : 0 : ret += __flow_hw_pull_indir_action_comp(dev, queue, &res[ret],
3935 : 0 : n_res - ret);
3936 : : return ret;
3937 : : }
3938 : :
3939 : : static inline uint32_t
3940 : 0 : __flow_hw_push_action(struct rte_eth_dev *dev,
3941 : : uint32_t queue)
3942 : : {
3943 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3944 : 0 : struct rte_ring *iq = priv->hw_q[queue].indir_iq;
3945 : 0 : struct rte_ring *cq = priv->hw_q[queue].indir_cq;
3946 : 0 : void *job = NULL;
3947 : : uint32_t ret, i;
3948 : :
3949 : : ret = rte_ring_count(iq);
3950 [ # # ]: 0 : for (i = 0; i < ret; i++) {
3951 : : rte_ring_dequeue(iq, &job);
3952 [ # # # # : 0 : rte_ring_enqueue(cq, job);
# ]
3953 : : }
3954 [ # # ]: 0 : if (!priv->shared_host) {
3955 [ # # ]: 0 : if (priv->hws_ctpool)
3956 : 0 : mlx5_aso_push_wqe(priv->sh,
3957 : 0 : &priv->ct_mng->aso_sqs[queue]);
3958 [ # # ]: 0 : if (priv->hws_mpool)
3959 : 0 : mlx5_aso_push_wqe(priv->sh,
3960 : 0 : &priv->hws_mpool->sq[queue]);
3961 : : }
3962 : 0 : return priv->hw_q[queue].size - priv->hw_q[queue].job_idx;
3963 : : }
3964 : :
3965 : : static int
3966 : 0 : __flow_hw_push(struct rte_eth_dev *dev,
3967 : : uint32_t queue,
3968 : : struct rte_flow_error *error)
3969 : : {
3970 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3971 : : int ret, num;
3972 : :
3973 : 0 : num = __flow_hw_push_action(dev, queue);
3974 : 0 : ret = mlx5dr_send_queue_action(priv->dr_ctx, queue,
3975 : : MLX5DR_SEND_QUEUE_ACTION_DRAIN_ASYNC);
3976 [ # # ]: 0 : if (ret) {
3977 : 0 : rte_flow_error_set(error, rte_errno,
3978 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3979 : : "fail to push flows");
3980 : 0 : return ret;
3981 : : }
3982 : : return num;
3983 : : }
3984 : :
3985 : : /**
3986 : : * Push the enqueued flows to HW.
3987 : : *
3988 : : * Force apply all the enqueued flows to the HW.
3989 : : *
3990 : : * @param[in] dev
3991 : : * Pointer to the rte_eth_dev structure.
3992 : : * @param[in] queue
3993 : : * The queue to push the flow.
3994 : : * @param[out] error
3995 : : * Pointer to error structure.
3996 : : *
3997 : : * @return
3998 : : * 0 on success, negative value otherwise and rte_errno is set.
3999 : : */
4000 : : static int
4001 : 0 : flow_hw_push(struct rte_eth_dev *dev,
4002 : : uint32_t queue, struct rte_flow_error *error)
4003 : : {
4004 : 0 : int ret = __flow_hw_push(dev, queue, error);
4005 : :
4006 : 0 : return ret >= 0 ? 0 : ret;
4007 : : }
4008 : :
4009 : : /**
4010 : : * Drain the enqueued flows' completion.
4011 : : *
4012 : : * @param[in] dev
4013 : : * Pointer to the rte_eth_dev structure.
4014 : : * @param[in] queue
4015 : : * The queue to pull the flow.
4016 : : * @param[out] error
4017 : : * Pointer to error structure.
4018 : : *
4019 : : * @return
4020 : : * 0 on success, negative value otherwise and rte_errno is set.
4021 : : */
4022 : : static int
4023 : 0 : __flow_hw_pull_comp(struct rte_eth_dev *dev,
4024 : : uint32_t queue, struct rte_flow_error *error)
4025 : : {
4026 : : struct rte_flow_op_result comp[BURST_THR];
4027 : : int ret, i, empty_loop = 0;
4028 : : uint32_t pending_rules;
4029 : :
4030 : 0 : ret = __flow_hw_push(dev, queue, error);
4031 [ # # ]: 0 : if (ret < 0)
4032 : : return ret;
4033 : 0 : pending_rules = ret;
4034 [ # # ]: 0 : while (pending_rules) {
4035 : 0 : ret = flow_hw_pull(dev, queue, comp, BURST_THR, error);
4036 [ # # ]: 0 : if (ret < 0)
4037 : : return -1;
4038 [ # # ]: 0 : if (!ret) {
4039 : 0 : rte_delay_us_sleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY);
4040 [ # # ]: 0 : if (++empty_loop > 5) {
4041 : 0 : DRV_LOG(WARNING, "No available dequeue %u, quit.", pending_rules);
4042 : 0 : break;
4043 : : }
4044 : 0 : continue;
4045 : : }
4046 [ # # ]: 0 : for (i = 0; i < ret; i++) {
4047 [ # # ]: 0 : if (comp[i].status == RTE_FLOW_OP_ERROR)
4048 : 0 : DRV_LOG(WARNING, "Flow flush get error CQE.");
4049 : : }
4050 : : /*
4051 : : * Indirect **SYNC** METER_MARK and CT actions do not
4052 : : * remove completion after WQE post.
4053 : : * That implementation avoids HW timeout.
4054 : : * The completion is removed before the following WQE post.
4055 : : * However, HWS queue updates do not reflect that behaviour.
4056 : : * Therefore, during port destruction sync queue may have
4057 : : * pending completions.
4058 : : */
4059 : 0 : pending_rules -= RTE_MIN(pending_rules, (uint32_t)ret);
4060 : : empty_loop = 0;
4061 : : }
4062 : : return 0;
4063 : : }
4064 : :
4065 : : /**
4066 : : * Flush created flows.
4067 : : *
4068 : : * @param[in] dev
4069 : : * Pointer to the rte_eth_dev structure.
4070 : : * @param[out] error
4071 : : * Pointer to error structure.
4072 : : *
4073 : : * @return
4074 : : * 0 on success, negative value otherwise and rte_errno is set.
4075 : : */
4076 : : int
4077 : 0 : flow_hw_q_flow_flush(struct rte_eth_dev *dev,
4078 : : struct rte_flow_error *error)
4079 : : {
4080 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4081 : 0 : struct mlx5_hw_q *hw_q = &priv->hw_q[MLX5_DEFAULT_FLUSH_QUEUE];
4082 : : struct rte_flow_template_table *tbl;
4083 : : struct rte_flow_hw *flow;
4084 : 0 : struct rte_flow_op_attr attr = {
4085 : : .postpone = 0,
4086 : : };
4087 : : uint32_t pending_rules = 0;
4088 : : uint32_t queue;
4089 : : uint32_t fidx;
4090 : :
4091 : : /*
4092 : : * Ensure to push and dequeue all the enqueued flow
4093 : : * creation/destruction jobs in case user forgot to
4094 : : * dequeue. Or the enqueued created flows will be
4095 : : * leaked. The forgotten dequeues would also cause
4096 : : * flow flush get extra CQEs as expected and pending_rules
4097 : : * be minus value.
4098 : : */
4099 [ # # ]: 0 : for (queue = 0; queue < priv->nb_queue; queue++) {
4100 [ # # ]: 0 : if (__flow_hw_pull_comp(dev, queue, error))
4101 : : return -1;
4102 : : }
4103 : : /* Flush flow per-table from MLX5_DEFAULT_FLUSH_QUEUE. */
4104 [ # # ]: 0 : LIST_FOREACH(tbl, &priv->flow_hw_tbl, next) {
4105 [ # # ]: 0 : if (!tbl->cfg.external)
4106 : 0 : continue;
4107 [ # # ]: 0 : MLX5_IPOOL_FOREACH(tbl->flow, fidx, flow) {
4108 [ # # ]: 0 : if (flow_hw_async_flow_destroy(dev,
4109 : : MLX5_DEFAULT_FLUSH_QUEUE,
4110 : : &attr,
4111 : : (struct rte_flow *)flow,
4112 : : NULL,
4113 : : error))
4114 : : return -1;
4115 : 0 : pending_rules++;
4116 : : /* Drain completion with queue size. */
4117 [ # # ]: 0 : if (pending_rules >= hw_q->size) {
4118 [ # # ]: 0 : if (__flow_hw_pull_comp(dev,
4119 : : MLX5_DEFAULT_FLUSH_QUEUE,
4120 : : error))
4121 : : return -1;
4122 : : pending_rules = 0;
4123 : : }
4124 : : }
4125 : : }
4126 : : /* Drain left completion. */
4127 [ # # # # ]: 0 : if (pending_rules &&
4128 : 0 : __flow_hw_pull_comp(dev, MLX5_DEFAULT_FLUSH_QUEUE, error))
4129 : 0 : return -1;
4130 : : return 0;
4131 : : }
4132 : :
4133 : : static int
4134 : 0 : mlx5_tbl_multi_pattern_process(struct rte_eth_dev *dev,
4135 : : struct rte_flow_template_table *tbl,
4136 : : struct mlx5_tbl_multi_pattern_ctx *mpat,
4137 : : struct rte_flow_error *error)
4138 : : {
4139 : : uint32_t i;
4140 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
4141 : : const struct rte_flow_template_table_attr *table_attr = &tbl->cfg.attr;
4142 : : const struct rte_flow_attr *attr = &table_attr->flow_attr;
4143 : : enum mlx5dr_table_type type = get_mlx5dr_table_type(attr);
4144 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][type];
4145 : : struct mlx5dr_action *dr_action;
4146 [ # # ]: 0 : uint32_t bulk_size = rte_log2_u32(table_attr->nb_flows);
4147 : :
4148 [ # # ]: 0 : for (i = 0; i < MLX5_MULTIPATTERN_ENCAP_NUM; i++) {
4149 : : uint32_t j;
4150 : : uint32_t *reformat_refcnt;
4151 : 0 : typeof(mpat->reformat[0]) *reformat = mpat->reformat + i;
4152 : : struct mlx5dr_action_reformat_header hdr[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
4153 : : enum mlx5dr_action_type reformat_type =
4154 : : mlx5_multi_pattern_reformat_index_to_type(i);
4155 : :
4156 [ # # ]: 0 : if (!reformat->elements_num)
4157 : 0 : continue;
4158 [ # # ]: 0 : for (j = 0; j < reformat->elements_num; j++)
4159 : 0 : hdr[j] = reformat->ctx[j].reformat_hdr;
4160 : 0 : reformat_refcnt = mlx5_malloc(MLX5_MEM_ZERO, sizeof(uint32_t), 0,
4161 : 0 : rte_socket_id());
4162 [ # # ]: 0 : if (!reformat_refcnt)
4163 : 0 : return rte_flow_error_set(error, ENOMEM,
4164 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4165 : : NULL, "failed to allocate multi-pattern encap counter");
4166 : 0 : *reformat_refcnt = reformat->elements_num;
4167 : 0 : dr_action = mlx5dr_action_create_reformat
4168 : : (priv->dr_ctx, reformat_type, reformat->elements_num, hdr,
4169 : : bulk_size, flags);
4170 [ # # ]: 0 : if (!dr_action) {
4171 : 0 : mlx5_free(reformat_refcnt);
4172 : 0 : return rte_flow_error_set(error, rte_errno,
4173 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4174 : : NULL,
4175 : : "failed to create multi-pattern encap action");
4176 : : }
4177 [ # # ]: 0 : for (j = 0; j < reformat->elements_num; j++) {
4178 : 0 : reformat->ctx[j].rule_action->action = dr_action;
4179 : 0 : reformat->ctx[j].encap->action = dr_action;
4180 : 0 : reformat->ctx[j].encap->multi_pattern = 1;
4181 : 0 : reformat->ctx[j].encap->multi_pattern_refcnt = reformat_refcnt;
4182 : : }
4183 : : }
4184 [ # # ]: 0 : if (mpat->mh.elements_num) {
4185 : : typeof(mpat->mh) *mh = &mpat->mh;
4186 : : struct mlx5dr_action_mh_pattern pattern[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
4187 : 0 : uint32_t *mh_refcnt = mlx5_malloc(MLX5_MEM_ZERO, sizeof(uint32_t),
4188 : 0 : 0, rte_socket_id());
4189 : :
4190 [ # # ]: 0 : if (!mh_refcnt)
4191 : 0 : return rte_flow_error_set(error, ENOMEM,
4192 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4193 : : NULL, "failed to allocate modify header counter");
4194 : 0 : *mh_refcnt = mpat->mh.elements_num;
4195 [ # # ]: 0 : for (i = 0; i < mpat->mh.elements_num; i++)
4196 : 0 : pattern[i] = mh->ctx[i].mh_pattern;
4197 : 0 : dr_action = mlx5dr_action_create_modify_header
4198 : : (priv->dr_ctx, mpat->mh.elements_num, pattern,
4199 : : bulk_size, flags);
4200 [ # # ]: 0 : if (!dr_action) {
4201 : 0 : mlx5_free(mh_refcnt);
4202 : 0 : return rte_flow_error_set(error, rte_errno,
4203 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4204 : : NULL,
4205 : : "failed to create multi-pattern header modify action");
4206 : : }
4207 [ # # ]: 0 : for (i = 0; i < mpat->mh.elements_num; i++) {
4208 : 0 : mh->ctx[i].rule_action->action = dr_action;
4209 : 0 : mh->ctx[i].mhdr->action = dr_action;
4210 : 0 : mh->ctx[i].mhdr->multi_pattern = 1;
4211 : 0 : mh->ctx[i].mhdr->multi_pattern_refcnt = mh_refcnt;
4212 : : }
4213 : : }
4214 : :
4215 : : return 0;
4216 : : }
4217 : :
4218 : : static int
4219 : 0 : mlx5_hw_build_template_table(struct rte_eth_dev *dev,
4220 : : uint8_t nb_action_templates,
4221 : : struct rte_flow_actions_template *action_templates[],
4222 : : struct mlx5dr_action_template *at[],
4223 : : struct rte_flow_template_table *tbl,
4224 : : struct rte_flow_error *error)
4225 : : {
4226 : : int ret;
4227 : : uint8_t i;
4228 : 0 : struct mlx5_tbl_multi_pattern_ctx mpat = MLX5_EMPTY_MULTI_PATTERN_CTX;
4229 : :
4230 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
4231 : 0 : uint32_t refcnt = __atomic_add_fetch(&action_templates[i]->refcnt, 1,
4232 : : __ATOMIC_RELAXED);
4233 : :
4234 [ # # ]: 0 : if (refcnt <= 1) {
4235 : 0 : rte_flow_error_set(error, EINVAL,
4236 : : RTE_FLOW_ERROR_TYPE_ACTION,
4237 : : &action_templates[i], "invalid AT refcount");
4238 : 0 : goto at_error;
4239 : : }
4240 : 0 : at[i] = action_templates[i]->tmpl;
4241 : 0 : tbl->ats[i].action_template = action_templates[i];
4242 : 0 : LIST_INIT(&tbl->ats[i].acts.act_list);
4243 : : /* do NOT translate table action if `dev` was not started */
4244 [ # # ]: 0 : if (!dev->data->dev_started)
4245 : 0 : continue;
4246 : 0 : ret = __flow_hw_actions_translate(dev, &tbl->cfg,
4247 : : &tbl->ats[i].acts,
4248 : : action_templates[i],
4249 : : &mpat, error);
4250 [ # # ]: 0 : if (ret) {
4251 : 0 : i++;
4252 : 0 : goto at_error;
4253 : : }
4254 : : }
4255 : 0 : tbl->nb_action_templates = nb_action_templates;
4256 : 0 : ret = mlx5_tbl_multi_pattern_process(dev, tbl, &mpat, error);
4257 [ # # ]: 0 : if (ret)
4258 : 0 : goto at_error;
4259 : : return 0;
4260 : :
4261 : : at_error:
4262 [ # # ]: 0 : while (i--) {
4263 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
4264 : 0 : __atomic_sub_fetch(&action_templates[i]->refcnt,
4265 : : 1, __ATOMIC_RELAXED);
4266 : : }
4267 : 0 : return rte_errno;
4268 : : }
4269 : :
4270 : : /**
4271 : : * Create flow table.
4272 : : *
4273 : : * The input item and action templates will be binded to the table.
4274 : : * Flow memory will also be allocated. Matcher will be created based
4275 : : * on the item template. Action will be translated to the dedicated
4276 : : * DR action if possible.
4277 : : *
4278 : : * @param[in] dev
4279 : : * Pointer to the rte_eth_dev structure.
4280 : : * @param[in] table_cfg
4281 : : * Pointer to the table configuration.
4282 : : * @param[in] item_templates
4283 : : * Item template array to be binded to the table.
4284 : : * @param[in] nb_item_templates
4285 : : * Number of item template.
4286 : : * @param[in] action_templates
4287 : : * Action template array to be binded to the table.
4288 : : * @param[in] nb_action_templates
4289 : : * Number of action template.
4290 : : * @param[out] error
4291 : : * Pointer to error structure.
4292 : : *
4293 : : * @return
4294 : : * Table on success, NULL otherwise and rte_errno is set.
4295 : : */
4296 : : static struct rte_flow_template_table *
4297 : 0 : flow_hw_table_create(struct rte_eth_dev *dev,
4298 : : const struct mlx5_flow_template_table_cfg *table_cfg,
4299 : : struct rte_flow_pattern_template *item_templates[],
4300 : : uint8_t nb_item_templates,
4301 : : struct rte_flow_actions_template *action_templates[],
4302 : : uint8_t nb_action_templates,
4303 : : struct rte_flow_error *error)
4304 : : {
4305 : 0 : struct rte_flow_error sub_error = {
4306 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
4307 : : .cause = NULL,
4308 : : .message = NULL,
4309 : : };
4310 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4311 : 0 : struct mlx5dr_matcher_attr matcher_attr = {0};
4312 : : struct rte_flow_template_table *tbl = NULL;
4313 : : struct mlx5_flow_group *grp;
4314 : : struct mlx5dr_match_template *mt[MLX5_HW_TBL_MAX_ITEM_TEMPLATE];
4315 : : struct mlx5dr_action_template *at[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
4316 : : const struct rte_flow_template_table_attr *attr = &table_cfg->attr;
4317 : 0 : struct rte_flow_attr flow_attr = attr->flow_attr;
4318 : 0 : struct mlx5_flow_cb_ctx ctx = {
4319 : : .dev = dev,
4320 : : .error = &sub_error,
4321 : : .data = &flow_attr,
4322 : : };
4323 : 0 : struct mlx5_indexed_pool_config cfg = {
4324 : 0 : .size = sizeof(struct rte_flow_hw) + mlx5dr_rule_get_handle_size(),
4325 : : .trunk_size = 1 << 12,
4326 : : .per_core_cache = 1 << 13,
4327 : : .need_lock = 1,
4328 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
4329 : : .malloc = mlx5_malloc,
4330 : : .free = mlx5_free,
4331 : : .type = "mlx5_hw_table_flow",
4332 : : };
4333 : : struct mlx5_list_entry *ge;
4334 : : uint32_t i = 0, max_tpl = MLX5_HW_TBL_MAX_ITEM_TEMPLATE;
4335 [ # # ]: 0 : uint32_t nb_flows = rte_align32pow2(attr->nb_flows);
4336 : 0 : bool port_started = !!dev->data->dev_started;
4337 : : int err;
4338 : :
4339 : : /* HWS layer accepts only 1 item template with root table. */
4340 [ # # ]: 0 : if (!attr->flow_attr.group)
4341 : : max_tpl = 1;
4342 : 0 : cfg.max_idx = nb_flows;
4343 : : /* For table has very limited flows, disable cache. */
4344 [ # # ]: 0 : if (nb_flows < cfg.trunk_size) {
4345 : 0 : cfg.per_core_cache = 0;
4346 : 0 : cfg.trunk_size = nb_flows;
4347 [ # # ]: 0 : } else if (nb_flows <= MLX5_HW_IPOOL_SIZE_THRESHOLD) {
4348 : 0 : cfg.per_core_cache = MLX5_HW_IPOOL_CACHE_MIN;
4349 : : }
4350 : : /* Check if we requires too many templates. */
4351 [ # # # # ]: 0 : if (nb_item_templates > max_tpl ||
4352 : : nb_action_templates > MLX5_HW_TBL_MAX_ACTION_TEMPLATE) {
4353 : 0 : rte_errno = EINVAL;
4354 : 0 : goto error;
4355 : : }
4356 : : /* Allocate the table memory. */
4357 : 0 : tbl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*tbl), 0, rte_socket_id());
4358 [ # # ]: 0 : if (!tbl)
4359 : 0 : goto error;
4360 : 0 : tbl->cfg = *table_cfg;
4361 : : /* Allocate flow indexed pool. */
4362 : 0 : tbl->flow = mlx5_ipool_create(&cfg);
4363 [ # # ]: 0 : if (!tbl->flow)
4364 : 0 : goto error;
4365 : : /* Allocate rule indexed pool. */
4366 : 0 : cfg.size = 0;
4367 : 0 : cfg.type = "mlx5_hw_table_rule";
4368 : 0 : cfg.max_idx += priv->hw_q[0].size;
4369 : 0 : tbl->resource = mlx5_ipool_create(&cfg);
4370 [ # # ]: 0 : if (!tbl->resource)
4371 : 0 : goto error;
4372 : : /* Register the flow group. */
4373 : 0 : ge = mlx5_hlist_register(priv->sh->groups, attr->flow_attr.group, &ctx);
4374 [ # # ]: 0 : if (!ge)
4375 : 0 : goto error;
4376 : : grp = container_of(ge, struct mlx5_flow_group, entry);
4377 : 0 : tbl->grp = grp;
4378 : : /* Prepare matcher information. */
4379 : 0 : matcher_attr.optimize_flow_src = MLX5DR_MATCHER_FLOW_SRC_ANY;
4380 : 0 : matcher_attr.priority = attr->flow_attr.priority;
4381 : 0 : matcher_attr.optimize_using_rule_idx = true;
4382 : 0 : matcher_attr.mode = MLX5DR_MATCHER_RESOURCE_MODE_RULE;
4383 [ # # ]: 0 : matcher_attr.insert_mode = flow_hw_matcher_insert_mode_get(attr->insertion_type);
4384 [ # # ]: 0 : if (attr->hash_func == RTE_FLOW_TABLE_HASH_FUNC_CRC16) {
4385 : 0 : DRV_LOG(ERR, "16-bit checksum hash type is not supported");
4386 : 0 : rte_errno = ENOTSUP;
4387 : 0 : goto it_error;
4388 : : }
4389 [ # # ]: 0 : matcher_attr.distribute_mode = flow_hw_matcher_distribute_mode_get(attr->hash_func);
4390 : 0 : matcher_attr.rule.num_log = rte_log2_u32(nb_flows);
4391 : : /* Parse hints information. */
4392 [ # # ]: 0 : if (attr->specialize) {
4393 [ # # ]: 0 : if (attr->specialize == RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG)
4394 : 0 : matcher_attr.optimize_flow_src = MLX5DR_MATCHER_FLOW_SRC_WIRE;
4395 [ # # ]: 0 : else if (attr->specialize == RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG)
4396 : 0 : matcher_attr.optimize_flow_src = MLX5DR_MATCHER_FLOW_SRC_VPORT;
4397 : : else
4398 : 0 : DRV_LOG(INFO, "Unsupported hint value %x", attr->specialize);
4399 : : }
4400 : : /* Build the item template. */
4401 [ # # ]: 0 : for (i = 0; i < nb_item_templates; i++) {
4402 : : uint32_t ret;
4403 : :
4404 [ # # # # ]: 0 : if ((flow_attr.ingress && !item_templates[i]->attr.ingress) ||
4405 [ # # # # ]: 0 : (flow_attr.egress && !item_templates[i]->attr.egress) ||
4406 [ # # # # ]: 0 : (flow_attr.transfer && !item_templates[i]->attr.transfer)) {
4407 : 0 : DRV_LOG(ERR, "pattern template and template table attribute mismatch");
4408 : 0 : rte_errno = EINVAL;
4409 : 0 : goto it_error;
4410 : : }
4411 [ # # ]: 0 : if (item_templates[i]->item_flags & MLX5_FLOW_ITEM_COMPARE)
4412 : 0 : matcher_attr.mode = MLX5DR_MATCHER_RESOURCE_MODE_HTABLE;
4413 : 0 : ret = __atomic_fetch_add(&item_templates[i]->refcnt, 1,
4414 : : __ATOMIC_RELAXED) + 1;
4415 [ # # ]: 0 : if (ret <= 1) {
4416 : 0 : rte_errno = EINVAL;
4417 : 0 : goto it_error;
4418 : : }
4419 : 0 : mt[i] = item_templates[i]->mt;
4420 : 0 : tbl->its[i] = item_templates[i];
4421 : : }
4422 : 0 : tbl->nb_item_templates = nb_item_templates;
4423 : : /* Build the action template. */
4424 : 0 : err = mlx5_hw_build_template_table(dev, nb_action_templates,
4425 : : action_templates, at, tbl, &sub_error);
4426 [ # # ]: 0 : if (err) {
4427 : : i = nb_item_templates;
4428 : 0 : goto it_error;
4429 : : }
4430 : 0 : tbl->matcher = mlx5dr_matcher_create
4431 : 0 : (tbl->grp->tbl, mt, nb_item_templates, at, nb_action_templates, &matcher_attr);
4432 [ # # ]: 0 : if (!tbl->matcher)
4433 : 0 : goto at_error;
4434 [ # # ]: 0 : tbl->type = attr->flow_attr.transfer ? MLX5DR_TABLE_TYPE_FDB :
4435 : 0 : (attr->flow_attr.egress ? MLX5DR_TABLE_TYPE_NIC_TX :
4436 : : MLX5DR_TABLE_TYPE_NIC_RX);
4437 [ # # ]: 0 : if (port_started)
4438 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
4439 : : else
4440 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl_ongo, tbl, next);
4441 : : return tbl;
4442 : : at_error:
4443 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
4444 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
4445 : 0 : __atomic_fetch_sub(&action_templates[i]->refcnt,
4446 : : 1, __ATOMIC_RELAXED);
4447 : : }
4448 : : i = nb_item_templates;
4449 : : it_error:
4450 [ # # ]: 0 : while (i--)
4451 : 0 : __atomic_fetch_sub(&item_templates[i]->refcnt,
4452 : : 1, __ATOMIC_RELAXED);
4453 : 0 : error:
4454 : 0 : err = rte_errno;
4455 [ # # ]: 0 : if (tbl) {
4456 [ # # ]: 0 : if (tbl->grp)
4457 : 0 : mlx5_hlist_unregister(priv->sh->groups,
4458 : : &tbl->grp->entry);
4459 [ # # ]: 0 : if (tbl->resource)
4460 : 0 : mlx5_ipool_destroy(tbl->resource);
4461 [ # # ]: 0 : if (tbl->flow)
4462 : 0 : mlx5_ipool_destroy(tbl->flow);
4463 : 0 : mlx5_free(tbl);
4464 : : }
4465 [ # # ]: 0 : if (error != NULL) {
4466 [ # # ]: 0 : if (sub_error.type == RTE_FLOW_ERROR_TYPE_NONE)
4467 : 0 : rte_flow_error_set(error, err, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4468 : : "Failed to create template table");
4469 : : else
4470 : : rte_memcpy(error, &sub_error, sizeof(sub_error));
4471 : : }
4472 : : return NULL;
4473 : : }
4474 : :
4475 : : /**
4476 : : * Update flow template table.
4477 : : *
4478 : : * @param[in] dev
4479 : : * Pointer to the rte_eth_dev structure.
4480 : : * @param[out] error
4481 : : * Pointer to error structure.
4482 : : *
4483 : : * @return
4484 : : * 0 on success, negative value otherwise and rte_errno is set.
4485 : : */
4486 : : int
4487 : 0 : flow_hw_table_update(struct rte_eth_dev *dev,
4488 : : struct rte_flow_error *error)
4489 : : {
4490 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4491 : : struct rte_flow_template_table *tbl;
4492 : :
4493 [ # # ]: 0 : while ((tbl = LIST_FIRST(&priv->flow_hw_tbl_ongo)) != NULL) {
4494 [ # # ]: 0 : if (flow_hw_actions_translate(dev, tbl, error))
4495 : : return -1;
4496 [ # # ]: 0 : LIST_REMOVE(tbl, next);
4497 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
4498 : : }
4499 : : return 0;
4500 : : }
4501 : :
4502 : : /**
4503 : : * Translates group index specified by the user in @p attr to internal
4504 : : * group index.
4505 : : *
4506 : : * Translation is done by incrementing group index, so group n becomes n + 1.
4507 : : *
4508 : : * @param[in] dev
4509 : : * Pointer to Ethernet device.
4510 : : * @param[in] cfg
4511 : : * Pointer to the template table configuration.
4512 : : * @param[in] group
4513 : : * Currently used group index (table group or jump destination).
4514 : : * @param[out] table_group
4515 : : * Pointer to output group index.
4516 : : * @param[out] error
4517 : : * Pointer to error structure.
4518 : : *
4519 : : * @return
4520 : : * 0 on success. Otherwise, returns negative error code, rte_errno is set
4521 : : * and error structure is filled.
4522 : : */
4523 : : static int
4524 : 0 : flow_hw_translate_group(struct rte_eth_dev *dev,
4525 : : const struct mlx5_flow_template_table_cfg *cfg,
4526 : : uint32_t group,
4527 : : uint32_t *table_group,
4528 : : struct rte_flow_error *error)
4529 : : {
4530 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4531 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
4532 : : const struct rte_flow_attr *flow_attr = &cfg->attr.flow_attr;
4533 : :
4534 [ # # ]: 0 : if (config->dv_esw_en &&
4535 [ # # ]: 0 : priv->fdb_def_rule &&
4536 [ # # # # ]: 0 : cfg->external &&
4537 : : flow_attr->transfer) {
4538 [ # # ]: 0 : if (group > MLX5_HW_MAX_TRANSFER_GROUP)
4539 : 0 : return rte_flow_error_set(error, EINVAL,
4540 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4541 : : NULL,
4542 : : "group index not supported");
4543 : 0 : *table_group = group + 1;
4544 [ # # ]: 0 : } else if (config->dv_esw_en &&
4545 [ # # # # ]: 0 : (config->repr_matching || config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) &&
4546 [ # # # # ]: 0 : cfg->external &&
4547 : : flow_attr->egress) {
4548 : : /*
4549 : : * On E-Switch setups, default egress flow rules are inserted to allow
4550 : : * representor matching and/or preserving metadata across steering domains.
4551 : : * These flow rules are inserted in group 0 and this group is reserved by PMD
4552 : : * for these purposes.
4553 : : *
4554 : : * As a result, if representor matching or extended metadata mode is enabled,
4555 : : * group provided by the user must be incremented to avoid inserting flow rules
4556 : : * in group 0.
4557 : : */
4558 [ # # ]: 0 : if (group > MLX5_HW_MAX_EGRESS_GROUP)
4559 : 0 : return rte_flow_error_set(error, EINVAL,
4560 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4561 : : NULL,
4562 : : "group index not supported");
4563 : 0 : *table_group = group + 1;
4564 : : } else {
4565 : 0 : *table_group = group;
4566 : : }
4567 : : return 0;
4568 : : }
4569 : :
4570 : : /**
4571 : : * Create flow table.
4572 : : *
4573 : : * This function is a wrapper over @ref flow_hw_table_create(), which translates parameters
4574 : : * provided by user to proper internal values.
4575 : : *
4576 : : * @param[in] dev
4577 : : * Pointer to Ethernet device.
4578 : : * @param[in] attr
4579 : : * Pointer to the table attributes.
4580 : : * @param[in] item_templates
4581 : : * Item template array to be binded to the table.
4582 : : * @param[in] nb_item_templates
4583 : : * Number of item templates.
4584 : : * @param[in] action_templates
4585 : : * Action template array to be binded to the table.
4586 : : * @param[in] nb_action_templates
4587 : : * Number of action templates.
4588 : : * @param[out] error
4589 : : * Pointer to error structure.
4590 : : *
4591 : : * @return
4592 : : * Table on success, Otherwise, returns negative error code, rte_errno is set
4593 : : * and error structure is filled.
4594 : : */
4595 : : static struct rte_flow_template_table *
4596 : 0 : flow_hw_template_table_create(struct rte_eth_dev *dev,
4597 : : const struct rte_flow_template_table_attr *attr,
4598 : : struct rte_flow_pattern_template *item_templates[],
4599 : : uint8_t nb_item_templates,
4600 : : struct rte_flow_actions_template *action_templates[],
4601 : : uint8_t nb_action_templates,
4602 : : struct rte_flow_error *error)
4603 : : {
4604 : 0 : struct mlx5_flow_template_table_cfg cfg = {
4605 : : .attr = *attr,
4606 : : .external = true,
4607 : : };
4608 : 0 : uint32_t group = attr->flow_attr.group;
4609 : :
4610 [ # # ]: 0 : if (flow_hw_translate_group(dev, &cfg, group, &cfg.attr.flow_attr.group, error))
4611 : : return NULL;
4612 : 0 : return flow_hw_table_create(dev, &cfg, item_templates, nb_item_templates,
4613 : : action_templates, nb_action_templates, error);
4614 : : }
4615 : :
4616 : : /**
4617 : : * Destroy flow table.
4618 : : *
4619 : : * @param[in] dev
4620 : : * Pointer to the rte_eth_dev structure.
4621 : : * @param[in] table
4622 : : * Pointer to the table to be destroyed.
4623 : : * @param[out] error
4624 : : * Pointer to error structure.
4625 : : *
4626 : : * @return
4627 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4628 : : */
4629 : : static int
4630 : 0 : flow_hw_table_destroy(struct rte_eth_dev *dev,
4631 : : struct rte_flow_template_table *table,
4632 : : struct rte_flow_error *error)
4633 : : {
4634 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4635 : : int i;
4636 : 0 : uint32_t fidx = 1;
4637 : 0 : uint32_t ridx = 1;
4638 : :
4639 : : /* Build ipool allocated object bitmap. */
4640 : 0 : mlx5_ipool_flush_cache(table->resource);
4641 : 0 : mlx5_ipool_flush_cache(table->flow);
4642 : : /* Check if ipool has allocated objects. */
4643 [ # # # # ]: 0 : if (table->refcnt ||
4644 [ # # ]: 0 : mlx5_ipool_get_next(table->flow, &fidx) ||
4645 : 0 : mlx5_ipool_get_next(table->resource, &ridx)) {
4646 : 0 : DRV_LOG(WARNING, "Table %p is still in use.", (void *)table);
4647 : 0 : return rte_flow_error_set(error, EBUSY,
4648 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4649 : : NULL,
4650 : : "table in use");
4651 : : }
4652 [ # # ]: 0 : LIST_REMOVE(table, next);
4653 [ # # ]: 0 : for (i = 0; i < table->nb_item_templates; i++)
4654 : 0 : __atomic_fetch_sub(&table->its[i]->refcnt,
4655 : : 1, __ATOMIC_RELAXED);
4656 [ # # ]: 0 : for (i = 0; i < table->nb_action_templates; i++) {
4657 : 0 : __flow_hw_action_template_destroy(dev, &table->ats[i].acts);
4658 : 0 : __atomic_fetch_sub(&table->ats[i].action_template->refcnt,
4659 : : 1, __ATOMIC_RELAXED);
4660 : : }
4661 : 0 : mlx5dr_matcher_destroy(table->matcher);
4662 : 0 : mlx5_hlist_unregister(priv->sh->groups, &table->grp->entry);
4663 : 0 : mlx5_ipool_destroy(table->resource);
4664 : 0 : mlx5_ipool_destroy(table->flow);
4665 : 0 : mlx5_free(table);
4666 : 0 : return 0;
4667 : : }
4668 : :
4669 : : /**
4670 : : * Parse group's miss actions.
4671 : : *
4672 : : * @param[in] dev
4673 : : * Pointer to the rte_eth_dev structure.
4674 : : * @param[in] cfg
4675 : : * Pointer to the table_cfg structure.
4676 : : * @param[in] actions
4677 : : * Array of actions to perform on group miss. Supported types:
4678 : : * RTE_FLOW_ACTION_TYPE_JUMP, RTE_FLOW_ACTION_TYPE_VOID, RTE_FLOW_ACTION_TYPE_END.
4679 : : * @param[out] dst_group_id
4680 : : * Pointer to destination group id output. will be set to 0 if actions is END,
4681 : : * otherwise will be set to destination group id.
4682 : : * @param[out] error
4683 : : * Pointer to error structure.
4684 : : *
4685 : : * @return
4686 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4687 : : */
4688 : :
4689 : : static int
4690 : 0 : flow_hw_group_parse_miss_actions(struct rte_eth_dev *dev,
4691 : : struct mlx5_flow_template_table_cfg *cfg,
4692 : : const struct rte_flow_action actions[],
4693 : : uint32_t *dst_group_id,
4694 : : struct rte_flow_error *error)
4695 : : {
4696 : : const struct rte_flow_action_jump *jump_conf;
4697 : 0 : uint32_t temp = 0;
4698 : : uint32_t i;
4699 : :
4700 [ # # ]: 0 : for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
4701 [ # # # ]: 0 : switch (actions[i].type) {
4702 : 0 : case RTE_FLOW_ACTION_TYPE_VOID:
4703 : 0 : continue;
4704 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
4705 [ # # ]: 0 : if (temp)
4706 : 0 : return rte_flow_error_set(error, ENOTSUP,
4707 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, actions,
4708 : : "Miss actions can contain only a single JUMP");
4709 : :
4710 : 0 : jump_conf = (const struct rte_flow_action_jump *)actions[i].conf;
4711 [ # # ]: 0 : if (!jump_conf)
4712 : 0 : return rte_flow_error_set(error, EINVAL,
4713 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4714 : : jump_conf, "Jump conf must not be NULL");
4715 : :
4716 [ # # ]: 0 : if (flow_hw_translate_group(dev, cfg, jump_conf->group, &temp, error))
4717 : 0 : return -rte_errno;
4718 : :
4719 [ # # ]: 0 : if (!temp)
4720 : 0 : return rte_flow_error_set(error, EINVAL,
4721 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4722 : : "Failed to set group miss actions - Invalid target group");
4723 : : break;
4724 : 0 : default:
4725 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
4726 : : &actions[i], "Unsupported default miss action type");
4727 : : }
4728 : : }
4729 : :
4730 : 0 : *dst_group_id = temp;
4731 : 0 : return 0;
4732 : : }
4733 : :
4734 : : /**
4735 : : * Set group's miss group.
4736 : : *
4737 : : * @param[in] dev
4738 : : * Pointer to the rte_eth_dev structure.
4739 : : * @param[in] cfg
4740 : : * Pointer to the table_cfg structure.
4741 : : * @param[in] src_grp
4742 : : * Pointer to source group structure.
4743 : : * if NULL, a new group will be created based on group id from cfg->attr.flow_attr.group.
4744 : : * @param[in] dst_grp
4745 : : * Pointer to destination group structure.
4746 : : * @param[out] error
4747 : : * Pointer to error structure.
4748 : : *
4749 : : * @return
4750 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4751 : : */
4752 : :
4753 : : static int
4754 : 0 : flow_hw_group_set_miss_group(struct rte_eth_dev *dev,
4755 : : struct mlx5_flow_template_table_cfg *cfg,
4756 : : struct mlx5_flow_group *src_grp,
4757 : : struct mlx5_flow_group *dst_grp,
4758 : : struct rte_flow_error *error)
4759 : : {
4760 : 0 : struct rte_flow_error sub_error = {
4761 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
4762 : : .cause = NULL,
4763 : : .message = NULL,
4764 : : };
4765 : 0 : struct mlx5_flow_cb_ctx ctx = {
4766 : : .dev = dev,
4767 : : .error = &sub_error,
4768 : 0 : .data = &cfg->attr.flow_attr,
4769 : : };
4770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4771 : : struct mlx5_list_entry *ge;
4772 : : bool ref = false;
4773 : : int ret;
4774 : :
4775 [ # # ]: 0 : if (!dst_grp)
4776 : : return -EINVAL;
4777 : :
4778 : : /* If group doesn't exist - needs to be created. */
4779 [ # # ]: 0 : if (!src_grp) {
4780 : 0 : ge = mlx5_hlist_register(priv->sh->groups, cfg->attr.flow_attr.group, &ctx);
4781 [ # # ]: 0 : if (!ge)
4782 : 0 : return -rte_errno;
4783 : :
4784 : : src_grp = container_of(ge, struct mlx5_flow_group, entry);
4785 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_grp, src_grp, next);
4786 : : ref = true;
4787 [ # # ]: 0 : } else if (!src_grp->miss_group) {
4788 : : /* If group exists, but has no miss actions - need to increase ref_cnt. */
4789 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_grp, src_grp, next);
4790 : 0 : src_grp->entry.ref_cnt++;
4791 : : ref = true;
4792 : : }
4793 : :
4794 : 0 : ret = mlx5dr_table_set_default_miss(src_grp->tbl, dst_grp->tbl);
4795 [ # # ]: 0 : if (ret)
4796 : 0 : goto mlx5dr_error;
4797 : :
4798 : : /* If group existed and had old miss actions - ref_cnt is already correct.
4799 : : * However, need to reduce ref counter for old miss group.
4800 : : */
4801 [ # # ]: 0 : if (src_grp->miss_group)
4802 : 0 : mlx5_hlist_unregister(priv->sh->groups, &src_grp->miss_group->entry);
4803 : :
4804 : 0 : src_grp->miss_group = dst_grp;
4805 : 0 : return 0;
4806 : :
4807 : : mlx5dr_error:
4808 : : /* Reduce src_grp ref_cnt back & remove from grp list in case of mlx5dr error */
4809 [ # # ]: 0 : if (ref) {
4810 : 0 : mlx5_hlist_unregister(priv->sh->groups, &src_grp->entry);
4811 [ # # ]: 0 : LIST_REMOVE(src_grp, next);
4812 : : }
4813 : :
4814 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4815 : : "Failed to set group miss actions");
4816 : : }
4817 : :
4818 : : /**
4819 : : * Unset group's miss group.
4820 : : *
4821 : : * @param[in] dev
4822 : : * Pointer to the rte_eth_dev structure.
4823 : : * @param[in] grp
4824 : : * Pointer to group structure.
4825 : : * @param[out] error
4826 : : * Pointer to error structure.
4827 : : *
4828 : : * @return
4829 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4830 : : */
4831 : :
4832 : : static int
4833 : 0 : flow_hw_group_unset_miss_group(struct rte_eth_dev *dev,
4834 : : struct mlx5_flow_group *grp,
4835 : : struct rte_flow_error *error)
4836 : : {
4837 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4838 : : int ret;
4839 : :
4840 : : /* If group doesn't exist - no need to change anything. */
4841 [ # # ]: 0 : if (!grp)
4842 : : return 0;
4843 : :
4844 : : /* If group exists, but miss actions is already default behavior -
4845 : : * no need to change anything.
4846 : : */
4847 [ # # ]: 0 : if (!grp->miss_group)
4848 : : return 0;
4849 : :
4850 : 0 : ret = mlx5dr_table_set_default_miss(grp->tbl, NULL);
4851 [ # # ]: 0 : if (ret)
4852 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4853 : : "Failed to unset group miss actions");
4854 : :
4855 : 0 : mlx5_hlist_unregister(priv->sh->groups, &grp->miss_group->entry);
4856 : 0 : grp->miss_group = NULL;
4857 : :
4858 [ # # ]: 0 : LIST_REMOVE(grp, next);
4859 : 0 : mlx5_hlist_unregister(priv->sh->groups, &grp->entry);
4860 : :
4861 : 0 : return 0;
4862 : : }
4863 : :
4864 : : /**
4865 : : * Set group miss actions.
4866 : : *
4867 : : * @param[in] dev
4868 : : * Pointer to the rte_eth_dev structure.
4869 : : * @param[in] group_id
4870 : : * Group id.
4871 : : * @param[in] attr
4872 : : * Pointer to group attributes structure.
4873 : : * @param[in] actions
4874 : : * Array of actions to perform on group miss. Supported types:
4875 : : * RTE_FLOW_ACTION_TYPE_JUMP, RTE_FLOW_ACTION_TYPE_VOID, RTE_FLOW_ACTION_TYPE_END.
4876 : : * @param[out] error
4877 : : * Pointer to error structure.
4878 : : *
4879 : : * @return
4880 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4881 : : */
4882 : :
4883 : : static int
4884 : 0 : flow_hw_group_set_miss_actions(struct rte_eth_dev *dev,
4885 : : uint32_t group_id,
4886 : : const struct rte_flow_group_attr *attr,
4887 : : const struct rte_flow_action actions[],
4888 : : struct rte_flow_error *error)
4889 : : {
4890 : 0 : struct rte_flow_error sub_error = {
4891 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
4892 : : .cause = NULL,
4893 : : .message = NULL,
4894 : : };
4895 : 0 : struct mlx5_flow_template_table_cfg cfg = {
4896 : : .external = true,
4897 : : .attr = {
4898 : : .flow_attr = {
4899 : : .group = group_id,
4900 : 0 : .ingress = attr->ingress,
4901 : 0 : .egress = attr->egress,
4902 : 0 : .transfer = attr->transfer,
4903 : : },
4904 : : },
4905 : : };
4906 : 0 : struct mlx5_flow_cb_ctx ctx = {
4907 : : .dev = dev,
4908 : : .error = &sub_error,
4909 : : .data = &cfg.attr.flow_attr,
4910 : : };
4911 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4912 : : struct mlx5_flow_group *src_grp = NULL;
4913 : : struct mlx5_flow_group *dst_grp = NULL;
4914 : : struct mlx5_list_entry *ge;
4915 : 0 : uint32_t dst_group_id = 0;
4916 : : int ret;
4917 : :
4918 [ # # ]: 0 : if (flow_hw_translate_group(dev, &cfg, group_id, &group_id, error))
4919 : 0 : return -rte_errno;
4920 : :
4921 [ # # ]: 0 : if (!group_id)
4922 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4923 : : NULL, "Failed to set group miss actions - invalid group id");
4924 : :
4925 : 0 : ret = flow_hw_group_parse_miss_actions(dev, &cfg, actions, &dst_group_id, error);
4926 [ # # ]: 0 : if (ret)
4927 : 0 : return -rte_errno;
4928 : :
4929 [ # # ]: 0 : if (dst_group_id == group_id) {
4930 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4931 : : NULL, "Failed to set group miss actions - target group id must differ from group_id");
4932 : : }
4933 : :
4934 : 0 : cfg.attr.flow_attr.group = group_id;
4935 : 0 : ge = mlx5_hlist_lookup(priv->sh->groups, group_id, &ctx);
4936 [ # # ]: 0 : if (ge)
4937 : : src_grp = container_of(ge, struct mlx5_flow_group, entry);
4938 : :
4939 [ # # ]: 0 : if (dst_group_id) {
4940 : : /* Increase ref_cnt for new miss group. */
4941 : 0 : cfg.attr.flow_attr.group = dst_group_id;
4942 : 0 : ge = mlx5_hlist_register(priv->sh->groups, dst_group_id, &ctx);
4943 [ # # ]: 0 : if (!ge)
4944 : 0 : return -rte_errno;
4945 : :
4946 : : dst_grp = container_of(ge, struct mlx5_flow_group, entry);
4947 : :
4948 : 0 : cfg.attr.flow_attr.group = group_id;
4949 : 0 : ret = flow_hw_group_set_miss_group(dev, &cfg, src_grp, dst_grp, error);
4950 [ # # ]: 0 : if (ret)
4951 : 0 : goto error;
4952 : : } else {
4953 : 0 : return flow_hw_group_unset_miss_group(dev, src_grp, error);
4954 : : }
4955 : :
4956 : : return 0;
4957 : :
4958 : : error:
4959 : : if (dst_grp)
4960 : 0 : mlx5_hlist_unregister(priv->sh->groups, &dst_grp->entry);
4961 : 0 : return -rte_errno;
4962 : : }
4963 : :
4964 : : static bool
4965 : : flow_hw_modify_field_is_used(const struct rte_flow_action_modify_field *action,
4966 : : enum rte_flow_field_id field)
4967 : : {
4968 [ # # # # : 0 : return action->src.field == field || action->dst.field == field;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
4969 : : }
4970 : :
4971 : : static bool
4972 : : flow_hw_modify_field_is_geneve_opt(enum rte_flow_field_id field)
4973 : : {
4974 : : return field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
4975 : 0 : field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
4976 : : field == RTE_FLOW_FIELD_GENEVE_OPT_DATA;
4977 : : }
4978 : :
4979 : : static bool
4980 : 0 : flow_hw_modify_field_is_add_dst_valid(const struct rte_flow_action_modify_field *conf)
4981 : : {
4982 [ # # ]: 0 : if (conf->operation != RTE_FLOW_MODIFY_ADD)
4983 : : return true;
4984 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
4985 : : conf->src.field == RTE_FLOW_FIELD_VALUE)
4986 : : return true;
4987 [ # # ]: 0 : switch (conf->dst.field) {
4988 : : case RTE_FLOW_FIELD_IPV4_TTL:
4989 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
4990 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
4991 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
4992 : : case RTE_FLOW_FIELD_TAG:
4993 : : case RTE_FLOW_FIELD_META:
4994 : : case RTE_FLOW_FIELD_FLEX_ITEM:
4995 : : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
4996 : : case RTE_FLOW_FIELD_IPV4_IHL:
4997 : : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
4998 : : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
4999 : : return true;
5000 : : default:
5001 : : break;
5002 : : }
5003 : 0 : return false;
5004 : : }
5005 : :
5006 : : static int
5007 : 0 : flow_hw_validate_action_modify_field(struct rte_eth_dev *dev,
5008 : : const struct rte_flow_action *action,
5009 : : const struct rte_flow_action *mask,
5010 : : struct rte_flow_error *error)
5011 : : {
5012 : 0 : const struct rte_flow_action_modify_field *action_conf = action->conf;
5013 : 0 : const struct rte_flow_action_modify_field *mask_conf = mask->conf;
5014 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5015 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
5016 : : int ret;
5017 : :
5018 [ # # ]: 0 : if (!mask_conf)
5019 : 0 : return rte_flow_error_set(error, EINVAL,
5020 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5021 : : "modify_field mask conf is missing");
5022 [ # # ]: 0 : if (action_conf->operation != mask_conf->operation)
5023 : 0 : return rte_flow_error_set(error, EINVAL,
5024 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5025 : : "modify_field operation mask and template are not equal");
5026 [ # # ]: 0 : if (action_conf->dst.field != mask_conf->dst.field)
5027 : 0 : return rte_flow_error_set(error, EINVAL,
5028 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5029 : : "destination field mask and template are not equal");
5030 : 0 : if (action_conf->dst.field == RTE_FLOW_FIELD_POINTER ||
5031 [ # # ]: 0 : action_conf->dst.field == RTE_FLOW_FIELD_VALUE ||
5032 : : action_conf->dst.field == RTE_FLOW_FIELD_HASH_RESULT)
5033 : 0 : return rte_flow_error_set(error, EINVAL,
5034 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5035 : : "immediate value, pointer and hash result cannot be used as destination");
5036 : 0 : ret = flow_validate_modify_field_level(&action_conf->dst, error);
5037 [ # # ]: 0 : if (ret)
5038 : : return ret;
5039 [ # # ]: 0 : if (!flow_hw_modify_field_is_geneve_opt(action_conf->dst.field)) {
5040 [ # # ]: 0 : if (action_conf->dst.tag_index &&
5041 : : !flow_modify_field_support_tag_array(action_conf->dst.field))
5042 : 0 : return rte_flow_error_set(error, EINVAL,
5043 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5044 : : "destination tag index is not supported");
5045 [ # # ]: 0 : if (action_conf->dst.class_id)
5046 : 0 : return rte_flow_error_set(error, EINVAL,
5047 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5048 : : "destination class id is not supported");
5049 : : }
5050 [ # # ]: 0 : if (mask_conf->dst.level != UINT8_MAX)
5051 : 0 : return rte_flow_error_set(error, EINVAL,
5052 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5053 : : "destination encapsulation level must be fully masked");
5054 [ # # ]: 0 : if (mask_conf->dst.offset != UINT32_MAX)
5055 : 0 : return rte_flow_error_set(error, EINVAL,
5056 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5057 : : "destination offset level must be fully masked");
5058 [ # # ]: 0 : if (action_conf->src.field != mask_conf->src.field)
5059 : 0 : return rte_flow_error_set(error, EINVAL,
5060 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5061 : : "destination field mask and template are not equal");
5062 [ # # ]: 0 : if (action_conf->src.field != RTE_FLOW_FIELD_POINTER &&
5063 : : action_conf->src.field != RTE_FLOW_FIELD_VALUE) {
5064 [ # # ]: 0 : if (!flow_hw_modify_field_is_geneve_opt(action_conf->src.field)) {
5065 [ # # ]: 0 : if (action_conf->src.tag_index &&
5066 : : !flow_modify_field_support_tag_array(action_conf->src.field))
5067 : 0 : return rte_flow_error_set(error, EINVAL,
5068 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5069 : : "source tag index is not supported");
5070 [ # # ]: 0 : if (action_conf->src.class_id)
5071 : 0 : return rte_flow_error_set(error, EINVAL,
5072 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5073 : : "source class id is not supported");
5074 : : }
5075 [ # # ]: 0 : if (mask_conf->src.level != UINT8_MAX)
5076 : 0 : return rte_flow_error_set(error, EINVAL,
5077 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5078 : : "source encapsulation level must be fully masked");
5079 [ # # ]: 0 : if (mask_conf->src.offset != UINT32_MAX)
5080 : 0 : return rte_flow_error_set(error, EINVAL,
5081 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5082 : : "source offset level must be fully masked");
5083 : 0 : ret = flow_validate_modify_field_level(&action_conf->src, error);
5084 [ # # ]: 0 : if (ret)
5085 : : return ret;
5086 : : }
5087 [ # # ]: 0 : if ((action_conf->dst.field == RTE_FLOW_FIELD_TAG &&
5088 [ # # # # ]: 0 : action_conf->dst.tag_index >= MLX5_FLOW_HW_TAGS_MAX &&
5089 : 0 : action_conf->dst.tag_index != RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ||
5090 [ # # ]: 0 : (action_conf->src.field == RTE_FLOW_FIELD_TAG &&
5091 [ # # # # ]: 0 : action_conf->src.tag_index >= MLX5_FLOW_HW_TAGS_MAX &&
5092 : : action_conf->src.tag_index != RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX))
5093 : 0 : return rte_flow_error_set(error, EINVAL,
5094 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5095 : : "tag index is out of range");
5096 [ # # # # ]: 0 : if ((action_conf->dst.field == RTE_FLOW_FIELD_TAG &&
5097 [ # # # # ]: 0 : flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, action_conf->dst.tag_index) == REG_NON) ||
5098 [ # # ]: 0 : (action_conf->src.field == RTE_FLOW_FIELD_TAG &&
5099 [ # # ]: 0 : flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, action_conf->src.tag_index) == REG_NON))
5100 : 0 : return rte_flow_error_set(error, EINVAL,
5101 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5102 : : "tag index is out of range");
5103 [ # # ]: 0 : if (mask_conf->width != UINT32_MAX)
5104 : 0 : return rte_flow_error_set(error, EINVAL,
5105 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5106 : : "modify_field width field must be fully masked");
5107 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_START))
5108 : 0 : return rte_flow_error_set(error, EINVAL,
5109 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5110 : : "modifying arbitrary place in a packet is not supported");
5111 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_VLAN_TYPE))
5112 : 0 : return rte_flow_error_set(error, EINVAL,
5113 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5114 : : "modifying vlan_type is not supported");
5115 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_RANDOM))
5116 : 0 : return rte_flow_error_set(error, EINVAL,
5117 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5118 : : "modifying random value is not supported");
5119 : : /**
5120 : : * Geneve VNI modification is supported only when Geneve header is
5121 : : * parsed natively. When GENEVE options are supported, they both Geneve
5122 : : * and options headers are parsed as a flex parser.
5123 : : */
5124 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_VNI) &&
5125 [ # # ]: 0 : attr->geneve_tlv_opt)
5126 : 0 : return rte_flow_error_set(error, EINVAL,
5127 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5128 : : "modifying Geneve VNI is not supported when GENEVE opt is supported");
5129 [ # # # # ]: 0 : if (priv->tlv_options == NULL &&
5130 [ # # ]: 0 : (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_OPT_TYPE) ||
5131 [ # # ]: 0 : flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_OPT_CLASS) ||
5132 : : flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_OPT_DATA)))
5133 : 0 : return rte_flow_error_set(error, EINVAL,
5134 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5135 : : "modifying Geneve TLV option is supported only after parser configuration");
5136 : : /* Due to HW bug, tunnel MPLS header is read only. */
5137 [ # # ]: 0 : if (action_conf->dst.field == RTE_FLOW_FIELD_MPLS)
5138 : 0 : return rte_flow_error_set(error, EINVAL,
5139 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5140 : : "MPLS cannot be used as destination");
5141 : : /* ADD_FIELD is not supported for all the fields. */
5142 [ # # ]: 0 : if (!flow_hw_modify_field_is_add_dst_valid(action_conf))
5143 : 0 : return rte_flow_error_set(error, EINVAL,
5144 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5145 : : "invalid add_field destination");
5146 : : return 0;
5147 : : }
5148 : : static int
5149 : 0 : flow_hw_validate_action_port_representor(struct rte_eth_dev *dev __rte_unused,
5150 : : const struct rte_flow_actions_template_attr *attr,
5151 : : const struct rte_flow_action *action,
5152 : : const struct rte_flow_action *mask,
5153 : : struct rte_flow_error *error)
5154 : : {
5155 : : const struct rte_flow_action_ethdev *action_conf = NULL;
5156 : : const struct rte_flow_action_ethdev *mask_conf = NULL;
5157 : :
5158 : : /* If transfer is set, port has been validated as proxy port. */
5159 [ # # ]: 0 : if (!attr->transfer)
5160 : 0 : return rte_flow_error_set(error, EINVAL,
5161 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5162 : : "cannot use port_representor actions"
5163 : : " without an E-Switch");
5164 [ # # ]: 0 : if (!action || !mask)
5165 : 0 : return rte_flow_error_set(error, EINVAL,
5166 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5167 : : "actiona and mask configuration must be set");
5168 : 0 : action_conf = action->conf;
5169 : 0 : mask_conf = mask->conf;
5170 [ # # # # : 0 : if (!mask_conf || mask_conf->port_id != MLX5_REPRESENTED_PORT_ESW_MGR ||
# # ]
5171 [ # # ]: 0 : !action_conf || action_conf->port_id != MLX5_REPRESENTED_PORT_ESW_MGR)
5172 : 0 : return rte_flow_error_set(error, EINVAL,
5173 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5174 : : "only eswitch manager port 0xffff is"
5175 : : " supported");
5176 : : return 0;
5177 : : }
5178 : :
5179 : : static int
5180 : 0 : flow_hw_validate_action_represented_port(struct rte_eth_dev *dev,
5181 : : const struct rte_flow_action *action,
5182 : : const struct rte_flow_action *mask,
5183 : : struct rte_flow_error *error)
5184 : : {
5185 : 0 : const struct rte_flow_action_ethdev *action_conf = action->conf;
5186 : 0 : const struct rte_flow_action_ethdev *mask_conf = mask->conf;
5187 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5188 : :
5189 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
5190 : 0 : return rte_flow_error_set(error, EINVAL,
5191 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5192 : : "cannot use represented_port actions"
5193 : : " without an E-Switch");
5194 [ # # # # ]: 0 : if (mask_conf && mask_conf->port_id) {
5195 : : struct mlx5_priv *port_priv;
5196 : : struct mlx5_priv *dev_priv;
5197 : :
5198 [ # # ]: 0 : if (!action_conf)
5199 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
5200 : : action, "port index was not provided");
5201 : 0 : port_priv = mlx5_port_to_eswitch_info(action_conf->port_id, false);
5202 [ # # ]: 0 : if (!port_priv)
5203 : 0 : return rte_flow_error_set(error, rte_errno,
5204 : : RTE_FLOW_ERROR_TYPE_ACTION,
5205 : : action,
5206 : : "failed to obtain E-Switch"
5207 : : " info for port");
5208 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5209 [ # # ]: 0 : if (!dev_priv)
5210 : 0 : return rte_flow_error_set(error, rte_errno,
5211 : : RTE_FLOW_ERROR_TYPE_ACTION,
5212 : : action,
5213 : : "failed to obtain E-Switch"
5214 : : " info for transfer proxy");
5215 [ # # ]: 0 : if (port_priv->domain_id != dev_priv->domain_id)
5216 : 0 : return rte_flow_error_set(error, rte_errno,
5217 : : RTE_FLOW_ERROR_TYPE_ACTION,
5218 : : action,
5219 : : "cannot forward to port from"
5220 : : " a different E-Switch");
5221 : : }
5222 : : return 0;
5223 : : }
5224 : :
5225 : : /**
5226 : : * Validate AGE action.
5227 : : *
5228 : : * @param[in] dev
5229 : : * Pointer to rte_eth_dev structure.
5230 : : * @param[in] action
5231 : : * Pointer to the indirect action.
5232 : : * @param[in] action_flags
5233 : : * Holds the actions detected until now.
5234 : : * @param[in] fixed_cnt
5235 : : * Indicator if this list has a fixed COUNT action.
5236 : : * @param[out] error
5237 : : * Pointer to error structure.
5238 : : *
5239 : : * @return
5240 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5241 : : */
5242 : : static int
5243 : 0 : flow_hw_validate_action_age(struct rte_eth_dev *dev,
5244 : : const struct rte_flow_action *action,
5245 : : uint64_t action_flags, bool fixed_cnt,
5246 : : struct rte_flow_error *error)
5247 : : {
5248 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5249 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
5250 : :
5251 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
5252 : 0 : return rte_flow_error_set(error, ENOTSUP,
5253 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5254 : : NULL, "AGE action not supported");
5255 [ # # ]: 0 : if (age_info->ages_ipool == NULL)
5256 : 0 : return rte_flow_error_set(error, EINVAL,
5257 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5258 : : "aging pool not initialized");
5259 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_AGE) ||
5260 : : (action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE))
5261 : 0 : return rte_flow_error_set(error, EINVAL,
5262 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5263 : : "duplicate AGE actions set");
5264 [ # # ]: 0 : if (fixed_cnt)
5265 : 0 : return rte_flow_error_set(error, EINVAL,
5266 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5267 : : "AGE and fixed COUNT combination is not supported");
5268 : : return 0;
5269 : : }
5270 : :
5271 : : /**
5272 : : * Validate count action.
5273 : : *
5274 : : * @param[in] dev
5275 : : * Pointer to rte_eth_dev structure.
5276 : : * @param[in] action
5277 : : * Pointer to the indirect action.
5278 : : * @param[in] mask
5279 : : * Pointer to the indirect action mask.
5280 : : * @param[in] action_flags
5281 : : * Holds the actions detected until now.
5282 : : * @param[out] error
5283 : : * Pointer to error structure.
5284 : : *
5285 : : * @return
5286 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5287 : : */
5288 : : static int
5289 : 0 : flow_hw_validate_action_count(struct rte_eth_dev *dev,
5290 : : const struct rte_flow_action *action,
5291 : : const struct rte_flow_action *mask,
5292 : : uint64_t action_flags,
5293 : : struct rte_flow_error *error)
5294 : : {
5295 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5296 : 0 : const struct rte_flow_action_count *count = mask->conf;
5297 : :
5298 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
5299 : 0 : return rte_flow_error_set(error, ENOTSUP,
5300 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5301 : : "count action not supported");
5302 [ # # ]: 0 : if (!priv->hws_cpool)
5303 : 0 : return rte_flow_error_set(error, EINVAL,
5304 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5305 : : "counters pool not initialized");
5306 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_COUNT) ||
5307 : : (action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT))
5308 : 0 : return rte_flow_error_set(error, EINVAL,
5309 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5310 : : "duplicate count actions set");
5311 [ # # # # : 0 : if (count && count->id && (action_flags & MLX5_FLOW_ACTION_AGE))
# # ]
5312 : 0 : return rte_flow_error_set(error, EINVAL,
5313 : : RTE_FLOW_ERROR_TYPE_ACTION, mask,
5314 : : "AGE and COUNT action shared by mask combination is not supported");
5315 : : return 0;
5316 : : }
5317 : :
5318 : : /**
5319 : : * Validate meter_mark action.
5320 : : *
5321 : : * @param[in] dev
5322 : : * Pointer to rte_eth_dev structure.
5323 : : * @param[in] action
5324 : : * Pointer to the indirect action.
5325 : : * @param[out] error
5326 : : * Pointer to error structure.
5327 : : *
5328 : : * @return
5329 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5330 : : */
5331 : : static int
5332 : 0 : flow_hw_validate_action_meter_mark(struct rte_eth_dev *dev,
5333 : : const struct rte_flow_action *action,
5334 : : struct rte_flow_error *error)
5335 : : {
5336 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5337 : :
5338 : : RTE_SET_USED(action);
5339 : :
5340 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
5341 : 0 : return rte_flow_error_set(error, ENOTSUP,
5342 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5343 : : "meter_mark action not supported");
5344 [ # # ]: 0 : if (!priv->hws_mpool)
5345 : 0 : return rte_flow_error_set(error, EINVAL,
5346 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5347 : : "meter_mark pool not initialized");
5348 : : return 0;
5349 : : }
5350 : :
5351 : : /**
5352 : : * Validate indirect action.
5353 : : *
5354 : : * @param[in] dev
5355 : : * Pointer to rte_eth_dev structure.
5356 : : * @param[in] action
5357 : : * Pointer to the indirect action.
5358 : : * @param[in] mask
5359 : : * Pointer to the indirect action mask.
5360 : : * @param[in, out] action_flags
5361 : : * Holds the actions detected until now.
5362 : : * @param[in, out] fixed_cnt
5363 : : * Pointer to indicator if this list has a fixed COUNT action.
5364 : : * @param[out] error
5365 : : * Pointer to error structure.
5366 : : *
5367 : : * @return
5368 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5369 : : */
5370 : : static int
5371 : 0 : flow_hw_validate_action_indirect(struct rte_eth_dev *dev,
5372 : : const struct rte_flow_action *action,
5373 : : const struct rte_flow_action *mask,
5374 : : uint64_t *action_flags, bool *fixed_cnt,
5375 : : struct rte_flow_error *error)
5376 : : {
5377 : : uint32_t type;
5378 : : int ret;
5379 : :
5380 [ # # ]: 0 : if (!mask)
5381 : 0 : return rte_flow_error_set(error, EINVAL,
5382 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5383 : : "Unable to determine indirect action type without a mask specified");
5384 : 0 : type = mask->type;
5385 [ # # # # : 0 : switch (type) {
# # # ]
5386 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
5387 : 0 : ret = flow_hw_validate_action_meter_mark(dev, mask, error);
5388 [ # # ]: 0 : if (ret < 0)
5389 : : return ret;
5390 : 0 : *action_flags |= MLX5_FLOW_ACTION_METER;
5391 : 0 : break;
5392 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
5393 : : /* TODO: Validation logic (same as flow_hw_actions_validate) */
5394 : 0 : *action_flags |= MLX5_FLOW_ACTION_RSS;
5395 : 0 : break;
5396 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
5397 : : /* TODO: Validation logic (same as flow_hw_actions_validate) */
5398 : 0 : *action_flags |= MLX5_FLOW_ACTION_CT;
5399 : 0 : break;
5400 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5401 [ # # # # ]: 0 : if (action->conf && mask->conf) {
5402 [ # # ]: 0 : if ((*action_flags & MLX5_FLOW_ACTION_AGE) ||
5403 : : (*action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE))
5404 : : /*
5405 : : * AGE cannot use indirect counter which is
5406 : : * shared with enother flow rules.
5407 : : */
5408 : 0 : return rte_flow_error_set(error, EINVAL,
5409 : : RTE_FLOW_ERROR_TYPE_ACTION,
5410 : : NULL,
5411 : : "AGE and fixed COUNT combination is not supported");
5412 : 0 : *fixed_cnt = true;
5413 : : }
5414 : 0 : ret = flow_hw_validate_action_count(dev, action, mask,
5415 : : *action_flags, error);
5416 [ # # ]: 0 : if (ret < 0)
5417 : : return ret;
5418 : 0 : *action_flags |= MLX5_FLOW_ACTION_INDIRECT_COUNT;
5419 : 0 : break;
5420 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
5421 : 0 : ret = flow_hw_validate_action_age(dev, action, *action_flags,
5422 : 0 : *fixed_cnt, error);
5423 [ # # ]: 0 : if (ret < 0)
5424 : : return ret;
5425 : 0 : *action_flags |= MLX5_FLOW_ACTION_INDIRECT_AGE;
5426 : 0 : break;
5427 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
5428 : : /* TODO: add proper quota verification */
5429 : 0 : *action_flags |= MLX5_FLOW_ACTION_QUOTA;
5430 : 0 : break;
5431 : 0 : default:
5432 : 0 : DRV_LOG(WARNING, "Unsupported shared action type: %d", type);
5433 : 0 : return rte_flow_error_set(error, ENOTSUP,
5434 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, mask,
5435 : : "Unsupported indirect action type");
5436 : : }
5437 : : return 0;
5438 : : }
5439 : :
5440 : : /**
5441 : : * Validate ipv6_ext_push action.
5442 : : *
5443 : : * @param[in] dev
5444 : : * Pointer to rte_eth_dev structure.
5445 : : * @param[in] action
5446 : : * Pointer to the indirect action.
5447 : : * @param[out] error
5448 : : * Pointer to error structure.
5449 : : *
5450 : : * @return
5451 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5452 : : */
5453 : : static int
5454 : 0 : flow_hw_validate_action_ipv6_ext_push(struct rte_eth_dev *dev __rte_unused,
5455 : : const struct rte_flow_action *action,
5456 : : struct rte_flow_error *error)
5457 : : {
5458 : 0 : const struct rte_flow_action_ipv6_ext_push *raw_push_data = action->conf;
5459 : :
5460 [ # # # # : 0 : if (!raw_push_data || !raw_push_data->size || !raw_push_data->data)
# # ]
5461 : 0 : return rte_flow_error_set(error, EINVAL,
5462 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5463 : : "invalid ipv6_ext_push data");
5464 [ # # # # ]: 0 : if (raw_push_data->type != IPPROTO_ROUTING ||
5465 : : raw_push_data->size > MLX5_PUSH_MAX_LEN)
5466 : 0 : return rte_flow_error_set(error, EINVAL,
5467 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5468 : : "Unsupported ipv6_ext_push type or length");
5469 : : return 0;
5470 : : }
5471 : :
5472 : : /**
5473 : : * Validate raw_encap action.
5474 : : *
5475 : : * @param[in] dev
5476 : : * Pointer to rte_eth_dev structure.
5477 : : * @param[in] action
5478 : : * Pointer to the indirect action.
5479 : : * @param[out] error
5480 : : * Pointer to error structure.
5481 : : *
5482 : : * @return
5483 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5484 : : */
5485 : : static int
5486 : 0 : flow_hw_validate_action_raw_encap(const struct rte_flow_action *action,
5487 : : const struct rte_flow_action *mask,
5488 : : struct rte_flow_error *error)
5489 : : {
5490 : 0 : const struct rte_flow_action_raw_encap *mask_conf = mask->conf;
5491 : 0 : const struct rte_flow_action_raw_encap *action_conf = action->conf;
5492 : :
5493 [ # # # # ]: 0 : if (!mask_conf || !mask_conf->size)
5494 : 0 : return rte_flow_error_set(error, EINVAL,
5495 : : RTE_FLOW_ERROR_TYPE_ACTION, mask,
5496 : : "raw_encap: size must be masked");
5497 [ # # # # ]: 0 : if (!action_conf || !action_conf->size)
5498 : 0 : return rte_flow_error_set(error, EINVAL,
5499 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5500 : : "raw_encap: invalid action configuration");
5501 [ # # # # ]: 0 : if (mask_conf->data && !action_conf->data)
5502 : 0 : return rte_flow_error_set(error, EINVAL,
5503 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5504 : : "raw_encap: masked data is missing");
5505 : : return 0;
5506 : : }
5507 : :
5508 : : /**
5509 : : * Process `... / raw_decap / raw_encap / ...` actions sequence.
5510 : : * The PMD handles the sequence as a single encap or decap reformat action,
5511 : : * depending on the raw_encap configuration.
5512 : : *
5513 : : * The function assumes that the raw_decap / raw_encap location
5514 : : * in actions template list complies with relative HWS actions order:
5515 : : * for the required reformat configuration:
5516 : : * ENCAP configuration must appear before [JUMP|DROP|PORT]
5517 : : * DECAP configuration must appear at the template head.
5518 : : */
5519 : : static uint64_t
5520 : : mlx5_decap_encap_reformat_type(const struct rte_flow_action *actions,
5521 : : uint32_t encap_ind, uint64_t flags)
5522 : : {
5523 : 0 : const struct rte_flow_action_raw_encap *encap = actions[encap_ind].conf;
5524 : :
5525 [ # # ]: 0 : if ((flags & MLX5_FLOW_ACTION_DECAP) == 0)
5526 : : return MLX5_FLOW_ACTION_ENCAP;
5527 [ # # ]: 0 : if (actions[encap_ind - 1].type != RTE_FLOW_ACTION_TYPE_RAW_DECAP)
5528 : : return MLX5_FLOW_ACTION_ENCAP;
5529 : 0 : return encap->size >= MLX5_ENCAPSULATION_DECISION_SIZE ?
5530 [ # # ]: 0 : MLX5_FLOW_ACTION_ENCAP : MLX5_FLOW_ACTION_DECAP;
5531 : : }
5532 : :
5533 : : static inline uint16_t
5534 : 0 : flow_hw_template_expand_modify_field(struct rte_flow_action actions[],
5535 : : struct rte_flow_action masks[],
5536 : : const struct rte_flow_action *mf_actions,
5537 : : const struct rte_flow_action *mf_masks,
5538 : : uint64_t flags, uint32_t act_num,
5539 : : uint32_t mf_num)
5540 : : {
5541 : : uint32_t i, tail;
5542 : :
5543 : : MLX5_ASSERT(actions && masks);
5544 : : MLX5_ASSERT(mf_num > 0);
5545 [ # # ]: 0 : if (flags & MLX5_FLOW_ACTION_MODIFY_FIELD) {
5546 : : /*
5547 : : * Application action template already has Modify Field.
5548 : : * It's location will be used in DR.
5549 : : * Expanded MF action can be added before the END.
5550 : : */
5551 : 0 : i = act_num - 1;
5552 : 0 : goto insert;
5553 : : }
5554 : : /**
5555 : : * Locate the first action positioned BEFORE the new MF.
5556 : : *
5557 : : * Search for a place to insert modify header
5558 : : * from the END action backwards:
5559 : : * 1. END is always present in actions array
5560 : : * 2. END location is always at action[act_num - 1]
5561 : : * 3. END always positioned AFTER modify field location
5562 : : *
5563 : : * Relative actions order is the same for RX, TX and FDB.
5564 : : *
5565 : : * Current actions order (draft-3)
5566 : : * @see action_order_arr[]
5567 : : */
5568 [ # # ]: 0 : for (i = act_num - 2; (int)i >= 0; i--) {
5569 : 0 : enum rte_flow_action_type type = actions[i].type;
5570 : : uint64_t reformat_type;
5571 : :
5572 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_INDIRECT)
5573 : 0 : type = masks[i].type;
5574 [ # # # ]: 0 : switch (type) {
5575 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5576 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5577 : : case RTE_FLOW_ACTION_TYPE_DROP:
5578 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
5579 : : case RTE_FLOW_ACTION_TYPE_JUMP:
5580 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
5581 : : case RTE_FLOW_ACTION_TYPE_RSS:
5582 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5583 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
5584 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5585 : : case RTE_FLOW_ACTION_TYPE_VOID:
5586 : : case RTE_FLOW_ACTION_TYPE_END:
5587 : : break;
5588 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5589 : : reformat_type =
5590 : : mlx5_decap_encap_reformat_type(actions, i,
5591 : : flags);
5592 : : if (reformat_type == MLX5_FLOW_ACTION_DECAP) {
5593 : 0 : i++;
5594 : 0 : goto insert;
5595 : : }
5596 [ # # ]: 0 : if (actions[i - 1].type == RTE_FLOW_ACTION_TYPE_RAW_DECAP)
5597 : : i--;
5598 : : break;
5599 : 0 : default:
5600 : 0 : i++; /* new MF inserted AFTER actions[i] */
5601 : 0 : goto insert;
5602 : : }
5603 : : }
5604 : : i = 0;
5605 : 0 : insert:
5606 : 0 : tail = act_num - i; /* num action to move */
5607 : 0 : memmove(actions + i + mf_num, actions + i, sizeof(actions[0]) * tail);
5608 : 0 : memcpy(actions + i, mf_actions, sizeof(actions[0]) * mf_num);
5609 : 0 : memmove(masks + i + mf_num, masks + i, sizeof(masks[0]) * tail);
5610 : : memcpy(masks + i, mf_masks, sizeof(masks[0]) * mf_num);
5611 : 0 : return i;
5612 : : }
5613 : :
5614 : : static int
5615 : 0 : flow_hw_validate_action_push_vlan(struct rte_eth_dev *dev,
5616 : : const
5617 : : struct rte_flow_actions_template_attr *attr,
5618 : : const struct rte_flow_action *action,
5619 : : const struct rte_flow_action *mask,
5620 : : struct rte_flow_error *error)
5621 : : {
5622 : : #define X_FIELD(ptr, t, f) (((ptr)->conf) && ((t *)((ptr)->conf))->f)
5623 : :
5624 : 0 : const bool masked_push =
5625 [ # # # # ]: 0 : X_FIELD(mask + MLX5_HW_VLAN_PUSH_TYPE_IDX,
5626 : : const struct rte_flow_action_of_push_vlan, ethertype);
5627 : : bool masked_param;
5628 : :
5629 : : /*
5630 : : * Mandatory actions order:
5631 : : * OF_PUSH_VLAN / OF_SET_VLAN_VID [ / OF_SET_VLAN_PCP ]
5632 : : */
5633 : : RTE_SET_USED(dev);
5634 : : RTE_SET_USED(attr);
5635 : : /* Check that mark matches OF_PUSH_VLAN */
5636 [ # # ]: 0 : if (mask[MLX5_HW_VLAN_PUSH_TYPE_IDX].type !=
5637 : : RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5638 : 0 : return rte_flow_error_set(error, EINVAL,
5639 : : RTE_FLOW_ERROR_TYPE_ACTION,
5640 : : action, "OF_PUSH_VLAN: mask does not match");
5641 : : /* Check that the second template and mask items are SET_VLAN_VID */
5642 [ # # ]: 0 : if (action[MLX5_HW_VLAN_PUSH_VID_IDX].type !=
5643 : 0 : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID ||
5644 [ # # ]: 0 : mask[MLX5_HW_VLAN_PUSH_VID_IDX].type !=
5645 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
5646 : 0 : return rte_flow_error_set(error, EINVAL,
5647 : : RTE_FLOW_ERROR_TYPE_ACTION,
5648 : : action, "OF_PUSH_VLAN: invalid actions order");
5649 [ # # # # ]: 0 : masked_param = X_FIELD(mask + MLX5_HW_VLAN_PUSH_VID_IDX,
5650 : : const struct rte_flow_action_of_set_vlan_vid,
5651 : : vlan_vid);
5652 : : /*
5653 : : * PMD requires OF_SET_VLAN_VID mask to must match OF_PUSH_VLAN
5654 : : */
5655 [ # # ]: 0 : if (masked_push ^ masked_param)
5656 : 0 : return rte_flow_error_set(error, EINVAL,
5657 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5658 : : "OF_SET_VLAN_VID: mask does not match OF_PUSH_VLAN");
5659 [ # # ]: 0 : if (is_of_vlan_pcp_present(action)) {
5660 [ # # ]: 0 : if (mask[MLX5_HW_VLAN_PUSH_PCP_IDX].type !=
5661 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)
5662 : 0 : return rte_flow_error_set(error, EINVAL,
5663 : : RTE_FLOW_ERROR_TYPE_ACTION,
5664 : : action, "OF_SET_VLAN_PCP: missing mask configuration");
5665 [ # # # # ]: 0 : masked_param = X_FIELD(mask + MLX5_HW_VLAN_PUSH_PCP_IDX,
5666 : : const struct
5667 : : rte_flow_action_of_set_vlan_pcp,
5668 : : vlan_pcp);
5669 : : /*
5670 : : * PMD requires OF_SET_VLAN_PCP mask to must match OF_PUSH_VLAN
5671 : : */
5672 [ # # ]: 0 : if (masked_push ^ masked_param)
5673 : 0 : return rte_flow_error_set(error, EINVAL,
5674 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5675 : : "OF_SET_VLAN_PCP: mask does not match OF_PUSH_VLAN");
5676 : : }
5677 : : return 0;
5678 : : #undef X_FIELD
5679 : : }
5680 : :
5681 : : static int
5682 : 0 : flow_hw_validate_action_default_miss(struct rte_eth_dev *dev,
5683 : : const struct rte_flow_actions_template_attr *attr,
5684 : : uint64_t action_flags,
5685 : : struct rte_flow_error *error)
5686 : : {
5687 : : /*
5688 : : * The private DEFAULT_MISS action is used internally for LACP in control
5689 : : * flows. So this validation can be ignored. It can be kept right now since
5690 : : * the validation will be done only once.
5691 : : */
5692 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5693 : :
5694 [ # # ]: 0 : if (!attr->ingress || attr->egress || attr->transfer)
5695 : 0 : return rte_flow_error_set(error, EINVAL,
5696 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5697 : : "DEFAULT MISS is only supported in ingress.");
5698 [ # # ]: 0 : if (!priv->hw_def_miss)
5699 : 0 : return rte_flow_error_set(error, EINVAL,
5700 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5701 : : "DEFAULT MISS action does not exist.");
5702 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
5703 : 0 : return rte_flow_error_set(error, EINVAL,
5704 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5705 : : "DEFAULT MISS should be the only termination.");
5706 : : return 0;
5707 : : }
5708 : :
5709 : : static int
5710 : 0 : mlx5_flow_hw_actions_validate(struct rte_eth_dev *dev,
5711 : : const struct rte_flow_actions_template_attr *attr,
5712 : : const struct rte_flow_action actions[],
5713 : : const struct rte_flow_action masks[],
5714 : : uint64_t *act_flags,
5715 : : struct rte_flow_error *error)
5716 : : {
5717 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5718 : : const struct rte_flow_action_count *count_mask = NULL;
5719 : 0 : bool fixed_cnt = false;
5720 : 0 : uint64_t action_flags = 0;
5721 : : bool actions_end = false;
5722 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
5723 : : int table_type;
5724 : : #endif
5725 : : uint16_t i;
5726 : : int ret;
5727 : : const struct rte_flow_action_ipv6_ext_remove *remove_data;
5728 : :
5729 : : /* FDB actions are only valid to proxy port. */
5730 [ # # # # : 0 : if (attr->transfer && (!priv->sh->config.dv_esw_en || !priv->master))
# # ]
5731 : 0 : return rte_flow_error_set(error, EINVAL,
5732 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5733 : : NULL,
5734 : : "transfer actions are only valid to proxy port");
5735 [ # # ]: 0 : for (i = 0; !actions_end; ++i) {
5736 : 0 : const struct rte_flow_action *action = &actions[i];
5737 : 0 : const struct rte_flow_action *mask = &masks[i];
5738 : :
5739 : : MLX5_ASSERT(i < MLX5_HW_MAX_ACTS);
5740 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_INDIRECT &&
5741 [ # # ]: 0 : action->type != mask->type)
5742 : 0 : return rte_flow_error_set(error, ENOTSUP,
5743 : : RTE_FLOW_ERROR_TYPE_ACTION,
5744 : : action,
5745 : : "mask type does not match action type");
5746 [ # # # # : 0 : switch ((int)action->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
5747 : : case RTE_FLOW_ACTION_TYPE_VOID:
5748 : : break;
5749 : : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
5750 : : break;
5751 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
5752 : 0 : ret = flow_hw_validate_action_indirect(dev, action,
5753 : : mask,
5754 : : &action_flags,
5755 : : &fixed_cnt,
5756 : : error);
5757 [ # # ]: 0 : if (ret < 0)
5758 : 0 : return ret;
5759 : : break;
5760 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
5761 : : /* TODO: Validation logic */
5762 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
5763 : 0 : break;
5764 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
5765 : : /* TODO: Validation logic */
5766 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
5767 : 0 : break;
5768 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
5769 : : /* TODO: Validation logic */
5770 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
5771 : 0 : break;
5772 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
5773 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
5774 : : if (priv->shared_host)
5775 : : return rte_flow_error_set(error, ENOTSUP,
5776 : : RTE_FLOW_ERROR_TYPE_ACTION,
5777 : : action,
5778 : : "action not supported in guest port");
5779 : : table_type = attr->ingress ? MLX5DR_TABLE_TYPE_NIC_RX :
5780 : : ((attr->egress) ? MLX5DR_TABLE_TYPE_NIC_TX :
5781 : : MLX5DR_TABLE_TYPE_FDB);
5782 : : if (!priv->hw_send_to_kernel[table_type])
5783 : : return rte_flow_error_set(error, ENOTSUP,
5784 : : RTE_FLOW_ERROR_TYPE_ACTION,
5785 : : action,
5786 : : "action is not available");
5787 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
5788 : : break;
5789 : : #endif
5790 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
5791 : : /* TODO: Validation logic */
5792 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
5793 : 0 : break;
5794 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
5795 : : /* TODO: Validation logic */
5796 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
5797 : 0 : break;
5798 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5799 : : /* TODO: Validation logic */
5800 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
5801 : 0 : break;
5802 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5803 : : /* TODO: Validation logic */
5804 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
5805 : 0 : break;
5806 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5807 : : /* TODO: Validation logic */
5808 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
5809 : 0 : break;
5810 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5811 : : /* TODO: Validation logic */
5812 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
5813 : 0 : break;
5814 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5815 : 0 : ret = flow_hw_validate_action_raw_encap(action, mask, error);
5816 [ # # ]: 0 : if (ret < 0)
5817 : 0 : return ret;
5818 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
5819 : 0 : break;
5820 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5821 : : /* TODO: Validation logic */
5822 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
5823 : 0 : break;
5824 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
5825 : 0 : ret = flow_hw_validate_action_ipv6_ext_push(dev, action, error);
5826 [ # # ]: 0 : if (ret < 0)
5827 : 0 : return ret;
5828 : 0 : action_flags |= MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH;
5829 : 0 : break;
5830 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE:
5831 : 0 : remove_data = action->conf;
5832 : : /* Remove action must be shared. */
5833 [ # # # # ]: 0 : if (remove_data->type != IPPROTO_ROUTING || !mask) {
5834 : 0 : DRV_LOG(ERR, "Only supports shared IPv6 routing remove");
5835 : 0 : return -EINVAL;
5836 : : }
5837 : 0 : action_flags |= MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE;
5838 : 0 : break;
5839 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
5840 : : /* TODO: Validation logic */
5841 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
5842 : 0 : break;
5843 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
5844 : 0 : ret = flow_hw_validate_action_meter_mark(dev, action,
5845 : : error);
5846 [ # # ]: 0 : if (ret < 0)
5847 : 0 : return ret;
5848 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
5849 : 0 : break;
5850 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5851 : 0 : ret = flow_hw_validate_action_modify_field(dev, action, mask,
5852 : : error);
5853 [ # # ]: 0 : if (ret < 0)
5854 : 0 : return ret;
5855 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
5856 : 0 : break;
5857 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5858 : 0 : ret = flow_hw_validate_action_represented_port
5859 : : (dev, action, mask, error);
5860 [ # # ]: 0 : if (ret < 0)
5861 : 0 : return ret;
5862 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5863 : 0 : break;
5864 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
5865 : 0 : ret = flow_hw_validate_action_port_representor
5866 : : (dev, attr, action, mask, error);
5867 [ # # ]: 0 : if (ret < 0)
5868 : 0 : return ret;
5869 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_REPRESENTOR;
5870 : 0 : break;
5871 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
5872 [ # # # # ]: 0 : if (count_mask && count_mask->id)
5873 : 0 : fixed_cnt = true;
5874 : 0 : ret = flow_hw_validate_action_age(dev, action,
5875 : : action_flags,
5876 : : fixed_cnt, error);
5877 [ # # ]: 0 : if (ret < 0)
5878 : 0 : return ret;
5879 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
5880 : 0 : break;
5881 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5882 : 0 : ret = flow_hw_validate_action_count(dev, action, mask,
5883 : : action_flags,
5884 : : error);
5885 [ # # ]: 0 : if (ret < 0)
5886 : 0 : return ret;
5887 : 0 : count_mask = mask->conf;
5888 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
5889 : 0 : break;
5890 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
5891 : : /* TODO: Validation logic */
5892 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
5893 : 0 : break;
5894 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5895 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5896 : 0 : break;
5897 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5898 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5899 : 0 : break;
5900 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5901 : 0 : ret = flow_hw_validate_action_push_vlan
5902 : : (dev, attr, action, mask, error);
5903 [ # # ]: 0 : if (ret != 0)
5904 : 0 : return ret;
5905 : 0 : i += is_of_vlan_pcp_present(action) ?
5906 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
5907 : : MLX5_HW_VLAN_PUSH_VID_IDX;
5908 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5909 : 0 : break;
5910 : 0 : case RTE_FLOW_ACTION_TYPE_END:
5911 : : actions_end = true;
5912 : 0 : break;
5913 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
5914 : 0 : ret = flow_hw_validate_action_default_miss(dev, attr,
5915 : : action_flags, error);
5916 [ # # ]: 0 : if (ret < 0)
5917 : 0 : return ret;
5918 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
5919 : 0 : break;
5920 : 0 : default:
5921 : 0 : return rte_flow_error_set(error, ENOTSUP,
5922 : : RTE_FLOW_ERROR_TYPE_ACTION,
5923 : : action,
5924 : : "action not supported in template API");
5925 : : }
5926 : : }
5927 [ # # ]: 0 : if (act_flags != NULL)
5928 : 0 : *act_flags = action_flags;
5929 : : return 0;
5930 : : }
5931 : :
5932 : : static int
5933 : 0 : flow_hw_actions_validate(struct rte_eth_dev *dev,
5934 : : const struct rte_flow_actions_template_attr *attr,
5935 : : const struct rte_flow_action actions[],
5936 : : const struct rte_flow_action masks[],
5937 : : struct rte_flow_error *error)
5938 : : {
5939 : 0 : return mlx5_flow_hw_actions_validate(dev, attr, actions, masks, NULL, error);
5940 : : }
5941 : :
5942 : :
5943 : : static enum mlx5dr_action_type mlx5_hw_dr_action_types[] = {
5944 : : [RTE_FLOW_ACTION_TYPE_MARK] = MLX5DR_ACTION_TYP_TAG,
5945 : : [RTE_FLOW_ACTION_TYPE_DROP] = MLX5DR_ACTION_TYP_DROP,
5946 : : [RTE_FLOW_ACTION_TYPE_JUMP] = MLX5DR_ACTION_TYP_TBL,
5947 : : [RTE_FLOW_ACTION_TYPE_QUEUE] = MLX5DR_ACTION_TYP_TIR,
5948 : : [RTE_FLOW_ACTION_TYPE_RSS] = MLX5DR_ACTION_TYP_TIR,
5949 : : [RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP] = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2,
5950 : : [RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP] = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2,
5951 : : [RTE_FLOW_ACTION_TYPE_VXLAN_DECAP] = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2,
5952 : : [RTE_FLOW_ACTION_TYPE_NVGRE_DECAP] = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2,
5953 : : [RTE_FLOW_ACTION_TYPE_MODIFY_FIELD] = MLX5DR_ACTION_TYP_MODIFY_HDR,
5954 : : [RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT] = MLX5DR_ACTION_TYP_VPORT,
5955 : : [RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR] = MLX5DR_ACTION_TYP_MISS,
5956 : : [RTE_FLOW_ACTION_TYPE_CONNTRACK] = MLX5DR_ACTION_TYP_ASO_CT,
5957 : : [RTE_FLOW_ACTION_TYPE_OF_POP_VLAN] = MLX5DR_ACTION_TYP_POP_VLAN,
5958 : : [RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN] = MLX5DR_ACTION_TYP_PUSH_VLAN,
5959 : : [RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL] = MLX5DR_ACTION_TYP_DEST_ROOT,
5960 : : [RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH] = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
5961 : : [RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE] = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
5962 : : };
5963 : :
5964 : : static inline void
5965 : : action_template_set_type(struct rte_flow_actions_template *at,
5966 : : enum mlx5dr_action_type *action_types,
5967 : : unsigned int action_src, uint16_t *curr_off,
5968 : : enum mlx5dr_action_type type)
5969 : : {
5970 : 0 : at->dr_off[action_src] = *curr_off;
5971 : 0 : action_types[*curr_off] = type;
5972 : 0 : *curr_off = *curr_off + 1;
5973 : 0 : }
5974 : :
5975 : : static int
5976 : 0 : flow_hw_dr_actions_template_handle_shared(int type, uint32_t action_src,
5977 : : enum mlx5dr_action_type *action_types,
5978 : : uint16_t *curr_off, uint16_t *cnt_off,
5979 : : struct rte_flow_actions_template *at)
5980 : : {
5981 [ # # # # : 0 : switch (type) {
# ]
5982 : : case RTE_FLOW_ACTION_TYPE_RSS:
5983 : : action_template_set_type(at, action_types, action_src, curr_off,
5984 : : MLX5DR_ACTION_TYP_TIR);
5985 : : break;
5986 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
5987 : : case RTE_FLOW_ACTION_TYPE_COUNT:
5988 : : /*
5989 : : * Both AGE and COUNT action need counter, the first one fills
5990 : : * the action_types array, and the second only saves the offset.
5991 : : */
5992 [ # # ]: 0 : if (*cnt_off == UINT16_MAX) {
5993 : 0 : *cnt_off = *curr_off;
5994 : : action_template_set_type(at, action_types,
5995 : : action_src, curr_off,
5996 : : MLX5DR_ACTION_TYP_CTR);
5997 : : }
5998 : 0 : at->dr_off[action_src] = *cnt_off;
5999 : 0 : break;
6000 : : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
6001 : : action_template_set_type(at, action_types, action_src, curr_off,
6002 : : MLX5DR_ACTION_TYP_ASO_CT);
6003 : : break;
6004 : : case RTE_FLOW_ACTION_TYPE_QUOTA:
6005 : : case RTE_FLOW_ACTION_TYPE_METER_MARK:
6006 : : action_template_set_type(at, action_types, action_src, curr_off,
6007 : : MLX5DR_ACTION_TYP_ASO_METER);
6008 : : break;
6009 : 0 : default:
6010 : 0 : DRV_LOG(WARNING, "Unsupported shared action type: %d", type);
6011 : 0 : return -EINVAL;
6012 : : }
6013 : : return 0;
6014 : : }
6015 : :
6016 : :
6017 : : static int
6018 : 0 : flow_hw_template_actions_list(struct rte_flow_actions_template *at,
6019 : : unsigned int action_src,
6020 : : enum mlx5dr_action_type *action_types,
6021 : : uint16_t *curr_off, uint16_t *cnt_off)
6022 : : {
6023 : : int ret;
6024 : 0 : const struct rte_flow_action_indirect_list *indlst_conf = at->actions[action_src].conf;
6025 [ # # # # ]: 0 : enum mlx5_indirect_list_type list_type = mlx5_get_indirect_list_type(indlst_conf->handle);
6026 : : const union {
6027 : : struct mlx5_indlst_legacy *legacy;
6028 : : struct rte_flow_action_list_handle *handle;
6029 : : } indlst_obj = { .handle = indlst_conf->handle };
6030 : : enum mlx5dr_action_type type;
6031 : :
6032 [ # # # # ]: 0 : switch (list_type) {
6033 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
6034 : 0 : ret = flow_hw_dr_actions_template_handle_shared
6035 : 0 : (indlst_obj.legacy->legacy_type, action_src,
6036 : : action_types, curr_off, cnt_off, at);
6037 [ # # ]: 0 : if (ret)
6038 : 0 : return ret;
6039 : : break;
6040 : : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
6041 : : action_template_set_type(at, action_types, action_src, curr_off,
6042 : : MLX5DR_ACTION_TYP_DEST_ARRAY);
6043 : : break;
6044 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
6045 : 0 : type = ((struct mlx5_hw_encap_decap_action *)
6046 : : (indlst_conf->handle))->action_type;
6047 : : action_template_set_type(at, action_types, action_src, curr_off, type);
6048 : : break;
6049 : 0 : default:
6050 : 0 : DRV_LOG(ERR, "Unsupported indirect list type");
6051 : 0 : return -EINVAL;
6052 : : }
6053 : : return 0;
6054 : : }
6055 : :
6056 : : /**
6057 : : * Create DR action template based on a provided sequence of flow actions.
6058 : : *
6059 : : * @param[in] dev
6060 : : * Pointer to the rte_eth_dev structure.
6061 : : * @param[in] at
6062 : : * Pointer to flow actions template to be updated.
6063 : : *
6064 : : * @return
6065 : : * DR action template pointer on success and action offsets in @p at are updated.
6066 : : * NULL otherwise.
6067 : : */
6068 : : static struct mlx5dr_action_template *
6069 : 0 : flow_hw_dr_actions_template_create(struct rte_eth_dev *dev,
6070 : : struct rte_flow_actions_template *at)
6071 : : {
6072 : : struct mlx5dr_action_template *dr_template;
6073 : 0 : enum mlx5dr_action_type action_types[MLX5_HW_MAX_ACTS] = { MLX5DR_ACTION_TYP_LAST };
6074 : : unsigned int i;
6075 : : uint16_t curr_off;
6076 : : enum mlx5dr_action_type reformat_act_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
6077 : : uint16_t reformat_off = UINT16_MAX;
6078 : : uint16_t mhdr_off = UINT16_MAX;
6079 : : uint16_t recom_off = UINT16_MAX;
6080 : 0 : uint16_t cnt_off = UINT16_MAX;
6081 : : enum mlx5dr_action_type recom_type = MLX5DR_ACTION_TYP_LAST;
6082 : : int ret;
6083 : :
6084 [ # # ]: 0 : for (i = 0, curr_off = 0; at->actions[i].type != RTE_FLOW_ACTION_TYPE_END; ++i) {
6085 : : const struct rte_flow_action_raw_encap *raw_encap_data;
6086 : : size_t data_size;
6087 : : enum mlx5dr_action_type type;
6088 : :
6089 [ # # ]: 0 : if (curr_off >= MLX5_HW_MAX_ACTS)
6090 : 0 : goto err_actions_num;
6091 [ # # # # : 0 : switch ((int)at->actions[i].type) {
# # # # #
# # # # #
# ]
6092 : : case RTE_FLOW_ACTION_TYPE_VOID:
6093 : : break;
6094 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
6095 : 0 : ret = flow_hw_template_actions_list(at, i, action_types,
6096 : : &curr_off, &cnt_off);
6097 [ # # ]: 0 : if (ret)
6098 : : return NULL;
6099 : : break;
6100 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
6101 : 0 : ret = flow_hw_dr_actions_template_handle_shared
6102 : 0 : (at->masks[i].type, i, action_types,
6103 : : &curr_off, &cnt_off, at);
6104 [ # # ]: 0 : if (ret)
6105 : : return NULL;
6106 : : break;
6107 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6108 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6109 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
6110 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
6111 : : MLX5_ASSERT(reformat_off == UINT16_MAX);
6112 : 0 : reformat_off = curr_off++;
6113 : 0 : reformat_act_type = mlx5_hw_dr_action_types[at->actions[i].type];
6114 : 0 : break;
6115 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
6116 : : MLX5_ASSERT(recom_off == UINT16_MAX);
6117 : : recom_type = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT;
6118 : 0 : recom_off = curr_off++;
6119 : 0 : break;
6120 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE:
6121 : : MLX5_ASSERT(recom_off == UINT16_MAX);
6122 : : recom_type = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT;
6123 : 0 : recom_off = curr_off++;
6124 : 0 : break;
6125 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6126 : 0 : raw_encap_data = at->actions[i].conf;
6127 : 0 : data_size = raw_encap_data->size;
6128 [ # # ]: 0 : if (reformat_off != UINT16_MAX) {
6129 : : reformat_act_type = data_size < MLX5_ENCAPSULATION_DECISION_SIZE ?
6130 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2 :
6131 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
6132 : : } else {
6133 : 0 : reformat_off = curr_off++;
6134 : : reformat_act_type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
6135 : : }
6136 : : break;
6137 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6138 : 0 : reformat_off = curr_off++;
6139 : : reformat_act_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
6140 : 0 : break;
6141 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6142 [ # # ]: 0 : if (mhdr_off == UINT16_MAX) {
6143 : 0 : mhdr_off = curr_off++;
6144 : 0 : type = mlx5_hw_dr_action_types[at->actions[i].type];
6145 : 0 : action_types[mhdr_off] = type;
6146 : : }
6147 : : break;
6148 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
6149 : 0 : at->dr_off[i] = curr_off;
6150 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_ASO_METER;
6151 [ # # ]: 0 : if (curr_off >= MLX5_HW_MAX_ACTS)
6152 : 0 : goto err_actions_num;
6153 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_TBL;
6154 : 0 : break;
6155 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6156 : 0 : type = mlx5_hw_dr_action_types[at->actions[i].type];
6157 : 0 : at->dr_off[i] = curr_off;
6158 : 0 : action_types[curr_off++] = type;
6159 : 0 : i += is_of_vlan_pcp_present(at->actions + i) ?
6160 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
6161 : : MLX5_HW_VLAN_PUSH_VID_IDX;
6162 : 0 : break;
6163 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
6164 : 0 : at->dr_off[i] = curr_off;
6165 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_ASO_METER;
6166 [ # # ]: 0 : if (curr_off >= MLX5_HW_MAX_ACTS)
6167 : 0 : goto err_actions_num;
6168 : : break;
6169 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
6170 : : case RTE_FLOW_ACTION_TYPE_COUNT:
6171 : : /*
6172 : : * Both AGE and COUNT action need counter, the first
6173 : : * one fills the action_types array, and the second only
6174 : : * saves the offset.
6175 : : */
6176 [ # # ]: 0 : if (cnt_off == UINT16_MAX) {
6177 : 0 : cnt_off = curr_off++;
6178 : 0 : action_types[cnt_off] = MLX5DR_ACTION_TYP_CTR;
6179 : : }
6180 : 0 : at->dr_off[i] = cnt_off;
6181 : 0 : break;
6182 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
6183 : 0 : at->dr_off[i] = curr_off;
6184 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_MISS;
6185 : 0 : break;
6186 : 0 : default:
6187 : 0 : type = mlx5_hw_dr_action_types[at->actions[i].type];
6188 : 0 : at->dr_off[i] = curr_off;
6189 : 0 : action_types[curr_off++] = type;
6190 : 0 : break;
6191 : : }
6192 : : }
6193 [ # # ]: 0 : if (curr_off >= MLX5_HW_MAX_ACTS)
6194 : 0 : goto err_actions_num;
6195 [ # # ]: 0 : if (mhdr_off != UINT16_MAX)
6196 : 0 : at->mhdr_off = mhdr_off;
6197 [ # # ]: 0 : if (reformat_off != UINT16_MAX) {
6198 : 0 : at->reformat_off = reformat_off;
6199 : 0 : action_types[reformat_off] = reformat_act_type;
6200 : : }
6201 [ # # ]: 0 : if (recom_off != UINT16_MAX) {
6202 : 0 : at->recom_off = recom_off;
6203 : 0 : action_types[recom_off] = recom_type;
6204 : : }
6205 : 0 : dr_template = mlx5dr_action_template_create(action_types);
6206 [ # # ]: 0 : if (dr_template) {
6207 : 0 : at->dr_actions_num = curr_off;
6208 : : } else {
6209 : 0 : DRV_LOG(ERR, "Failed to create DR action template: %d", rte_errno);
6210 : 0 : return NULL;
6211 : : }
6212 : : /* Create srh flex parser for remove anchor. */
6213 [ # # ]: 0 : if ((recom_type == MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT ||
6214 [ # # ]: 0 : recom_type == MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) &&
6215 : 0 : mlx5_alloc_srh_flex_parser(dev)) {
6216 : 0 : DRV_LOG(ERR, "Failed to create srv6 flex parser");
6217 : 0 : claim_zero(mlx5dr_action_template_destroy(dr_template));
6218 : 0 : return NULL;
6219 : : }
6220 : : return dr_template;
6221 : 0 : err_actions_num:
6222 : 0 : DRV_LOG(ERR, "Number of HW actions (%u) exceeded maximum (%u) allowed in template",
6223 : : curr_off, MLX5_HW_MAX_ACTS);
6224 : 0 : return NULL;
6225 : : }
6226 : :
6227 : : static void
6228 : 0 : flow_hw_set_vlan_vid(struct rte_eth_dev *dev,
6229 : : struct rte_flow_action *ra,
6230 : : struct rte_flow_action *rm,
6231 : : struct rte_flow_action_modify_field *spec,
6232 : : struct rte_flow_action_modify_field *mask,
6233 : : int set_vlan_vid_ix)
6234 : : {
6235 : : struct rte_flow_error error;
6236 [ # # ]: 0 : const bool masked = rm[set_vlan_vid_ix].conf &&
6237 : : (((const struct rte_flow_action_of_set_vlan_vid *)
6238 [ # # ]: 0 : rm[set_vlan_vid_ix].conf)->vlan_vid != 0);
6239 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
6240 : 0 : ra[set_vlan_vid_ix].conf;
6241 [ # # ]: 0 : rte_be16_t vid = masked ? conf->vlan_vid : 0;
6242 : 0 : int width = mlx5_flow_item_field_width(dev, RTE_FLOW_FIELD_VLAN_ID, 0,
6243 : : NULL, &error);
6244 : 0 : *spec = (typeof(*spec)) {
6245 : : .operation = RTE_FLOW_MODIFY_SET,
6246 : : .dst = {
6247 : : .field = RTE_FLOW_FIELD_VLAN_ID,
6248 : : .level = 0, .offset = 0,
6249 : : },
6250 : : .src = {
6251 : : .field = RTE_FLOW_FIELD_VALUE,
6252 : : .level = vid,
6253 : : .offset = 0,
6254 : : },
6255 : : .width = width,
6256 : : };
6257 [ # # ]: 0 : *mask = (typeof(*mask)) {
6258 : : .operation = RTE_FLOW_MODIFY_SET,
6259 : : .dst = {
6260 : : .field = RTE_FLOW_FIELD_VLAN_ID,
6261 : : .level = 0xff, .offset = 0xffffffff,
6262 : : },
6263 : : .src = {
6264 : : .field = RTE_FLOW_FIELD_VALUE,
6265 : 0 : .level = masked ? (1U << width) - 1 : 0,
6266 : : .offset = 0,
6267 : : },
6268 : : .width = 0xffffffff,
6269 : : };
6270 : 0 : ra[set_vlan_vid_ix].type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD;
6271 : 0 : ra[set_vlan_vid_ix].conf = spec;
6272 : 0 : rm[set_vlan_vid_ix].type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD;
6273 : 0 : rm[set_vlan_vid_ix].conf = mask;
6274 : 0 : }
6275 : :
6276 : : static __rte_always_inline int
6277 : : flow_hw_set_vlan_vid_construct(struct rte_eth_dev *dev,
6278 : : struct mlx5_hw_q_job *job,
6279 : : struct mlx5_action_construct_data *act_data,
6280 : : const struct mlx5_hw_actions *hw_acts,
6281 : : const struct rte_flow_action *action)
6282 : : {
6283 : : struct rte_flow_error error;
6284 : 0 : rte_be16_t vid = ((const struct rte_flow_action_of_set_vlan_vid *)
6285 : 0 : action->conf)->vlan_vid;
6286 : 0 : int width = mlx5_flow_item_field_width(dev, RTE_FLOW_FIELD_VLAN_ID, 0,
6287 : : NULL, &error);
6288 [ # # # # : 0 : struct rte_flow_action_modify_field conf = {
# # ]
6289 : : .operation = RTE_FLOW_MODIFY_SET,
6290 : : .dst = {
6291 : : .field = RTE_FLOW_FIELD_VLAN_ID,
6292 : : .level = 0, .offset = 0,
6293 : : },
6294 : : .src = {
6295 : : .field = RTE_FLOW_FIELD_VALUE,
6296 : : .level = vid,
6297 : : .offset = 0,
6298 : : },
6299 : : .width = width,
6300 : : };
6301 : : struct rte_flow_action modify_action = {
6302 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
6303 : : .conf = &conf
6304 : : };
6305 : :
6306 : : return flow_hw_modify_field_construct(job, act_data, hw_acts,
6307 : : &modify_action);
6308 : : }
6309 : :
6310 : : static int
6311 : 0 : flow_hw_flex_item_acquire(struct rte_eth_dev *dev,
6312 : : struct rte_flow_item_flex_handle *handle,
6313 : : uint8_t *flex_item)
6314 : : {
6315 : 0 : int index = mlx5_flex_acquire_index(dev, handle, false);
6316 : :
6317 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
6318 [ # # ]: 0 : if (index < 0)
6319 : : return -1;
6320 [ # # ]: 0 : if (!(*flex_item & RTE_BIT32(index))) {
6321 : : /* Don't count same flex item again. */
6322 : 0 : if (mlx5_flex_acquire_index(dev, handle, true) != index)
6323 : : MLX5_ASSERT(false);
6324 : 0 : *flex_item |= (uint8_t)RTE_BIT32(index);
6325 : : }
6326 : : return 0;
6327 : : }
6328 : :
6329 : : static void
6330 : 0 : flow_hw_flex_item_release(struct rte_eth_dev *dev, uint8_t *flex_item)
6331 : : {
6332 [ # # ]: 0 : while (*flex_item) {
6333 : 0 : int index = rte_bsf32(*flex_item);
6334 : :
6335 : 0 : mlx5_flex_release_index(dev, index);
6336 : 0 : *flex_item &= ~(uint8_t)RTE_BIT32(index);
6337 : : }
6338 : 0 : }
6339 : : static __rte_always_inline void
6340 : : flow_hw_actions_template_replace_container(const
6341 : : struct rte_flow_action *actions,
6342 : : const
6343 : : struct rte_flow_action *masks,
6344 : : struct rte_flow_action *new_actions,
6345 : : struct rte_flow_action *new_masks,
6346 : : struct rte_flow_action **ra,
6347 : : struct rte_flow_action **rm,
6348 : : uint32_t act_num)
6349 : : {
6350 : 0 : memcpy(new_actions, actions, sizeof(actions[0]) * act_num);
6351 : : memcpy(new_masks, masks, sizeof(masks[0]) * act_num);
6352 : : *ra = (void *)(uintptr_t)new_actions;
6353 : : *rm = (void *)(uintptr_t)new_masks;
6354 : 0 : }
6355 : :
6356 : : /* Action template copies these actions in rte_flow_conv() */
6357 : :
6358 : : static const struct rte_flow_action rx_meta_copy_action = {
6359 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
6360 : : .conf = &(struct rte_flow_action_modify_field){
6361 : : .operation = RTE_FLOW_MODIFY_SET,
6362 : : .dst = {
6363 : : .field = (enum rte_flow_field_id)
6364 : : MLX5_RTE_FLOW_FIELD_META_REG,
6365 : : .tag_index = REG_B,
6366 : : },
6367 : : .src = {
6368 : : .field = (enum rte_flow_field_id)
6369 : : MLX5_RTE_FLOW_FIELD_META_REG,
6370 : : .tag_index = REG_C_1,
6371 : : },
6372 : : .width = 32,
6373 : : }
6374 : : };
6375 : :
6376 : : static const struct rte_flow_action rx_meta_copy_mask = {
6377 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
6378 : : .conf = &(struct rte_flow_action_modify_field){
6379 : : .operation = RTE_FLOW_MODIFY_SET,
6380 : : .dst = {
6381 : : .field = (enum rte_flow_field_id)
6382 : : MLX5_RTE_FLOW_FIELD_META_REG,
6383 : : .level = UINT8_MAX,
6384 : : .tag_index = UINT8_MAX,
6385 : : .offset = UINT32_MAX,
6386 : : },
6387 : : .src = {
6388 : : .field = (enum rte_flow_field_id)
6389 : : MLX5_RTE_FLOW_FIELD_META_REG,
6390 : : .level = UINT8_MAX,
6391 : : .tag_index = UINT8_MAX,
6392 : : .offset = UINT32_MAX,
6393 : : },
6394 : : .width = UINT32_MAX,
6395 : : }
6396 : : };
6397 : :
6398 : : static const struct rte_flow_action quota_color_inc_action = {
6399 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
6400 : : .conf = &(struct rte_flow_action_modify_field) {
6401 : : .operation = RTE_FLOW_MODIFY_ADD,
6402 : : .dst = {
6403 : : .field = RTE_FLOW_FIELD_METER_COLOR,
6404 : : .level = 0, .offset = 0
6405 : : },
6406 : : .src = {
6407 : : .field = RTE_FLOW_FIELD_VALUE,
6408 : : .level = 1,
6409 : : .offset = 0,
6410 : : },
6411 : : .width = 2
6412 : : }
6413 : : };
6414 : :
6415 : : static const struct rte_flow_action quota_color_inc_mask = {
6416 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
6417 : : .conf = &(struct rte_flow_action_modify_field) {
6418 : : .operation = RTE_FLOW_MODIFY_ADD,
6419 : : .dst = {
6420 : : .field = RTE_FLOW_FIELD_METER_COLOR,
6421 : : .level = UINT8_MAX,
6422 : : .tag_index = UINT8_MAX,
6423 : : .offset = UINT32_MAX,
6424 : : },
6425 : : .src = {
6426 : : .field = RTE_FLOW_FIELD_VALUE,
6427 : : .level = 3,
6428 : : .offset = 0
6429 : : },
6430 : : .width = UINT32_MAX
6431 : : }
6432 : : };
6433 : :
6434 : : /**
6435 : : * Create flow action template.
6436 : : *
6437 : : * @param[in] dev
6438 : : * Pointer to the rte_eth_dev structure.
6439 : : * @param[in] attr
6440 : : * Pointer to the action template attributes.
6441 : : * @param[in] actions
6442 : : * Associated actions (list terminated by the END action).
6443 : : * @param[in] masks
6444 : : * List of actions that marks which of the action's member is constant.
6445 : : * @param[out] error
6446 : : * Pointer to error structure.
6447 : : *
6448 : : * @return
6449 : : * Action template pointer on success, NULL otherwise and rte_errno is set.
6450 : : */
6451 : : static struct rte_flow_actions_template *
6452 : 0 : flow_hw_actions_template_create(struct rte_eth_dev *dev,
6453 : : const struct rte_flow_actions_template_attr *attr,
6454 : : const struct rte_flow_action actions[],
6455 : : const struct rte_flow_action masks[],
6456 : : struct rte_flow_error *error)
6457 : : {
6458 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6459 : : int len, act_len, mask_len;
6460 : : unsigned int act_num;
6461 : : unsigned int i;
6462 : : struct rte_flow_actions_template *at = NULL;
6463 : : uint16_t pos = UINT16_MAX;
6464 : 0 : uint64_t action_flags = 0;
6465 : : struct rte_flow_action tmp_action[MLX5_HW_MAX_ACTS];
6466 : : struct rte_flow_action tmp_mask[MLX5_HW_MAX_ACTS];
6467 : : struct rte_flow_action *ra = (void *)(uintptr_t)actions;
6468 : : struct rte_flow_action *rm = (void *)(uintptr_t)masks;
6469 : : int set_vlan_vid_ix = -1;
6470 : 0 : struct rte_flow_action_modify_field set_vlan_vid_spec = {0, };
6471 : 0 : struct rte_flow_action_modify_field set_vlan_vid_mask = {0, };
6472 : : struct rte_flow_action mf_actions[MLX5_HW_MAX_ACTS];
6473 : : struct rte_flow_action mf_masks[MLX5_HW_MAX_ACTS];
6474 : : uint32_t expand_mf_num = 0;
6475 : 0 : uint16_t src_off[MLX5_HW_MAX_ACTS] = {0, };
6476 : :
6477 [ # # ]: 0 : if (mlx5_flow_hw_actions_validate(dev, attr, actions, masks,
6478 : : &action_flags, error))
6479 : : return NULL;
6480 [ # # ]: 0 : for (i = 0; ra[i].type != RTE_FLOW_ACTION_TYPE_END; ++i) {
6481 [ # # # ]: 0 : switch (ra[i].type) {
6482 : : /* OF_PUSH_VLAN *MUST* come before OF_SET_VLAN_VID */
6483 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6484 : 0 : i += is_of_vlan_pcp_present(ra + i) ?
6485 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
6486 : : MLX5_HW_VLAN_PUSH_VID_IDX;
6487 : 0 : break;
6488 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6489 : 0 : set_vlan_vid_ix = i;
6490 : 0 : break;
6491 : : default:
6492 : : break;
6493 : : }
6494 : : }
6495 : : /*
6496 : : * Count flow actions to allocate required space for storing DR offsets and to check
6497 : : * if temporary buffer would not be overrun.
6498 : : */
6499 : 0 : act_num = i + 1;
6500 [ # # ]: 0 : if (act_num >= MLX5_HW_MAX_ACTS) {
6501 : 0 : rte_flow_error_set(error, EINVAL,
6502 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "Too many actions");
6503 : 0 : return NULL;
6504 : : }
6505 [ # # ]: 0 : if (set_vlan_vid_ix != -1) {
6506 : : /* If temporary action buffer was not used, copy template actions to it */
6507 : : if (ra == actions)
6508 : : flow_hw_actions_template_replace_container(actions,
6509 : : masks,
6510 : : tmp_action,
6511 : : tmp_mask,
6512 : : &ra, &rm,
6513 : : act_num);
6514 : 0 : flow_hw_set_vlan_vid(dev, ra, rm,
6515 : : &set_vlan_vid_spec, &set_vlan_vid_mask,
6516 : : set_vlan_vid_ix);
6517 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
6518 : : }
6519 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUOTA) {
6520 : 0 : mf_actions[expand_mf_num] = quota_color_inc_action;
6521 : 0 : mf_masks[expand_mf_num] = quota_color_inc_mask;
6522 : : expand_mf_num++;
6523 : : }
6524 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS &&
6525 : 0 : priv->sh->config.dv_esw_en &&
6526 [ # # ]: 0 : (action_flags & (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS))) {
6527 : : /* Insert META copy */
6528 : 0 : mf_actions[expand_mf_num] = rx_meta_copy_action;
6529 : 0 : mf_masks[expand_mf_num] = rx_meta_copy_mask;
6530 : 0 : expand_mf_num++;
6531 : : }
6532 [ # # ]: 0 : if (expand_mf_num) {
6533 [ # # ]: 0 : if (act_num + expand_mf_num > MLX5_HW_MAX_ACTS) {
6534 : 0 : rte_flow_error_set(error, E2BIG,
6535 : : RTE_FLOW_ERROR_TYPE_ACTION,
6536 : : NULL, "cannot expand: too many actions");
6537 : 0 : return NULL;
6538 : : }
6539 [ # # ]: 0 : if (ra == actions)
6540 : : flow_hw_actions_template_replace_container(actions,
6541 : : masks,
6542 : : tmp_action,
6543 : : tmp_mask,
6544 : : &ra, &rm,
6545 : : act_num);
6546 : : /* Application should make sure only one Q/RSS exist in one rule. */
6547 : 0 : pos = flow_hw_template_expand_modify_field(ra, rm,
6548 : : mf_actions,
6549 : : mf_masks,
6550 : : action_flags,
6551 : : act_num,
6552 : : expand_mf_num);
6553 : : act_num += expand_mf_num;
6554 [ # # ]: 0 : for (i = pos + expand_mf_num; i < act_num; i++)
6555 : 0 : src_off[i] += expand_mf_num;
6556 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
6557 : : }
6558 : 0 : act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, ra, error);
6559 [ # # ]: 0 : if (act_len <= 0)
6560 : : return NULL;
6561 : 0 : len = RTE_ALIGN(act_len, 16);
6562 : 0 : mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, rm, error);
6563 [ # # ]: 0 : if (mask_len <= 0)
6564 : : return NULL;
6565 : 0 : len += RTE_ALIGN(mask_len, 16);
6566 : 0 : len += RTE_ALIGN(act_num * sizeof(*at->dr_off), 16);
6567 : 0 : len += RTE_ALIGN(act_num * sizeof(*at->src_off), 16);
6568 : 0 : at = mlx5_malloc(MLX5_MEM_ZERO, len + sizeof(*at),
6569 : 0 : RTE_CACHE_LINE_SIZE, rte_socket_id());
6570 [ # # ]: 0 : if (!at) {
6571 : 0 : rte_flow_error_set(error, ENOMEM,
6572 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6573 : : NULL,
6574 : : "cannot allocate action template");
6575 : 0 : return NULL;
6576 : : }
6577 : : /* Actions part is in the first part. */
6578 : 0 : at->attr = *attr;
6579 : 0 : at->actions = (struct rte_flow_action *)(at + 1);
6580 : 0 : act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->actions,
6581 : : len, ra, error);
6582 [ # # ]: 0 : if (act_len <= 0)
6583 : 0 : goto error;
6584 : : /* Masks part is in the second part. */
6585 : 0 : at->masks = (struct rte_flow_action *)(((uint8_t *)at->actions) + act_len);
6586 : 0 : mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->masks,
6587 : 0 : len - act_len, rm, error);
6588 [ # # ]: 0 : if (mask_len <= 0)
6589 : 0 : goto error;
6590 : : /* DR actions offsets in the third part. */
6591 : 0 : at->dr_off = (uint16_t *)((uint8_t *)at->masks + mask_len);
6592 : 0 : at->src_off = RTE_PTR_ADD(at->dr_off,
6593 : : RTE_ALIGN(act_num * sizeof(*at->dr_off), 16));
6594 : : memcpy(at->src_off, src_off, act_num * sizeof(at->src_off[0]));
6595 : 0 : at->actions_num = act_num;
6596 [ # # ]: 0 : for (i = 0; i < at->actions_num; ++i)
6597 : 0 : at->dr_off[i] = UINT16_MAX;
6598 : 0 : at->reformat_off = UINT16_MAX;
6599 : 0 : at->mhdr_off = UINT16_MAX;
6600 : 0 : at->recom_off = UINT16_MAX;
6601 [ # # ]: 0 : for (i = 0; actions->type != RTE_FLOW_ACTION_TYPE_END;
6602 : 0 : actions++, masks++, i++) {
6603 : : const struct rte_flow_action_modify_field *info;
6604 : :
6605 [ # # # ]: 0 : switch (actions->type) {
6606 : : /*
6607 : : * mlx5 PMD hacks indirect action index directly to the action conf.
6608 : : * The rte_flow_conv() function copies the content from conf pointer.
6609 : : * Need to restore the indirect action index from action conf here.
6610 : : */
6611 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
6612 : 0 : at->actions[i].conf = ra[i].conf;
6613 : 0 : at->masks[i].conf = rm[i].conf;
6614 : 0 : break;
6615 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6616 : 0 : info = actions->conf;
6617 [ # # # # ]: 0 : if ((info->dst.field == RTE_FLOW_FIELD_FLEX_ITEM &&
6618 : 0 : flow_hw_flex_item_acquire(dev, info->dst.flex_handle,
6619 : 0 : &at->flex_item)) ||
6620 [ # # # # ]: 0 : (info->src.field == RTE_FLOW_FIELD_FLEX_ITEM &&
6621 : 0 : flow_hw_flex_item_acquire(dev, info->src.flex_handle,
6622 : : &at->flex_item)))
6623 : 0 : goto error;
6624 : : break;
6625 : : default:
6626 : : break;
6627 : : }
6628 : : }
6629 : 0 : at->tmpl = flow_hw_dr_actions_template_create(dev, at);
6630 [ # # ]: 0 : if (!at->tmpl)
6631 : 0 : goto error;
6632 : 0 : at->action_flags = action_flags;
6633 : 0 : __atomic_fetch_add(&at->refcnt, 1, __ATOMIC_RELAXED);
6634 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_at, at, next);
6635 : 0 : return at;
6636 : 0 : error:
6637 : : if (at) {
6638 [ # # ]: 0 : if (at->tmpl)
6639 : 0 : mlx5dr_action_template_destroy(at->tmpl);
6640 : 0 : mlx5_free(at);
6641 : : }
6642 : 0 : rte_flow_error_set(error, rte_errno,
6643 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6644 : : "Failed to create action template");
6645 : 0 : return NULL;
6646 : : }
6647 : :
6648 : : /**
6649 : : * Destroy flow action template.
6650 : : *
6651 : : * @param[in] dev
6652 : : * Pointer to the rte_eth_dev structure.
6653 : : * @param[in] template
6654 : : * Pointer to the action template to be destroyed.
6655 : : * @param[out] error
6656 : : * Pointer to error structure.
6657 : : *
6658 : : * @return
6659 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6660 : : */
6661 : : static int
6662 : 0 : flow_hw_actions_template_destroy(struct rte_eth_dev *dev,
6663 : : struct rte_flow_actions_template *template,
6664 : : struct rte_flow_error *error __rte_unused)
6665 : : {
6666 : : uint64_t flag = MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE |
6667 : : MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH;
6668 : :
6669 [ # # ]: 0 : if (__atomic_load_n(&template->refcnt, __ATOMIC_RELAXED) > 1) {
6670 : 0 : DRV_LOG(WARNING, "Action template %p is still in use.",
6671 : : (void *)template);
6672 : 0 : return rte_flow_error_set(error, EBUSY,
6673 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6674 : : NULL,
6675 : : "action template in using");
6676 : : }
6677 [ # # ]: 0 : if (template->action_flags & flag)
6678 : 0 : mlx5_free_srh_flex_parser(dev);
6679 [ # # ]: 0 : LIST_REMOVE(template, next);
6680 : 0 : flow_hw_flex_item_release(dev, &template->flex_item);
6681 [ # # ]: 0 : if (template->tmpl)
6682 : 0 : mlx5dr_action_template_destroy(template->tmpl);
6683 : 0 : mlx5_free(template);
6684 : 0 : return 0;
6685 : : }
6686 : :
6687 : : static uint32_t
6688 : : flow_hw_count_items(const struct rte_flow_item *items)
6689 : : {
6690 : : const struct rte_flow_item *curr_item;
6691 : : uint32_t nb_items;
6692 : :
6693 : : nb_items = 0;
6694 [ # # ]: 0 : for (curr_item = items; curr_item->type != RTE_FLOW_ITEM_TYPE_END; ++curr_item)
6695 : 0 : ++nb_items;
6696 : 0 : return ++nb_items;
6697 : : }
6698 : :
6699 : : static struct rte_flow_item *
6700 : 0 : flow_hw_prepend_item(const struct rte_flow_item *items,
6701 : : const uint32_t nb_items,
6702 : : const struct rte_flow_item *new_item,
6703 : : struct rte_flow_error *error)
6704 : : {
6705 : : struct rte_flow_item *copied_items;
6706 : : size_t size;
6707 : :
6708 : : /* Allocate new array of items. */
6709 : 0 : size = sizeof(*copied_items) * (nb_items + 1);
6710 : 0 : copied_items = mlx5_malloc(MLX5_MEM_ZERO, size, 0, rte_socket_id());
6711 [ # # ]: 0 : if (!copied_items) {
6712 : 0 : rte_flow_error_set(error, ENOMEM,
6713 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6714 : : NULL,
6715 : : "cannot allocate item template");
6716 : 0 : return NULL;
6717 : : }
6718 : : /* Put new item at the beginning and copy the rest. */
6719 : 0 : copied_items[0] = *new_item;
6720 [ # # ]: 0 : rte_memcpy(&copied_items[1], items, sizeof(*items) * nb_items);
6721 : : return copied_items;
6722 : : }
6723 : :
6724 : : static inline bool
6725 : : flow_hw_item_compare_field_supported(enum rte_flow_field_id field)
6726 : : {
6727 : 0 : switch (field) {
6728 : : case RTE_FLOW_FIELD_TAG:
6729 : : case RTE_FLOW_FIELD_META:
6730 : : case RTE_FLOW_FIELD_VALUE:
6731 : : return true;
6732 : : default:
6733 : : break;
6734 : : }
6735 : : return false;
6736 : : }
6737 : :
6738 : : static int
6739 : 0 : flow_hw_validate_item_compare(const struct rte_flow_item *item,
6740 : : struct rte_flow_error *error)
6741 : : {
6742 : 0 : const struct rte_flow_item_compare *comp_m = item->mask;
6743 : 0 : const struct rte_flow_item_compare *comp_v = item->spec;
6744 : :
6745 [ # # ]: 0 : if (unlikely(!comp_m))
6746 : 0 : return rte_flow_error_set(error, EINVAL,
6747 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6748 : : NULL,
6749 : : "compare item mask is missing");
6750 [ # # ]: 0 : if (comp_m->width != UINT32_MAX)
6751 : 0 : return rte_flow_error_set(error, EINVAL,
6752 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6753 : : NULL,
6754 : : "compare item only support full mask");
6755 [ # # ]: 0 : if (!flow_hw_item_compare_field_supported(comp_m->a.field) ||
6756 [ # # ]: 0 : !flow_hw_item_compare_field_supported(comp_m->b.field))
6757 : 0 : return rte_flow_error_set(error, ENOTSUP,
6758 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6759 : : NULL,
6760 : : "compare item field not support");
6761 [ # # # # ]: 0 : if (comp_m->a.field == RTE_FLOW_FIELD_VALUE &&
6762 : : comp_m->b.field == RTE_FLOW_FIELD_VALUE)
6763 : 0 : return rte_flow_error_set(error, EINVAL,
6764 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6765 : : NULL,
6766 : : "compare between value is not valid");
6767 [ # # ]: 0 : if (comp_v) {
6768 [ # # ]: 0 : if (comp_v->operation != comp_m->operation ||
6769 [ # # ]: 0 : comp_v->a.field != comp_m->a.field ||
6770 [ # # ]: 0 : comp_v->b.field != comp_m->b.field)
6771 : 0 : return rte_flow_error_set(error, EINVAL,
6772 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6773 : : NULL,
6774 : : "compare item spec/mask not matching");
6775 [ # # ]: 0 : if ((comp_v->width & comp_m->width) != 32)
6776 : 0 : return rte_flow_error_set(error, EINVAL,
6777 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6778 : : NULL,
6779 : : "compare item only support full mask");
6780 : : }
6781 : : return 0;
6782 : : }
6783 : :
6784 : : static int
6785 : 0 : flow_hw_pattern_validate(struct rte_eth_dev *dev,
6786 : : const struct rte_flow_pattern_template_attr *attr,
6787 : : const struct rte_flow_item items[],
6788 : : struct rte_flow_error *error)
6789 : : {
6790 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6791 : : int i, tag_idx;
6792 : : bool items_end = false;
6793 : : uint32_t tag_bitmap = 0;
6794 : : int ret;
6795 : :
6796 [ # # ]: 0 : if (!attr->ingress && !attr->egress && !attr->transfer)
6797 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6798 : : "at least one of the direction attributes"
6799 : : " must be specified");
6800 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
6801 : : MLX5_ASSERT(priv->master || priv->representor);
6802 [ # # ]: 0 : if (priv->master) {
6803 [ # # ]: 0 : if ((attr->ingress && attr->egress) ||
6804 [ # # ]: 0 : (attr->ingress && attr->transfer) ||
6805 [ # # ]: 0 : (attr->egress && attr->transfer))
6806 : 0 : return rte_flow_error_set(error, EINVAL,
6807 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6808 : : "only one direction attribute at once"
6809 : : " can be used on transfer proxy port");
6810 : : } else {
6811 [ # # ]: 0 : if (attr->transfer)
6812 : 0 : return rte_flow_error_set(error, EINVAL,
6813 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, NULL,
6814 : : "transfer attribute cannot be used with"
6815 : : " port representors");
6816 [ # # ]: 0 : if (attr->ingress && attr->egress)
6817 : 0 : return rte_flow_error_set(error, EINVAL,
6818 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6819 : : "ingress and egress direction attributes"
6820 : : " cannot be used at the same time on"
6821 : : " port representors");
6822 : : }
6823 : : } else {
6824 [ # # ]: 0 : if (attr->transfer)
6825 : 0 : return rte_flow_error_set(error, EINVAL,
6826 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, NULL,
6827 : : "transfer attribute cannot be used when"
6828 : : " E-Switch is disabled");
6829 : : }
6830 [ # # ]: 0 : for (i = 0; !items_end; i++) {
6831 : 0 : int type = items[i].type;
6832 : :
6833 [ # # # # : 0 : switch (type) {
# # # # #
# # ]
6834 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
6835 : : {
6836 : 0 : const struct rte_flow_item_tag *tag =
6837 : : (const struct rte_flow_item_tag *)items[i].spec;
6838 : :
6839 [ # # ]: 0 : if (tag == NULL)
6840 : 0 : return rte_flow_error_set(error, EINVAL,
6841 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6842 : : NULL,
6843 : : "Tag spec is NULL");
6844 [ # # ]: 0 : if (tag->index >= MLX5_FLOW_HW_TAGS_MAX &&
6845 : : tag->index != RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
6846 : 0 : return rte_flow_error_set(error, EINVAL,
6847 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6848 : : NULL,
6849 : : "Invalid tag index");
6850 [ # # ]: 0 : tag_idx = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, tag->index);
6851 [ # # ]: 0 : if (tag_idx == REG_NON)
6852 : 0 : return rte_flow_error_set(error, EINVAL,
6853 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6854 : : NULL,
6855 : : "Unsupported tag index");
6856 [ # # ]: 0 : if (tag_bitmap & (1 << tag_idx))
6857 : 0 : return rte_flow_error_set(error, EINVAL,
6858 : : RTE_FLOW_ERROR_TYPE_ITEM,
6859 : : NULL,
6860 : : "Duplicated tag index");
6861 : 0 : tag_bitmap |= 1 << tag_idx;
6862 : 0 : break;
6863 : : }
6864 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
6865 : : {
6866 : 0 : const struct rte_flow_item_tag *tag =
6867 : : (const struct rte_flow_item_tag *)items[i].spec;
6868 : 0 : uint16_t regcs = (uint8_t)priv->sh->cdev->config.hca_attr.set_reg_c;
6869 : :
6870 [ # # ]: 0 : if (!((1 << (tag->index - REG_C_0)) & regcs))
6871 : 0 : return rte_flow_error_set(error, EINVAL,
6872 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6873 : : NULL,
6874 : : "Unsupported internal tag index");
6875 [ # # ]: 0 : if (tag_bitmap & (1 << tag->index))
6876 : 0 : return rte_flow_error_set(error, EINVAL,
6877 : : RTE_FLOW_ERROR_TYPE_ITEM,
6878 : : NULL,
6879 : : "Duplicated tag index");
6880 : 0 : tag_bitmap |= 1 << tag->index;
6881 : 0 : break;
6882 : : }
6883 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
6884 [ # # # # ]: 0 : if (attr->ingress && priv->sh->config.repr_matching)
6885 : 0 : return rte_flow_error_set(error, EINVAL,
6886 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6887 : : "represented port item cannot be used"
6888 : : " when ingress attribute is set");
6889 [ # # ]: 0 : if (attr->egress)
6890 : 0 : return rte_flow_error_set(error, EINVAL,
6891 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6892 : : "represented port item cannot be used"
6893 : : " when egress attribute is set");
6894 : : break;
6895 : 0 : case RTE_FLOW_ITEM_TYPE_META:
6896 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en ||
6897 : : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS) {
6898 [ # # ]: 0 : if (attr->ingress)
6899 : 0 : return rte_flow_error_set(error, EINVAL,
6900 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6901 : : "META item is not supported"
6902 : : " on current FW with ingress"
6903 : : " attribute");
6904 : : }
6905 : : break;
6906 : : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
6907 : : {
6908 : : int reg = flow_hw_get_reg_id(dev,
6909 : : RTE_FLOW_ITEM_TYPE_METER_COLOR,
6910 : : 0);
6911 [ # # ]: 0 : if (reg == REG_NON)
6912 : 0 : return rte_flow_error_set(error, EINVAL,
6913 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6914 : : NULL,
6915 : : "Unsupported meter color register");
6916 : : break;
6917 : : }
6918 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
6919 : : {
6920 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
6921 : 0 : return rte_flow_error_set(error, EINVAL,
6922 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6923 : : "Unsupported aggregated affinity with Older FW");
6924 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) || attr->egress)
# # ]
6925 : 0 : return rte_flow_error_set(error, EINVAL,
6926 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6927 : : "Aggregated affinity item not supported"
6928 : : " with egress or transfer"
6929 : : " attribute");
6930 : : break;
6931 : : }
6932 : 0 : case RTE_FLOW_ITEM_TYPE_COMPARE:
6933 : : {
6934 : 0 : ret = flow_hw_validate_item_compare(&items[i], error);
6935 [ # # ]: 0 : if (ret)
6936 : 0 : return ret;
6937 : : break;
6938 : : }
6939 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
6940 : : {
6941 : : int ret;
6942 : :
6943 : 0 : ret = mlx5_flow_geneve_tlv_option_validate(priv,
6944 : : &items[i],
6945 : : error);
6946 [ # # ]: 0 : if (ret < 0)
6947 : 0 : return ret;
6948 : : break;
6949 : : }
6950 : : case RTE_FLOW_ITEM_TYPE_VOID:
6951 : : case RTE_FLOW_ITEM_TYPE_ETH:
6952 : : case RTE_FLOW_ITEM_TYPE_VLAN:
6953 : : case RTE_FLOW_ITEM_TYPE_IPV4:
6954 : : case RTE_FLOW_ITEM_TYPE_IPV6:
6955 : : case RTE_FLOW_ITEM_TYPE_UDP:
6956 : : case RTE_FLOW_ITEM_TYPE_TCP:
6957 : : case RTE_FLOW_ITEM_TYPE_GTP:
6958 : : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6959 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
6960 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6961 : : case RTE_FLOW_ITEM_TYPE_MPLS:
6962 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
6963 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
6964 : : case RTE_FLOW_ITEM_TYPE_GRE:
6965 : : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6966 : : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
6967 : : case RTE_FLOW_ITEM_TYPE_ICMP:
6968 : : case RTE_FLOW_ITEM_TYPE_ICMP6:
6969 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
6970 : : case RTE_FLOW_ITEM_TYPE_QUOTA:
6971 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
6972 : : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
6973 : : case RTE_FLOW_ITEM_TYPE_IPV6_ROUTING_EXT:
6974 : : case RTE_FLOW_ITEM_TYPE_ESP:
6975 : : case RTE_FLOW_ITEM_TYPE_FLEX:
6976 : : case RTE_FLOW_ITEM_TYPE_IB_BTH:
6977 : : case RTE_FLOW_ITEM_TYPE_PTYPE:
6978 : : case RTE_FLOW_ITEM_TYPE_RANDOM:
6979 : : break;
6980 : : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
6981 : : /*
6982 : : * Integrity flow item validation require access to
6983 : : * both item mask and spec.
6984 : : * Current HWS model allows item mask in pattern
6985 : : * template and item spec in flow rule.
6986 : : */
6987 : : break;
6988 : 0 : case RTE_FLOW_ITEM_TYPE_END:
6989 : : items_end = true;
6990 : 0 : break;
6991 : 0 : default:
6992 : 0 : return rte_flow_error_set(error, EINVAL,
6993 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6994 : : NULL,
6995 : : "Unsupported item type");
6996 : : }
6997 : : }
6998 : : return 0;
6999 : : }
7000 : :
7001 : : static bool
7002 : : flow_hw_pattern_has_sq_match(const struct rte_flow_item *items)
7003 : : {
7004 : : unsigned int i;
7005 : :
7006 [ # # ]: 0 : for (i = 0; items[i].type != RTE_FLOW_ITEM_TYPE_END; ++i)
7007 [ # # ]: 0 : if (items[i].type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ)
7008 : : return true;
7009 : : return false;
7010 : : }
7011 : :
7012 : : /**
7013 : : * Create flow item template.
7014 : : *
7015 : : * @param[in] dev
7016 : : * Pointer to the rte_eth_dev structure.
7017 : : * @param[in] attr
7018 : : * Pointer to the item template attributes.
7019 : : * @param[in] items
7020 : : * The template item pattern.
7021 : : * @param[out] error
7022 : : * Pointer to error structure.
7023 : : *
7024 : : * @return
7025 : : * Item template pointer on success, NULL otherwise and rte_errno is set.
7026 : : */
7027 : : static struct rte_flow_pattern_template *
7028 : 0 : flow_hw_pattern_template_create(struct rte_eth_dev *dev,
7029 : : const struct rte_flow_pattern_template_attr *attr,
7030 : : const struct rte_flow_item items[],
7031 : : struct rte_flow_error *error)
7032 : : {
7033 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7034 : : struct rte_flow_pattern_template *it;
7035 : : struct rte_flow_item *copied_items = NULL;
7036 : : const struct rte_flow_item *tmpl_items;
7037 : : uint32_t orig_item_nb;
7038 : 0 : struct rte_flow_item port = {
7039 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
7040 : : .mask = &rte_flow_item_ethdev_mask,
7041 : : };
7042 : 0 : struct rte_flow_item_tag tag_v = {
7043 : : .data = 0,
7044 : : .index = REG_C_0,
7045 : : };
7046 : 0 : struct rte_flow_item_tag tag_m = {
7047 : : .data = flow_hw_tx_tag_regc_mask(dev),
7048 : : .index = 0xff,
7049 : : };
7050 : 0 : struct rte_flow_item tag = {
7051 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
7052 : : .spec = &tag_v,
7053 : : .mask = &tag_m,
7054 : : .last = NULL
7055 : : };
7056 : : unsigned int i = 0;
7057 : :
7058 [ # # ]: 0 : if (flow_hw_pattern_validate(dev, attr, items, error))
7059 : : return NULL;
7060 : : orig_item_nb = flow_hw_count_items(items);
7061 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en &&
7062 : : priv->sh->config.repr_matching &&
7063 [ # # ]: 0 : attr->ingress && !attr->egress && !attr->transfer) {
7064 : 0 : copied_items = flow_hw_prepend_item(items, orig_item_nb, &port, error);
7065 [ # # ]: 0 : if (!copied_items)
7066 : : return NULL;
7067 : : tmpl_items = copied_items;
7068 [ # # # # ]: 0 : } else if (priv->sh->config.dv_esw_en &&
7069 : : priv->sh->config.repr_matching &&
7070 [ # # ]: 0 : !attr->ingress && attr->egress && !attr->transfer) {
7071 [ # # ]: 0 : if (flow_hw_pattern_has_sq_match(items)) {
7072 : 0 : DRV_LOG(DEBUG, "Port %u omitting implicit REG_C_0 match for egress "
7073 : : "pattern template", dev->data->port_id);
7074 : : tmpl_items = items;
7075 : 0 : goto setup_pattern_template;
7076 : : }
7077 : 0 : copied_items = flow_hw_prepend_item(items, orig_item_nb, &tag, error);
7078 [ # # ]: 0 : if (!copied_items)
7079 : : return NULL;
7080 : : tmpl_items = copied_items;
7081 : : } else {
7082 : : tmpl_items = items;
7083 : : }
7084 : 0 : setup_pattern_template:
7085 : 0 : it = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*it), 0, rte_socket_id());
7086 [ # # ]: 0 : if (!it) {
7087 [ # # ]: 0 : if (copied_items)
7088 : 0 : mlx5_free(copied_items);
7089 : 0 : rte_flow_error_set(error, ENOMEM,
7090 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7091 : : NULL,
7092 : : "cannot allocate item template");
7093 : 0 : return NULL;
7094 : : }
7095 : 0 : it->attr = *attr;
7096 : 0 : it->orig_item_nb = orig_item_nb;
7097 : 0 : it->mt = mlx5dr_match_template_create(tmpl_items, attr->relaxed_matching);
7098 [ # # ]: 0 : if (!it->mt) {
7099 [ # # ]: 0 : if (copied_items)
7100 : 0 : mlx5_free(copied_items);
7101 : 0 : mlx5_free(it);
7102 : 0 : rte_flow_error_set(error, rte_errno,
7103 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7104 : : NULL,
7105 : : "cannot create match template");
7106 : 0 : return NULL;
7107 : : }
7108 : 0 : it->item_flags = flow_hw_matching_item_flags_get(tmpl_items);
7109 [ # # ]: 0 : if (copied_items) {
7110 [ # # ]: 0 : if (attr->ingress)
7111 : 0 : it->implicit_port = true;
7112 [ # # ]: 0 : else if (attr->egress)
7113 : 0 : it->implicit_tag = true;
7114 : 0 : mlx5_free(copied_items);
7115 : : }
7116 : : /* Either inner or outer, can't both. */
7117 [ # # ]: 0 : if (it->item_flags & (MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT |
7118 : : MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT)) {
7119 [ # # ]: 0 : if (((it->item_flags & MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT) &&
7120 [ # # ]: 0 : (it->item_flags & MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT)) ||
7121 : 0 : (mlx5_alloc_srh_flex_parser(dev))) {
7122 : 0 : claim_zero(mlx5dr_match_template_destroy(it->mt));
7123 : 0 : mlx5_free(it);
7124 : 0 : rte_flow_error_set(error, rte_errno,
7125 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7126 : : "cannot create IPv6 routing extension support");
7127 : 0 : return NULL;
7128 : : }
7129 : : }
7130 [ # # ]: 0 : for (i = 0; items[i].type != RTE_FLOW_ITEM_TYPE_END; ++i) {
7131 [ # # # ]: 0 : switch (items[i].type) {
7132 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX: {
7133 : 0 : const struct rte_flow_item_flex *spec =
7134 : : (const struct rte_flow_item_flex *)items[i].spec;
7135 : 0 : struct rte_flow_item_flex_handle *handle = spec->handle;
7136 : :
7137 [ # # ]: 0 : if (flow_hw_flex_item_acquire(dev, handle, &it->flex_item)) {
7138 : 0 : rte_flow_error_set(error, rte_errno,
7139 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7140 : : "Failed to acquire flex item");
7141 : 0 : goto error;
7142 : : }
7143 : : break;
7144 : : }
7145 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT: {
7146 : 0 : const struct rte_flow_item_geneve_opt *spec = items[i].spec;
7147 : :
7148 [ # # ]: 0 : if (mlx5_geneve_tlv_option_register(priv, spec,
7149 : : &it->geneve_opt_mng)) {
7150 : 0 : rte_flow_error_set(error, rte_errno,
7151 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7152 : : "Failed to register GENEVE TLV option");
7153 : 0 : goto error;
7154 : : }
7155 : : break;
7156 : : }
7157 : : default:
7158 : : break;
7159 : : }
7160 : : }
7161 : 0 : __atomic_fetch_add(&it->refcnt, 1, __ATOMIC_RELAXED);
7162 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_itt, it, next);
7163 : 0 : return it;
7164 : 0 : error:
7165 : 0 : flow_hw_flex_item_release(dev, &it->flex_item);
7166 : 0 : mlx5_geneve_tlv_options_unregister(priv, &it->geneve_opt_mng);
7167 : 0 : claim_zero(mlx5dr_match_template_destroy(it->mt));
7168 : 0 : mlx5_free(it);
7169 : 0 : return NULL;
7170 : : }
7171 : :
7172 : : /**
7173 : : * Destroy flow item template.
7174 : : *
7175 : : * @param[in] dev
7176 : : * Pointer to the rte_eth_dev structure.
7177 : : * @param[in] template
7178 : : * Pointer to the item template to be destroyed.
7179 : : * @param[out] error
7180 : : * Pointer to error structure.
7181 : : *
7182 : : * @return
7183 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7184 : : */
7185 : : static int
7186 : 0 : flow_hw_pattern_template_destroy(struct rte_eth_dev *dev,
7187 : : struct rte_flow_pattern_template *template,
7188 : : struct rte_flow_error *error __rte_unused)
7189 : : {
7190 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7191 : :
7192 [ # # ]: 0 : if (__atomic_load_n(&template->refcnt, __ATOMIC_RELAXED) > 1) {
7193 : 0 : DRV_LOG(WARNING, "Item template %p is still in use.",
7194 : : (void *)template);
7195 : 0 : return rte_flow_error_set(error, EBUSY,
7196 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7197 : : NULL,
7198 : : "item template in using");
7199 : : }
7200 [ # # ]: 0 : if (template->item_flags & (MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT |
7201 : : MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT))
7202 : 0 : mlx5_free_srh_flex_parser(dev);
7203 [ # # ]: 0 : LIST_REMOVE(template, next);
7204 : 0 : flow_hw_flex_item_release(dev, &template->flex_item);
7205 : 0 : mlx5_geneve_tlv_options_unregister(priv, &template->geneve_opt_mng);
7206 : 0 : claim_zero(mlx5dr_match_template_destroy(template->mt));
7207 : 0 : mlx5_free(template);
7208 : 0 : return 0;
7209 : : }
7210 : :
7211 : : /*
7212 : : * Get information about HWS pre-configurable resources.
7213 : : *
7214 : : * @param[in] dev
7215 : : * Pointer to the rte_eth_dev structure.
7216 : : * @param[out] port_info
7217 : : * Pointer to port information.
7218 : : * @param[out] queue_info
7219 : : * Pointer to queue information.
7220 : : * @param[out] error
7221 : : * Pointer to error structure.
7222 : : *
7223 : : * @return
7224 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7225 : : */
7226 : : static int
7227 : 0 : flow_hw_info_get(struct rte_eth_dev *dev,
7228 : : struct rte_flow_port_info *port_info,
7229 : : struct rte_flow_queue_info *queue_info,
7230 : : struct rte_flow_error *error __rte_unused)
7231 : : {
7232 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7233 : 0 : uint16_t port_id = dev->data->port_id;
7234 : : struct rte_mtr_capabilities mtr_cap;
7235 : : int ret;
7236 : :
7237 : : memset(port_info, 0, sizeof(*port_info));
7238 : : /* Queue size is unlimited from low-level. */
7239 : 0 : port_info->max_nb_queues = UINT32_MAX;
7240 : 0 : queue_info->max_size = UINT32_MAX;
7241 : :
7242 : : memset(&mtr_cap, 0, sizeof(struct rte_mtr_capabilities));
7243 : 0 : ret = rte_mtr_capabilities_get(port_id, &mtr_cap, NULL);
7244 [ # # ]: 0 : if (!ret)
7245 : 0 : port_info->max_nb_meters = mtr_cap.n_max;
7246 : 0 : port_info->max_nb_counters = priv->sh->hws_max_nb_counters;
7247 : 0 : port_info->max_nb_aging_objects = port_info->max_nb_counters;
7248 : 0 : return 0;
7249 : : }
7250 : :
7251 : : /**
7252 : : * Create group callback.
7253 : : *
7254 : : * @param[in] tool_ctx
7255 : : * Pointer to the hash list related context.
7256 : : * @param[in] cb_ctx
7257 : : * Pointer to the group creation context.
7258 : : *
7259 : : * @return
7260 : : * Group entry on success, NULL otherwise and rte_errno is set.
7261 : : */
7262 : : struct mlx5_list_entry *
7263 : 0 : flow_hw_grp_create_cb(void *tool_ctx, void *cb_ctx)
7264 : : {
7265 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
7266 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
7267 : 0 : struct rte_eth_dev *dev = ctx->dev;
7268 : 0 : struct rte_flow_attr *attr = (struct rte_flow_attr *)ctx->data;
7269 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7270 : 0 : struct mlx5dr_table_attr dr_tbl_attr = {0};
7271 : 0 : struct rte_flow_error *error = ctx->error;
7272 : : struct mlx5_flow_group *grp_data;
7273 : : struct mlx5dr_table *tbl = NULL;
7274 : : struct mlx5dr_action *jump;
7275 : 0 : uint32_t idx = 0;
7276 : :
7277 : 0 : grp_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_HW_GRP], &idx);
7278 [ # # ]: 0 : if (!grp_data) {
7279 : 0 : rte_flow_error_set(error, ENOMEM,
7280 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7281 : : NULL,
7282 : : "cannot allocate flow table data entry");
7283 : 0 : return NULL;
7284 : : }
7285 : 0 : dr_tbl_attr.level = attr->group;
7286 [ # # ]: 0 : if (attr->transfer)
7287 : 0 : dr_tbl_attr.type = MLX5DR_TABLE_TYPE_FDB;
7288 [ # # ]: 0 : else if (attr->egress)
7289 : 0 : dr_tbl_attr.type = MLX5DR_TABLE_TYPE_NIC_TX;
7290 : : else
7291 : 0 : dr_tbl_attr.type = MLX5DR_TABLE_TYPE_NIC_RX;
7292 : 0 : tbl = mlx5dr_table_create(priv->dr_ctx, &dr_tbl_attr);
7293 [ # # ]: 0 : if (!tbl)
7294 : 0 : goto error;
7295 : 0 : grp_data->tbl = tbl;
7296 [ # # ]: 0 : if (attr->group) {
7297 : : /* Jump action be used by non-root table. */
7298 : 0 : jump = mlx5dr_action_create_dest_table
7299 : : (priv->dr_ctx, tbl,
7300 : 0 : mlx5_hw_act_flag[!!attr->group][dr_tbl_attr.type]);
7301 [ # # ]: 0 : if (!jump)
7302 : 0 : goto error;
7303 : 0 : grp_data->jump.hws_action = jump;
7304 : : /* Jump action be used by root table. */
7305 : 0 : jump = mlx5dr_action_create_dest_table
7306 : : (priv->dr_ctx, tbl,
7307 : : mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_ROOT]
7308 : 0 : [dr_tbl_attr.type]);
7309 [ # # ]: 0 : if (!jump)
7310 : 0 : goto error;
7311 : 0 : grp_data->jump.root_action = jump;
7312 : : }
7313 : 0 : grp_data->dev = dev;
7314 : 0 : grp_data->idx = idx;
7315 : 0 : grp_data->group_id = attr->group;
7316 : 0 : grp_data->type = dr_tbl_attr.type;
7317 : 0 : return &grp_data->entry;
7318 : 0 : error:
7319 [ # # ]: 0 : if (grp_data->jump.root_action)
7320 : 0 : mlx5dr_action_destroy(grp_data->jump.root_action);
7321 [ # # ]: 0 : if (grp_data->jump.hws_action)
7322 : 0 : mlx5dr_action_destroy(grp_data->jump.hws_action);
7323 [ # # ]: 0 : if (tbl)
7324 : 0 : mlx5dr_table_destroy(tbl);
7325 [ # # ]: 0 : if (idx)
7326 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_HW_GRP], idx);
7327 : 0 : rte_flow_error_set(error, ENOMEM,
7328 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7329 : : NULL,
7330 : : "cannot allocate flow dr table");
7331 : 0 : return NULL;
7332 : : }
7333 : :
7334 : : /**
7335 : : * Remove group callback.
7336 : : *
7337 : : * @param[in] tool_ctx
7338 : : * Pointer to the hash list related context.
7339 : : * @param[in] entry
7340 : : * Pointer to the entry to be removed.
7341 : : */
7342 : : void
7343 : 0 : flow_hw_grp_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
7344 : : {
7345 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
7346 : : struct mlx5_flow_group *grp_data =
7347 : : container_of(entry, struct mlx5_flow_group, entry);
7348 : :
7349 : : MLX5_ASSERT(entry && sh);
7350 : : /* To use the wrapper glue functions instead. */
7351 [ # # ]: 0 : if (grp_data->jump.hws_action)
7352 : 0 : mlx5dr_action_destroy(grp_data->jump.hws_action);
7353 [ # # ]: 0 : if (grp_data->jump.root_action)
7354 : 0 : mlx5dr_action_destroy(grp_data->jump.root_action);
7355 : 0 : mlx5dr_table_destroy(grp_data->tbl);
7356 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_HW_GRP], grp_data->idx);
7357 : 0 : }
7358 : :
7359 : : /**
7360 : : * Match group callback.
7361 : : *
7362 : : * @param[in] tool_ctx
7363 : : * Pointer to the hash list related context.
7364 : : * @param[in] entry
7365 : : * Pointer to the group to be matched.
7366 : : * @param[in] cb_ctx
7367 : : * Pointer to the group matching context.
7368 : : *
7369 : : * @return
7370 : : * 0 on matched, 1 on miss matched.
7371 : : */
7372 : : int
7373 : 0 : flow_hw_grp_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
7374 : : void *cb_ctx)
7375 : : {
7376 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
7377 : : struct mlx5_flow_group *grp_data =
7378 : : container_of(entry, struct mlx5_flow_group, entry);
7379 : 0 : struct rte_flow_attr *attr =
7380 : : (struct rte_flow_attr *)ctx->data;
7381 : :
7382 : 0 : return (grp_data->dev != ctx->dev) ||
7383 [ # # ]: 0 : (grp_data->group_id != attr->group) ||
7384 [ # # # # ]: 0 : ((grp_data->type != MLX5DR_TABLE_TYPE_FDB) &&
7385 [ # # ]: 0 : attr->transfer) ||
7386 [ # # ]: 0 : ((grp_data->type != MLX5DR_TABLE_TYPE_NIC_TX) &&
7387 [ # # # # ]: 0 : attr->egress) ||
7388 [ # # ]: 0 : ((grp_data->type != MLX5DR_TABLE_TYPE_NIC_RX) &&
7389 : : attr->ingress);
7390 : : }
7391 : :
7392 : : /**
7393 : : * Clone group entry callback.
7394 : : *
7395 : : * @param[in] tool_ctx
7396 : : * Pointer to the hash list related context.
7397 : : * @param[in] entry
7398 : : * Pointer to the group to be matched.
7399 : : * @param[in] cb_ctx
7400 : : * Pointer to the group matching context.
7401 : : *
7402 : : * @return
7403 : : * 0 on matched, 1 on miss matched.
7404 : : */
7405 : : struct mlx5_list_entry *
7406 : 0 : flow_hw_grp_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
7407 : : void *cb_ctx)
7408 : : {
7409 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
7410 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
7411 : : struct mlx5_flow_group *grp_data;
7412 : 0 : struct rte_flow_error *error = ctx->error;
7413 : 0 : uint32_t idx = 0;
7414 : :
7415 : 0 : grp_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_HW_GRP], &idx);
7416 [ # # ]: 0 : if (!grp_data) {
7417 : 0 : rte_flow_error_set(error, ENOMEM,
7418 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7419 : : NULL,
7420 : : "cannot allocate flow table data entry");
7421 : 0 : return NULL;
7422 : : }
7423 : : memcpy(grp_data, oentry, sizeof(*grp_data));
7424 : 0 : grp_data->idx = idx;
7425 : 0 : return &grp_data->entry;
7426 : : }
7427 : :
7428 : : /**
7429 : : * Free cloned group entry callback.
7430 : : *
7431 : : * @param[in] tool_ctx
7432 : : * Pointer to the hash list related context.
7433 : : * @param[in] entry
7434 : : * Pointer to the group to be freed.
7435 : : */
7436 : : void
7437 : 0 : flow_hw_grp_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
7438 : : {
7439 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
7440 : : struct mlx5_flow_group *grp_data =
7441 : : container_of(entry, struct mlx5_flow_group, entry);
7442 : :
7443 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_HW_GRP], grp_data->idx);
7444 : 0 : }
7445 : :
7446 : : /**
7447 : : * Create and cache a vport action for given @p dev port. vport actions
7448 : : * cache is used in HWS with FDB flows.
7449 : : *
7450 : : * This function does not create any function if proxy port for @p dev port
7451 : : * was not configured for HW Steering.
7452 : : *
7453 : : * This function assumes that E-Switch is enabled and PMD is running with
7454 : : * HW Steering configured.
7455 : : *
7456 : : * @param dev
7457 : : * Pointer to Ethernet device which will be the action destination.
7458 : : *
7459 : : * @return
7460 : : * 0 on success, positive value otherwise.
7461 : : */
7462 : : int
7463 : 0 : flow_hw_create_vport_action(struct rte_eth_dev *dev)
7464 : : {
7465 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7466 : : struct rte_eth_dev *proxy_dev;
7467 : : struct mlx5_priv *proxy_priv;
7468 : 0 : uint16_t port_id = dev->data->port_id;
7469 : 0 : uint16_t proxy_port_id = port_id;
7470 : : int ret;
7471 : :
7472 : 0 : ret = mlx5_flow_pick_transfer_proxy(dev, &proxy_port_id, NULL);
7473 [ # # ]: 0 : if (ret)
7474 : : return ret;
7475 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
7476 : 0 : proxy_priv = proxy_dev->data->dev_private;
7477 [ # # ]: 0 : if (!proxy_priv->hw_vport)
7478 : : return 0;
7479 [ # # ]: 0 : if (proxy_priv->hw_vport[port_id]) {
7480 : 0 : DRV_LOG(ERR, "port %u HWS vport action already created",
7481 : : port_id);
7482 : 0 : return -EINVAL;
7483 : : }
7484 : 0 : proxy_priv->hw_vport[port_id] = mlx5dr_action_create_dest_vport
7485 : : (proxy_priv->dr_ctx, priv->dev_port,
7486 : : MLX5DR_ACTION_FLAG_HWS_FDB);
7487 [ # # ]: 0 : if (!proxy_priv->hw_vport[port_id]) {
7488 : 0 : DRV_LOG(ERR, "port %u unable to create HWS vport action",
7489 : : port_id);
7490 : 0 : return -EINVAL;
7491 : : }
7492 : : return 0;
7493 : : }
7494 : :
7495 : : /**
7496 : : * Destroys the vport action associated with @p dev device
7497 : : * from actions' cache.
7498 : : *
7499 : : * This function does not destroy any action if there is no action cached
7500 : : * for @p dev or proxy port was not configured for HW Steering.
7501 : : *
7502 : : * This function assumes that E-Switch is enabled and PMD is running with
7503 : : * HW Steering configured.
7504 : : *
7505 : : * @param dev
7506 : : * Pointer to Ethernet device which will be the action destination.
7507 : : */
7508 : : void
7509 : 0 : flow_hw_destroy_vport_action(struct rte_eth_dev *dev)
7510 : : {
7511 : : struct rte_eth_dev *proxy_dev;
7512 : : struct mlx5_priv *proxy_priv;
7513 : 0 : uint16_t port_id = dev->data->port_id;
7514 : 0 : uint16_t proxy_port_id = port_id;
7515 : :
7516 [ # # ]: 0 : if (mlx5_flow_pick_transfer_proxy(dev, &proxy_port_id, NULL))
7517 : 0 : return;
7518 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
7519 : 0 : proxy_priv = proxy_dev->data->dev_private;
7520 [ # # # # ]: 0 : if (!proxy_priv->hw_vport || !proxy_priv->hw_vport[port_id])
7521 : : return;
7522 : 0 : mlx5dr_action_destroy(proxy_priv->hw_vport[port_id]);
7523 : 0 : proxy_priv->hw_vport[port_id] = NULL;
7524 : : }
7525 : :
7526 : : static int
7527 : 0 : flow_hw_create_vport_actions(struct mlx5_priv *priv)
7528 : : {
7529 : : uint16_t port_id;
7530 : :
7531 : : MLX5_ASSERT(!priv->hw_vport);
7532 : 0 : priv->hw_vport = mlx5_malloc(MLX5_MEM_ZERO,
7533 : : sizeof(*priv->hw_vport) * RTE_MAX_ETHPORTS,
7534 : : 0, SOCKET_ID_ANY);
7535 [ # # ]: 0 : if (!priv->hw_vport)
7536 : : return -ENOMEM;
7537 : 0 : DRV_LOG(DEBUG, "port %u :: creating vport actions", priv->dev_data->port_id);
7538 : 0 : DRV_LOG(DEBUG, "port %u :: domain_id=%u", priv->dev_data->port_id, priv->domain_id);
7539 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
7540 : 0 : struct mlx5_priv *port_priv = rte_eth_devices[port_id].data->dev_private;
7541 : :
7542 [ # # ]: 0 : if (!port_priv ||
7543 [ # # ]: 0 : port_priv->domain_id != priv->domain_id)
7544 : 0 : continue;
7545 : 0 : DRV_LOG(DEBUG, "port %u :: for port_id=%u, calling mlx5dr_action_create_dest_vport() with ibport=%u",
7546 : : priv->dev_data->port_id, port_id, port_priv->dev_port);
7547 : 0 : priv->hw_vport[port_id] = mlx5dr_action_create_dest_vport
7548 : : (priv->dr_ctx, port_priv->dev_port,
7549 : : MLX5DR_ACTION_FLAG_HWS_FDB);
7550 : 0 : DRV_LOG(DEBUG, "port %u :: priv->hw_vport[%u]=%p",
7551 : : priv->dev_data->port_id, port_id, (void *)priv->hw_vport[port_id]);
7552 [ # # ]: 0 : if (!priv->hw_vport[port_id])
7553 : : return -EINVAL;
7554 : : }
7555 : : return 0;
7556 : : }
7557 : :
7558 : : static void
7559 : 0 : flow_hw_free_vport_actions(struct mlx5_priv *priv)
7560 : : {
7561 : : uint16_t port_id;
7562 : :
7563 [ # # ]: 0 : if (!priv->hw_vport)
7564 : : return;
7565 [ # # ]: 0 : for (port_id = 0; port_id < RTE_MAX_ETHPORTS; ++port_id)
7566 [ # # ]: 0 : if (priv->hw_vport[port_id])
7567 : 0 : mlx5dr_action_destroy(priv->hw_vport[port_id]);
7568 : 0 : mlx5_free(priv->hw_vport);
7569 : 0 : priv->hw_vport = NULL;
7570 : : }
7571 : :
7572 : : static void
7573 : : flow_hw_create_send_to_kernel_actions(struct mlx5_priv *priv __rte_unused)
7574 : : {
7575 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
7576 : : int action_flag;
7577 : : int i;
7578 : : bool is_vf_sf_dev = priv->sh->dev_cap.vf || priv->sh->dev_cap.sf;
7579 : :
7580 : : for (i = MLX5DR_TABLE_TYPE_NIC_RX; i < MLX5DR_TABLE_TYPE_MAX; i++) {
7581 : : if ((!priv->sh->config.dv_esw_en || is_vf_sf_dev) &&
7582 : : i == MLX5DR_TABLE_TYPE_FDB)
7583 : : continue;
7584 : : action_flag = mlx5_hw_act_flag[1][i];
7585 : : priv->hw_send_to_kernel[i] =
7586 : : mlx5dr_action_create_dest_root(priv->dr_ctx,
7587 : : MLX5_HW_LOWEST_PRIO_ROOT,
7588 : : action_flag);
7589 : : if (!priv->hw_send_to_kernel[i]) {
7590 : : DRV_LOG(WARNING, "Unable to create HWS send to kernel action");
7591 : : return;
7592 : : }
7593 : : }
7594 : : #endif
7595 : : }
7596 : :
7597 : : static void
7598 : 0 : flow_hw_destroy_send_to_kernel_action(struct mlx5_priv *priv)
7599 : : {
7600 : : int i;
7601 [ # # ]: 0 : for (i = MLX5DR_TABLE_TYPE_NIC_RX; i < MLX5DR_TABLE_TYPE_MAX; i++) {
7602 [ # # ]: 0 : if (priv->hw_send_to_kernel[i]) {
7603 : 0 : mlx5dr_action_destroy(priv->hw_send_to_kernel[i]);
7604 : 0 : priv->hw_send_to_kernel[i] = NULL;
7605 : : }
7606 : : }
7607 : 0 : }
7608 : :
7609 : : /**
7610 : : * Create an egress pattern template matching on source SQ.
7611 : : *
7612 : : * @param dev
7613 : : * Pointer to Ethernet device.
7614 : : * @param[out] error
7615 : : * Pointer to error structure.
7616 : : *
7617 : : * @return
7618 : : * Pointer to pattern template on success. NULL otherwise, and rte_errno is set.
7619 : : */
7620 : : static struct rte_flow_pattern_template *
7621 : 0 : flow_hw_create_tx_repr_sq_pattern_tmpl(struct rte_eth_dev *dev, struct rte_flow_error *error)
7622 : : {
7623 : 0 : struct rte_flow_pattern_template_attr attr = {
7624 : : .relaxed_matching = 0,
7625 : : .egress = 1,
7626 : : };
7627 : 0 : struct mlx5_rte_flow_item_sq sq_mask = {
7628 : : .queue = UINT32_MAX,
7629 : : };
7630 : 0 : struct rte_flow_item items[] = {
7631 : : {
7632 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7633 : : .mask = &sq_mask,
7634 : : },
7635 : : {
7636 : : .type = RTE_FLOW_ITEM_TYPE_END,
7637 : : },
7638 : : };
7639 : :
7640 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, error);
7641 : : }
7642 : :
7643 : : static __rte_always_inline uint32_t
7644 : : flow_hw_tx_tag_regc_mask(struct rte_eth_dev *dev)
7645 : : {
7646 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7647 : 0 : uint32_t mask = priv->sh->dv_regc0_mask;
7648 : :
7649 : : /* Mask is verified during device initialization. Sanity checking here. */
7650 : : MLX5_ASSERT(mask != 0);
7651 : : /*
7652 : : * Availability of sufficient number of bits in REG_C_0 is verified on initialization.
7653 : : * Sanity checking here.
7654 : : */
7655 : : MLX5_ASSERT(rte_popcount32(mask) >= rte_popcount32(priv->vport_meta_mask));
7656 : : return mask;
7657 : : }
7658 : :
7659 : : static __rte_always_inline uint32_t
7660 : : flow_hw_tx_tag_regc_value(struct rte_eth_dev *dev)
7661 : : {
7662 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7663 : : uint32_t tag;
7664 : :
7665 : : /* Mask is verified during device initialization. Sanity checking here. */
7666 : : MLX5_ASSERT(priv->vport_meta_mask != 0);
7667 [ # # ]: 0 : tag = priv->vport_meta_tag >> (rte_bsf32(priv->vport_meta_mask));
7668 : : /*
7669 : : * Availability of sufficient number of bits in REG_C_0 is verified on initialization.
7670 : : * Sanity checking here.
7671 : : */
7672 : : MLX5_ASSERT((tag & priv->sh->dv_regc0_mask) == tag);
7673 : : return tag;
7674 : : }
7675 : :
7676 : : static void
7677 : : flow_hw_update_action_mask(struct rte_flow_action *action,
7678 : : struct rte_flow_action *mask,
7679 : : enum rte_flow_action_type type,
7680 : : void *conf_v,
7681 : : void *conf_m)
7682 : : {
7683 : 0 : action->type = type;
7684 : 0 : action->conf = conf_v;
7685 : 0 : mask->type = type;
7686 : 0 : mask->conf = conf_m;
7687 : : }
7688 : :
7689 : : /**
7690 : : * Create an egress actions template with MODIFY_FIELD action for setting unused REG_C_0 bits
7691 : : * to vport tag and JUMP action to group 1.
7692 : : *
7693 : : * If extended metadata mode is enabled, then MODIFY_FIELD action for copying software metadata
7694 : : * to REG_C_1 is added as well.
7695 : : *
7696 : : * @param dev
7697 : : * Pointer to Ethernet device.
7698 : : * @param[out] error
7699 : : * Pointer to error structure.
7700 : : *
7701 : : * @return
7702 : : * Pointer to actions template on success. NULL otherwise, and rte_errno is set.
7703 : : */
7704 : : static struct rte_flow_actions_template *
7705 : 0 : flow_hw_create_tx_repr_tag_jump_acts_tmpl(struct rte_eth_dev *dev,
7706 : : struct rte_flow_error *error)
7707 : : {
7708 [ # # ]: 0 : uint32_t tag_mask = flow_hw_tx_tag_regc_mask(dev);
7709 : 0 : uint32_t tag_value = flow_hw_tx_tag_regc_value(dev);
7710 : 0 : struct rte_flow_actions_template_attr attr = {
7711 : : .egress = 1,
7712 : : };
7713 [ # # ]: 0 : struct rte_flow_action_modify_field set_tag_v = {
7714 : : .operation = RTE_FLOW_MODIFY_SET,
7715 : : .dst = {
7716 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
7717 : : .tag_index = REG_C_0,
7718 : : .offset = rte_bsf32(tag_mask),
7719 : : },
7720 : : .src = {
7721 : : .field = RTE_FLOW_FIELD_VALUE,
7722 : : },
7723 : : .width = rte_popcount32(tag_mask),
7724 : : };
7725 : 0 : struct rte_flow_action_modify_field set_tag_m = {
7726 : : .operation = RTE_FLOW_MODIFY_SET,
7727 : : .dst = {
7728 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
7729 : : .level = UINT8_MAX,
7730 : : .tag_index = UINT8_MAX,
7731 : : .offset = UINT32_MAX,
7732 : : },
7733 : : .src = {
7734 : : .field = RTE_FLOW_FIELD_VALUE,
7735 : : },
7736 : : .width = UINT32_MAX,
7737 : : };
7738 : 0 : struct rte_flow_action_modify_field copy_metadata_v = {
7739 : : .operation = RTE_FLOW_MODIFY_SET,
7740 : : .dst = {
7741 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
7742 : : .tag_index = REG_C_1,
7743 : : },
7744 : : .src = {
7745 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
7746 : : .tag_index = REG_A,
7747 : : },
7748 : : .width = 32,
7749 : : };
7750 : 0 : struct rte_flow_action_modify_field copy_metadata_m = {
7751 : : .operation = RTE_FLOW_MODIFY_SET,
7752 : : .dst = {
7753 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
7754 : : .level = UINT8_MAX,
7755 : : .tag_index = UINT8_MAX,
7756 : : .offset = UINT32_MAX,
7757 : : },
7758 : : .src = {
7759 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
7760 : : .level = UINT8_MAX,
7761 : : .tag_index = UINT8_MAX,
7762 : : .offset = UINT32_MAX,
7763 : : },
7764 : : .width = UINT32_MAX,
7765 : : };
7766 : 0 : struct rte_flow_action_jump jump_v = {
7767 : : .group = MLX5_HW_LOWEST_USABLE_GROUP,
7768 : : };
7769 : 0 : struct rte_flow_action_jump jump_m = {
7770 : : .group = UINT32_MAX,
7771 : : };
7772 : 0 : struct rte_flow_action actions_v[4] = { { 0 } };
7773 [ # # ]: 0 : struct rte_flow_action actions_m[4] = { { 0 } };
7774 : : unsigned int idx = 0;
7775 : :
7776 : : rte_memcpy(set_tag_v.src.value, &tag_value, sizeof(tag_value));
7777 : : rte_memcpy(set_tag_m.src.value, &tag_mask, sizeof(tag_mask));
7778 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx],
7779 : : RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
7780 : : &set_tag_v, &set_tag_m);
7781 : : idx++;
7782 [ # # ]: 0 : if (MLX5_SH(dev)->config.dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
7783 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx],
7784 : : RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
7785 : : ©_metadata_v, ©_metadata_m);
7786 : : idx++;
7787 : : }
7788 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx], RTE_FLOW_ACTION_TYPE_JUMP,
7789 : : &jump_v, &jump_m);
7790 : 0 : idx++;
7791 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx], RTE_FLOW_ACTION_TYPE_END,
7792 : : NULL, NULL);
7793 : : idx++;
7794 : : MLX5_ASSERT(idx <= RTE_DIM(actions_v));
7795 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v, actions_m, error);
7796 : : }
7797 : :
7798 : : static void
7799 : 0 : flow_hw_cleanup_tx_repr_tagging(struct rte_eth_dev *dev)
7800 : : {
7801 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7802 : :
7803 [ # # ]: 0 : if (priv->hw_tx_repr_tagging_tbl) {
7804 : 0 : flow_hw_table_destroy(dev, priv->hw_tx_repr_tagging_tbl, NULL);
7805 : 0 : priv->hw_tx_repr_tagging_tbl = NULL;
7806 : : }
7807 [ # # ]: 0 : if (priv->hw_tx_repr_tagging_at) {
7808 : 0 : flow_hw_actions_template_destroy(dev, priv->hw_tx_repr_tagging_at, NULL);
7809 : 0 : priv->hw_tx_repr_tagging_at = NULL;
7810 : : }
7811 [ # # ]: 0 : if (priv->hw_tx_repr_tagging_pt) {
7812 : 0 : flow_hw_pattern_template_destroy(dev, priv->hw_tx_repr_tagging_pt, NULL);
7813 : 0 : priv->hw_tx_repr_tagging_pt = NULL;
7814 : : }
7815 : 0 : }
7816 : :
7817 : : /**
7818 : : * Setup templates and table used to create default Tx flow rules. These default rules
7819 : : * allow for matching Tx representor traffic using a vport tag placed in unused bits of
7820 : : * REG_C_0 register.
7821 : : *
7822 : : * @param dev
7823 : : * Pointer to Ethernet device.
7824 : : * @param[out] error
7825 : : * Pointer to error structure.
7826 : : *
7827 : : * @return
7828 : : * 0 on success, negative errno value otherwise.
7829 : : */
7830 : : static int
7831 : 0 : flow_hw_setup_tx_repr_tagging(struct rte_eth_dev *dev, struct rte_flow_error *error)
7832 : : {
7833 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7834 : 0 : struct rte_flow_template_table_attr attr = {
7835 : : .flow_attr = {
7836 : : .group = 0,
7837 : : .priority = MLX5_HW_LOWEST_PRIO_ROOT,
7838 : : .egress = 1,
7839 : : },
7840 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
7841 : : };
7842 : 0 : struct mlx5_flow_template_table_cfg cfg = {
7843 : : .attr = attr,
7844 : : .external = false,
7845 : : };
7846 : :
7847 : : MLX5_ASSERT(priv->sh->config.dv_esw_en);
7848 : : MLX5_ASSERT(priv->sh->config.repr_matching);
7849 : 0 : priv->hw_tx_repr_tagging_pt =
7850 : 0 : flow_hw_create_tx_repr_sq_pattern_tmpl(dev, error);
7851 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_pt)
7852 : 0 : goto err;
7853 : 0 : priv->hw_tx_repr_tagging_at =
7854 : 0 : flow_hw_create_tx_repr_tag_jump_acts_tmpl(dev, error);
7855 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_at)
7856 : 0 : goto err;
7857 : 0 : priv->hw_tx_repr_tagging_tbl = flow_hw_table_create(dev, &cfg,
7858 : : &priv->hw_tx_repr_tagging_pt, 1,
7859 : : &priv->hw_tx_repr_tagging_at, 1,
7860 : : error);
7861 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_tbl)
7862 : 0 : goto err;
7863 : : return 0;
7864 : 0 : err:
7865 : 0 : flow_hw_cleanup_tx_repr_tagging(dev);
7866 : 0 : return -rte_errno;
7867 : : }
7868 : :
7869 : : static uint32_t
7870 : : flow_hw_esw_mgr_regc_marker_mask(struct rte_eth_dev *dev)
7871 : : {
7872 : 0 : uint32_t mask = MLX5_SH(dev)->dv_regc0_mask;
7873 : :
7874 : : /* Mask is verified during device initialization. */
7875 : : MLX5_ASSERT(mask != 0);
7876 : : return mask;
7877 : : }
7878 : :
7879 : : static uint32_t
7880 : : flow_hw_esw_mgr_regc_marker(struct rte_eth_dev *dev)
7881 : : {
7882 : 0 : uint32_t mask = MLX5_SH(dev)->dv_regc0_mask;
7883 : :
7884 : : /* Mask is verified during device initialization. */
7885 : : MLX5_ASSERT(mask != 0);
7886 : 0 : return RTE_BIT32(rte_bsf32(mask));
7887 : : }
7888 : :
7889 : : /**
7890 : : * Creates a flow pattern template used to match on E-Switch Manager.
7891 : : * This template is used to set up a table for SQ miss default flow.
7892 : : *
7893 : : * @param dev
7894 : : * Pointer to Ethernet device.
7895 : : * @param error
7896 : : * Pointer to error structure.
7897 : : *
7898 : : * @return
7899 : : * Pointer to flow pattern template on success, NULL otherwise.
7900 : : */
7901 : : static struct rte_flow_pattern_template *
7902 : 0 : flow_hw_create_ctrl_esw_mgr_pattern_template(struct rte_eth_dev *dev,
7903 : : struct rte_flow_error *error)
7904 : : {
7905 : 0 : struct rte_flow_pattern_template_attr attr = {
7906 : : .relaxed_matching = 0,
7907 : : .transfer = 1,
7908 : : };
7909 : 0 : struct rte_flow_item_ethdev port_spec = {
7910 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
7911 : : };
7912 : 0 : struct rte_flow_item_ethdev port_mask = {
7913 : : .port_id = UINT16_MAX,
7914 : : };
7915 : 0 : struct mlx5_rte_flow_item_sq sq_mask = {
7916 : : .queue = UINT32_MAX,
7917 : : };
7918 : 0 : struct rte_flow_item items[] = {
7919 : : {
7920 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
7921 : : .spec = &port_spec,
7922 : : .mask = &port_mask,
7923 : : },
7924 : : {
7925 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7926 : : .mask = &sq_mask,
7927 : : },
7928 : : {
7929 : : .type = RTE_FLOW_ITEM_TYPE_END,
7930 : : },
7931 : : };
7932 : :
7933 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, error);
7934 : : }
7935 : :
7936 : : /**
7937 : : * Creates a flow pattern template used to match REG_C_0 and a SQ.
7938 : : * Matching on REG_C_0 is set up to match on all bits usable by user-space.
7939 : : * If traffic was sent from E-Switch Manager, then all usable bits will be set to 0,
7940 : : * except the least significant bit, which will be set to 1.
7941 : : *
7942 : : * This template is used to set up a table for SQ miss default flow.
7943 : : *
7944 : : * @param dev
7945 : : * Pointer to Ethernet device.
7946 : : * @param error
7947 : : * Pointer to error structure.
7948 : : *
7949 : : * @return
7950 : : * Pointer to flow pattern template on success, NULL otherwise.
7951 : : */
7952 : : static struct rte_flow_pattern_template *
7953 : 0 : flow_hw_create_ctrl_regc_sq_pattern_template(struct rte_eth_dev *dev,
7954 : : struct rte_flow_error *error)
7955 : : {
7956 : 0 : struct rte_flow_pattern_template_attr attr = {
7957 : : .relaxed_matching = 0,
7958 : : .transfer = 1,
7959 : : };
7960 : 0 : struct rte_flow_item_tag reg_c0_spec = {
7961 : : .index = (uint8_t)REG_C_0,
7962 : : };
7963 : 0 : struct rte_flow_item_tag reg_c0_mask = {
7964 : : .index = 0xff,
7965 : : .data = flow_hw_esw_mgr_regc_marker_mask(dev),
7966 : : };
7967 : 0 : struct mlx5_rte_flow_item_sq queue_mask = {
7968 : : .queue = UINT32_MAX,
7969 : : };
7970 : 0 : struct rte_flow_item items[] = {
7971 : : {
7972 : : .type = (enum rte_flow_item_type)
7973 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
7974 : : .spec = ®_c0_spec,
7975 : : .mask = ®_c0_mask,
7976 : : },
7977 : : {
7978 : : .type = (enum rte_flow_item_type)
7979 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7980 : : .mask = &queue_mask,
7981 : : },
7982 : : {
7983 : : .type = RTE_FLOW_ITEM_TYPE_END,
7984 : : },
7985 : : };
7986 : :
7987 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, error);
7988 : : }
7989 : :
7990 : : /**
7991 : : * Creates a flow pattern template with unmasked represented port matching.
7992 : : * This template is used to set up a table for default transfer flows
7993 : : * directing packets to group 1.
7994 : : *
7995 : : * @param dev
7996 : : * Pointer to Ethernet device.
7997 : : * @param error
7998 : : * Pointer to error structure.
7999 : : *
8000 : : * @return
8001 : : * Pointer to flow pattern template on success, NULL otherwise.
8002 : : */
8003 : : static struct rte_flow_pattern_template *
8004 : 0 : flow_hw_create_ctrl_port_pattern_template(struct rte_eth_dev *dev,
8005 : : struct rte_flow_error *error)
8006 : : {
8007 : 0 : struct rte_flow_pattern_template_attr attr = {
8008 : : .relaxed_matching = 0,
8009 : : .transfer = 1,
8010 : : };
8011 : 0 : struct rte_flow_item_ethdev port_mask = {
8012 : : .port_id = UINT16_MAX,
8013 : : };
8014 : 0 : struct rte_flow_item items[] = {
8015 : : {
8016 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
8017 : : .mask = &port_mask,
8018 : : },
8019 : : {
8020 : : .type = RTE_FLOW_ITEM_TYPE_END,
8021 : : },
8022 : : };
8023 : :
8024 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, error);
8025 : : }
8026 : :
8027 : : /*
8028 : : * Creating a flow pattern template with all ETH packets matching.
8029 : : * This template is used to set up a table for default Tx copy (Tx metadata
8030 : : * to REG_C_1) flow rule usage.
8031 : : *
8032 : : * @param dev
8033 : : * Pointer to Ethernet device.
8034 : : * @param error
8035 : : * Pointer to error structure.
8036 : : *
8037 : : * @return
8038 : : * Pointer to flow pattern template on success, NULL otherwise.
8039 : : */
8040 : : static struct rte_flow_pattern_template *
8041 : 0 : flow_hw_create_tx_default_mreg_copy_pattern_template(struct rte_eth_dev *dev,
8042 : : struct rte_flow_error *error)
8043 : : {
8044 : 0 : struct rte_flow_pattern_template_attr tx_pa_attr = {
8045 : : .relaxed_matching = 0,
8046 : : .egress = 1,
8047 : : };
8048 : 0 : struct rte_flow_item_eth promisc = {
8049 : : .hdr.dst_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
8050 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
8051 : : .hdr.ether_type = 0,
8052 : : };
8053 : 0 : struct rte_flow_item eth_all[] = {
8054 : : [0] = {
8055 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8056 : : .spec = &promisc,
8057 : : .mask = &promisc,
8058 : : },
8059 : : [1] = {
8060 : : .type = RTE_FLOW_ITEM_TYPE_END,
8061 : : },
8062 : : };
8063 : :
8064 : 0 : return flow_hw_pattern_template_create(dev, &tx_pa_attr, eth_all, error);
8065 : : }
8066 : :
8067 : : /*
8068 : : * Creating a flow pattern template with all LACP packets matching, only for NIC
8069 : : * ingress domain.
8070 : : *
8071 : : * @param dev
8072 : : * Pointer to Ethernet device.
8073 : : * @param error
8074 : : * Pointer to error structure.
8075 : : *
8076 : : * @return
8077 : : * Pointer to flow pattern template on success, NULL otherwise.
8078 : : */
8079 : : static struct rte_flow_pattern_template *
8080 : 0 : flow_hw_create_lacp_rx_pattern_template(struct rte_eth_dev *dev, struct rte_flow_error *error)
8081 : : {
8082 : 0 : struct rte_flow_pattern_template_attr pa_attr = {
8083 : : .relaxed_matching = 0,
8084 : : .ingress = 1,
8085 : : };
8086 : 0 : struct rte_flow_item_eth lacp_mask = {
8087 : : .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
8088 : : .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
8089 : : .type = 0xFFFF,
8090 : : };
8091 : 0 : struct rte_flow_item eth_all[] = {
8092 : : [0] = {
8093 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8094 : : .mask = &lacp_mask,
8095 : : },
8096 : : [1] = {
8097 : : .type = RTE_FLOW_ITEM_TYPE_END,
8098 : : },
8099 : : };
8100 : 0 : return flow_hw_pattern_template_create(dev, &pa_attr, eth_all, error);
8101 : : }
8102 : :
8103 : : /**
8104 : : * Creates a flow actions template with modify field action and masked jump action.
8105 : : * Modify field action sets the least significant bit of REG_C_0 (usable by user-space)
8106 : : * to 1, meaning that packet was originated from E-Switch Manager. Jump action
8107 : : * transfers steering to group 1.
8108 : : *
8109 : : * @param dev
8110 : : * Pointer to Ethernet device.
8111 : : * @param error
8112 : : * Pointer to error structure.
8113 : : *
8114 : : * @return
8115 : : * Pointer to flow actions template on success, NULL otherwise.
8116 : : */
8117 : : static struct rte_flow_actions_template *
8118 : 0 : flow_hw_create_ctrl_regc_jump_actions_template(struct rte_eth_dev *dev,
8119 : : struct rte_flow_error *error)
8120 : : {
8121 [ # # ]: 0 : uint32_t marker_mask = flow_hw_esw_mgr_regc_marker_mask(dev);
8122 : 0 : uint32_t marker_bits = flow_hw_esw_mgr_regc_marker(dev);
8123 : 0 : struct rte_flow_actions_template_attr attr = {
8124 : : .transfer = 1,
8125 : : };
8126 [ # # ]: 0 : struct rte_flow_action_modify_field set_reg_v = {
8127 : : .operation = RTE_FLOW_MODIFY_SET,
8128 : : .dst = {
8129 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
8130 : : .tag_index = REG_C_0,
8131 : : },
8132 : : .src = {
8133 : : .field = RTE_FLOW_FIELD_VALUE,
8134 : : },
8135 : : .width = rte_popcount32(marker_mask),
8136 : : };
8137 : 0 : struct rte_flow_action_modify_field set_reg_m = {
8138 : : .operation = RTE_FLOW_MODIFY_SET,
8139 : : .dst = {
8140 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
8141 : : .level = UINT8_MAX,
8142 : : .tag_index = UINT8_MAX,
8143 : : .offset = UINT32_MAX,
8144 : : },
8145 : : .src = {
8146 : : .field = RTE_FLOW_FIELD_VALUE,
8147 : : },
8148 : : .width = UINT32_MAX,
8149 : : };
8150 : 0 : struct rte_flow_action_jump jump_v = {
8151 : : .group = MLX5_HW_LOWEST_USABLE_GROUP,
8152 : : };
8153 : 0 : struct rte_flow_action_jump jump_m = {
8154 : : .group = UINT32_MAX,
8155 : : };
8156 : 0 : struct rte_flow_action actions_v[] = {
8157 : : {
8158 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8159 : : .conf = &set_reg_v,
8160 : : },
8161 : : {
8162 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
8163 : : .conf = &jump_v,
8164 : : },
8165 : : {
8166 : : .type = RTE_FLOW_ACTION_TYPE_END,
8167 : : }
8168 : : };
8169 : 0 : struct rte_flow_action actions_m[] = {
8170 : : {
8171 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8172 : : .conf = &set_reg_m,
8173 : : },
8174 : : {
8175 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
8176 : : .conf = &jump_m,
8177 : : },
8178 : : {
8179 : : .type = RTE_FLOW_ACTION_TYPE_END,
8180 : : }
8181 : : };
8182 : :
8183 [ # # ]: 0 : set_reg_v.dst.offset = rte_bsf32(marker_mask);
8184 : : rte_memcpy(set_reg_v.src.value, &marker_bits, sizeof(marker_bits));
8185 : : rte_memcpy(set_reg_m.src.value, &marker_mask, sizeof(marker_mask));
8186 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v, actions_m, error);
8187 : : }
8188 : :
8189 : : /**
8190 : : * Creates a flow actions template with an unmasked JUMP action. Flows
8191 : : * based on this template will perform a jump to some group. This template
8192 : : * is used to set up tables for control flows.
8193 : : *
8194 : : * @param dev
8195 : : * Pointer to Ethernet device.
8196 : : * @param group
8197 : : * Destination group for this action template.
8198 : : * @param error
8199 : : * Pointer to error structure.
8200 : : *
8201 : : * @return
8202 : : * Pointer to flow actions template on success, NULL otherwise.
8203 : : */
8204 : : static struct rte_flow_actions_template *
8205 : 0 : flow_hw_create_ctrl_jump_actions_template(struct rte_eth_dev *dev,
8206 : : uint32_t group,
8207 : : struct rte_flow_error *error)
8208 : : {
8209 : 0 : struct rte_flow_actions_template_attr attr = {
8210 : : .transfer = 1,
8211 : : };
8212 : 0 : struct rte_flow_action_jump jump_v = {
8213 : : .group = group,
8214 : : };
8215 : 0 : struct rte_flow_action_jump jump_m = {
8216 : : .group = UINT32_MAX,
8217 : : };
8218 : 0 : struct rte_flow_action actions_v[] = {
8219 : : {
8220 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
8221 : : .conf = &jump_v,
8222 : : },
8223 : : {
8224 : : .type = RTE_FLOW_ACTION_TYPE_END,
8225 : : }
8226 : : };
8227 : 0 : struct rte_flow_action actions_m[] = {
8228 : : {
8229 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
8230 : : .conf = &jump_m,
8231 : : },
8232 : : {
8233 : : .type = RTE_FLOW_ACTION_TYPE_END,
8234 : : }
8235 : : };
8236 : :
8237 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v,
8238 : : actions_m, error);
8239 : : }
8240 : :
8241 : : /**
8242 : : * Creates a flow action template with a unmasked REPRESENTED_PORT action.
8243 : : * It is used to create control flow tables.
8244 : : *
8245 : : * @param dev
8246 : : * Pointer to Ethernet device.
8247 : : * @param error
8248 : : * Pointer to error structure.
8249 : : *
8250 : : * @return
8251 : : * Pointer to flow action template on success, NULL otherwise.
8252 : : */
8253 : : static struct rte_flow_actions_template *
8254 : 0 : flow_hw_create_ctrl_port_actions_template(struct rte_eth_dev *dev,
8255 : : struct rte_flow_error *error)
8256 : : {
8257 : 0 : struct rte_flow_actions_template_attr attr = {
8258 : : .transfer = 1,
8259 : : };
8260 : 0 : struct rte_flow_action_ethdev port_v = {
8261 : : .port_id = 0,
8262 : : };
8263 : 0 : struct rte_flow_action actions_v[] = {
8264 : : {
8265 : : .type = RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
8266 : : .conf = &port_v,
8267 : : },
8268 : : {
8269 : : .type = RTE_FLOW_ACTION_TYPE_END,
8270 : : }
8271 : : };
8272 : 0 : struct rte_flow_action_ethdev port_m = {
8273 : : .port_id = 0,
8274 : : };
8275 : 0 : struct rte_flow_action actions_m[] = {
8276 : : {
8277 : : .type = RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
8278 : : .conf = &port_m,
8279 : : },
8280 : : {
8281 : : .type = RTE_FLOW_ACTION_TYPE_END,
8282 : : }
8283 : : };
8284 : :
8285 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v, actions_m, error);
8286 : : }
8287 : :
8288 : : /*
8289 : : * Creating an actions template to use header modify action for register
8290 : : * copying. This template is used to set up a table for copy flow.
8291 : : *
8292 : : * @param dev
8293 : : * Pointer to Ethernet device.
8294 : : * @param error
8295 : : * Pointer to error structure.
8296 : : *
8297 : : * @return
8298 : : * Pointer to flow actions template on success, NULL otherwise.
8299 : : */
8300 : : static struct rte_flow_actions_template *
8301 : 0 : flow_hw_create_tx_default_mreg_copy_actions_template(struct rte_eth_dev *dev,
8302 : : struct rte_flow_error *error)
8303 : : {
8304 : 0 : struct rte_flow_actions_template_attr tx_act_attr = {
8305 : : .egress = 1,
8306 : : };
8307 : 0 : const struct rte_flow_action_modify_field mreg_action = {
8308 : : .operation = RTE_FLOW_MODIFY_SET,
8309 : : .dst = {
8310 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
8311 : : .tag_index = REG_C_1,
8312 : : },
8313 : : .src = {
8314 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
8315 : : .tag_index = REG_A,
8316 : : },
8317 : : .width = 32,
8318 : : };
8319 : 0 : const struct rte_flow_action_modify_field mreg_mask = {
8320 : : .operation = RTE_FLOW_MODIFY_SET,
8321 : : .dst = {
8322 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
8323 : : .level = UINT8_MAX,
8324 : : .tag_index = UINT8_MAX,
8325 : : .offset = UINT32_MAX,
8326 : : },
8327 : : .src = {
8328 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
8329 : : .level = UINT8_MAX,
8330 : : .tag_index = UINT8_MAX,
8331 : : .offset = UINT32_MAX,
8332 : : },
8333 : : .width = UINT32_MAX,
8334 : : };
8335 : 0 : const struct rte_flow_action_jump jump_action = {
8336 : : .group = 1,
8337 : : };
8338 : 0 : const struct rte_flow_action_jump jump_mask = {
8339 : : .group = UINT32_MAX,
8340 : : };
8341 : 0 : const struct rte_flow_action actions[] = {
8342 : : [0] = {
8343 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8344 : : .conf = &mreg_action,
8345 : : },
8346 : : [1] = {
8347 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
8348 : : .conf = &jump_action,
8349 : : },
8350 : : [2] = {
8351 : : .type = RTE_FLOW_ACTION_TYPE_END,
8352 : : },
8353 : : };
8354 : 0 : const struct rte_flow_action masks[] = {
8355 : : [0] = {
8356 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8357 : : .conf = &mreg_mask,
8358 : : },
8359 : : [1] = {
8360 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
8361 : : .conf = &jump_mask,
8362 : : },
8363 : : [2] = {
8364 : : .type = RTE_FLOW_ACTION_TYPE_END,
8365 : : },
8366 : : };
8367 : :
8368 : 0 : return flow_hw_actions_template_create(dev, &tx_act_attr, actions,
8369 : : masks, error);
8370 : : }
8371 : :
8372 : : /*
8373 : : * Creating an actions template to use default miss to re-route packets to the
8374 : : * kernel driver stack.
8375 : : * On root table, only DEFAULT_MISS action can be used.
8376 : : *
8377 : : * @param dev
8378 : : * Pointer to Ethernet device.
8379 : : * @param error
8380 : : * Pointer to error structure.
8381 : : *
8382 : : * @return
8383 : : * Pointer to flow actions template on success, NULL otherwise.
8384 : : */
8385 : : static struct rte_flow_actions_template *
8386 : 0 : flow_hw_create_lacp_rx_actions_template(struct rte_eth_dev *dev, struct rte_flow_error *error)
8387 : : {
8388 : 0 : struct rte_flow_actions_template_attr act_attr = {
8389 : : .ingress = 1,
8390 : : };
8391 : 0 : const struct rte_flow_action actions[] = {
8392 : : [0] = {
8393 : : .type = (enum rte_flow_action_type)
8394 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
8395 : : },
8396 : : [1] = {
8397 : : .type = RTE_FLOW_ACTION_TYPE_END,
8398 : : },
8399 : : };
8400 : :
8401 : 0 : return flow_hw_actions_template_create(dev, &act_attr, actions, actions, error);
8402 : : }
8403 : :
8404 : : /**
8405 : : * Creates a control flow table used to transfer traffic from E-Switch Manager
8406 : : * and TX queues from group 0 to group 1.
8407 : : *
8408 : : * @param dev
8409 : : * Pointer to Ethernet device.
8410 : : * @param it
8411 : : * Pointer to flow pattern template.
8412 : : * @param at
8413 : : * Pointer to flow actions template.
8414 : : * @param error
8415 : : * Pointer to error structure.
8416 : : *
8417 : : * @return
8418 : : * Pointer to flow table on success, NULL otherwise.
8419 : : */
8420 : : static struct rte_flow_template_table*
8421 : 0 : flow_hw_create_ctrl_sq_miss_root_table(struct rte_eth_dev *dev,
8422 : : struct rte_flow_pattern_template *it,
8423 : : struct rte_flow_actions_template *at,
8424 : : struct rte_flow_error *error)
8425 : : {
8426 : 0 : struct rte_flow_template_table_attr attr = {
8427 : : .flow_attr = {
8428 : : .group = 0,
8429 : : .priority = MLX5_HW_LOWEST_PRIO_ROOT,
8430 : : .ingress = 0,
8431 : : .egress = 0,
8432 : : .transfer = 1,
8433 : : },
8434 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
8435 : : };
8436 : 0 : struct mlx5_flow_template_table_cfg cfg = {
8437 : : .attr = attr,
8438 : : .external = false,
8439 : : };
8440 : :
8441 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
8442 : : }
8443 : :
8444 : :
8445 : : /**
8446 : : * Creates a control flow table used to transfer traffic from E-Switch Manager
8447 : : * and TX queues from group 0 to group 1.
8448 : : *
8449 : : * @param dev
8450 : : * Pointer to Ethernet device.
8451 : : * @param it
8452 : : * Pointer to flow pattern template.
8453 : : * @param at
8454 : : * Pointer to flow actions template.
8455 : : * @param error
8456 : : * Pointer to error structure.
8457 : : *
8458 : : * @return
8459 : : * Pointer to flow table on success, NULL otherwise.
8460 : : */
8461 : : static struct rte_flow_template_table*
8462 : 0 : flow_hw_create_ctrl_sq_miss_table(struct rte_eth_dev *dev,
8463 : : struct rte_flow_pattern_template *it,
8464 : : struct rte_flow_actions_template *at,
8465 : : struct rte_flow_error *error)
8466 : : {
8467 : 0 : struct rte_flow_template_table_attr attr = {
8468 : : .flow_attr = {
8469 : : .group = 1,
8470 : : .priority = MLX5_HW_LOWEST_PRIO_NON_ROOT,
8471 : : .ingress = 0,
8472 : : .egress = 0,
8473 : : .transfer = 1,
8474 : : },
8475 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
8476 : : };
8477 : 0 : struct mlx5_flow_template_table_cfg cfg = {
8478 : : .attr = attr,
8479 : : .external = false,
8480 : : };
8481 : :
8482 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
8483 : : }
8484 : :
8485 : : /*
8486 : : * Creating the default Tx metadata copy table on NIC Tx group 0.
8487 : : *
8488 : : * @param dev
8489 : : * Pointer to Ethernet device.
8490 : : * @param pt
8491 : : * Pointer to flow pattern template.
8492 : : * @param at
8493 : : * Pointer to flow actions template.
8494 : : * @param error
8495 : : * Pointer to error structure.
8496 : : *
8497 : : * @return
8498 : : * Pointer to flow table on success, NULL otherwise.
8499 : : */
8500 : : static struct rte_flow_template_table*
8501 : 0 : flow_hw_create_tx_default_mreg_copy_table(struct rte_eth_dev *dev,
8502 : : struct rte_flow_pattern_template *pt,
8503 : : struct rte_flow_actions_template *at,
8504 : : struct rte_flow_error *error)
8505 : : {
8506 : 0 : struct rte_flow_template_table_attr tx_tbl_attr = {
8507 : : .flow_attr = {
8508 : : .group = 0, /* Root */
8509 : : .priority = MLX5_HW_LOWEST_PRIO_ROOT,
8510 : : .egress = 1,
8511 : : },
8512 : : .nb_flows = 1, /* One default flow rule for all. */
8513 : : };
8514 : 0 : struct mlx5_flow_template_table_cfg tx_tbl_cfg = {
8515 : : .attr = tx_tbl_attr,
8516 : : .external = false,
8517 : : };
8518 : :
8519 : 0 : return flow_hw_table_create(dev, &tx_tbl_cfg, &pt, 1, &at, 1, error);
8520 : : }
8521 : :
8522 : : /**
8523 : : * Creates a control flow table used to transfer traffic
8524 : : * from group 0 to group 1.
8525 : : *
8526 : : * @param dev
8527 : : * Pointer to Ethernet device.
8528 : : * @param it
8529 : : * Pointer to flow pattern template.
8530 : : * @param at
8531 : : * Pointer to flow actions template.
8532 : : * @param error
8533 : : * Pointer to error structure.
8534 : : *
8535 : : * @return
8536 : : * Pointer to flow table on success, NULL otherwise.
8537 : : */
8538 : : static struct rte_flow_template_table *
8539 : 0 : flow_hw_create_ctrl_jump_table(struct rte_eth_dev *dev,
8540 : : struct rte_flow_pattern_template *it,
8541 : : struct rte_flow_actions_template *at,
8542 : : struct rte_flow_error *error)
8543 : : {
8544 : 0 : struct rte_flow_template_table_attr attr = {
8545 : : .flow_attr = {
8546 : : .group = 0,
8547 : : .priority = 0,
8548 : : .ingress = 0,
8549 : : .egress = 0,
8550 : : .transfer = 1,
8551 : : },
8552 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
8553 : : };
8554 : 0 : struct mlx5_flow_template_table_cfg cfg = {
8555 : : .attr = attr,
8556 : : .external = false,
8557 : : };
8558 : :
8559 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
8560 : : }
8561 : :
8562 : : /*
8563 : : * Create a table on the root group to for the LACP traffic redirecting.
8564 : : *
8565 : : * @param dev
8566 : : * Pointer to Ethernet device.
8567 : : * @param it
8568 : : * Pointer to flow pattern template.
8569 : : * @param at
8570 : : * Pointer to flow actions template.
8571 : : *
8572 : : * @return
8573 : : * Pointer to flow table on success, NULL otherwise.
8574 : : */
8575 : : static struct rte_flow_template_table *
8576 : 0 : flow_hw_create_lacp_rx_table(struct rte_eth_dev *dev,
8577 : : struct rte_flow_pattern_template *it,
8578 : : struct rte_flow_actions_template *at,
8579 : : struct rte_flow_error *error)
8580 : : {
8581 : 0 : struct rte_flow_template_table_attr attr = {
8582 : : .flow_attr = {
8583 : : .group = 0,
8584 : : .priority = 0,
8585 : : .ingress = 1,
8586 : : .egress = 0,
8587 : : .transfer = 0,
8588 : : },
8589 : : .nb_flows = 1,
8590 : : };
8591 : 0 : struct mlx5_flow_template_table_cfg cfg = {
8592 : : .attr = attr,
8593 : : .external = false,
8594 : : };
8595 : :
8596 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
8597 : : }
8598 : :
8599 : : /**
8600 : : * Creates a set of flow tables used to create control flows used
8601 : : * when E-Switch is engaged.
8602 : : *
8603 : : * @param dev
8604 : : * Pointer to Ethernet device.
8605 : : * @param error
8606 : : * Pointer to error structure.
8607 : : *
8608 : : * @return
8609 : : * 0 on success, negative values otherwise
8610 : : */
8611 : : static __rte_unused int
8612 : 0 : flow_hw_create_ctrl_tables(struct rte_eth_dev *dev, struct rte_flow_error *error)
8613 : : {
8614 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8615 : : struct rte_flow_pattern_template *esw_mgr_items_tmpl = NULL;
8616 : : struct rte_flow_pattern_template *regc_sq_items_tmpl = NULL;
8617 : : struct rte_flow_pattern_template *port_items_tmpl = NULL;
8618 : : struct rte_flow_pattern_template *tx_meta_items_tmpl = NULL;
8619 : : struct rte_flow_pattern_template *lacp_rx_items_tmpl = NULL;
8620 : : struct rte_flow_actions_template *regc_jump_actions_tmpl = NULL;
8621 : : struct rte_flow_actions_template *port_actions_tmpl = NULL;
8622 : : struct rte_flow_actions_template *jump_one_actions_tmpl = NULL;
8623 : : struct rte_flow_actions_template *tx_meta_actions_tmpl = NULL;
8624 : : struct rte_flow_actions_template *lacp_rx_actions_tmpl = NULL;
8625 : 0 : uint32_t xmeta = priv->sh->config.dv_xmeta_en;
8626 : 0 : uint32_t repr_matching = priv->sh->config.repr_matching;
8627 : : int ret;
8628 : :
8629 : : /* Create templates and table for default SQ miss flow rules - root table. */
8630 : 0 : esw_mgr_items_tmpl = flow_hw_create_ctrl_esw_mgr_pattern_template(dev, error);
8631 [ # # ]: 0 : if (!esw_mgr_items_tmpl) {
8632 : 0 : DRV_LOG(ERR, "port %u failed to create E-Switch Manager item"
8633 : : " template for control flows", dev->data->port_id);
8634 : 0 : goto err;
8635 : : }
8636 : 0 : regc_jump_actions_tmpl = flow_hw_create_ctrl_regc_jump_actions_template(dev, error);
8637 [ # # ]: 0 : if (!regc_jump_actions_tmpl) {
8638 : 0 : DRV_LOG(ERR, "port %u failed to create REG_C set and jump action template"
8639 : : " for control flows", dev->data->port_id);
8640 : 0 : goto err;
8641 : : }
8642 : : MLX5_ASSERT(priv->hw_esw_sq_miss_root_tbl == NULL);
8643 : 0 : priv->hw_esw_sq_miss_root_tbl = flow_hw_create_ctrl_sq_miss_root_table
8644 : : (dev, esw_mgr_items_tmpl, regc_jump_actions_tmpl, error);
8645 [ # # ]: 0 : if (!priv->hw_esw_sq_miss_root_tbl) {
8646 : 0 : DRV_LOG(ERR, "port %u failed to create table for default sq miss (root table)"
8647 : : " for control flows", dev->data->port_id);
8648 : 0 : goto err;
8649 : : }
8650 : : /* Create templates and table for default SQ miss flow rules - non-root table. */
8651 : 0 : regc_sq_items_tmpl = flow_hw_create_ctrl_regc_sq_pattern_template(dev, error);
8652 [ # # ]: 0 : if (!regc_sq_items_tmpl) {
8653 : 0 : DRV_LOG(ERR, "port %u failed to create SQ item template for"
8654 : : " control flows", dev->data->port_id);
8655 : 0 : goto err;
8656 : : }
8657 : 0 : port_actions_tmpl = flow_hw_create_ctrl_port_actions_template(dev, error);
8658 [ # # ]: 0 : if (!port_actions_tmpl) {
8659 : 0 : DRV_LOG(ERR, "port %u failed to create port action template"
8660 : : " for control flows", dev->data->port_id);
8661 : 0 : goto err;
8662 : : }
8663 : : MLX5_ASSERT(priv->hw_esw_sq_miss_tbl == NULL);
8664 : 0 : priv->hw_esw_sq_miss_tbl = flow_hw_create_ctrl_sq_miss_table(dev, regc_sq_items_tmpl,
8665 : : port_actions_tmpl, error);
8666 [ # # ]: 0 : if (!priv->hw_esw_sq_miss_tbl) {
8667 : 0 : DRV_LOG(ERR, "port %u failed to create table for default sq miss (non-root table)"
8668 : : " for control flows", dev->data->port_id);
8669 : 0 : goto err;
8670 : : }
8671 : : /* Create templates and table for default FDB jump flow rules. */
8672 : 0 : port_items_tmpl = flow_hw_create_ctrl_port_pattern_template(dev, error);
8673 [ # # ]: 0 : if (!port_items_tmpl) {
8674 : 0 : DRV_LOG(ERR, "port %u failed to create SQ item template for"
8675 : : " control flows", dev->data->port_id);
8676 : 0 : goto err;
8677 : : }
8678 : 0 : jump_one_actions_tmpl = flow_hw_create_ctrl_jump_actions_template
8679 : : (dev, MLX5_HW_LOWEST_USABLE_GROUP, error);
8680 [ # # ]: 0 : if (!jump_one_actions_tmpl) {
8681 : 0 : DRV_LOG(ERR, "port %u failed to create jump action template"
8682 : : " for control flows", dev->data->port_id);
8683 : 0 : goto err;
8684 : : }
8685 : : MLX5_ASSERT(priv->hw_esw_zero_tbl == NULL);
8686 : 0 : priv->hw_esw_zero_tbl = flow_hw_create_ctrl_jump_table(dev, port_items_tmpl,
8687 : : jump_one_actions_tmpl,
8688 : : error);
8689 [ # # ]: 0 : if (!priv->hw_esw_zero_tbl) {
8690 : 0 : DRV_LOG(ERR, "port %u failed to create table for default jump to group 1"
8691 : : " for control flows", dev->data->port_id);
8692 : 0 : goto err;
8693 : : }
8694 : : /* Create templates and table for default Tx metadata copy flow rule. */
8695 [ # # ]: 0 : if (!repr_matching && xmeta == MLX5_XMETA_MODE_META32_HWS) {
8696 : : tx_meta_items_tmpl =
8697 : 0 : flow_hw_create_tx_default_mreg_copy_pattern_template(dev, error);
8698 [ # # ]: 0 : if (!tx_meta_items_tmpl) {
8699 : 0 : DRV_LOG(ERR, "port %u failed to Tx metadata copy pattern"
8700 : : " template for control flows", dev->data->port_id);
8701 : 0 : goto err;
8702 : : }
8703 : : tx_meta_actions_tmpl =
8704 : 0 : flow_hw_create_tx_default_mreg_copy_actions_template(dev, error);
8705 [ # # ]: 0 : if (!tx_meta_actions_tmpl) {
8706 : 0 : DRV_LOG(ERR, "port %u failed to Tx metadata copy actions"
8707 : : " template for control flows", dev->data->port_id);
8708 : 0 : goto err;
8709 : : }
8710 : : MLX5_ASSERT(priv->hw_tx_meta_cpy_tbl == NULL);
8711 : 0 : priv->hw_tx_meta_cpy_tbl =
8712 : 0 : flow_hw_create_tx_default_mreg_copy_table(dev, tx_meta_items_tmpl,
8713 : : tx_meta_actions_tmpl, error);
8714 [ # # ]: 0 : if (!priv->hw_tx_meta_cpy_tbl) {
8715 : 0 : DRV_LOG(ERR, "port %u failed to create table for default"
8716 : : " Tx metadata copy flow rule", dev->data->port_id);
8717 : 0 : goto err;
8718 : : }
8719 : : }
8720 : : /* Create LACP default miss table. */
8721 [ # # # # ]: 0 : if (!priv->sh->config.lacp_by_user && priv->pf_bond >= 0) {
8722 : 0 : lacp_rx_items_tmpl = flow_hw_create_lacp_rx_pattern_template(dev, error);
8723 [ # # ]: 0 : if (!lacp_rx_items_tmpl) {
8724 : 0 : DRV_LOG(ERR, "port %u failed to create pattern template"
8725 : : " for LACP Rx traffic", dev->data->port_id);
8726 : 0 : goto err;
8727 : : }
8728 : 0 : lacp_rx_actions_tmpl = flow_hw_create_lacp_rx_actions_template(dev, error);
8729 [ # # ]: 0 : if (!lacp_rx_actions_tmpl) {
8730 : 0 : DRV_LOG(ERR, "port %u failed to create actions template"
8731 : : " for LACP Rx traffic", dev->data->port_id);
8732 : 0 : goto err;
8733 : : }
8734 : 0 : priv->hw_lacp_rx_tbl = flow_hw_create_lacp_rx_table(dev, lacp_rx_items_tmpl,
8735 : : lacp_rx_actions_tmpl, error);
8736 [ # # ]: 0 : if (!priv->hw_lacp_rx_tbl) {
8737 : 0 : DRV_LOG(ERR, "port %u failed to create template table for"
8738 : : " for LACP Rx traffic", dev->data->port_id);
8739 : 0 : goto err;
8740 : : }
8741 : : }
8742 : : return 0;
8743 : 0 : err:
8744 : : /* Do not overwrite the rte_errno. */
8745 : 0 : ret = -rte_errno;
8746 [ # # ]: 0 : if (ret == 0)
8747 : 0 : ret = rte_flow_error_set(error, EINVAL,
8748 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8749 : : "Failed to create control tables.");
8750 [ # # ]: 0 : if (priv->hw_tx_meta_cpy_tbl) {
8751 : 0 : flow_hw_table_destroy(dev, priv->hw_tx_meta_cpy_tbl, NULL);
8752 : 0 : priv->hw_tx_meta_cpy_tbl = NULL;
8753 : : }
8754 [ # # ]: 0 : if (priv->hw_esw_zero_tbl) {
8755 : 0 : flow_hw_table_destroy(dev, priv->hw_esw_zero_tbl, NULL);
8756 : 0 : priv->hw_esw_zero_tbl = NULL;
8757 : : }
8758 [ # # ]: 0 : if (priv->hw_esw_sq_miss_tbl) {
8759 : 0 : flow_hw_table_destroy(dev, priv->hw_esw_sq_miss_tbl, NULL);
8760 : 0 : priv->hw_esw_sq_miss_tbl = NULL;
8761 : : }
8762 [ # # ]: 0 : if (priv->hw_esw_sq_miss_root_tbl) {
8763 : 0 : flow_hw_table_destroy(dev, priv->hw_esw_sq_miss_root_tbl, NULL);
8764 : 0 : priv->hw_esw_sq_miss_root_tbl = NULL;
8765 : : }
8766 [ # # ]: 0 : if (lacp_rx_actions_tmpl)
8767 : 0 : flow_hw_actions_template_destroy(dev, lacp_rx_actions_tmpl, NULL);
8768 [ # # ]: 0 : if (tx_meta_actions_tmpl)
8769 : 0 : flow_hw_actions_template_destroy(dev, tx_meta_actions_tmpl, NULL);
8770 [ # # ]: 0 : if (jump_one_actions_tmpl)
8771 : 0 : flow_hw_actions_template_destroy(dev, jump_one_actions_tmpl, NULL);
8772 [ # # ]: 0 : if (port_actions_tmpl)
8773 : 0 : flow_hw_actions_template_destroy(dev, port_actions_tmpl, NULL);
8774 [ # # ]: 0 : if (regc_jump_actions_tmpl)
8775 : 0 : flow_hw_actions_template_destroy(dev, regc_jump_actions_tmpl, NULL);
8776 [ # # ]: 0 : if (lacp_rx_items_tmpl)
8777 : 0 : flow_hw_pattern_template_destroy(dev, lacp_rx_items_tmpl, NULL);
8778 [ # # ]: 0 : if (tx_meta_items_tmpl)
8779 : 0 : flow_hw_pattern_template_destroy(dev, tx_meta_items_tmpl, NULL);
8780 [ # # ]: 0 : if (port_items_tmpl)
8781 : 0 : flow_hw_pattern_template_destroy(dev, port_items_tmpl, NULL);
8782 [ # # ]: 0 : if (regc_sq_items_tmpl)
8783 : 0 : flow_hw_pattern_template_destroy(dev, regc_sq_items_tmpl, NULL);
8784 [ # # ]: 0 : if (esw_mgr_items_tmpl)
8785 : 0 : flow_hw_pattern_template_destroy(dev, esw_mgr_items_tmpl, NULL);
8786 : : return ret;
8787 : : }
8788 : :
8789 : : static void
8790 : 0 : flow_hw_ct_mng_destroy(struct rte_eth_dev *dev,
8791 : : struct mlx5_aso_ct_pools_mng *ct_mng)
8792 : : {
8793 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8794 : :
8795 : 0 : mlx5_aso_ct_queue_uninit(priv->sh, ct_mng);
8796 : 0 : mlx5_free(ct_mng);
8797 : 0 : }
8798 : :
8799 : : static void
8800 : 0 : flow_hw_ct_pool_destroy(struct rte_eth_dev *dev __rte_unused,
8801 : : struct mlx5_aso_ct_pool *pool)
8802 : : {
8803 [ # # ]: 0 : if (pool->dr_action)
8804 : 0 : mlx5dr_action_destroy(pool->dr_action);
8805 [ # # ]: 0 : if (pool->devx_obj)
8806 : 0 : claim_zero(mlx5_devx_cmd_destroy(pool->devx_obj));
8807 [ # # ]: 0 : if (pool->cts)
8808 : 0 : mlx5_ipool_destroy(pool->cts);
8809 : 0 : mlx5_free(pool);
8810 : 0 : }
8811 : :
8812 : : static struct mlx5_aso_ct_pool *
8813 : 0 : flow_hw_ct_pool_create(struct rte_eth_dev *dev,
8814 : : const struct rte_flow_port_attr *port_attr)
8815 : : {
8816 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8817 : : struct mlx5_aso_ct_pool *pool;
8818 : : struct mlx5_devx_obj *obj;
8819 [ # # ]: 0 : uint32_t nb_cts = rte_align32pow2(port_attr->nb_conn_tracks);
8820 : : uint32_t log_obj_size = rte_log2_u32(nb_cts);
8821 : 0 : struct mlx5_indexed_pool_config cfg = {
8822 : : .size = sizeof(struct mlx5_aso_ct_action),
8823 : : .trunk_size = 1 << 12,
8824 : : .per_core_cache = 1 << 13,
8825 : : .need_lock = 1,
8826 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
8827 : : .malloc = mlx5_malloc,
8828 : : .free = mlx5_free,
8829 : : .type = "mlx5_hw_ct_action",
8830 : : };
8831 : : int reg_id;
8832 : : uint32_t flags;
8833 : :
8834 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_SHARE_INDIRECT) {
8835 : 0 : DRV_LOG(ERR, "Connection tracking is not supported "
8836 : : "in cross vHCA sharing mode");
8837 : 0 : rte_errno = ENOTSUP;
8838 : 0 : return NULL;
8839 : : }
8840 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
8841 [ # # ]: 0 : if (!pool) {
8842 : 0 : rte_errno = ENOMEM;
8843 : 0 : return NULL;
8844 : : }
8845 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
8846 : 0 : priv->sh->cdev->pdn,
8847 : : log_obj_size);
8848 [ # # ]: 0 : if (!obj) {
8849 : 0 : rte_errno = ENODATA;
8850 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
8851 : 0 : goto err;
8852 : : }
8853 : 0 : pool->devx_obj = obj;
8854 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, NULL);
8855 : : flags = MLX5DR_ACTION_FLAG_HWS_RX | MLX5DR_ACTION_FLAG_HWS_TX;
8856 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en && priv->master)
8857 : : flags |= MLX5DR_ACTION_FLAG_HWS_FDB;
8858 : 0 : pool->dr_action = mlx5dr_action_create_aso_ct(priv->dr_ctx,
8859 : : (struct mlx5dr_devx_obj *)obj,
8860 : 0 : reg_id - REG_C_0, flags);
8861 [ # # ]: 0 : if (!pool->dr_action)
8862 : 0 : goto err;
8863 : : /*
8864 : : * No need for local cache if CT number is a small number. Since
8865 : : * flow insertion rate will be very limited in that case. Here let's
8866 : : * set the number to less than default trunk size 4K.
8867 : : */
8868 [ # # ]: 0 : if (nb_cts <= cfg.trunk_size) {
8869 : 0 : cfg.per_core_cache = 0;
8870 : 0 : cfg.trunk_size = nb_cts;
8871 [ # # ]: 0 : } else if (nb_cts <= MLX5_HW_IPOOL_SIZE_THRESHOLD) {
8872 : 0 : cfg.per_core_cache = MLX5_HW_IPOOL_CACHE_MIN;
8873 : : }
8874 : 0 : pool->cts = mlx5_ipool_create(&cfg);
8875 [ # # ]: 0 : if (!pool->cts)
8876 : 0 : goto err;
8877 : 0 : pool->sq = priv->ct_mng->aso_sqs;
8878 : : /* Assign the last extra ASO SQ as public SQ. */
8879 : 0 : pool->shared_sq = &priv->ct_mng->aso_sqs[priv->nb_queue - 1];
8880 : 0 : return pool;
8881 : 0 : err:
8882 : 0 : flow_hw_ct_pool_destroy(dev, pool);
8883 : 0 : return NULL;
8884 : : }
8885 : :
8886 : : static void
8887 : 0 : flow_hw_destroy_vlan(struct rte_eth_dev *dev)
8888 : : {
8889 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8890 : : enum mlx5dr_table_type i;
8891 : :
8892 [ # # ]: 0 : for (i = MLX5DR_TABLE_TYPE_NIC_RX; i < MLX5DR_TABLE_TYPE_MAX; i++) {
8893 [ # # ]: 0 : if (priv->hw_pop_vlan[i]) {
8894 : 0 : mlx5dr_action_destroy(priv->hw_pop_vlan[i]);
8895 : 0 : priv->hw_pop_vlan[i] = NULL;
8896 : : }
8897 [ # # ]: 0 : if (priv->hw_push_vlan[i]) {
8898 : 0 : mlx5dr_action_destroy(priv->hw_push_vlan[i]);
8899 : 0 : priv->hw_push_vlan[i] = NULL;
8900 : : }
8901 : : }
8902 : 0 : }
8903 : :
8904 : : static int
8905 : 0 : flow_hw_create_vlan(struct rte_eth_dev *dev)
8906 : : {
8907 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8908 : : enum mlx5dr_table_type i;
8909 : 0 : const enum mlx5dr_action_flags flags[MLX5DR_TABLE_TYPE_MAX] = {
8910 : : MLX5DR_ACTION_FLAG_HWS_RX,
8911 : : MLX5DR_ACTION_FLAG_HWS_TX,
8912 : : MLX5DR_ACTION_FLAG_HWS_FDB
8913 : : };
8914 : :
8915 : : /* rte_errno is set in the mlx5dr_action* functions. */
8916 [ # # ]: 0 : for (i = MLX5DR_TABLE_TYPE_NIC_RX; i <= MLX5DR_TABLE_TYPE_NIC_TX; i++) {
8917 : 0 : priv->hw_pop_vlan[i] =
8918 : 0 : mlx5dr_action_create_pop_vlan(priv->dr_ctx, flags[i]);
8919 [ # # ]: 0 : if (!priv->hw_pop_vlan[i])
8920 : 0 : return -rte_errno;
8921 : 0 : priv->hw_push_vlan[i] =
8922 : 0 : mlx5dr_action_create_push_vlan(priv->dr_ctx, flags[i]);
8923 [ # # ]: 0 : if (!priv->hw_pop_vlan[i])
8924 : 0 : return -rte_errno;
8925 : : }
8926 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en && priv->master) {
8927 : 0 : priv->hw_pop_vlan[MLX5DR_TABLE_TYPE_FDB] =
8928 : 0 : mlx5dr_action_create_pop_vlan
8929 : : (priv->dr_ctx, MLX5DR_ACTION_FLAG_HWS_FDB);
8930 [ # # ]: 0 : if (!priv->hw_pop_vlan[MLX5DR_TABLE_TYPE_FDB])
8931 : 0 : return -rte_errno;
8932 : 0 : priv->hw_push_vlan[MLX5DR_TABLE_TYPE_FDB] =
8933 : 0 : mlx5dr_action_create_push_vlan
8934 : : (priv->dr_ctx, MLX5DR_ACTION_FLAG_HWS_FDB);
8935 [ # # ]: 0 : if (!priv->hw_pop_vlan[MLX5DR_TABLE_TYPE_FDB])
8936 : 0 : return -rte_errno;
8937 : : }
8938 : : return 0;
8939 : : }
8940 : :
8941 : : static void
8942 : 0 : flow_hw_cleanup_ctrl_rx_tables(struct rte_eth_dev *dev)
8943 : : {
8944 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8945 : : unsigned int i;
8946 : : unsigned int j;
8947 : :
8948 [ # # ]: 0 : if (!priv->hw_ctrl_rx)
8949 : : return;
8950 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
8951 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
8952 : 0 : struct rte_flow_template_table *tbl = priv->hw_ctrl_rx->tables[i][j].tbl;
8953 : 0 : struct rte_flow_pattern_template *pt = priv->hw_ctrl_rx->tables[i][j].pt;
8954 : :
8955 [ # # ]: 0 : if (tbl)
8956 : 0 : claim_zero(flow_hw_table_destroy(dev, tbl, NULL));
8957 [ # # ]: 0 : if (pt)
8958 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, pt, NULL));
8959 : : }
8960 : : }
8961 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++i) {
8962 : 0 : struct rte_flow_actions_template *at = priv->hw_ctrl_rx->rss[i];
8963 : :
8964 [ # # ]: 0 : if (at)
8965 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, at, NULL));
8966 : : }
8967 : 0 : mlx5_free(priv->hw_ctrl_rx);
8968 : 0 : priv->hw_ctrl_rx = NULL;
8969 : : }
8970 : :
8971 : : static uint64_t
8972 : : flow_hw_ctrl_rx_rss_type_hash_types(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
8973 : : {
8974 : : switch (rss_type) {
8975 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_NON_IP:
8976 : : return 0;
8977 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4:
8978 : : return RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_NONFRAG_IPV4_OTHER;
8979 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
8980 : : return RTE_ETH_RSS_NONFRAG_IPV4_UDP;
8981 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
8982 : : return RTE_ETH_RSS_NONFRAG_IPV4_TCP;
8983 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6:
8984 : : return RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
8985 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
8986 : : return RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_IPV6_UDP_EX;
8987 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
8988 : : return RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_IPV6_TCP_EX;
8989 : : default:
8990 : : /* Should not reach here. */
8991 : : MLX5_ASSERT(false);
8992 : : return 0;
8993 : : }
8994 : : }
8995 : :
8996 : : static struct rte_flow_actions_template *
8997 : 0 : flow_hw_create_ctrl_rx_rss_template(struct rte_eth_dev *dev,
8998 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
8999 : : {
9000 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9001 : 0 : struct rte_flow_actions_template_attr attr = {
9002 : : .ingress = 1,
9003 : : };
9004 : : uint16_t queue[RTE_MAX_QUEUES_PER_PORT];
9005 : 0 : struct rte_flow_action_rss rss_conf = {
9006 : : .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
9007 : : .level = 0,
9008 : : .types = 0,
9009 : 0 : .key_len = priv->rss_conf.rss_key_len,
9010 : 0 : .key = priv->rss_conf.rss_key,
9011 : 0 : .queue_num = priv->reta_idx_n,
9012 : : .queue = queue,
9013 : : };
9014 : 0 : struct rte_flow_action actions[] = {
9015 : : {
9016 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
9017 : : .conf = &rss_conf,
9018 : : },
9019 : : {
9020 : : .type = RTE_FLOW_ACTION_TYPE_END,
9021 : : }
9022 : : };
9023 [ # # ]: 0 : struct rte_flow_action masks[] = {
9024 : : {
9025 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
9026 : : .conf = &rss_conf,
9027 : : },
9028 : : {
9029 : : .type = RTE_FLOW_ACTION_TYPE_END,
9030 : : }
9031 : : };
9032 : : struct rte_flow_actions_template *at;
9033 : : struct rte_flow_error error;
9034 : : unsigned int i;
9035 : :
9036 : : MLX5_ASSERT(priv->reta_idx_n > 0 && priv->reta_idx);
9037 : : /* Select proper RSS hash types and based on that configure the actions template. */
9038 : 0 : rss_conf.types = flow_hw_ctrl_rx_rss_type_hash_types(rss_type);
9039 [ # # ]: 0 : if (rss_conf.types) {
9040 [ # # ]: 0 : for (i = 0; i < priv->reta_idx_n; ++i)
9041 : 0 : queue[i] = (*priv->reta_idx)[i];
9042 : : } else {
9043 : 0 : rss_conf.queue_num = 1;
9044 : 0 : queue[0] = (*priv->reta_idx)[0];
9045 : : }
9046 : 0 : at = flow_hw_actions_template_create(dev, &attr, actions, masks, &error);
9047 [ # # ]: 0 : if (!at)
9048 [ # # ]: 0 : DRV_LOG(ERR,
9049 : : "Failed to create ctrl flow actions template: rte_errno(%d), type(%d): %s",
9050 : : rte_errno, error.type,
9051 : : error.message ? error.message : "(no stated reason)");
9052 : 0 : return at;
9053 : : }
9054 : :
9055 : : static uint32_t ctrl_rx_rss_priority_map[MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX] = {
9056 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_NON_IP] = MLX5_HW_CTRL_RX_PRIO_L2,
9057 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4] = MLX5_HW_CTRL_RX_PRIO_L3,
9058 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP] = MLX5_HW_CTRL_RX_PRIO_L4,
9059 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP] = MLX5_HW_CTRL_RX_PRIO_L4,
9060 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6] = MLX5_HW_CTRL_RX_PRIO_L3,
9061 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP] = MLX5_HW_CTRL_RX_PRIO_L4,
9062 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP] = MLX5_HW_CTRL_RX_PRIO_L4,
9063 : : };
9064 : :
9065 : : static uint32_t ctrl_rx_nb_flows_map[MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX] = {
9066 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL] = 1,
9067 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST] = 1,
9068 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST] = 1,
9069 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN] = MLX5_MAX_VLAN_IDS,
9070 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST] = 1,
9071 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN] = MLX5_MAX_VLAN_IDS,
9072 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST] = 1,
9073 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN] = MLX5_MAX_VLAN_IDS,
9074 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC] = MLX5_MAX_UC_MAC_ADDRESSES,
9075 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN] =
9076 : : MLX5_MAX_UC_MAC_ADDRESSES * MLX5_MAX_VLAN_IDS,
9077 : : };
9078 : :
9079 : : static struct rte_flow_template_table_attr
9080 : : flow_hw_get_ctrl_rx_table_attr(enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
9081 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
9082 : : {
9083 : 0 : return (struct rte_flow_template_table_attr){
9084 : : .flow_attr = {
9085 : : .group = 0,
9086 : 0 : .priority = ctrl_rx_rss_priority_map[rss_type],
9087 : : .ingress = 1,
9088 : : },
9089 : 0 : .nb_flows = ctrl_rx_nb_flows_map[eth_pattern_type],
9090 : : };
9091 : : }
9092 : :
9093 : : static struct rte_flow_item
9094 : : flow_hw_get_ctrl_rx_eth_item(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
9095 : : {
9096 : : struct rte_flow_item item = {
9097 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
9098 : : .mask = NULL,
9099 : : };
9100 : :
9101 : 0 : switch (eth_pattern_type) {
9102 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
9103 : : item.mask = &ctrl_rx_eth_promisc_mask;
9104 : : break;
9105 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
9106 : : item.mask = &ctrl_rx_eth_mcast_mask;
9107 : 0 : break;
9108 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
9109 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
9110 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
9111 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
9112 : : item.mask = &ctrl_rx_eth_dmac_mask;
9113 : 0 : break;
9114 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
9115 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
9116 : : item.mask = &ctrl_rx_eth_ipv4_mcast_mask;
9117 : 0 : break;
9118 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
9119 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
9120 : : item.mask = &ctrl_rx_eth_ipv6_mcast_mask;
9121 : 0 : break;
9122 : 0 : default:
9123 : : /* Should not reach here - ETH mask must be present. */
9124 : : item.type = RTE_FLOW_ITEM_TYPE_END;
9125 : : MLX5_ASSERT(false);
9126 : 0 : break;
9127 : : }
9128 : 0 : return item;
9129 : : }
9130 : :
9131 : : static struct rte_flow_item
9132 : : flow_hw_get_ctrl_rx_vlan_item(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
9133 : : {
9134 : : struct rte_flow_item item = {
9135 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
9136 : : .mask = NULL,
9137 : : };
9138 : :
9139 [ # # ]: 0 : switch (eth_pattern_type) {
9140 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
9141 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
9142 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
9143 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
9144 : : item.type = RTE_FLOW_ITEM_TYPE_VLAN;
9145 : : item.mask = &rte_flow_item_vlan_mask;
9146 : 0 : break;
9147 : : default:
9148 : : /* Nothing to update. */
9149 : : break;
9150 : : }
9151 : 0 : return item;
9152 : : }
9153 : :
9154 : : static struct rte_flow_item
9155 : : flow_hw_get_ctrl_rx_l3_item(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
9156 : : {
9157 : : struct rte_flow_item item = {
9158 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
9159 : : .mask = NULL,
9160 : : };
9161 : :
9162 [ # # # ]: 0 : switch (rss_type) {
9163 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4:
9164 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
9165 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
9166 : : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
9167 : 0 : break;
9168 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6:
9169 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
9170 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
9171 : : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
9172 : 0 : break;
9173 : : default:
9174 : : /* Nothing to update. */
9175 : : break;
9176 : : }
9177 : 0 : return item;
9178 : : }
9179 : :
9180 : : static struct rte_flow_item
9181 : : flow_hw_get_ctrl_rx_l4_item(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
9182 : : {
9183 : : struct rte_flow_item item = {
9184 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
9185 : : .mask = NULL,
9186 : : };
9187 : :
9188 [ # # # ]: 0 : switch (rss_type) {
9189 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
9190 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
9191 : : item.type = RTE_FLOW_ITEM_TYPE_UDP;
9192 : 0 : break;
9193 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
9194 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
9195 : : item.type = RTE_FLOW_ITEM_TYPE_TCP;
9196 : 0 : break;
9197 : : default:
9198 : : /* Nothing to update. */
9199 : : break;
9200 : : }
9201 : 0 : return item;
9202 : : }
9203 : :
9204 : : static struct rte_flow_pattern_template *
9205 : 0 : flow_hw_create_ctrl_rx_pattern_template
9206 : : (struct rte_eth_dev *dev,
9207 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
9208 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
9209 : : {
9210 : 0 : const struct rte_flow_pattern_template_attr attr = {
9211 : : .relaxed_matching = 0,
9212 : : .ingress = 1,
9213 : : };
9214 [ # # # # : 0 : struct rte_flow_item items[] = {
# # ]
9215 : : /* Matching patterns */
9216 : : flow_hw_get_ctrl_rx_eth_item(eth_pattern_type),
9217 : : flow_hw_get_ctrl_rx_vlan_item(eth_pattern_type),
9218 : : flow_hw_get_ctrl_rx_l3_item(rss_type),
9219 : : flow_hw_get_ctrl_rx_l4_item(rss_type),
9220 : : /* Terminate pattern */
9221 : : { .type = RTE_FLOW_ITEM_TYPE_END }
9222 : : };
9223 : :
9224 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, NULL);
9225 : : }
9226 : :
9227 : : static int
9228 : 0 : flow_hw_create_ctrl_rx_tables(struct rte_eth_dev *dev)
9229 : : {
9230 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9231 : : unsigned int i;
9232 : : unsigned int j;
9233 : : int ret;
9234 : :
9235 : : MLX5_ASSERT(!priv->hw_ctrl_rx);
9236 : 0 : priv->hw_ctrl_rx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*priv->hw_ctrl_rx),
9237 : 0 : RTE_CACHE_LINE_SIZE, rte_socket_id());
9238 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
9239 : 0 : DRV_LOG(ERR, "Failed to allocate memory for Rx control flow tables");
9240 : 0 : rte_errno = ENOMEM;
9241 : 0 : return -rte_errno;
9242 : : }
9243 : : /* Create all pattern template variants. */
9244 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
9245 : : enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type = i;
9246 : :
9247 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
9248 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
9249 : : struct rte_flow_template_table_attr attr;
9250 : : struct rte_flow_pattern_template *pt;
9251 : :
9252 : : attr = flow_hw_get_ctrl_rx_table_attr(eth_pattern_type, rss_type);
9253 : 0 : pt = flow_hw_create_ctrl_rx_pattern_template(dev, eth_pattern_type,
9254 : : rss_type);
9255 [ # # ]: 0 : if (!pt)
9256 : 0 : goto err;
9257 : 0 : priv->hw_ctrl_rx->tables[i][j].attr = attr;
9258 : 0 : priv->hw_ctrl_rx->tables[i][j].pt = pt;
9259 : : }
9260 : : }
9261 : : return 0;
9262 : : err:
9263 : 0 : ret = rte_errno;
9264 : 0 : flow_hw_cleanup_ctrl_rx_tables(dev);
9265 : 0 : rte_errno = ret;
9266 : 0 : return -ret;
9267 : : }
9268 : :
9269 : : void
9270 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev)
9271 : : {
9272 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9273 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
9274 : : unsigned int i;
9275 : : unsigned int j;
9276 : :
9277 [ # # ]: 0 : if (!priv->dr_ctx)
9278 : : return;
9279 [ # # ]: 0 : if (!priv->hw_ctrl_rx)
9280 : : return;
9281 : : hw_ctrl_rx = priv->hw_ctrl_rx;
9282 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
9283 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
9284 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[i][j];
9285 : :
9286 [ # # ]: 0 : if (tmpls->tbl) {
9287 : 0 : claim_zero(flow_hw_table_destroy(dev, tmpls->tbl, NULL));
9288 : 0 : tmpls->tbl = NULL;
9289 : : }
9290 : : }
9291 : : }
9292 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
9293 [ # # ]: 0 : if (hw_ctrl_rx->rss[j]) {
9294 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, hw_ctrl_rx->rss[j], NULL));
9295 : 0 : hw_ctrl_rx->rss[j] = NULL;
9296 : : }
9297 : : }
9298 : : }
9299 : :
9300 : : /**
9301 : : * Copy the provided HWS configuration to a newly allocated buffer.
9302 : : *
9303 : : * @param[in] port_attr
9304 : : * Port configuration attributes.
9305 : : * @param[in] nb_queue
9306 : : * Number of queue.
9307 : : * @param[in] queue_attr
9308 : : * Array that holds attributes for each flow queue.
9309 : : *
9310 : : * @return
9311 : : * Pointer to copied HWS configuration is returned on success.
9312 : : * Otherwise, NULL is returned and rte_errno is set.
9313 : : */
9314 : : static struct mlx5_flow_hw_attr *
9315 : 0 : flow_hw_alloc_copy_config(const struct rte_flow_port_attr *port_attr,
9316 : : const uint16_t nb_queue,
9317 : : const struct rte_flow_queue_attr *queue_attr[],
9318 : : struct rte_flow_error *error)
9319 : : {
9320 : : struct mlx5_flow_hw_attr *hw_attr;
9321 : : size_t hw_attr_size;
9322 : : unsigned int i;
9323 : :
9324 : 0 : hw_attr_size = sizeof(*hw_attr) + nb_queue * sizeof(*hw_attr->queue_attr);
9325 : 0 : hw_attr = mlx5_malloc(MLX5_MEM_ZERO, hw_attr_size, 0, SOCKET_ID_ANY);
9326 [ # # ]: 0 : if (!hw_attr) {
9327 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9328 : : "Not enough memory to store configuration");
9329 : 0 : return NULL;
9330 : : }
9331 : 0 : memcpy(&hw_attr->port_attr, port_attr, sizeof(*port_attr));
9332 : 0 : hw_attr->nb_queue = nb_queue;
9333 : : /* Queue attributes are placed after the mlx5_flow_hw_attr. */
9334 : 0 : hw_attr->queue_attr = (struct rte_flow_queue_attr *)(hw_attr + 1);
9335 [ # # ]: 0 : for (i = 0; i < nb_queue; ++i)
9336 : 0 : memcpy(&hw_attr->queue_attr[i], queue_attr[i], sizeof(hw_attr->queue_attr[i]));
9337 : : return hw_attr;
9338 : : }
9339 : :
9340 : : /**
9341 : : * Compares the preserved HWS configuration with the provided one.
9342 : : *
9343 : : * @param[in] hw_attr
9344 : : * Pointer to preserved HWS configuration.
9345 : : * @param[in] new_pa
9346 : : * Port configuration attributes to compare.
9347 : : * @param[in] new_nbq
9348 : : * Number of queues to compare.
9349 : : * @param[in] new_qa
9350 : : * Array that holds attributes for each flow queue.
9351 : : *
9352 : : * @return
9353 : : * True if configurations are the same, false otherwise.
9354 : : */
9355 : : static bool
9356 : 0 : flow_hw_compare_config(const struct mlx5_flow_hw_attr *hw_attr,
9357 : : const struct rte_flow_port_attr *new_pa,
9358 : : const uint16_t new_nbq,
9359 : : const struct rte_flow_queue_attr *new_qa[])
9360 : : {
9361 : : const struct rte_flow_port_attr *old_pa = &hw_attr->port_attr;
9362 : 0 : const uint16_t old_nbq = hw_attr->nb_queue;
9363 : 0 : const struct rte_flow_queue_attr *old_qa = hw_attr->queue_attr;
9364 : : unsigned int i;
9365 : :
9366 [ # # ]: 0 : if (old_pa->nb_counters != new_pa->nb_counters ||
9367 [ # # ]: 0 : old_pa->nb_aging_objects != new_pa->nb_aging_objects ||
9368 [ # # ]: 0 : old_pa->nb_meters != new_pa->nb_meters ||
9369 [ # # ]: 0 : old_pa->nb_conn_tracks != new_pa->nb_conn_tracks ||
9370 [ # # ]: 0 : old_pa->flags != new_pa->flags)
9371 : : return false;
9372 [ # # ]: 0 : if (old_nbq != new_nbq)
9373 : : return false;
9374 [ # # ]: 0 : for (i = 0; i < old_nbq; ++i)
9375 [ # # ]: 0 : if (old_qa[i].size != new_qa[i]->size)
9376 : : return false;
9377 : : return true;
9378 : : }
9379 : :
9380 : : /**
9381 : : * Configure port HWS resources.
9382 : : *
9383 : : * @param[in] dev
9384 : : * Pointer to the rte_eth_dev structure.
9385 : : * @param[in] port_attr
9386 : : * Port configuration attributes.
9387 : : * @param[in] nb_queue
9388 : : * Number of queue.
9389 : : * @param[in] queue_attr
9390 : : * Array that holds attributes for each flow queue.
9391 : : * @param[out] error
9392 : : * Pointer to error structure.
9393 : : *
9394 : : * @return
9395 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9396 : : */
9397 : : static int
9398 : 0 : flow_hw_configure(struct rte_eth_dev *dev,
9399 : : const struct rte_flow_port_attr *port_attr,
9400 : : uint16_t nb_queue,
9401 : : const struct rte_flow_queue_attr *queue_attr[],
9402 : : struct rte_flow_error *error)
9403 : : {
9404 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9405 : : struct mlx5_priv *host_priv = NULL;
9406 : : struct mlx5dr_context *dr_ctx = NULL;
9407 : 0 : struct mlx5dr_context_attr dr_ctx_attr = {0};
9408 : : struct mlx5_hw_q *hw_q;
9409 : : struct mlx5_hw_q_job *job = NULL;
9410 : : uint32_t mem_size, i, j;
9411 : 0 : struct mlx5_indexed_pool_config cfg = {
9412 : : .size = sizeof(struct mlx5_action_construct_data),
9413 : : .trunk_size = 4096,
9414 : : .need_lock = 1,
9415 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
9416 : : .malloc = mlx5_malloc,
9417 : : .free = mlx5_free,
9418 : : .type = "mlx5_hw_action_construct_data",
9419 : : };
9420 : : /*
9421 : : * Adds one queue to be used by PMD.
9422 : : * The last queue will be used by the PMD.
9423 : : */
9424 : : uint16_t nb_q_updated = 0;
9425 : : struct rte_flow_queue_attr **_queue_attr = NULL;
9426 : 0 : struct rte_flow_queue_attr ctrl_queue_attr = {0};
9427 [ # # # # ]: 0 : bool is_proxy = !!(priv->sh->config.dv_esw_en && priv->master);
9428 : : int ret = 0;
9429 : : uint32_t action_flags;
9430 : :
9431 [ # # # # ]: 0 : if (!port_attr || !nb_queue || !queue_attr) {
9432 : 0 : rte_errno = EINVAL;
9433 : 0 : goto err;
9434 : : }
9435 : : /*
9436 : : * Calling rte_flow_configure() again is allowed if and only if
9437 : : * provided configuration matches the initially provided one.
9438 : : */
9439 [ # # ]: 0 : if (priv->dr_ctx) {
9440 : : MLX5_ASSERT(priv->hw_attr != NULL);
9441 [ # # ]: 0 : for (i = 0; i < priv->nb_queue; i++) {
9442 : 0 : hw_q = &priv->hw_q[i];
9443 : : /* Make sure all queues are empty. */
9444 [ # # ]: 0 : if (hw_q->size != hw_q->job_idx) {
9445 : 0 : rte_errno = EBUSY;
9446 : 0 : goto err;
9447 : : }
9448 : : }
9449 [ # # ]: 0 : if (flow_hw_compare_config(priv->hw_attr, port_attr, nb_queue, queue_attr))
9450 : : return 0;
9451 : : else
9452 : 0 : return rte_flow_error_set(error, ENOTSUP,
9453 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9454 : : "Changing HWS configuration attributes "
9455 : : "is not supported");
9456 : : }
9457 : 0 : priv->hw_attr = flow_hw_alloc_copy_config(port_attr, nb_queue, queue_attr, error);
9458 [ # # ]: 0 : if (!priv->hw_attr) {
9459 : 0 : ret = -rte_errno;
9460 : 0 : goto err;
9461 : : }
9462 : 0 : ctrl_queue_attr.size = queue_attr[0]->size;
9463 : 0 : nb_q_updated = nb_queue + 1;
9464 : 0 : _queue_attr = mlx5_malloc(MLX5_MEM_ZERO,
9465 : : nb_q_updated *
9466 : : sizeof(struct rte_flow_queue_attr *),
9467 : : 64, SOCKET_ID_ANY);
9468 [ # # ]: 0 : if (!_queue_attr) {
9469 : 0 : rte_errno = ENOMEM;
9470 : 0 : goto err;
9471 : : }
9472 : :
9473 : 0 : memcpy(_queue_attr, queue_attr, sizeof(void *) * nb_queue);
9474 : 0 : _queue_attr[nb_queue] = &ctrl_queue_attr;
9475 : 0 : priv->acts_ipool = mlx5_ipool_create(&cfg);
9476 [ # # ]: 0 : if (!priv->acts_ipool)
9477 : 0 : goto err;
9478 : : /* Allocate the queue job descriptor LIFO. */
9479 : 0 : mem_size = sizeof(priv->hw_q[0]) * nb_q_updated;
9480 [ # # ]: 0 : for (i = 0; i < nb_q_updated; i++) {
9481 : : /*
9482 : : * Check if the queues' size are all the same as the
9483 : : * limitation from HWS layer.
9484 : : */
9485 [ # # ]: 0 : if (_queue_attr[i]->size != _queue_attr[0]->size) {
9486 : 0 : rte_errno = EINVAL;
9487 : 0 : goto err;
9488 : : }
9489 : 0 : mem_size += (sizeof(struct mlx5_hw_q_job *) +
9490 : : sizeof(struct mlx5_hw_q_job) +
9491 : : sizeof(uint8_t) * MLX5_ENCAP_MAX_LEN +
9492 : : sizeof(uint8_t) * MLX5_PUSH_MAX_LEN +
9493 : : sizeof(struct mlx5_modification_cmd) *
9494 : : MLX5_MHDR_MAX_CMD +
9495 : : sizeof(struct rte_flow_item) *
9496 : : MLX5_HW_MAX_ITEMS +
9497 : 0 : sizeof(struct rte_flow_hw)) *
9498 : : _queue_attr[i]->size;
9499 : : }
9500 : 0 : priv->hw_q = mlx5_malloc(MLX5_MEM_ZERO, mem_size,
9501 : : 64, SOCKET_ID_ANY);
9502 [ # # ]: 0 : if (!priv->hw_q) {
9503 : 0 : rte_errno = ENOMEM;
9504 : 0 : goto err;
9505 : : }
9506 [ # # ]: 0 : for (i = 0; i < nb_q_updated; i++) {
9507 : : char mz_name[RTE_MEMZONE_NAMESIZE];
9508 : : uint8_t *encap = NULL, *push = NULL;
9509 : : struct mlx5_modification_cmd *mhdr_cmd = NULL;
9510 : : struct rte_flow_item *items = NULL;
9511 : : struct rte_flow_hw *upd_flow = NULL;
9512 : :
9513 : 0 : priv->hw_q[i].job_idx = _queue_attr[i]->size;
9514 : 0 : priv->hw_q[i].size = _queue_attr[i]->size;
9515 [ # # ]: 0 : if (i == 0)
9516 : 0 : priv->hw_q[i].job = (struct mlx5_hw_q_job **)
9517 : 0 : &priv->hw_q[nb_q_updated];
9518 : : else
9519 : 0 : priv->hw_q[i].job = (struct mlx5_hw_q_job **)
9520 : 0 : &job[_queue_attr[i - 1]->size - 1].upd_flow[1];
9521 : 0 : job = (struct mlx5_hw_q_job *)
9522 : 0 : &priv->hw_q[i].job[_queue_attr[i]->size];
9523 : 0 : mhdr_cmd = (struct mlx5_modification_cmd *)
9524 : 0 : &job[_queue_attr[i]->size];
9525 : 0 : encap = (uint8_t *)
9526 : 0 : &mhdr_cmd[_queue_attr[i]->size * MLX5_MHDR_MAX_CMD];
9527 : 0 : push = (uint8_t *)
9528 : 0 : &encap[_queue_attr[i]->size * MLX5_ENCAP_MAX_LEN];
9529 : 0 : items = (struct rte_flow_item *)
9530 : 0 : &push[_queue_attr[i]->size * MLX5_PUSH_MAX_LEN];
9531 : : upd_flow = (struct rte_flow_hw *)
9532 : 0 : &items[_queue_attr[i]->size * MLX5_HW_MAX_ITEMS];
9533 [ # # ]: 0 : for (j = 0; j < _queue_attr[i]->size; j++) {
9534 : 0 : job[j].mhdr_cmd = &mhdr_cmd[j * MLX5_MHDR_MAX_CMD];
9535 : 0 : job[j].encap_data = &encap[j * MLX5_ENCAP_MAX_LEN];
9536 : 0 : job[j].push_data = &push[j * MLX5_PUSH_MAX_LEN];
9537 : 0 : job[j].items = &items[j * MLX5_HW_MAX_ITEMS];
9538 : 0 : job[j].upd_flow = &upd_flow[j];
9539 : 0 : priv->hw_q[i].job[j] = &job[j];
9540 : : }
9541 : 0 : snprintf(mz_name, sizeof(mz_name), "port_%u_indir_act_cq_%u",
9542 : 0 : dev->data->port_id, i);
9543 : 0 : priv->hw_q[i].indir_cq = rte_ring_create(mz_name,
9544 : 0 : _queue_attr[i]->size, SOCKET_ID_ANY,
9545 : : RING_F_SP_ENQ | RING_F_SC_DEQ |
9546 : : RING_F_EXACT_SZ);
9547 [ # # ]: 0 : if (!priv->hw_q[i].indir_cq)
9548 : 0 : goto err;
9549 : 0 : snprintf(mz_name, sizeof(mz_name), "port_%u_indir_act_iq_%u",
9550 : 0 : dev->data->port_id, i);
9551 : 0 : priv->hw_q[i].indir_iq = rte_ring_create(mz_name,
9552 : 0 : _queue_attr[i]->size, SOCKET_ID_ANY,
9553 : : RING_F_SP_ENQ | RING_F_SC_DEQ |
9554 : : RING_F_EXACT_SZ);
9555 [ # # ]: 0 : if (!priv->hw_q[i].indir_iq)
9556 : 0 : goto err;
9557 : : }
9558 : 0 : dr_ctx_attr.pd = priv->sh->cdev->pd;
9559 : 0 : dr_ctx_attr.queues = nb_q_updated;
9560 : : /* Queue size should all be the same. Take the first one. */
9561 : 0 : dr_ctx_attr.queue_size = _queue_attr[0]->size;
9562 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_SHARE_INDIRECT) {
9563 : : struct rte_eth_dev *host_dev = NULL;
9564 : : uint16_t port_id;
9565 : :
9566 : : MLX5_ASSERT(rte_eth_dev_is_valid_port(port_attr->host_port_id));
9567 [ # # ]: 0 : if (is_proxy) {
9568 : 0 : DRV_LOG(ERR, "cross vHCA shared mode not supported "
9569 : : "for E-Switch confgiurations");
9570 : 0 : rte_errno = ENOTSUP;
9571 : 0 : goto err;
9572 : : }
9573 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
9574 [ # # ]: 0 : if (port_id == port_attr->host_port_id) {
9575 : 0 : host_dev = &rte_eth_devices[port_id];
9576 : 0 : break;
9577 : : }
9578 : : }
9579 [ # # ]: 0 : if (!host_dev || host_dev == dev ||
9580 [ # # # # ]: 0 : !host_dev->data || !host_dev->data->dev_private) {
9581 : 0 : DRV_LOG(ERR, "Invalid cross vHCA host port %u",
9582 : : port_attr->host_port_id);
9583 : 0 : rte_errno = EINVAL;
9584 : 0 : goto err;
9585 : : }
9586 : : host_priv = host_dev->data->dev_private;
9587 [ # # ]: 0 : if (host_priv->sh->cdev->ctx == priv->sh->cdev->ctx) {
9588 : 0 : DRV_LOG(ERR, "Sibling ports %u and %u do not "
9589 : : "require cross vHCA sharing mode",
9590 : : dev->data->port_id, port_attr->host_port_id);
9591 : 0 : rte_errno = EINVAL;
9592 : 0 : goto err;
9593 : : }
9594 [ # # ]: 0 : if (host_priv->shared_host) {
9595 : 0 : DRV_LOG(ERR, "Host port %u is not the sharing base",
9596 : : port_attr->host_port_id);
9597 : 0 : rte_errno = EINVAL;
9598 : 0 : goto err;
9599 : : }
9600 [ # # ]: 0 : if (port_attr->nb_counters ||
9601 [ # # ]: 0 : port_attr->nb_aging_objects ||
9602 [ # # ]: 0 : port_attr->nb_meters ||
9603 [ # # ]: 0 : port_attr->nb_conn_tracks) {
9604 : 0 : DRV_LOG(ERR,
9605 : : "Object numbers on guest port must be zeros");
9606 : 0 : rte_errno = EINVAL;
9607 : 0 : goto err;
9608 : : }
9609 : 0 : dr_ctx_attr.shared_ibv_ctx = host_priv->sh->cdev->ctx;
9610 : 0 : priv->shared_host = host_dev;
9611 : 0 : __atomic_fetch_add(&host_priv->shared_refcnt, 1, __ATOMIC_RELAXED);
9612 : : }
9613 : 0 : dr_ctx = mlx5dr_context_open(priv->sh->cdev->ctx, &dr_ctx_attr);
9614 : : /* rte_errno has been updated by HWS layer. */
9615 [ # # ]: 0 : if (!dr_ctx)
9616 : 0 : goto err;
9617 : 0 : priv->dr_ctx = dr_ctx;
9618 : 0 : priv->nb_queue = nb_q_updated;
9619 : : rte_spinlock_init(&priv->hw_ctrl_lock);
9620 : 0 : LIST_INIT(&priv->hw_ctrl_flows);
9621 : 0 : LIST_INIT(&priv->hw_ext_ctrl_flows);
9622 : 0 : ret = flow_hw_create_ctrl_rx_tables(dev);
9623 [ # # ]: 0 : if (ret) {
9624 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9625 : : "Failed to set up Rx control flow templates");
9626 : 0 : goto err;
9627 : : }
9628 : : /* Initialize quotas */
9629 [ # # # # : 0 : if (port_attr->nb_quotas || (host_priv && host_priv->quota_ctx.devx_obj)) {
# # ]
9630 : 0 : ret = mlx5_flow_quota_init(dev, port_attr->nb_quotas);
9631 [ # # ]: 0 : if (ret) {
9632 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9633 : : "Failed to initialize quota.");
9634 : 0 : goto err;
9635 : : }
9636 : : }
9637 : : /* Initialize meter library*/
9638 [ # # # # : 0 : if (port_attr->nb_meters || (host_priv && host_priv->hws_mpool))
# # ]
9639 [ # # ]: 0 : if (mlx5_flow_meter_init(dev, port_attr->nb_meters, 0, 0, nb_q_updated))
9640 : 0 : goto err;
9641 : : /* Add global actions. */
9642 [ # # ]: 0 : for (i = 0; i < MLX5_HW_ACTION_FLAG_MAX; i++) {
9643 : : uint32_t act_flags = 0;
9644 : :
9645 : 0 : act_flags = mlx5_hw_act_flag[i][0] | mlx5_hw_act_flag[i][1];
9646 [ # # ]: 0 : if (is_proxy)
9647 : 0 : act_flags |= mlx5_hw_act_flag[i][2];
9648 : 0 : priv->hw_drop[i] = mlx5dr_action_create_dest_drop(priv->dr_ctx, act_flags);
9649 [ # # ]: 0 : if (!priv->hw_drop[i])
9650 : 0 : goto err;
9651 : 0 : priv->hw_tag[i] = mlx5dr_action_create_tag
9652 : : (priv->dr_ctx, mlx5_hw_act_flag[i][0]);
9653 [ # # ]: 0 : if (!priv->hw_tag[i])
9654 : 0 : goto err;
9655 : : }
9656 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en && priv->sh->config.repr_matching) {
9657 : 0 : ret = flow_hw_setup_tx_repr_tagging(dev, error);
9658 [ # # ]: 0 : if (ret)
9659 : 0 : goto err;
9660 : : }
9661 : : /*
9662 : : * DEFAULT_MISS action have different behaviors in different domains.
9663 : : * In FDB, it will steering the packets to the E-switch manager.
9664 : : * In NIC Rx root, it will steering the packet to the kernel driver stack.
9665 : : * An action with all bits set in the flag can be created and the HWS
9666 : : * layer will translate it properly when being used in different rules.
9667 : : */
9668 : : action_flags = MLX5DR_ACTION_FLAG_ROOT_RX | MLX5DR_ACTION_FLAG_HWS_RX |
9669 : : MLX5DR_ACTION_FLAG_ROOT_TX | MLX5DR_ACTION_FLAG_HWS_TX;
9670 [ # # ]: 0 : if (is_proxy)
9671 : : action_flags |= (MLX5DR_ACTION_FLAG_ROOT_FDB | MLX5DR_ACTION_FLAG_HWS_FDB);
9672 : 0 : priv->hw_def_miss = mlx5dr_action_create_default_miss(priv->dr_ctx, action_flags);
9673 [ # # ]: 0 : if (!priv->hw_def_miss)
9674 : 0 : goto err;
9675 [ # # ]: 0 : if (is_proxy) {
9676 : 0 : ret = flow_hw_create_vport_actions(priv);
9677 [ # # ]: 0 : if (ret) {
9678 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9679 : : NULL, "Failed to create vport actions.");
9680 : 0 : goto err;
9681 : : }
9682 : 0 : ret = flow_hw_create_ctrl_tables(dev, error);
9683 [ # # ]: 0 : if (ret)
9684 : 0 : goto err;
9685 : : }
9686 : : if (!priv->shared_host)
9687 : : flow_hw_create_send_to_kernel_actions(priv);
9688 [ # # # # : 0 : if (port_attr->nb_conn_tracks || (host_priv && host_priv->hws_ctpool)) {
# # ]
9689 : 0 : mem_size = sizeof(struct mlx5_aso_sq) * nb_q_updated +
9690 : : sizeof(*priv->ct_mng);
9691 : 0 : priv->ct_mng = mlx5_malloc(MLX5_MEM_ZERO, mem_size,
9692 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
9693 [ # # ]: 0 : if (!priv->ct_mng)
9694 : 0 : goto err;
9695 [ # # ]: 0 : if (mlx5_aso_ct_queue_init(priv->sh, priv->ct_mng, nb_q_updated))
9696 : 0 : goto err;
9697 : 0 : priv->hws_ctpool = flow_hw_ct_pool_create(dev, port_attr);
9698 [ # # ]: 0 : if (!priv->hws_ctpool)
9699 : 0 : goto err;
9700 : 0 : priv->sh->ct_aso_en = 1;
9701 : : }
9702 [ # # # # : 0 : if (port_attr->nb_counters || (host_priv && host_priv->hws_cpool)) {
# # ]
9703 : 0 : priv->hws_cpool = mlx5_hws_cnt_pool_create(dev, port_attr,
9704 : : nb_queue);
9705 [ # # ]: 0 : if (priv->hws_cpool == NULL)
9706 : 0 : goto err;
9707 : : }
9708 [ # # ]: 0 : if (port_attr->nb_aging_objects) {
9709 [ # # ]: 0 : if (port_attr->nb_counters == 0) {
9710 : : /*
9711 : : * Aging management uses counter. Number counters
9712 : : * requesting should take into account a counter for
9713 : : * each flow rules containing AGE without counter.
9714 : : */
9715 : 0 : DRV_LOG(ERR, "Port %u AGE objects are requested (%u) "
9716 : : "without counters requesting.",
9717 : : dev->data->port_id,
9718 : : port_attr->nb_aging_objects);
9719 : 0 : rte_errno = EINVAL;
9720 : 0 : goto err;
9721 : : }
9722 : 0 : ret = mlx5_hws_age_pool_init(dev, port_attr, nb_queue);
9723 [ # # ]: 0 : if (ret < 0) {
9724 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9725 : : NULL, "Failed to init age pool.");
9726 : 0 : goto err;
9727 : : }
9728 : : }
9729 : 0 : ret = flow_hw_create_vlan(dev);
9730 [ # # ]: 0 : if (ret) {
9731 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9732 : : NULL, "Failed to VLAN actions.");
9733 : 0 : goto err;
9734 : : }
9735 : : if (_queue_attr)
9736 : 0 : mlx5_free(_queue_attr);
9737 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_STRICT_QUEUE)
9738 : 0 : priv->hws_strict_queue = 1;
9739 : 0 : dev->flow_fp_ops = &mlx5_flow_hw_fp_ops;
9740 : 0 : return 0;
9741 : 0 : err:
9742 [ # # ]: 0 : if (priv->hws_ctpool) {
9743 : 0 : flow_hw_ct_pool_destroy(dev, priv->hws_ctpool);
9744 : 0 : priv->hws_ctpool = NULL;
9745 : : }
9746 [ # # ]: 0 : if (priv->ct_mng) {
9747 : 0 : flow_hw_ct_mng_destroy(dev, priv->ct_mng);
9748 : 0 : priv->ct_mng = NULL;
9749 : : }
9750 [ # # ]: 0 : if (priv->hws_age_req)
9751 : 0 : mlx5_hws_age_pool_destroy(priv);
9752 [ # # ]: 0 : if (priv->hws_cpool) {
9753 : 0 : mlx5_hws_cnt_pool_destroy(priv->sh, priv->hws_cpool);
9754 : 0 : priv->hws_cpool = NULL;
9755 : : }
9756 : 0 : mlx5_flow_quota_destroy(dev);
9757 : 0 : flow_hw_destroy_send_to_kernel_action(priv);
9758 : 0 : flow_hw_free_vport_actions(priv);
9759 [ # # ]: 0 : for (i = 0; i < MLX5_HW_ACTION_FLAG_MAX; i++) {
9760 [ # # ]: 0 : if (priv->hw_drop[i])
9761 : 0 : mlx5dr_action_destroy(priv->hw_drop[i]);
9762 [ # # ]: 0 : if (priv->hw_tag[i])
9763 : 0 : mlx5dr_action_destroy(priv->hw_tag[i]);
9764 : : }
9765 [ # # ]: 0 : if (priv->hw_def_miss)
9766 : 0 : mlx5dr_action_destroy(priv->hw_def_miss);
9767 : 0 : flow_hw_destroy_vlan(dev);
9768 [ # # ]: 0 : if (dr_ctx)
9769 : 0 : claim_zero(mlx5dr_context_close(dr_ctx));
9770 [ # # ]: 0 : for (i = 0; i < nb_q_updated; i++) {
9771 : 0 : rte_ring_free(priv->hw_q[i].indir_iq);
9772 : 0 : rte_ring_free(priv->hw_q[i].indir_cq);
9773 : : }
9774 : 0 : mlx5_free(priv->hw_q);
9775 : 0 : priv->hw_q = NULL;
9776 [ # # ]: 0 : if (priv->acts_ipool) {
9777 : 0 : mlx5_ipool_destroy(priv->acts_ipool);
9778 : 0 : priv->acts_ipool = NULL;
9779 : : }
9780 [ # # ]: 0 : if (_queue_attr)
9781 : 0 : mlx5_free(_queue_attr);
9782 [ # # ]: 0 : if (priv->shared_host) {
9783 : 0 : __atomic_fetch_sub(&host_priv->shared_refcnt, 1, __ATOMIC_RELAXED);
9784 : 0 : priv->shared_host = NULL;
9785 : : }
9786 : 0 : mlx5_free(priv->hw_attr);
9787 : 0 : priv->hw_attr = NULL;
9788 : : /* Do not overwrite the internal errno information. */
9789 [ # # ]: 0 : if (ret)
9790 : : return ret;
9791 : 0 : return rte_flow_error_set(error, rte_errno,
9792 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9793 : : "fail to configure port");
9794 : : }
9795 : :
9796 : : /**
9797 : : * Release HWS resources.
9798 : : *
9799 : : * @param[in] dev
9800 : : * Pointer to the rte_eth_dev structure.
9801 : : */
9802 : : void
9803 : 0 : flow_hw_resource_release(struct rte_eth_dev *dev)
9804 : : {
9805 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9806 : : struct rte_flow_template_table *tbl;
9807 : : struct rte_flow_pattern_template *it;
9808 : : struct rte_flow_actions_template *at;
9809 : : struct mlx5_flow_group *grp;
9810 : : uint32_t i;
9811 : :
9812 [ # # ]: 0 : if (!priv->dr_ctx)
9813 : : return;
9814 : 0 : dev->flow_fp_ops = &rte_flow_fp_default_ops;
9815 : 0 : flow_hw_rxq_flag_set(dev, false);
9816 : 0 : flow_hw_flush_all_ctrl_flows(dev);
9817 : 0 : flow_hw_cleanup_tx_repr_tagging(dev);
9818 : 0 : flow_hw_cleanup_ctrl_rx_tables(dev);
9819 [ # # ]: 0 : while (!LIST_EMPTY(&priv->flow_hw_grp)) {
9820 : : grp = LIST_FIRST(&priv->flow_hw_grp);
9821 : 0 : flow_hw_group_unset_miss_group(dev, grp, NULL);
9822 : : }
9823 [ # # ]: 0 : while (!LIST_EMPTY(&priv->flow_hw_tbl_ongo)) {
9824 : : tbl = LIST_FIRST(&priv->flow_hw_tbl_ongo);
9825 : 0 : flow_hw_table_destroy(dev, tbl, NULL);
9826 : : }
9827 [ # # ]: 0 : while (!LIST_EMPTY(&priv->flow_hw_tbl)) {
9828 : : tbl = LIST_FIRST(&priv->flow_hw_tbl);
9829 : 0 : flow_hw_table_destroy(dev, tbl, NULL);
9830 : : }
9831 [ # # ]: 0 : while (!LIST_EMPTY(&priv->flow_hw_itt)) {
9832 : : it = LIST_FIRST(&priv->flow_hw_itt);
9833 : 0 : flow_hw_pattern_template_destroy(dev, it, NULL);
9834 : : }
9835 [ # # ]: 0 : while (!LIST_EMPTY(&priv->flow_hw_at)) {
9836 : : at = LIST_FIRST(&priv->flow_hw_at);
9837 : 0 : flow_hw_actions_template_destroy(dev, at, NULL);
9838 : : }
9839 [ # # ]: 0 : for (i = 0; i < MLX5_HW_ACTION_FLAG_MAX; i++) {
9840 [ # # ]: 0 : if (priv->hw_drop[i])
9841 : 0 : mlx5dr_action_destroy(priv->hw_drop[i]);
9842 [ # # ]: 0 : if (priv->hw_tag[i])
9843 : 0 : mlx5dr_action_destroy(priv->hw_tag[i]);
9844 : : }
9845 [ # # ]: 0 : if (priv->hw_def_miss)
9846 : 0 : mlx5dr_action_destroy(priv->hw_def_miss);
9847 : 0 : flow_hw_destroy_vlan(dev);
9848 : 0 : flow_hw_destroy_send_to_kernel_action(priv);
9849 : 0 : flow_hw_free_vport_actions(priv);
9850 [ # # ]: 0 : if (priv->acts_ipool) {
9851 : 0 : mlx5_ipool_destroy(priv->acts_ipool);
9852 : 0 : priv->acts_ipool = NULL;
9853 : : }
9854 [ # # ]: 0 : if (priv->hws_age_req)
9855 : 0 : mlx5_hws_age_pool_destroy(priv);
9856 [ # # ]: 0 : if (priv->hws_cpool) {
9857 : 0 : mlx5_hws_cnt_pool_destroy(priv->sh, priv->hws_cpool);
9858 : 0 : priv->hws_cpool = NULL;
9859 : : }
9860 [ # # ]: 0 : if (priv->hws_ctpool) {
9861 : 0 : flow_hw_ct_pool_destroy(dev, priv->hws_ctpool);
9862 : 0 : priv->hws_ctpool = NULL;
9863 : : }
9864 [ # # ]: 0 : if (priv->ct_mng) {
9865 : 0 : flow_hw_ct_mng_destroy(dev, priv->ct_mng);
9866 : 0 : priv->ct_mng = NULL;
9867 : : }
9868 : 0 : mlx5_flow_quota_destroy(dev);
9869 [ # # ]: 0 : for (i = 0; i < priv->nb_queue; i++) {
9870 : 0 : rte_ring_free(priv->hw_q[i].indir_iq);
9871 : 0 : rte_ring_free(priv->hw_q[i].indir_cq);
9872 : : }
9873 : 0 : mlx5_free(priv->hw_q);
9874 : 0 : priv->hw_q = NULL;
9875 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
9876 [ # # ]: 0 : if (priv->shared_host) {
9877 : 0 : struct mlx5_priv *host_priv = priv->shared_host->data->dev_private;
9878 : 0 : __atomic_fetch_sub(&host_priv->shared_refcnt, 1, __ATOMIC_RELAXED);
9879 : 0 : priv->shared_host = NULL;
9880 : : }
9881 : 0 : priv->dr_ctx = NULL;
9882 : 0 : mlx5_free(priv->hw_attr);
9883 : 0 : priv->hw_attr = NULL;
9884 : 0 : priv->nb_queue = 0;
9885 : : }
9886 : :
9887 : : /* Sets vport tag and mask, for given port, used in HWS rules. */
9888 : : void
9889 : 0 : flow_hw_set_port_info(struct rte_eth_dev *dev)
9890 : : {
9891 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9892 : 0 : uint16_t port_id = dev->data->port_id;
9893 : : struct flow_hw_port_info *info;
9894 : :
9895 : : MLX5_ASSERT(port_id < RTE_MAX_ETHPORTS);
9896 : 0 : info = &mlx5_flow_hw_port_infos[port_id];
9897 : 0 : info->regc_mask = priv->vport_meta_mask;
9898 [ # # ]: 0 : info->regc_value = priv->vport_meta_tag;
9899 [ # # ]: 0 : info->is_wire = mlx5_is_port_on_mpesw_device(priv) ? priv->mpesw_uplink : priv->master;
9900 : 0 : }
9901 : :
9902 : : /* Clears vport tag and mask used for HWS rules. */
9903 : : void
9904 : 0 : flow_hw_clear_port_info(struct rte_eth_dev *dev)
9905 : : {
9906 : 0 : uint16_t port_id = dev->data->port_id;
9907 : : struct flow_hw_port_info *info;
9908 : :
9909 : : MLX5_ASSERT(port_id < RTE_MAX_ETHPORTS);
9910 : 0 : info = &mlx5_flow_hw_port_infos[port_id];
9911 : 0 : info->regc_mask = 0;
9912 : 0 : info->regc_value = 0;
9913 : 0 : info->is_wire = 0;
9914 : 0 : }
9915 : :
9916 : : static int
9917 : 0 : flow_hw_conntrack_destroy(struct rte_eth_dev *dev __rte_unused,
9918 : : uint32_t idx,
9919 : : struct rte_flow_error *error)
9920 : : {
9921 : 0 : uint16_t owner = (uint16_t)MLX5_ACTION_CTX_CT_GET_OWNER(idx);
9922 : 0 : uint32_t ct_idx = MLX5_ACTION_CTX_CT_GET_IDX(idx);
9923 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
9924 : 0 : struct mlx5_priv *priv = owndev->data->dev_private;
9925 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
9926 : : struct mlx5_aso_ct_action *ct;
9927 : :
9928 : 0 : ct = mlx5_ipool_get(pool->cts, ct_idx);
9929 [ # # ]: 0 : if (!ct) {
9930 : 0 : return rte_flow_error_set(error, EINVAL,
9931 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9932 : : NULL,
9933 : : "Invalid CT destruction index");
9934 : : }
9935 : 0 : __atomic_store_n(&ct->state, ASO_CONNTRACK_FREE,
9936 : : __ATOMIC_RELAXED);
9937 : 0 : mlx5_ipool_free(pool->cts, ct_idx);
9938 : 0 : return 0;
9939 : : }
9940 : :
9941 : : static int
9942 : 0 : flow_hw_conntrack_query(struct rte_eth_dev *dev, uint32_t queue, uint32_t idx,
9943 : : struct rte_flow_action_conntrack *profile,
9944 : : void *user_data, bool push,
9945 : : struct rte_flow_error *error)
9946 : : {
9947 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9948 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
9949 : : struct mlx5_aso_ct_action *ct;
9950 : 0 : uint16_t owner = (uint16_t)MLX5_ACTION_CTX_CT_GET_OWNER(idx);
9951 : : uint32_t ct_idx;
9952 : :
9953 [ # # ]: 0 : if (owner != PORT_ID(priv))
9954 : 0 : return rte_flow_error_set(error, EACCES,
9955 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9956 : : NULL,
9957 : : "Can't query CT object owned by another port");
9958 : 0 : ct_idx = MLX5_ACTION_CTX_CT_GET_IDX(idx);
9959 : 0 : ct = mlx5_ipool_get(pool->cts, ct_idx);
9960 [ # # ]: 0 : if (!ct) {
9961 : 0 : return rte_flow_error_set(error, EINVAL,
9962 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9963 : : NULL,
9964 : : "Invalid CT query index");
9965 : : }
9966 : 0 : profile->peer_port = ct->peer;
9967 : 0 : profile->is_original_dir = ct->is_original;
9968 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, queue, ct, profile, user_data, push))
9969 : 0 : return rte_flow_error_set(error, EIO,
9970 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9971 : : NULL,
9972 : : "Failed to query CT context");
9973 : : return 0;
9974 : : }
9975 : :
9976 : :
9977 : : static int
9978 : 0 : flow_hw_conntrack_update(struct rte_eth_dev *dev, uint32_t queue,
9979 : : const struct rte_flow_modify_conntrack *action_conf,
9980 : : uint32_t idx, void *user_data, bool push,
9981 : : struct rte_flow_error *error)
9982 : : {
9983 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9984 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
9985 : : struct mlx5_aso_ct_action *ct;
9986 : : const struct rte_flow_action_conntrack *new_prf;
9987 : 0 : uint16_t owner = (uint16_t)MLX5_ACTION_CTX_CT_GET_OWNER(idx);
9988 : : uint32_t ct_idx;
9989 : : int ret = 0;
9990 : :
9991 [ # # ]: 0 : if (PORT_ID(priv) != owner)
9992 : 0 : return rte_flow_error_set(error, EACCES,
9993 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9994 : : NULL,
9995 : : "Can't update CT object owned by another port");
9996 : 0 : ct_idx = MLX5_ACTION_CTX_CT_GET_IDX(idx);
9997 : 0 : ct = mlx5_ipool_get(pool->cts, ct_idx);
9998 [ # # ]: 0 : if (!ct) {
9999 : 0 : return rte_flow_error_set(error, EINVAL,
10000 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10001 : : NULL,
10002 : : "Invalid CT update index");
10003 : : }
10004 : 0 : new_prf = &action_conf->new_ct;
10005 [ # # ]: 0 : if (action_conf->direction)
10006 : 0 : ct->is_original = !!new_prf->is_original_dir;
10007 [ # # ]: 0 : if (action_conf->state) {
10008 : : /* Only validate the profile when it needs to be updated. */
10009 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
10010 [ # # ]: 0 : if (ret)
10011 : : return ret;
10012 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, queue, ct, new_prf,
10013 : : user_data, push);
10014 [ # # ]: 0 : if (ret)
10015 : 0 : return rte_flow_error_set(error, EIO,
10016 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10017 : : NULL,
10018 : : "Failed to send CT context update WQE");
10019 [ # # ]: 0 : if (queue != MLX5_HW_INV_QUEUE)
10020 : : return 0;
10021 : : /* Block until ready or a failure in synchronous mode. */
10022 : 0 : ret = mlx5_aso_ct_available(priv->sh, queue, ct);
10023 [ # # ]: 0 : if (ret)
10024 : 0 : rte_flow_error_set(error, rte_errno,
10025 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10026 : : NULL,
10027 : : "Timeout to get the CT update");
10028 : : }
10029 : : return ret;
10030 : : }
10031 : :
10032 : : static struct rte_flow_action_handle *
10033 : 0 : flow_hw_conntrack_create(struct rte_eth_dev *dev, uint32_t queue,
10034 : : const struct rte_flow_action_conntrack *pro,
10035 : : void *user_data, bool push,
10036 : : struct rte_flow_error *error)
10037 : : {
10038 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10039 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
10040 : : struct mlx5_aso_ct_action *ct;
10041 : 0 : uint32_t ct_idx = 0;
10042 : : int ret;
10043 : : bool async = !!(queue != MLX5_HW_INV_QUEUE);
10044 : :
10045 [ # # ]: 0 : if (!pool) {
10046 : 0 : rte_flow_error_set(error, EINVAL,
10047 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10048 : : "CT is not enabled");
10049 : 0 : return 0;
10050 : : }
10051 : 0 : ct = mlx5_ipool_zmalloc(pool->cts, &ct_idx);
10052 [ # # ]: 0 : if (!ct) {
10053 : 0 : rte_flow_error_set(error, rte_errno,
10054 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10055 : : "Failed to allocate CT object");
10056 : 0 : return 0;
10057 : : }
10058 : 0 : ct->offset = ct_idx - 1;
10059 : 0 : ct->is_original = !!pro->is_original_dir;
10060 : 0 : ct->peer = pro->peer_port;
10061 : 0 : ct->pool = pool;
10062 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(priv->sh, queue, ct, pro, user_data, push)) {
10063 : 0 : mlx5_ipool_free(pool->cts, ct_idx);
10064 : 0 : rte_flow_error_set(error, EBUSY,
10065 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10066 : : "Failed to update CT");
10067 : 0 : return 0;
10068 : : }
10069 [ # # ]: 0 : if (!async) {
10070 : 0 : ret = mlx5_aso_ct_available(priv->sh, queue, ct);
10071 [ # # ]: 0 : if (ret) {
10072 : 0 : mlx5_ipool_free(pool->cts, ct_idx);
10073 : 0 : rte_flow_error_set(error, rte_errno,
10074 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10075 : : NULL,
10076 : : "Timeout to get the CT update");
10077 : 0 : return 0;
10078 : : }
10079 : : }
10080 : 0 : return (struct rte_flow_action_handle *)(uintptr_t)
10081 : 0 : MLX5_ACTION_CTX_CT_GEN_IDX(PORT_ID(priv), ct_idx);
10082 : : }
10083 : :
10084 : : /**
10085 : : * Validate shared action.
10086 : : *
10087 : : * @param[in] dev
10088 : : * Pointer to the rte_eth_dev structure.
10089 : : * @param[in] queue
10090 : : * Which queue to be used.
10091 : : * @param[in] attr
10092 : : * Operation attribute.
10093 : : * @param[in] conf
10094 : : * Indirect action configuration.
10095 : : * @param[in] action
10096 : : * rte_flow action detail.
10097 : : * @param[in] user_data
10098 : : * Pointer to the user_data.
10099 : : * @param[out] error
10100 : : * Pointer to error structure.
10101 : : *
10102 : : * @return
10103 : : * 0 on success, otherwise negative errno value.
10104 : : */
10105 : : static int
10106 : 0 : flow_hw_action_handle_validate(struct rte_eth_dev *dev, uint32_t queue,
10107 : : const struct rte_flow_op_attr *attr,
10108 : : const struct rte_flow_indir_action_conf *conf,
10109 : : const struct rte_flow_action *action,
10110 : : void *user_data,
10111 : : struct rte_flow_error *error)
10112 : : {
10113 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10114 : :
10115 : : RTE_SET_USED(attr);
10116 : : RTE_SET_USED(queue);
10117 : : RTE_SET_USED(user_data);
10118 [ # # # # : 0 : switch (action->type) {
# # # ]
10119 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
10120 [ # # ]: 0 : if (!priv->hws_age_req)
10121 : 0 : return rte_flow_error_set(error, EINVAL,
10122 : : RTE_FLOW_ERROR_TYPE_ACTION,
10123 : : NULL,
10124 : : "aging pool not initialized");
10125 : : break;
10126 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
10127 [ # # ]: 0 : if (!priv->hws_cpool)
10128 : 0 : return rte_flow_error_set(error, EINVAL,
10129 : : RTE_FLOW_ERROR_TYPE_ACTION,
10130 : : NULL,
10131 : : "counters pool not initialized");
10132 : : break;
10133 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
10134 [ # # ]: 0 : if (priv->hws_ctpool == NULL)
10135 : 0 : return rte_flow_error_set(error, EINVAL,
10136 : : RTE_FLOW_ERROR_TYPE_ACTION,
10137 : : NULL,
10138 : : "CT pool not initialized");
10139 : 0 : return mlx5_validate_action_ct(dev, action->conf, error);
10140 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
10141 : 0 : return flow_hw_validate_action_meter_mark(dev, action, error);
10142 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
10143 : 0 : return flow_dv_action_validate(dev, conf, action, error);
10144 : : case RTE_FLOW_ACTION_TYPE_QUOTA:
10145 : : return 0;
10146 : 0 : default:
10147 : 0 : return rte_flow_error_set(error, ENOTSUP,
10148 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10149 : : "action type not supported");
10150 : : }
10151 : : return 0;
10152 : : }
10153 : :
10154 : : static __rte_always_inline bool
10155 : : flow_hw_action_push(const struct rte_flow_op_attr *attr)
10156 : : {
10157 [ # # # # : 0 : return attr ? !attr->postpone : true;
# # # # #
# # # #
# ]
10158 : : }
10159 : :
10160 : : static __rte_always_inline struct mlx5_hw_q_job *
10161 : : flow_hw_action_job_init(struct mlx5_priv *priv, uint32_t queue,
10162 : : const struct rte_flow_action_handle *handle,
10163 : : void *user_data, void *query_data,
10164 : : enum mlx5_hw_job_type type,
10165 : : struct rte_flow_error *error)
10166 : : {
10167 : : struct mlx5_hw_q_job *job;
10168 : :
10169 : : MLX5_ASSERT(queue != MLX5_HW_INV_QUEUE);
10170 : : job = flow_hw_job_get(priv, queue);
10171 [ # # # # : 0 : if (!job) {
# # # # #
# # # #
# ]
10172 : 0 : rte_flow_error_set(error, ENOMEM,
10173 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
10174 : : "Action destroy failed due to queue full.");
10175 : : return NULL;
10176 : : }
10177 : 0 : job->type = type;
10178 : 0 : job->action = handle;
10179 : 0 : job->user_data = user_data;
10180 : 0 : job->query.user = query_data;
10181 : : return job;
10182 : : }
10183 : :
10184 : : static __rte_always_inline void
10185 : : flow_hw_action_finalize(struct rte_eth_dev *dev, uint32_t queue,
10186 : : struct mlx5_hw_q_job *job,
10187 : : bool push, bool aso, bool status)
10188 : : {
10189 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10190 : :
10191 [ # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE)
10192 : 0 : queue = CTRL_QUEUE_ID(priv);
10193 [ # # # # : 0 : if (likely(status)) {
# # # # #
# # # ]
10194 : : /* 1. add new job to a queue */
10195 [ # # # # : 0 : if (!aso)
# # # # #
# ]
10196 [ # # # # : 0 : rte_ring_enqueue(push ?
# # # # #
# # # #
# ]
10197 : 0 : priv->hw_q[queue].indir_cq :
10198 : 0 : priv->hw_q[queue].indir_iq,
10199 : : job);
10200 : : /* 2. send pending jobs */
10201 [ # # # # : 0 : if (push)
# # # # #
# # # #
# ]
10202 : 0 : __flow_hw_push_action(dev, queue);
10203 : : } else {
10204 : : flow_hw_job_put(priv, job, queue);
10205 : : }
10206 : : }
10207 : :
10208 : : /**
10209 : : * Create shared action.
10210 : : *
10211 : : * @param[in] dev
10212 : : * Pointer to the rte_eth_dev structure.
10213 : : * @param[in] queue
10214 : : * Which queue to be used.
10215 : : * @param[in] attr
10216 : : * Operation attribute.
10217 : : * @param[in] conf
10218 : : * Indirect action configuration.
10219 : : * @param[in] action
10220 : : * rte_flow action detail.
10221 : : * @param[in] user_data
10222 : : * Pointer to the user_data.
10223 : : * @param[out] error
10224 : : * Pointer to error structure.
10225 : : *
10226 : : * @return
10227 : : * Action handle on success, NULL otherwise and rte_errno is set.
10228 : : */
10229 : : static struct rte_flow_action_handle *
10230 : 0 : flow_hw_action_handle_create(struct rte_eth_dev *dev, uint32_t queue,
10231 : : const struct rte_flow_op_attr *attr,
10232 : : const struct rte_flow_indir_action_conf *conf,
10233 : : const struct rte_flow_action *action,
10234 : : void *user_data,
10235 : : struct rte_flow_error *error)
10236 : : {
10237 : : struct rte_flow_action_handle *handle = NULL;
10238 : : struct mlx5_hw_q_job *job = NULL;
10239 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
10240 : : const struct rte_flow_action_age *age;
10241 : : struct mlx5_aso_mtr *aso_mtr;
10242 : : cnt_id_t cnt_id;
10243 : : uint32_t mtr_id;
10244 : : uint32_t age_idx;
10245 : : bool push = flow_hw_action_push(attr);
10246 : : bool aso = false;
10247 : :
10248 [ # # ]: 0 : if (attr) {
10249 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
10250 : : NULL, MLX5_HW_Q_JOB_TYPE_CREATE,
10251 : : error);
10252 : : if (!job)
10253 : 0 : return NULL;
10254 : : }
10255 [ # # # # : 0 : switch (action->type) {
# # # ]
10256 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
10257 [ # # ]: 0 : if (priv->hws_strict_queue) {
10258 : 0 : struct mlx5_age_info *info = GET_PORT_AGE_INFO(priv);
10259 : :
10260 [ # # ]: 0 : if (queue >= info->hw_q_age->nb_rings) {
10261 : 0 : rte_flow_error_set(error, EINVAL,
10262 : : RTE_FLOW_ERROR_TYPE_ACTION,
10263 : : NULL,
10264 : : "Invalid queue ID for indirect AGE.");
10265 : 0 : rte_errno = EINVAL;
10266 : 0 : return NULL;
10267 : : }
10268 : : }
10269 : 0 : age = action->conf;
10270 : 0 : age_idx = mlx5_hws_age_action_create(priv, queue, true, age,
10271 : : 0, error);
10272 [ # # ]: 0 : if (age_idx == 0) {
10273 : 0 : rte_flow_error_set(error, ENODEV,
10274 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10275 : : "AGE are not configured!");
10276 : : } else {
10277 : 0 : age_idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
10278 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
10279 : 0 : handle =
10280 : 0 : (struct rte_flow_action_handle *)(uintptr_t)age_idx;
10281 : : }
10282 : : break;
10283 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
10284 [ # # ]: 0 : if (mlx5_hws_cnt_shared_get(priv->hws_cpool, &cnt_id, 0))
10285 : 0 : rte_flow_error_set(error, ENODEV,
10286 : : RTE_FLOW_ERROR_TYPE_ACTION,
10287 : : NULL,
10288 : : "counter are not configured!");
10289 : : else
10290 : 0 : handle = (struct rte_flow_action_handle *)
10291 : 0 : (uintptr_t)cnt_id;
10292 : : break;
10293 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
10294 : : aso = true;
10295 : 0 : handle = flow_hw_conntrack_create(dev, queue, action->conf, job,
10296 : : push, error);
10297 : 0 : break;
10298 [ # # ]: 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
10299 : : aso = true;
10300 : : aso_mtr = flow_hw_meter_mark_alloc(dev, queue, action, job, push);
10301 : : if (!aso_mtr)
10302 : : break;
10303 : 0 : mtr_id = (MLX5_INDIRECT_ACTION_TYPE_METER_MARK <<
10304 : 0 : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | (aso_mtr->fm.meter_id);
10305 : 0 : handle = (struct rte_flow_action_handle *)(uintptr_t)mtr_id;
10306 : 0 : break;
10307 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
10308 : 0 : handle = flow_dv_action_create(dev, conf, action, error);
10309 : 0 : break;
10310 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
10311 : : aso = true;
10312 : 0 : handle = mlx5_quota_alloc(dev, queue, action->conf,
10313 : : job, push, error);
10314 : 0 : break;
10315 : 0 : default:
10316 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10317 : : NULL, "action type not supported");
10318 : 0 : break;
10319 : : }
10320 [ # # ]: 0 : if (job) {
10321 : 0 : job->action = handle;
10322 : 0 : job->indirect_type = MLX5_HW_INDIRECT_TYPE_LEGACY;
10323 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso,
10324 : : handle != NULL);
10325 : : }
10326 : : return handle;
10327 : : }
10328 : :
10329 : : static int
10330 : 0 : mlx5_flow_update_meter_mark(struct rte_eth_dev *dev, uint32_t queue,
10331 : : const struct rte_flow_update_meter_mark *upd_meter_mark,
10332 : : uint32_t idx, bool push,
10333 : : struct mlx5_hw_q_job *job, struct rte_flow_error *error)
10334 : : {
10335 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10336 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
10337 : : const struct rte_flow_action_meter_mark *meter_mark = &upd_meter_mark->meter_mark;
10338 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
10339 : : struct mlx5_flow_meter_info *fm;
10340 : :
10341 [ # # ]: 0 : if (!aso_mtr)
10342 : 0 : return rte_flow_error_set(error, EINVAL,
10343 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10344 : : NULL, "Invalid meter_mark update index");
10345 : : fm = &aso_mtr->fm;
10346 [ # # ]: 0 : if (upd_meter_mark->profile_valid)
10347 : 0 : fm->profile = (struct mlx5_flow_meter_profile *)
10348 : 0 : (meter_mark->profile);
10349 [ # # ]: 0 : if (upd_meter_mark->color_mode_valid)
10350 : 0 : fm->color_aware = meter_mark->color_mode;
10351 [ # # ]: 0 : if (upd_meter_mark->state_valid)
10352 : 0 : fm->is_enable = meter_mark->state;
10353 : : /* Update ASO flow meter by wqe. */
10354 [ # # ]: 0 : if (mlx5_aso_meter_update_by_wqe(priv->sh, queue,
10355 : : aso_mtr, &priv->mtr_bulk, job, push))
10356 : 0 : return rte_flow_error_set(error, EINVAL,
10357 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10358 : : NULL, "Unable to update ASO meter WQE");
10359 : : /* Wait for ASO object completion. */
10360 [ # # # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE &&
10361 : 0 : mlx5_aso_mtr_wait(priv->sh, MLX5_HW_INV_QUEUE, aso_mtr))
10362 : 0 : return rte_flow_error_set(error, EINVAL,
10363 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10364 : : NULL, "Unable to wait for ASO meter CQE");
10365 : : return 0;
10366 : : }
10367 : :
10368 : : /**
10369 : : * Update shared action.
10370 : : *
10371 : : * @param[in] dev
10372 : : * Pointer to the rte_eth_dev structure.
10373 : : * @param[in] queue
10374 : : * Which queue to be used.
10375 : : * @param[in] attr
10376 : : * Operation attribute.
10377 : : * @param[in] handle
10378 : : * Action handle to be updated.
10379 : : * @param[in] update
10380 : : * Update value.
10381 : : * @param[in] user_data
10382 : : * Pointer to the user_data.
10383 : : * @param[out] error
10384 : : * Pointer to error structure.
10385 : : *
10386 : : * @return
10387 : : * 0 on success, negative value otherwise and rte_errno is set.
10388 : : */
10389 : : static int
10390 : 0 : flow_hw_action_handle_update(struct rte_eth_dev *dev, uint32_t queue,
10391 : : const struct rte_flow_op_attr *attr,
10392 : : struct rte_flow_action_handle *handle,
10393 : : const void *update,
10394 : : void *user_data,
10395 : : struct rte_flow_error *error)
10396 : : {
10397 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10398 : : const struct rte_flow_modify_conntrack *ct_conf =
10399 : : (const struct rte_flow_modify_conntrack *)update;
10400 : : struct mlx5_hw_q_job *job = NULL;
10401 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10402 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10403 [ # # ]: 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
10404 : : int ret = 0;
10405 : : bool push = flow_hw_action_push(attr);
10406 : : bool aso = false;
10407 : :
10408 [ # # ]: 0 : if (attr) {
10409 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
10410 : : NULL, MLX5_HW_Q_JOB_TYPE_UPDATE,
10411 : : error);
10412 : : if (!job)
10413 : 0 : return -rte_errno;
10414 : : }
10415 [ # # # # : 0 : switch (type) {
# # ]
10416 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
10417 : 0 : ret = mlx5_hws_age_action_update(priv, idx, update, error);
10418 : 0 : break;
10419 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
10420 [ # # ]: 0 : if (ct_conf->state)
10421 : : aso = true;
10422 : 0 : ret = flow_hw_conntrack_update(dev, queue, update, act_idx,
10423 : : job, push, error);
10424 : 0 : break;
10425 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
10426 : : aso = true;
10427 : 0 : ret = mlx5_flow_update_meter_mark(dev, queue, update, idx, push,
10428 : : job, error);
10429 : 0 : break;
10430 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
10431 : 0 : ret = flow_dv_action_update(dev, handle, update, error);
10432 : 0 : break;
10433 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
10434 : : aso = true;
10435 : 0 : ret = mlx5_quota_query_update(dev, queue, handle, update, NULL,
10436 : : job, push, error);
10437 : 0 : break;
10438 : 0 : default:
10439 : : ret = -ENOTSUP;
10440 : 0 : rte_flow_error_set(error, ENOTSUP,
10441 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10442 : : "action type not supported");
10443 : 0 : break;
10444 : : }
10445 [ # # ]: 0 : if (job)
10446 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
10447 : : return ret;
10448 : : }
10449 : :
10450 : : /**
10451 : : * Destroy shared action.
10452 : : *
10453 : : * @param[in] dev
10454 : : * Pointer to the rte_eth_dev structure.
10455 : : * @param[in] queue
10456 : : * Which queue to be used.
10457 : : * @param[in] attr
10458 : : * Operation attribute.
10459 : : * @param[in] handle
10460 : : * Action handle to be destroyed.
10461 : : * @param[in] user_data
10462 : : * Pointer to the user_data.
10463 : : * @param[out] error
10464 : : * Pointer to error structure.
10465 : : *
10466 : : * @return
10467 : : * 0 on success, negative value otherwise and rte_errno is set.
10468 : : */
10469 : : static int
10470 : 0 : flow_hw_action_handle_destroy(struct rte_eth_dev *dev, uint32_t queue,
10471 : : const struct rte_flow_op_attr *attr,
10472 : : struct rte_flow_action_handle *handle,
10473 : : void *user_data,
10474 : : struct rte_flow_error *error)
10475 : : {
10476 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10477 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10478 : 0 : uint32_t age_idx = act_idx & MLX5_HWS_AGE_IDX_MASK;
10479 : : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
10480 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10481 [ # # ]: 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
10482 : : struct mlx5_hw_q_job *job = NULL;
10483 : : struct mlx5_aso_mtr *aso_mtr;
10484 : : struct mlx5_flow_meter_info *fm;
10485 : : bool push = flow_hw_action_push(attr);
10486 : : bool aso = false;
10487 : : int ret = 0;
10488 : :
10489 [ # # ]: 0 : if (attr) {
10490 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
10491 : : NULL, MLX5_HW_Q_JOB_TYPE_DESTROY,
10492 : : error);
10493 : : if (!job)
10494 : 0 : return -rte_errno;
10495 : : }
10496 [ # # # # : 0 : switch (type) {
# # # ]
10497 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
10498 : 0 : ret = mlx5_hws_age_action_destroy(priv, age_idx, error);
10499 : 0 : break;
10500 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
10501 [ # # ]: 0 : age_idx = mlx5_hws_cnt_age_get(priv->hws_cpool, act_idx);
10502 [ # # ]: 0 : if (age_idx != 0)
10503 : : /*
10504 : : * If this counter belongs to indirect AGE, here is the
10505 : : * time to update the AGE.
10506 : : */
10507 : : mlx5_hws_age_nb_cnt_decrease(priv, age_idx);
10508 [ # # ]: 0 : mlx5_hws_cnt_shared_put(priv->hws_cpool, &act_idx);
10509 : : break;
10510 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
10511 : 0 : ret = flow_hw_conntrack_destroy(dev, act_idx, error);
10512 : 0 : break;
10513 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
10514 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
10515 [ # # ]: 0 : if (!aso_mtr) {
10516 : : ret = -EINVAL;
10517 : 0 : rte_flow_error_set(error, EINVAL,
10518 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10519 : : NULL, "Invalid meter_mark destroy index");
10520 : 0 : break;
10521 : : }
10522 : : fm = &aso_mtr->fm;
10523 : 0 : fm->is_enable = 0;
10524 : : /* Update ASO flow meter by wqe. */
10525 [ # # ]: 0 : if (mlx5_aso_meter_update_by_wqe(priv->sh, queue, aso_mtr,
10526 : : &priv->mtr_bulk, job, push)) {
10527 : : ret = -EINVAL;
10528 : 0 : rte_flow_error_set(error, EINVAL,
10529 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10530 : : NULL, "Unable to update ASO meter WQE");
10531 : 0 : break;
10532 : : }
10533 : : /* Wait for ASO object completion. */
10534 [ # # # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE &&
10535 : 0 : mlx5_aso_mtr_wait(priv->sh, MLX5_HW_INV_QUEUE, aso_mtr)) {
10536 : : ret = -EINVAL;
10537 : 0 : rte_flow_error_set(error, EINVAL,
10538 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10539 : : NULL, "Unable to wait for ASO meter CQE");
10540 : 0 : break;
10541 : : }
10542 [ # # ]: 0 : if (!job)
10543 : 0 : mlx5_ipool_free(pool->idx_pool, idx);
10544 : : else
10545 : : aso = true;
10546 : : break;
10547 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
10548 : 0 : ret = flow_dv_action_destroy(dev, handle, error);
10549 : 0 : break;
10550 : : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
10551 : : break;
10552 : 0 : default:
10553 : : ret = -ENOTSUP;
10554 : 0 : rte_flow_error_set(error, ENOTSUP,
10555 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10556 : : "action type not supported");
10557 : 0 : break;
10558 : : }
10559 [ # # ]: 0 : if (job)
10560 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
10561 : : return ret;
10562 : : }
10563 : :
10564 : : static int
10565 : 0 : flow_hw_query_counter(const struct rte_eth_dev *dev, uint32_t counter,
10566 : : void *data, struct rte_flow_error *error)
10567 : : {
10568 : : struct mlx5_hws_cnt_pool *hpool;
10569 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
10570 : : struct mlx5_hws_cnt *cnt;
10571 : : struct rte_flow_query_count *qc = data;
10572 : : uint32_t iidx;
10573 : : uint64_t pkts, bytes;
10574 : :
10575 [ # # ]: 0 : if (!mlx5_hws_cnt_id_valid(counter))
10576 : 0 : return rte_flow_error_set(error, EINVAL,
10577 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10578 : : "counter are not available");
10579 [ # # ]: 0 : hpool = mlx5_hws_cnt_host_pool(priv->hws_cpool);
10580 : : iidx = mlx5_hws_cnt_iidx(hpool, counter);
10581 : 0 : cnt = &hpool->pool[iidx];
10582 : : __hws_cnt_query_raw(priv->hws_cpool, counter, &pkts, &bytes);
10583 : 0 : qc->hits_set = 1;
10584 : 0 : qc->bytes_set = 1;
10585 : 0 : qc->hits = pkts - cnt->reset.hits;
10586 : 0 : qc->bytes = bytes - cnt->reset.bytes;
10587 [ # # ]: 0 : if (qc->reset) {
10588 : 0 : cnt->reset.bytes = bytes;
10589 : 0 : cnt->reset.hits = pkts;
10590 : : }
10591 : : return 0;
10592 : : }
10593 : :
10594 : : /**
10595 : : * Query a flow rule AGE action for aging information.
10596 : : *
10597 : : * @param[in] dev
10598 : : * Pointer to Ethernet device.
10599 : : * @param[in] age_idx
10600 : : * Index of AGE action parameter.
10601 : : * @param[out] data
10602 : : * Data retrieved by the query.
10603 : : * @param[out] error
10604 : : * Perform verbose error reporting if not NULL.
10605 : : *
10606 : : * @return
10607 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10608 : : */
10609 : : static int
10610 : 0 : flow_hw_query_age(const struct rte_eth_dev *dev, uint32_t age_idx, void *data,
10611 : : struct rte_flow_error *error)
10612 : : {
10613 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10614 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
10615 : 0 : struct mlx5_indexed_pool *ipool = age_info->ages_ipool;
10616 : 0 : struct mlx5_hws_age_param *param = mlx5_ipool_get(ipool, age_idx);
10617 : : struct rte_flow_query_age *resp = data;
10618 : :
10619 [ # # # # ]: 0 : if (!param || !param->timeout)
10620 : 0 : return rte_flow_error_set(error, EINVAL,
10621 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10622 : : NULL, "age data not available");
10623 [ # # # ]: 0 : switch (__atomic_load_n(¶m->state, __ATOMIC_RELAXED)) {
10624 : 0 : case HWS_AGE_AGED_OUT_REPORTED:
10625 : : case HWS_AGE_AGED_OUT_NOT_REPORTED:
10626 : 0 : resp->aged = 1;
10627 : 0 : break;
10628 : 0 : case HWS_AGE_CANDIDATE:
10629 : : case HWS_AGE_CANDIDATE_INSIDE_RING:
10630 : 0 : resp->aged = 0;
10631 : 0 : break;
10632 : : case HWS_AGE_FREE:
10633 : : /*
10634 : : * When state is FREE the flow itself should be invalid.
10635 : : * Fall-through.
10636 : : */
10637 : : default:
10638 : : MLX5_ASSERT(0);
10639 : : break;
10640 : : }
10641 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
10642 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
10643 : 0 : resp->sec_since_last_hit = __atomic_load_n
10644 : 0 : (¶m->sec_since_last_hit, __ATOMIC_RELAXED);
10645 : : return 0;
10646 : : }
10647 : :
10648 : : static int
10649 : 0 : flow_hw_query(struct rte_eth_dev *dev, struct rte_flow *flow,
10650 : : const struct rte_flow_action *actions, void *data,
10651 : : struct rte_flow_error *error)
10652 : : {
10653 : : int ret = -EINVAL;
10654 : : struct rte_flow_hw *hw_flow = (struct rte_flow_hw *)flow;
10655 : :
10656 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
10657 [ # # # # ]: 0 : switch (actions->type) {
10658 : : case RTE_FLOW_ACTION_TYPE_VOID:
10659 : : break;
10660 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
10661 : 0 : ret = flow_hw_query_counter(dev, hw_flow->cnt_id, data,
10662 : : error);
10663 : 0 : break;
10664 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
10665 : 0 : ret = flow_hw_query_age(dev, hw_flow->age_idx, data,
10666 : : error);
10667 : 0 : break;
10668 : 0 : default:
10669 : 0 : return rte_flow_error_set(error, ENOTSUP,
10670 : : RTE_FLOW_ERROR_TYPE_ACTION,
10671 : : actions,
10672 : : "action not supported");
10673 : : }
10674 : : }
10675 : : return ret;
10676 : : }
10677 : :
10678 : : /**
10679 : : * Validate indirect action.
10680 : : *
10681 : : * @param[in] dev
10682 : : * Pointer to the Ethernet device structure.
10683 : : * @param[in] conf
10684 : : * Shared action configuration.
10685 : : * @param[in] action
10686 : : * Action specification used to create indirect action.
10687 : : * @param[out] error
10688 : : * Perform verbose error reporting if not NULL. Initialized in case of
10689 : : * error only.
10690 : : *
10691 : : * @return
10692 : : * 0 on success, otherwise negative errno value.
10693 : : */
10694 : : static int
10695 : 0 : flow_hw_action_validate(struct rte_eth_dev *dev,
10696 : : const struct rte_flow_indir_action_conf *conf,
10697 : : const struct rte_flow_action *action,
10698 : : struct rte_flow_error *err)
10699 : : {
10700 : 0 : return flow_hw_action_handle_validate(dev, MLX5_HW_INV_QUEUE, NULL,
10701 : : conf, action, NULL, err);
10702 : : }
10703 : :
10704 : : /**
10705 : : * Create indirect action.
10706 : : *
10707 : : * @param[in] dev
10708 : : * Pointer to the Ethernet device structure.
10709 : : * @param[in] conf
10710 : : * Shared action configuration.
10711 : : * @param[in] action
10712 : : * Action specification used to create indirect action.
10713 : : * @param[out] error
10714 : : * Perform verbose error reporting if not NULL. Initialized in case of
10715 : : * error only.
10716 : : *
10717 : : * @return
10718 : : * A valid shared action handle in case of success, NULL otherwise and
10719 : : * rte_errno is set.
10720 : : */
10721 : : static struct rte_flow_action_handle *
10722 : 0 : flow_hw_action_create(struct rte_eth_dev *dev,
10723 : : const struct rte_flow_indir_action_conf *conf,
10724 : : const struct rte_flow_action *action,
10725 : : struct rte_flow_error *err)
10726 : : {
10727 : 0 : return flow_hw_action_handle_create(dev, MLX5_HW_INV_QUEUE,
10728 : : NULL, conf, action, NULL, err);
10729 : : }
10730 : :
10731 : : /**
10732 : : * Destroy the indirect action.
10733 : : * Release action related resources on the NIC and the memory.
10734 : : * Lock free, (mutex should be acquired by caller).
10735 : : * Dispatcher for action type specific call.
10736 : : *
10737 : : * @param[in] dev
10738 : : * Pointer to the Ethernet device structure.
10739 : : * @param[in] handle
10740 : : * The indirect action object handle to be removed.
10741 : : * @param[out] error
10742 : : * Perform verbose error reporting if not NULL. Initialized in case of
10743 : : * error only.
10744 : : *
10745 : : * @return
10746 : : * 0 on success, otherwise negative errno value.
10747 : : */
10748 : : static int
10749 : 0 : flow_hw_action_destroy(struct rte_eth_dev *dev,
10750 : : struct rte_flow_action_handle *handle,
10751 : : struct rte_flow_error *error)
10752 : : {
10753 : 0 : return flow_hw_action_handle_destroy(dev, MLX5_HW_INV_QUEUE,
10754 : : NULL, handle, NULL, error);
10755 : : }
10756 : :
10757 : : /**
10758 : : * Updates in place shared action configuration.
10759 : : *
10760 : : * @param[in] dev
10761 : : * Pointer to the Ethernet device structure.
10762 : : * @param[in] handle
10763 : : * The indirect action object handle to be updated.
10764 : : * @param[in] update
10765 : : * Action specification used to modify the action pointed by *handle*.
10766 : : * *update* could be of same type with the action pointed by the *handle*
10767 : : * handle argument, or some other structures like a wrapper, depending on
10768 : : * the indirect action type.
10769 : : * @param[out] error
10770 : : * Perform verbose error reporting if not NULL. Initialized in case of
10771 : : * error only.
10772 : : *
10773 : : * @return
10774 : : * 0 on success, otherwise negative errno value.
10775 : : */
10776 : : static int
10777 : 0 : flow_hw_action_update(struct rte_eth_dev *dev,
10778 : : struct rte_flow_action_handle *handle,
10779 : : const void *update,
10780 : : struct rte_flow_error *err)
10781 : : {
10782 : 0 : return flow_hw_action_handle_update(dev, MLX5_HW_INV_QUEUE,
10783 : : NULL, handle, update, NULL, err);
10784 : : }
10785 : :
10786 : : static int
10787 : 0 : flow_hw_action_handle_query(struct rte_eth_dev *dev, uint32_t queue,
10788 : : const struct rte_flow_op_attr *attr,
10789 : : const struct rte_flow_action_handle *handle,
10790 : : void *data, void *user_data,
10791 : : struct rte_flow_error *error)
10792 : : {
10793 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10794 : : struct mlx5_hw_q_job *job = NULL;
10795 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10796 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10797 [ # # ]: 0 : uint32_t age_idx = act_idx & MLX5_HWS_AGE_IDX_MASK;
10798 : : int ret;
10799 : : bool push = flow_hw_action_push(attr);
10800 : : bool aso = false;
10801 : :
10802 [ # # ]: 0 : if (attr) {
10803 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
10804 : : data, MLX5_HW_Q_JOB_TYPE_QUERY,
10805 : : error);
10806 : : if (!job)
10807 : 0 : return -rte_errno;
10808 : : }
10809 [ # # # # : 0 : switch (type) {
# ]
10810 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
10811 : 0 : ret = flow_hw_query_age(dev, age_idx, data, error);
10812 : 0 : break;
10813 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
10814 : 0 : ret = flow_hw_query_counter(dev, act_idx, data, error);
10815 : 0 : break;
10816 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
10817 : : aso = true;
10818 [ # # ]: 0 : if (job)
10819 : 0 : job->query.user = data;
10820 : 0 : ret = flow_hw_conntrack_query(dev, queue, act_idx, data,
10821 : : job, push, error);
10822 : 0 : break;
10823 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
10824 : : aso = true;
10825 : 0 : ret = mlx5_quota_query(dev, queue, handle, data,
10826 : : job, push, error);
10827 : 0 : break;
10828 : 0 : default:
10829 : : ret = -ENOTSUP;
10830 : 0 : rte_flow_error_set(error, ENOTSUP,
10831 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
10832 : : "action type not supported");
10833 : 0 : break;
10834 : : }
10835 [ # # ]: 0 : if (job)
10836 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
10837 : : return ret;
10838 : : }
10839 : :
10840 : : static int
10841 : 0 : flow_hw_async_action_handle_query_update
10842 : : (struct rte_eth_dev *dev, uint32_t queue,
10843 : : const struct rte_flow_op_attr *attr,
10844 : : struct rte_flow_action_handle *handle,
10845 : : const void *update, void *query,
10846 : : enum rte_flow_query_update_mode qu_mode,
10847 : : void *user_data, struct rte_flow_error *error)
10848 : : {
10849 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
10850 : : bool push = flow_hw_action_push(attr);
10851 : : bool aso = false;
10852 : : struct mlx5_hw_q_job *job = NULL;
10853 : : int ret = 0;
10854 : :
10855 [ # # ]: 0 : if (attr) {
10856 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
10857 : : query,
10858 : : MLX5_HW_Q_JOB_TYPE_UPDATE_QUERY,
10859 : : error);
10860 : : if (!job)
10861 : 0 : return -rte_errno;
10862 : : }
10863 [ # # ]: 0 : switch (MLX5_INDIRECT_ACTION_TYPE_GET(handle)) {
10864 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
10865 [ # # ]: 0 : if (qu_mode != RTE_FLOW_QU_QUERY_FIRST) {
10866 : 0 : ret = rte_flow_error_set
10867 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
10868 : : NULL, "quota action must query before update");
10869 : 0 : break;
10870 : : }
10871 : : aso = true;
10872 : 0 : ret = mlx5_quota_query_update(dev, queue, handle,
10873 : : update, query, job, push, error);
10874 : 0 : break;
10875 : 0 : default:
10876 : 0 : ret = rte_flow_error_set(error, ENOTSUP,
10877 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL, "update and query not supportred");
10878 : : }
10879 [ # # ]: 0 : if (job)
10880 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
10881 : : return ret;
10882 : : }
10883 : :
10884 : : static int
10885 : 0 : flow_hw_action_query(struct rte_eth_dev *dev,
10886 : : const struct rte_flow_action_handle *handle, void *data,
10887 : : struct rte_flow_error *error)
10888 : : {
10889 : 0 : return flow_hw_action_handle_query(dev, MLX5_HW_INV_QUEUE, NULL,
10890 : : handle, data, NULL, error);
10891 : : }
10892 : :
10893 : : static int
10894 : 0 : flow_hw_action_query_update(struct rte_eth_dev *dev,
10895 : : struct rte_flow_action_handle *handle,
10896 : : const void *update, void *query,
10897 : : enum rte_flow_query_update_mode qu_mode,
10898 : : struct rte_flow_error *error)
10899 : : {
10900 : 0 : return flow_hw_async_action_handle_query_update(dev, MLX5_HW_INV_QUEUE,
10901 : : NULL, handle, update,
10902 : : query, qu_mode, NULL,
10903 : : error);
10904 : : }
10905 : :
10906 : : /**
10907 : : * Get aged-out flows of a given port on the given HWS flow queue.
10908 : : *
10909 : : * @param[in] dev
10910 : : * Pointer to the Ethernet device structure.
10911 : : * @param[in] queue_id
10912 : : * Flow queue to query. Ignored when RTE_FLOW_PORT_FLAG_STRICT_QUEUE not set.
10913 : : * @param[in, out] contexts
10914 : : * The address of an array of pointers to the aged-out flows contexts.
10915 : : * @param[in] nb_contexts
10916 : : * The length of context array pointers.
10917 : : * @param[out] error
10918 : : * Perform verbose error reporting if not NULL. Initialized in case of
10919 : : * error only.
10920 : : *
10921 : : * @return
10922 : : * if nb_contexts is 0, return the amount of all aged contexts.
10923 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10924 : : * in the context array, otherwise negative errno value.
10925 : : */
10926 : : static int
10927 : 0 : flow_hw_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
10928 : : void **contexts, uint32_t nb_contexts,
10929 : : struct rte_flow_error *error)
10930 : : {
10931 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10932 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
10933 : : struct rte_ring *r;
10934 : : int nb_flows = 0;
10935 : :
10936 [ # # ]: 0 : if (nb_contexts && !contexts)
10937 : 0 : return rte_flow_error_set(error, EINVAL,
10938 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10939 : : NULL, "empty context");
10940 [ # # ]: 0 : if (priv->hws_strict_queue) {
10941 [ # # ]: 0 : if (queue_id >= age_info->hw_q_age->nb_rings)
10942 : 0 : return rte_flow_error_set(error, EINVAL,
10943 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10944 : : NULL, "invalid queue id");
10945 : 0 : r = age_info->hw_q_age->aged_lists[queue_id];
10946 : : } else {
10947 : 0 : r = age_info->hw_age.aged_list;
10948 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
10949 : : }
10950 [ # # ]: 0 : if (nb_contexts == 0)
10951 : 0 : return rte_ring_count(r);
10952 [ # # ]: 0 : while ((uint32_t)nb_flows < nb_contexts) {
10953 : : uint32_t age_idx;
10954 : :
10955 : : if (rte_ring_dequeue_elem(r, &age_idx, sizeof(uint32_t)) < 0)
10956 : : break;
10957 : : /* get the AGE context if the aged-out index is still valid. */
10958 : 0 : contexts[nb_flows] = mlx5_hws_age_context_get(priv, age_idx);
10959 [ # # ]: 0 : if (!contexts[nb_flows])
10960 : 0 : continue;
10961 : 0 : nb_flows++;
10962 : : }
10963 : : return nb_flows;
10964 : : }
10965 : :
10966 : : /**
10967 : : * Get aged-out flows.
10968 : : *
10969 : : * This function is relevant only if RTE_FLOW_PORT_FLAG_STRICT_QUEUE isn't set.
10970 : : *
10971 : : * @param[in] dev
10972 : : * Pointer to the Ethernet device structure.
10973 : : * @param[in] contexts
10974 : : * The address of an array of pointers to the aged-out flows contexts.
10975 : : * @param[in] nb_contexts
10976 : : * The length of context array pointers.
10977 : : * @param[out] error
10978 : : * Perform verbose error reporting if not NULL. Initialized in case of
10979 : : * error only.
10980 : : *
10981 : : * @return
10982 : : * how many contexts get in success, otherwise negative errno value.
10983 : : * if nb_contexts is 0, return the amount of all aged contexts.
10984 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10985 : : * in the context array.
10986 : : */
10987 : : static int
10988 : 0 : flow_hw_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
10989 : : uint32_t nb_contexts, struct rte_flow_error *error)
10990 : : {
10991 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10992 : :
10993 [ # # ]: 0 : if (priv->hws_strict_queue)
10994 : 0 : DRV_LOG(WARNING,
10995 : : "port %u get aged flows called in strict queue mode.",
10996 : : dev->data->port_id);
10997 : 0 : return flow_hw_get_q_aged_flows(dev, 0, contexts, nb_contexts, error);
10998 : : }
10999 : :
11000 : : static void
11001 : 0 : mlx5_mirror_destroy_clone(struct rte_eth_dev *dev,
11002 : : struct mlx5_mirror_clone *clone)
11003 : : {
11004 [ # # # ]: 0 : switch (clone->type) {
11005 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
11006 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
11007 : 0 : mlx5_hrxq_release(dev,
11008 : 0 : ((struct mlx5_hrxq *)(clone->action_ctx))->idx);
11009 : 0 : break;
11010 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
11011 : 0 : flow_hw_jump_release(dev, clone->action_ctx);
11012 : : break;
11013 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11014 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
11015 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11016 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
11017 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11018 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11019 : : default:
11020 : : break;
11021 : : }
11022 : 0 : }
11023 : :
11024 : : void
11025 [ # # ]: 0 : mlx5_hw_mirror_destroy(struct rte_eth_dev *dev, struct mlx5_mirror *mirror)
11026 : : {
11027 : : uint32_t i;
11028 : :
11029 : : mlx5_indirect_list_remove_entry(&mirror->indirect);
11030 [ # # ]: 0 : for (i = 0; i < mirror->clones_num; i++)
11031 : 0 : mlx5_mirror_destroy_clone(dev, &mirror->clone[i]);
11032 [ # # ]: 0 : if (mirror->mirror_action)
11033 : 0 : mlx5dr_action_destroy(mirror->mirror_action);
11034 : 0 : mlx5_free(mirror);
11035 : 0 : }
11036 : :
11037 : : static __rte_always_inline bool
11038 : : mlx5_mirror_terminal_action(const struct rte_flow_action *action)
11039 : : {
11040 : 0 : switch (action->type) {
11041 : : case RTE_FLOW_ACTION_TYPE_JUMP:
11042 : : case RTE_FLOW_ACTION_TYPE_RSS:
11043 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
11044 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11045 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
11046 : : return true;
11047 : : default:
11048 : : break;
11049 : : }
11050 : : return false;
11051 : : }
11052 : :
11053 : : static bool
11054 : 0 : mlx5_mirror_validate_sample_action(struct rte_eth_dev *dev,
11055 : : const struct rte_flow_attr *flow_attr,
11056 : : const struct rte_flow_action *action)
11057 : : {
11058 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11059 : : const struct rte_flow_action_ethdev *port = NULL;
11060 [ # # # # ]: 0 : bool is_proxy = MLX5_HW_PORT_IS_PROXY(priv);
11061 : :
11062 [ # # ]: 0 : if (!action)
11063 : : return false;
11064 [ # # # # ]: 0 : switch (action->type) {
11065 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
11066 : : case RTE_FLOW_ACTION_TYPE_RSS:
11067 [ # # ]: 0 : if (flow_attr->transfer)
11068 : 0 : return false;
11069 : : break;
11070 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
11071 [ # # # # ]: 0 : if (!is_proxy || !flow_attr->transfer)
11072 : : return false;
11073 : 0 : port = action->conf;
11074 [ # # # # ]: 0 : if (!port || port->port_id != MLX5_REPRESENTED_PORT_ESW_MGR)
11075 : 0 : return false;
11076 : : break;
11077 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11078 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11079 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
11080 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11081 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11082 [ # # # # ]: 0 : if (!is_proxy || !flow_attr->transfer)
11083 : : return false;
11084 [ # # ]: 0 : if (action[0].type == RTE_FLOW_ACTION_TYPE_RAW_DECAP &&
11085 [ # # ]: 0 : action[1].type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP)
11086 : 0 : return false;
11087 : : break;
11088 : : default:
11089 : : return false;
11090 : : }
11091 : : return true;
11092 : : }
11093 : :
11094 : : /**
11095 : : * Valid mirror actions list includes one or two SAMPLE actions
11096 : : * followed by JUMP.
11097 : : *
11098 : : * @return
11099 : : * Number of mirrors *action* list was valid.
11100 : : * -EINVAL otherwise.
11101 : : */
11102 : : static int
11103 : 0 : mlx5_hw_mirror_actions_list_validate(struct rte_eth_dev *dev,
11104 : : const struct rte_flow_attr *flow_attr,
11105 : : const struct rte_flow_action *actions)
11106 : : {
11107 [ # # ]: 0 : if (actions[0].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
11108 : : int i = 1;
11109 : : bool valid;
11110 : 0 : const struct rte_flow_action_sample *sample = actions[0].conf;
11111 : 0 : valid = mlx5_mirror_validate_sample_action(dev, flow_attr,
11112 : 0 : sample->actions);
11113 [ # # ]: 0 : if (!valid)
11114 : : return -EINVAL;
11115 [ # # ]: 0 : if (actions[1].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
11116 : : i = 2;
11117 : 0 : sample = actions[1].conf;
11118 : 0 : valid = mlx5_mirror_validate_sample_action(dev, flow_attr,
11119 : 0 : sample->actions);
11120 [ # # ]: 0 : if (!valid)
11121 : : return -EINVAL;
11122 : : }
11123 [ # # ]: 0 : return mlx5_mirror_terminal_action(actions + i) ? i + 1 : -EINVAL;
11124 : : }
11125 : : return -EINVAL;
11126 : : }
11127 : :
11128 : : static int
11129 [ # # ]: 0 : mirror_format_tir(struct rte_eth_dev *dev,
11130 : : struct mlx5_mirror_clone *clone,
11131 : : const struct mlx5_flow_template_table_cfg *table_cfg,
11132 : : const struct rte_flow_action *action,
11133 : : struct mlx5dr_action_dest_attr *dest_attr,
11134 : : struct rte_flow_error *error)
11135 : : {
11136 : : uint32_t hws_flags;
11137 : : enum mlx5dr_table_type table_type;
11138 : : struct mlx5_hrxq *tir_ctx;
11139 : :
11140 : : table_type = get_mlx5dr_table_type(&table_cfg->attr.flow_attr);
11141 : 0 : hws_flags = mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_NONE_ROOT][table_type];
11142 : 0 : tir_ctx = flow_hw_tir_action_register(dev, hws_flags, action);
11143 [ # # ]: 0 : if (!tir_ctx)
11144 : 0 : return rte_flow_error_set(error, EINVAL,
11145 : : RTE_FLOW_ERROR_TYPE_ACTION,
11146 : : action, "failed to create QUEUE action for mirror clone");
11147 : 0 : dest_attr->dest = tir_ctx->action;
11148 : 0 : clone->action_ctx = tir_ctx;
11149 : 0 : return 0;
11150 : : }
11151 : :
11152 : : static int
11153 : 0 : mirror_format_jump(struct rte_eth_dev *dev,
11154 : : struct mlx5_mirror_clone *clone,
11155 : : const struct mlx5_flow_template_table_cfg *table_cfg,
11156 : : const struct rte_flow_action *action,
11157 : : struct mlx5dr_action_dest_attr *dest_attr,
11158 : : struct rte_flow_error *error)
11159 : : {
11160 : 0 : const struct rte_flow_action_jump *jump_conf = action->conf;
11161 : 0 : struct mlx5_hw_jump_action *jump = flow_hw_jump_action_register
11162 : : (dev, table_cfg,
11163 : 0 : jump_conf->group, error);
11164 : :
11165 [ # # ]: 0 : if (!jump)
11166 : 0 : return rte_flow_error_set(error, EINVAL,
11167 : : RTE_FLOW_ERROR_TYPE_ACTION,
11168 : : action, "failed to create JUMP action for mirror clone");
11169 : 0 : dest_attr->dest = jump->hws_action;
11170 : 0 : clone->action_ctx = jump;
11171 : 0 : return 0;
11172 : : }
11173 : :
11174 : : static int
11175 : : mirror_format_port(struct rte_eth_dev *dev,
11176 : : const struct rte_flow_action *action,
11177 : : struct mlx5dr_action_dest_attr *dest_attr,
11178 : : struct rte_flow_error __rte_unused *error)
11179 : : {
11180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11181 : 0 : const struct rte_flow_action_ethdev *port_action = action->conf;
11182 : :
11183 : 0 : dest_attr->dest = priv->hw_vport[port_action->port_id];
11184 : : return 0;
11185 : : }
11186 : :
11187 : : static int
11188 : 0 : hw_mirror_clone_reformat(const struct rte_flow_action *actions,
11189 : : struct mlx5dr_action_dest_attr *dest_attr,
11190 : : enum mlx5dr_action_type *action_type,
11191 : : uint8_t *reformat_buf, bool decap)
11192 : : {
11193 : : int ret;
11194 : : const struct rte_flow_item *encap_item = NULL;
11195 : : const struct rte_flow_action_raw_encap *encap_conf = NULL;
11196 : : typeof(dest_attr->reformat) *reformat = &dest_attr->reformat;
11197 : :
11198 [ # # # # ]: 0 : switch (actions[0].type) {
11199 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11200 : 0 : encap_conf = actions[0].conf;
11201 : 0 : break;
11202 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11203 : 0 : encap_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_vxlan_encap,
11204 : : actions);
11205 : 0 : break;
11206 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11207 : 0 : encap_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_nvgre_encap,
11208 : : actions);
11209 : 0 : break;
11210 : : default:
11211 : : return -EINVAL;
11212 : : }
11213 : 0 : *action_type = decap ?
11214 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3 :
11215 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
11216 [ # # ]: 0 : if (encap_item) {
11217 : 0 : ret = flow_dv_convert_encap_data(encap_item, reformat_buf,
11218 : : &reformat->reformat_data_sz, NULL);
11219 [ # # ]: 0 : if (ret)
11220 : : return -EINVAL;
11221 : 0 : reformat->reformat_data = reformat_buf;
11222 : : } else {
11223 : 0 : reformat->reformat_data = (void *)(uintptr_t)encap_conf->data;
11224 : 0 : reformat->reformat_data_sz = encap_conf->size;
11225 : : }
11226 : : return 0;
11227 : : }
11228 : :
11229 : : static int
11230 : 0 : hw_mirror_format_clone(struct rte_eth_dev *dev,
11231 : : struct mlx5_mirror_clone *clone,
11232 : : const struct mlx5_flow_template_table_cfg *table_cfg,
11233 : : const struct rte_flow_action *actions,
11234 : : struct mlx5dr_action_dest_attr *dest_attr,
11235 : : uint8_t *reformat_buf, struct rte_flow_error *error)
11236 : : {
11237 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11238 : : int ret;
11239 : : uint32_t i;
11240 : : bool decap_seen = false;
11241 : :
11242 [ # # ]: 0 : for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
11243 : 0 : dest_attr->action_type[i] = mlx5_hw_dr_action_types[actions[i].type];
11244 [ # # # # : 0 : switch (actions[i].type) {
# # # ]
11245 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
11246 : : case RTE_FLOW_ACTION_TYPE_RSS:
11247 : 0 : ret = mirror_format_tir(dev, clone, table_cfg,
11248 : : &actions[i], dest_attr, error);
11249 [ # # ]: 0 : if (ret)
11250 : 0 : return ret;
11251 : : break;
11252 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11253 : : ret = mirror_format_port(dev, &actions[i],
11254 : : dest_attr, error);
11255 : : if (ret)
11256 : : return ret;
11257 : : break;
11258 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
11259 : 0 : ret = mirror_format_jump(dev, clone, table_cfg,
11260 : : &actions[i], dest_attr, error);
11261 [ # # ]: 0 : if (ret)
11262 : 0 : return ret;
11263 : : break;
11264 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
11265 : 0 : dest_attr->dest = priv->hw_def_miss;
11266 : 0 : break;
11267 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
11268 : : decap_seen = true;
11269 : : break;
11270 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11271 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11272 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11273 : 0 : ret = hw_mirror_clone_reformat(&actions[i], dest_attr,
11274 : : &dest_attr->action_type[i],
11275 : : reformat_buf, decap_seen);
11276 [ # # ]: 0 : if (ret < 0)
11277 : 0 : return rte_flow_error_set(error, EINVAL,
11278 : : RTE_FLOW_ERROR_TYPE_ACTION,
11279 : : &actions[i],
11280 : : "failed to create reformat action");
11281 : : break;
11282 : 0 : default:
11283 : 0 : return rte_flow_error_set(error, EINVAL,
11284 : : RTE_FLOW_ERROR_TYPE_ACTION,
11285 : : &actions[i], "unsupported sample action");
11286 : : }
11287 : 0 : clone->type = actions->type;
11288 : : }
11289 : 0 : dest_attr->action_type[i] = MLX5DR_ACTION_TYP_LAST;
11290 : 0 : return 0;
11291 : : }
11292 : :
11293 : : static struct rte_flow_action_list_handle *
11294 : 0 : mlx5_hw_mirror_handle_create(struct rte_eth_dev *dev,
11295 : : const struct mlx5_flow_template_table_cfg *table_cfg,
11296 : : const struct rte_flow_action *actions,
11297 : : struct rte_flow_error *error)
11298 : : {
11299 : : uint32_t hws_flags;
11300 : : int ret = 0, i, clones_num;
11301 : : struct mlx5_mirror *mirror;
11302 : : enum mlx5dr_table_type table_type;
11303 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11304 [ # # ]: 0 : const struct rte_flow_attr *flow_attr = &table_cfg->attr.flow_attr;
11305 : : uint8_t reformat_buf[MLX5_MIRROR_MAX_CLONES_NUM][MLX5_ENCAP_MAX_LEN];
11306 : : struct mlx5dr_action_dest_attr mirror_attr[MLX5_MIRROR_MAX_CLONES_NUM + 1];
11307 : : enum mlx5dr_action_type array_action_types[MLX5_MIRROR_MAX_CLONES_NUM + 1]
11308 : : [MLX5_MIRROR_MAX_SAMPLE_ACTIONS_LEN + 1];
11309 : :
11310 : : memset(mirror_attr, 0, sizeof(mirror_attr));
11311 : : memset(array_action_types, 0, sizeof(array_action_types));
11312 : : table_type = get_mlx5dr_table_type(flow_attr);
11313 : 0 : hws_flags = mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_NONE_ROOT][table_type];
11314 : 0 : clones_num = mlx5_hw_mirror_actions_list_validate(dev, flow_attr,
11315 : : actions);
11316 [ # # ]: 0 : if (clones_num < 0) {
11317 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11318 : : actions, "Invalid mirror list format");
11319 : 0 : return NULL;
11320 : : }
11321 : 0 : mirror = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mirror),
11322 : : 0, SOCKET_ID_ANY);
11323 [ # # ]: 0 : if (!mirror) {
11324 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ACTION,
11325 : : actions, "Failed to allocate mirror context");
11326 : 0 : return NULL;
11327 : : }
11328 : :
11329 : 0 : mirror->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR;
11330 : 0 : mirror->clones_num = clones_num;
11331 [ # # ]: 0 : for (i = 0; i < clones_num; i++) {
11332 : : const struct rte_flow_action *clone_actions;
11333 : :
11334 : 0 : mirror_attr[i].action_type = array_action_types[i];
11335 [ # # ]: 0 : if (actions[i].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
11336 : 0 : const struct rte_flow_action_sample *sample = actions[i].conf;
11337 : :
11338 : 0 : clone_actions = sample->actions;
11339 : : } else {
11340 : : clone_actions = &actions[i];
11341 : : }
11342 : 0 : ret = hw_mirror_format_clone(dev, &mirror->clone[i], table_cfg,
11343 : : clone_actions, &mirror_attr[i],
11344 : 0 : reformat_buf[i], error);
11345 : :
11346 [ # # ]: 0 : if (ret)
11347 : 0 : goto error;
11348 : : }
11349 : 0 : hws_flags |= MLX5DR_ACTION_FLAG_SHARED;
11350 : 0 : mirror->mirror_action = mlx5dr_action_create_dest_array(priv->dr_ctx,
11351 : : clones_num,
11352 : : mirror_attr,
11353 : : hws_flags);
11354 [ # # ]: 0 : if (!mirror->mirror_action) {
11355 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11356 : : actions, "Failed to create HWS mirror action");
11357 : 0 : goto error;
11358 : : }
11359 : :
11360 [ # # ]: 0 : mlx5_indirect_list_add_entry(&priv->indirect_list_head, &mirror->indirect);
11361 : 0 : return (struct rte_flow_action_list_handle *)mirror;
11362 : :
11363 : 0 : error:
11364 : 0 : mlx5_hw_mirror_destroy(dev, mirror);
11365 : 0 : return NULL;
11366 : : }
11367 : :
11368 : : void
11369 : 0 : mlx5_destroy_legacy_indirect(__rte_unused struct rte_eth_dev *dev,
11370 : : struct mlx5_indirect_list *ptr)
11371 : : {
11372 : : struct mlx5_indlst_legacy *obj = (typeof(obj))ptr;
11373 : :
11374 : : switch (obj->legacy_type) {
11375 : : case RTE_FLOW_ACTION_TYPE_METER_MARK:
11376 : : break; /* ASO meters were released in mlx5_flow_meter_flush() */
11377 : : default:
11378 : : break;
11379 : : }
11380 : 0 : mlx5_free(obj);
11381 : 0 : }
11382 : :
11383 : : static struct rte_flow_action_list_handle *
11384 : 0 : mlx5_create_legacy_indlst(struct rte_eth_dev *dev, uint32_t queue,
11385 : : const struct rte_flow_op_attr *attr,
11386 : : const struct rte_flow_indir_action_conf *conf,
11387 : : const struct rte_flow_action *actions,
11388 : : void *user_data, struct rte_flow_error *error)
11389 : : {
11390 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11391 : 0 : struct mlx5_indlst_legacy *indlst_obj = mlx5_malloc(MLX5_MEM_ZERO,
11392 : : sizeof(*indlst_obj),
11393 : : 0, SOCKET_ID_ANY);
11394 : :
11395 [ # # ]: 0 : if (!indlst_obj)
11396 : : return NULL;
11397 : 0 : indlst_obj->handle = flow_hw_action_handle_create(dev, queue, attr, conf,
11398 : : actions, user_data,
11399 : : error);
11400 [ # # ]: 0 : if (!indlst_obj->handle) {
11401 : 0 : mlx5_free(indlst_obj);
11402 : 0 : return NULL;
11403 : : }
11404 : 0 : indlst_obj->legacy_type = actions[0].type;
11405 : 0 : indlst_obj->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY;
11406 [ # # ]: 0 : mlx5_indirect_list_add_entry(&priv->indirect_list_head, &indlst_obj->indirect);
11407 : 0 : return (struct rte_flow_action_list_handle *)indlst_obj;
11408 : : }
11409 : :
11410 : : static __rte_always_inline enum mlx5_indirect_list_type
11411 : : flow_hw_inlist_type_get(const struct rte_flow_action *actions)
11412 : : {
11413 [ # # # # ]: 0 : switch (actions[0].type) {
11414 : : case RTE_FLOW_ACTION_TYPE_SAMPLE:
11415 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR;
11416 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
11417 : 0 : return actions[1].type == RTE_FLOW_ACTION_TYPE_END ?
11418 : 0 : MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY :
11419 : : MLX5_INDIRECT_ACTION_LIST_TYPE_ERR;
11420 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
11421 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11422 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT;
11423 : : default:
11424 : : break;
11425 : : }
11426 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_ERR;
11427 : : }
11428 : :
11429 : : static struct rte_flow_action_list_handle*
11430 : 0 : mlx5_hw_decap_encap_handle_create(struct rte_eth_dev *dev,
11431 : : const struct mlx5_flow_template_table_cfg *table_cfg,
11432 : : const struct rte_flow_action *actions,
11433 : : struct rte_flow_error *error)
11434 : : {
11435 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11436 : : const struct rte_flow_attr *flow_attr = &table_cfg->attr.flow_attr;
11437 : : const struct rte_flow_action *encap = NULL;
11438 : : const struct rte_flow_action *decap = NULL;
11439 : 0 : struct rte_flow_indir_action_conf indirect_conf = {
11440 : 0 : .ingress = flow_attr->ingress,
11441 : 0 : .egress = flow_attr->egress,
11442 : 0 : .transfer = flow_attr->transfer,
11443 : : };
11444 : : struct mlx5_hw_encap_decap_action *handle;
11445 : : uint64_t action_flags = 0;
11446 : :
11447 : : /*
11448 : : * Allow
11449 : : * 1. raw_decap / raw_encap / end
11450 : : * 2. raw_encap / end
11451 : : * 3. raw_decap / end
11452 : : */
11453 [ # # ]: 0 : while (actions->type != RTE_FLOW_ACTION_TYPE_END) {
11454 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP) {
11455 [ # # ]: 0 : if (action_flags) {
11456 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11457 : : actions, "Invalid indirect action list sequence");
11458 : 0 : return NULL;
11459 : : }
11460 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
11461 : : decap = actions;
11462 [ # # ]: 0 : } else if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
11463 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP) {
11464 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11465 : : actions, "Invalid indirect action list sequence");
11466 : 0 : return NULL;
11467 : : }
11468 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
11469 : : encap = actions;
11470 : : } else {
11471 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11472 : : actions, "Invalid indirect action type in list");
11473 : 0 : return NULL;
11474 : : }
11475 : 0 : actions++;
11476 : : }
11477 [ # # ]: 0 : if (!decap && !encap) {
11478 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11479 : : actions, "Invalid indirect action combinations");
11480 : 0 : return NULL;
11481 : : }
11482 : 0 : handle = mlx5_reformat_action_create(dev, &indirect_conf, encap, decap, error);
11483 [ # # ]: 0 : if (!handle) {
11484 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11485 : : actions, "Failed to create HWS decap_encap action");
11486 : 0 : return NULL;
11487 : : }
11488 : 0 : handle->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT;
11489 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->indirect_list_head, &handle->indirect, entry);
11490 : 0 : return (struct rte_flow_action_list_handle *)handle;
11491 : : }
11492 : :
11493 : : static struct rte_flow_action_list_handle *
11494 [ # # ]: 0 : flow_hw_async_action_list_handle_create(struct rte_eth_dev *dev, uint32_t queue,
11495 : : const struct rte_flow_op_attr *attr,
11496 : : const struct rte_flow_indir_action_conf *conf,
11497 : : const struct rte_flow_action *actions,
11498 : : void *user_data,
11499 : : struct rte_flow_error *error)
11500 : : {
11501 : : struct mlx5_hw_q_job *job = NULL;
11502 : : bool push = flow_hw_action_push(attr);
11503 : : enum mlx5_indirect_list_type list_type;
11504 : : struct rte_flow_action_list_handle *handle;
11505 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11506 : 0 : const struct mlx5_flow_template_table_cfg table_cfg = {
11507 : : .external = true,
11508 : : .attr = {
11509 : : .flow_attr = {
11510 : 0 : .ingress = conf->ingress,
11511 : 0 : .egress = conf->egress,
11512 : 0 : .transfer = conf->transfer
11513 : : }
11514 : : }
11515 : : };
11516 : :
11517 [ # # ]: 0 : if (!actions) {
11518 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11519 : : NULL, "No action list");
11520 : 0 : return NULL;
11521 : : }
11522 : : list_type = flow_hw_inlist_type_get(actions);
11523 [ # # ]: 0 : if (list_type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
11524 : : /*
11525 : : * Legacy indirect actions already have
11526 : : * async resources management. No need to do it twice.
11527 : : */
11528 : 0 : handle = mlx5_create_legacy_indlst(dev, queue, attr, conf,
11529 : : actions, user_data, error);
11530 : 0 : goto end;
11531 : : }
11532 [ # # ]: 0 : if (attr) {
11533 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
11534 : : NULL, MLX5_HW_Q_JOB_TYPE_CREATE,
11535 : : error);
11536 : : if (!job)
11537 : 0 : return NULL;
11538 : : }
11539 [ # # # ]: 0 : switch (list_type) {
11540 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
11541 : 0 : handle = mlx5_hw_mirror_handle_create(dev, &table_cfg,
11542 : : actions, error);
11543 : 0 : break;
11544 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
11545 : 0 : handle = mlx5_hw_decap_encap_handle_create(dev, &table_cfg,
11546 : : actions, error);
11547 : 0 : break;
11548 : 0 : default:
11549 : : handle = NULL;
11550 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
11551 : : actions, "Invalid list");
11552 : : }
11553 [ # # ]: 0 : if (job) {
11554 : 0 : job->action = handle;
11555 : 0 : job->indirect_type = MLX5_HW_INDIRECT_TYPE_LIST;
11556 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, false,
11557 : : handle != NULL);
11558 : : }
11559 : 0 : end:
11560 : : return handle;
11561 : : }
11562 : :
11563 : : static struct rte_flow_action_list_handle *
11564 : 0 : flow_hw_action_list_handle_create(struct rte_eth_dev *dev,
11565 : : const struct rte_flow_indir_action_conf *conf,
11566 : : const struct rte_flow_action *actions,
11567 : : struct rte_flow_error *error)
11568 : : {
11569 : 0 : return flow_hw_async_action_list_handle_create(dev, MLX5_HW_INV_QUEUE,
11570 : : NULL, conf, actions,
11571 : : NULL, error);
11572 : : }
11573 : :
11574 : : static int
11575 [ # # ]: 0 : flow_hw_async_action_list_handle_destroy
11576 : : (struct rte_eth_dev *dev, uint32_t queue,
11577 : : const struct rte_flow_op_attr *attr,
11578 : : struct rte_flow_action_list_handle *handle,
11579 : : void *user_data, struct rte_flow_error *error)
11580 : : {
11581 : : int ret = 0;
11582 : : struct mlx5_hw_q_job *job = NULL;
11583 : : bool push = flow_hw_action_push(attr);
11584 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
11585 : : enum mlx5_indirect_list_type type =
11586 : : mlx5_get_indirect_list_type((void *)handle);
11587 : :
11588 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
11589 : : struct mlx5_indlst_legacy *legacy = (typeof(legacy))handle;
11590 : :
11591 : 0 : ret = flow_hw_action_handle_destroy(dev, queue, attr,
11592 : : legacy->handle,
11593 : : user_data, error);
11594 : : mlx5_indirect_list_remove_entry(&legacy->indirect);
11595 : 0 : goto end;
11596 : : }
11597 [ # # ]: 0 : if (attr) {
11598 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
11599 : : NULL, MLX5_HW_Q_JOB_TYPE_DESTROY,
11600 : : error);
11601 : : if (!job)
11602 : 0 : return rte_errno;
11603 : : }
11604 [ # # # ]: 0 : switch (type) {
11605 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
11606 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)handle);
11607 : 0 : break;
11608 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
11609 [ # # ]: 0 : LIST_REMOVE(&((struct mlx5_hw_encap_decap_action *)handle)->indirect,
11610 : : entry);
11611 : 0 : mlx5_reformat_action_destroy(dev, handle, error);
11612 : 0 : break;
11613 : 0 : default:
11614 : 0 : ret = rte_flow_error_set(error, EINVAL,
11615 : : RTE_FLOW_ERROR_TYPE_ACTION,
11616 : : NULL, "Invalid indirect list handle");
11617 : : }
11618 [ # # ]: 0 : if (job) {
11619 : : flow_hw_action_finalize(dev, queue, job, push, false, true);
11620 : : }
11621 : 0 : end:
11622 : : return ret;
11623 : : }
11624 : :
11625 : : static int
11626 : 0 : flow_hw_action_list_handle_destroy(struct rte_eth_dev *dev,
11627 : : struct rte_flow_action_list_handle *handle,
11628 : : struct rte_flow_error *error)
11629 : : {
11630 : 0 : return flow_hw_async_action_list_handle_destroy(dev, MLX5_HW_INV_QUEUE,
11631 : : NULL, handle, NULL,
11632 : : error);
11633 : : }
11634 : :
11635 : : static int
11636 [ # # ]: 0 : flow_hw_async_action_list_handle_query_update
11637 : : (struct rte_eth_dev *dev, uint32_t queue_id,
11638 : : const struct rte_flow_op_attr *attr,
11639 : : const struct rte_flow_action_list_handle *handle,
11640 : : const void **update, void **query,
11641 : : enum rte_flow_query_update_mode mode,
11642 : : void *user_data, struct rte_flow_error *error)
11643 : : {
11644 : : enum mlx5_indirect_list_type type =
11645 : : mlx5_get_indirect_list_type((const void *)handle);
11646 : :
11647 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
11648 : : struct mlx5_indlst_legacy *legacy = (void *)(uintptr_t)handle;
11649 : :
11650 [ # # ]: 0 : if (update && query)
11651 : 0 : return flow_hw_async_action_handle_query_update
11652 : : (dev, queue_id, attr, legacy->handle,
11653 : : update, query, mode, user_data, error);
11654 [ # # # # ]: 0 : else if (update && update[0])
11655 : 0 : return flow_hw_action_handle_update(dev, queue_id, attr,
11656 : : legacy->handle, update[0],
11657 : : user_data, error);
11658 [ # # # # ]: 0 : else if (query && query[0])
11659 : 0 : return flow_hw_action_handle_query(dev, queue_id, attr,
11660 : 0 : legacy->handle, query[0],
11661 : : user_data, error);
11662 : : else
11663 : 0 : return rte_flow_error_set(error, EINVAL,
11664 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11665 : : NULL, "invalid legacy handle query_update parameters");
11666 : : }
11667 : : return -ENOTSUP;
11668 : : }
11669 : :
11670 : : static int
11671 : 0 : flow_hw_action_list_handle_query_update(struct rte_eth_dev *dev,
11672 : : const struct rte_flow_action_list_handle *handle,
11673 : : const void **update, void **query,
11674 : : enum rte_flow_query_update_mode mode,
11675 : : struct rte_flow_error *error)
11676 : : {
11677 : 0 : return flow_hw_async_action_list_handle_query_update
11678 : : (dev, MLX5_HW_INV_QUEUE, NULL, handle,
11679 : : update, query, mode, NULL, error);
11680 : : }
11681 : :
11682 : : static int
11683 : 0 : flow_hw_calc_table_hash(struct rte_eth_dev *dev,
11684 : : const struct rte_flow_template_table *table,
11685 : : const struct rte_flow_item pattern[],
11686 : : uint8_t pattern_template_index,
11687 : : uint32_t *hash, struct rte_flow_error *error)
11688 : : {
11689 : : const struct rte_flow_item *items;
11690 : : /* Temp job to allow adding missing items */
11691 : : static struct rte_flow_item tmp_items[MLX5_HW_MAX_ITEMS];
11692 : : static struct mlx5_hw_q_job job = {.items = tmp_items};
11693 : : int res;
11694 : :
11695 : 0 : items = flow_hw_get_rule_items(dev, table, pattern,
11696 : : pattern_template_index,
11697 : : &job);
11698 : 0 : res = mlx5dr_rule_hash_calculate(table->matcher, items,
11699 : : pattern_template_index,
11700 : : MLX5DR_RULE_HASH_CALC_MODE_RAW,
11701 : : hash);
11702 [ # # ]: 0 : if (res)
11703 : 0 : return rte_flow_error_set(error, res,
11704 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11705 : : NULL,
11706 : : "hash could not be calculated");
11707 : : return 0;
11708 : : }
11709 : :
11710 : : static int
11711 : 0 : flow_hw_calc_encap_hash(struct rte_eth_dev *dev,
11712 : : const struct rte_flow_item pattern[],
11713 : : enum rte_flow_encap_hash_field dest_field,
11714 : : uint8_t *hash,
11715 : : struct rte_flow_error *error)
11716 : : {
11717 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11718 : : struct mlx5dr_crc_encap_entropy_hash_fields data;
11719 : 0 : enum mlx5dr_crc_encap_entropy_hash_size res_size =
11720 : : dest_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ?
11721 : 0 : MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16 :
11722 : : MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8;
11723 : : int res;
11724 : :
11725 : : memset(&data, 0, sizeof(struct mlx5dr_crc_encap_entropy_hash_fields));
11726 : :
11727 [ # # ]: 0 : for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
11728 [ # # # # : 0 : switch (pattern->type) {
# # # ]
11729 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
11730 : 0 : data.dst.ipv4_addr =
11731 : 0 : ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.dst_addr;
11732 : 0 : data.src.ipv4_addr =
11733 : 0 : ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.src_addr;
11734 : 0 : break;
11735 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
11736 : : memcpy(data.dst.ipv6_addr,
11737 : 0 : ((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.dst_addr,
11738 : : sizeof(data.dst.ipv6_addr));
11739 : : memcpy(data.src.ipv6_addr,
11740 : : ((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.src_addr,
11741 : : sizeof(data.src.ipv6_addr));
11742 : : break;
11743 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
11744 : 0 : data.next_protocol = IPPROTO_UDP;
11745 : 0 : data.dst_port =
11746 : 0 : ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.dst_port;
11747 : 0 : data.src_port =
11748 : 0 : ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.src_port;
11749 : 0 : break;
11750 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
11751 : 0 : data.next_protocol = IPPROTO_TCP;
11752 : 0 : data.dst_port =
11753 : 0 : ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.dst_port;
11754 : 0 : data.src_port =
11755 : 0 : ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.src_port;
11756 : 0 : break;
11757 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
11758 : 0 : data.next_protocol = IPPROTO_ICMP;
11759 : 0 : break;
11760 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
11761 : 0 : data.next_protocol = IPPROTO_ICMPV6;
11762 : 0 : break;
11763 : : default:
11764 : : break;
11765 : : }
11766 : : }
11767 : 0 : res = mlx5dr_crc_encap_entropy_hash_calc(priv->dr_ctx, &data, hash, res_size);
11768 [ # # ]: 0 : if (res)
11769 : 0 : return rte_flow_error_set(error, res,
11770 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11771 : : NULL, "error while calculating encap hash");
11772 : : return 0;
11773 : : }
11774 : :
11775 : : const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = {
11776 : : .info_get = flow_hw_info_get,
11777 : : .configure = flow_hw_configure,
11778 : : .pattern_validate = flow_hw_pattern_validate,
11779 : : .pattern_template_create = flow_hw_pattern_template_create,
11780 : : .pattern_template_destroy = flow_hw_pattern_template_destroy,
11781 : : .actions_validate = flow_hw_actions_validate,
11782 : : .actions_template_create = flow_hw_actions_template_create,
11783 : : .actions_template_destroy = flow_hw_actions_template_destroy,
11784 : : .template_table_create = flow_hw_template_table_create,
11785 : : .template_table_destroy = flow_hw_table_destroy,
11786 : : .group_set_miss_actions = flow_hw_group_set_miss_actions,
11787 : : .async_flow_create = flow_hw_async_flow_create,
11788 : : .async_flow_create_by_index = flow_hw_async_flow_create_by_index,
11789 : : .async_flow_update = flow_hw_async_flow_update,
11790 : : .async_flow_destroy = flow_hw_async_flow_destroy,
11791 : : .pull = flow_hw_pull,
11792 : : .push = flow_hw_push,
11793 : : .async_action_create = flow_hw_action_handle_create,
11794 : : .async_action_destroy = flow_hw_action_handle_destroy,
11795 : : .async_action_update = flow_hw_action_handle_update,
11796 : : .async_action_query_update = flow_hw_async_action_handle_query_update,
11797 : : .async_action_query = flow_hw_action_handle_query,
11798 : : .action_validate = flow_hw_action_validate,
11799 : : .action_create = flow_hw_action_create,
11800 : : .action_destroy = flow_hw_action_destroy,
11801 : : .action_update = flow_hw_action_update,
11802 : : .action_query = flow_hw_action_query,
11803 : : .action_query_update = flow_hw_action_query_update,
11804 : : .action_list_handle_create = flow_hw_action_list_handle_create,
11805 : : .action_list_handle_destroy = flow_hw_action_list_handle_destroy,
11806 : : .action_list_handle_query_update =
11807 : : flow_hw_action_list_handle_query_update,
11808 : : .async_action_list_handle_create =
11809 : : flow_hw_async_action_list_handle_create,
11810 : : .async_action_list_handle_destroy =
11811 : : flow_hw_async_action_list_handle_destroy,
11812 : : .async_action_list_handle_query_update =
11813 : : flow_hw_async_action_list_handle_query_update,
11814 : : .query = flow_hw_query,
11815 : : .get_aged_flows = flow_hw_get_aged_flows,
11816 : : .get_q_aged_flows = flow_hw_get_q_aged_flows,
11817 : : .item_create = flow_dv_item_create,
11818 : : .item_release = flow_dv_item_release,
11819 : : .flow_calc_table_hash = flow_hw_calc_table_hash,
11820 : : .flow_calc_encap_hash = flow_hw_calc_encap_hash,
11821 : : };
11822 : :
11823 : : /**
11824 : : * Creates a control flow using flow template API on @p proxy_dev device,
11825 : : * on behalf of @p owner_dev device.
11826 : : *
11827 : : * This function uses locks internally to synchronize access to the
11828 : : * flow queue.
11829 : : *
11830 : : * Created flow is stored in private list associated with @p proxy_dev device.
11831 : : *
11832 : : * @param owner_dev
11833 : : * Pointer to Ethernet device on behalf of which flow is created.
11834 : : * @param proxy_dev
11835 : : * Pointer to Ethernet device on which flow is created.
11836 : : * @param table
11837 : : * Pointer to flow table.
11838 : : * @param items
11839 : : * Pointer to flow rule items.
11840 : : * @param item_template_idx
11841 : : * Index of an item template associated with @p table.
11842 : : * @param actions
11843 : : * Pointer to flow rule actions.
11844 : : * @param action_template_idx
11845 : : * Index of an action template associated with @p table.
11846 : : * @param info
11847 : : * Additional info about control flow rule.
11848 : : * @param external
11849 : : * External ctrl flow.
11850 : : *
11851 : : * @return
11852 : : * 0 on success, negative errno value otherwise and rte_errno set.
11853 : : */
11854 : : static __rte_unused int
11855 : 0 : flow_hw_create_ctrl_flow(struct rte_eth_dev *owner_dev,
11856 : : struct rte_eth_dev *proxy_dev,
11857 : : struct rte_flow_template_table *table,
11858 : : struct rte_flow_item items[],
11859 : : uint8_t item_template_idx,
11860 : : struct rte_flow_action actions[],
11861 : : uint8_t action_template_idx,
11862 : : struct mlx5_hw_ctrl_flow_info *info,
11863 : : bool external)
11864 : : {
11865 : 0 : struct mlx5_priv *priv = proxy_dev->data->dev_private;
11866 : 0 : uint32_t queue = CTRL_QUEUE_ID(priv);
11867 : 0 : struct rte_flow_op_attr op_attr = {
11868 : : .postpone = 0,
11869 : : };
11870 : : struct rte_flow *flow = NULL;
11871 : : struct mlx5_hw_ctrl_flow *entry = NULL;
11872 : : int ret;
11873 : :
11874 : 0 : rte_spinlock_lock(&priv->hw_ctrl_lock);
11875 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_SYS, sizeof(*entry),
11876 : : 0, SOCKET_ID_ANY);
11877 [ # # ]: 0 : if (!entry) {
11878 : 0 : DRV_LOG(ERR, "port %u not enough memory to create control flows",
11879 : : proxy_dev->data->port_id);
11880 : 0 : rte_errno = ENOMEM;
11881 : : ret = -rte_errno;
11882 : 0 : goto error;
11883 : : }
11884 : 0 : flow = flow_hw_async_flow_create(proxy_dev, queue, &op_attr, table,
11885 : : items, item_template_idx,
11886 : : actions, action_template_idx,
11887 : : NULL, NULL);
11888 [ # # ]: 0 : if (!flow) {
11889 : 0 : DRV_LOG(ERR, "port %u failed to enqueue create control"
11890 : : " flow operation", proxy_dev->data->port_id);
11891 : 0 : ret = -rte_errno;
11892 : 0 : goto error;
11893 : : }
11894 : 0 : ret = __flow_hw_pull_comp(proxy_dev, queue, NULL);
11895 [ # # ]: 0 : if (ret) {
11896 : 0 : DRV_LOG(ERR, "port %u failed to insert control flow",
11897 : : proxy_dev->data->port_id);
11898 : 0 : rte_errno = EINVAL;
11899 : : ret = -rte_errno;
11900 : 0 : goto error;
11901 : : }
11902 : 0 : entry->owner_dev = owner_dev;
11903 : 0 : entry->flow = flow;
11904 [ # # ]: 0 : if (info)
11905 : 0 : entry->info = *info;
11906 : : else
11907 : 0 : entry->info.type = MLX5_HW_CTRL_FLOW_TYPE_GENERAL;
11908 [ # # ]: 0 : if (external)
11909 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ext_ctrl_flows, entry, next);
11910 : : else
11911 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
11912 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
11913 : 0 : return 0;
11914 : 0 : error:
11915 [ # # ]: 0 : if (entry)
11916 : 0 : mlx5_free(entry);
11917 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
11918 : 0 : return ret;
11919 : : }
11920 : :
11921 : : /**
11922 : : * Destroys a control flow @p flow using flow template API on @p dev device.
11923 : : *
11924 : : * This function uses locks internally to synchronize access to the
11925 : : * flow queue.
11926 : : *
11927 : : * If the @p flow is stored on any private list/pool, then caller must free up
11928 : : * the relevant resources.
11929 : : *
11930 : : * @param dev
11931 : : * Pointer to Ethernet device.
11932 : : * @param flow
11933 : : * Pointer to flow rule.
11934 : : *
11935 : : * @return
11936 : : * 0 on success, non-zero value otherwise.
11937 : : */
11938 : : static int
11939 : 0 : flow_hw_destroy_ctrl_flow(struct rte_eth_dev *dev, struct rte_flow *flow)
11940 : : {
11941 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11942 : 0 : uint32_t queue = CTRL_QUEUE_ID(priv);
11943 : 0 : struct rte_flow_op_attr op_attr = {
11944 : : .postpone = 0,
11945 : : };
11946 : : int ret;
11947 : :
11948 : 0 : rte_spinlock_lock(&priv->hw_ctrl_lock);
11949 : 0 : ret = flow_hw_async_flow_destroy(dev, queue, &op_attr, flow, NULL, NULL);
11950 [ # # ]: 0 : if (ret) {
11951 : 0 : DRV_LOG(ERR, "port %u failed to enqueue destroy control"
11952 : : " flow operation", dev->data->port_id);
11953 : 0 : goto exit;
11954 : : }
11955 : 0 : ret = __flow_hw_pull_comp(dev, queue, NULL);
11956 [ # # ]: 0 : if (ret) {
11957 : 0 : DRV_LOG(ERR, "port %u failed to destroy control flow",
11958 : : dev->data->port_id);
11959 : 0 : rte_errno = EINVAL;
11960 : : ret = -rte_errno;
11961 : 0 : goto exit;
11962 : : }
11963 : 0 : exit:
11964 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
11965 : 0 : return ret;
11966 : : }
11967 : :
11968 : : /**
11969 : : * Destroys control flows created on behalf of @p owner device on @p dev device.
11970 : : *
11971 : : * @param dev
11972 : : * Pointer to Ethernet device on which control flows were created.
11973 : : * @param owner
11974 : : * Pointer to Ethernet device owning control flows.
11975 : : *
11976 : : * @return
11977 : : * 0 on success, otherwise negative error code is returned and
11978 : : * rte_errno is set.
11979 : : */
11980 : : static int
11981 : 0 : flow_hw_flush_ctrl_flows_owned_by(struct rte_eth_dev *dev, struct rte_eth_dev *owner)
11982 : : {
11983 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11984 : : struct mlx5_hw_ctrl_flow *cf;
11985 : : struct mlx5_hw_ctrl_flow *cf_next;
11986 : : int ret;
11987 : :
11988 : 0 : cf = LIST_FIRST(&priv->hw_ctrl_flows);
11989 [ # # ]: 0 : while (cf != NULL) {
11990 : 0 : cf_next = LIST_NEXT(cf, next);
11991 [ # # ]: 0 : if (cf->owner_dev == owner) {
11992 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
11993 [ # # ]: 0 : if (ret) {
11994 : 0 : rte_errno = ret;
11995 : 0 : return -ret;
11996 : : }
11997 [ # # ]: 0 : LIST_REMOVE(cf, next);
11998 : 0 : mlx5_free(cf);
11999 : : }
12000 : : cf = cf_next;
12001 : : }
12002 : : return 0;
12003 : : }
12004 : :
12005 : : /**
12006 : : * Destroys control flows created for @p owner_dev device.
12007 : : *
12008 : : * @param owner_dev
12009 : : * Pointer to Ethernet device owning control flows.
12010 : : *
12011 : : * @return
12012 : : * 0 on success, otherwise negative error code is returned and
12013 : : * rte_errno is set.
12014 : : */
12015 : : int
12016 : 0 : mlx5_flow_hw_flush_ctrl_flows(struct rte_eth_dev *owner_dev)
12017 : : {
12018 : 0 : struct mlx5_priv *owner_priv = owner_dev->data->dev_private;
12019 : : struct rte_eth_dev *proxy_dev;
12020 : 0 : uint16_t owner_port_id = owner_dev->data->port_id;
12021 : 0 : uint16_t proxy_port_id = owner_dev->data->port_id;
12022 : : int ret;
12023 : :
12024 : : /* Flush all flows created by this port for itself. */
12025 : 0 : ret = flow_hw_flush_ctrl_flows_owned_by(owner_dev, owner_dev);
12026 [ # # ]: 0 : if (ret)
12027 : : return ret;
12028 : : /* Flush all flows created for this port on proxy port. */
12029 [ # # ]: 0 : if (owner_priv->sh->config.dv_esw_en) {
12030 : 0 : ret = rte_flow_pick_transfer_proxy(owner_port_id, &proxy_port_id, NULL);
12031 [ # # ]: 0 : if (ret == -ENODEV) {
12032 : 0 : DRV_LOG(DEBUG, "Unable to find transfer proxy port for port %u. It was "
12033 : : "probably closed. Control flows were cleared.",
12034 : : owner_port_id);
12035 : 0 : rte_errno = 0;
12036 : 0 : return 0;
12037 [ # # ]: 0 : } else if (ret) {
12038 : 0 : DRV_LOG(ERR, "Unable to find proxy port for port %u (ret = %d)",
12039 : : owner_port_id, ret);
12040 : 0 : return ret;
12041 : : }
12042 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
12043 : : } else {
12044 : : proxy_dev = owner_dev;
12045 : : }
12046 : 0 : return flow_hw_flush_ctrl_flows_owned_by(proxy_dev, owner_dev);
12047 : : }
12048 : :
12049 : : /**
12050 : : * Destroys all control flows created on @p dev device.
12051 : : *
12052 : : * @param owner_dev
12053 : : * Pointer to Ethernet device.
12054 : : *
12055 : : * @return
12056 : : * 0 on success, otherwise negative error code is returned and
12057 : : * rte_errno is set.
12058 : : */
12059 : : static int
12060 : 0 : flow_hw_flush_all_ctrl_flows(struct rte_eth_dev *dev)
12061 : : {
12062 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12063 : : struct mlx5_hw_ctrl_flow *cf;
12064 : : struct mlx5_hw_ctrl_flow *cf_next;
12065 : : int ret;
12066 : :
12067 : 0 : cf = LIST_FIRST(&priv->hw_ctrl_flows);
12068 [ # # ]: 0 : while (cf != NULL) {
12069 : 0 : cf_next = LIST_NEXT(cf, next);
12070 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
12071 [ # # ]: 0 : if (ret) {
12072 : 0 : rte_errno = ret;
12073 : 0 : return -ret;
12074 : : }
12075 [ # # ]: 0 : LIST_REMOVE(cf, next);
12076 : 0 : mlx5_free(cf);
12077 : : cf = cf_next;
12078 : : }
12079 : 0 : cf = LIST_FIRST(&priv->hw_ext_ctrl_flows);
12080 [ # # ]: 0 : while (cf != NULL) {
12081 : 0 : cf_next = LIST_NEXT(cf, next);
12082 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
12083 [ # # ]: 0 : if (ret) {
12084 : 0 : rte_errno = ret;
12085 : 0 : return -ret;
12086 : : }
12087 [ # # ]: 0 : LIST_REMOVE(cf, next);
12088 : 0 : mlx5_free(cf);
12089 : : cf = cf_next;
12090 : : }
12091 : : return 0;
12092 : : }
12093 : :
12094 : : int
12095 : 0 : mlx5_flow_hw_esw_create_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
12096 : : {
12097 : 0 : uint16_t port_id = dev->data->port_id;
12098 : 0 : struct rte_flow_item_ethdev esw_mgr_spec = {
12099 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
12100 : : };
12101 : 0 : struct rte_flow_item_ethdev esw_mgr_mask = {
12102 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
12103 : : };
12104 : 0 : struct rte_flow_item_tag reg_c0_spec = {
12105 : : .index = (uint8_t)REG_C_0,
12106 : : .data = flow_hw_esw_mgr_regc_marker(dev),
12107 : : };
12108 : 0 : struct rte_flow_item_tag reg_c0_mask = {
12109 : : .index = 0xff,
12110 : : .data = flow_hw_esw_mgr_regc_marker_mask(dev),
12111 : : };
12112 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
12113 : : .queue = sqn,
12114 : : };
12115 : 0 : struct rte_flow_action_ethdev port = {
12116 : : .port_id = port_id,
12117 : : };
12118 : 0 : struct rte_flow_item items[3] = { { 0 } };
12119 : 0 : struct rte_flow_action actions[3] = { { 0 } };
12120 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12121 : : .type = MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS_ROOT,
12122 : : .esw_mgr_sq = sqn,
12123 : : };
12124 : : struct rte_eth_dev *proxy_dev;
12125 : : struct mlx5_priv *proxy_priv;
12126 : 0 : uint16_t proxy_port_id = dev->data->port_id;
12127 : : int ret;
12128 : :
12129 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
12130 [ # # ]: 0 : if (ret) {
12131 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
12132 : : "port must be present to create default SQ miss flows.",
12133 : : port_id);
12134 : 0 : return ret;
12135 : : }
12136 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
12137 : 0 : proxy_priv = proxy_dev->data->dev_private;
12138 [ # # ]: 0 : if (!proxy_priv->dr_ctx) {
12139 : 0 : DRV_LOG(DEBUG, "Transfer proxy port (port %u) of port %u must be configured "
12140 : : "for HWS to create default SQ miss flows. Default flows will "
12141 : : "not be created.",
12142 : : proxy_port_id, port_id);
12143 : 0 : return 0;
12144 : : }
12145 [ # # ]: 0 : if (!proxy_priv->hw_esw_sq_miss_root_tbl ||
12146 [ # # ]: 0 : !proxy_priv->hw_esw_sq_miss_tbl) {
12147 : 0 : DRV_LOG(ERR, "Transfer proxy port (port %u) of port %u was configured, but "
12148 : : "default flow tables were not created.",
12149 : : proxy_port_id, port_id);
12150 : 0 : rte_errno = ENOMEM;
12151 : 0 : return -rte_errno;
12152 : : }
12153 : : /*
12154 : : * Create a root SQ miss flow rule - match E-Switch Manager and SQ,
12155 : : * and jump to group 1.
12156 : : */
12157 : 0 : items[0] = (struct rte_flow_item){
12158 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
12159 : : .spec = &esw_mgr_spec,
12160 : : .mask = &esw_mgr_mask,
12161 : : };
12162 : 0 : items[1] = (struct rte_flow_item){
12163 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
12164 : : .spec = &sq_spec,
12165 : : };
12166 : 0 : items[2] = (struct rte_flow_item){
12167 : : .type = RTE_FLOW_ITEM_TYPE_END,
12168 : : };
12169 : 0 : actions[0] = (struct rte_flow_action){
12170 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
12171 : : };
12172 : 0 : actions[1] = (struct rte_flow_action){
12173 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
12174 : : };
12175 : 0 : actions[2] = (struct rte_flow_action) {
12176 : : .type = RTE_FLOW_ACTION_TYPE_END,
12177 : : };
12178 : 0 : ret = flow_hw_create_ctrl_flow(dev, proxy_dev, proxy_priv->hw_esw_sq_miss_root_tbl,
12179 : : items, 0, actions, 0, &flow_info, external);
12180 [ # # ]: 0 : if (ret) {
12181 : 0 : DRV_LOG(ERR, "Port %u failed to create root SQ miss flow rule for SQ %u, ret %d",
12182 : : port_id, sqn, ret);
12183 : 0 : return ret;
12184 : : }
12185 : : /*
12186 : : * Create a non-root SQ miss flow rule - match REG_C_0 marker and SQ,
12187 : : * and forward to port.
12188 : : */
12189 : 0 : items[0] = (struct rte_flow_item){
12190 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
12191 : : .spec = ®_c0_spec,
12192 : : .mask = ®_c0_mask,
12193 : : };
12194 : 0 : items[1] = (struct rte_flow_item){
12195 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
12196 : : .spec = &sq_spec,
12197 : : };
12198 : 0 : items[2] = (struct rte_flow_item){
12199 : : .type = RTE_FLOW_ITEM_TYPE_END,
12200 : : };
12201 : 0 : actions[0] = (struct rte_flow_action){
12202 : : .type = RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
12203 : : .conf = &port,
12204 : : };
12205 : 0 : actions[1] = (struct rte_flow_action){
12206 : : .type = RTE_FLOW_ACTION_TYPE_END,
12207 : : };
12208 : 0 : flow_info.type = MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS;
12209 : 0 : ret = flow_hw_create_ctrl_flow(dev, proxy_dev, proxy_priv->hw_esw_sq_miss_tbl,
12210 : : items, 0, actions, 0, &flow_info, external);
12211 [ # # ]: 0 : if (ret) {
12212 : 0 : DRV_LOG(ERR, "Port %u failed to create HWS SQ miss flow rule for SQ %u, ret %d",
12213 : : port_id, sqn, ret);
12214 : 0 : return ret;
12215 : : }
12216 : : return 0;
12217 : : }
12218 : :
12219 : : static bool
12220 : : flow_hw_is_matching_sq_miss_flow(struct mlx5_hw_ctrl_flow *cf,
12221 : : struct rte_eth_dev *dev,
12222 : : uint32_t sqn)
12223 : : {
12224 : 0 : if (cf->owner_dev != dev)
12225 : : return false;
12226 [ # # # # ]: 0 : if (cf->info.type == MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS_ROOT && cf->info.esw_mgr_sq == sqn)
12227 : : return true;
12228 [ # # # # ]: 0 : if (cf->info.type == MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS && cf->info.esw_mgr_sq == sqn)
12229 : : return true;
12230 : : return false;
12231 : : }
12232 : :
12233 : : int
12234 : 0 : mlx5_flow_hw_esw_destroy_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sqn)
12235 : : {
12236 : 0 : uint16_t port_id = dev->data->port_id;
12237 : 0 : uint16_t proxy_port_id = dev->data->port_id;
12238 : : struct rte_eth_dev *proxy_dev;
12239 : : struct mlx5_priv *proxy_priv;
12240 : : struct mlx5_hw_ctrl_flow *cf;
12241 : : struct mlx5_hw_ctrl_flow *cf_next;
12242 : : int ret;
12243 : :
12244 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
12245 [ # # ]: 0 : if (ret) {
12246 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
12247 : : "port must be present for default SQ miss flow rules to exist.",
12248 : : port_id);
12249 : 0 : return ret;
12250 : : }
12251 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
12252 : 0 : proxy_priv = proxy_dev->data->dev_private;
12253 [ # # ]: 0 : if (!proxy_priv->dr_ctx)
12254 : : return 0;
12255 [ # # ]: 0 : if (!proxy_priv->hw_esw_sq_miss_root_tbl ||
12256 [ # # ]: 0 : !proxy_priv->hw_esw_sq_miss_tbl)
12257 : : return 0;
12258 : 0 : cf = LIST_FIRST(&proxy_priv->hw_ctrl_flows);
12259 [ # # ]: 0 : while (cf != NULL) {
12260 [ # # ]: 0 : cf_next = LIST_NEXT(cf, next);
12261 : : if (flow_hw_is_matching_sq_miss_flow(cf, dev, sqn)) {
12262 : 0 : claim_zero(flow_hw_destroy_ctrl_flow(proxy_dev, cf->flow));
12263 [ # # ]: 0 : LIST_REMOVE(cf, next);
12264 : 0 : mlx5_free(cf);
12265 : : }
12266 : : cf = cf_next;
12267 : : }
12268 : : return 0;
12269 : : }
12270 : :
12271 : : int
12272 : 0 : mlx5_flow_hw_esw_create_default_jump_flow(struct rte_eth_dev *dev)
12273 : : {
12274 : 0 : uint16_t port_id = dev->data->port_id;
12275 : 0 : struct rte_flow_item_ethdev port_spec = {
12276 : : .port_id = port_id,
12277 : : };
12278 : 0 : struct rte_flow_item items[] = {
12279 : : {
12280 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
12281 : : .spec = &port_spec,
12282 : : },
12283 : : {
12284 : : .type = RTE_FLOW_ITEM_TYPE_END,
12285 : : },
12286 : : };
12287 : 0 : struct rte_flow_action_jump jump = {
12288 : : .group = 1,
12289 : : };
12290 : 0 : struct rte_flow_action actions[] = {
12291 : : {
12292 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
12293 : : .conf = &jump,
12294 : : },
12295 : : {
12296 : : .type = RTE_FLOW_ACTION_TYPE_END,
12297 : : }
12298 : : };
12299 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12300 : : .type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_JUMP,
12301 : : };
12302 : : struct rte_eth_dev *proxy_dev;
12303 : : struct mlx5_priv *proxy_priv;
12304 : 0 : uint16_t proxy_port_id = dev->data->port_id;
12305 : : int ret;
12306 : :
12307 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
12308 [ # # ]: 0 : if (ret) {
12309 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
12310 : : "port must be present to create default FDB jump rule.",
12311 : : port_id);
12312 : 0 : return ret;
12313 : : }
12314 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
12315 : 0 : proxy_priv = proxy_dev->data->dev_private;
12316 [ # # ]: 0 : if (!proxy_priv->dr_ctx) {
12317 : 0 : DRV_LOG(DEBUG, "Transfer proxy port (port %u) of port %u must be configured "
12318 : : "for HWS to create default FDB jump rule. Default rule will "
12319 : : "not be created.",
12320 : : proxy_port_id, port_id);
12321 : 0 : return 0;
12322 : : }
12323 [ # # ]: 0 : if (!proxy_priv->hw_esw_zero_tbl) {
12324 : 0 : DRV_LOG(ERR, "Transfer proxy port (port %u) of port %u was configured, but "
12325 : : "default flow tables were not created.",
12326 : : proxy_port_id, port_id);
12327 : 0 : rte_errno = EINVAL;
12328 : 0 : return -rte_errno;
12329 : : }
12330 : 0 : return flow_hw_create_ctrl_flow(dev, proxy_dev,
12331 : : proxy_priv->hw_esw_zero_tbl,
12332 : : items, 0, actions, 0, &flow_info, false);
12333 : : }
12334 : :
12335 : : int
12336 : 0 : mlx5_flow_hw_create_tx_default_mreg_copy_flow(struct rte_eth_dev *dev)
12337 : : {
12338 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12339 : 0 : struct rte_flow_item_eth promisc = {
12340 : : .hdr.dst_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
12341 : : .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
12342 : : .hdr.ether_type = 0,
12343 : : };
12344 : 0 : struct rte_flow_item eth_all[] = {
12345 : : [0] = {
12346 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
12347 : : .spec = &promisc,
12348 : : .mask = &promisc,
12349 : : },
12350 : : [1] = {
12351 : : .type = RTE_FLOW_ITEM_TYPE_END,
12352 : : },
12353 : : };
12354 : 0 : struct rte_flow_action_modify_field mreg_action = {
12355 : : .operation = RTE_FLOW_MODIFY_SET,
12356 : : .dst = {
12357 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
12358 : : .tag_index = REG_C_1,
12359 : : },
12360 : : .src = {
12361 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
12362 : : .tag_index = REG_A,
12363 : : },
12364 : : .width = 32,
12365 : : };
12366 : 0 : struct rte_flow_action copy_reg_action[] = {
12367 : : [0] = {
12368 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
12369 : : .conf = &mreg_action,
12370 : : },
12371 : : [1] = {
12372 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
12373 : : },
12374 : : [2] = {
12375 : : .type = RTE_FLOW_ACTION_TYPE_END,
12376 : : },
12377 : : };
12378 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12379 : : .type = MLX5_HW_CTRL_FLOW_TYPE_TX_META_COPY,
12380 : : };
12381 : :
12382 : : MLX5_ASSERT(priv->master);
12383 [ # # # # ]: 0 : if (!priv->dr_ctx || !priv->hw_tx_meta_cpy_tbl)
12384 : : return 0;
12385 : 0 : return flow_hw_create_ctrl_flow(dev, dev,
12386 : : priv->hw_tx_meta_cpy_tbl,
12387 : : eth_all, 0, copy_reg_action, 0, &flow_info, false);
12388 : : }
12389 : :
12390 : : int
12391 : 0 : mlx5_flow_hw_tx_repr_matching_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
12392 : : {
12393 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12394 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
12395 : : .queue = sqn,
12396 : : };
12397 : 0 : struct rte_flow_item items[] = {
12398 : : {
12399 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
12400 : : .spec = &sq_spec,
12401 : : },
12402 : : {
12403 : : .type = RTE_FLOW_ITEM_TYPE_END,
12404 : : },
12405 : : };
12406 : : /*
12407 : : * Allocate actions array suitable for all cases - extended metadata enabled or not.
12408 : : * With extended metadata there will be an additional MODIFY_FIELD action before JUMP.
12409 : : */
12410 : 0 : struct rte_flow_action actions[] = {
12411 : : { .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD },
12412 : : { .type = RTE_FLOW_ACTION_TYPE_JUMP },
12413 : : { .type = RTE_FLOW_ACTION_TYPE_END },
12414 : : { .type = RTE_FLOW_ACTION_TYPE_END },
12415 : : };
12416 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12417 : : .type = MLX5_HW_CTRL_FLOW_TYPE_TX_REPR_MATCH,
12418 : : .tx_repr_sq = sqn,
12419 : : };
12420 : :
12421 : : /* It is assumed that caller checked for representor matching. */
12422 : : MLX5_ASSERT(priv->sh->config.repr_matching);
12423 [ # # ]: 0 : if (!priv->dr_ctx) {
12424 : 0 : DRV_LOG(DEBUG, "Port %u must be configured for HWS, before creating "
12425 : : "default egress flow rules. Omitting creation.",
12426 : : dev->data->port_id);
12427 : 0 : return 0;
12428 : : }
12429 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_tbl) {
12430 : 0 : DRV_LOG(ERR, "Port %u is configured for HWS, but table for default "
12431 : : "egress flow rules does not exist.",
12432 : : dev->data->port_id);
12433 : 0 : rte_errno = EINVAL;
12434 : 0 : return -rte_errno;
12435 : : }
12436 : : /*
12437 : : * If extended metadata mode is enabled, then an additional MODIFY_FIELD action must be
12438 : : * placed before terminating JUMP action.
12439 : : */
12440 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
12441 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD;
12442 : 0 : actions[2].type = RTE_FLOW_ACTION_TYPE_JUMP;
12443 : : }
12444 : 0 : return flow_hw_create_ctrl_flow(dev, dev, priv->hw_tx_repr_tagging_tbl,
12445 : : items, 0, actions, 0, &flow_info, external);
12446 : : }
12447 : :
12448 : : int
12449 : 0 : mlx5_flow_hw_lacp_rx_flow(struct rte_eth_dev *dev)
12450 : : {
12451 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12452 : 0 : struct rte_flow_item_eth lacp_item = {
12453 : : .type = RTE_BE16(RTE_ETHER_TYPE_SLOW),
12454 : : };
12455 : 0 : struct rte_flow_item eth_lacp[] = {
12456 : : [0] = {
12457 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
12458 : : .spec = &lacp_item,
12459 : : .mask = &lacp_item,
12460 : : },
12461 : : [1] = {
12462 : : .type = RTE_FLOW_ITEM_TYPE_END,
12463 : : },
12464 : : };
12465 : 0 : struct rte_flow_action miss_action[] = {
12466 : : [0] = {
12467 : : .type = (enum rte_flow_action_type)
12468 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
12469 : : },
12470 : : [1] = {
12471 : : .type = RTE_FLOW_ACTION_TYPE_END,
12472 : : },
12473 : : };
12474 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12475 : : .type = MLX5_HW_CTRL_FLOW_TYPE_LACP_RX,
12476 : : };
12477 : :
12478 : : MLX5_ASSERT(priv->master);
12479 [ # # # # ]: 0 : if (!priv->dr_ctx || !priv->hw_lacp_rx_tbl)
12480 : : return 0;
12481 : 0 : return flow_hw_create_ctrl_flow(dev, dev, priv->hw_lacp_rx_tbl, eth_lacp, 0,
12482 : : miss_action, 0, &flow_info, false);
12483 : : }
12484 : :
12485 : : static uint32_t
12486 : : __calc_pattern_flags(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
12487 : : {
12488 : : switch (eth_pattern_type) {
12489 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
12490 : : return MLX5_CTRL_PROMISCUOUS;
12491 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
12492 : : return MLX5_CTRL_ALL_MULTICAST;
12493 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
12494 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
12495 : : return MLX5_CTRL_BROADCAST;
12496 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
12497 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
12498 : : return MLX5_CTRL_IPV4_MULTICAST;
12499 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
12500 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
12501 : : return MLX5_CTRL_IPV6_MULTICAST;
12502 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
12503 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
12504 : : return MLX5_CTRL_DMAC;
12505 : : default:
12506 : : /* Should not reach here. */
12507 : : MLX5_ASSERT(false);
12508 : : return 0;
12509 : : }
12510 : : }
12511 : :
12512 : : static uint32_t
12513 : : __calc_vlan_flags(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
12514 : : {
12515 [ # # ]: 0 : switch (eth_pattern_type) {
12516 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
12517 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
12518 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
12519 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
12520 : : return MLX5_CTRL_VLAN_FILTER;
12521 : 0 : default:
12522 : 0 : return 0;
12523 : : }
12524 : : }
12525 : :
12526 : : static bool
12527 [ # # ]: 0 : eth_pattern_type_is_requested(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
12528 : : uint32_t flags)
12529 : : {
12530 : : uint32_t pattern_flags = __calc_pattern_flags(eth_pattern_type);
12531 : : uint32_t vlan_flags = __calc_vlan_flags(eth_pattern_type);
12532 : 0 : bool pattern_requested = !!(pattern_flags & flags);
12533 [ # # # # ]: 0 : bool consider_vlan = vlan_flags || (MLX5_CTRL_VLAN_FILTER & flags);
12534 : 0 : bool vlan_requested = !!(vlan_flags & flags);
12535 : :
12536 [ # # ]: 0 : if (consider_vlan)
12537 : 0 : return pattern_requested && vlan_requested;
12538 : : else
12539 : : return pattern_requested;
12540 : : }
12541 : :
12542 : : static bool
12543 : : rss_type_is_requested(struct mlx5_priv *priv,
12544 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
12545 : : {
12546 : 0 : struct rte_flow_actions_template *at = priv->hw_ctrl_rx->rss[rss_type];
12547 : : unsigned int i;
12548 : :
12549 [ # # ]: 0 : for (i = 0; at->actions[i].type != RTE_FLOW_ACTION_TYPE_END; ++i) {
12550 [ # # ]: 0 : if (at->actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
12551 : 0 : const struct rte_flow_action_rss *rss = at->actions[i].conf;
12552 : 0 : uint64_t rss_types = rss->types;
12553 : :
12554 [ # # ]: 0 : if ((rss_types & priv->rss_conf.rss_hf) != rss_types)
12555 : : return false;
12556 : : }
12557 : : }
12558 : : return true;
12559 : : }
12560 : :
12561 : : static const struct rte_flow_item_eth *
12562 : : __get_eth_spec(const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern)
12563 : : {
12564 : 0 : switch (pattern) {
12565 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
12566 : : return &ctrl_rx_eth_promisc_spec;
12567 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
12568 : 0 : return &ctrl_rx_eth_mcast_spec;
12569 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
12570 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
12571 : 0 : return &ctrl_rx_eth_bcast_spec;
12572 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
12573 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
12574 : 0 : return &ctrl_rx_eth_ipv4_mcast_spec;
12575 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
12576 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
12577 : 0 : return &ctrl_rx_eth_ipv6_mcast_spec;
12578 : 0 : default:
12579 : : /* This case should not be reached. */
12580 : : MLX5_ASSERT(false);
12581 : 0 : return NULL;
12582 : : }
12583 : : }
12584 : :
12585 : : static int
12586 [ # # # # : 0 : __flow_hw_ctrl_flows_single(struct rte_eth_dev *dev,
# # ]
12587 : : struct rte_flow_template_table *tbl,
12588 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
12589 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
12590 : : {
12591 : : const struct rte_flow_item_eth *eth_spec = __get_eth_spec(pattern_type);
12592 : : struct rte_flow_item items[5];
12593 : 0 : struct rte_flow_action actions[] = {
12594 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
12595 : : { .type = RTE_FLOW_ACTION_TYPE_END },
12596 : : };
12597 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12598 : : .type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
12599 : : };
12600 : :
12601 [ # # ]: 0 : if (!eth_spec)
12602 : : return -EINVAL;
12603 : : memset(items, 0, sizeof(items));
12604 : 0 : items[0] = (struct rte_flow_item){
12605 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
12606 : : .spec = eth_spec,
12607 : : };
12608 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VOID };
12609 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
12610 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
12611 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
12612 : : /* Without VLAN filtering, only a single flow rule must be created. */
12613 : 0 : return flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0, &flow_info, false);
12614 : : }
12615 : :
12616 : : static int
12617 : 0 : __flow_hw_ctrl_flows_single_vlan(struct rte_eth_dev *dev,
12618 : : struct rte_flow_template_table *tbl,
12619 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
12620 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
12621 : : {
12622 [ # # # # : 0 : struct mlx5_priv *priv = dev->data->dev_private;
# # ]
12623 : : const struct rte_flow_item_eth *eth_spec = __get_eth_spec(pattern_type);
12624 : : struct rte_flow_item items[5];
12625 : 0 : struct rte_flow_action actions[] = {
12626 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
12627 : : { .type = RTE_FLOW_ACTION_TYPE_END },
12628 : : };
12629 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12630 : : .type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
12631 : : };
12632 : : unsigned int i;
12633 : :
12634 [ # # ]: 0 : if (!eth_spec)
12635 : : return -EINVAL;
12636 : : memset(items, 0, sizeof(items));
12637 : 0 : items[0] = (struct rte_flow_item){
12638 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
12639 : : .spec = eth_spec,
12640 : : };
12641 : : /* Optional VLAN for now will be VOID - will be filled later. */
12642 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VLAN };
12643 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
12644 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
12645 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
12646 : : /* Since VLAN filtering is done, create a single flow rule for each registered vid. */
12647 [ # # ]: 0 : for (i = 0; i < priv->vlan_filter_n; ++i) {
12648 : 0 : uint16_t vlan = priv->vlan_filter[i];
12649 : 0 : struct rte_flow_item_vlan vlan_spec = {
12650 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
12651 : : };
12652 : :
12653 : 0 : items[1].spec = &vlan_spec;
12654 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev,
12655 : : tbl, items, 0, actions, 0, &flow_info, false))
12656 : 0 : return -rte_errno;
12657 : : }
12658 : : return 0;
12659 : : }
12660 : :
12661 : : static int
12662 : 0 : __flow_hw_ctrl_flows_unicast(struct rte_eth_dev *dev,
12663 : : struct rte_flow_template_table *tbl,
12664 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
12665 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
12666 : : {
12667 : : struct rte_flow_item_eth eth_spec;
12668 : : struct rte_flow_item items[5];
12669 : 0 : struct rte_flow_action actions[] = {
12670 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
12671 : : { .type = RTE_FLOW_ACTION_TYPE_END },
12672 : : };
12673 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12674 : : .type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
12675 : : };
12676 [ # # # ]: 0 : const struct rte_ether_addr cmp = {
12677 : : .addr_bytes = "\x00\x00\x00\x00\x00\x00",
12678 : : };
12679 : : unsigned int i;
12680 : :
12681 : : RTE_SET_USED(pattern_type);
12682 : :
12683 : : memset(ð_spec, 0, sizeof(eth_spec));
12684 : : memset(items, 0, sizeof(items));
12685 : 0 : items[0] = (struct rte_flow_item){
12686 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
12687 : : .spec = ð_spec,
12688 : : };
12689 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VOID };
12690 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
12691 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
12692 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
12693 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_MAC_ADDRESSES; ++i) {
12694 : 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
12695 : :
12696 [ # # ]: 0 : if (!memcmp(mac, &cmp, sizeof(*mac)))
12697 : 0 : continue;
12698 : : memcpy(ð_spec.hdr.dst_addr.addr_bytes, mac->addr_bytes, RTE_ETHER_ADDR_LEN);
12699 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev,
12700 : : tbl, items, 0, actions, 0, &flow_info, false))
12701 : 0 : return -rte_errno;
12702 : : }
12703 : : return 0;
12704 : : }
12705 : :
12706 : : static int
12707 : 0 : __flow_hw_ctrl_flows_unicast_vlan(struct rte_eth_dev *dev,
12708 : : struct rte_flow_template_table *tbl,
12709 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
12710 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
12711 : : {
12712 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12713 : : struct rte_flow_item_eth eth_spec;
12714 : : struct rte_flow_item items[5];
12715 : 0 : struct rte_flow_action actions[] = {
12716 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
12717 : : { .type = RTE_FLOW_ACTION_TYPE_END },
12718 : : };
12719 : 0 : struct mlx5_hw_ctrl_flow_info flow_info = {
12720 : : .type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
12721 : : };
12722 [ # # # ]: 0 : const struct rte_ether_addr cmp = {
12723 : : .addr_bytes = "\x00\x00\x00\x00\x00\x00",
12724 : : };
12725 : : unsigned int i;
12726 : : unsigned int j;
12727 : :
12728 : : RTE_SET_USED(pattern_type);
12729 : :
12730 : : memset(ð_spec, 0, sizeof(eth_spec));
12731 : : memset(items, 0, sizeof(items));
12732 : 0 : items[0] = (struct rte_flow_item){
12733 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
12734 : : .spec = ð_spec,
12735 : : };
12736 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VLAN };
12737 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
12738 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
12739 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
12740 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_MAC_ADDRESSES; ++i) {
12741 : 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
12742 : :
12743 [ # # ]: 0 : if (!memcmp(mac, &cmp, sizeof(*mac)))
12744 : 0 : continue;
12745 : : memcpy(ð_spec.hdr.dst_addr.addr_bytes, mac->addr_bytes, RTE_ETHER_ADDR_LEN);
12746 [ # # ]: 0 : for (j = 0; j < priv->vlan_filter_n; ++j) {
12747 : 0 : uint16_t vlan = priv->vlan_filter[j];
12748 : 0 : struct rte_flow_item_vlan vlan_spec = {
12749 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
12750 : : };
12751 : :
12752 : 0 : items[1].spec = &vlan_spec;
12753 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0,
12754 : : &flow_info, false))
12755 : 0 : return -rte_errno;
12756 : : }
12757 : : }
12758 : : return 0;
12759 : : }
12760 : :
12761 : : static int
12762 : 0 : __flow_hw_ctrl_flows(struct rte_eth_dev *dev,
12763 : : struct rte_flow_template_table *tbl,
12764 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
12765 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
12766 : : {
12767 [ # # # # : 0 : switch (pattern_type) {
# ]
12768 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
12769 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
12770 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
12771 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
12772 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
12773 : 0 : return __flow_hw_ctrl_flows_single(dev, tbl, pattern_type, rss_type);
12774 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
12775 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
12776 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
12777 : 0 : return __flow_hw_ctrl_flows_single_vlan(dev, tbl, pattern_type, rss_type);
12778 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
12779 : 0 : return __flow_hw_ctrl_flows_unicast(dev, tbl, pattern_type, rss_type);
12780 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
12781 : 0 : return __flow_hw_ctrl_flows_unicast_vlan(dev, tbl, pattern_type, rss_type);
12782 : 0 : default:
12783 : : /* Should not reach here. */
12784 : : MLX5_ASSERT(false);
12785 : 0 : rte_errno = EINVAL;
12786 : 0 : return -EINVAL;
12787 : : }
12788 : : }
12789 : :
12790 : :
12791 : : int
12792 : 0 : mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags)
12793 : : {
12794 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12795 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
12796 : : unsigned int i;
12797 : : unsigned int j;
12798 : : int ret = 0;
12799 : :
12800 : : RTE_SET_USED(priv);
12801 : : RTE_SET_USED(flags);
12802 [ # # ]: 0 : if (!priv->dr_ctx) {
12803 : 0 : DRV_LOG(DEBUG, "port %u Control flow rules will not be created. "
12804 : : "HWS needs to be configured beforehand.",
12805 : : dev->data->port_id);
12806 : 0 : return 0;
12807 : : }
12808 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
12809 : 0 : DRV_LOG(ERR, "port %u Control flow rules templates were not created.",
12810 : : dev->data->port_id);
12811 : 0 : rte_errno = EINVAL;
12812 : 0 : return -rte_errno;
12813 : : }
12814 : : hw_ctrl_rx = priv->hw_ctrl_rx;
12815 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
12816 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type = i;
12817 : :
12818 [ # # ]: 0 : if (!eth_pattern_type_is_requested(eth_pattern_type, flags))
12819 : 0 : continue;
12820 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
12821 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
12822 : : struct rte_flow_actions_template *at;
12823 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[i][j];
12824 : 0 : const struct mlx5_flow_template_table_cfg cfg = {
12825 : : .attr = tmpls->attr,
12826 : : .external = 0,
12827 : : };
12828 : :
12829 [ # # ]: 0 : if (!hw_ctrl_rx->rss[rss_type]) {
12830 : 0 : at = flow_hw_create_ctrl_rx_rss_template(dev, rss_type);
12831 [ # # ]: 0 : if (!at)
12832 : 0 : return -rte_errno;
12833 : 0 : hw_ctrl_rx->rss[rss_type] = at;
12834 : : } else {
12835 : 0 : at = hw_ctrl_rx->rss[rss_type];
12836 : : }
12837 [ # # ]: 0 : if (!rss_type_is_requested(priv, rss_type))
12838 : 0 : continue;
12839 [ # # ]: 0 : if (!tmpls->tbl) {
12840 : 0 : tmpls->tbl = flow_hw_table_create(dev, &cfg,
12841 : : &tmpls->pt, 1, &at, 1, NULL);
12842 [ # # ]: 0 : if (!tmpls->tbl) {
12843 : 0 : DRV_LOG(ERR, "port %u Failed to create template table "
12844 : : "for control flow rules. Unable to create "
12845 : : "control flow rules.",
12846 : : dev->data->port_id);
12847 : 0 : return -rte_errno;
12848 : : }
12849 : : }
12850 : :
12851 : 0 : ret = __flow_hw_ctrl_flows(dev, tmpls->tbl, eth_pattern_type, rss_type);
12852 [ # # ]: 0 : if (ret) {
12853 : 0 : DRV_LOG(ERR, "port %u Failed to create control flow rule.",
12854 : : dev->data->port_id);
12855 : 0 : return ret;
12856 : : }
12857 : : }
12858 : : }
12859 : : return 0;
12860 : : }
12861 : :
12862 : : void
12863 : 0 : mlx5_flow_meter_uninit(struct rte_eth_dev *dev)
12864 : : {
12865 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12866 : :
12867 [ # # ]: 0 : if (priv->mtr_policy_arr) {
12868 : 0 : mlx5_free(priv->mtr_policy_arr);
12869 : 0 : priv->mtr_policy_arr = NULL;
12870 : : }
12871 [ # # ]: 0 : if (priv->mtr_profile_arr) {
12872 : 0 : mlx5_free(priv->mtr_profile_arr);
12873 : 0 : priv->mtr_profile_arr = NULL;
12874 : : }
12875 [ # # ]: 0 : if (priv->hws_mpool) {
12876 : 0 : mlx5_aso_mtr_queue_uninit(priv->sh, priv->hws_mpool, NULL);
12877 : 0 : mlx5_ipool_destroy(priv->hws_mpool->idx_pool);
12878 : 0 : mlx5_free(priv->hws_mpool);
12879 : 0 : priv->hws_mpool = NULL;
12880 : : }
12881 [ # # ]: 0 : if (priv->mtr_bulk.aso) {
12882 : 0 : mlx5_free(priv->mtr_bulk.aso);
12883 : 0 : priv->mtr_bulk.aso = NULL;
12884 : 0 : priv->mtr_bulk.size = 0;
12885 : 0 : mlx5_aso_queue_uninit(priv->sh, ASO_OPC_MOD_POLICER);
12886 : : }
12887 [ # # ]: 0 : if (priv->mtr_bulk.action) {
12888 : 0 : mlx5dr_action_destroy(priv->mtr_bulk.action);
12889 : 0 : priv->mtr_bulk.action = NULL;
12890 : : }
12891 [ # # ]: 0 : if (priv->mtr_bulk.devx_obj) {
12892 : 0 : claim_zero(mlx5_devx_cmd_destroy(priv->mtr_bulk.devx_obj));
12893 : 0 : priv->mtr_bulk.devx_obj = NULL;
12894 : : }
12895 : 0 : }
12896 : :
12897 : : int
12898 : 0 : mlx5_flow_meter_init(struct rte_eth_dev *dev,
12899 : : uint32_t nb_meters,
12900 : : uint32_t nb_meter_profiles,
12901 : : uint32_t nb_meter_policies,
12902 : : uint32_t nb_queues)
12903 : : {
12904 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
12905 : : struct mlx5_devx_obj *dcs = NULL;
12906 : : uint32_t log_obj_size;
12907 : : int ret = 0;
12908 : : int reg_id;
12909 : : struct mlx5_aso_mtr *aso;
12910 : : uint32_t i;
12911 : : struct rte_flow_error error;
12912 : : uint32_t flags;
12913 : : uint32_t nb_mtrs = rte_align32pow2(nb_meters);
12914 : 0 : struct mlx5_indexed_pool_config cfg = {
12915 : : .size = sizeof(struct mlx5_aso_mtr),
12916 : : .trunk_size = 1 << 12,
12917 : : .per_core_cache = 1 << 13,
12918 : : .need_lock = 1,
12919 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
12920 : : .malloc = mlx5_malloc,
12921 : : .max_idx = nb_meters,
12922 : : .free = mlx5_free,
12923 : : .type = "mlx5_hw_mtr_mark_action",
12924 : : };
12925 : :
12926 [ # # ]: 0 : if (!nb_meters) {
12927 : : ret = ENOTSUP;
12928 : 0 : rte_flow_error_set(&error, ENOMEM,
12929 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12930 : : NULL, "Meter configuration is invalid.");
12931 : 0 : goto err;
12932 : : }
12933 [ # # # # ]: 0 : if (!priv->mtr_en || !priv->sh->meter_aso_en) {
12934 : : ret = ENOTSUP;
12935 : 0 : rte_flow_error_set(&error, ENOMEM,
12936 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12937 : : NULL, "Meter ASO is not supported.");
12938 : 0 : goto err;
12939 : : }
12940 : 0 : priv->mtr_config.nb_meters = nb_meters;
12941 [ # # ]: 0 : log_obj_size = rte_log2_u32(nb_meters >> 1);
12942 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj
12943 : 0 : (priv->sh->cdev->ctx, priv->sh->cdev->pdn,
12944 : : log_obj_size);
12945 [ # # ]: 0 : if (!dcs) {
12946 : : ret = ENOMEM;
12947 : 0 : rte_flow_error_set(&error, ENOMEM,
12948 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12949 : : NULL, "Meter ASO object allocation failed.");
12950 : 0 : goto err;
12951 : : }
12952 : 0 : priv->mtr_bulk.devx_obj = dcs;
12953 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
12954 [ # # ]: 0 : if (reg_id < 0) {
12955 : : ret = ENOTSUP;
12956 : 0 : rte_flow_error_set(&error, ENOMEM,
12957 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12958 : : NULL, "Meter register is not available.");
12959 : 0 : goto err;
12960 : : }
12961 : : flags = MLX5DR_ACTION_FLAG_HWS_RX | MLX5DR_ACTION_FLAG_HWS_TX;
12962 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en && priv->master)
12963 : : flags |= MLX5DR_ACTION_FLAG_HWS_FDB;
12964 : 0 : priv->mtr_bulk.action = mlx5dr_action_create_aso_meter
12965 : : (priv->dr_ctx, (struct mlx5dr_devx_obj *)dcs,
12966 : 0 : reg_id - REG_C_0, flags);
12967 [ # # ]: 0 : if (!priv->mtr_bulk.action) {
12968 : : ret = ENOMEM;
12969 : 0 : rte_flow_error_set(&error, ENOMEM,
12970 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12971 : : NULL, "Meter action creation failed.");
12972 : 0 : goto err;
12973 : : }
12974 : 0 : priv->mtr_bulk.aso = mlx5_malloc(MLX5_MEM_ZERO,
12975 : : sizeof(struct mlx5_aso_mtr) *
12976 : : nb_meters,
12977 : : RTE_CACHE_LINE_SIZE,
12978 : : SOCKET_ID_ANY);
12979 [ # # ]: 0 : if (!priv->mtr_bulk.aso) {
12980 : : ret = ENOMEM;
12981 : 0 : rte_flow_error_set(&error, ENOMEM,
12982 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12983 : : NULL, "Meter bulk ASO allocation failed.");
12984 : 0 : goto err;
12985 : : }
12986 : 0 : priv->mtr_bulk.size = nb_meters;
12987 : : aso = priv->mtr_bulk.aso;
12988 [ # # ]: 0 : for (i = 0; i < priv->mtr_bulk.size; i++) {
12989 : 0 : aso->type = ASO_METER_DIRECT;
12990 : 0 : aso->state = ASO_METER_WAIT;
12991 : 0 : aso->offset = i;
12992 : 0 : aso++;
12993 : : }
12994 : 0 : priv->hws_mpool = mlx5_malloc(MLX5_MEM_ZERO,
12995 : : sizeof(struct mlx5_aso_mtr_pool),
12996 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
12997 [ # # ]: 0 : if (!priv->hws_mpool) {
12998 : : ret = ENOMEM;
12999 : 0 : rte_flow_error_set(&error, ENOMEM,
13000 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13001 : : NULL, "Meter ipool allocation failed.");
13002 : 0 : goto err;
13003 : : }
13004 : 0 : priv->hws_mpool->devx_obj = priv->mtr_bulk.devx_obj;
13005 : 0 : priv->hws_mpool->action = priv->mtr_bulk.action;
13006 : 0 : priv->hws_mpool->nb_sq = nb_queues;
13007 [ # # ]: 0 : if (mlx5_aso_mtr_queue_init(priv->sh, priv->hws_mpool,
13008 : 0 : &priv->sh->mtrmng->pools_mng, nb_queues)) {
13009 : : ret = ENOMEM;
13010 : 0 : rte_flow_error_set(&error, ENOMEM,
13011 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13012 : : NULL, "Meter ASO queue allocation failed.");
13013 : 0 : goto err;
13014 : : }
13015 : : /*
13016 : : * No need for local cache if Meter number is a small number.
13017 : : * Since flow insertion rate will be very limited in that case.
13018 : : * Here let's set the number to less than default trunk size 4K.
13019 : : */
13020 [ # # ]: 0 : if (nb_mtrs <= cfg.trunk_size) {
13021 : 0 : cfg.per_core_cache = 0;
13022 : 0 : cfg.trunk_size = nb_mtrs;
13023 [ # # ]: 0 : } else if (nb_mtrs <= MLX5_HW_IPOOL_SIZE_THRESHOLD) {
13024 : 0 : cfg.per_core_cache = MLX5_HW_IPOOL_CACHE_MIN;
13025 : : }
13026 : 0 : priv->hws_mpool->idx_pool = mlx5_ipool_create(&cfg);
13027 [ # # ]: 0 : if (nb_meter_profiles) {
13028 : 0 : priv->mtr_config.nb_meter_profiles = nb_meter_profiles;
13029 : 0 : priv->mtr_profile_arr =
13030 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
13031 : : sizeof(struct mlx5_flow_meter_profile) *
13032 : : nb_meter_profiles,
13033 : : RTE_CACHE_LINE_SIZE,
13034 : : SOCKET_ID_ANY);
13035 [ # # ]: 0 : if (!priv->mtr_profile_arr) {
13036 : : ret = ENOMEM;
13037 : 0 : rte_flow_error_set(&error, ENOMEM,
13038 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13039 : : NULL, "Meter profile allocation failed.");
13040 : 0 : goto err;
13041 : : }
13042 : : }
13043 [ # # ]: 0 : if (nb_meter_policies) {
13044 : 0 : priv->mtr_config.nb_meter_policies = nb_meter_policies;
13045 : 0 : priv->mtr_policy_arr =
13046 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
13047 : : sizeof(struct mlx5_flow_meter_policy) *
13048 : : nb_meter_policies,
13049 : : RTE_CACHE_LINE_SIZE,
13050 : : SOCKET_ID_ANY);
13051 [ # # ]: 0 : if (!priv->mtr_policy_arr) {
13052 : : ret = ENOMEM;
13053 : 0 : rte_flow_error_set(&error, ENOMEM,
13054 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13055 : : NULL, "Meter policy allocation failed.");
13056 : 0 : goto err;
13057 : : }
13058 : : }
13059 : : return 0;
13060 : 0 : err:
13061 : 0 : mlx5_flow_meter_uninit(dev);
13062 : 0 : return ret;
13063 : : }
13064 : :
13065 : : static __rte_always_inline uint32_t
13066 : : mlx5_reformat_domain_to_tbl_type(const struct rte_flow_indir_action_conf *domain)
13067 : : {
13068 : : uint32_t tbl_type;
13069 : :
13070 : 0 : if (domain->transfer)
13071 : : tbl_type = MLX5DR_ACTION_FLAG_HWS_FDB;
13072 [ # # ]: 0 : else if (domain->egress)
13073 : : tbl_type = MLX5DR_ACTION_FLAG_HWS_TX;
13074 [ # # ]: 0 : else if (domain->ingress)
13075 : : tbl_type = MLX5DR_ACTION_FLAG_HWS_RX;
13076 : : else
13077 : : tbl_type = UINT32_MAX;
13078 : : return tbl_type;
13079 : : }
13080 : :
13081 : : static struct mlx5_hw_encap_decap_action *
13082 : 0 : __mlx5_reformat_create(struct rte_eth_dev *dev,
13083 : : const struct rte_flow_action_raw_encap *encap_conf,
13084 : : const struct rte_flow_indir_action_conf *domain,
13085 : : enum mlx5dr_action_type type)
13086 : : {
13087 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13088 : : struct mlx5_hw_encap_decap_action *handle;
13089 : : struct mlx5dr_action_reformat_header hdr;
13090 : : uint32_t flags;
13091 : :
13092 : : flags = mlx5_reformat_domain_to_tbl_type(domain);
13093 : 0 : flags |= (uint32_t)MLX5DR_ACTION_FLAG_SHARED;
13094 [ # # ]: 0 : if (flags == UINT32_MAX) {
13095 : 0 : DRV_LOG(ERR, "Reformat: invalid indirect action configuration");
13096 : 0 : return NULL;
13097 : : }
13098 : : /* Allocate new list entry. */
13099 : 0 : handle = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*handle), 0, SOCKET_ID_ANY);
13100 [ # # ]: 0 : if (!handle) {
13101 : 0 : DRV_LOG(ERR, "Reformat: failed to allocate reformat entry");
13102 : 0 : return NULL;
13103 : : }
13104 : 0 : handle->action_type = type;
13105 [ # # ]: 0 : hdr.sz = encap_conf ? encap_conf->size : 0;
13106 [ # # ]: 0 : hdr.data = encap_conf ? encap_conf->data : NULL;
13107 : 0 : handle->action = mlx5dr_action_create_reformat(priv->dr_ctx,
13108 : : type, 1, &hdr, 0, flags);
13109 [ # # ]: 0 : if (!handle->action) {
13110 : 0 : DRV_LOG(ERR, "Reformat: failed to create reformat action");
13111 : 0 : mlx5_free(handle);
13112 : 0 : return NULL;
13113 : : }
13114 : : return handle;
13115 : : }
13116 : :
13117 : : /**
13118 : : * Create mlx5 reformat action.
13119 : : *
13120 : : * @param[in] dev
13121 : : * Pointer to rte_eth_dev structure.
13122 : : * @param[in] conf
13123 : : * Pointer to the indirect action parameters.
13124 : : * @param[in] encap_action
13125 : : * Pointer to the raw_encap action configuration.
13126 : : * @param[in] decap_action
13127 : : * Pointer to the raw_decap action configuration.
13128 : : * @param[out] error
13129 : : * Pointer to error structure.
13130 : : *
13131 : : * @return
13132 : : * A valid shared action handle in case of success, NULL otherwise and
13133 : : * rte_errno is set.
13134 : : */
13135 : : struct mlx5_hw_encap_decap_action*
13136 : 0 : mlx5_reformat_action_create(struct rte_eth_dev *dev,
13137 : : const struct rte_flow_indir_action_conf *conf,
13138 : : const struct rte_flow_action *encap_action,
13139 : : const struct rte_flow_action *decap_action,
13140 : : struct rte_flow_error *error)
13141 : : {
13142 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13143 : : struct mlx5_hw_encap_decap_action *handle;
13144 : : const struct rte_flow_action_raw_encap *encap = NULL;
13145 : : const struct rte_flow_action_raw_decap *decap = NULL;
13146 : : enum mlx5dr_action_type type = MLX5DR_ACTION_TYP_LAST;
13147 : :
13148 : : MLX5_ASSERT(!encap_action || encap_action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP);
13149 : : MLX5_ASSERT(!decap_action || decap_action->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP);
13150 [ # # ]: 0 : if (priv->sh->config.dv_flow_en != 2) {
13151 : 0 : rte_flow_error_set(error, ENOTSUP,
13152 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13153 : : "Reformat: hardware does not support");
13154 : 0 : return NULL;
13155 : : }
13156 [ # # # # ]: 0 : if (!conf || (conf->transfer + conf->egress + conf->ingress != 1)) {
13157 : 0 : rte_flow_error_set(error, EINVAL,
13158 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13159 : : "Reformat: domain should be specified");
13160 : 0 : return NULL;
13161 : : }
13162 [ # # # # : 0 : if ((encap_action && !encap_action->conf) || (decap_action && !decap_action->conf)) {
# # # # ]
13163 : 0 : rte_flow_error_set(error, EINVAL,
13164 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13165 : : "Reformat: missed action configuration");
13166 : 0 : return NULL;
13167 : : }
13168 [ # # ]: 0 : if (encap_action && !decap_action) {
13169 : 0 : encap = (const struct rte_flow_action_raw_encap *)encap_action->conf;
13170 [ # # ]: 0 : if (!encap->size || encap->size > MLX5_ENCAP_MAX_LEN ||
13171 : : encap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
13172 : 0 : rte_flow_error_set(error, EINVAL,
13173 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13174 : : "Reformat: Invalid encap length");
13175 : 0 : return NULL;
13176 : : }
13177 : : type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
13178 [ # # ]: 0 : } else if (decap_action && !encap_action) {
13179 : 0 : decap = (const struct rte_flow_action_raw_decap *)decap_action->conf;
13180 [ # # ]: 0 : if (!decap->size || decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
13181 : 0 : rte_flow_error_set(error, EINVAL,
13182 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13183 : : "Reformat: Invalid decap length");
13184 : 0 : return NULL;
13185 : : }
13186 : : type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
13187 [ # # ]: 0 : } else if (encap_action && decap_action) {
13188 : 0 : decap = (const struct rte_flow_action_raw_decap *)decap_action->conf;
13189 : 0 : encap = (const struct rte_flow_action_raw_encap *)encap_action->conf;
13190 [ # # ]: 0 : if (decap->size < MLX5_ENCAPSULATION_DECISION_SIZE &&
13191 [ # # # # ]: 0 : encap->size >= MLX5_ENCAPSULATION_DECISION_SIZE &&
13192 : : encap->size <= MLX5_ENCAP_MAX_LEN) {
13193 : : type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
13194 [ # # ]: 0 : } else if (decap->size >= MLX5_ENCAPSULATION_DECISION_SIZE &&
13195 [ # # ]: 0 : encap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
13196 : : type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2;
13197 : : } else {
13198 : 0 : rte_flow_error_set(error, EINVAL,
13199 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13200 : : "Reformat: Invalid decap & encap length");
13201 : 0 : return NULL;
13202 : : }
13203 [ # # ]: 0 : } else if (!encap_action && !decap_action) {
13204 : 0 : rte_flow_error_set(error, EINVAL,
13205 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13206 : : "Reformat: Invalid decap & encap configurations");
13207 : 0 : return NULL;
13208 : : }
13209 [ # # ]: 0 : if (!priv->dr_ctx) {
13210 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
13211 : : encap_action, "Reformat: HWS not supported");
13212 : 0 : return NULL;
13213 : : }
13214 : 0 : handle = __mlx5_reformat_create(dev, encap, conf, type);
13215 [ # # ]: 0 : if (!handle) {
13216 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
13217 : : "Reformat: failed to create indirect action");
13218 : 0 : return NULL;
13219 : : }
13220 : : return handle;
13221 : : }
13222 : :
13223 : : /**
13224 : : * Destroy the indirect reformat action.
13225 : : * Release action related resources on the NIC and the memory.
13226 : : * Lock free, (mutex should be acquired by caller).
13227 : : *
13228 : : * @param[in] dev
13229 : : * Pointer to the Ethernet device structure.
13230 : : * @param[in] handle
13231 : : * The indirect action list handle to be removed.
13232 : : * @param[out] error
13233 : : * Perform verbose error reporting if not NULL. Initialized in case of
13234 : : * error only.
13235 : : *
13236 : : * @return
13237 : : * 0 on success, otherwise negative errno value.
13238 : : */
13239 : : int
13240 : 0 : mlx5_reformat_action_destroy(struct rte_eth_dev *dev,
13241 : : struct rte_flow_action_list_handle *handle,
13242 : : struct rte_flow_error *error)
13243 : : {
13244 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13245 : : struct mlx5_hw_encap_decap_action *action;
13246 : :
13247 : : action = (struct mlx5_hw_encap_decap_action *)handle;
13248 [ # # # # ]: 0 : if (!priv->dr_ctx || !action)
13249 : 0 : return rte_flow_error_set(error, ENOTSUP,
13250 : : RTE_FLOW_ERROR_TYPE_ACTION, handle,
13251 : : "Reformat: invalid action handle");
13252 : 0 : mlx5dr_action_destroy(action->action);
13253 : 0 : mlx5_free(handle);
13254 : 0 : return 0;
13255 : : }
13256 : :
13257 : : static struct rte_flow_fp_ops mlx5_flow_hw_fp_ops = {
13258 : : .async_create = flow_hw_async_flow_create,
13259 : : .async_create_by_index = flow_hw_async_flow_create_by_index,
13260 : : .async_actions_update = flow_hw_async_flow_update,
13261 : : .async_destroy = flow_hw_async_flow_destroy,
13262 : : .push = flow_hw_push,
13263 : : .pull = flow_hw_pull,
13264 : : .async_action_handle_create = flow_hw_action_handle_create,
13265 : : .async_action_handle_destroy = flow_hw_action_handle_destroy,
13266 : : .async_action_handle_update = flow_hw_action_handle_update,
13267 : : .async_action_handle_query = flow_hw_action_handle_query,
13268 : : .async_action_handle_query_update = flow_hw_async_action_handle_query_update,
13269 : : .async_action_list_handle_create = flow_hw_async_action_list_handle_create,
13270 : : .async_action_list_handle_destroy = flow_hw_async_action_list_handle_destroy,
13271 : : .async_action_list_handle_query_update =
13272 : : flow_hw_async_action_list_handle_query_update,
13273 : : };
13274 : :
13275 : : #endif
|