Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2022 NVIDIA Corporation & Affiliates
3 : : */
4 : :
5 : : #include <eal_export.h>
6 : : #include <rte_flow.h>
7 : : #include <rte_flow_driver.h>
8 : : #include <rte_stdatomic.h>
9 : :
10 : : #include <mlx5_malloc.h>
11 : :
12 : : #include "mlx5.h"
13 : : #include "mlx5_common.h"
14 : : #include "mlx5_defs.h"
15 : : #include "mlx5_flow.h"
16 : : #include "mlx5_flow_os.h"
17 : : #include "mlx5_rx.h"
18 : :
19 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
20 : : #include "mlx5_hws_cnt.h"
21 : :
22 : : /** Fast path async flow API functions. */
23 : : static struct rte_flow_fp_ops mlx5_flow_hw_fp_ops;
24 : :
25 : : /*
26 : : * The default ipool threshold value indicates which per_core_cache
27 : : * value to set.
28 : : */
29 : : #define MLX5_HW_IPOOL_SIZE_THRESHOLD (1 << 19)
30 : : /* The default min local cache size. */
31 : : #define MLX5_HW_IPOOL_CACHE_MIN (1 << 9)
32 : :
33 : : /* Default push burst threshold. */
34 : : #define BURST_THR 32u
35 : :
36 : : /* Default queue to flush the flows. */
37 : : #define MLX5_DEFAULT_FLUSH_QUEUE 0
38 : :
39 : : /* Maximum number of rules in control flow tables. */
40 : : #define MLX5_HW_CTRL_FLOW_NB_RULES (4096)
41 : :
42 : : /* Lowest flow group usable by an application if group translation is done. */
43 : : #define MLX5_HW_LOWEST_USABLE_GROUP (1)
44 : :
45 : : /* Maximum group index usable by user applications for transfer flows. */
46 : : #define MLX5_HW_MAX_TRANSFER_GROUP (UINT32_MAX - 1)
47 : :
48 : : /* Maximum group index usable by user applications for egress flows. */
49 : : #define MLX5_HW_MAX_EGRESS_GROUP (UINT32_MAX - 1)
50 : :
51 : : /* Lowest priority for HW root table. */
52 : : #define MLX5_HW_LOWEST_PRIO_ROOT 15
53 : :
54 : : /* Lowest priority for HW non-root table. */
55 : : #define MLX5_HW_LOWEST_PRIO_NON_ROOT (UINT32_MAX)
56 : :
57 : : /* Priorities for Rx control flow rules. */
58 : : #define MLX5_HW_CTRL_RX_PRIO_L2 (MLX5_HW_LOWEST_PRIO_ROOT)
59 : : #define MLX5_HW_CTRL_RX_PRIO_L3 (MLX5_HW_LOWEST_PRIO_ROOT - 1)
60 : : #define MLX5_HW_CTRL_RX_PRIO_L4 (MLX5_HW_LOWEST_PRIO_ROOT - 2)
61 : :
62 : : #define MLX5_HW_VLAN_PUSH_TYPE_IDX 0
63 : : #define MLX5_HW_VLAN_PUSH_VID_IDX 1
64 : : #define MLX5_HW_VLAN_PUSH_PCP_IDX 2
65 : :
66 : : struct mlx5_indlst_legacy {
67 : : struct mlx5_indirect_list indirect;
68 : : struct rte_flow_action_handle *handle;
69 : : enum rte_flow_action_type legacy_type;
70 : : };
71 : :
72 : : #define MLX5_CONST_ENCAP_ITEM(encap_type, ptr) \
73 : : (((const struct encap_type *)(ptr))->definition)
74 : :
75 : : /**
76 : : * Returns the size of a struct with a following layout:
77 : : *
78 : : * @code{.c}
79 : : * struct rte_flow_hw {
80 : : * // rte_flow_hw fields
81 : : * uint8_t rule[mlx5dr_rule_get_handle_size()];
82 : : * };
83 : : * @endcode
84 : : *
85 : : * Such struct is used as a basic container for HW Steering flow rule.
86 : : */
87 : : static size_t
88 : : mlx5_flow_hw_entry_size(void)
89 : : {
90 : 0 : return sizeof(struct rte_flow_hw) + mlx5dr_rule_get_handle_size();
91 : : }
92 : :
93 : : /**
94 : : * Returns the size of "auxed" rte_flow_hw structure which is assumed to be laid out as follows:
95 : : *
96 : : * @code{.c}
97 : : * struct {
98 : : * struct rte_flow_hw {
99 : : * // rte_flow_hw fields
100 : : * uint8_t rule[mlx5dr_rule_get_handle_size()];
101 : : * } flow;
102 : : * struct rte_flow_hw_aux aux;
103 : : * };
104 : : * @endcode
105 : : *
106 : : * Such struct is used whenever rte_flow_hw_aux cannot be allocated separately from the rte_flow_hw
107 : : * e.g., when table is resizable.
108 : : */
109 : : static size_t
110 : : mlx5_flow_hw_auxed_entry_size(void)
111 : : {
112 : 0 : size_t rule_size = mlx5dr_rule_get_handle_size();
113 : :
114 : 0 : return sizeof(struct rte_flow_hw) + rule_size + sizeof(struct rte_flow_hw_aux);
115 : : }
116 : :
117 : : /**
118 : : * Returns a valid pointer to rte_flow_hw_aux associated with given rte_flow_hw
119 : : * depending on template table configuration.
120 : : */
121 : : static __rte_always_inline struct rte_flow_hw_aux *
122 : : mlx5_flow_hw_aux(uint16_t port_id, struct rte_flow_hw *flow)
123 : : {
124 : 0 : struct rte_flow_template_table *table = flow->table;
125 : :
126 : 0 : if (!flow->nt_rule) {
127 [ # # # # : 0 : if (rte_flow_template_table_resizable(port_id, &table->cfg.attr)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
128 : 0 : size_t offset = sizeof(struct rte_flow_hw) + mlx5dr_rule_get_handle_size();
129 : :
130 : 0 : return RTE_PTR_ADD(flow, offset);
131 : : } else {
132 : 0 : return &table->flow_aux[flow->idx - 1];
133 : : }
134 : : } else {
135 : 0 : return flow->nt2hws->flow_aux;
136 : : }
137 : : }
138 : :
139 : : static __rte_always_inline void
140 : : mlx5_flow_hw_aux_set_age_idx(struct rte_flow_hw *flow,
141 : : struct rte_flow_hw_aux *aux,
142 : : uint32_t age_idx)
143 : : {
144 : : /*
145 : : * Only when creating a flow rule, the type will be set explicitly.
146 : : * Or else, it should be none in the rule update case.
147 : : */
148 [ # # # # : 0 : if (unlikely(flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE))
# # # # #
# # # # #
# # # # #
# ]
149 : 0 : aux->upd.age_idx = age_idx;
150 : : else
151 : 0 : aux->orig.age_idx = age_idx;
152 : : }
153 : :
154 : : static __rte_always_inline uint32_t
155 : : mlx5_flow_hw_aux_get_age_idx(struct rte_flow_hw *flow, struct rte_flow_hw_aux *aux)
156 : : {
157 [ # # # # : 0 : if (unlikely(flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE))
# # # # #
# # # ]
158 : 0 : return aux->upd.age_idx;
159 : : else
160 : 0 : return aux->orig.age_idx;
161 : : }
162 : :
163 : : static __rte_always_inline void
164 : : mlx5_flow_hw_aux_set_mtr_id(struct rte_flow_hw *flow,
165 : : struct rte_flow_hw_aux *aux,
166 : : uint32_t mtr_id)
167 : : {
168 [ # # # # : 0 : if (unlikely(flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE))
# # # # #
# ]
169 : 0 : aux->upd.mtr_id = mtr_id;
170 : : else
171 : 0 : aux->orig.mtr_id = mtr_id;
172 : : }
173 : :
174 : : static __rte_always_inline uint32_t
175 : : mlx5_flow_hw_aux_get_mtr_id(struct rte_flow_hw *flow, struct rte_flow_hw_aux *aux)
176 : : {
177 [ # # ]: 0 : if (unlikely(flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE))
178 : 0 : return aux->upd.mtr_id;
179 : : else
180 : 0 : return aux->orig.mtr_id;
181 : : }
182 : :
183 : : static __rte_always_inline struct mlx5_hw_q_job *
184 : : flow_hw_action_job_init(struct mlx5_priv *priv, uint32_t queue,
185 : : const struct rte_flow_action_handle *handle,
186 : : void *user_data, void *query_data,
187 : : enum mlx5_hw_job_type type,
188 : : enum mlx5_hw_indirect_type indirect_type,
189 : : struct rte_flow_error *error);
190 : : static void
191 : : flow_hw_age_count_release(struct mlx5_priv *priv, uint32_t queue, struct rte_flow_hw *flow,
192 : : struct rte_flow_error *error);
193 : :
194 : : static int
195 : : mlx5_tbl_multi_pattern_process(struct rte_eth_dev *dev,
196 : : struct rte_flow_template_table *tbl,
197 : : struct mlx5_multi_pattern_segment *segment,
198 : : uint32_t bulk_size,
199 : : struct rte_flow_error *error);
200 : : static void
201 : : mlx5_destroy_multi_pattern_segment(struct mlx5_multi_pattern_segment *segment);
202 : :
203 : : static __rte_always_inline enum mlx5_indirect_list_type
204 : : flow_hw_inlist_type_get(const struct rte_flow_action *actions);
205 : :
206 : : static int
207 : : flow_hw_allocate_actions(struct rte_eth_dev *dev,
208 : : uint64_t action_flags,
209 : : struct rte_flow_error *error);
210 : :
211 : : static int
212 : : flow_hw_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
213 : : const struct rte_flow_item items[],
214 : : const struct rte_flow_action actions[],
215 : : bool external __rte_unused, int hairpin __rte_unused,
216 : : struct rte_flow_error *error);
217 : :
218 : : bool
219 : 0 : mlx5_hw_ctx_validate(const struct rte_eth_dev *dev, struct rte_flow_error *error)
220 : : {
221 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
222 : :
223 [ # # ]: 0 : if (!priv->dr_ctx) {
224 : 0 : rte_flow_error_set(error, EINVAL,
225 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
226 : : "non-template flow engine was not configured");
227 : 0 : return false;
228 : : }
229 : : return true;
230 : : }
231 : :
232 : : static int
233 : : flow_hw_allocate_actions(struct rte_eth_dev *dev,
234 : : uint64_t action_flags,
235 : : struct rte_flow_error *error);
236 : :
237 : : static __rte_always_inline int
238 : : mlx5_multi_pattern_reformat_to_index(enum mlx5dr_action_type type)
239 : : {
240 : : switch (type) {
241 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
242 : : return 0;
243 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
244 : : return 1;
245 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
246 : : return 2;
247 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
248 : : return 3;
249 : : default:
250 : : break;
251 : : }
252 : : return -1;
253 : : }
254 : :
255 : : /* Include only supported reformat actions for BWC non template API. */
256 : : static __rte_always_inline int
257 : : mlx5_bwc_multi_pattern_reformat_to_index(enum mlx5dr_action_type type)
258 : : {
259 : 0 : switch (type) {
260 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
261 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
262 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
263 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
264 : : return mlx5_multi_pattern_reformat_to_index(type);
265 : : default:
266 : : break;
267 : : }
268 : : return -1;
269 : : }
270 : :
271 : : static __rte_always_inline enum mlx5dr_action_type
272 : : mlx5_multi_pattern_reformat_index_to_type(uint32_t ix)
273 : : {
274 : : switch (ix) {
275 : : case 0:
276 : : return MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
277 : : case 1:
278 : : return MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
279 : : case 2:
280 : : return MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2;
281 : : case 3:
282 : : return MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
283 : : default:
284 : : break;
285 : : }
286 : : return MLX5DR_ACTION_TYP_MAX;
287 : : }
288 : :
289 : : static inline enum mlx5dr_table_type
290 : : get_mlx5dr_fdb_table_type(const struct rte_flow_attr *attr,
291 : : uint32_t specialize, bool fdb_unified_en)
292 : : {
293 [ # # # # ]: 0 : if (fdb_unified_en && !!attr->group) {
294 [ # # ]: 0 : if ((specialize & (RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG |
295 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG)) == 0)
296 : : return MLX5DR_TABLE_TYPE_FDB_UNIFIED;
297 : : MLX5_ASSERT((specialize & (RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG |
298 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG)) !=
299 : : (RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG |
300 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG));
301 [ # # ]: 0 : if (specialize & RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG)
302 : : return MLX5DR_TABLE_TYPE_FDB_RX;
303 [ # # ]: 0 : if (specialize & RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG)
304 : 0 : return MLX5DR_TABLE_TYPE_FDB_TX;
305 : : }
306 : :
307 : : return MLX5DR_TABLE_TYPE_FDB;
308 : : }
309 : :
310 : : static inline enum mlx5dr_table_type
311 : 0 : get_mlx5dr_table_type(const struct rte_flow_attr *attr, uint32_t specialize,
312 : : bool fdb_unified_en)
313 : : {
314 : : enum mlx5dr_table_type type;
315 : :
316 [ # # ]: 0 : if (attr->transfer)
317 : : type = get_mlx5dr_fdb_table_type(attr, specialize, fdb_unified_en);
318 [ # # ]: 0 : else if (attr->egress)
319 : : type = MLX5DR_TABLE_TYPE_NIC_TX;
320 : : else
321 : : type = MLX5DR_TABLE_TYPE_NIC_RX;
322 : 0 : return type;
323 : : }
324 : :
325 : : /** Human-readable name for mlx5dr_table_type (for error messages). */
326 : : static inline const char *
327 : : mlx5dr_table_type_name(enum mlx5dr_table_type type)
328 : : {
329 [ # # # # : 0 : switch (type) {
# # # # #
# # # #
# ]
330 : : case MLX5DR_TABLE_TYPE_NIC_RX: return "NIC_RX";
331 : 0 : case MLX5DR_TABLE_TYPE_NIC_TX: return "NIC_TX";
332 : 0 : case MLX5DR_TABLE_TYPE_FDB: return "FDB";
333 : 0 : case MLX5DR_TABLE_TYPE_FDB_RX: return "FDB_RX(wire_orig)";
334 : 0 : case MLX5DR_TABLE_TYPE_FDB_TX: return "FDB_TX(vf_orig)";
335 : 0 : case MLX5DR_TABLE_TYPE_FDB_UNIFIED: return "FDB_UNIFIED";
336 : 0 : default: return "unknown";
337 : : }
338 : : }
339 : :
340 : : /* Non template default queue size used for inner ctrl queue. */
341 : : #define MLX5_NT_DEFAULT_QUEUE_SIZE 32
342 : :
343 : : static int flow_hw_flush_all_ctrl_flows(struct rte_eth_dev *dev);
344 : : static int flow_hw_translate_group(struct rte_eth_dev *dev,
345 : : const struct mlx5_flow_template_table_cfg *cfg,
346 : : uint32_t group,
347 : : uint32_t *table_group,
348 : : struct rte_flow_error *error);
349 : : static __rte_always_inline int
350 : : flow_hw_set_vlan_vid_construct(struct rte_eth_dev *dev,
351 : : struct mlx5_modification_cmd *mhdr_cmd,
352 : : struct mlx5_action_construct_data *act_data,
353 : : const struct mlx5_hw_actions *hw_acts,
354 : : const struct rte_flow_action *action);
355 : : static void
356 : : flow_hw_construct_quota(struct mlx5_priv *priv,
357 : : struct mlx5dr_rule_action *rule_act, uint32_t qid);
358 : :
359 : : static int
360 : : mlx5_flow_ct_init(struct rte_eth_dev *dev,
361 : : uint32_t nb_conn_tracks,
362 : : uint16_t nb_queue);
363 : :
364 : : static __rte_always_inline uint32_t flow_hw_tx_tag_regc_mask(struct rte_eth_dev *dev);
365 : : static __rte_always_inline uint32_t flow_hw_tx_tag_regc_value(struct rte_eth_dev *dev);
366 : :
367 : : static int
368 : : mlx5_hw_validate_action_rss(struct rte_eth_dev *dev,
369 : : const struct rte_flow_action *template_action,
370 : : const struct rte_flow_action *template_mask,
371 : : const struct rte_flow_actions_template_attr *template_attr,
372 : : uint64_t action_flags,
373 : : bool is_indirect,
374 : : struct rte_flow_error *error);
375 : :
376 : : static int
377 : : mlx5_hw_validate_action_conntrack(struct rte_eth_dev *dev,
378 : : const struct rte_flow_action *template_action,
379 : : const struct rte_flow_action *template_mask,
380 : : const struct rte_flow_actions_template_attr *template_attr,
381 : : uint64_t action_flags,
382 : : struct rte_flow_error *error);
383 : :
384 : : static int flow_hw_async_create_validate(struct rte_eth_dev *dev,
385 : : const uint32_t queue,
386 : : const struct rte_flow_template_table *table,
387 : : enum rte_flow_table_insertion_type insertion_type,
388 : : const uint32_t rule_index,
389 : : const struct rte_flow_item items[],
390 : : const uint8_t pattern_template_index,
391 : : const struct rte_flow_action actions[],
392 : : const uint8_t action_template_index,
393 : : struct rte_flow_error *error);
394 : : static int flow_hw_async_update_validate(struct rte_eth_dev *dev,
395 : : const uint32_t queue,
396 : : const struct rte_flow_hw *flow,
397 : : const struct rte_flow_action actions[],
398 : : const uint8_t action_template_index,
399 : : struct rte_flow_error *error);
400 : : static int flow_hw_async_destroy_validate(struct rte_eth_dev *dev,
401 : : const uint32_t queue,
402 : : const struct rte_flow_hw *flow,
403 : : struct rte_flow_error *error);
404 : : static bool flow_hw_should_create_nat64_actions(struct mlx5_priv *priv);
405 : :
406 : : const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops;
407 : :
408 : : /* DR action flags with different table. */
409 : : static uint32_t mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_MAX]
410 : : [MLX5DR_TABLE_TYPE_MAX] = {
411 : : {
412 : : MLX5DR_ACTION_FLAG_ROOT_RX,
413 : : MLX5DR_ACTION_FLAG_ROOT_TX,
414 : : MLX5DR_ACTION_FLAG_ROOT_FDB,
415 : : MLX5DR_ACTION_FLAG_ROOT_FDB,
416 : : MLX5DR_ACTION_FLAG_ROOT_FDB,
417 : : MLX5DR_ACTION_FLAG_ROOT_FDB,
418 : : },
419 : : {
420 : : MLX5DR_ACTION_FLAG_HWS_RX,
421 : : MLX5DR_ACTION_FLAG_HWS_TX,
422 : : MLX5DR_ACTION_FLAG_HWS_FDB,
423 : : MLX5DR_ACTION_FLAG_HWS_FDB_RX,
424 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX,
425 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED,
426 : : },
427 : : };
428 : :
429 : : /**
430 : : * Jump table flags.
431 : : * Can jump to FDB_RX table from FDB_RX or UNIFIED tables.
432 : : * Can jump to FDB_TX table from FDB_TX or UNIFIED tables.
433 : : * Can jump to UNIFIED table from all tables.
434 : : */
435 : : static uint32_t mlx5_hw_act_dest_table_flag[MLX5DR_TABLE_TYPE_MAX] = {
436 : : MLX5DR_ACTION_FLAG_HWS_RX,
437 : : MLX5DR_ACTION_FLAG_HWS_TX,
438 : : MLX5DR_ACTION_FLAG_HWS_FDB,
439 : : (MLX5DR_ACTION_FLAG_HWS_FDB_RX | MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED),
440 : : (MLX5DR_ACTION_FLAG_HWS_FDB_TX | MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED),
441 : : (MLX5DR_ACTION_FLAG_HWS_FDB_RX | MLX5DR_ACTION_FLAG_HWS_FDB_TX |
442 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED),
443 : : };
444 : :
445 : : /* Ethernet item spec for promiscuous mode. */
446 : : static const struct rte_flow_item_eth ctrl_rx_eth_promisc_spec = {
447 : : .hdr.dst_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
448 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
449 : : .hdr.ether_type = 0,
450 : : };
451 : : /* Ethernet item mask for promiscuous mode. */
452 : : static const struct rte_flow_item_eth ctrl_rx_eth_promisc_mask = {
453 : : .hdr.dst_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
454 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
455 : : .hdr.ether_type = 0,
456 : : };
457 : :
458 : : /* Ethernet item spec for all multicast mode. */
459 : : static const struct rte_flow_item_eth ctrl_rx_eth_mcast_spec = {
460 : : .hdr.dst_addr.addr_bytes = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
461 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
462 : : .hdr.ether_type = 0,
463 : : };
464 : : /* Ethernet item mask for all multicast mode. */
465 : : static const struct rte_flow_item_eth ctrl_rx_eth_mcast_mask = {
466 : : .hdr.dst_addr.addr_bytes = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
467 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
468 : : .hdr.ether_type = 0,
469 : : };
470 : :
471 : : /* Ethernet item spec for IPv4 multicast traffic. */
472 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv4_mcast_spec = {
473 : : .hdr.dst_addr.addr_bytes = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 },
474 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
475 : : .hdr.ether_type = 0,
476 : : };
477 : : /* Ethernet item mask for IPv4 multicast traffic. */
478 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv4_mcast_mask = {
479 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 },
480 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
481 : : .hdr.ether_type = 0,
482 : : };
483 : :
484 : : /* Ethernet item spec for IPv6 multicast traffic. */
485 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv6_mcast_spec = {
486 : : .hdr.dst_addr.addr_bytes = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 },
487 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
488 : : .hdr.ether_type = 0,
489 : : };
490 : : /* Ethernet item mask for IPv6 multicast traffic. */
491 : : static const struct rte_flow_item_eth ctrl_rx_eth_ipv6_mcast_mask = {
492 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
493 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
494 : : .hdr.ether_type = 0,
495 : : };
496 : :
497 : : /* Ethernet item mask for unicast traffic. */
498 : : static const struct rte_flow_item_eth ctrl_rx_eth_dmac_mask = {
499 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
500 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
501 : : .hdr.ether_type = 0,
502 : : };
503 : :
504 : : /* Ethernet item spec for broadcast. */
505 : : static const struct rte_flow_item_eth ctrl_rx_eth_bcast_spec = {
506 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
507 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
508 : : .hdr.ether_type = 0,
509 : : };
510 : :
511 : : static inline uint32_t
512 : : flow_hw_q_pending(struct mlx5_priv *priv, uint32_t queue)
513 : : {
514 : 0 : struct mlx5_hw_q *q = &priv->hw_q[queue];
515 : :
516 : : MLX5_ASSERT(q->size >= q->job_idx);
517 : 0 : return (q->size - q->job_idx) + q->ongoing_flow_ops;
518 : : }
519 : :
520 : : static inline void
521 : 0 : flow_hw_q_inc_flow_ops(struct mlx5_priv *priv, uint32_t queue)
522 : : {
523 : 0 : struct mlx5_hw_q *q = &priv->hw_q[queue];
524 : :
525 : 0 : q->ongoing_flow_ops++;
526 : 0 : }
527 : :
528 : : static inline void
529 : : flow_hw_q_dec_flow_ops(struct mlx5_priv *priv, uint32_t queue)
530 : : {
531 : 0 : struct mlx5_hw_q *q = &priv->hw_q[queue];
532 : :
533 : 0 : q->ongoing_flow_ops--;
534 : : }
535 : :
536 : : static inline enum mlx5dr_matcher_insert_mode
537 : : flow_hw_matcher_insert_mode_get(enum rte_flow_table_insertion_type insert_type)
538 : : {
539 : 0 : if (insert_type == RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN)
540 : : return MLX5DR_MATCHER_INSERT_BY_HASH;
541 : : else
542 : 0 : return MLX5DR_MATCHER_INSERT_BY_INDEX;
543 : : }
544 : :
545 : : static inline enum mlx5dr_matcher_distribute_mode
546 : : flow_hw_matcher_distribute_mode_get(enum rte_flow_table_hash_func hash_func)
547 : : {
548 [ # # ]: 0 : if (hash_func == RTE_FLOW_TABLE_HASH_FUNC_LINEAR)
549 : : return MLX5DR_MATCHER_DISTRIBUTE_BY_LINEAR;
550 : : else
551 : 0 : return MLX5DR_MATCHER_DISTRIBUTE_BY_HASH;
552 : : }
553 : :
554 : : /**
555 : : * Set the hash fields according to the @p rss_desc information.
556 : : *
557 : : * @param[in] rss_desc
558 : : * Pointer to the mlx5_flow_rss_desc.
559 : : * @param[out] hash_fields
560 : : * Pointer to the RSS hash fields.
561 : : */
562 : : static void
563 : 0 : flow_hw_hashfields_set(struct mlx5_flow_rss_desc *rss_desc,
564 : : uint64_t *hash_fields)
565 : : {
566 : : uint64_t fields = 0;
567 : : int rss_inner = 0;
568 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
569 : :
570 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
571 [ # # ]: 0 : if (rss_desc->level >= 2)
572 : : rss_inner = 1;
573 : : #endif
574 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
575 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
576 : : fields |= IBV_RX_HASH_SRC_IPV4;
577 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
578 : : fields |= IBV_RX_HASH_DST_IPV4;
579 : : else
580 : : fields |= MLX5_IPV4_IBV_RX_HASH;
581 [ # # ]: 0 : } else if (rss_types & MLX5_IPV6_LAYER_TYPES) {
582 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
583 : : fields |= IBV_RX_HASH_SRC_IPV6;
584 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
585 : : fields |= IBV_RX_HASH_DST_IPV6;
586 : : else
587 : : fields |= MLX5_IPV6_IBV_RX_HASH;
588 : : }
589 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
590 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
591 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
592 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
593 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
594 : : else
595 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
596 [ # # ]: 0 : } else if (rss_types & RTE_ETH_RSS_TCP) {
597 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
598 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
599 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
600 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
601 : : else
602 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
603 : : }
604 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
605 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
606 [ # # ]: 0 : if (rss_inner)
607 : 0 : fields |= IBV_RX_HASH_INNER;
608 : 0 : *hash_fields |= fields;
609 : 0 : }
610 : :
611 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_rss_tir_register, 26.03)
612 : : int
613 : 0 : rte_pmd_mlx5_rss_tir_register(uint16_t port_id,
614 : : const struct rte_flow_action_rss *rss,
615 : : struct rte_pmd_mlx5_rss_devx *devx)
616 : : {
617 : : struct rte_eth_dev *dev;
618 : : struct mlx5_hrxq *hrxq;
619 : 0 : struct mlx5_flow_rss_desc rss_desc = {
620 : : .hws_flags = MLX5DR_ACTION_FLAG_ROOT_RX,
621 : : };
622 : :
623 [ # # ]: 0 : if (rte_eth_dev_is_valid_port(port_id) < 0) {
624 : 0 : DRV_LOG(ERR, "port %u: no Ethernet device", port_id);
625 : 0 : rte_errno = ENODEV;
626 : 0 : return -rte_errno;
627 : : }
628 [ # # # # ]: 0 : if (!rss->queue_num || !rss->queue) {
629 : 0 : DRV_LOG(ERR, "port %u: invalid RSS queues configuration", port_id);
630 : 0 : rte_errno = EINVAL;
631 : 0 : return -rte_errno;
632 : : }
633 [ # # # # ]: 0 : if (rss->key && rss->key_len != MLX5_RSS_HASH_KEY_LEN) {
634 : 0 : DRV_LOG(ERR, "port %u: RSS key length must be %d",
635 : : port_id, MLX5_RSS_HASH_KEY_LEN);
636 : 0 : rte_errno = EINVAL;
637 : 0 : return -rte_errno;
638 : : }
639 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
640 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
641 : 0 : DRV_LOG(ERR, "port %u: HWS not active", port_id);
642 : 0 : rte_errno = EINVAL;
643 : 0 : return -rte_errno;
644 : : }
645 : 0 : rss_desc.queue_num = rss->queue_num;
646 : 0 : rss_desc.const_q = rss->queue;
647 [ # # ]: 0 : if (rss->queue_num > 1) {
648 [ # # ]: 0 : memcpy(rss_desc.key,
649 : : rss->key ? rss->key : mlx5_rss_hash_default_key,
650 : : MLX5_RSS_HASH_KEY_LEN);
651 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
652 [ # # ]: 0 : rss_desc.types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
653 : 0 : rss_desc.symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
654 : 0 : flow_hw_hashfields_set(&rss_desc, &rss_desc.hash_fields);
655 : 0 : mlx5_flow_dv_action_rss_l34_hash_adjust(rss->types,
656 : : &rss_desc.hash_fields);
657 [ # # ]: 0 : if (rss->level > 1) {
658 : 0 : rss_desc.hash_fields |= IBV_RX_HASH_INNER;
659 : 0 : rss_desc.tunnel = 1;
660 : : }
661 : : }
662 : :
663 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
664 [ # # ]: 0 : if (!hrxq) {
665 : 0 : DRV_LOG(ERR, "port %u: failed to allocate DevX", port_id);
666 : 0 : return -rte_errno;
667 : : }
668 : 0 : devx->destroy_handle = hrxq;
669 : 0 : devx->obj = hrxq->tir->obj;
670 : 0 : devx->id = hrxq->tir->id;
671 : :
672 : 0 : return 0;
673 : : }
674 : :
675 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_rss_tir_unregister, 26.03)
676 : : int
677 : 0 : rte_pmd_mlx5_rss_tir_unregister(uint16_t port_id, void *handle)
678 : : {
679 : : struct rte_eth_dev *dev;
680 : : struct mlx5_hrxq *hrxq = handle;
681 : :
682 [ # # ]: 0 : if (rte_eth_dev_is_valid_port(port_id) < 0) {
683 : 0 : DRV_LOG(ERR, "port %u: no Ethernet device", port_id);
684 : 0 : rte_errno = ENODEV;
685 : 0 : return -rte_errno;
686 : : }
687 : 0 : dev = &rte_eth_devices[port_id];
688 : 0 : mlx5_hrxq_obj_release(dev, hrxq);
689 : 0 : return 0;
690 : : }
691 : :
692 : : uint64_t
693 : 0 : mlx5_flow_hw_action_flags_get(const struct rte_flow_action actions[],
694 : : const struct rte_flow_action **qrss,
695 : : const struct rte_flow_action **mark,
696 : : int *encap_idx,
697 : : int *act_cnt,
698 : : struct rte_flow_error *error)
699 : : {
700 : : uint64_t action_flags = 0;
701 : : const struct rte_flow_action *action;
702 : : const struct rte_flow_action_raw_encap *raw_encap;
703 : : int raw_decap_idx = -1;
704 : : int action_idx;
705 : :
706 : 0 : *encap_idx = -1;
707 : : action_idx = 0;
708 [ # # ]: 0 : for (action = actions; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
709 : 0 : int type = (int)action->type;
710 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
711 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
712 [ # # # # : 0 : switch (MLX5_INDIRECT_ACTION_TYPE_GET(action->conf)) {
# # ]
713 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
714 : 0 : goto rss;
715 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
716 : 0 : goto age;
717 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
718 : 0 : goto count;
719 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
720 : 0 : goto ct;
721 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
722 : 0 : goto meter;
723 : 0 : default:
724 : 0 : goto error;
725 : : }
726 : : break;
727 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
728 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
729 : 0 : break;
730 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
731 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
732 : 0 : break;
733 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
734 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
735 : 0 : *mark = action;
736 : 0 : break;
737 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
738 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
739 : 0 : break;
740 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
741 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
742 : 0 : break;
743 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
744 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
745 : 0 : break;
746 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
747 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
748 : 0 : break;
749 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
750 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
751 : 0 : *qrss = action;
752 : 0 : break;
753 : : case RTE_FLOW_ACTION_TYPE_RSS:
754 : 0 : rss:
755 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
756 : 0 : *qrss = action;
757 : 0 : break;
758 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
759 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
760 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
761 : 0 : *encap_idx = action_idx;
762 : 0 : break;
763 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
764 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
765 : 0 : raw_encap = action->conf;
766 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
767 : 0 : *encap_idx = raw_decap_idx != -1 ?
768 [ # # ]: 0 : raw_decap_idx : action_idx;
769 : : break;
770 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
771 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
772 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
773 : 0 : break;
774 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
775 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
776 : : raw_decap_idx = action_idx;
777 : 0 : break;
778 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
779 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
780 : 0 : break;
781 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
782 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
783 : 0 : break;
784 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
785 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
786 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
787 : 0 : break;
788 : : case RTE_FLOW_ACTION_TYPE_AGE:
789 : 0 : age:
790 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
791 : 0 : break;
792 : : case RTE_FLOW_ACTION_TYPE_COUNT:
793 : 0 : count:
794 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
795 : 0 : break;
796 : : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
797 : 0 : ct:
798 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
799 : 0 : break;
800 : : case RTE_FLOW_ACTION_TYPE_METER_MARK:
801 : 0 : meter:
802 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
803 : 0 : break;
804 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
805 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
806 : 0 : break;
807 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
808 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP_TO_TABLE_INDEX;
809 : 0 : break;
810 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
811 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
812 : 0 : break;
813 : : case RTE_FLOW_ACTION_TYPE_VOID:
814 : : case RTE_FLOW_ACTION_TYPE_END:
815 : : break;
816 : 0 : default:
817 : 0 : goto error;
818 : : }
819 : 0 : action_idx++;
820 : : }
821 [ # # ]: 0 : if (*encap_idx == -1)
822 : 0 : *encap_idx = action_idx;
823 : 0 : action_idx++; /* The END action. */
824 : 0 : *act_cnt = action_idx;
825 : 0 : return action_flags;
826 : 0 : error:
827 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
828 : : action, "invalid flow action");
829 : 0 : return 0;
830 : : }
831 : :
832 : : /**
833 : : * Register destination table DR jump action.
834 : : *
835 : : * @param[in] dev
836 : : * Pointer to the rte_eth_dev structure.
837 : : * @param[in] table_attr
838 : : * Pointer to the flow attributes.
839 : : * @param[in] dest_group
840 : : * The destination group ID.
841 : : * @param[out] error
842 : : * Pointer to error structure.
843 : : *
844 : : * @return
845 : : * Table on success, NULL otherwise and rte_errno is set.
846 : : */
847 : : static struct mlx5_hw_jump_action *
848 : 0 : flow_hw_jump_action_register(struct rte_eth_dev *dev,
849 : : const struct mlx5_flow_template_table_cfg *cfg,
850 : : uint32_t dest_group,
851 : : struct rte_flow_error *error)
852 : : {
853 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
854 : 0 : struct rte_flow_attr jattr = cfg->attr.flow_attr;
855 : 0 : uint32_t specialize = cfg->attr.specialize;
856 : : struct mlx5_flow_group *grp;
857 : 0 : struct mlx5_flow_cb_ctx ctx = {
858 : : .dev = dev,
859 : : .error = error,
860 : : .data = &jattr,
861 : : .data2 = &specialize,
862 : : };
863 : : struct mlx5_list_entry *ge;
864 : : uint32_t target_group;
865 : :
866 : 0 : target_group = dest_group;
867 [ # # ]: 0 : if (flow_hw_translate_group(dev, cfg, dest_group, &target_group, error))
868 : : return NULL;
869 : 0 : jattr.group = target_group;
870 : 0 : ge = mlx5_hlist_register(priv->sh->flow_tbls, target_group, &ctx);
871 [ # # ]: 0 : if (!ge)
872 : : return NULL;
873 : : grp = container_of(ge, struct mlx5_flow_group, entry);
874 : 0 : return &grp->jump;
875 : : }
876 : :
877 : : /**
878 : : * Release jump action.
879 : : *
880 : : * @param[in] dev
881 : : * Pointer to the rte_eth_dev structure.
882 : : * @param[in] jump
883 : : * Pointer to the jump action.
884 : : */
885 : :
886 : : static void
887 : : flow_hw_jump_release(struct rte_eth_dev *dev, struct mlx5_hw_jump_action *jump)
888 : : {
889 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
890 : : struct mlx5_flow_group *grp;
891 : :
892 : 0 : grp = container_of(jump, struct mlx5_flow_group, jump);
893 : 0 : mlx5_hlist_unregister(priv->sh->flow_tbls, &grp->entry);
894 : 0 : }
895 : :
896 : : /**
897 : : * Register queue/RSS action.
898 : : *
899 : : * @param[in] dev
900 : : * Pointer to the rte_eth_dev structure.
901 : : * @param[in] hws_flags
902 : : * DR action flags.
903 : : * @param[in] action
904 : : * rte flow action.
905 : : * @param[in] item_flags
906 : : * Item flags for non template rule.
907 : : * @param[in] is_template
908 : : * True if it is a template rule.
909 : : *
910 : : * @return
911 : : * Table on success, NULL otherwise and rte_errno is set.
912 : : */
913 : : static inline struct mlx5_hrxq*
914 : 0 : flow_hw_tir_action_register(struct rte_eth_dev *dev,
915 : : uint32_t hws_flags,
916 : : const struct rte_flow_action *action)
917 : : {
918 : 0 : struct mlx5_flow_rss_desc rss_desc = {
919 : : .hws_flags = hws_flags,
920 : : };
921 : : struct mlx5_hrxq *hrxq;
922 : :
923 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
924 : 0 : const struct rte_flow_action_queue *queue = action->conf;
925 : :
926 : 0 : rss_desc.const_q = &queue->index;
927 : 0 : rss_desc.queue_num = 1;
928 : : } else {
929 : 0 : const struct rte_flow_action_rss *rss = action->conf;
930 : :
931 : 0 : rss_desc.queue_num = rss->queue_num;
932 : 0 : rss_desc.const_q = rss->queue;
933 : 0 : memcpy(rss_desc.key,
934 [ # # ]: 0 : !rss->key ? mlx5_rss_hash_default_key : rss->key,
935 : : MLX5_RSS_HASH_KEY_LEN);
936 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
937 [ # # ]: 0 : rss_desc.types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
938 : 0 : rss_desc.symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
939 : 0 : flow_hw_hashfields_set(&rss_desc, &rss_desc.hash_fields);
940 : 0 : mlx5_flow_dv_action_rss_l34_hash_adjust(rss->types,
941 : : &rss_desc.hash_fields);
942 [ # # ]: 0 : if (rss->level > 1) {
943 : 0 : rss_desc.hash_fields |= IBV_RX_HASH_INNER;
944 : 0 : rss_desc.tunnel = 1;
945 : : }
946 : : }
947 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
948 : 0 : return hrxq;
949 : : }
950 : :
951 : : static __rte_always_inline int
952 : : flow_hw_ct_compile(struct rte_eth_dev *dev,
953 : : uint32_t queue, uint32_t idx,
954 : : struct mlx5dr_rule_action *rule_act)
955 : : {
956 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
957 : : struct mlx5_aso_ct_action *ct;
958 : :
959 : 0 : ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
960 [ # # # # : 0 : if (!ct || (!priv->shared_host && mlx5_aso_ct_available(priv->sh, queue, ct)))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
961 : : return -1;
962 : 0 : rule_act->action = priv->hws_ctpool->dr_action;
963 : 0 : rule_act->aso_ct.offset = ct->offset;
964 : 0 : rule_act->aso_ct.direction = ct->is_original ?
965 : 0 : MLX5DR_ACTION_ASO_CT_DIRECTION_INITIATOR :
966 : : MLX5DR_ACTION_ASO_CT_DIRECTION_RESPONDER;
967 : : return 0;
968 : : }
969 : :
970 : : static void
971 : : flow_hw_template_destroy_reformat_action(struct mlx5_hw_encap_decap_action *encap_decap)
972 : : {
973 [ # # # # ]: 0 : if (encap_decap->action && !encap_decap->multi_pattern)
974 : 0 : mlx5dr_action_destroy(encap_decap->action);
975 : : }
976 : :
977 : : static void
978 : : flow_hw_template_destroy_mhdr_action(struct mlx5_hw_modify_header_action *mhdr)
979 : : {
980 [ # # # # ]: 0 : if (mhdr->action && !mhdr->multi_pattern)
981 : 0 : mlx5dr_action_destroy(mhdr->action);
982 : : }
983 : :
984 : : /**
985 : : * Destroy DR actions created by action template.
986 : : *
987 : : * For DR actions created during table creation's action translate.
988 : : * Need to destroy the DR action when destroying the table.
989 : : *
990 : : * @param[in] dev
991 : : * Pointer to the rte_eth_dev structure.
992 : : * @param[in] acts
993 : : * Pointer to the template HW steering DR actions.
994 : : */
995 : : static void
996 : 0 : __flow_hw_actions_release(struct rte_eth_dev *dev, struct mlx5_hw_actions *acts)
997 : : {
998 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
999 : :
1000 [ # # ]: 0 : if (acts->mark)
1001 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&priv->hws_mark_refcnt, 1,
1002 : : rte_memory_order_relaxed) - 1))
1003 : 0 : mlx5_flow_hw_rxq_flag_set(dev, false);
1004 : :
1005 [ # # ]: 0 : if (acts->jump) {
1006 : : struct mlx5_flow_group *grp;
1007 : :
1008 : 0 : grp = container_of
1009 : : (acts->jump, struct mlx5_flow_group, jump);
1010 : 0 : mlx5_hlist_unregister(priv->sh->flow_tbls, &grp->entry);
1011 : 0 : acts->jump = NULL;
1012 : : }
1013 [ # # ]: 0 : if (acts->tir) {
1014 : 0 : mlx5_hrxq_release(dev, acts->tir->idx);
1015 : 0 : acts->tir = NULL;
1016 : : }
1017 [ # # ]: 0 : if (acts->encap_decap) {
1018 : : flow_hw_template_destroy_reformat_action(acts->encap_decap);
1019 : 0 : mlx5_free(acts->encap_decap);
1020 : 0 : acts->encap_decap = NULL;
1021 : : }
1022 [ # # ]: 0 : if (acts->push_remove) {
1023 [ # # ]: 0 : if (acts->push_remove->action)
1024 : 0 : mlx5dr_action_destroy(acts->push_remove->action);
1025 : 0 : mlx5_free(acts->push_remove);
1026 : 0 : acts->push_remove = NULL;
1027 : : }
1028 [ # # ]: 0 : if (acts->mhdr) {
1029 : : flow_hw_template_destroy_mhdr_action(acts->mhdr);
1030 : 0 : mlx5_free(acts->mhdr);
1031 : 0 : acts->mhdr = NULL;
1032 : : }
1033 [ # # ]: 0 : if (mlx5_hws_cnt_id_valid(acts->cnt_id)) {
1034 [ # # ]: 0 : mlx5_hws_cnt_shared_put(priv->hws_cpool, &acts->cnt_id);
1035 : 0 : acts->cnt_id = 0;
1036 : : }
1037 [ # # ]: 0 : if (acts->mtr_id) {
1038 : 0 : mlx5_ipool_free(priv->hws_mpool->idx_pool, acts->mtr_id);
1039 : 0 : acts->mtr_id = 0;
1040 : : }
1041 : 0 : }
1042 : :
1043 : : /**
1044 : : * Release the action data back into the pool without destroy any action.
1045 : : *
1046 : : * @param[in] dev
1047 : : * Pointer to the rte_eth_dev structure.
1048 : : * @param[in] acts
1049 : : * Pointer to the template HW steering DR actions.
1050 : : */
1051 : : static inline void
1052 : 0 : __flow_hw_act_data_flush(struct rte_eth_dev *dev, struct mlx5_hw_actions *acts)
1053 : : {
1054 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1055 : : struct mlx5_action_construct_data *data;
1056 : :
1057 [ # # ]: 0 : while (!LIST_EMPTY(&acts->act_list)) {
1058 : : data = LIST_FIRST(&acts->act_list);
1059 [ # # ]: 0 : LIST_REMOVE(data, next);
1060 : 0 : mlx5_ipool_free(priv->acts_ipool, data->idx);
1061 : : }
1062 : 0 : }
1063 : :
1064 : : /*
1065 : : * Destroy DR actions created by action template.
1066 : : *
1067 : : * For DR actions created during table creation's action translate.
1068 : : * Need to destroy the DR action when destroying the table.
1069 : : *
1070 : : * @param[in] dev
1071 : : * Pointer to the rte_eth_dev structure.
1072 : : * @param[in] acts
1073 : : * Pointer to the template HW steering DR actions.
1074 : : */
1075 : : static void
1076 : 0 : __flow_hw_action_template_destroy(struct rte_eth_dev *dev, struct mlx5_hw_actions *acts)
1077 : : {
1078 : 0 : __flow_hw_act_data_flush(dev, acts);
1079 : 0 : __flow_hw_actions_release(dev, acts);
1080 : 0 : }
1081 : :
1082 : : /**
1083 : : * Append dynamic action to the dynamic action list.
1084 : : *
1085 : : * @param[in] priv
1086 : : * Pointer to the port private data structure.
1087 : : * @param[in] acts
1088 : : * Pointer to the template HW steering DR actions.
1089 : : * @param[in] type
1090 : : * Action type.
1091 : : * @param[in] action_src
1092 : : * Offset of source rte flow action.
1093 : : * @param[in] action_dst
1094 : : * Offset of destination DR action.
1095 : : *
1096 : : * @return
1097 : : * 0 on success, negative value otherwise and rte_errno is set.
1098 : : */
1099 : : static __rte_always_inline struct mlx5_action_construct_data *
1100 : : __flow_hw_act_data_alloc(struct mlx5_priv *priv,
1101 : : enum rte_flow_action_type type,
1102 : : uint16_t action_src,
1103 : : uint16_t action_dst)
1104 : : {
1105 : : struct mlx5_action_construct_data *act_data;
1106 : 0 : uint32_t idx = 0;
1107 : :
1108 : 0 : act_data = mlx5_ipool_zmalloc(priv->acts_ipool, &idx);
1109 [ # # # # : 0 : if (!act_data)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1110 : : return NULL;
1111 : 0 : act_data->idx = idx;
1112 : 0 : act_data->type = type;
1113 : 0 : act_data->action_src = action_src;
1114 : 0 : act_data->action_dst = action_dst;
1115 : : return act_data;
1116 : : }
1117 : :
1118 : : /**
1119 : : * Append dynamic action to the dynamic action list.
1120 : : *
1121 : : * @param[in] priv
1122 : : * Pointer to the port private data structure.
1123 : : * @param[in] acts
1124 : : * Pointer to the template HW steering DR actions.
1125 : : * @param[in] type
1126 : : * Action type.
1127 : : * @param[in] action_src
1128 : : * Offset of source rte flow action.
1129 : : * @param[in] action_dst
1130 : : * Offset of destination DR action.
1131 : : *
1132 : : * @return
1133 : : * 0 on success, negative value otherwise and rte_errno is set.
1134 : : */
1135 : : static __rte_always_inline int
1136 : : __flow_hw_act_data_general_append(struct mlx5_priv *priv,
1137 : : struct mlx5_hw_actions *acts,
1138 : : enum rte_flow_action_type type,
1139 : : uint16_t action_src,
1140 : : uint16_t action_dst)
1141 : : {
1142 : : struct mlx5_action_construct_data *act_data;
1143 : :
1144 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1145 : : if (!act_data)
1146 : : return -1;
1147 [ # # # # : 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1148 : : return 0;
1149 : : }
1150 : :
1151 : : static __rte_always_inline int
1152 : : __flow_hw_act_data_indirect_append(struct mlx5_priv *priv,
1153 : : struct mlx5_hw_actions *acts,
1154 : : enum rte_flow_action_type type,
1155 : : enum rte_flow_action_type mask_type,
1156 : : uint16_t action_src,
1157 : : uint16_t action_dst)
1158 : : {
1159 : : struct mlx5_action_construct_data *act_data;
1160 : :
1161 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1162 : : if (!act_data)
1163 : : return -1;
1164 : 0 : act_data->indirect.expected_type = mask_type;
1165 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
1166 : : return 0;
1167 : : }
1168 : :
1169 : : static __rte_always_inline int
1170 : : flow_hw_act_data_indirect_list_append(struct mlx5_priv *priv,
1171 : : struct mlx5_hw_actions *acts,
1172 : : enum rte_flow_action_type type,
1173 : : uint16_t action_src, uint16_t action_dst,
1174 : : indirect_list_callback_t cb)
1175 : : {
1176 : : struct mlx5_action_construct_data *act_data;
1177 : :
1178 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1179 : : if (!act_data)
1180 : 0 : return -1;
1181 : 0 : act_data->indirect_list_cb = cb;
1182 [ # # # # : 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
# # ]
1183 : 0 : return 0;
1184 : : }
1185 : : /**
1186 : : * Append dynamic encap action to the dynamic action list.
1187 : : *
1188 : : * @param[in] priv
1189 : : * Pointer to the port private data structure.
1190 : : * @param[in] acts
1191 : : * Pointer to the template HW steering DR actions.
1192 : : * @param[in] type
1193 : : * Action type.
1194 : : * @param[in] action_src
1195 : : * Offset of source rte flow action.
1196 : : * @param[in] action_dst
1197 : : * Offset of destination DR action.
1198 : : * @param[in] len
1199 : : * Length of the data to be updated.
1200 : : *
1201 : : * @return
1202 : : * 0 on success, negative value otherwise and rte_errno is set.
1203 : : */
1204 : : static __rte_always_inline int
1205 : : __flow_hw_act_data_encap_append(struct mlx5_priv *priv,
1206 : : struct mlx5_hw_actions *acts,
1207 : : enum rte_flow_action_type type,
1208 : : uint16_t action_src,
1209 : : uint16_t action_dst,
1210 : : uint16_t len)
1211 : : {
1212 : : struct mlx5_action_construct_data *act_data;
1213 : :
1214 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1215 : : if (!act_data)
1216 : : return -1;
1217 : 0 : act_data->encap.len = len;
1218 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
1219 : : return 0;
1220 : : }
1221 : :
1222 : : /**
1223 : : * Append dynamic push action to the dynamic action list.
1224 : : *
1225 : : * @param[in] dev
1226 : : * Pointer to the port.
1227 : : * @param[in] acts
1228 : : * Pointer to the template HW steering DR actions.
1229 : : * @param[in] type
1230 : : * Action type.
1231 : : * @param[in] action_src
1232 : : * Offset of source rte flow action.
1233 : : * @param[in] action_dst
1234 : : * Offset of destination DR action.
1235 : : * @param[in] len
1236 : : * Length of the data to be updated.
1237 : : *
1238 : : * @return
1239 : : * Data pointer on success, NULL otherwise and rte_errno is set.
1240 : : */
1241 : : static __rte_always_inline void *
1242 : : __flow_hw_act_data_push_append(struct rte_eth_dev *dev,
1243 : : struct mlx5_hw_actions *acts,
1244 : : enum rte_flow_action_type type,
1245 : : uint16_t action_src,
1246 : : uint16_t action_dst,
1247 : : uint16_t len)
1248 : : {
1249 : : struct mlx5_action_construct_data *act_data;
1250 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1251 : :
1252 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1253 : : if (!act_data)
1254 : : return NULL;
1255 : 0 : act_data->ipv6_ext.len = len;
1256 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
1257 : : return act_data;
1258 : : }
1259 : :
1260 : : static __rte_always_inline int
1261 : : __flow_hw_act_data_hdr_modify_append(struct mlx5_priv *priv,
1262 : : struct mlx5_hw_actions *acts,
1263 : : enum rte_flow_action_type type,
1264 : : uint16_t action_src,
1265 : : uint16_t action_dst,
1266 : : const struct rte_flow_action_modify_field *mf,
1267 : : uint16_t mhdr_cmds_off,
1268 : : uint16_t mhdr_cmds_end,
1269 : : bool shared,
1270 : : struct field_modify_info *field,
1271 : : struct field_modify_info *dcopy,
1272 : : uint32_t *mask)
1273 : : {
1274 : : struct mlx5_action_construct_data *act_data;
1275 : :
1276 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1277 : : if (!act_data)
1278 : : return -1;
1279 : 0 : act_data->modify_header.action = *mf;
1280 : 0 : act_data->modify_header.mhdr_cmds_off = mhdr_cmds_off;
1281 : 0 : act_data->modify_header.mhdr_cmds_end = mhdr_cmds_end;
1282 : 0 : act_data->modify_header.shared = shared;
1283 [ # # ]: 0 : rte_memcpy(act_data->modify_header.field, field,
1284 : : sizeof(*field) * MLX5_ACT_MAX_MOD_FIELDS);
1285 [ # # ]: 0 : rte_memcpy(act_data->modify_header.dcopy, dcopy,
1286 : : sizeof(*dcopy) * MLX5_ACT_MAX_MOD_FIELDS);
1287 : : rte_memcpy(act_data->modify_header.mask, mask,
1288 : : sizeof(*mask) * MLX5_ACT_MAX_MOD_FIELDS);
1289 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
1290 : : return 0;
1291 : : }
1292 : :
1293 : : /**
1294 : : * Append shared RSS action to the dynamic action list.
1295 : : *
1296 : : * @param[in] priv
1297 : : * Pointer to the port private data structure.
1298 : : * @param[in] acts
1299 : : * Pointer to the template HW steering DR actions.
1300 : : * @param[in] type
1301 : : * Action type.
1302 : : * @param[in] action_src
1303 : : * Offset of source rte flow action.
1304 : : * @param[in] action_dst
1305 : : * Offset of destination DR action.
1306 : : * @param[in] idx
1307 : : * Shared RSS index.
1308 : : * @param[in] rss
1309 : : * Pointer to the shared RSS info.
1310 : : *
1311 : : * @return
1312 : : * 0 on success, negative value otherwise and rte_errno is set.
1313 : : */
1314 : : static __rte_always_inline int
1315 : : __flow_hw_act_data_shared_rss_append(struct mlx5_priv *priv,
1316 : : struct mlx5_hw_actions *acts,
1317 : : enum rte_flow_action_type type,
1318 : : uint16_t action_src,
1319 : : uint16_t action_dst,
1320 : : uint32_t idx,
1321 : : struct mlx5_shared_action_rss *rss)
1322 : : {
1323 : : struct mlx5_action_construct_data *act_data;
1324 : :
1325 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1326 : : if (!act_data)
1327 : : return -1;
1328 : 0 : act_data->shared_rss.level = rss->origin.level;
1329 [ # # ]: 0 : act_data->shared_rss.types = !rss->origin.types ? RTE_ETH_RSS_IP :
1330 : : rss->origin.types;
1331 : 0 : act_data->shared_rss.idx = idx;
1332 : 0 : act_data->shared_rss.symmetric_hash_function =
1333 : 0 : MLX5_RSS_IS_SYMM(rss->origin.func);
1334 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
1335 : : return 0;
1336 : : }
1337 : :
1338 : : /**
1339 : : * Append shared counter action to the dynamic action list.
1340 : : *
1341 : : * @param[in] priv
1342 : : * Pointer to the port private data structure.
1343 : : * @param[in] acts
1344 : : * Pointer to the template HW steering DR actions.
1345 : : * @param[in] type
1346 : : * Action type.
1347 : : * @param[in] action_src
1348 : : * Offset of source rte flow action.
1349 : : * @param[in] action_dst
1350 : : * Offset of destination DR action.
1351 : : * @param[in] cnt_id
1352 : : * Shared counter id.
1353 : : *
1354 : : * @return
1355 : : * 0 on success, negative value otherwise and rte_errno is set.
1356 : : */
1357 : : static __rte_always_inline int
1358 : : __flow_hw_act_data_shared_cnt_append(struct mlx5_priv *priv,
1359 : : struct mlx5_hw_actions *acts,
1360 : : enum rte_flow_action_type type,
1361 : : uint16_t action_src,
1362 : : uint16_t action_dst,
1363 : : cnt_id_t cnt_id)
1364 : : {
1365 : : struct mlx5_action_construct_data *act_data;
1366 : :
1367 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1368 : : if (!act_data)
1369 : : return -1;
1370 : : act_data->type = type;
1371 : 0 : act_data->shared_counter.id = cnt_id;
1372 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
1373 : : return 0;
1374 : : }
1375 : :
1376 : : /**
1377 : : * Append shared meter_mark action to the dynamic action list.
1378 : : *
1379 : : * @param[in] priv
1380 : : * Pointer to the port private data structure.
1381 : : * @param[in] acts
1382 : : * Pointer to the template HW steering DR actions.
1383 : : * @param[in] type
1384 : : * Action type.
1385 : : * @param[in] action_src
1386 : : * Offset of source rte flow action.
1387 : : * @param[in] action_dst
1388 : : * Offset of destination DR action.
1389 : : * @param[in] mtr_id
1390 : : * Shared meter id.
1391 : : *
1392 : : * @return
1393 : : * 0 on success, negative value otherwise and rte_errno is set.
1394 : : */
1395 : : static __rte_always_inline int
1396 : : __flow_hw_act_data_shared_mtr_append(struct mlx5_priv *priv,
1397 : : struct mlx5_hw_actions *acts,
1398 : : enum rte_flow_action_type type,
1399 : : uint16_t action_src,
1400 : : uint16_t action_dst,
1401 : : cnt_id_t mtr_id)
1402 : : { struct mlx5_action_construct_data *act_data;
1403 : :
1404 : : act_data = __flow_hw_act_data_alloc(priv, type, action_src, action_dst);
1405 : : if (!act_data)
1406 : : return -1;
1407 : : act_data->type = type;
1408 : 0 : act_data->shared_meter.id = mtr_id;
1409 [ # # ]: 0 : LIST_INSERT_HEAD(&acts->act_list, act_data, next);
1410 : : return 0;
1411 : : }
1412 : :
1413 : : /**
1414 : : * Translate shared indirect action.
1415 : : *
1416 : : * @param[in] dev
1417 : : * Pointer to the rte_eth_dev data structure.
1418 : : * @param[in] action
1419 : : * Pointer to the shared indirect rte_flow action.
1420 : : * @param[in] acts
1421 : : * Pointer to the template HW steering DR actions.
1422 : : * @param[in] action_src
1423 : : * Offset of source rte flow action.
1424 : : * @param[in] action_dst
1425 : : * Offset of destination DR action.
1426 : : *
1427 : : * @return
1428 : : * 0 on success, negative value otherwise and rte_errno is set.
1429 : : */
1430 : : static __rte_always_inline int
1431 : : flow_hw_shared_action_translate(struct rte_eth_dev *dev,
1432 : : const struct rte_flow_action *action,
1433 : : struct mlx5_hw_actions *acts,
1434 : : uint16_t action_src,
1435 : : uint16_t action_dst,
1436 : : struct rte_flow_error *error)
1437 : : {
1438 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1439 : : struct mlx5_shared_action_rss *shared_rss;
1440 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)action->conf;
1441 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
1442 : 0 : uint32_t idx = act_idx &
1443 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
1444 : :
1445 : 0 : switch (type) {
1446 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
1447 : 0 : shared_rss = mlx5_ipool_get
1448 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
1449 [ # # ]: 0 : if (!shared_rss || __flow_hw_act_data_shared_rss_append
1450 : : (priv, acts,
1451 : : (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_RSS,
1452 : : action_src, action_dst, idx, shared_rss)) {
1453 : 0 : DRV_LOG(ERR, "port %u Indirect RSS action (handle %p) translate failed",
1454 : : dev->data->port_id, action->conf);
1455 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1456 : : action, "Indirect RSS action translate failed");
1457 : : }
1458 : : break;
1459 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
1460 : : if (__flow_hw_act_data_shared_cnt_append(priv, acts,
1461 : : (enum rte_flow_action_type)
1462 : : MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
1463 : : action_src, action_dst, act_idx)) {
1464 : 0 : DRV_LOG(ERR,
1465 : : "port %u Indirect count action (handle %p) "
1466 : : "translate failed",
1467 : : dev->data->port_id, action->conf);
1468 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1469 : : action,
1470 : : "Indirect count action translate failed");
1471 : : }
1472 : : break;
1473 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
1474 : : if (flow_hw_ct_compile(dev, MLX5_HW_INV_QUEUE,
1475 : : idx, &acts->rule_acts[action_dst])) {
1476 : 0 : DRV_LOG(ERR, "port %u Indirect CT action (handle %p) translate failed",
1477 : : dev->data->port_id, action->conf);
1478 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1479 : : action, "Indirect CT action translate failed");
1480 : : }
1481 : : break;
1482 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
1483 : : if (__flow_hw_act_data_shared_mtr_append(priv, acts,
1484 : : (enum rte_flow_action_type)
1485 : : MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK,
1486 : : action_src, action_dst, idx)) {
1487 : 0 : DRV_LOG(ERR,
1488 : : "port %u Indirect meter mark action (handle %p) "
1489 : : "translate failed",
1490 : : dev->data->port_id, action->conf);
1491 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1492 : : action,
1493 : : "Indirect meter mark action translate failed");
1494 : : }
1495 : : break;
1496 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
1497 : : flow_hw_construct_quota(priv, &acts->rule_acts[action_dst], idx);
1498 : : break;
1499 : 0 : default:
1500 : 0 : DRV_LOG(ERR, "Unsupported shared action type: %d", type);
1501 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, action,
1502 : : "Unsupported shared action type");
1503 : : }
1504 : : return 0;
1505 : : }
1506 : :
1507 : : static __rte_always_inline bool
1508 : : flow_hw_action_modify_field_is_shared(const struct rte_flow_action *action,
1509 : : const struct rte_flow_action *mask)
1510 : : {
1511 : : const struct rte_flow_action_modify_field *v = action->conf;
1512 : 0 : const struct rte_flow_action_modify_field *m = mask->conf;
1513 : :
1514 : 0 : if (v->src.field == RTE_FLOW_FIELD_VALUE) {
1515 : : uint32_t j;
1516 : :
1517 [ # # ]: 0 : for (j = 0; j < RTE_DIM(m->src.value); ++j) {
1518 : : /*
1519 : : * Immediate value is considered to be masked
1520 : : * (and thus shared by all flow rules), if mask
1521 : : * is non-zero. Partial mask over immediate value
1522 : : * is not allowed.
1523 : : */
1524 [ # # ]: 0 : if (m->src.value[j])
1525 : : return true;
1526 : : }
1527 : : return false;
1528 : : }
1529 [ # # ]: 0 : if (v->src.field == RTE_FLOW_FIELD_POINTER)
1530 : 0 : return m->src.pvalue != NULL;
1531 : : /*
1532 : : * Source field types other than VALUE and
1533 : : * POINTER are always shared.
1534 : : */
1535 : : return true;
1536 : : }
1537 : :
1538 : : static __rte_always_inline bool
1539 : : flow_hw_should_insert_nop(const struct mlx5_hw_modify_header_action *mhdr,
1540 : : const struct mlx5_modification_cmd *cmd,
1541 : : const struct rte_flow_attr *attr)
1542 : : {
1543 : : struct mlx5_modification_cmd last_cmd = { { 0 } };
1544 : : struct mlx5_modification_cmd new_cmd = { { 0 } };
1545 : 0 : const uint32_t cmds_num = mhdr->mhdr_cmds_num;
1546 : : unsigned int last_type;
1547 : : bool should_insert = false;
1548 : :
1549 : : /*
1550 : : * Modify header action list does not require NOPs in root table,
1551 : : * because different type of underlying object is used:
1552 : : * - in root table - MODIFY_HEADER_CONTEXT (does not require NOPs),
1553 : : * - in non-root - either inline modify action or based on Modify Header Pattern
1554 : : * (which requires NOPs).
1555 : : */
1556 [ # # # # ]: 0 : if (attr->group == 0)
1557 : : return false;
1558 [ # # # # ]: 0 : if (cmds_num == 0)
1559 : : return false;
1560 : 0 : last_cmd = *(&mhdr->mhdr_cmds[cmds_num - 1]);
1561 [ # # # # ]: 0 : last_cmd.data0 = rte_be_to_cpu_32(last_cmd.data0);
1562 [ # # # # ]: 0 : last_cmd.data1 = rte_be_to_cpu_32(last_cmd.data1);
1563 : 0 : last_type = last_cmd.action_type;
1564 : 0 : new_cmd = *cmd;
1565 [ # # # # ]: 0 : new_cmd.data0 = rte_be_to_cpu_32(new_cmd.data0);
1566 [ # # # # ]: 0 : new_cmd.data1 = rte_be_to_cpu_32(new_cmd.data1);
1567 [ # # # # : 0 : switch (new_cmd.action_type) {
# # ]
1568 : 0 : case MLX5_MODIFICATION_TYPE_SET:
1569 : : case MLX5_MODIFICATION_TYPE_ADD:
1570 [ # # # # ]: 0 : if (last_type == MLX5_MODIFICATION_TYPE_SET ||
1571 : : last_type == MLX5_MODIFICATION_TYPE_ADD)
1572 : 0 : should_insert = new_cmd.field == last_cmd.field;
1573 : 0 : else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
1574 [ # # # # ]: 0 : last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
1575 : 0 : should_insert = new_cmd.field == last_cmd.dst_field;
1576 : : else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
1577 : : should_insert = false;
1578 : : else
1579 : : MLX5_ASSERT(false); /* Other types are not supported. */
1580 : : break;
1581 : 0 : case MLX5_MODIFICATION_TYPE_COPY:
1582 : : case MLX5_MODIFICATION_TYPE_ADD_FIELD:
1583 [ # # # # ]: 0 : if (last_type == MLX5_MODIFICATION_TYPE_SET ||
1584 : : last_type == MLX5_MODIFICATION_TYPE_ADD)
1585 [ # # # # ]: 0 : should_insert = (new_cmd.field == last_cmd.field ||
1586 [ # # # # ]: 0 : new_cmd.dst_field == last_cmd.field);
1587 : 0 : else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
1588 [ # # # # ]: 0 : last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
1589 [ # # # # ]: 0 : should_insert = (new_cmd.field == last_cmd.dst_field ||
1590 [ # # # # ]: 0 : new_cmd.dst_field == last_cmd.dst_field);
1591 : : else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
1592 : : should_insert = false;
1593 : : else
1594 : : MLX5_ASSERT(false); /* Other types are not supported. */
1595 : : break;
1596 : : default:
1597 : : /* Other action types should be rejected on AT validation. */
1598 : : MLX5_ASSERT(false);
1599 : : break;
1600 : : }
1601 : : return should_insert;
1602 : : }
1603 : :
1604 : : static __rte_always_inline int
1605 : : flow_hw_mhdr_cmd_nop_append(struct mlx5_hw_modify_header_action *mhdr)
1606 : : {
1607 : : struct mlx5_modification_cmd *nop;
1608 : : uint32_t num = mhdr->mhdr_cmds_num;
1609 : :
1610 [ # # # # ]: 0 : if (num + 1 >= MLX5_MHDR_MAX_CMD)
1611 : : return -ENOMEM;
1612 : 0 : nop = mhdr->mhdr_cmds + num;
1613 : : nop->data0 = 0;
1614 : : nop->action_type = MLX5_MODIFICATION_TYPE_NOP;
1615 : 0 : nop->data0 = rte_cpu_to_be_32(nop->data0);
1616 : 0 : nop->data1 = 0;
1617 : 0 : mhdr->mhdr_cmds_num = num + 1;
1618 : : return 0;
1619 : : }
1620 : :
1621 : : static __rte_always_inline int
1622 : : flow_hw_mhdr_cmd_append(struct mlx5_hw_modify_header_action *mhdr,
1623 : : struct mlx5_modification_cmd *cmd)
1624 : : {
1625 : 0 : uint32_t num = mhdr->mhdr_cmds_num;
1626 : :
1627 [ # # ]: 0 : if (num + 1 >= MLX5_MHDR_MAX_CMD)
1628 : : return -ENOMEM;
1629 : 0 : mhdr->mhdr_cmds[num] = *cmd;
1630 : 0 : mhdr->mhdr_cmds_num = num + 1;
1631 : : return 0;
1632 : : }
1633 : :
1634 : : static __rte_always_inline int
1635 : : flow_hw_converted_mhdr_cmds_append(struct mlx5_hw_modify_header_action *mhdr,
1636 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1637 : : const struct rte_flow_attr *attr)
1638 : : {
1639 : : uint32_t idx;
1640 : : int ret;
1641 : :
1642 [ # # ]: 0 : for (idx = 0; idx < resource->actions_num; ++idx) {
1643 : : struct mlx5_modification_cmd *src = &resource->actions[idx];
1644 : :
1645 [ # # ]: 0 : if (flow_hw_should_insert_nop(mhdr, src, attr)) {
1646 : : ret = flow_hw_mhdr_cmd_nop_append(mhdr);
1647 : : if (ret)
1648 : : return ret;
1649 : : }
1650 : : ret = flow_hw_mhdr_cmd_append(mhdr, src);
1651 : : if (ret)
1652 : : return ret;
1653 : : }
1654 : : return 0;
1655 : : }
1656 : :
1657 : : static __rte_always_inline void
1658 : : flow_hw_modify_field_init(struct mlx5_hw_modify_header_action *mhdr,
1659 : : struct rte_flow_actions_template *at)
1660 : : {
1661 : : memset(mhdr, 0, sizeof(*mhdr));
1662 : : /* Modify header action without any commands is shared by default. */
1663 : 0 : mhdr->shared = true;
1664 : 0 : mhdr->pos = at->mhdr_off;
1665 : : }
1666 : :
1667 : : static __rte_always_inline int
1668 : : flow_hw_modify_field_compile(struct rte_eth_dev *dev,
1669 : : const struct rte_flow_attr *attr,
1670 : : const struct rte_flow_action *action, /* Current action from AT. */
1671 : : const struct rte_flow_action *action_mask, /* Current mask from AT. */
1672 : : struct mlx5_hw_actions *acts,
1673 : : struct mlx5_hw_modify_header_action *mhdr,
1674 : : uint16_t src_pos,
1675 : : struct rte_flow_error *error)
1676 : : {
1677 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1678 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
1679 : : union {
1680 : : struct mlx5_flow_dv_modify_hdr_resource resource;
1681 : : uint8_t data[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
1682 : : sizeof(struct mlx5_modification_cmd) * MLX5_MHDR_MAX_CMD];
1683 : : } dummy;
1684 : : struct mlx5_flow_dv_modify_hdr_resource *resource;
1685 : 0 : struct rte_flow_item item = {
1686 : : .spec = NULL,
1687 : : .mask = NULL
1688 : : };
1689 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1690 : : {0, 0, MLX5_MODI_OUT_NONE} };
1691 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1692 : : {0, 0, MLX5_MODI_OUT_NONE} };
1693 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = { 0 };
1694 : 0 : uint32_t type, value = 0;
1695 : : uint16_t cmds_start, cmds_end;
1696 : : bool shared;
1697 : : int ret;
1698 : :
1699 : : /*
1700 : : * Modify header action is shared if previous modify_field actions
1701 : : * are shared and currently compiled action is shared.
1702 : : */
1703 : : shared = flow_hw_action_modify_field_is_shared(action, action_mask);
1704 : 0 : mhdr->shared &= shared;
1705 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1706 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
1707 [ # # ]: 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ? MLX5_MODIFICATION_TYPE_SET :
1708 : : MLX5_MODIFICATION_TYPE_ADD;
1709 : : /* For SET/ADD fill the destination field (field) first. */
1710 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1711 : 0 : conf->width, dev,
1712 : : attr, error);
1713 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1714 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
1715 : : (void *)(uintptr_t)&conf->src.value;
1716 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
1717 : : conf->dst.field == RTE_FLOW_FIELD_TAG ||
1718 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR ||
1719 : 0 : conf->dst.field == (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
1720 : : uint8_t tag_index = flow_tag_index_get(&conf->dst);
1721 : :
1722 : 0 : value = *(const unaligned_uint32_t *)item.spec;
1723 [ # # # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_TAG &&
1724 : : tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
1725 [ # # ]: 0 : value = rte_cpu_to_be_32(value << 16);
1726 : : else
1727 [ # # ]: 0 : value = rte_cpu_to_be_32(value);
1728 : 0 : item.spec = &value;
1729 : : } else if (conf->dst.field == RTE_FLOW_FIELD_GTP_PSC_QFI ||
1730 : : conf->dst.field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE) {
1731 : : /*
1732 : : * Both QFI and Geneve option type are passed as an uint8_t integer,
1733 : : * but it is accessed through a 2nd least significant byte of a 32-bit
1734 : : * field in modify header command.
1735 : : */
1736 : 0 : value = *(const uint8_t *)item.spec;
1737 [ # # ]: 0 : value = rte_cpu_to_be_32(value << 8);
1738 : 0 : item.spec = &value;
1739 : : } else if (conf->dst.field == RTE_FLOW_FIELD_VXLAN_LAST_RSVD) {
1740 : 0 : value = *(const uint8_t *)item.spec << 24;
1741 [ # # ]: 0 : value = rte_cpu_to_be_32(value);
1742 : 0 : item.spec = &value;
1743 : 0 : } else if (conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
1744 [ # # # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK) &&
1745 [ # # ]: 0 : mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private)) {
1746 : 0 : value = *(const unaligned_uint32_t *)item.spec << MLX5_IPV6_HDR_DSCP_SHIFT;
1747 : 0 : item.spec = &value;
1748 : : }
1749 : : } else {
1750 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
1751 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_COPY : MLX5_MODIFICATION_TYPE_ADD_FIELD;
1752 : : /* For COPY fill the destination field (dcopy) without mask. */
1753 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1754 : 0 : conf->width, dev,
1755 : : attr, error);
1756 : : /* Then construct the source field (field) with mask. */
1757 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1758 : 0 : conf->width, dev,
1759 : : attr, error);
1760 : : }
1761 : 0 : item.mask = &mask;
1762 : : memset(&dummy, 0, sizeof(dummy));
1763 : : resource = &dummy.resource;
1764 : 0 : ret = mlx5_flow_dv_convert_modify_action(&item, field, dcopy, resource, type, error);
1765 [ # # ]: 0 : if (ret)
1766 : : return ret;
1767 : : MLX5_ASSERT(resource->actions_num > 0);
1768 : : /*
1769 : : * If previous modify field action collide with this one, then insert NOP command.
1770 : : * This NOP command will not be a part of action's command range used to update commands
1771 : : * on rule creation.
1772 : : */
1773 [ # # ]: 0 : if (flow_hw_should_insert_nop(mhdr, &resource->actions[0], attr)) {
1774 : : ret = flow_hw_mhdr_cmd_nop_append(mhdr);
1775 : : if (ret)
1776 : 0 : return rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1777 : : NULL, "too many modify field operations specified");
1778 : : }
1779 : 0 : cmds_start = mhdr->mhdr_cmds_num;
1780 : : ret = flow_hw_converted_mhdr_cmds_append(mhdr, resource, attr);
1781 [ # # ]: 0 : if (ret)
1782 : 0 : return rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1783 : : NULL, "too many modify field operations specified");
1784 : :
1785 : 0 : cmds_end = mhdr->mhdr_cmds_num;
1786 [ # # ]: 0 : if (shared)
1787 : : return 0;
1788 : : ret = __flow_hw_act_data_hdr_modify_append(priv, acts, RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
1789 : 0 : src_pos, mhdr->pos, conf,
1790 : : cmds_start, cmds_end, shared,
1791 : : field, dcopy, mask);
1792 : : if (ret)
1793 : 0 : return rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1794 : : NULL, "not enough memory to store modify field metadata");
1795 : : return 0;
1796 : : }
1797 : :
1798 : : static uint32_t
1799 : 0 : flow_hw_count_nop_modify_field(struct mlx5_hw_modify_header_action *mhdr)
1800 : : {
1801 : : uint32_t i;
1802 : : uint32_t nops = 0;
1803 : :
1804 [ # # ]: 0 : for (i = 0; i < mhdr->mhdr_cmds_num; ++i) {
1805 : 0 : struct mlx5_modification_cmd cmd = mhdr->mhdr_cmds[i];
1806 : :
1807 [ # # ]: 0 : cmd.data0 = rte_be_to_cpu_32(cmd.data0);
1808 [ # # ]: 0 : if (cmd.action_type == MLX5_MODIFICATION_TYPE_NOP)
1809 : 0 : ++nops;
1810 : : }
1811 : 0 : return nops;
1812 : : }
1813 : :
1814 : : static int
1815 : 0 : flow_hw_validate_compiled_modify_field(struct rte_eth_dev *dev,
1816 : : const struct mlx5_flow_template_table_cfg *cfg,
1817 : : struct mlx5_hw_modify_header_action *mhdr,
1818 : : struct rte_flow_error *error)
1819 : : {
1820 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1821 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
1822 : :
1823 : : /*
1824 : : * Header modify pattern length limitation is only valid for HWS groups, i.e. groups > 0.
1825 : : * In group 0, MODIFY_FIELD actions are handled with header modify actions
1826 : : * managed by rdma-core.
1827 : : */
1828 [ # # ]: 0 : if (cfg->attr.flow_attr.group != 0 &&
1829 [ # # ]: 0 : mhdr->mhdr_cmds_num > hca_attr->max_header_modify_pattern_length) {
1830 : 0 : uint32_t nops = flow_hw_count_nop_modify_field(mhdr);
1831 : :
1832 : 0 : DRV_LOG(ERR, "Too many modify header commands generated from "
1833 : : "MODIFY_FIELD actions. "
1834 : : "Generated HW commands = %u (amount of NOP commands = %u). "
1835 : : "Maximum supported = %u.",
1836 : : mhdr->mhdr_cmds_num, nops,
1837 : : hca_attr->max_header_modify_pattern_length);
1838 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1839 : : "Number of MODIFY_FIELD actions exceeds maximum "
1840 : : "supported limit of actions");
1841 : : }
1842 : : return 0;
1843 : : }
1844 : :
1845 : : static int
1846 : 0 : flow_hw_represented_port_compile(struct rte_eth_dev *dev,
1847 : : const struct rte_flow_attr *attr,
1848 : : const struct rte_flow_action *action,
1849 : : const struct rte_flow_action *action_mask,
1850 : : struct mlx5_hw_actions *acts,
1851 : : uint16_t action_src, uint16_t action_dst,
1852 : : struct rte_flow_error *error)
1853 : : {
1854 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1855 : 0 : const struct rte_flow_action_ethdev *v = action->conf;
1856 : 0 : const struct rte_flow_action_ethdev *m = action_mask->conf;
1857 : : int ret;
1858 : :
1859 [ # # ]: 0 : if (!attr->group)
1860 : 0 : return rte_flow_error_set(error, EINVAL,
1861 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1862 : : "represented_port action cannot"
1863 : : " be used on group 0");
1864 [ # # ]: 0 : if (!attr->transfer)
1865 : 0 : return rte_flow_error_set(error, EINVAL,
1866 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1867 : : NULL,
1868 : : "represented_port action requires"
1869 : : " transfer attribute");
1870 [ # # ]: 0 : if (attr->ingress || attr->egress)
1871 : 0 : return rte_flow_error_set(error, EINVAL,
1872 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1873 : : "represented_port action cannot"
1874 : : " be used with direction attributes");
1875 [ # # ]: 0 : if (!priv->master)
1876 : 0 : return rte_flow_error_set(error, EINVAL,
1877 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1878 : : "represented_port action must"
1879 : : " be used on proxy port");
1880 [ # # # # ]: 0 : if (m && !!m->port_id) {
1881 : : struct mlx5_priv *port_priv;
1882 : :
1883 [ # # ]: 0 : if (!v)
1884 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1885 : : action, "port index was not provided");
1886 : 0 : port_priv = mlx5_port_to_eswitch_info(v->port_id, false);
1887 [ # # ]: 0 : if (port_priv == NULL)
1888 : 0 : return rte_flow_error_set
1889 : : (error, EINVAL,
1890 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1891 : : "port does not exist or unable to"
1892 : : " obtain E-Switch info for port");
1893 : : MLX5_ASSERT(priv->hw_vport != NULL);
1894 [ # # ]: 0 : if (priv->hw_vport[v->port_id]) {
1895 : 0 : acts->rule_acts[action_dst].action =
1896 : : priv->hw_vport[v->port_id];
1897 : : } else {
1898 : 0 : return rte_flow_error_set
1899 : : (error, EINVAL,
1900 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1901 : : "cannot use represented_port action"
1902 : : " with this port");
1903 : : }
1904 : : } else {
1905 : : ret = __flow_hw_act_data_general_append
1906 : 0 : (priv, acts, action->type,
1907 : : action_src, action_dst);
1908 : : if (ret)
1909 : 0 : return rte_flow_error_set
1910 : : (error, ENOMEM,
1911 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1912 : : "not enough memory to store"
1913 : : " vport action");
1914 : : }
1915 : : return 0;
1916 : : }
1917 : :
1918 : : static __rte_always_inline int
1919 : : flow_hw_cnt_compile(struct rte_eth_dev *dev, uint32_t start_pos,
1920 : : struct mlx5_hw_actions *acts, bool is_root)
1921 : : {
1922 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1923 : : uint32_t pos = start_pos;
1924 : : cnt_id_t cnt_id;
1925 : : int ret;
1926 : :
1927 : 0 : ret = mlx5_hws_cnt_shared_get(priv->hws_cpool, &cnt_id, 0);
1928 : : if (ret != 0)
1929 : : return ret;
1930 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
1931 : : (priv->hws_cpool,
1932 : : cnt_id,
1933 : : &acts->rule_acts[pos].action,
1934 : : &acts->rule_acts[pos].counter.offset,
1935 : : is_root);
1936 : : if (ret != 0)
1937 : : return ret;
1938 : 0 : acts->cnt_id = cnt_id;
1939 : : return 0;
1940 : : }
1941 : :
1942 : : static __rte_always_inline bool
1943 : : is_of_vlan_pcp_present(const struct rte_flow_action *actions)
1944 : : {
1945 : : /*
1946 : : * Order of RTE VLAN push actions is
1947 : : * OF_PUSH_VLAN / OF_SET_VLAN_VID [ / OF_SET_VLAN_PCP ]
1948 : : */
1949 : 0 : return actions[MLX5_HW_VLAN_PUSH_PCP_IDX].type ==
1950 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP;
1951 : : }
1952 : :
1953 : : static __rte_always_inline bool
1954 : : is_template_masked_push_vlan(const struct rte_flow_action_of_push_vlan *mask)
1955 : : {
1956 : : /*
1957 : : * In masked push VLAN template all RTE push actions are masked.
1958 : : */
1959 [ # # ]: 0 : return mask && mask->ethertype != 0;
1960 : : }
1961 : :
1962 : 0 : static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
1963 : : {
1964 : : /*
1965 : : * OpenFlow Switch Specification defines 801.1q VID as 12+1 bits.
1966 : : */
1967 : : rte_be32_t type, vid, pcp;
1968 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1969 : : rte_be32_t vid_lo, vid_hi;
1970 : : #endif
1971 : :
1972 : 0 : type = ((const struct rte_flow_action_of_push_vlan *)
1973 : 0 : actions[MLX5_HW_VLAN_PUSH_TYPE_IDX].conf)->ethertype;
1974 : 0 : vid = ((const struct rte_flow_action_of_set_vlan_vid *)
1975 : 0 : actions[MLX5_HW_VLAN_PUSH_VID_IDX].conf)->vlan_vid;
1976 : : pcp = is_of_vlan_pcp_present(actions) ?
1977 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
1978 [ # # ]: 0 : actions[MLX5_HW_VLAN_PUSH_PCP_IDX].conf)->vlan_pcp : 0;
1979 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1980 : 0 : vid_hi = vid & 0xff;
1981 : : vid_lo = vid >> 8;
1982 : 0 : return (((vid_lo << 8) | (pcp << 5) | vid_hi) << 16) | type;
1983 : : #else
1984 : : return (type << 16) | (pcp << 13) | vid;
1985 : : #endif
1986 : : }
1987 : :
1988 : : static __rte_always_inline int
1989 : : flow_hw_meter_mark_alloc(struct rte_eth_dev *dev, uint32_t queue,
1990 : : const struct rte_flow_action *action,
1991 : : struct mlx5_hw_q_job *job, bool push,
1992 : : struct mlx5_aso_mtr **aso_mtr,
1993 : : struct rte_flow_error *error)
1994 : : {
1995 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1996 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
1997 : 0 : const struct rte_flow_action_meter_mark *meter_mark = action->conf;
1998 : : struct mlx5_flow_meter_info *fm;
1999 : 0 : uint32_t mtr_id = 0;
2000 : : uintptr_t handle = (uintptr_t)MLX5_INDIRECT_ACTION_TYPE_METER_MARK <<
2001 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET;
2002 : :
2003 : 0 : if (priv->shared_host)
2004 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2005 : : "Meter mark actions can only be created on the host port");
2006 : : MLX5_ASSERT(aso_mtr);
2007 [ # # # # : 0 : if (meter_mark->profile == NULL)
# # # # #
# # # #
# ]
2008 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2009 : : "No Meter mark profile");
2010 : :
2011 : 0 : *aso_mtr = mlx5_ipool_malloc(pool->idx_pool, &mtr_id);
2012 [ # # # # : 0 : if (!*aso_mtr) {
# # # # #
# # # #
# ]
2013 [ # # # # : 0 : if (mtr_id)
# # # # #
# # # #
# ]
2014 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
2015 : 0 : return rte_flow_error_set(error, ENOMEM,
2016 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2017 : : NULL,
2018 : : "failed to allocate aso meter entry");
2019 : : }
2020 : : /* Fill the flow meter parameters. */
2021 : 0 : (*aso_mtr)->type = ASO_METER_INDIRECT;
2022 : : fm = &(*aso_mtr)->fm;
2023 : 0 : fm->meter_id = mtr_id;
2024 : 0 : fm->profile = (struct mlx5_flow_meter_profile *)(meter_mark->profile);
2025 : 0 : fm->is_enable = meter_mark->state;
2026 : 0 : fm->color_aware = meter_mark->color_mode;
2027 : 0 : (*aso_mtr)->pool = pool;
2028 [ # # ]: 0 : (*aso_mtr)->state = (queue == MLX5_HW_INV_QUEUE) ?
2029 : : ASO_METER_WAIT : ASO_METER_WAIT_ASYNC;
2030 : 0 : (*aso_mtr)->offset = mtr_id - 1;
2031 [ # # # # : 0 : (*aso_mtr)->init_color = fm->color_aware ? RTE_COLORS : RTE_COLOR_GREEN;
# # # # #
# # # #
# ]
2032 : 0 : job->action = (void *)(handle | mtr_id);
2033 : : /* Update ASO flow meter by wqe. */
2034 [ # # # # : 0 : if (mlx5_aso_meter_update_by_wqe(priv, queue, *aso_mtr,
# # # # #
# # # #
# ]
2035 : : &priv->mtr_bulk, job, push)) {
2036 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
2037 : 0 : return rte_flow_error_set(error, EBUSY,
2038 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2039 : : NULL,
2040 : : "Failed to enqueue ASO meter update");
2041 : : }
2042 : : /* Wait for ASO object completion. */
2043 [ # # # # : 0 : if (queue == MLX5_HW_INV_QUEUE &&
# # # # #
# # # # #
# # ]
2044 : 0 : mlx5_aso_mtr_wait(priv, *aso_mtr, true)) {
2045 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
2046 : : return -EIO;
2047 : : }
2048 : : return 0;
2049 : : }
2050 : :
2051 : : static __rte_always_inline int
2052 : : flow_hw_meter_mark_compile(struct rte_eth_dev *dev,
2053 : : uint16_t aso_mtr_pos,
2054 : : const struct rte_flow_action *action,
2055 : : struct mlx5dr_rule_action *acts,
2056 : : uint32_t *index,
2057 : : uint32_t queue,
2058 : : struct rte_flow_error *error)
2059 : : {
2060 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2061 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
2062 : : struct mlx5_aso_mtr *aso_mtr = NULL;
2063 : : struct mlx5_hw_q_job *job =
2064 : : flow_hw_action_job_init(priv, queue, NULL, NULL, NULL,
2065 : : MLX5_HW_Q_JOB_TYPE_CREATE,
2066 : : MLX5_HW_INDIRECT_TYPE_LEGACY, NULL);
2067 : : int ret;
2068 : :
2069 : : if (!job)
2070 : : return -1;
2071 : : ret = flow_hw_meter_mark_alloc(dev, queue, action, job, true, &aso_mtr, error);
2072 [ # # # # : 0 : if (ret) {
# # # # #
# # # ]
2073 [ # # # # : 0 : if (ret != -EIO) {
# # # # #
# # # ]
2074 : : if (queue == MLX5_HW_INV_QUEUE)
2075 : 0 : queue = CTRL_QUEUE_ID(priv);
2076 : : flow_hw_job_put(priv, job, queue);
2077 : : }
2078 : : return -1;
2079 : : }
2080 : :
2081 : : /* Compile METER_MARK action */
2082 : 0 : acts[aso_mtr_pos].action = pool->action;
2083 : 0 : acts[aso_mtr_pos].aso_meter.offset = aso_mtr->offset;
2084 : 0 : *index = aso_mtr->fm.meter_id;
2085 : : return 0;
2086 : : }
2087 : :
2088 : : static int
2089 : 0 : flow_hw_translate_indirect_mirror(__rte_unused struct rte_eth_dev *dev,
2090 : : __rte_unused const struct mlx5_action_construct_data *act_data,
2091 : : const struct rte_flow_action *action,
2092 : : struct mlx5dr_rule_action *dr_rule)
2093 : : {
2094 : 0 : const struct rte_flow_action_indirect_list *list_conf = action->conf;
2095 : 0 : const struct mlx5_mirror *mirror = (typeof(mirror))list_conf->handle;
2096 : :
2097 : 0 : dr_rule->action = mirror->mirror_action;
2098 : 0 : return 0;
2099 : : }
2100 : :
2101 : : /**
2102 : : * HWS mirror implemented as FW island.
2103 : : * The action does not support indirect list flow configuration.
2104 : : * If template handle was masked, use handle mirror action in flow rules.
2105 : : * Otherwise let flow rule specify mirror handle.
2106 : : */
2107 : : static int
2108 : 0 : hws_table_tmpl_translate_indirect_mirror(struct rte_eth_dev *dev,
2109 : : const struct rte_flow_action *action,
2110 : : const struct rte_flow_action *mask,
2111 : : struct mlx5_hw_actions *acts,
2112 : : uint16_t action_src, uint16_t action_dst)
2113 : : {
2114 : : int ret = 0;
2115 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
2116 : :
2117 [ # # # # ]: 0 : if (mask_conf && mask_conf->handle) {
2118 : : /**
2119 : : * If mirror handle was masked, assign fixed DR5 mirror action.
2120 : : */
2121 : : flow_hw_translate_indirect_mirror(dev, NULL, action,
2122 : 0 : &acts->rule_acts[action_dst]);
2123 : : } else {
2124 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2125 : : ret = flow_hw_act_data_indirect_list_append
2126 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
2127 : : action_src, action_dst,
2128 : : flow_hw_translate_indirect_mirror);
2129 : : }
2130 : :
2131 : 0 : return ret;
2132 : : }
2133 : :
2134 : : static int
2135 : 0 : flow_hw_reformat_action(__rte_unused struct rte_eth_dev *dev,
2136 : : __rte_unused const struct mlx5_action_construct_data *data,
2137 : : const struct rte_flow_action *action,
2138 : : struct mlx5dr_rule_action *dr_rule)
2139 : : {
2140 : 0 : const struct rte_flow_action_indirect_list *indlst_conf = action->conf;
2141 : :
2142 : 0 : dr_rule->action = ((struct mlx5_hw_encap_decap_action *)
2143 : 0 : (indlst_conf->handle))->action;
2144 [ # # ]: 0 : if (!dr_rule->action)
2145 : 0 : return -EINVAL;
2146 : : return 0;
2147 : : }
2148 : :
2149 : : /**
2150 : : * Template conf must not be masked. If handle is masked, use the one in template,
2151 : : * otherwise update per flow rule.
2152 : : */
2153 : : static int
2154 : 0 : hws_table_tmpl_translate_indirect_reformat(struct rte_eth_dev *dev,
2155 : : const struct rte_flow_action *action,
2156 : : const struct rte_flow_action *mask,
2157 : : struct mlx5_hw_actions *acts,
2158 : : uint16_t action_src, uint16_t action_dst)
2159 : : {
2160 : : int ret = -1;
2161 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
2162 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2163 : :
2164 [ # # # # : 0 : if (mask_conf && mask_conf->handle && !mask_conf->conf)
# # ]
2165 : : /**
2166 : : * If handle was masked, assign fixed DR action.
2167 : : */
2168 : : ret = flow_hw_reformat_action(dev, NULL, action,
2169 [ # # ]: 0 : &acts->rule_acts[action_dst]);
2170 [ # # # # : 0 : else if (mask_conf && !mask_conf->handle && !mask_conf->conf)
# # ]
2171 : : ret = flow_hw_act_data_indirect_list_append
2172 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
2173 : : action_src, action_dst, flow_hw_reformat_action);
2174 : 0 : return ret;
2175 : : }
2176 : :
2177 : : static int
2178 : 0 : flow_dr_set_meter(struct mlx5_priv *priv,
2179 : : struct mlx5dr_rule_action *dr_rule,
2180 : : const struct rte_flow_action_indirect_list *action_conf)
2181 : : {
2182 : 0 : const struct mlx5_indlst_legacy *legacy_obj =
2183 : : (typeof(legacy_obj))action_conf->handle;
2184 : 0 : struct mlx5_aso_mtr_pool *mtr_pool = priv->hws_mpool;
2185 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)legacy_obj->handle;
2186 : 0 : uint32_t mtr_id = act_idx & (RTE_BIT32(MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
2187 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_ipool_get(mtr_pool->idx_pool, mtr_id);
2188 : :
2189 [ # # ]: 0 : if (!aso_mtr)
2190 : : return -EINVAL;
2191 : 0 : dr_rule->action = mtr_pool->action;
2192 : 0 : dr_rule->aso_meter.offset = aso_mtr->offset;
2193 : 0 : return 0;
2194 : : }
2195 : :
2196 : : __rte_always_inline static void
2197 : : flow_dr_mtr_flow_color(struct mlx5dr_rule_action *dr_rule, enum rte_color init_color)
2198 : : {
2199 : 0 : dr_rule->aso_meter.init_color =
2200 : 0 : (enum mlx5dr_action_aso_meter_color)rte_col_2_mlx5_col(init_color);
2201 : 0 : }
2202 : :
2203 : : static int
2204 : 0 : flow_hw_translate_indirect_meter(struct rte_eth_dev *dev,
2205 : : const struct mlx5_action_construct_data *act_data,
2206 : : const struct rte_flow_action *action,
2207 : : struct mlx5dr_rule_action *dr_rule)
2208 : : {
2209 : : int ret;
2210 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2211 : 0 : const struct rte_flow_action_indirect_list *action_conf = action->conf;
2212 : 0 : const struct rte_flow_indirect_update_flow_meter_mark **flow_conf =
2213 : : (typeof(flow_conf))action_conf->conf;
2214 : :
2215 : 0 : ret = flow_dr_set_meter(priv, dr_rule, action_conf);
2216 [ # # ]: 0 : if (ret)
2217 : : return ret;
2218 [ # # ]: 0 : if (!act_data->shared_meter.conf_masked) {
2219 [ # # # # : 0 : if (flow_conf && flow_conf[0] && flow_conf[0]->init_color < RTE_COLORS)
# # ]
2220 : : flow_dr_mtr_flow_color(dr_rule, flow_conf[0]->init_color);
2221 : : }
2222 : : return 0;
2223 : : }
2224 : :
2225 : : static int
2226 : 0 : hws_table_tmpl_translate_indirect_meter(struct rte_eth_dev *dev,
2227 : : const struct rte_flow_action *action,
2228 : : const struct rte_flow_action *mask,
2229 : : struct mlx5_hw_actions *acts,
2230 : : uint16_t action_src, uint16_t action_dst)
2231 : : {
2232 : : int ret;
2233 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2234 : 0 : const struct rte_flow_action_indirect_list *action_conf = action->conf;
2235 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
2236 [ # # # # ]: 0 : bool is_handle_masked = mask_conf && mask_conf->handle;
2237 [ # # # # : 0 : bool is_conf_masked = mask_conf && mask_conf->conf && mask_conf->conf[0];
# # ]
2238 : 0 : struct mlx5dr_rule_action *dr_rule = &acts->rule_acts[action_dst];
2239 : :
2240 [ # # ]: 0 : if (is_handle_masked) {
2241 : 0 : ret = flow_dr_set_meter(priv, dr_rule, action->conf);
2242 [ # # ]: 0 : if (ret)
2243 : : return ret;
2244 : : }
2245 [ # # ]: 0 : if (is_conf_masked) {
2246 : : const struct
2247 : 0 : rte_flow_indirect_update_flow_meter_mark **flow_conf =
2248 : : (typeof(flow_conf))action_conf->conf;
2249 : : flow_dr_mtr_flow_color(dr_rule,
2250 [ # # ]: 0 : flow_conf[0]->init_color);
2251 : : }
2252 [ # # ]: 0 : if (!is_handle_masked || !is_conf_masked) {
2253 : : struct mlx5_action_construct_data *act_data;
2254 : :
2255 : : ret = flow_hw_act_data_indirect_list_append
2256 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
2257 : : action_src, action_dst, flow_hw_translate_indirect_meter);
2258 : : if (ret)
2259 : 0 : return ret;
2260 : : act_data = LIST_FIRST(&acts->act_list);
2261 : 0 : act_data->shared_meter.conf_masked = is_conf_masked;
2262 : : }
2263 : : return 0;
2264 : : }
2265 : :
2266 : : static int
2267 : : hws_table_tmpl_translate_indirect_legacy(struct rte_eth_dev *dev,
2268 : : const struct rte_flow_action *action,
2269 : : const struct rte_flow_action *mask,
2270 : : struct mlx5_hw_actions *acts,
2271 : : uint16_t action_src, uint16_t action_dst)
2272 : : {
2273 : : int ret;
2274 : : const struct rte_flow_action_indirect_list *indlst_conf = action->conf;
2275 : : struct mlx5_indlst_legacy *indlst_obj = (typeof(indlst_obj))indlst_conf->handle;
2276 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)indlst_obj->handle;
2277 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
2278 : :
2279 : 0 : switch (type) {
2280 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
2281 : 0 : ret = hws_table_tmpl_translate_indirect_meter(dev, action, mask,
2282 : : acts, action_src,
2283 : : action_dst);
2284 : 0 : break;
2285 : : default:
2286 : : ret = -EINVAL;
2287 : : break;
2288 : : }
2289 : : return ret;
2290 : : }
2291 : :
2292 : : /*
2293 : : * template .. indirect_list handle Ht conf Ct ..
2294 : : * mask .. indirect_list handle Hm conf Cm ..
2295 : : *
2296 : : * PMD requires Ht != 0 to resolve handle type.
2297 : : * If Ht was masked (Hm != 0) DR5 action will be set according to Ht and will
2298 : : * not change. Otherwise, DR5 action will be resolved during flow rule build.
2299 : : * If Ct was masked (Cm != 0), table template processing updates base
2300 : : * indirect action configuration with Ct parameters.
2301 : : */
2302 : : static int
2303 : 0 : table_template_translate_indirect_list(struct rte_eth_dev *dev,
2304 : : const struct rte_flow_action *action,
2305 : : const struct rte_flow_action *mask,
2306 : : struct mlx5_hw_actions *acts,
2307 : : uint16_t action_src, uint16_t action_dst)
2308 : : {
2309 : : int ret = 0;
2310 : : enum mlx5_indirect_list_type type;
2311 : 0 : const struct rte_flow_action_indirect_list *list_conf = action->conf;
2312 : :
2313 [ # # # # ]: 0 : if (!list_conf || !list_conf->handle)
2314 : : return -EINVAL;
2315 : : type = mlx5_get_indirect_list_type(list_conf->handle);
2316 [ # # # # ]: 0 : switch (type) {
2317 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
2318 [ # # ]: 0 : ret = hws_table_tmpl_translate_indirect_legacy(dev, action, mask,
2319 : : acts, action_src,
2320 : : action_dst);
2321 : : break;
2322 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
2323 : 0 : ret = hws_table_tmpl_translate_indirect_mirror(dev, action, mask,
2324 : : acts, action_src,
2325 : : action_dst);
2326 : 0 : break;
2327 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
2328 [ # # ]: 0 : if (list_conf->conf)
2329 : : return -EINVAL;
2330 : 0 : ret = hws_table_tmpl_translate_indirect_reformat(dev, action, mask,
2331 : : acts, action_src,
2332 : : action_dst);
2333 : 0 : break;
2334 : : default:
2335 : : return -EINVAL;
2336 : : }
2337 : : return ret;
2338 : : }
2339 : :
2340 : : /**
2341 : : * Translate given encap action and mask to raw tunnel header buffer.
2342 : : *
2343 : : * @param[in] action
2344 : : * Pointer to encap action.
2345 : : * @param[in] mask
2346 : : * Pointer to encap action's mask.
2347 : : * @param[out] conf_encap_data
2348 : : * Buffer where tunnel header will be written.
2349 : : * @param[out] data_size
2350 : : * Pointer to tunnel header size.
2351 : : * @param[out] error
2352 : : * Pointer to error structure.
2353 : : *
2354 : : * @return
2355 : : * 0 or greater if translation was successful.
2356 : : * Negative errno value otherwise.
2357 : : *
2358 : : * If returned value is 0, then action is not shared in the actions template
2359 : : * If bigger than 0, then it is shared.
2360 : : */
2361 : : static int
2362 : 0 : translate_l2_encap_action(const struct rte_flow_action *action,
2363 : : const struct rte_flow_action *mask,
2364 : : uint8_t conf_encap_data[MLX5_ENCAP_MAX_LEN],
2365 : : size_t *data_size,
2366 : : struct rte_flow_error *error)
2367 : : {
2368 : : struct rte_flow_item *conf_item;
2369 : : int ret;
2370 : :
2371 [ # # ]: 0 : if (action->conf == NULL)
2372 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2373 : : "Missing VXLAN/NVGRE encap action configuration");
2374 : :
2375 : : /* Only these 2 action types receive encap data as flow item pattern. */
2376 : : MLX5_ASSERT(action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ||
2377 : : action->type == RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP);
2378 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
2379 : 0 : conf_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_vxlan_encap, action->conf);
2380 : : else
2381 : 0 : conf_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_nvgre_encap, action->conf);
2382 [ # # ]: 0 : if (conf_item == NULL)
2383 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2384 : : "Missing VXLAN/NVGRE tunnel definition in action config");
2385 : :
2386 : 0 : ret = mlx5_flow_dv_convert_encap_data(conf_item, conf_encap_data, data_size, error);
2387 [ # # ]: 0 : if (ret < 0)
2388 : : return ret;
2389 : :
2390 : : /* If mask is provided, then action is shared */
2391 : 0 : return mask->conf != NULL;
2392 : : }
2393 : :
2394 : : static void
2395 : : mlx5_set_reformat_header(struct mlx5dr_action_reformat_header *hdr,
2396 : : uint8_t *encap_data,
2397 : : size_t data_size)
2398 : : {
2399 : 0 : hdr->sz = data_size;
2400 : 0 : hdr->data = encap_data;
2401 : : }
2402 : :
2403 : : static int
2404 [ # # ]: 0 : mlx5_tbl_translate_reformat(struct mlx5_priv *priv,
2405 : : struct mlx5_hw_actions *acts,
2406 : : struct rte_flow_actions_template *at,
2407 : : uint8_t *encap_data, uint8_t *encap_data_m,
2408 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
2409 : : size_t data_size, uint16_t reformat_src,
2410 : : enum mlx5dr_action_type refmt_type,
2411 : : struct rte_flow_error *error)
2412 : : {
2413 : : int mp_reformat_ix = mlx5_multi_pattern_reformat_to_index(refmt_type);
2414 : : struct mlx5dr_action_reformat_header hdr;
2415 : : bool shared_rfmt = false;
2416 : : int ret;
2417 : :
2418 : : MLX5_ASSERT(at->reformat_off != UINT16_MAX);
2419 [ # # ]: 0 : if (encap_data && encap_data_m)
2420 : : shared_rfmt = true;
2421 : 0 : acts->encap_decap = mlx5_malloc(MLX5_MEM_ZERO,
2422 : : sizeof(*acts->encap_decap) + data_size,
2423 : : 0, SOCKET_ID_ANY);
2424 [ # # ]: 0 : if (!acts->encap_decap)
2425 : 0 : return rte_flow_error_set(error, ENOMEM,
2426 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2427 : : NULL, "no memory for reformat context");
2428 : 0 : acts->encap_decap_pos = at->reformat_off;
2429 : 0 : acts->encap_decap->data_size = data_size;
2430 : 0 : acts->encap_decap->action_type = refmt_type;
2431 [ # # ]: 0 : if (shared_rfmt || mp_reformat_ix < 0) {
2432 : : uint16_t reformat_ix = at->reformat_off;
2433 : : /*
2434 : : * This copy is only needed in non template mode.
2435 : : * In order to create the action later.
2436 : : */
2437 : 0 : memcpy(acts->encap_decap->data, encap_data, data_size);
2438 : 0 : acts->rule_acts[reformat_ix].reformat.data = acts->encap_decap->data;
2439 : 0 : acts->rule_acts[reformat_ix].reformat.offset = 0;
2440 : 0 : acts->encap_decap->shared = true;
2441 : : } else {
2442 : : uint32_t ix;
2443 : 0 : typeof(mp_ctx->reformat[0]) *reformat = mp_ctx->reformat +
2444 : : mp_reformat_ix;
2445 : : mlx5_set_reformat_header(&hdr, encap_data, data_size);
2446 : 0 : ix = reformat->elements_num++;
2447 : 0 : reformat->reformat_hdr[ix] = hdr;
2448 : 0 : acts->rule_acts[at->reformat_off].reformat.hdr_idx = ix;
2449 : 0 : acts->encap_decap->multi_pattern = 1;
2450 : 0 : ret = __flow_hw_act_data_encap_append
2451 : 0 : (priv, acts, (at->actions + reformat_src)->type,
2452 : : reformat_src, at->reformat_off, data_size);
2453 : : if (ret)
2454 : 0 : return -rte_errno;
2455 : : mlx5_multi_pattern_activate(mp_ctx);
2456 : : }
2457 : : return 0;
2458 : : }
2459 : :
2460 : : static int
2461 : 0 : mlx5_tbl_create_reformat_action(struct mlx5_priv *priv,
2462 : : const struct rte_flow_template_table_attr *table_attr,
2463 : : struct mlx5_hw_actions *acts,
2464 : : struct rte_flow_actions_template *at,
2465 : : uint8_t *encap_data,
2466 : : size_t data_size,
2467 : : enum mlx5dr_action_type refmt_type)
2468 : : {
2469 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2470 : : bool unified_fdb = is_unified_fdb(priv);
2471 : 0 : enum mlx5dr_table_type tbl_type = get_mlx5dr_table_type(attr, table_attr->specialize,
2472 : : unified_fdb);
2473 : : struct mlx5dr_action_reformat_header hdr;
2474 : :
2475 : : mlx5_set_reformat_header(&hdr, encap_data, data_size);
2476 : 0 : uint16_t reformat_ix = at->reformat_off;
2477 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][tbl_type] |
2478 : : MLX5DR_ACTION_FLAG_SHARED;
2479 : :
2480 : 0 : acts->encap_decap->action = mlx5dr_action_create_reformat(priv->dr_ctx, refmt_type,
2481 : : 1, &hdr, 0, flags);
2482 [ # # ]: 0 : if (!acts->encap_decap->action)
2483 : 0 : return -rte_errno;
2484 : 0 : acts->rule_acts[reformat_ix].action = acts->encap_decap->action;
2485 : 0 : return 0;
2486 : : }
2487 : :
2488 : : static int
2489 : 0 : mlx5_tbl_translate_modify_header(struct rte_eth_dev *dev,
2490 : : const struct mlx5_flow_template_table_cfg *cfg,
2491 : : struct mlx5_hw_actions *acts,
2492 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
2493 : : struct mlx5_hw_modify_header_action *mhdr,
2494 : : struct rte_flow_error *error)
2495 : : {
2496 : 0 : uint16_t mhdr_ix = mhdr->pos;
2497 : : struct mlx5dr_action_mh_pattern pattern = {
2498 : 0 : .sz = sizeof(struct mlx5_modification_cmd) * mhdr->mhdr_cmds_num
2499 : : };
2500 : :
2501 : 0 : int ret = flow_hw_validate_compiled_modify_field(dev, cfg, mhdr, error);
2502 [ # # ]: 0 : if (ret) {
2503 : : __flow_hw_action_template_destroy(dev, acts);
2504 : 0 : return ret;
2505 : : }
2506 : 0 : acts->mhdr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*acts->mhdr),
2507 : : 0, SOCKET_ID_ANY);
2508 [ # # ]: 0 : if (!acts->mhdr)
2509 : 0 : return rte_flow_error_set(error, ENOMEM,
2510 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2511 : : NULL, "translate modify_header: no memory for modify header context");
2512 : : rte_memcpy(acts->mhdr, mhdr, sizeof(*mhdr));
2513 [ # # ]: 0 : if (!mhdr->shared) {
2514 : 0 : pattern.data = (rte_be64_t *)acts->mhdr->mhdr_cmds;
2515 : : typeof(mp_ctx->mh) *mh = &mp_ctx->mh;
2516 : 0 : uint32_t idx = mh->elements_num;
2517 : 0 : mh->pattern[mh->elements_num++] = pattern;
2518 : 0 : acts->mhdr->multi_pattern = 1;
2519 : 0 : acts->rule_acts[mhdr_ix].modify_header.pattern_idx = idx;
2520 : : mlx5_multi_pattern_activate(mp_ctx);
2521 : : }
2522 : : return 0;
2523 : : }
2524 : :
2525 : : static int
2526 : 0 : mlx5_tbl_ensure_shared_modify_header(struct rte_eth_dev *dev,
2527 : : const struct mlx5_flow_template_table_cfg *cfg,
2528 : : struct mlx5_hw_actions *acts,
2529 : : struct rte_flow_error *error)
2530 : : {
2531 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2532 : : bool unified_fdb = is_unified_fdb(priv);
2533 : : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2534 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2535 : 0 : enum mlx5dr_table_type tbl_type = get_mlx5dr_table_type(attr, table_attr->specialize,
2536 : : unified_fdb);
2537 : : struct mlx5dr_action_mh_pattern pattern;
2538 : :
2539 [ # # ]: 0 : if (!acts->mhdr)
2540 : 0 : return rte_flow_error_set(error, EINVAL,
2541 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2542 : : "translate modify_header: mhdr is NULL");
2543 : :
2544 : 0 : pattern.sz = sizeof(struct mlx5_modification_cmd) * acts->mhdr->mhdr_cmds_num;
2545 : 0 : uint16_t mhdr_ix = acts->mhdr->pos;
2546 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][tbl_type] | MLX5DR_ACTION_FLAG_SHARED;
2547 : :
2548 : 0 : pattern.data = (rte_be64_t *)acts->mhdr->mhdr_cmds;
2549 : 0 : acts->mhdr->action = mlx5dr_action_create_modify_header(priv->dr_ctx, 1,
2550 : : &pattern, 0, flags);
2551 [ # # ]: 0 : if (!acts->mhdr->action)
2552 : 0 : return rte_flow_error_set(error, rte_errno,
2553 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2554 : : "translate modify_header: failed to create DR action");
2555 : 0 : acts->rule_acts[mhdr_ix].action = acts->mhdr->action;
2556 : 0 : return 0;
2557 : : }
2558 : :
2559 : : static int
2560 : 0 : mlx5_create_ipv6_ext_reformat(struct rte_eth_dev *dev,
2561 : : const struct mlx5_flow_template_table_cfg *cfg,
2562 : : struct mlx5_hw_actions *acts,
2563 : : struct rte_flow_actions_template *at,
2564 : : uint8_t *push_data, uint8_t *push_data_m,
2565 : : size_t push_size, uint16_t recom_src,
2566 : : enum mlx5dr_action_type recom_type)
2567 : : {
2568 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2569 : : bool unified_fdb = is_unified_fdb(priv);
2570 : : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2571 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2572 : : enum mlx5dr_table_type type =
2573 : 0 : get_mlx5dr_table_type(attr, table_attr->specialize, unified_fdb);
2574 : : struct mlx5_action_construct_data *act_data;
2575 : 0 : struct mlx5dr_action_reformat_header hdr = {0};
2576 : : uint32_t flag, bulk = 0;
2577 : :
2578 : 0 : flag = mlx5_hw_act_flag[!!attr->group][type];
2579 : 0 : acts->push_remove = mlx5_malloc(MLX5_MEM_ZERO,
2580 : : sizeof(*acts->push_remove) + push_size,
2581 : : 0, SOCKET_ID_ANY);
2582 [ # # ]: 0 : if (!acts->push_remove)
2583 : : return -ENOMEM;
2584 : :
2585 [ # # # ]: 0 : switch (recom_type) {
2586 : 0 : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
2587 [ # # ]: 0 : if (!push_data || !push_size)
2588 : 0 : goto err1;
2589 [ # # ]: 0 : if (!push_data_m) {
2590 [ # # ]: 0 : bulk = rte_log2_u32(table_attr->nb_flows);
2591 : : } else {
2592 : 0 : flag |= MLX5DR_ACTION_FLAG_SHARED;
2593 : 0 : acts->push_remove->shared = 1;
2594 : : }
2595 : 0 : acts->push_remove->data_size = push_size;
2596 : 0 : memcpy(acts->push_remove->data, push_data, push_size);
2597 : 0 : hdr.data = push_data;
2598 : 0 : hdr.sz = push_size;
2599 : 0 : break;
2600 : 0 : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
2601 : 0 : flag |= MLX5DR_ACTION_FLAG_SHARED;
2602 : 0 : acts->push_remove->shared = 1;
2603 : 0 : break;
2604 : : default:
2605 : : break;
2606 : : }
2607 : :
2608 : 0 : acts->push_remove->action =
2609 : 0 : mlx5dr_action_create_reformat_ipv6_ext(priv->dr_ctx,
2610 : : recom_type, &hdr, bulk, flag);
2611 [ # # ]: 0 : if (!acts->push_remove->action)
2612 : 0 : goto err1;
2613 : 0 : acts->rule_acts[at->recom_off].action = acts->push_remove->action;
2614 : 0 : acts->rule_acts[at->recom_off].ipv6_ext.header = acts->push_remove->data;
2615 : 0 : acts->rule_acts[at->recom_off].ipv6_ext.offset = 0;
2616 : 0 : acts->push_remove_pos = at->recom_off;
2617 [ # # ]: 0 : if (!acts->push_remove->shared) {
2618 : 0 : act_data = __flow_hw_act_data_push_append(dev, acts,
2619 : : RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH,
2620 : : recom_src, at->recom_off, push_size);
2621 : : if (!act_data)
2622 : 0 : goto err;
2623 : : }
2624 : : return 0;
2625 : : err:
2626 [ # # ]: 0 : if (acts->push_remove->action)
2627 : 0 : mlx5dr_action_destroy(acts->push_remove->action);
2628 : 0 : err1:
2629 [ # # ]: 0 : if (acts->push_remove) {
2630 : 0 : mlx5_free(acts->push_remove);
2631 : 0 : acts->push_remove = NULL;
2632 : : }
2633 : : return -EINVAL;
2634 : : }
2635 : :
2636 : : static bool
2637 : : is_indirect_action_type_supported_root(const enum rte_flow_action_type type)
2638 : : {
2639 : : switch (type) {
2640 : : case RTE_FLOW_ACTION_TYPE_COUNT:
2641 : : case RTE_FLOW_ACTION_TYPE_AGE:
2642 : : return mlx5dr_action_counter_root_is_supported();
2643 : : default:
2644 : : return false;
2645 : : }
2646 : : }
2647 : :
2648 : : /**
2649 : : * Translate rte_flow actions to DR action.
2650 : : *
2651 : : * As the action template has already indicated the actions. Translate
2652 : : * the rte_flow actions to DR action if possbile. So in flow create
2653 : : * stage we will save cycles from handing the actions' organizing.
2654 : : * For the actions with limited information, need to add these to a
2655 : : * list.
2656 : : *
2657 : : * @param[in] dev
2658 : : * Pointer to the rte_eth_dev structure.
2659 : : * @param[in] cfg
2660 : : * Pointer to the table configuration.
2661 : : * @param[in/out] acts
2662 : : * Pointer to the template HW steering DR actions.
2663 : : * @param[in] at
2664 : : * Action template.
2665 : : * @param[in] nt_mode
2666 : : * Non template rule translate.
2667 : : * @param[out] error
2668 : : * Pointer to error structure.
2669 : : *
2670 : : * @return
2671 : : * 0 on success, a negative errno otherwise and rte_errno is set.
2672 : : */
2673 : : static int
2674 : 0 : __flow_hw_translate_actions_template(struct rte_eth_dev *dev,
2675 : : const struct mlx5_flow_template_table_cfg *cfg,
2676 : : struct mlx5_hw_actions *acts,
2677 : : struct rte_flow_actions_template *at,
2678 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
2679 : : bool nt_mode,
2680 : : struct rte_flow_error *error)
2681 : : {
2682 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2683 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
2684 : 0 : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2685 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2686 : 0 : struct rte_flow_action *actions = at->actions;
2687 : 0 : struct rte_flow_action *masks = at->masks;
2688 : : enum mlx5dr_action_type refmt_type = MLX5DR_ACTION_TYP_LAST;
2689 : : enum mlx5dr_action_type recom_type = MLX5DR_ACTION_TYP_LAST;
2690 : : const struct rte_flow_action_raw_encap *raw_encap_data;
2691 : : const struct rte_flow_action_ipv6_ext_push *ipv6_ext_data;
2692 : : uint16_t reformat_src = 0, recom_src = 0;
2693 : 0 : uint8_t converted_encap_data[MLX5_ENCAP_MAX_LEN] = { 0 };
2694 : : uint8_t *encap_data = NULL, *encap_data_m = NULL;
2695 : : uint8_t *push_data = NULL, *push_data_m = NULL;
2696 : 0 : size_t data_size = 0, push_size = 0;
2697 : : struct mlx5_hw_modify_header_action mhdr = { 0 };
2698 : 0 : struct rte_flow_error sub_error = {
2699 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
2700 : : .cause = NULL,
2701 : : .message = NULL,
2702 : : };
2703 : : bool actions_end = false;
2704 : : uint32_t type;
2705 : : bool reformat_used = false;
2706 : : bool recom_used = false;
2707 : : unsigned int of_vlan_offset;
2708 : : uint32_t ct_idx;
2709 : : int ret, err;
2710 : 0 : bool is_root = mlx5_group_id_is_root(cfg->attr.flow_attr.group);
2711 : : bool unified_fdb = is_unified_fdb(priv);
2712 : : struct mlx5dr_action *dr_action = NULL;
2713 : :
2714 : : flow_hw_modify_field_init(&mhdr, at);
2715 : 0 : type = get_mlx5dr_table_type(attr, cfg->attr.specialize, unified_fdb);
2716 [ # # ]: 0 : for (; !actions_end; actions++, masks++) {
2717 : 0 : uint64_t pos = actions - at->actions;
2718 : 0 : uint16_t src_pos = pos - at->src_off[pos];
2719 : 0 : uint16_t dr_pos = at->dr_off[pos];
2720 : :
2721 [ # # # # : 0 : switch ((int)actions->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2722 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
2723 [ # # ]: 0 : if (is_root) {
2724 : 0 : DRV_LOG(ERR, "Indirect action is not supported in root table.");
2725 : 0 : goto err;
2726 : : }
2727 : 0 : ret = table_template_translate_indirect_list
2728 : : (dev, actions, masks, acts, src_pos, dr_pos);
2729 [ # # ]: 0 : if (ret)
2730 : 0 : goto err;
2731 : : break;
2732 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
2733 [ # # ]: 0 : if (is_root && !is_indirect_action_type_supported_root(masks->type)) {
2734 : 0 : DRV_LOG(ERR, "Indirect action type (%d) is not supported on root.",
2735 : : masks->type);
2736 : 0 : goto err;
2737 : : }
2738 [ # # # # ]: 0 : if (actions->conf && masks->conf) {
2739 [ # # # # : 0 : if (flow_hw_shared_action_translate(dev, actions, acts,
# # # # ]
2740 : : src_pos, dr_pos, &sub_error))
2741 : 0 : goto err;
2742 : 0 : } else if (__flow_hw_act_data_indirect_append
2743 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT,
2744 : : masks->type, src_pos, dr_pos)){
2745 : 0 : goto err;
2746 : : }
2747 : : break;
2748 : : case RTE_FLOW_ACTION_TYPE_VOID:
2749 : : break;
2750 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
2751 : 0 : dr_action = mlx5_hws_global_action_drop_get(priv, type, is_root);
2752 [ # # ]: 0 : if (dr_action == NULL) {
2753 : 0 : DRV_LOG(ERR, "port %u failed to allocate drop action",
2754 : : priv->dev_data->port_id);
2755 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2756 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2757 : : "failed to allocate drop action");
2758 : 0 : goto err;
2759 : : }
2760 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2761 : 0 : break;
2762 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
2763 [ # # ]: 0 : if (is_root) {
2764 : 0 : DRV_LOG(ERR, "Port representor is not supported in root table.");
2765 : 0 : goto err;
2766 : : }
2767 : 0 : dr_action = mlx5_hws_global_action_def_miss_get(priv, type, is_root);
2768 [ # # ]: 0 : if (dr_action == NULL) {
2769 : 0 : DRV_LOG(ERR, "port %u failed to allocate port representor action",
2770 : : priv->dev_data->port_id);
2771 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2772 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2773 : : "failed to allocate port representor action");
2774 : 0 : goto err;
2775 : : }
2776 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2777 : 0 : break;
2778 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
2779 : 0 : dr_action = mlx5_hws_global_action_tag_get(priv, type, is_root);
2780 [ # # ]: 0 : if (dr_action == NULL) {
2781 : 0 : DRV_LOG(ERR, "port %u failed to allocate flag action",
2782 : : priv->dev_data->port_id);
2783 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2784 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2785 : : "failed to allocate flag action");
2786 : 0 : goto err;
2787 : : }
2788 : 0 : acts->mark = true;
2789 : 0 : acts->rule_acts[dr_pos].tag.value =
2790 : : mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
2791 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2792 : 0 : rte_atomic_fetch_add_explicit(&priv->hws_mark_refcnt, 1,
2793 : : rte_memory_order_relaxed);
2794 : 0 : mlx5_flow_hw_rxq_flag_set(dev, true);
2795 : 0 : break;
2796 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
2797 : 0 : dr_action = mlx5_hws_global_action_tag_get(priv, type, is_root);
2798 [ # # ]: 0 : if (dr_action == NULL) {
2799 : 0 : DRV_LOG(ERR, "port %u failed to allocate mark action",
2800 : : priv->dev_data->port_id);
2801 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2802 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2803 : : "failed to allocate mark action");
2804 : 0 : goto err;
2805 : : }
2806 : 0 : acts->mark = true;
2807 [ # # ]: 0 : if (masks->conf &&
2808 : : ((const struct rte_flow_action_mark *)
2809 [ # # ]: 0 : masks->conf)->id)
2810 : 0 : acts->rule_acts[dr_pos].tag.value =
2811 : 0 : mlx5_flow_mark_set
2812 : : (((const struct rte_flow_action_mark *)
2813 : 0 : (actions->conf))->id);
2814 : 0 : else if (__flow_hw_act_data_general_append(priv, acts,
2815 : : actions->type,
2816 : : src_pos, dr_pos))
2817 : 0 : goto err;
2818 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2819 : 0 : rte_atomic_fetch_add_explicit(&priv->hws_mark_refcnt, 1,
2820 : : rte_memory_order_relaxed);
2821 : 0 : mlx5_flow_hw_rxq_flag_set(dev, true);
2822 : 0 : break;
2823 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
2824 : 0 : dr_action = mlx5_hws_global_action_push_vlan_get(priv, type, is_root);
2825 [ # # ]: 0 : if (dr_action == NULL) {
2826 : 0 : DRV_LOG(ERR, "port %u failed to allocate push VLAN action",
2827 : : priv->dev_data->port_id);
2828 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2829 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2830 : : "failed to allocate push VLAN action");
2831 : 0 : goto err;
2832 : : }
2833 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2834 [ # # # # ]: 0 : if (is_template_masked_push_vlan(masks->conf))
2835 : 0 : acts->rule_acts[dr_pos].push_vlan.vlan_hdr =
2836 : 0 : vlan_hdr_to_be32(actions);
2837 : 0 : else if (__flow_hw_act_data_general_append
2838 : : (priv, acts, actions->type,
2839 : : src_pos, dr_pos))
2840 : 0 : goto err;
2841 : : of_vlan_offset = is_of_vlan_pcp_present(actions) ?
2842 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
2843 : : MLX5_HW_VLAN_PUSH_VID_IDX;
2844 : 0 : actions += of_vlan_offset;
2845 : 0 : masks += of_vlan_offset;
2846 : 0 : break;
2847 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
2848 : 0 : dr_action = mlx5_hws_global_action_pop_vlan_get(priv, type, is_root);
2849 [ # # ]: 0 : if (dr_action == NULL) {
2850 : 0 : DRV_LOG(ERR, "port %u failed to allocate pop VLAN action",
2851 : : priv->dev_data->port_id);
2852 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2853 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2854 : : "failed to allocate pop VLAN action");
2855 : 0 : goto err;
2856 : : }
2857 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2858 : 0 : break;
2859 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
2860 [ # # ]: 0 : if (masks->conf &&
2861 : : ((const struct rte_flow_action_jump *)
2862 [ # # ]: 0 : masks->conf)->group) {
2863 : 0 : uint32_t jump_group =
2864 : : ((const struct rte_flow_action_jump *)
2865 : 0 : actions->conf)->group;
2866 : 0 : acts->jump = flow_hw_jump_action_register
2867 : : (dev, cfg, jump_group, &sub_error);
2868 [ # # ]: 0 : if (!acts->jump)
2869 : 0 : goto err;
2870 : 0 : acts->rule_acts[dr_pos].action = (!!attr->group) ?
2871 [ # # ]: 0 : acts->jump->hws_action :
2872 : : acts->jump->root_action;
2873 : : } else if (__flow_hw_act_data_general_append
2874 : : (priv, acts, actions->type,
2875 : : src_pos, dr_pos)){
2876 : 0 : goto err;
2877 : : }
2878 : : break;
2879 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
2880 [ # # ]: 0 : if (masks->conf &&
2881 : : ((const struct rte_flow_action_queue *)
2882 [ # # ]: 0 : masks->conf)->index) {
2883 : 0 : acts->tir = flow_hw_tir_action_register
2884 : 0 : (dev, mlx5_hw_act_flag[!!attr->group][type],
2885 : : actions);
2886 [ # # ]: 0 : if (!acts->tir)
2887 : 0 : goto err;
2888 : 0 : acts->rule_acts[dr_pos].action =
2889 : 0 : acts->tir->action;
2890 : : } else if (__flow_hw_act_data_general_append
2891 : : (priv, acts, actions->type,
2892 : : src_pos, dr_pos)) {
2893 : 0 : goto err;
2894 : : }
2895 : : break;
2896 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
2897 [ # # # # ]: 0 : if (actions->conf && masks->conf) {
2898 : 0 : acts->tir = flow_hw_tir_action_register
2899 : 0 : (dev, mlx5_hw_act_flag[!!attr->group][type],
2900 : : actions);
2901 [ # # ]: 0 : if (!acts->tir)
2902 : 0 : goto err;
2903 : 0 : acts->rule_acts[dr_pos].action =
2904 : 0 : acts->tir->action;
2905 : : } else if (__flow_hw_act_data_general_append
2906 : : (priv, acts, actions->type,
2907 : : src_pos, dr_pos)) {
2908 : 0 : goto err;
2909 : : }
2910 : : break;
2911 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2912 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2913 : : MLX5_ASSERT(!reformat_used);
2914 : 0 : ret = translate_l2_encap_action(actions, masks, converted_encap_data,
2915 : : &data_size, error);
2916 [ # # ]: 0 : if (ret < 0)
2917 : 0 : goto err;
2918 : : /* If masked action, then use converted encap data for shared action. */
2919 [ # # ]: 0 : if (ret > 0) {
2920 : : encap_data = converted_encap_data;
2921 : : encap_data_m = converted_encap_data;
2922 : : }
2923 : : reformat_used = true;
2924 : : reformat_src = src_pos;
2925 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
2926 : : break;
2927 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2928 : 0 : raw_encap_data =
2929 : : (const struct rte_flow_action_raw_encap *)
2930 : : masks->conf;
2931 [ # # ]: 0 : if (raw_encap_data)
2932 : 0 : encap_data_m = raw_encap_data->data;
2933 : 0 : raw_encap_data =
2934 : : (const struct rte_flow_action_raw_encap *)
2935 : : actions->conf;
2936 : 0 : encap_data = raw_encap_data->data;
2937 : 0 : data_size = raw_encap_data->size;
2938 [ # # ]: 0 : if (reformat_used) {
2939 : : refmt_type = data_size <
2940 : : MLX5_ENCAPSULATION_DECISION_SIZE ?
2941 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2 :
2942 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
2943 : : } else {
2944 : : reformat_used = true;
2945 : : refmt_type =
2946 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
2947 : : }
2948 : : reformat_src = src_pos;
2949 : : break;
2950 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
2951 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
2952 : : MLX5_ASSERT(!reformat_used);
2953 : : reformat_used = true;
2954 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
2955 : 0 : break;
2956 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
2957 : : reformat_used = true;
2958 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
2959 : 0 : break;
2960 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
2961 [ # # ]: 0 : if (!hca_attr->flex.query_match_sample_info ||
2962 : 0 : !hca_attr->flex.parse_graph_anchor ||
2963 [ # # ]: 0 : !priv->sh->srh_flex_parser.flex.mapnum) {
2964 : 0 : DRV_LOG(ERR, "SRv6 anchor is not supported.");
2965 : 0 : goto err;
2966 : : }
2967 : : MLX5_ASSERT(!recom_used && !recom_type);
2968 : : recom_used = true;
2969 : : recom_type = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT;
2970 : 0 : ipv6_ext_data =
2971 : : (const struct rte_flow_action_ipv6_ext_push *)masks->conf;
2972 [ # # ]: 0 : if (ipv6_ext_data)
2973 : 0 : push_data_m = ipv6_ext_data->data;
2974 : 0 : ipv6_ext_data =
2975 : : (const struct rte_flow_action_ipv6_ext_push *)actions->conf;
2976 [ # # ]: 0 : if (ipv6_ext_data) {
2977 : 0 : push_data = ipv6_ext_data->data;
2978 : 0 : push_size = ipv6_ext_data->size;
2979 : : }
2980 : : recom_src = src_pos;
2981 : : break;
2982 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE:
2983 [ # # ]: 0 : if (!hca_attr->flex.query_match_sample_info ||
2984 : 0 : !hca_attr->flex.parse_graph_anchor ||
2985 [ # # ]: 0 : !priv->sh->srh_flex_parser.flex.mapnum) {
2986 : 0 : DRV_LOG(ERR, "SRv6 anchor is not supported.");
2987 : 0 : goto err;
2988 : : }
2989 : : recom_used = true;
2990 : : recom_type = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT;
2991 : : break;
2992 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
2993 [ # # ]: 0 : if (is_root) {
2994 : 0 : rte_flow_error_set(&sub_error, ENOTSUP,
2995 : : RTE_FLOW_ERROR_TYPE_ACTION,
2996 : : NULL,
2997 : : "Send to kernel action on root table is not supported in HW steering mode");
2998 : 0 : goto err;
2999 : : }
3000 : 0 : dr_action = mlx5_hws_global_action_send_to_kernel_get(priv,
3001 : : type,
3002 : : MLX5_HW_LOWEST_PRIO_ROOT);
3003 [ # # ]: 0 : if (dr_action == NULL) {
3004 : 0 : DRV_LOG(ERR, "port %u failed to allocate send to kernel action",
3005 : : priv->dev_data->port_id);
3006 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3007 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3008 : : "failed to allocate send to kernel action");
3009 : 0 : goto err;
3010 : : }
3011 : 0 : acts->rule_acts[dr_pos].action = dr_action;
3012 : 0 : break;
3013 [ # # ]: 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3014 : : err = flow_hw_modify_field_compile(dev, attr, actions,
3015 : : masks, acts, &mhdr,
3016 : : src_pos, &sub_error);
3017 [ # # ]: 0 : if (err)
3018 : 0 : goto err;
3019 : : break;
3020 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3021 [ # # ]: 0 : if (flow_hw_represented_port_compile
3022 : : (dev, attr, actions,
3023 : : masks, acts, src_pos, dr_pos, &sub_error))
3024 : 0 : goto err;
3025 : : break;
3026 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
3027 [ # # ]: 0 : if (is_root && !mlx5dr_action_counter_root_is_supported()) {
3028 : 0 : rte_flow_error_set(&sub_error, ENOTSUP,
3029 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3030 : : "Age action is not supported on group 0");
3031 : 0 : goto err;
3032 : : }
3033 : : if (__flow_hw_act_data_general_append(priv, acts,
3034 : : actions->type,
3035 : : src_pos,
3036 : : dr_pos))
3037 : 0 : goto err;
3038 : : break;
3039 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
3040 [ # # ]: 0 : if (is_root && !mlx5dr_action_counter_root_is_supported()) {
3041 : 0 : rte_flow_error_set(&sub_error, ENOTSUP,
3042 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3043 : : "Count action is not supported on root table");
3044 : 0 : goto err;
3045 : : }
3046 [ # # ]: 0 : if ((at->action_flags & MLX5_FLOW_ACTION_AGE) ||
3047 : : (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE))
3048 : : /*
3049 : : * When both COUNT and AGE are requested, it is
3050 : : * saved as AGE action which creates also the
3051 : : * counter.
3052 : : */
3053 : : break;
3054 [ # # ]: 0 : if (masks->conf &&
3055 : : ((const struct rte_flow_action_count *)
3056 [ # # ]: 0 : masks->conf)->id) {
3057 [ # # ]: 0 : err = flow_hw_cnt_compile(dev, dr_pos, acts, is_root);
3058 : : if (err)
3059 : 0 : goto err;
3060 : : } else if (__flow_hw_act_data_general_append
3061 : : (priv, acts, actions->type,
3062 : : src_pos, dr_pos)) {
3063 : 0 : goto err;
3064 : : }
3065 : : break;
3066 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
3067 [ # # ]: 0 : if (masks->conf) {
3068 : 0 : ct_idx = MLX5_INDIRECT_ACTION_IDX_GET(actions->conf);
3069 : : if (flow_hw_ct_compile(dev, MLX5_HW_INV_QUEUE, ct_idx,
3070 : 0 : &acts->rule_acts[dr_pos]))
3071 : 0 : goto err;
3072 : : } else if (__flow_hw_act_data_general_append
3073 : : (priv, acts, actions->type,
3074 : : src_pos, dr_pos)) {
3075 : 0 : goto err;
3076 : : }
3077 : : break;
3078 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
3079 [ # # # # ]: 0 : if (actions->conf && masks->conf &&
3080 : : ((const struct rte_flow_action_meter_mark *)
3081 [ # # ]: 0 : masks->conf)->profile) {
3082 : : err = flow_hw_meter_mark_compile(dev,
3083 : : dr_pos, actions,
3084 : 0 : acts->rule_acts,
3085 : : &acts->mtr_id,
3086 : : MLX5_HW_INV_QUEUE,
3087 : : &sub_error);
3088 : : if (err)
3089 : 0 : goto err;
3090 : : } else if (__flow_hw_act_data_general_append(priv, acts,
3091 : : actions->type,
3092 : : src_pos,
3093 : : dr_pos))
3094 : 0 : goto err;
3095 : : break;
3096 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
3097 : 0 : dr_action = mlx5_hws_global_action_def_miss_get(priv, type, is_root);
3098 [ # # ]: 0 : if (dr_action == NULL) {
3099 : 0 : DRV_LOG(ERR, "port %u failed to allocate default miss action",
3100 : : priv->dev_data->port_id);
3101 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3102 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3103 : : "failed to allocate default miss action");
3104 : 0 : goto err;
3105 : : }
3106 : 0 : acts->rule_acts[dr_pos].action = dr_action;
3107 : 0 : break;
3108 : 0 : case RTE_FLOW_ACTION_TYPE_NAT64:
3109 [ # # ]: 0 : if (masks->conf &&
3110 [ # # ]: 0 : ((const struct rte_flow_action_nat64 *)masks->conf)->type) {
3111 : 0 : const struct rte_flow_action_nat64 *nat64_c =
3112 : : (const struct rte_flow_action_nat64 *)actions->conf;
3113 : 0 : dr_action = mlx5_hws_global_action_nat64_get(priv,
3114 : : type,
3115 : 0 : nat64_c->type);
3116 [ # # ]: 0 : if (dr_action == NULL) {
3117 : 0 : DRV_LOG(ERR, "port %u failed to allocate NAT64 action",
3118 : : priv->dev_data->port_id);
3119 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3120 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3121 : : "failed to allocate NAT64 action");
3122 : 0 : goto err;
3123 : : }
3124 : 0 : acts->rule_acts[dr_pos].action = dr_action;
3125 : 0 : break;
3126 : : }
3127 : 0 : acts->nat64[RTE_FLOW_NAT64_6TO4] = mlx5_hws_global_action_nat64_get(priv,
3128 : : type,
3129 : : RTE_FLOW_NAT64_6TO4);
3130 : 0 : acts->nat64[RTE_FLOW_NAT64_4TO6] = mlx5_hws_global_action_nat64_get(priv,
3131 : : type,
3132 : : RTE_FLOW_NAT64_4TO6);
3133 [ # # # # ]: 0 : if (!acts->nat64[RTE_FLOW_NAT64_6TO4] ||
3134 : : !acts->nat64[RTE_FLOW_NAT64_4TO6]) {
3135 : 0 : DRV_LOG(ERR, "port %u failed to allocate both NAT64 actions",
3136 : : priv->dev_data->port_id);
3137 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3138 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3139 : : "failed to allocate both NAT64 actions");
3140 : 0 : goto err;
3141 : : }
3142 : 0 : if (__flow_hw_act_data_general_append(priv, acts,
3143 : : actions->type,
3144 : : src_pos, dr_pos))
3145 : 0 : goto err;
3146 : : break;
3147 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
3148 [ # # ]: 0 : if (masks->conf &&
3149 : : ((const struct rte_flow_action_jump_to_table_index *)
3150 [ # # ]: 0 : masks->conf)->table) {
3151 : 0 : struct rte_flow_template_table *jump_table =
3152 : : ((const struct rte_flow_action_jump_to_table_index *)
3153 : 0 : actions->conf)->table;
3154 : 0 : acts->rule_acts[dr_pos].jump_to_matcher.offset =
3155 : : ((const struct rte_flow_action_jump_to_table_index *)
3156 : 0 : actions->conf)->index;
3157 [ # # ]: 0 : if (likely(!rte_flow_template_table_resizable(dev->data->port_id,
3158 : : &jump_table->cfg.attr))) {
3159 : 0 : acts->rule_acts[dr_pos].action =
3160 : 0 : jump_table->matcher_info[0].jump;
3161 : : } else {
3162 : : uint32_t selector;
3163 : 0 : rte_rwlock_read_lock(&jump_table->matcher_replace_rwlk);
3164 : 0 : selector = jump_table->matcher_selector;
3165 : 0 : acts->rule_acts[dr_pos].action =
3166 : 0 : jump_table->matcher_info[selector].jump;
3167 : 0 : rte_rwlock_read_unlock(&jump_table->matcher_replace_rwlk);
3168 : : }
3169 : : } else if (__flow_hw_act_data_general_append
3170 : : (priv, acts, actions->type,
3171 : : src_pos, dr_pos)){
3172 : 0 : goto err;
3173 : : }
3174 : : break;
3175 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_MIRROR:
3176 : : if (__flow_hw_act_data_general_append(priv, acts,
3177 : : actions->type,
3178 : : src_pos, dr_pos))
3179 : 0 : goto err;
3180 : : break;
3181 : 0 : case RTE_FLOW_ACTION_TYPE_END:
3182 : : actions_end = true;
3183 : 0 : break;
3184 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
3185 : 0 : DRV_LOG(ERR, "RTE_FLOW_ACTION_TYPE_PORT_ID action is not supported. "
3186 : : "Use RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT instead.");
3187 : 0 : goto err;
3188 : : default:
3189 : : break;
3190 : : }
3191 : : }
3192 [ # # ]: 0 : if (mhdr.pos != UINT16_MAX) {
3193 : 0 : ret = mlx5_tbl_translate_modify_header(dev, cfg, acts, mp_ctx, &mhdr, &sub_error);
3194 [ # # ]: 0 : if (ret)
3195 : 0 : goto err;
3196 [ # # # # ]: 0 : if (!nt_mode && mhdr.shared) {
3197 : 0 : ret = mlx5_tbl_ensure_shared_modify_header(dev, cfg, acts, &sub_error);
3198 [ # # ]: 0 : if (ret)
3199 : 0 : goto err;
3200 : : }
3201 : : }
3202 [ # # ]: 0 : if (reformat_used) {
3203 : 0 : ret = mlx5_tbl_translate_reformat(priv, acts, at,
3204 : : encap_data, encap_data_m,
3205 : : mp_ctx, data_size,
3206 : : reformat_src,
3207 : : refmt_type, &sub_error);
3208 [ # # ]: 0 : if (ret)
3209 : 0 : goto err;
3210 [ # # # # ]: 0 : if (!nt_mode && acts->encap_decap->shared) {
3211 : 0 : ret = mlx5_tbl_create_reformat_action(priv, table_attr, acts, at,
3212 : : encap_data, data_size,
3213 : : refmt_type);
3214 [ # # ]: 0 : if (ret)
3215 : 0 : goto err;
3216 : : }
3217 : : }
3218 [ # # ]: 0 : if (recom_used) {
3219 : : MLX5_ASSERT(at->recom_off != UINT16_MAX);
3220 : 0 : ret = mlx5_create_ipv6_ext_reformat(dev, cfg, acts, at, push_data,
3221 : : push_data_m, push_size, recom_src,
3222 : : recom_type);
3223 [ # # ]: 0 : if (ret)
3224 : 0 : goto err;
3225 : : }
3226 : : return 0;
3227 : 0 : err:
3228 : : /* If rte_errno was not initialized and reached error state. */
3229 [ # # ]: 0 : if (!rte_errno)
3230 : 0 : rte_errno = EINVAL;
3231 : 0 : err = rte_errno;
3232 : : __flow_hw_action_template_destroy(dev, acts);
3233 [ # # # # ]: 0 : if (error != NULL && sub_error.type != RTE_FLOW_ERROR_TYPE_NONE) {
3234 : : rte_memcpy(error, &sub_error, sizeof(sub_error));
3235 : 0 : return -EINVAL;
3236 : : }
3237 : 0 : return rte_flow_error_set(error, err,
3238 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3239 : : "fail to create rte table");
3240 : : }
3241 : :
3242 : : /**
3243 : : * Translate rte_flow actions to DR action.
3244 : : *
3245 : : * As the action template has already indicated the actions. Translate
3246 : : * the rte_flow actions to DR action if possible. So in flow create
3247 : : * stage we will save cycles from handing the actions' organizing.
3248 : : * For the actions with limited information, need to add these to a
3249 : : * list.
3250 : : *
3251 : : * @param[in] dev
3252 : : * Pointer to the rte_eth_dev structure.
3253 : : * @param[in] cfg
3254 : : * Pointer to the table configuration.
3255 : : * @param[in/out] acts
3256 : : * Pointer to the template HW steering DR actions.
3257 : : * @param[in] at
3258 : : * Action template.
3259 : : * @param[out] error
3260 : : * Pointer to error structure.
3261 : : *
3262 : : * @return
3263 : : * 0 on success, a negative errno otherwise and rte_errno is set.
3264 : : */
3265 : : static int
3266 : : flow_hw_translate_actions_template(struct rte_eth_dev *dev,
3267 : : const struct mlx5_flow_template_table_cfg *cfg,
3268 : : struct mlx5_hw_actions *acts,
3269 : : struct rte_flow_actions_template *at,
3270 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
3271 : : struct rte_flow_error *error)
3272 : : {
3273 : 0 : return __flow_hw_translate_actions_template(dev, cfg, acts, at, mp_ctx, false, error);
3274 : : }
3275 : :
3276 : : static __rte_always_inline struct mlx5dr_rule_action *
3277 : : flow_hw_get_dr_action_buffer(struct mlx5_priv *priv,
3278 : : struct rte_flow_template_table *table,
3279 : : uint8_t action_template_index,
3280 : : uint32_t queue)
3281 : : {
3282 : 0 : uint32_t offset = action_template_index * priv->nb_queue + queue;
3283 : :
3284 : 0 : return &table->rule_acts[offset].acts[0];
3285 : : }
3286 : :
3287 : : static void
3288 : 0 : flow_hw_populate_rule_acts_caches(struct rte_eth_dev *dev,
3289 : : struct rte_flow_template_table *table,
3290 : : uint8_t at_idx)
3291 : : {
3292 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3293 : : uint32_t q;
3294 : :
3295 [ # # ]: 0 : for (q = 0; q < priv->nb_queue; ++q) {
3296 : : struct mlx5dr_rule_action *rule_acts =
3297 : 0 : flow_hw_get_dr_action_buffer(priv, table, at_idx, q);
3298 : :
3299 [ # # ]: 0 : rte_memcpy(rule_acts, table->ats[at_idx].acts.rule_acts,
3300 : : sizeof(table->ats[at_idx].acts.rule_acts));
3301 : : }
3302 : 0 : }
3303 : :
3304 : : /**
3305 : : * Translate rte_flow actions to DR action.
3306 : : *
3307 : : * @param[in] dev
3308 : : * Pointer to the rte_eth_dev structure.
3309 : : * @param[in] tbl
3310 : : * Pointer to the flow template table.
3311 : : * @param[out] error
3312 : : * Pointer to error structure.
3313 : : *
3314 : : * @return
3315 : : * 0 on success, negative value otherwise and rte_errno is set.
3316 : : */
3317 : : static int
3318 : 0 : flow_hw_translate_all_actions_templates(struct rte_eth_dev *dev,
3319 : : struct rte_flow_template_table *tbl,
3320 : : struct rte_flow_error *error)
3321 : : {
3322 : : int ret;
3323 : : uint32_t i;
3324 : :
3325 [ # # ]: 0 : for (i = 0; i < tbl->nb_action_templates; i++) {
3326 [ # # ]: 0 : if (flow_hw_translate_actions_template(dev, &tbl->cfg,
3327 : : &tbl->ats[i].acts,
3328 : : tbl->ats[i].action_template,
3329 : : &tbl->mpctx, error))
3330 : 0 : goto err;
3331 : 0 : flow_hw_populate_rule_acts_caches(dev, tbl, i);
3332 : : }
3333 [ # # ]: 0 : ret = mlx5_tbl_multi_pattern_process(dev, tbl, &tbl->mpctx.segments[0],
3334 : : rte_log2_u32(tbl->cfg.attr.nb_flows),
3335 : : error);
3336 [ # # ]: 0 : if (ret)
3337 : 0 : goto err;
3338 : : return 0;
3339 : : err:
3340 [ # # ]: 0 : while (i--)
3341 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
3342 : : return -1;
3343 : : }
3344 : :
3345 : : /**
3346 : : * Get shared indirect action.
3347 : : *
3348 : : * @param[in] dev
3349 : : * Pointer to the rte_eth_dev data structure.
3350 : : * @param[in] act_data
3351 : : * Pointer to the recorded action construct data.
3352 : : * @param[in] item_flags
3353 : : * The matcher itme_flags used for RSS lookup.
3354 : : * @param[in] rule_act
3355 : : * Pointer to the shared action's destination rule DR action.
3356 : : *
3357 : : * @return
3358 : : * 0 on success, negative value otherwise and rte_errno is set.
3359 : : */
3360 : : static __rte_always_inline int
3361 : : flow_hw_shared_action_get(struct rte_eth_dev *dev,
3362 : : struct mlx5_action_construct_data *act_data,
3363 : : const uint64_t item_flags,
3364 : : struct mlx5dr_rule_action *rule_act)
3365 : : {
3366 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3367 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
3368 : 0 : uint64_t hash_fields = 0;
3369 : : uint32_t hrxq_idx = 0;
3370 : : struct mlx5_hrxq *hrxq = NULL;
3371 : : int act_type = act_data->type;
3372 : :
3373 : : switch (act_type) {
3374 : : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
3375 : 0 : rss_desc.level = act_data->shared_rss.level;
3376 : 0 : rss_desc.types = act_data->shared_rss.types;
3377 : 0 : rss_desc.symmetric_hash_function = act_data->shared_rss.symmetric_hash_function;
3378 : 0 : mlx5_flow_dv_hashfields_set(item_flags, &rss_desc, &hash_fields);
3379 : 0 : hrxq_idx = mlx5_flow_dv_action_rss_hrxq_lookup
3380 : : (dev, act_data->shared_rss.idx, hash_fields);
3381 [ # # # # : 0 : if (hrxq_idx)
# # # # #
# # # # #
# # # # #
# ]
3382 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
3383 : : hrxq_idx);
3384 [ # # # # : 0 : if (hrxq) {
# # # # #
# # # # #
# # # # #
# ]
3385 : 0 : rule_act->action = hrxq->action;
3386 : : return 0;
3387 : : }
3388 : : break;
3389 : : default:
3390 : : DRV_LOG(WARNING, "Unsupported shared action type:%d",
3391 : : act_data->type);
3392 : : break;
3393 : : }
3394 : : return -1;
3395 : : }
3396 : :
3397 : : static void
3398 : 0 : flow_hw_construct_quota(struct mlx5_priv *priv,
3399 : : struct mlx5dr_rule_action *rule_act, uint32_t qid)
3400 : : {
3401 : 0 : rule_act->action = priv->quota_ctx.dr_action;
3402 : 0 : rule_act->aso_meter.offset = qid - 1;
3403 : 0 : rule_act->aso_meter.init_color =
3404 : : MLX5DR_ACTION_ASO_METER_COLOR_GREEN;
3405 : 0 : }
3406 : :
3407 : : /**
3408 : : * Construct shared indirect action.
3409 : : *
3410 : : * @param[in] dev
3411 : : * Pointer to the rte_eth_dev data structure.
3412 : : * @param[in] queue
3413 : : * The flow creation queue index.
3414 : : * @param[in] action
3415 : : * Pointer to the shared indirect rte_flow action.
3416 : : * @param[in] table
3417 : : * Pointer to the flow table.
3418 : : * @param[in] item_flags
3419 : : * Item flags.
3420 : : * @param[in] action_flags
3421 : : * Actions bit-map detected in this template.
3422 : : * @param[in, out] flow
3423 : : * Pointer to the flow containing the counter.
3424 : : * @param[in] rule_act
3425 : : * Pointer to the shared action's destination rule DR action.
3426 : : *
3427 : : * @return
3428 : : * 0 on success, negative value otherwise and rte_errno is set.
3429 : : */
3430 : : static __rte_always_inline int
3431 : : flow_hw_shared_action_construct(struct rte_eth_dev *dev, uint32_t queue,
3432 : : const struct rte_flow_action *action,
3433 : : struct rte_flow_template_table *table,
3434 : : const uint64_t item_flags, uint64_t action_flags,
3435 : : struct rte_flow_hw *flow,
3436 : : struct mlx5dr_rule_action *rule_act)
3437 : : {
3438 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3439 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
3440 : : struct mlx5_action_construct_data act_data;
3441 : : struct mlx5_shared_action_rss *shared_rss;
3442 : : struct mlx5_aso_mtr *aso_mtr;
3443 : : struct mlx5_age_info *age_info;
3444 : : struct mlx5_hws_age_param *param;
3445 : : struct rte_flow_hw_aux *aux;
3446 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)action->conf;
3447 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3448 : 0 : uint32_t idx = act_idx &
3449 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3450 : : uint32_t *cnt_queue;
3451 : : cnt_id_t age_cnt;
3452 : 0 : bool is_root = mlx5_group_id_is_root(table->grp->group_id);
3453 : :
3454 : : memset(&act_data, 0, sizeof(act_data));
3455 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3456 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
3457 : 0 : act_data.type = MLX5_RTE_FLOW_ACTION_TYPE_RSS;
3458 : 0 : shared_rss = mlx5_ipool_get
3459 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3460 [ # # # # : 0 : if (!shared_rss)
# # # # #
# ]
3461 : : return -1;
3462 : 0 : act_data.shared_rss.idx = idx;
3463 : 0 : act_data.shared_rss.level = shared_rss->origin.level;
3464 : 0 : act_data.shared_rss.types = !shared_rss->origin.types ?
3465 [ # # # # : 0 : RTE_ETH_RSS_IP :
# # # # #
# ]
3466 : : shared_rss->origin.types;
3467 : 0 : act_data.shared_rss.symmetric_hash_function =
3468 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
3469 : :
3470 : : if (flow_hw_shared_action_get
3471 : : (dev, &act_data, item_flags, rule_act))
3472 : : return -1;
3473 : : break;
3474 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3475 [ # # # # : 0 : if (mlx5_hws_cnt_pool_get_action_offset(priv->hws_cpool,
# # # # #
# ]
3476 : : act_idx,
3477 : : &rule_act->action,
3478 : : &rule_act->counter.offset,
3479 : : is_root))
3480 : : return -1;
3481 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3482 : 0 : flow->cnt_id = act_idx;
3483 : : break;
3484 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
3485 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
3486 : : /*
3487 : : * Save the index with the indirect type, to recognize
3488 : : * it in flow destroy.
3489 : : */
3490 : : mlx5_flow_hw_aux_set_age_idx(flow, aux, act_idx);
3491 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX;
3492 [ # # # # : 0 : if (action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT)
# # # # #
# ]
3493 : : /*
3494 : : * The mutual update for idirect AGE & COUNT will be
3495 : : * performed later after we have ID for both of them.
3496 : : */
3497 : : break;
3498 : 0 : age_info = GET_PORT_AGE_INFO(priv);
3499 : 0 : param = mlx5_ipool_get(age_info->ages_ipool, idx);
3500 [ # # # # : 0 : if (param == NULL)
# # # # #
# ]
3501 : : return -1;
3502 [ # # # # : 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
# # # # #
# ]
3503 : : cnt_queue = mlx5_hws_cnt_get_queue(priv, &queue);
3504 [ # # # # : 0 : if (mlx5_hws_cnt_pool_get(priv->hws_cpool, cnt_queue, &age_cnt, idx, 0) < 0)
# # # # #
# ]
3505 : : return -1;
3506 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3507 : 0 : flow->cnt_id = age_cnt;
3508 : 0 : param->nb_cnts++;
3509 : : } else {
3510 : : /*
3511 : : * Get the counter of this indirect AGE or create one
3512 : : * if doesn't exist.
3513 : : */
3514 : : age_cnt = mlx5_hws_age_cnt_get(priv, param, idx);
3515 [ # # # # : 0 : if (age_cnt == 0)
# # # # #
# ]
3516 : : return -1;
3517 : : }
3518 [ # # # # : 0 : if (mlx5_hws_cnt_pool_get_action_offset(priv->hws_cpool,
# # # # #
# ]
3519 : : age_cnt, &rule_act->action,
3520 : : &rule_act->counter.offset, is_root))
3521 : : return -1;
3522 : : break;
3523 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
3524 : : if (flow_hw_ct_compile(dev, queue, idx, rule_act))
3525 : : return -1;
3526 : : break;
3527 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
3528 : : /* Find ASO object. */
3529 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
3530 [ # # # # : 0 : if (!aso_mtr)
# # # # #
# ]
3531 : : return -1;
3532 : 0 : rule_act->action = pool->action;
3533 : 0 : rule_act->aso_meter.offset = aso_mtr->offset;
3534 : : break;
3535 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
3536 : 0 : flow_hw_construct_quota(priv, rule_act, idx);
3537 : : break;
3538 : 0 : default:
3539 : 0 : DRV_LOG(WARNING, "Unsupported shared action type:%d", type);
3540 : : break;
3541 : : }
3542 : : return 0;
3543 : : }
3544 : :
3545 : : static __rte_always_inline int
3546 : : flow_hw_mhdr_cmd_is_nop(const struct mlx5_modification_cmd *cmd)
3547 : : {
3548 : : struct mlx5_modification_cmd cmd_he = {
3549 : 0 : .data0 = rte_be_to_cpu_32(cmd->data0),
3550 : : .data1 = 0,
3551 : : };
3552 : :
3553 : 0 : return cmd_he.action_type == MLX5_MODIFICATION_TYPE_NOP;
3554 : : }
3555 : :
3556 : : /**
3557 : : * Construct flow action array.
3558 : : *
3559 : : * For action template contains dynamic actions, these actions need to
3560 : : * be updated according to the rte_flow action during flow creation.
3561 : : *
3562 : : * @param[in] dev
3563 : : * Pointer to the rte_eth_dev structure.
3564 : : * @param[in] job
3565 : : * Pointer to job descriptor.
3566 : : * @param[in] hw_acts
3567 : : * Pointer to translated actions from template.
3568 : : * @param[in] it_idx
3569 : : * Item template index the action template refer to.
3570 : : * @param[in] actions
3571 : : * Array of rte_flow action need to be checked.
3572 : : * @param[in] rule_acts
3573 : : * Array of DR rule actions to be used during flow creation..
3574 : : * @param[in] acts_num
3575 : : * Pointer to the real acts_num flow has.
3576 : : *
3577 : : * @return
3578 : : * 0 on success, negative value otherwise and rte_errno is set.
3579 : : */
3580 : : static __rte_always_inline int
3581 : : flow_hw_modify_field_construct(struct mlx5_modification_cmd *mhdr_cmd,
3582 : : struct mlx5_action_construct_data *act_data,
3583 : : const struct mlx5_hw_actions *hw_acts,
3584 : : const struct rte_flow_action *action)
3585 : : {
3586 : 0 : const struct rte_flow_action_modify_field *mhdr_action = action->conf;
3587 : 0 : uint8_t values[16] = { 0 };
3588 : : unaligned_uint32_t *value_p;
3589 : : uint32_t i;
3590 : : struct field_modify_info *field;
3591 : :
3592 [ # # # # : 0 : if (!hw_acts->mhdr)
# # # # #
# ]
3593 : : return -1;
3594 [ # # # # : 0 : if (hw_acts->mhdr->shared || act_data->modify_header.shared)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3595 : : return 0;
3596 : : MLX5_ASSERT(mhdr_action->operation == RTE_FLOW_MODIFY_SET ||
3597 : : mhdr_action->operation == RTE_FLOW_MODIFY_ADD);
3598 [ # # # # : 0 : if (mhdr_action->src.field != RTE_FLOW_FIELD_VALUE &&
# # # # #
# ]
3599 : : mhdr_action->src.field != RTE_FLOW_FIELD_POINTER)
3600 : : return 0;
3601 [ # # # # : 0 : if (mhdr_action->src.field == RTE_FLOW_FIELD_VALUE)
# # # # #
# ]
3602 : : rte_memcpy(values, &mhdr_action->src.value, sizeof(values));
3603 : : else
3604 : 0 : rte_memcpy(values, mhdr_action->src.pvalue, sizeof(values));
3605 [ # # # # : 0 : if (mhdr_action->dst.field == RTE_FLOW_FIELD_META ||
# # # # #
# ]
3606 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_TAG ||
# # # # #
# ]
3607 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_METER_COLOR ||
# # # # #
# ]
3608 : : mhdr_action->dst.field == (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
3609 : 0 : uint8_t tag_index = flow_tag_index_get(&mhdr_action->dst);
3610 : :
3611 : : value_p = (unaligned_uint32_t *)values;
3612 [ # # # # : 0 : if (mhdr_action->dst.field == RTE_FLOW_FIELD_TAG &&
# # # # #
# # # # #
# # # # #
# ]
3613 : : tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
3614 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(*value_p << 16);
# # # # #
# ]
3615 : : else
3616 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(*value_p);
# # # # #
# ]
3617 [ # # # # : 0 : } else if (mhdr_action->dst.field == RTE_FLOW_FIELD_GTP_PSC_QFI ||
# # # # #
# ]
3618 : : mhdr_action->dst.field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE) {
3619 : : uint32_t tmp;
3620 : :
3621 : : /*
3622 : : * Both QFI and Geneve option type are passed as an uint8_t integer,
3623 : : * but it is accessed through a 2nd least significant byte of a 32-bit
3624 : : * field in modify header command.
3625 : : */
3626 : 0 : tmp = values[0];
3627 : : value_p = (unaligned_uint32_t *)values;
3628 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(tmp << 8);
# # # # #
# ]
3629 : : }
3630 : 0 : i = act_data->modify_header.mhdr_cmds_off;
3631 : 0 : field = act_data->modify_header.field;
3632 : : do {
3633 : : uint32_t off_b;
3634 : : uint32_t mask;
3635 : : uint32_t data;
3636 : : const uint8_t *mask_src;
3637 : :
3638 [ # # # # : 0 : if (i >= act_data->modify_header.mhdr_cmds_end)
# # # # #
# # # # #
# # # # #
# ]
3639 : : return -1;
3640 [ # # # # : 0 : if (flow_hw_mhdr_cmd_is_nop(&mhdr_cmd[i])) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3641 : 0 : ++i;
3642 : 0 : continue;
3643 : : }
3644 : 0 : mask_src = (const uint8_t *)act_data->modify_header.mask;
3645 : 0 : mask = flow_dv_fetch_field(mask_src + field->offset, field->size);
3646 [ # # # # : 0 : if (!mask) {
# # # # #
# # # # #
# # # # #
# ]
3647 : 0 : ++field;
3648 : 0 : continue;
3649 : : }
3650 : 0 : off_b = rte_bsf32(mask);
3651 : 0 : data = flow_dv_fetch_field(values + field->offset, field->size);
3652 : : /*
3653 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
3654 : : * bits left. Shift the data left for IPv6 DSCP
3655 : : */
3656 [ # # # # : 0 : if (field->id == MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS &&
# # # # #
# # # #
# ]
3657 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_IPV6_DSCP)
# # ]
3658 : 0 : data <<= MLX5_IPV6_HDR_DSCP_SHIFT;
3659 : 0 : data = (data & mask) >> off_b;
3660 [ # # # # : 0 : mhdr_cmd[i++].data1 = rte_cpu_to_be_32(data);
# # # # #
# # # # #
# # # # #
# ]
3661 : 0 : ++field;
3662 [ # # # # : 0 : } while (field->size);
# # # # #
# # # # #
# # # # #
# ]
3663 : : return 0;
3664 : : }
3665 : :
3666 : : /**
3667 : : * Release any actions allocated for the flow rule during actions construction.
3668 : : *
3669 : : * @param[in] flow
3670 : : * Pointer to flow structure.
3671 : : */
3672 : : static void
3673 : 0 : flow_hw_release_actions(struct rte_eth_dev *dev,
3674 : : uint32_t queue,
3675 : : struct rte_flow_hw *flow)
3676 : : {
3677 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3678 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
3679 [ # # ]: 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
3680 : :
3681 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP)
3682 : 0 : flow_hw_jump_release(dev, flow->jump);
3683 [ # # ]: 0 : else if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ)
3684 : 0 : mlx5_hrxq_obj_release(dev, flow->hrxq);
3685 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID)
3686 : 0 : flow_hw_age_count_release(priv, queue, flow, NULL);
3687 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MTR_ID)
3688 : 0 : mlx5_ipool_free(pool->idx_pool, mlx5_flow_hw_aux_get_mtr_id(flow, aux));
3689 : 0 : }
3690 : :
3691 : : /**
3692 : : * Construct flow action array.
3693 : : *
3694 : : * For action template contains dynamic actions, these actions need to
3695 : : * be updated according to the rte_flow action during flow creation.
3696 : : *
3697 : : * @param[in] dev
3698 : : * Pointer to the rte_eth_dev structure.
3699 : : * @param[in] flow
3700 : : * Pointer to flow structure.
3701 : : * @param[in] ap
3702 : : * Pointer to container for temporarily constructed actions' parameters.
3703 : : * @param[in] hw_acts
3704 : : * Pointer to translated actions from template.
3705 : : * @param[in] items_flags
3706 : : * Item flags.
3707 : : * @param[in] table
3708 : : * Pointer to the template table.
3709 : : * @param[in] actions
3710 : : * Array of rte_flow action need to be checked.
3711 : : * @param[in] rule_acts
3712 : : * Array of DR rule actions to be used during flow creation..
3713 : : * @param[in] acts_num
3714 : : * Pointer to the real acts_num flow has.
3715 : : *
3716 : : * @return
3717 : : * 0 on success, negative value otherwise and rte_errno is set.
3718 : : */
3719 : : static __rte_always_inline int
3720 : : flow_hw_actions_construct(struct rte_eth_dev *dev,
3721 : : struct rte_flow_hw *flow,
3722 : : struct mlx5_flow_hw_action_params *ap,
3723 : : const struct mlx5_hw_action_template *hw_at,
3724 : : uint64_t item_flags,
3725 : : struct rte_flow_template_table *table,
3726 : : const struct rte_flow_action actions[],
3727 : : struct mlx5dr_rule_action *rule_acts,
3728 : : uint32_t queue,
3729 : : struct rte_flow_error *error)
3730 : : {
3731 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3732 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
3733 : : struct mlx5_action_construct_data *act_data;
3734 : 0 : const struct rte_flow_actions_template *at = hw_at->action_template;
3735 : : const struct mlx5_hw_actions *hw_acts = &hw_at->acts;
3736 : : const struct rte_flow_action *action;
3737 : : const struct rte_flow_action_raw_encap *raw_encap_data;
3738 : : const struct rte_flow_action_ipv6_ext_push *ipv6_push;
3739 : : const struct rte_flow_item *enc_item = NULL;
3740 : : const struct rte_flow_action_ethdev *port_action = NULL;
3741 : : const struct rte_flow_action_age *age = NULL;
3742 : : const struct rte_flow_action_nat64 *nat64_c = NULL;
3743 : 0 : struct rte_flow_attr attr = {
3744 : : .ingress = 1,
3745 : : };
3746 : : uint32_t ft_flag;
3747 : : int ret;
3748 : 0 : size_t encap_len = 0;
3749 : : uint32_t age_idx = 0;
3750 : : uint32_t mtr_idx = 0;
3751 : : struct mlx5_aso_mtr *aso_mtr;
3752 : : struct mlx5_multi_pattern_segment *mp_segment = NULL;
3753 : : struct rte_flow_hw_aux *aux;
3754 : 0 : bool is_root = mlx5_group_id_is_root(table->grp->group_id);
3755 : :
3756 : : attr.group = table->grp->group_id;
3757 : 0 : ft_flag = mlx5_hw_act_flag[!!table->grp->group_id][table->type];
3758 : 0 : if (table->type >= MLX5DR_TABLE_TYPE_FDB && table->type < MLX5DR_TABLE_TYPE_MAX) {
3759 : 0 : attr.transfer = 1;
3760 : : attr.ingress = 1;
3761 [ # # # # : 0 : } else if (table->type == MLX5DR_TABLE_TYPE_NIC_TX) {
# # # # #
# ]
3762 : 0 : attr.egress = 1;
3763 : 0 : attr.ingress = 0;
3764 : : } else {
3765 : : attr.ingress = 1;
3766 : : }
3767 [ # # # # : 0 : if (hw_acts->mhdr && hw_acts->mhdr->mhdr_cmds_num > 0 && !hw_acts->mhdr->shared) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3768 : 0 : uint16_t pos = hw_acts->mhdr->pos;
3769 : :
3770 : 0 : mp_segment = mlx5_multi_pattern_segment_find(table, flow->res_idx);
3771 [ # # # # : 0 : if (!mp_segment || !mp_segment->mhdr_action)
# # # # #
# # # # #
# # # # #
# ]
3772 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3773 : : NULL, "No modify header action found");
3774 : 0 : rule_acts[pos].action = mp_segment->mhdr_action;
3775 : : /* offset is relative to DR action */
3776 : 0 : rule_acts[pos].modify_header.offset =
3777 : 0 : flow->res_idx - mp_segment->head_index;
3778 : 0 : rule_acts[pos].modify_header.data =
3779 : 0 : (uint8_t *)ap->mhdr_cmd;
3780 : : MLX5_ASSERT(hw_acts->mhdr->mhdr_cmds_num <= MLX5_MHDR_MAX_CMD);
3781 : 0 : rte_memcpy(ap->mhdr_cmd, hw_acts->mhdr->mhdr_cmds,
3782 [ # # # # : 0 : sizeof(*ap->mhdr_cmd) * hw_acts->mhdr->mhdr_cmds_num);
# # # # #
# ]
3783 : : }
3784 [ # # # # : 0 : LIST_FOREACH(act_data, &hw_acts->act_list, next) {
# # # # #
# ]
3785 : : uint32_t jump_group;
3786 : : uint32_t tag;
3787 : : struct mlx5_hw_jump_action *jump;
3788 : : struct mlx5_hrxq *hrxq;
3789 : : uint32_t ct_idx;
3790 : : cnt_id_t cnt_id;
3791 : : uint32_t *cnt_queue;
3792 : : uint32_t mtr_id;
3793 : : struct rte_flow_template_table *jump_table;
3794 : :
3795 : 0 : action = &actions[act_data->action_src];
3796 : : /*
3797 : : * action template construction replaces
3798 : : * OF_SET_VLAN_VID with MODIFY_FIELD
3799 : : */
3800 : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
3801 : : MLX5_ASSERT(act_data->type ==
3802 : : RTE_FLOW_ACTION_TYPE_MODIFY_FIELD);
3803 : : else
3804 : : MLX5_ASSERT(action->type ==
3805 : : RTE_FLOW_ACTION_TYPE_INDIRECT ||
3806 : : (int)action->type == act_data->type);
3807 [ # # # # : 0 : switch ((int)act_data->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3808 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
3809 : 0 : act_data->indirect_list_cb(dev, act_data, action,
3810 : 0 : &rule_acts[act_data->action_dst]);
3811 : 0 : break;
3812 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
3813 : 0 : if (flow_hw_shared_action_construct
3814 : : (dev, queue, action, table,
3815 : 0 : item_flags, at->action_flags, flow,
3816 [ # # # # : 0 : &rule_acts[act_data->action_dst]))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3817 : 0 : goto error;
3818 : : break;
3819 : : case RTE_FLOW_ACTION_TYPE_VOID:
3820 : : break;
3821 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
3822 : 0 : tag = mlx5_flow_mark_set
3823 : : (((const struct rte_flow_action_mark *)
3824 : 0 : (action->conf))->id);
3825 : 0 : rule_acts[act_data->action_dst].tag.value = tag;
3826 : 0 : break;
3827 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3828 : 0 : rule_acts[act_data->action_dst].push_vlan.vlan_hdr =
3829 : 0 : vlan_hdr_to_be32(action);
3830 : 0 : break;
3831 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
3832 : 0 : jump_group = ((const struct rte_flow_action_jump *)
3833 : 0 : action->conf)->group;
3834 : 0 : jump = flow_hw_jump_action_register
3835 : 0 : (dev, &table->cfg, jump_group, NULL);
3836 [ # # # # : 0 : if (!jump)
# # # # #
# ]
3837 : 0 : goto error;
3838 : 0 : rule_acts[act_data->action_dst].action =
3839 [ # # # # : 0 : (!!attr.group) ? jump->hws_action : jump->root_action;
# # # # #
# ]
3840 : 0 : flow->jump = jump;
3841 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP;
3842 : 0 : break;
3843 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
3844 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
3845 : 0 : hrxq = flow_hw_tir_action_register(dev, ft_flag, action);
3846 [ # # # # : 0 : if (!hrxq)
# # # # #
# ]
3847 : 0 : goto error;
3848 : 0 : rule_acts[act_data->action_dst].action = hrxq->action;
3849 : 0 : flow->hrxq = hrxq;
3850 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ;
3851 : 0 : break;
3852 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
3853 : 0 : if (flow_hw_shared_action_get
3854 : : (dev, act_data, item_flags,
3855 : 0 : &rule_acts[act_data->action_dst]))
3856 : 0 : goto error;
3857 : : break;
3858 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3859 : 0 : enc_item = ((const struct rte_flow_action_vxlan_encap *)
3860 : 0 : action->conf)->definition;
3861 [ # # # # : 0 : if (mlx5_flow_dv_convert_encap_data(enc_item, ap->encap_data,
# # # # #
# ]
3862 : : &encap_len, NULL))
3863 : 0 : goto error;
3864 : : break;
3865 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3866 : 0 : enc_item = ((const struct rte_flow_action_nvgre_encap *)
3867 : 0 : action->conf)->definition;
3868 [ # # # # : 0 : if (mlx5_flow_dv_convert_encap_data(enc_item, ap->encap_data,
# # # # #
# ]
3869 : : &encap_len, NULL))
3870 : 0 : goto error;
3871 : : break;
3872 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3873 : 0 : raw_encap_data =
3874 : : (const struct rte_flow_action_raw_encap *)
3875 : : action->conf;
3876 : : MLX5_ASSERT(raw_encap_data->size == act_data->encap.len);
3877 [ # # # # : 0 : if (unlikely(act_data->encap.len > MLX5_ENCAP_MAX_LEN))
# # # # #
# ]
3878 : : return -1;
3879 [ # # # # : 0 : rte_memcpy(ap->encap_data, raw_encap_data->data, act_data->encap.len);
# # # # #
# ]
3880 : : break;
3881 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
3882 : 0 : ipv6_push =
3883 : : (const struct rte_flow_action_ipv6_ext_push *)action->conf;
3884 : : MLX5_ASSERT(ipv6_push->size == act_data->ipv6_ext.len);
3885 [ # # # # : 0 : if (unlikely(act_data->ipv6_ext.len > MLX5_PUSH_MAX_LEN))
# # # # #
# ]
3886 : : return -1;
3887 [ # # # # : 0 : rte_memcpy(ap->ipv6_push_data, ipv6_push->data,
# # # # #
# ]
3888 : : act_data->ipv6_ext.len);
3889 : : break;
3890 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3891 [ # # # # : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
# # # # #
# ]
3892 : 0 : ret = flow_hw_set_vlan_vid_construct(dev, ap->mhdr_cmd,
3893 : : act_data,
3894 : : hw_acts,
3895 : : action);
3896 : : else
3897 [ # # # # : 0 : ret = flow_hw_modify_field_construct(ap->mhdr_cmd,
# # # # #
# ]
3898 : : act_data,
3899 : : hw_acts,
3900 : : action);
3901 [ # # # # : 0 : if (ret)
# # # # #
# ]
3902 : 0 : goto error;
3903 : : break;
3904 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3905 : 0 : port_action = action->conf;
3906 [ # # # # : 0 : if (!priv->hw_vport[port_action->port_id])
# # # # #
# ]
3907 : 0 : goto error;
3908 : 0 : rule_acts[act_data->action_dst].action =
3909 : : priv->hw_vport[port_action->port_id];
3910 : 0 : break;
3911 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
3912 : 0 : flow_hw_construct_quota(priv,
3913 : 0 : rule_acts + act_data->action_dst,
3914 : : act_data->shared_meter.id);
3915 : 0 : break;
3916 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
3917 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
3918 : 0 : age = action->conf;
3919 : : /*
3920 : : * First, create the AGE parameter, then create its
3921 : : * counter later:
3922 : : * Regular counter - in next case.
3923 : : * Indirect counter - update it after the loop.
3924 : : */
3925 : 0 : age_idx = mlx5_hws_age_action_create(priv, queue, 0,
3926 : : age,
3927 : : flow->res_idx,
3928 : : error);
3929 [ # # # # : 0 : if (age_idx == 0)
# # # # #
# ]
3930 : 0 : goto error;
3931 : : mlx5_flow_hw_aux_set_age_idx(flow, aux, age_idx);
3932 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX;
3933 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT)
# # # # #
# ]
3934 : : /*
3935 : : * When AGE uses indirect counter, no need to
3936 : : * create counter but need to update it with the
3937 : : * AGE parameter, will be done after the loop.
3938 : : */
3939 : : break;
3940 : : /* Fall-through. */
3941 : : case RTE_FLOW_ACTION_TYPE_COUNT:
3942 : : cnt_queue = mlx5_hws_cnt_get_queue(priv, &queue);
3943 : : ret = mlx5_hws_cnt_pool_get(priv->hws_cpool, cnt_queue, &cnt_id,
3944 : : age_idx, 0);
3945 [ # # # # : 0 : if (ret != 0) {
# # # # #
# ]
3946 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ACTION,
3947 : : action, "Failed to allocate flow counter");
3948 : 0 : goto error;
3949 : : }
3950 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
3951 : : (priv->hws_cpool,
3952 : : cnt_id,
3953 : : &rule_acts[act_data->action_dst].action,
3954 [ # # # # : 0 : &rule_acts[act_data->action_dst].counter.offset,
# # # # #
# ]
3955 : : is_root
3956 : : );
3957 : : if (ret != 0)
3958 : : goto error;
3959 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3960 : 0 : flow->cnt_id = cnt_id;
3961 : 0 : break;
3962 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
3963 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
3964 : : (priv->hws_cpool,
3965 : : act_data->shared_counter.id,
3966 : : &rule_acts[act_data->action_dst].action,
3967 [ # # # # : 0 : &rule_acts[act_data->action_dst].counter.offset,
# # # # #
# ]
3968 : : is_root
3969 : : );
3970 : : if (ret != 0)
3971 : : goto error;
3972 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3973 : 0 : flow->cnt_id = act_data->shared_counter.id;
3974 : 0 : break;
3975 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
3976 : 0 : ct_idx = MLX5_INDIRECT_ACTION_IDX_GET(action->conf);
3977 : 0 : if (flow_hw_ct_compile(dev, queue, ct_idx,
3978 : 0 : &rule_acts[act_data->action_dst]))
3979 : 0 : goto error;
3980 : : break;
3981 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK:
3982 : 0 : mtr_id = act_data->shared_meter.id &
3983 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3984 : : /* Find ASO object. */
3985 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, mtr_id);
3986 [ # # # # : 0 : if (!aso_mtr)
# # # # #
# ]
3987 : 0 : goto error;
3988 : 0 : rule_acts[act_data->action_dst].action =
3989 : 0 : pool->action;
3990 : 0 : rule_acts[act_data->action_dst].aso_meter.offset =
3991 : 0 : aso_mtr->offset;
3992 : 0 : break;
3993 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
3994 : : /*
3995 : : * Allocate meter directly will slow down flow
3996 : : * insertion rate.
3997 : : */
3998 : : ret = flow_hw_meter_mark_compile(dev,
3999 : 0 : act_data->action_dst, action,
4000 : : rule_acts, &mtr_idx, MLX5_HW_INV_QUEUE, error);
4001 : : if (ret != 0)
4002 : 0 : goto error;
4003 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
4004 : : mlx5_flow_hw_aux_set_mtr_id(flow, aux, mtr_idx);
4005 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_MTR_ID;
4006 : 0 : break;
4007 : 0 : case RTE_FLOW_ACTION_TYPE_NAT64:
4008 : 0 : nat64_c = action->conf;
4009 : 0 : rule_acts[act_data->action_dst].action = hw_acts->nat64[nat64_c->type];
4010 : 0 : break;
4011 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
4012 : 0 : jump_table = ((const struct rte_flow_action_jump_to_table_index *)
4013 : 0 : action->conf)->table;
4014 [ # # # # : 0 : if (likely(!rte_flow_template_table_resizable(dev->data->port_id,
# # # # #
# ]
4015 : : &table->cfg.attr))) {
4016 : 0 : rule_acts[act_data->action_dst].action =
4017 : 0 : jump_table->matcher_info[0].jump;
4018 : : } else {
4019 : : uint32_t selector;
4020 : 0 : rte_rwlock_read_lock(&table->matcher_replace_rwlk);
4021 : 0 : selector = table->matcher_selector;
4022 : 0 : rule_acts[act_data->action_dst].action =
4023 : 0 : jump_table->matcher_info[selector].jump;
4024 : 0 : rte_rwlock_read_unlock(&table->matcher_replace_rwlk);
4025 : : }
4026 : 0 : rule_acts[act_data->action_dst].jump_to_matcher.offset =
4027 : : ((const struct rte_flow_action_jump_to_table_index *)
4028 : 0 : action->conf)->index;
4029 : 0 : break;
4030 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_MIRROR: {
4031 : 0 : const struct mlx5_mirror *mirror = action->conf;
4032 : :
4033 : 0 : rule_acts[act_data->action_dst].action = mirror->mirror_action;
4034 : 0 : break;
4035 : : }
4036 : : default:
4037 : : break;
4038 : : }
4039 : : }
4040 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT) {
# # # # #
# ]
4041 : : /* If indirect count is used, then CNT_ID flag should be set. */
4042 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID);
4043 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE) {
# # # # #
# ]
4044 : : /* If indirect AGE is used, then AGE_IDX flag should be set. */
4045 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX);
4046 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
4047 : 0 : age_idx = mlx5_flow_hw_aux_get_age_idx(flow, aux) &
4048 : : MLX5_HWS_AGE_IDX_MASK;
4049 [ # # # # : 0 : if (mlx5_hws_cnt_age_get(priv->hws_cpool, flow->cnt_id) != age_idx)
# # # # #
# # # # #
# # # # #
# ]
4050 : : /*
4051 : : * This is first use of this indirect counter
4052 : : * for this indirect AGE, need to increase the
4053 : : * number of counters.
4054 : : */
4055 : : mlx5_hws_age_nb_cnt_increase(priv, age_idx);
4056 : : }
4057 : : /*
4058 : : * Update this indirect counter the indirect/direct AGE in which
4059 : : * using it.
4060 : : */
4061 [ # # # # : 0 : mlx5_hws_cnt_age_set(priv->hws_cpool, flow->cnt_id, age_idx);
# # # # #
# ]
4062 : : }
4063 [ # # # # : 0 : if (hw_acts->encap_decap && !hw_acts->encap_decap->shared) {
# # # # #
# # # # #
# # # # #
# ]
4064 [ # # # # : 0 : int ix = mlx5_multi_pattern_reformat_to_index(hw_acts->encap_decap->action_type);
# # # # #
# ]
4065 : 0 : struct mlx5dr_rule_action *ra = &rule_acts[hw_acts->encap_decap_pos];
4066 : :
4067 [ # # # # : 0 : if (ix < 0)
# # # # #
# ]
4068 : 0 : goto error;
4069 [ # # # # : 0 : if (!mp_segment)
# # # # #
# ]
4070 : 0 : mp_segment = mlx5_multi_pattern_segment_find(table, flow->res_idx);
4071 [ # # # # : 0 : if (!mp_segment || !mp_segment->reformat_action[ix])
# # # # #
# # # # #
# # # # #
# ]
4072 : 0 : goto error;
4073 : 0 : ra->action = mp_segment->reformat_action[ix];
4074 : : /* reformat offset is relative to selected DR action */
4075 : 0 : ra->reformat.offset = flow->res_idx - mp_segment->head_index;
4076 : 0 : ra->reformat.data = ap->encap_data;
4077 : : }
4078 [ # # # # : 0 : if (hw_acts->push_remove && !hw_acts->push_remove->shared) {
# # # # #
# # # # #
# # # # #
# ]
4079 : 0 : rule_acts[hw_acts->push_remove_pos].ipv6_ext.offset =
4080 : 0 : flow->res_idx - 1;
4081 : 0 : rule_acts[hw_acts->push_remove_pos].ipv6_ext.header = ap->ipv6_push_data;
4082 : : }
4083 [ # # # # : 0 : if (mlx5_hws_cnt_id_valid(hw_acts->cnt_id)) {
# # # # #
# ]
4084 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
4085 : 0 : flow->cnt_id = hw_acts->cnt_id;
4086 : : }
4087 : : return 0;
4088 : :
4089 : 0 : error:
4090 : 0 : flow_hw_release_actions(dev, queue, flow);
4091 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4092 : : NULL, "Action construction failed");
4093 : : }
4094 : :
4095 : : static const struct rte_flow_item *
4096 : 0 : flow_hw_get_rule_items(struct rte_eth_dev *dev,
4097 : : const struct rte_flow_template_table *table,
4098 : : const struct rte_flow_item items[],
4099 : : uint8_t pattern_template_index,
4100 : : struct mlx5_flow_hw_pattern_params *pp)
4101 : : {
4102 : 0 : struct rte_flow_pattern_template *pt = table->its[pattern_template_index];
4103 : :
4104 : : /* Only one implicit item can be added to flow rule pattern. */
4105 : : MLX5_ASSERT(!pt->implicit_port || !pt->implicit_tag);
4106 : : /* At least one item was allocated in pattern params for items. */
4107 : : MLX5_ASSERT(MLX5_HW_MAX_ITEMS >= 1);
4108 [ # # ]: 0 : if (pt->implicit_port) {
4109 [ # # ]: 0 : if (pt->orig_item_nb + 1 > MLX5_HW_MAX_ITEMS) {
4110 : 0 : rte_errno = ENOMEM;
4111 : 0 : return NULL;
4112 : : }
4113 : : /* Set up represented port item in pattern params. */
4114 : 0 : pp->port_spec = (struct rte_flow_item_ethdev){
4115 : 0 : .port_id = dev->data->port_id,
4116 : : };
4117 : 0 : pp->items[0] = (struct rte_flow_item){
4118 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
4119 : 0 : .spec = &pp->port_spec,
4120 : : };
4121 [ # # ]: 0 : rte_memcpy(&pp->items[1], items, sizeof(*items) * pt->orig_item_nb);
4122 : 0 : return pp->items;
4123 [ # # ]: 0 : } else if (pt->implicit_tag) {
4124 [ # # ]: 0 : if (pt->orig_item_nb + 1 > MLX5_HW_MAX_ITEMS) {
4125 : 0 : rte_errno = ENOMEM;
4126 : 0 : return NULL;
4127 : : }
4128 : : /* Set up tag item in pattern params. */
4129 : 0 : pp->tag_spec = (struct rte_flow_item_tag){
4130 : : .data = flow_hw_tx_tag_regc_value(dev),
4131 : : };
4132 : 0 : pp->items[0] = (struct rte_flow_item){
4133 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4134 : 0 : .spec = &pp->tag_spec,
4135 : : };
4136 [ # # ]: 0 : rte_memcpy(&pp->items[1], items, sizeof(*items) * pt->orig_item_nb);
4137 : 0 : return pp->items;
4138 : : } else {
4139 : : return items;
4140 : : }
4141 : : }
4142 : :
4143 : : /**
4144 : : * Enqueue HW steering flow creation.
4145 : : *
4146 : : * The flow will be applied to the HW only if the postpone bit is not set or
4147 : : * the extra push function is called.
4148 : : * The flow creation status should be checked from dequeue result.
4149 : : *
4150 : : * @param[in] dev
4151 : : * Pointer to the rte_eth_dev structure.
4152 : : * @param[in] queue
4153 : : * The queue to create the flow.
4154 : : * @param[in] attr
4155 : : * Pointer to the flow operation attributes.
4156 : : * @param[in] table
4157 : : * Pointer to the template table.
4158 : : * @param[in] insertion_type
4159 : : * Insertion type for flow rules.
4160 : : * @param[in] rule_index
4161 : : * The item pattern flow follows from the table.
4162 : : * @param[in] items
4163 : : * Items with flow spec value.
4164 : : * @param[in] pattern_template_index
4165 : : * The item pattern flow follows from the table.
4166 : : * @param[in] actions
4167 : : * Action with flow spec value.
4168 : : * @param[in] action_template_index
4169 : : * The action pattern flow follows from the table.
4170 : : * @param[in] user_data
4171 : : * Pointer to the user_data.
4172 : : * @param[out] error
4173 : : * Pointer to error structure.
4174 : : *
4175 : : * @return
4176 : : * Flow pointer on success, NULL otherwise and rte_errno is set.
4177 : : */
4178 : : static __rte_always_inline struct rte_flow *
4179 : : flow_hw_async_flow_create_generic(struct rte_eth_dev *dev,
4180 : : uint32_t queue,
4181 : : const struct rte_flow_op_attr *attr,
4182 : : struct rte_flow_template_table *table,
4183 : : enum rte_flow_table_insertion_type insertion_type,
4184 : : uint32_t rule_index,
4185 : : const struct rte_flow_item items[],
4186 : : uint8_t pattern_template_index,
4187 : : const struct rte_flow_action actions[],
4188 : : uint8_t action_template_index,
4189 : : void *user_data,
4190 : : struct rte_flow_error *error)
4191 : : {
4192 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4193 : 0 : struct mlx5dr_rule_attr rule_attr = {
4194 : : .queue_id = queue,
4195 : : .user_data = user_data,
4196 : 0 : .burst = attr->postpone,
4197 : : };
4198 : : struct mlx5dr_rule_action *rule_acts;
4199 : : struct rte_flow_hw *flow = NULL;
4200 : : const struct rte_flow_item *rule_items;
4201 : 0 : struct rte_flow_error sub_error = { 0 };
4202 : 0 : uint32_t flow_idx = 0;
4203 : 0 : uint32_t res_idx = 0;
4204 : : int ret;
4205 : :
4206 : 0 : if (mlx5_fp_debug_enabled()) {
4207 [ # # # # : 0 : if (flow_hw_async_create_validate(dev, queue, table, insertion_type, rule_index,
# # ]
4208 : : items, pattern_template_index, actions, action_template_index, error))
4209 : : return NULL;
4210 : : }
4211 : 0 : flow = mlx5_ipool_malloc(table->flow_pool, &flow_idx);
4212 [ # # # # : 0 : if (!flow) {
# # ]
4213 : 0 : rte_errno = ENOMEM;
4214 : 0 : goto error;
4215 : : }
4216 : 0 : flow->nt_rule = false;
4217 : : rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
4218 : : /*
4219 : : * Set the table here in order to know the destination table
4220 : : * when free the flow afterward.
4221 : : */
4222 : 0 : flow->table = table;
4223 : 0 : flow->mt_idx = pattern_template_index;
4224 : 0 : flow->idx = flow_idx;
4225 [ # # # # : 0 : if (table->resource) {
# # ]
4226 : 0 : mlx5_ipool_malloc(table->resource, &res_idx);
4227 [ # # # # : 0 : if (!res_idx) {
# # ]
4228 : 0 : rte_errno = ENOMEM;
4229 : 0 : goto error;
4230 : : }
4231 : 0 : flow->res_idx = res_idx;
4232 : : } else {
4233 : 0 : flow->res_idx = flow_idx;
4234 : : }
4235 : 0 : flow->flags = 0;
4236 : : /*
4237 : : * Set the flow operation type here in order to know if the flow memory
4238 : : * should be freed or not when get the result from dequeue.
4239 : : */
4240 : 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_CREATE;
4241 : 0 : flow->user_data = user_data;
4242 : 0 : rule_attr.user_data = flow;
4243 : : /*
4244 : : * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
4245 : : * for rule insertion hints.
4246 : : */
4247 [ # # # # ]: 0 : flow->rule_idx = (rule_index == UINT32_MAX) ? flow->res_idx - 1 : rule_index;
4248 : 0 : rule_attr.rule_idx = flow->rule_idx;
4249 : : /*
4250 : : * Construct the flow actions based on the input actions.
4251 : : * The implicitly appended action is always fixed, like metadata
4252 : : * copy action from FDB to NIC Rx.
4253 : : * No need to copy and contrust a new "actions" list based on the
4254 : : * user's input, in order to save the cost.
4255 : : */
4256 [ # # # # : 0 : if (flow_hw_actions_construct(dev, flow, &priv->hw_q[queue].ap,
# # ]
4257 : 0 : &table->ats[action_template_index],
4258 [ # # # # : 0 : table->its[pattern_template_index]->item_flags,
# # ]
4259 : : flow->table, actions,
4260 : : rule_acts, queue, &sub_error))
4261 : 0 : goto error;
4262 : : if (insertion_type == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX) {
4263 : : rule_items = items;
4264 : : } else {
4265 : 0 : rule_items = flow_hw_get_rule_items(dev, table, items,
4266 : 0 : pattern_template_index, &priv->hw_q[queue].pp);
4267 [ # # # # ]: 0 : if (!rule_items)
4268 : 0 : goto error;
4269 : : }
4270 [ # # # # : 0 : if (likely(!rte_flow_template_table_resizable(dev->data->port_id, &table->cfg.attr))) {
# # ]
4271 : 0 : ret = mlx5dr_rule_create(table->matcher_info[0].matcher,
4272 : : pattern_template_index, rule_items,
4273 : : action_template_index, rule_acts,
4274 : : &rule_attr,
4275 : 0 : (struct mlx5dr_rule *)flow->rule);
4276 : : } else {
4277 [ # # # # : 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # ]
4278 : : uint32_t selector;
4279 : :
4280 : 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE;
4281 : 0 : rte_rwlock_read_lock(&table->matcher_replace_rwlk);
4282 : 0 : selector = table->matcher_selector;
4283 : 0 : ret = mlx5dr_rule_create(table->matcher_info[selector].matcher,
4284 : : pattern_template_index, rule_items,
4285 : : action_template_index, rule_acts,
4286 : : &rule_attr,
4287 : 0 : (struct mlx5dr_rule *)flow->rule);
4288 : 0 : rte_rwlock_read_unlock(&table->matcher_replace_rwlk);
4289 : 0 : aux->matcher_selector = selector;
4290 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR;
4291 : : }
4292 : :
4293 [ # # # # : 0 : if (likely(!ret)) {
# # ]
4294 : 0 : flow_hw_q_inc_flow_ops(priv, queue);
4295 : 0 : return (struct rte_flow *)flow;
4296 : : }
4297 : 0 : error:
4298 [ # # # # : 0 : if (table->resource && res_idx)
# # # # #
# # # ]
4299 : 0 : mlx5_ipool_free(table->resource, res_idx);
4300 [ # # # # : 0 : if (flow_idx)
# # ]
4301 : 0 : mlx5_ipool_free(table->flow_pool, flow_idx);
4302 [ # # # # : 0 : if (sub_error.cause != RTE_FLOW_ERROR_TYPE_NONE && error != NULL)
# # # # #
# # # ]
4303 : 0 : *error = sub_error;
4304 : : else
4305 : 0 : rte_flow_error_set(error, rte_errno,
4306 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4307 : : "fail to create rte flow");
4308 : : return NULL;
4309 : : }
4310 : :
4311 : : static struct rte_flow *
4312 : 0 : flow_hw_async_flow_create(struct rte_eth_dev *dev,
4313 : : uint32_t queue,
4314 : : const struct rte_flow_op_attr *attr,
4315 : : struct rte_flow_template_table *table,
4316 : : const struct rte_flow_item items[],
4317 : : uint8_t pattern_template_index,
4318 : : const struct rte_flow_action actions[],
4319 : : uint8_t action_template_index,
4320 : : void *user_data,
4321 : : struct rte_flow_error *error)
4322 : : {
4323 : : uint32_t rule_index = UINT32_MAX;
4324 : :
4325 [ # # ]: 0 : return flow_hw_async_flow_create_generic(dev, queue, attr, table,
4326 : : RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN, rule_index,
4327 : : items, pattern_template_index, actions, action_template_index,
4328 : : user_data, error);
4329 : : }
4330 : :
4331 : : static struct rte_flow *
4332 : 0 : flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
4333 : : uint32_t queue,
4334 : : const struct rte_flow_op_attr *attr,
4335 : : struct rte_flow_template_table *table,
4336 : : uint32_t rule_index,
4337 : : const struct rte_flow_action actions[],
4338 : : uint8_t action_template_index,
4339 : : void *user_data,
4340 : : struct rte_flow_error *error)
4341 : : {
4342 : 0 : struct rte_flow_item items[] = {{.type = RTE_FLOW_ITEM_TYPE_END,}};
4343 : : uint8_t pattern_template_index = 0;
4344 : :
4345 [ # # ]: 0 : return flow_hw_async_flow_create_generic(dev, queue, attr, table,
4346 : : RTE_FLOW_TABLE_INSERTION_TYPE_INDEX, rule_index,
4347 : : items, pattern_template_index, actions, action_template_index,
4348 : : user_data, error);
4349 : : }
4350 : :
4351 : : static struct rte_flow *
4352 : 0 : flow_hw_async_flow_create_by_index_with_pattern(struct rte_eth_dev *dev,
4353 : : uint32_t queue,
4354 : : const struct rte_flow_op_attr *attr,
4355 : : struct rte_flow_template_table *table,
4356 : : uint32_t rule_index,
4357 : : const struct rte_flow_item items[],
4358 : : uint8_t pattern_template_index,
4359 : : const struct rte_flow_action actions[],
4360 : : uint8_t action_template_index,
4361 : : void *user_data,
4362 : : struct rte_flow_error *error)
4363 : : {
4364 [ # # ]: 0 : return flow_hw_async_flow_create_generic(dev, queue, attr, table,
4365 : : RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN, rule_index,
4366 : : items, pattern_template_index, actions, action_template_index,
4367 : : user_data, error);
4368 : : }
4369 : :
4370 : : /**
4371 : : * Enqueue HW steering flow update.
4372 : : *
4373 : : * The flow will be applied to the HW only if the postpone bit is not set or
4374 : : * the extra push function is called.
4375 : : * The flow destruction status should be checked from dequeue result.
4376 : : *
4377 : : * @param[in] dev
4378 : : * Pointer to the rte_eth_dev structure.
4379 : : * @param[in] queue
4380 : : * The queue to destroy the flow.
4381 : : * @param[in] attr
4382 : : * Pointer to the flow operation attributes.
4383 : : * @param[in] flow
4384 : : * Pointer to the flow to be destroyed.
4385 : : * @param[in] actions
4386 : : * Action with flow spec value.
4387 : : * @param[in] action_template_index
4388 : : * The action pattern flow follows from the table.
4389 : : * @param[in] user_data
4390 : : * Pointer to the user_data.
4391 : : * @param[out] error
4392 : : * Pointer to error structure.
4393 : : *
4394 : : * @return
4395 : : * 0 on success, negative value otherwise and rte_errno is set.
4396 : : */
4397 : : static int
4398 : 0 : flow_hw_async_flow_update(struct rte_eth_dev *dev,
4399 : : uint32_t queue,
4400 : : const struct rte_flow_op_attr *attr,
4401 : : struct rte_flow *flow,
4402 : : const struct rte_flow_action actions[],
4403 : : uint8_t action_template_index,
4404 : : void *user_data,
4405 : : struct rte_flow_error *error)
4406 : : {
4407 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4408 : 0 : struct mlx5dr_rule_attr rule_attr = {
4409 : : .queue_id = queue,
4410 : : .user_data = user_data,
4411 : 0 : .burst = attr->postpone,
4412 : : };
4413 : : struct mlx5dr_rule_action *rule_acts;
4414 : : struct rte_flow_hw *of = (struct rte_flow_hw *)flow;
4415 : : struct rte_flow_hw *nf;
4416 : : struct rte_flow_hw_aux *aux;
4417 : 0 : struct rte_flow_template_table *table = of->table;
4418 : 0 : uint32_t res_idx = 0;
4419 : : int ret;
4420 : :
4421 [ # # ]: 0 : if (mlx5_fp_debug_enabled()) {
4422 [ # # ]: 0 : if (flow_hw_async_update_validate(dev, queue, of, actions, action_template_index,
4423 : : error))
4424 : 0 : return -rte_errno;
4425 : : }
4426 [ # # ]: 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, of);
4427 : 0 : nf = &aux->upd_flow;
4428 : 0 : nf->nt_rule = false;
4429 : 0 : rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
4430 : : /*
4431 : : * Set the table here in order to know the destination table
4432 : : * when free the flow afterwards.
4433 : : */
4434 : 0 : nf->table = table;
4435 : 0 : nf->mt_idx = of->mt_idx;
4436 : 0 : nf->idx = of->idx;
4437 [ # # ]: 0 : if (table->resource) {
4438 : 0 : mlx5_ipool_malloc(table->resource, &res_idx);
4439 [ # # ]: 0 : if (!res_idx) {
4440 : 0 : rte_errno = ENOMEM;
4441 : 0 : goto error;
4442 : : }
4443 : 0 : nf->res_idx = res_idx;
4444 : : } else {
4445 : 0 : nf->res_idx = of->res_idx;
4446 : : }
4447 : 0 : nf->flags = 0;
4448 : : /* Indicate the construction function to set the proper fields. */
4449 : 0 : nf->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE;
4450 : : /*
4451 : : * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
4452 : : * for rule insertion hints.
4453 : : * If there is only one STE, the update will be atomic by nature.
4454 : : */
4455 : 0 : nf->rule_idx = nf->res_idx - 1;
4456 : 0 : rule_attr.rule_idx = nf->rule_idx;
4457 : : /*
4458 : : * Construct the flow actions based on the input actions.
4459 : : * The implicitly appended action is always fixed, like metadata
4460 : : * copy action from FDB to NIC Rx.
4461 : : * No need to copy and contrust a new "actions" list based on the
4462 : : * user's input, in order to save the cost.
4463 : : */
4464 [ # # ]: 0 : if (flow_hw_actions_construct(dev, nf, &priv->hw_q[queue].ap,
4465 : 0 : &table->ats[action_template_index],
4466 [ # # ]: 0 : table->its[nf->mt_idx]->item_flags,
4467 : : table, actions,
4468 : : rule_acts, queue, error)) {
4469 : 0 : rte_errno = EINVAL;
4470 : 0 : goto error;
4471 : : }
4472 : : /*
4473 : : * Set the flow operation type here in order to know if the flow memory
4474 : : * should be freed or not when get the result from dequeue.
4475 : : */
4476 : 0 : of->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE;
4477 : 0 : of->user_data = user_data;
4478 : 0 : of->flags |= MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW;
4479 : 0 : rule_attr.user_data = of;
4480 : 0 : ret = mlx5dr_rule_action_update((struct mlx5dr_rule *)of->rule,
4481 : : action_template_index, rule_acts, &rule_attr);
4482 [ # # ]: 0 : if (likely(!ret)) {
4483 : 0 : flow_hw_q_inc_flow_ops(priv, queue);
4484 : 0 : return 0;
4485 : : }
4486 : 0 : error:
4487 [ # # # # ]: 0 : if (table->resource && res_idx)
4488 : 0 : mlx5_ipool_free(table->resource, res_idx);
4489 : 0 : return rte_flow_error_set(error, rte_errno,
4490 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4491 : : "fail to update rte flow");
4492 : : }
4493 : :
4494 : : /**
4495 : : * Enqueue HW steering flow destruction.
4496 : : *
4497 : : * The flow will be applied to the HW only if the postpone bit is not set or
4498 : : * the extra push function is called.
4499 : : * The flow destruction status should be checked from dequeue result.
4500 : : *
4501 : : * @param[in] dev
4502 : : * Pointer to the rte_eth_dev structure.
4503 : : * @param[in] queue
4504 : : * The queue to destroy the flow.
4505 : : * @param[in] attr
4506 : : * Pointer to the flow operation attributes.
4507 : : * @param[in] flow
4508 : : * Pointer to the flow to be destroyed.
4509 : : * @param[in] user_data
4510 : : * Pointer to the user_data.
4511 : : * @param[out] error
4512 : : * Pointer to error structure.
4513 : : *
4514 : : * @return
4515 : : * 0 on success, negative value otherwise and rte_errno is set.
4516 : : */
4517 : : static int
4518 : 0 : flow_hw_async_flow_destroy(struct rte_eth_dev *dev,
4519 : : uint32_t queue,
4520 : : const struct rte_flow_op_attr *attr,
4521 : : struct rte_flow *flow,
4522 : : void *user_data,
4523 : : struct rte_flow_error *error)
4524 : : {
4525 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4526 : 0 : struct mlx5dr_rule_attr rule_attr = {
4527 : : .queue_id = queue,
4528 : : .user_data = user_data,
4529 : 0 : .burst = attr->postpone,
4530 : : };
4531 : : struct rte_flow_hw *fh = (struct rte_flow_hw *)flow;
4532 : 0 : bool resizable = rte_flow_template_table_resizable(dev->data->port_id,
4533 : 0 : &fh->table->cfg.attr);
4534 : : int ret;
4535 : :
4536 : : if (mlx5_fp_debug_enabled()) {
4537 : : if (flow_hw_async_destroy_validate(dev, queue, fh, error))
4538 : : return -rte_errno;
4539 : : }
4540 [ # # ]: 0 : fh->operation_type = !resizable ?
4541 : : MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY :
4542 : : MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY;
4543 : 0 : fh->user_data = user_data;
4544 : 0 : rule_attr.user_data = fh;
4545 : 0 : rule_attr.rule_idx = fh->rule_idx;
4546 : 0 : ret = mlx5dr_rule_destroy((struct mlx5dr_rule *)fh->rule, &rule_attr);
4547 [ # # ]: 0 : if (ret) {
4548 : 0 : return rte_flow_error_set(error, rte_errno,
4549 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4550 : : "fail to destroy rte flow");
4551 : : }
4552 : : flow_hw_q_inc_flow_ops(priv, queue);
4553 : 0 : return 0;
4554 : : }
4555 : :
4556 : : /**
4557 : : * Release the AGE and counter for given flow.
4558 : : *
4559 : : * @param[in] priv
4560 : : * Pointer to the port private data structure.
4561 : : * @param[in] queue
4562 : : * The queue to release the counter.
4563 : : * @param[in, out] flow
4564 : : * Pointer to the flow containing the counter.
4565 : : * @param[out] error
4566 : : * Pointer to error structure.
4567 : : */
4568 : : static void
4569 : 0 : flow_hw_age_count_release(struct mlx5_priv *priv, uint32_t queue,
4570 : : struct rte_flow_hw *flow,
4571 : : struct rte_flow_error *error)
4572 : : {
4573 [ # # ]: 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(priv->dev_data->port_id, flow);
4574 : : uint32_t *cnt_queue;
4575 : 0 : uint32_t age_idx = aux->orig.age_idx;
4576 : :
4577 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID);
4578 [ # # # # ]: 0 : if (mlx5_hws_cnt_is_shared(priv->hws_cpool, flow->cnt_id)) {
4579 [ # # # # ]: 0 : if ((flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX) &&
4580 : : !mlx5_hws_age_is_indirect(age_idx)) {
4581 : : /* Remove this AGE parameter from indirect counter. */
4582 [ # # ]: 0 : mlx5_hws_cnt_age_set(priv->hws_cpool, flow->cnt_id, 0);
4583 : : /* Release the AGE parameter. */
4584 : 0 : mlx5_hws_age_action_destroy(priv, age_idx, error);
4585 : : }
4586 : 0 : return;
4587 : : }
4588 : : cnt_queue = mlx5_hws_cnt_get_queue(priv, &queue);
4589 : : /* Put the counter first to reduce the race risk in BG thread. */
4590 [ # # ]: 0 : mlx5_hws_cnt_pool_put(priv->hws_cpool, cnt_queue, &flow->cnt_id);
4591 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX) {
4592 [ # # ]: 0 : if (mlx5_hws_age_is_indirect(age_idx)) {
4593 : 0 : uint32_t idx = age_idx & MLX5_HWS_AGE_IDX_MASK;
4594 : :
4595 : : mlx5_hws_age_nb_cnt_decrease(priv, idx);
4596 : : } else {
4597 : : /* Release the AGE parameter. */
4598 : 0 : mlx5_hws_age_action_destroy(priv, age_idx, error);
4599 : : }
4600 : : }
4601 : : }
4602 : :
4603 : : static __rte_always_inline void
4604 : : flow_hw_pull_legacy_indirect_comp(struct rte_eth_dev *dev, struct mlx5_hw_q_job *job,
4605 : : uint32_t queue)
4606 : : {
4607 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4608 : : struct mlx5_aso_ct_action *aso_ct;
4609 : : struct mlx5_aso_mtr *aso_mtr;
4610 : : uint32_t type, idx;
4611 : :
4612 [ # # ]: 0 : if (MLX5_INDIRECT_ACTION_TYPE_GET(job->action) ==
4613 : : MLX5_INDIRECT_ACTION_TYPE_QUOTA) {
4614 : 0 : mlx5_quota_async_completion(dev, queue, job);
4615 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_DESTROY) {
4616 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
4617 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK) {
4618 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4619 : 0 : mlx5_ipool_free(priv->hws_mpool->idx_pool, idx);
4620 : : }
4621 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_CREATE) {
4622 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
4623 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK) {
4624 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4625 : 0 : aso_mtr = mlx5_ipool_get(priv->hws_mpool->idx_pool, idx);
4626 : 0 : aso_mtr->state = ASO_METER_READY;
4627 [ # # ]: 0 : } else if (type == MLX5_INDIRECT_ACTION_TYPE_CT) {
4628 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4629 : 0 : aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
4630 : 0 : aso_ct->state = ASO_CONNTRACK_READY;
4631 : : }
4632 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_QUERY) {
4633 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
4634 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_CT) {
4635 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4636 : 0 : aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
4637 : 0 : mlx5_aso_ct_obj_analyze(job->query.user,
4638 : 0 : job->query.hw);
4639 : 0 : aso_ct->state = ASO_CONNTRACK_READY;
4640 : : }
4641 : : }
4642 : : }
4643 : :
4644 : : static __rte_always_inline int
4645 : : mlx5_hw_pull_flow_transfer_comp(struct rte_eth_dev *dev,
4646 : : uint32_t queue, struct rte_flow_op_result res[],
4647 : : uint16_t n_res)
4648 : : {
4649 : : uint32_t size, i;
4650 : 0 : struct rte_flow_hw *flow = NULL;
4651 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4652 : 0 : struct rte_ring *ring = priv->hw_q[queue].flow_transfer_completed;
4653 : :
4654 : 0 : if (ring == NULL)
4655 : : return 0;
4656 : :
4657 : 0 : size = RTE_MIN(rte_ring_count(ring), n_res);
4658 [ # # ]: 0 : for (i = 0; i < size; i++) {
4659 [ # # # # : 0 : res[i].status = RTE_FLOW_OP_SUCCESS;
# ]
4660 : : rte_ring_dequeue(ring, (void **)&flow);
4661 : 0 : res[i].user_data = flow->user_data;
4662 : : flow_hw_q_dec_flow_ops(priv, queue);
4663 : : }
4664 : 0 : return (int)size;
4665 : : }
4666 : :
4667 : : static inline int
4668 : 0 : __flow_hw_pull_indir_action_comp(struct rte_eth_dev *dev,
4669 : : uint32_t queue,
4670 : : struct rte_flow_op_result res[],
4671 : : uint16_t n_res)
4672 : :
4673 : : {
4674 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4675 : 0 : struct rte_ring *r = priv->hw_q[queue].indir_cq;
4676 : 0 : void *user_data = NULL;
4677 : : int ret_comp, i;
4678 : :
4679 : 0 : ret_comp = (int)rte_ring_count(r);
4680 : 0 : if (ret_comp > n_res)
4681 : : ret_comp = n_res;
4682 [ # # ]: 0 : for (i = 0; i < ret_comp; i++) {
4683 : : rte_ring_dequeue(r, &user_data);
4684 : 0 : res[i].user_data = user_data;
4685 : 0 : res[i].status = RTE_FLOW_OP_SUCCESS;
4686 : : }
4687 [ # # ]: 0 : if (!priv->shared_host) {
4688 [ # # # # ]: 0 : if (ret_comp < n_res && priv->hws_mpool)
4689 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->hws_mpool->sq[queue],
4690 : 0 : &res[ret_comp], n_res - ret_comp);
4691 [ # # # # ]: 0 : if (ret_comp < n_res && priv->hws_ctpool)
4692 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->ct_mng->aso_sqs[queue],
4693 : 0 : &res[ret_comp], n_res - ret_comp);
4694 : : }
4695 [ # # # # ]: 0 : if (ret_comp < n_res && priv->quota_ctx.sq)
4696 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->quota_ctx.sq[queue],
4697 : 0 : &res[ret_comp],
4698 : 0 : n_res - ret_comp);
4699 [ # # ]: 0 : for (i = 0; i < ret_comp; i++) {
4700 : 0 : struct mlx5_hw_q_job *job = (struct mlx5_hw_q_job *)res[i].user_data;
4701 : :
4702 : : /* Restore user data. */
4703 : 0 : res[i].user_data = job->user_data;
4704 [ # # ]: 0 : if (job->indirect_type == MLX5_HW_INDIRECT_TYPE_LEGACY)
4705 : : flow_hw_pull_legacy_indirect_comp(dev, job, queue);
4706 : : /*
4707 : : * Current PMD supports 2 indirect action list types - MIRROR and REFORMAT.
4708 : : * These indirect list types do not post WQE to create action.
4709 : : * Future indirect list types that do post WQE will add
4710 : : * completion handlers here.
4711 : : */
4712 : : flow_hw_job_put(priv, job, queue);
4713 : : }
4714 : 0 : return ret_comp;
4715 : : }
4716 : :
4717 : : static __rte_always_inline void
4718 : : hw_cmpl_flow_update_or_destroy(struct rte_eth_dev *dev,
4719 : : struct rte_flow_hw *flow,
4720 : : uint32_t queue, struct rte_flow_error *error)
4721 : : {
4722 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4723 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
4724 : 0 : struct rte_flow_template_table *table = flow->table;
4725 : : /* Release the original resource index in case of update. */
4726 : 0 : uint32_t res_idx = flow->res_idx;
4727 : :
4728 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAGS_ALL) {
4729 [ # # # # : 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # ]
4730 : :
4731 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP)
# # ]
4732 : 0 : flow_hw_jump_release(dev, flow->jump);
4733 [ # # # # : 0 : else if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ)
# # ]
4734 : 0 : mlx5_hrxq_obj_release(dev, flow->hrxq);
4735 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID)
# # ]
4736 : 0 : flow_hw_age_count_release(priv, queue, flow, error);
4737 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MTR_ID)
# # ]
4738 : 0 : mlx5_ipool_free(pool->idx_pool, aux->orig.mtr_id);
4739 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW) {
# # ]
4740 : : struct rte_flow_hw *upd_flow = &aux->upd_flow;
4741 : :
4742 : : rte_memcpy(flow, upd_flow, offsetof(struct rte_flow_hw, rule));
4743 : 0 : aux->orig = aux->upd;
4744 : 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_CREATE;
4745 [ # # # # : 0 : if (!flow->nt_rule && table->resource)
# # # # #
# # # ]
4746 : 0 : mlx5_ipool_free(table->resource, res_idx);
4747 : : }
4748 : : }
4749 [ # # # # : 0 : if (flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY ||
# # ]
4750 : : flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY) {
4751 [ # # # # : 0 : if (!flow->nt_rule) {
# # ]
4752 [ # # # # : 0 : if (table->resource)
# # ]
4753 : 0 : mlx5_ipool_free(table->resource, res_idx);
4754 [ # # # # : 0 : if (table->flow_pool)
# # ]
4755 : 0 : mlx5_ipool_free(table->flow_pool, flow->idx);
4756 : : }
4757 : : }
4758 : : }
4759 : :
4760 : : static __rte_always_inline void
4761 : : hw_cmpl_resizable_tbl(struct rte_eth_dev *dev,
4762 : : struct rte_flow_hw *flow,
4763 : : uint32_t queue, enum rte_flow_op_status status,
4764 : : struct rte_flow_error *error)
4765 : : {
4766 : 0 : struct rte_flow_template_table *table = flow->table;
4767 : 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
4768 : 0 : uint32_t selector = aux->matcher_selector;
4769 : 0 : uint32_t other_selector = (selector + 1) & 1;
4770 : :
4771 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR);
4772 [ # # # # ]: 0 : switch (flow->operation_type) {
4773 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE:
4774 : 0 : rte_atomic_fetch_add_explicit
4775 : : (&table->matcher_info[selector].refcnt, 1,
4776 : : rte_memory_order_relaxed);
4777 : 0 : break;
4778 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY:
4779 [ # # ]: 0 : rte_atomic_fetch_sub_explicit
4780 : : (&table->matcher_info[selector].refcnt, 1,
4781 : : rte_memory_order_relaxed);
4782 : : hw_cmpl_flow_update_or_destroy(dev, flow, queue, error);
4783 : : break;
4784 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE:
4785 [ # # ]: 0 : if (status == RTE_FLOW_OP_SUCCESS) {
4786 : 0 : rte_atomic_fetch_sub_explicit
4787 : : (&table->matcher_info[selector].refcnt, 1,
4788 : : rte_memory_order_relaxed);
4789 : 0 : rte_atomic_fetch_add_explicit
4790 : : (&table->matcher_info[other_selector].refcnt, 1,
4791 : : rte_memory_order_relaxed);
4792 : 0 : aux->matcher_selector = other_selector;
4793 : : }
4794 : : break;
4795 : : default:
4796 : : break;
4797 : : }
4798 : : }
4799 : :
4800 : : /**
4801 : : * Pull the enqueued flows.
4802 : : *
4803 : : * For flows enqueued from creation/destruction, the status should be
4804 : : * checked from the dequeue result.
4805 : : *
4806 : : * @param[in] dev
4807 : : * Pointer to the rte_eth_dev structure.
4808 : : * @param[in] queue
4809 : : * The queue to pull the result.
4810 : : * @param[in/out] res
4811 : : * Array to save the results.
4812 : : * @param[in] n_res
4813 : : * Available result with the array.
4814 : : * @param[out] error
4815 : : * Pointer to error structure.
4816 : : *
4817 : : * @return
4818 : : * Result number on success, negative value otherwise and rte_errno is set.
4819 : : */
4820 : : static int
4821 : 0 : flow_hw_pull(struct rte_eth_dev *dev,
4822 : : uint32_t queue,
4823 : : struct rte_flow_op_result res[],
4824 : : uint16_t n_res,
4825 : : struct rte_flow_error *error)
4826 : : {
4827 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4828 : : int ret, i;
4829 : :
4830 : : /* 1. Pull the flow completion. */
4831 : 0 : ret = mlx5dr_send_queue_poll(priv->dr_ctx, queue, res, n_res);
4832 [ # # ]: 0 : if (ret < 0)
4833 : 0 : return rte_flow_error_set(error, rte_errno,
4834 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4835 : : "fail to query flow queue");
4836 [ # # ]: 0 : for (i = 0; i < ret; i++) {
4837 : 0 : struct rte_flow_hw *flow = res[i].user_data;
4838 : :
4839 : : /* Restore user data. */
4840 : 0 : res[i].user_data = flow->user_data;
4841 [ # # # ]: 0 : switch (flow->operation_type) {
4842 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY:
4843 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE:
4844 : : hw_cmpl_flow_update_or_destroy(dev, flow, queue, error);
4845 : : break;
4846 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE:
4847 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY:
4848 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE:
4849 [ # # ]: 0 : hw_cmpl_resizable_tbl(dev, flow, queue, res[i].status, error);
4850 : : break;
4851 : : default:
4852 : : break;
4853 : : }
4854 : : flow_hw_q_dec_flow_ops(priv, queue);
4855 : : }
4856 : : /* 2. Pull indirect action comp. */
4857 [ # # ]: 0 : if (ret < n_res)
4858 : 0 : ret += __flow_hw_pull_indir_action_comp(dev, queue, &res[ret],
4859 : 0 : n_res - ret);
4860 [ # # ]: 0 : if (ret < n_res)
4861 : 0 : ret += mlx5_hw_pull_flow_transfer_comp(dev, queue, &res[ret],
4862 [ # # ]: 0 : n_res - ret);
4863 : :
4864 : : return ret;
4865 : : }
4866 : :
4867 : : static uint32_t
4868 : 0 : mlx5_hw_push_queue(struct rte_ring *pending_q, struct rte_ring *cmpl_q)
4869 : : {
4870 : 0 : void *job = NULL;
4871 : : uint32_t i, size = rte_ring_count(pending_q);
4872 : :
4873 [ # # ]: 0 : for (i = 0; i < size; i++) {
4874 : : rte_ring_dequeue(pending_q, &job);
4875 [ # # # # : 0 : rte_ring_enqueue(cmpl_q, job);
# ]
4876 : : }
4877 : 0 : return size;
4878 : : }
4879 : :
4880 : : static inline uint32_t
4881 : 0 : __flow_hw_push_action(struct rte_eth_dev *dev,
4882 : : uint32_t queue)
4883 : : {
4884 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4885 : 0 : struct mlx5_hw_q *hw_q = &priv->hw_q[queue];
4886 : :
4887 : 0 : mlx5_hw_push_queue(hw_q->indir_iq, hw_q->indir_cq);
4888 [ # # # # ]: 0 : if (hw_q->flow_transfer_pending != NULL && hw_q->flow_transfer_completed != NULL)
4889 : 0 : mlx5_hw_push_queue(hw_q->flow_transfer_pending,
4890 : : hw_q->flow_transfer_completed);
4891 [ # # ]: 0 : if (!priv->shared_host) {
4892 [ # # ]: 0 : if (priv->hws_ctpool)
4893 : 0 : mlx5_aso_push_wqe(priv->sh,
4894 : 0 : &priv->ct_mng->aso_sqs[queue]);
4895 [ # # ]: 0 : if (priv->hws_mpool)
4896 : 0 : mlx5_aso_push_wqe(priv->sh,
4897 : 0 : &priv->hws_mpool->sq[queue]);
4898 : : }
4899 : 0 : return flow_hw_q_pending(priv, queue);
4900 : : }
4901 : :
4902 : : static int
4903 : 0 : __flow_hw_push(struct rte_eth_dev *dev,
4904 : : uint32_t queue,
4905 : : struct rte_flow_error *error)
4906 : : {
4907 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4908 : : int ret, num;
4909 : :
4910 : 0 : num = __flow_hw_push_action(dev, queue);
4911 : 0 : ret = mlx5dr_send_queue_action(priv->dr_ctx, queue,
4912 : : MLX5DR_SEND_QUEUE_ACTION_DRAIN_ASYNC);
4913 [ # # ]: 0 : if (ret) {
4914 : 0 : rte_flow_error_set(error, rte_errno,
4915 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4916 : : "fail to push flows");
4917 : 0 : return ret;
4918 : : }
4919 : : return num;
4920 : : }
4921 : :
4922 : : /**
4923 : : * Push the enqueued flows to HW.
4924 : : *
4925 : : * Force apply all the enqueued flows to the HW.
4926 : : *
4927 : : * @param[in] dev
4928 : : * Pointer to the rte_eth_dev structure.
4929 : : * @param[in] queue
4930 : : * The queue to push the flow.
4931 : : * @param[out] error
4932 : : * Pointer to error structure.
4933 : : *
4934 : : * @return
4935 : : * 0 on success, negative value otherwise and rte_errno is set.
4936 : : */
4937 : : static int
4938 : 0 : flow_hw_push(struct rte_eth_dev *dev,
4939 : : uint32_t queue, struct rte_flow_error *error)
4940 : : {
4941 : 0 : int ret = __flow_hw_push(dev, queue, error);
4942 : :
4943 : 0 : return ret >= 0 ? 0 : ret;
4944 : : }
4945 : :
4946 : : /**
4947 : : * Drain the enqueued flows' completion.
4948 : : *
4949 : : * @param[in] dev
4950 : : * Pointer to the rte_eth_dev structure.
4951 : : * @param[in] queue
4952 : : * The queue to pull the flow.
4953 : : * @param[out] error
4954 : : * Pointer to error structure.
4955 : : *
4956 : : * @return
4957 : : * 0 on success, negative value otherwise and rte_errno is set.
4958 : : */
4959 : : static int
4960 : 0 : __flow_hw_pull_comp(struct rte_eth_dev *dev,
4961 : : uint32_t queue, struct rte_flow_error *error)
4962 : : {
4963 : : struct rte_flow_op_result comp[BURST_THR];
4964 : : int ret, i, empty_loop = 0;
4965 : : uint32_t pending_rules;
4966 : :
4967 : 0 : ret = __flow_hw_push(dev, queue, error);
4968 [ # # ]: 0 : if (ret < 0)
4969 : : return ret;
4970 : 0 : pending_rules = ret;
4971 [ # # ]: 0 : while (pending_rules) {
4972 : 0 : ret = flow_hw_pull(dev, queue, comp, BURST_THR, error);
4973 [ # # ]: 0 : if (ret < 0)
4974 : : return -1;
4975 [ # # ]: 0 : if (!ret) {
4976 : 0 : rte_delay_us_sleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY);
4977 [ # # ]: 0 : if (++empty_loop > 5) {
4978 : 0 : DRV_LOG(WARNING, "No available dequeue %u, quit.", pending_rules);
4979 : 0 : break;
4980 : : }
4981 : 0 : continue;
4982 : : }
4983 [ # # ]: 0 : for (i = 0; i < ret; i++) {
4984 [ # # ]: 0 : if (comp[i].status == RTE_FLOW_OP_ERROR)
4985 : 0 : DRV_LOG(WARNING, "Flow flush get error CQE.");
4986 : : }
4987 : : /*
4988 : : * Indirect **SYNC** METER_MARK and CT actions do not
4989 : : * remove completion after WQE post.
4990 : : * That implementation avoids HW timeout.
4991 : : * The completion is removed before the following WQE post.
4992 : : * However, HWS queue updates do not reflect that behaviour.
4993 : : * Therefore, during port destruction sync queue may have
4994 : : * pending completions.
4995 : : */
4996 : 0 : pending_rules -= RTE_MIN(pending_rules, (uint32_t)ret);
4997 : : empty_loop = 0;
4998 : : }
4999 : : return 0;
5000 : : }
5001 : :
5002 : : /**
5003 : : * Flush created flows.
5004 : : *
5005 : : * @param[in] dev
5006 : : * Pointer to the rte_eth_dev structure.
5007 : : * @param[out] error
5008 : : * Pointer to error structure.
5009 : : *
5010 : : * @return
5011 : : * 0 on success, negative value otherwise and rte_errno is set.
5012 : : */
5013 : : int
5014 : 0 : mlx5_flow_hw_q_flow_flush(struct rte_eth_dev *dev,
5015 : : struct rte_flow_error *error)
5016 : : {
5017 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5018 : 0 : struct mlx5_hw_q *hw_q = &priv->hw_q[MLX5_DEFAULT_FLUSH_QUEUE];
5019 : : struct rte_flow_template_table *tbl;
5020 : : struct rte_flow_hw *flow;
5021 : 0 : struct rte_flow_op_attr attr = {
5022 : : .postpone = 0,
5023 : : };
5024 : : uint32_t pending_rules = 0;
5025 : : uint32_t queue;
5026 : : uint32_t fidx;
5027 : :
5028 : : /*
5029 : : * Ensure to push and dequeue all the enqueued flow
5030 : : * creation/destruction jobs in case user forgot to
5031 : : * dequeue. Or the enqueued created flows will be
5032 : : * leaked. The forgotten dequeues would also cause
5033 : : * flow flush get extra CQEs as expected and pending_rules
5034 : : * be minus value.
5035 : : */
5036 [ # # ]: 0 : for (queue = 0; queue < priv->nb_queue; queue++) {
5037 [ # # ]: 0 : if (__flow_hw_pull_comp(dev, queue, error))
5038 : : return -1;
5039 : : }
5040 : : /* Flush flow per-table from MLX5_DEFAULT_FLUSH_QUEUE. */
5041 [ # # ]: 0 : LIST_FOREACH(tbl, &priv->flow_hw_tbl, next) {
5042 [ # # ]: 0 : if (!tbl->cfg.external)
5043 : 0 : continue;
5044 [ # # ]: 0 : MLX5_IPOOL_FOREACH(tbl->flow_pool, fidx, flow) {
5045 [ # # ]: 0 : if (flow_hw_async_flow_destroy(dev,
5046 : : MLX5_DEFAULT_FLUSH_QUEUE,
5047 : : &attr,
5048 : : (struct rte_flow *)flow,
5049 : : NULL,
5050 : : error))
5051 : : return -1;
5052 : 0 : pending_rules++;
5053 : : /* Drain completion with queue size. */
5054 [ # # ]: 0 : if (pending_rules >= hw_q->size) {
5055 [ # # ]: 0 : if (__flow_hw_pull_comp(dev,
5056 : : MLX5_DEFAULT_FLUSH_QUEUE,
5057 : : error))
5058 : : return -1;
5059 : : pending_rules = 0;
5060 : : }
5061 : : }
5062 : : }
5063 : : /* Drain left completion. */
5064 [ # # # # ]: 0 : if (pending_rules &&
5065 : 0 : __flow_hw_pull_comp(dev, MLX5_DEFAULT_FLUSH_QUEUE, error))
5066 : 0 : return -1;
5067 : : return 0;
5068 : : }
5069 : :
5070 : : static int
5071 : 0 : mlx5_tbl_multi_pattern_process(struct rte_eth_dev *dev,
5072 : : struct rte_flow_template_table *tbl,
5073 : : struct mlx5_multi_pattern_segment *segment,
5074 : : uint32_t bulk_size,
5075 : : struct rte_flow_error *error)
5076 : : {
5077 : : int ret = 0;
5078 : : uint32_t i;
5079 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5080 : : bool unified_fdb = is_unified_fdb(priv);
5081 : : struct mlx5_tbl_multi_pattern_ctx *mpctx = &tbl->mpctx;
5082 : : const struct rte_flow_template_table_attr *table_attr = &tbl->cfg.attr;
5083 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
5084 : : enum mlx5dr_table_type type =
5085 : 0 : get_mlx5dr_table_type(attr, table_attr->specialize, unified_fdb);
5086 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][type];
5087 : : struct mlx5dr_action *dr_action = NULL;
5088 : :
5089 [ # # ]: 0 : for (i = 0; i < MLX5_MULTIPATTERN_ENCAP_NUM; i++) {
5090 [ # # ]: 0 : typeof(mpctx->reformat[0]) *reformat = mpctx->reformat + i;
5091 : : enum mlx5dr_action_type reformat_type =
5092 : : mlx5_multi_pattern_reformat_index_to_type(i);
5093 : :
5094 [ # # ]: 0 : if (!reformat->elements_num)
5095 : 0 : continue;
5096 : : dr_action = reformat_type == MLX5DR_ACTION_TYP_INSERT_HEADER ?
5097 : : mlx5dr_action_create_insert_header
5098 : : (priv->dr_ctx, reformat->elements_num,
5099 : : reformat->insert_hdr, bulk_size, flags) :
5100 : 0 : mlx5dr_action_create_reformat
5101 : : (priv->dr_ctx, reformat_type, reformat->elements_num,
5102 : 0 : reformat->reformat_hdr, bulk_size, flags);
5103 [ # # ]: 0 : if (!dr_action) {
5104 : 0 : ret = rte_flow_error_set(error, rte_errno,
5105 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5106 : : NULL,
5107 : : "failed to create multi-pattern encap action");
5108 : 0 : goto error;
5109 : : }
5110 : 0 : segment->reformat_action[i] = dr_action;
5111 : : }
5112 [ # # ]: 0 : if (mpctx->mh.elements_num) {
5113 : : typeof(mpctx->mh) *mh = &mpctx->mh;
5114 : 0 : dr_action = mlx5dr_action_create_modify_header
5115 : 0 : (priv->dr_ctx, mpctx->mh.elements_num, mh->pattern,
5116 : : bulk_size, flags);
5117 [ # # ]: 0 : if (!dr_action) {
5118 : 0 : ret = rte_flow_error_set(error, rte_errno,
5119 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5120 : : NULL, "failed to create multi-pattern header modify action");
5121 : 0 : goto error;
5122 : : }
5123 : 0 : segment->mhdr_action = dr_action;
5124 : : }
5125 [ # # ]: 0 : if (dr_action) {
5126 : 0 : segment->capacity = RTE_BIT32(bulk_size);
5127 [ # # ]: 0 : if (segment != &mpctx->segments[MLX5_MAX_TABLE_RESIZE_NUM - 1])
5128 : 0 : segment[1].head_index = segment->head_index + segment->capacity;
5129 : : }
5130 : : return 0;
5131 : 0 : error:
5132 : 0 : mlx5_destroy_multi_pattern_segment(segment);
5133 : 0 : return ret;
5134 : : }
5135 : :
5136 : : static int
5137 : 0 : mlx5_hw_build_template_table(struct rte_eth_dev *dev,
5138 : : uint8_t nb_action_templates,
5139 : : struct rte_flow_actions_template *action_templates[],
5140 : : struct mlx5dr_action_template *at[],
5141 : : struct rte_flow_template_table *tbl,
5142 : : struct rte_flow_error *error)
5143 : : {
5144 : : int ret;
5145 : : uint8_t i;
5146 : :
5147 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
5148 : 0 : uint32_t refcnt = rte_atomic_fetch_add_explicit(&action_templates[i]->refcnt, 1,
5149 : : rte_memory_order_relaxed) + 1;
5150 : :
5151 [ # # ]: 0 : if (refcnt <= 1) {
5152 : 0 : rte_flow_error_set(error, EINVAL,
5153 : : RTE_FLOW_ERROR_TYPE_ACTION,
5154 : : &action_templates[i], "invalid AT refcount");
5155 : 0 : goto at_error;
5156 : : }
5157 : 0 : at[i] = action_templates[i]->tmpl;
5158 : 0 : tbl->ats[i].action_template = action_templates[i];
5159 : 0 : LIST_INIT(&tbl->ats[i].acts.act_list);
5160 : : /* do NOT translate table action if `dev` was not started */
5161 [ # # ]: 0 : if (!dev->data->dev_started)
5162 : 0 : continue;
5163 : 0 : ret = flow_hw_translate_actions_template(dev, &tbl->cfg,
5164 : : &tbl->ats[i].acts,
5165 : : action_templates[i],
5166 : : &tbl->mpctx, error);
5167 [ # # ]: 0 : if (ret) {
5168 : 0 : i++;
5169 : 0 : goto at_error;
5170 : : }
5171 : 0 : flow_hw_populate_rule_acts_caches(dev, tbl, i);
5172 : : }
5173 [ # # ]: 0 : tbl->nb_action_templates = nb_action_templates;
5174 [ # # ]: 0 : if (mlx5_is_multi_pattern_active(&tbl->mpctx)) {
5175 [ # # ]: 0 : ret = mlx5_tbl_multi_pattern_process(dev, tbl,
5176 : : &tbl->mpctx.segments[0],
5177 : : rte_log2_u32(tbl->cfg.attr.nb_flows),
5178 : : error);
5179 [ # # ]: 0 : if (ret)
5180 : 0 : goto at_error;
5181 : : }
5182 : : return 0;
5183 : :
5184 : : at_error:
5185 [ # # ]: 0 : while (i--) {
5186 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
5187 : 0 : rte_atomic_fetch_sub_explicit(&action_templates[i]->refcnt,
5188 : : 1, rte_memory_order_relaxed);
5189 : : }
5190 : 0 : return rte_errno;
5191 : : }
5192 : :
5193 : : static bool
5194 : : flow_hw_validate_template_domain(const struct rte_flow_attr *table_attr,
5195 : : uint32_t ingress, uint32_t egress, uint32_t transfer)
5196 : : {
5197 : 0 : if (table_attr->ingress)
5198 : : return ingress != 0;
5199 [ # # # # ]: 0 : else if (table_attr->egress)
5200 : : return egress != 0;
5201 : : else
5202 : 0 : return transfer;
5203 : : }
5204 : :
5205 : : static bool
5206 : : flow_hw_validate_table_domain(const struct rte_flow_attr *table_attr)
5207 : : {
5208 : 0 : return table_attr->ingress + table_attr->egress + table_attr->transfer
5209 : : == 1;
5210 : : }
5211 : :
5212 : : /**
5213 : : * Create flow table.
5214 : : *
5215 : : * The input item and action templates will be binded to the table.
5216 : : * Flow memory will also be allocated. Matcher will be created based
5217 : : * on the item template. Action will be translated to the dedicated
5218 : : * DR action if possible.
5219 : : *
5220 : : * @param[in] dev
5221 : : * Pointer to the rte_eth_dev structure.
5222 : : * @param[in] table_cfg
5223 : : * Pointer to the table configuration.
5224 : : * @param[in] item_templates
5225 : : * Item template array to be binded to the table.
5226 : : * @param[in] nb_item_templates
5227 : : * Number of item template.
5228 : : * @param[in] action_templates
5229 : : * Action template array to be binded to the table.
5230 : : * @param[in] nb_action_templates
5231 : : * Number of action template.
5232 : : * @param[out] error
5233 : : * Pointer to error structure.
5234 : : *
5235 : : * @return
5236 : : * Table on success, NULL otherwise and rte_errno is set.
5237 : : */
5238 : : static struct rte_flow_template_table *
5239 : 0 : flow_hw_table_create(struct rte_eth_dev *dev,
5240 : : const struct mlx5_flow_template_table_cfg *table_cfg,
5241 : : struct rte_flow_pattern_template *item_templates[],
5242 : : uint8_t nb_item_templates,
5243 : : struct rte_flow_actions_template *action_templates[],
5244 : : uint8_t nb_action_templates,
5245 : : struct rte_flow_error *error)
5246 : : {
5247 : 0 : struct rte_flow_error sub_error = {
5248 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
5249 : : .cause = NULL,
5250 : : .message = NULL,
5251 : : };
5252 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
5253 : : bool unified_fdb = is_unified_fdb(priv);
5254 : 0 : struct mlx5dr_matcher_attr matcher_attr = {0};
5255 : 0 : struct mlx5dr_action_jump_to_matcher_attr jump_attr = {
5256 : : .type = MLX5DR_ACTION_JUMP_TO_MATCHER_BY_INDEX,
5257 : : .matcher = NULL,
5258 : : };
5259 : : struct rte_flow_template_table *tbl = NULL;
5260 : : struct mlx5_flow_group *grp;
5261 : : struct mlx5dr_match_template *mt[MLX5_HW_TBL_MAX_ITEM_TEMPLATE];
5262 : : struct mlx5dr_action_template *at[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
5263 : 0 : const struct rte_flow_template_table_attr *attr = &table_cfg->attr;
5264 : 0 : struct rte_flow_attr flow_attr = attr->flow_attr;
5265 : 0 : uint32_t specialize = table_cfg->attr.specialize;
5266 : 0 : struct mlx5_flow_cb_ctx ctx = {
5267 : : .dev = dev,
5268 : : .error = &sub_error,
5269 : : .data = &flow_attr,
5270 : : .data2 = &specialize,
5271 : : };
5272 : 0 : struct mlx5_indexed_pool_config cfg = {
5273 : : .trunk_size = 1 << 12,
5274 : : .per_core_cache = 1 << 13,
5275 : : .need_lock = 1,
5276 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
5277 : : .malloc = mlx5_malloc,
5278 : : .free = mlx5_free,
5279 : : .type = "mlx5_hw_table_flow",
5280 : : };
5281 : : struct mlx5_list_entry *ge;
5282 : : uint32_t i = 0, max_tpl = MLX5_HW_TBL_MAX_ITEM_TEMPLATE;
5283 [ # # ]: 0 : uint32_t nb_flows = rte_align32pow2(attr->nb_flows);
5284 : 0 : bool port_started = !!dev->data->dev_started;
5285 : : bool rpool_needed;
5286 : : size_t tbl_mem_size;
5287 : : enum mlx5dr_table_type table_type;
5288 : : int err;
5289 : :
5290 [ # # ]: 0 : if (!flow_hw_validate_table_domain(&attr->flow_attr)) {
5291 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR,
5292 : : NULL, "invalid table domain attributes");
5293 : 0 : return NULL;
5294 : : }
5295 [ # # ]: 0 : for (i = 0; i < nb_item_templates; i++) {
5296 : : const struct rte_flow_pattern_template_attr *pt_attr =
5297 : 0 : &item_templates[i]->attr;
5298 : : bool match = flow_hw_validate_template_domain(&attr->flow_attr,
5299 : 0 : pt_attr->ingress,
5300 : 0 : pt_attr->egress,
5301 [ # # ]: 0 : pt_attr->transfer);
5302 [ # # ]: 0 : if (!match) {
5303 : 0 : rte_flow_error_set(error, EINVAL,
5304 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5305 : : NULL, "pattern template domain does not match table");
5306 : 0 : return NULL;
5307 : : }
5308 [ # # # # ]: 0 : if (item_templates[i]->item_flags & MLX5_FLOW_LAYER_ECPRI &&
5309 : 0 : !mlx5_flex_parser_ecpri_exist(dev))
5310 [ # # ]: 0 : if (mlx5_flex_parser_ecpri_alloc(dev)) {
5311 : 0 : rte_flow_error_set(error, EIO,
5312 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5313 : : NULL,
5314 : : "failed to create Flex parser "
5315 : : "profile for ECPRI");
5316 : 0 : goto error;
5317 : : }
5318 : : }
5319 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
5320 : 0 : const struct rte_flow_actions_template *at = action_templates[i];
5321 : : bool match = flow_hw_validate_template_domain(&attr->flow_attr,
5322 : 0 : at->attr.ingress,
5323 : 0 : at->attr.egress,
5324 [ # # ]: 0 : at->attr.transfer);
5325 [ # # ]: 0 : if (!match) {
5326 : 0 : rte_flow_error_set(error, EINVAL,
5327 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5328 : : NULL, "action template domain does not match table");
5329 : 0 : return NULL;
5330 : : }
5331 : : }
5332 : : /* HWS layer accepts only 1 item template with root table. */
5333 [ # # ]: 0 : if (!attr->flow_attr.group)
5334 : : max_tpl = 1;
5335 : 0 : cfg.max_idx = nb_flows;
5336 [ # # ]: 0 : cfg.size = !rte_flow_template_table_resizable(dev->data->port_id, attr) ?
5337 : : mlx5_flow_hw_entry_size() :
5338 : : mlx5_flow_hw_auxed_entry_size();
5339 : : /* For table has very limited flows, disable cache. */
5340 [ # # ]: 0 : if (nb_flows < cfg.trunk_size) {
5341 : 0 : cfg.per_core_cache = 0;
5342 : 0 : cfg.trunk_size = nb_flows;
5343 [ # # ]: 0 : } else if (nb_flows <= MLX5_HW_IPOOL_SIZE_THRESHOLD) {
5344 : 0 : cfg.per_core_cache = MLX5_HW_IPOOL_CACHE_MIN;
5345 : : }
5346 : : /* Check if we requires too many templates. */
5347 [ # # # # ]: 0 : if (nb_item_templates > max_tpl ||
5348 : : nb_action_templates > MLX5_HW_TBL_MAX_ACTION_TEMPLATE) {
5349 : 0 : rte_errno = EINVAL;
5350 : 0 : goto error;
5351 : : }
5352 : : /*
5353 : : * Amount of memory required for rte_flow_template_table struct:
5354 : : * - Size of the struct itself.
5355 : : * - VLA of DR rule action containers at the end =
5356 : : * number of actions templates * number of queues * size of DR rule actions container.
5357 : : */
5358 : : tbl_mem_size = sizeof(*tbl);
5359 : 0 : tbl_mem_size += nb_action_templates * priv->nb_queue * sizeof(tbl->rule_acts[0]);
5360 : : /* Allocate the table memory. */
5361 : 0 : tbl = mlx5_malloc(MLX5_MEM_ZERO, tbl_mem_size, RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
5362 [ # # ]: 0 : if (!tbl)
5363 : 0 : goto error;
5364 : 0 : tbl->cfg = *table_cfg;
5365 : : /* Allocate flow indexed pool. */
5366 : 0 : tbl->flow_pool = mlx5_ipool_create(&cfg);
5367 [ # # ]: 0 : if (!tbl->flow_pool)
5368 : 0 : goto error;
5369 : : /* Allocate table of auxiliary flow rule structs. */
5370 : 0 : tbl->flow_aux = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct rte_flow_hw_aux) * nb_flows,
5371 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
5372 [ # # ]: 0 : if (!tbl->flow_aux)
5373 : 0 : goto error;
5374 : : /* Register the flow group. */
5375 : 0 : ge = mlx5_hlist_register(priv->sh->groups, attr->flow_attr.group, &ctx);
5376 [ # # ]: 0 : if (!ge)
5377 : 0 : goto error;
5378 : : grp = container_of(ge, struct mlx5_flow_group, entry);
5379 : : /* Verify unified fdb sub domains consistency */
5380 : 0 : table_type = get_mlx5dr_table_type(&flow_attr, specialize, unified_fdb);
5381 [ # # ]: 0 : if (table_type != grp->type) {
5382 : 0 : DRV_LOG(ERR,
5383 : : "Group %u table type mismatch: group type is fixed on first use. "
5384 : : "This table requires %s but group was first used as %s. "
5385 : : "Create tables with transfer wire_orig or vf_orig before tables jumping to it.",
5386 : : grp->group_id,
5387 : : mlx5dr_table_type_name(table_type),
5388 : : mlx5dr_table_type_name(grp->type));
5389 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5390 : : NULL,
5391 : : "group table type mismatch: type is fixed on first use; "
5392 : : "create transfer wire_orig/vf_orig tables before tables jumping to it");
5393 : 0 : rte_errno = EINVAL;
5394 : 0 : goto error;
5395 : : }
5396 : 0 : tbl->grp = grp;
5397 : : /* Prepare matcher information. */
5398 : 0 : matcher_attr.resizable = !!rte_flow_template_table_resizable
5399 : 0 : (dev->data->port_id, &table_cfg->attr);
5400 : 0 : matcher_attr.optimize_flow_src = MLX5DR_MATCHER_FLOW_SRC_ANY;
5401 : 0 : matcher_attr.priority = attr->flow_attr.priority;
5402 : 0 : matcher_attr.optimize_using_rule_idx = true;
5403 : 0 : matcher_attr.mode = MLX5DR_MATCHER_RESOURCE_MODE_RULE;
5404 [ # # ]: 0 : matcher_attr.insert_mode = flow_hw_matcher_insert_mode_get(attr->insertion_type);
5405 [ # # ]: 0 : if (matcher_attr.insert_mode == MLX5DR_MATCHER_INSERT_BY_INDEX) {
5406 [ # # ]: 0 : if (attr->insertion_type == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN) {
5407 : 0 : matcher_attr.isolated = true;
5408 : 0 : matcher_attr.match_mode = MLX5DR_MATCHER_MATCH_MODE_DEFAULT;
5409 : : } else {
5410 : 0 : matcher_attr.isolated = false;
5411 : 0 : matcher_attr.match_mode = MLX5DR_MATCHER_MATCH_MODE_ALWAYS_HIT;
5412 : : }
5413 : : }
5414 [ # # ]: 0 : if (attr->hash_func == RTE_FLOW_TABLE_HASH_FUNC_CRC16) {
5415 : 0 : DRV_LOG(ERR, "16-bit checksum hash type is not supported");
5416 : 0 : rte_errno = ENOTSUP;
5417 : 0 : goto it_error;
5418 : : }
5419 [ # # ]: 0 : matcher_attr.distribute_mode = flow_hw_matcher_distribute_mode_get(attr->hash_func);
5420 : 0 : matcher_attr.rule.num_log = rte_log2_u32(nb_flows);
5421 : : /* Parse hints information. */
5422 [ # # ]: 0 : if (attr->specialize) {
5423 : : uint32_t val = RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG |
5424 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG;
5425 : :
5426 [ # # ]: 0 : if ((attr->specialize & val) == val) {
5427 : 0 : DRV_LOG(ERR, "Invalid hint value %x",
5428 : : attr->specialize);
5429 : 0 : rte_errno = EINVAL;
5430 : 0 : goto it_error;
5431 : : }
5432 [ # # ]: 0 : if (attr->specialize &
5433 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG) {
5434 : 0 : matcher_attr.optimize_flow_src =
5435 : : MLX5DR_MATCHER_FLOW_SRC_WIRE;
5436 [ # # ]: 0 : } else if (attr->specialize &
5437 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG) {
5438 : 0 : matcher_attr.optimize_flow_src =
5439 : : MLX5DR_MATCHER_FLOW_SRC_VPORT;
5440 : : }
5441 : : }
5442 : : /* Build the item template. */
5443 [ # # ]: 0 : for (i = 0; i < nb_item_templates; i++) {
5444 : : uint32_t ret;
5445 : :
5446 [ # # # # ]: 0 : if ((flow_attr.ingress && !item_templates[i]->attr.ingress) ||
5447 [ # # # # ]: 0 : (flow_attr.egress && !item_templates[i]->attr.egress) ||
5448 [ # # # # ]: 0 : (flow_attr.transfer && !item_templates[i]->attr.transfer)) {
5449 : 0 : DRV_LOG(ERR, "pattern template and template table attribute mismatch");
5450 : 0 : rte_errno = EINVAL;
5451 : 0 : goto it_error;
5452 : : }
5453 [ # # ]: 0 : if (item_templates[i]->item_flags & MLX5_FLOW_ITEM_COMPARE)
5454 : 0 : matcher_attr.mode = MLX5DR_MATCHER_RESOURCE_MODE_HTABLE;
5455 : 0 : ret = rte_atomic_fetch_add_explicit(&item_templates[i]->refcnt, 1,
5456 : : rte_memory_order_relaxed) + 1;
5457 [ # # ]: 0 : if (ret <= 1) {
5458 : 0 : rte_errno = EINVAL;
5459 : 0 : goto it_error;
5460 : : }
5461 : 0 : mt[i] = item_templates[i]->mt;
5462 : 0 : tbl->its[i] = item_templates[i];
5463 : : }
5464 : 0 : tbl->nb_item_templates = nb_item_templates;
5465 : : /* Build the action template. */
5466 : 0 : err = mlx5_hw_build_template_table(dev, nb_action_templates,
5467 : : action_templates, at, tbl, &sub_error);
5468 [ # # ]: 0 : if (err) {
5469 : : i = nb_item_templates;
5470 : 0 : goto it_error;
5471 : : }
5472 : 0 : tbl->matcher_info[0].matcher = mlx5dr_matcher_create
5473 : 0 : (tbl->grp->tbl, mt, nb_item_templates, at, nb_action_templates, &matcher_attr);
5474 [ # # ]: 0 : if (!tbl->matcher_info[0].matcher)
5475 : 0 : goto at_error;
5476 : 0 : tbl->matcher_attr = matcher_attr;
5477 : 0 : tbl->type = table_type;
5478 [ # # ]: 0 : if (matcher_attr.isolated) {
5479 : 0 : jump_attr.matcher = tbl->matcher_info[0].matcher;
5480 : 0 : tbl->matcher_info[0].jump = mlx5dr_action_create_jump_to_matcher(priv->dr_ctx,
5481 : 0 : &jump_attr, mlx5_hw_act_flag[!!attr->flow_attr.group][tbl->type]);
5482 [ # # ]: 0 : if (!tbl->matcher_info[0].jump)
5483 : 0 : goto jtm_error;
5484 : : }
5485 : : /*
5486 : : * Only the matcher supports update and needs more than 1 WQE, an additional
5487 : : * index is needed. Or else the flow index can be reused.
5488 : : */
5489 [ # # # # ]: 0 : rpool_needed = mlx5dr_matcher_is_updatable(tbl->matcher_info[0].matcher) &&
5490 : 0 : mlx5dr_matcher_is_dependent(tbl->matcher_info[0].matcher);
5491 [ # # ]: 0 : if (rpool_needed) {
5492 : : /* Allocate rule indexed pool. */
5493 : 0 : cfg.size = 0;
5494 : 0 : cfg.type = "mlx5_hw_table_rule";
5495 : 0 : cfg.max_idx += priv->hw_q[0].size;
5496 : 0 : tbl->resource = mlx5_ipool_create(&cfg);
5497 [ # # ]: 0 : if (!tbl->resource)
5498 : 0 : goto res_error;
5499 : : }
5500 [ # # ]: 0 : if (port_started)
5501 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
5502 : : else
5503 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl_ongo, tbl, next);
5504 : : rte_rwlock_init(&tbl->matcher_replace_rwlk);
5505 : 0 : return tbl;
5506 : : res_error:
5507 [ # # ]: 0 : if (tbl->matcher_info[0].jump)
5508 : 0 : mlx5dr_action_destroy(tbl->matcher_info[0].jump);
5509 : 0 : jtm_error:
5510 [ # # ]: 0 : if (tbl->matcher_info[0].matcher)
5511 : 0 : (void)mlx5dr_matcher_destroy(tbl->matcher_info[0].matcher);
5512 : 0 : at_error:
5513 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
5514 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
5515 : 0 : rte_atomic_fetch_sub_explicit(&action_templates[i]->refcnt,
5516 : : 1, rte_memory_order_relaxed);
5517 : : }
5518 : : i = nb_item_templates;
5519 : : it_error:
5520 [ # # ]: 0 : while (i--)
5521 : 0 : rte_atomic_fetch_sub_explicit(&item_templates[i]->refcnt,
5522 : : 1, rte_memory_order_relaxed);
5523 : 0 : error:
5524 : 0 : err = rte_errno;
5525 [ # # ]: 0 : if (tbl) {
5526 [ # # ]: 0 : if (tbl->grp)
5527 : 0 : mlx5_hlist_unregister(priv->sh->groups,
5528 : : &tbl->grp->entry);
5529 [ # # ]: 0 : if (tbl->flow_aux)
5530 : 0 : mlx5_free(tbl->flow_aux);
5531 [ # # ]: 0 : if (tbl->flow_pool)
5532 : 0 : mlx5_ipool_destroy(tbl->flow_pool);
5533 : 0 : mlx5_free(tbl);
5534 : : }
5535 [ # # ]: 0 : if (error != NULL) {
5536 [ # # ]: 0 : if (sub_error.type == RTE_FLOW_ERROR_TYPE_NONE)
5537 : 0 : rte_flow_error_set(error, err, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5538 : : "Failed to create template table");
5539 : : else
5540 : : rte_memcpy(error, &sub_error, sizeof(sub_error));
5541 : : }
5542 : : return NULL;
5543 : : }
5544 : :
5545 : : /**
5546 : : * Update flow template table.
5547 : : *
5548 : : * @param[in] dev
5549 : : * Pointer to the rte_eth_dev structure.
5550 : : * @param[out] error
5551 : : * Pointer to error structure.
5552 : : *
5553 : : * @return
5554 : : * 0 on success, negative value otherwise and rte_errno is set.
5555 : : */
5556 : : int
5557 : 0 : mlx5_flow_hw_table_update(struct rte_eth_dev *dev,
5558 : : struct rte_flow_error *error)
5559 : : {
5560 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5561 : : struct rte_flow_template_table *tbl;
5562 : :
5563 [ # # ]: 0 : while ((tbl = LIST_FIRST(&priv->flow_hw_tbl_ongo)) != NULL) {
5564 [ # # ]: 0 : if (flow_hw_translate_all_actions_templates(dev, tbl, error))
5565 : : return -1;
5566 [ # # ]: 0 : LIST_REMOVE(tbl, next);
5567 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
5568 : : }
5569 : : return 0;
5570 : : }
5571 : :
5572 : : static inline int
5573 : 0 : __translate_group(struct rte_eth_dev *dev,
5574 : : const struct rte_flow_attr *flow_attr,
5575 : : bool external,
5576 : : uint32_t group,
5577 : : uint32_t *table_group,
5578 : : struct rte_flow_error *error)
5579 : : {
5580 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5581 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5582 : :
5583 [ # # ]: 0 : if (config->dv_esw_en &&
5584 [ # # # # ]: 0 : priv->fdb_def_rule &&
5585 [ # # ]: 0 : external &&
5586 : : flow_attr->transfer) {
5587 [ # # ]: 0 : if (group > MLX5_HW_MAX_TRANSFER_GROUP)
5588 : 0 : return rte_flow_error_set(error, EINVAL,
5589 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5590 : : NULL,
5591 : : "group index not supported");
5592 : 0 : *table_group = group + 1;
5593 [ # # ]: 0 : } else if (config->dv_esw_en &&
5594 [ # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS &&
5595 [ # # ]: 0 : external &&
5596 : : flow_attr->egress) {
5597 : : /*
5598 : : * On E-Switch setups, default egress flow rules are inserted to allow
5599 : : * representor matching and/or preserving metadata across steering domains.
5600 : : * These flow rules are inserted in group 0 and this group is reserved by PMD
5601 : : * for these purposes.
5602 : : *
5603 : : * As a result, if representor matching or extended metadata mode is enabled,
5604 : : * group provided by the user must be incremented to avoid inserting flow rules
5605 : : * in group 0.
5606 : : */
5607 [ # # ]: 0 : if (group > MLX5_HW_MAX_EGRESS_GROUP)
5608 : 0 : return rte_flow_error_set(error, EINVAL,
5609 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5610 : : NULL,
5611 : : "group index not supported");
5612 : 0 : *table_group = group + 1;
5613 [ # # # # ]: 0 : } else if (mlx5_vport_tx_metadata_passing_enabled(priv->sh) &&
5614 [ # # ]: 0 : flow_attr->egress && external) {
5615 : : /*
5616 : : * If VM cross GVMI metadata Tx was enabled, PMD creates a default
5617 : : * flow rule in the group 0 to copy metadata value.
5618 : : */
5619 [ # # ]: 0 : if (group > MLX5_HW_MAX_EGRESS_GROUP)
5620 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5621 : : NULL, "group index not supported");
5622 : 0 : *table_group = group + 1;
5623 : : } else {
5624 : 0 : *table_group = group;
5625 : : }
5626 : : return 0;
5627 : : }
5628 : :
5629 : : /**
5630 : : * Translates group index specified by the user in @p attr to internal
5631 : : * group index.
5632 : : *
5633 : : * Translation is done by incrementing group index, so group n becomes n + 1.
5634 : : *
5635 : : * @param[in] dev
5636 : : * Pointer to Ethernet device.
5637 : : * @param[in] cfg
5638 : : * Pointer to the template table configuration.
5639 : : * @param[in] group
5640 : : * Currently used group index (table group or jump destination).
5641 : : * @param[out] table_group
5642 : : * Pointer to output group index.
5643 : : * @param[out] error
5644 : : * Pointer to error structure.
5645 : : *
5646 : : * @return
5647 : : * 0 on success. Otherwise, returns negative error code, rte_errno is set
5648 : : * and error structure is filled.
5649 : : */
5650 : : static int
5651 : : flow_hw_translate_group(struct rte_eth_dev *dev,
5652 : : const struct mlx5_flow_template_table_cfg *cfg,
5653 : : uint32_t group,
5654 : : uint32_t *table_group,
5655 : : struct rte_flow_error *error)
5656 : : {
5657 : 0 : const struct rte_flow_attr *flow_attr = &cfg->attr.flow_attr;
5658 : :
5659 : 0 : return __translate_group(dev, flow_attr, cfg->external, group, table_group, error);
5660 : : }
5661 : :
5662 : : /**
5663 : : * Create flow table.
5664 : : *
5665 : : * This function is a wrapper over @ref flow_hw_table_create(), which translates parameters
5666 : : * provided by user to proper internal values.
5667 : : *
5668 : : * @param[in] dev
5669 : : * Pointer to Ethernet device.
5670 : : * @param[in] attr
5671 : : * Pointer to the table attributes.
5672 : : * @param[in] item_templates
5673 : : * Item template array to be binded to the table.
5674 : : * @param[in] nb_item_templates
5675 : : * Number of item templates.
5676 : : * @param[in] action_templates
5677 : : * Action template array to be binded to the table.
5678 : : * @param[in] nb_action_templates
5679 : : * Number of action templates.
5680 : : * @param[out] error
5681 : : * Pointer to error structure.
5682 : : *
5683 : : * @return
5684 : : * Table on success, Otherwise, returns negative error code, rte_errno is set
5685 : : * and error structure is filled.
5686 : : */
5687 : : static struct rte_flow_template_table *
5688 : 0 : flow_hw_template_table_create(struct rte_eth_dev *dev,
5689 : : const struct rte_flow_template_table_attr *attr,
5690 : : struct rte_flow_pattern_template *item_templates[],
5691 : : uint8_t nb_item_templates,
5692 : : struct rte_flow_actions_template *action_templates[],
5693 : : uint8_t nb_action_templates,
5694 : : struct rte_flow_error *error)
5695 : : {
5696 : 0 : struct mlx5_flow_template_table_cfg cfg = {
5697 : : .attr = *attr,
5698 : : .external = true,
5699 : : };
5700 : 0 : uint32_t group = attr->flow_attr.group;
5701 : :
5702 [ # # ]: 0 : if (flow_hw_translate_group(dev, &cfg, group, &cfg.attr.flow_attr.group, error))
5703 : : return NULL;
5704 [ # # # # ]: 0 : if (!cfg.attr.flow_attr.group &&
5705 : 0 : rte_flow_template_table_resizable(dev->data->port_id, attr)) {
5706 : 0 : rte_flow_error_set(error, EINVAL,
5707 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5708 : : "table cannot be resized: invalid group");
5709 : 0 : return NULL;
5710 : : }
5711 : 0 : return flow_hw_table_create(dev, &cfg, item_templates, nb_item_templates,
5712 : : action_templates, nb_action_templates, error);
5713 : : }
5714 : :
5715 : : static void
5716 : 0 : mlx5_destroy_multi_pattern_segment(struct mlx5_multi_pattern_segment *segment)
5717 : : {
5718 : : int i;
5719 : :
5720 [ # # ]: 0 : if (segment->mhdr_action)
5721 : 0 : mlx5dr_action_destroy(segment->mhdr_action);
5722 [ # # ]: 0 : for (i = 0; i < MLX5_MULTIPATTERN_ENCAP_NUM; i++) {
5723 [ # # ]: 0 : if (segment->reformat_action[i])
5724 : 0 : mlx5dr_action_destroy(segment->reformat_action[i]);
5725 : : }
5726 : 0 : segment->capacity = 0;
5727 : 0 : }
5728 : :
5729 : : static void
5730 : : flow_hw_destroy_table_multi_pattern_ctx(struct rte_flow_template_table *table)
5731 : : {
5732 : : int sx;
5733 : :
5734 [ # # ]: 0 : for (sx = 0; sx < MLX5_MAX_TABLE_RESIZE_NUM; sx++)
5735 : 0 : mlx5_destroy_multi_pattern_segment(table->mpctx.segments + sx);
5736 : : }
5737 : : /**
5738 : : * Destroy flow table.
5739 : : *
5740 : : * @param[in] dev
5741 : : * Pointer to the rte_eth_dev structure.
5742 : : * @param[in] table
5743 : : * Pointer to the table to be destroyed.
5744 : : * @param[out] error
5745 : : * Pointer to error structure.
5746 : : *
5747 : : * @return
5748 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5749 : : */
5750 : : static int
5751 : 0 : flow_hw_table_destroy(struct rte_eth_dev *dev,
5752 : : struct rte_flow_template_table *table,
5753 : : struct rte_flow_error *error)
5754 : : {
5755 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5756 : : int i;
5757 : 0 : uint32_t fidx = 1;
5758 : 0 : uint32_t ridx = 1;
5759 : :
5760 : : /* Build ipool allocated object bitmap. */
5761 [ # # ]: 0 : if (table->resource)
5762 : 0 : mlx5_ipool_flush_cache(table->resource);
5763 : 0 : mlx5_ipool_flush_cache(table->flow_pool);
5764 : : /* Check if ipool has allocated objects. */
5765 [ # # # # ]: 0 : if (table->refcnt ||
5766 : 0 : mlx5_ipool_get_next(table->flow_pool, &fidx) ||
5767 [ # # # # ]: 0 : (table->resource && mlx5_ipool_get_next(table->resource, &ridx))) {
5768 : 0 : DRV_LOG(WARNING, "Table %p is still in use.", (void *)table);
5769 : 0 : return rte_flow_error_set(error, EBUSY,
5770 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5771 : : NULL,
5772 : : "table is in use");
5773 : : }
5774 [ # # ]: 0 : LIST_REMOVE(table, next);
5775 [ # # ]: 0 : for (i = 0; i < table->nb_item_templates; i++)
5776 : 0 : rte_atomic_fetch_sub_explicit(&table->its[i]->refcnt,
5777 : : 1, rte_memory_order_relaxed);
5778 [ # # ]: 0 : for (i = 0; i < table->nb_action_templates; i++) {
5779 : 0 : __flow_hw_action_template_destroy(dev, &table->ats[i].acts);
5780 : 0 : rte_atomic_fetch_sub_explicit(&table->ats[i].action_template->refcnt,
5781 : : 1, rte_memory_order_relaxed);
5782 : : }
5783 : : flow_hw_destroy_table_multi_pattern_ctx(table);
5784 [ # # ]: 0 : if (table->matcher_info[0].jump)
5785 : 0 : mlx5dr_action_destroy(table->matcher_info[0].jump);
5786 [ # # ]: 0 : if (table->matcher_info[0].matcher)
5787 : 0 : mlx5dr_matcher_destroy(table->matcher_info[0].matcher);
5788 [ # # ]: 0 : if (table->matcher_info[1].jump)
5789 : 0 : mlx5dr_action_destroy(table->matcher_info[1].jump);
5790 [ # # ]: 0 : if (table->matcher_info[1].matcher)
5791 : 0 : mlx5dr_matcher_destroy(table->matcher_info[1].matcher);
5792 : 0 : mlx5_hlist_unregister(priv->sh->groups, &table->grp->entry);
5793 [ # # ]: 0 : if (table->resource)
5794 : 0 : mlx5_ipool_destroy(table->resource);
5795 : 0 : mlx5_free(table->flow_aux);
5796 : 0 : mlx5_ipool_destroy(table->flow_pool);
5797 : 0 : mlx5_free(table);
5798 : 0 : return 0;
5799 : : }
5800 : :
5801 : : /**
5802 : : * Parse group's miss actions.
5803 : : *
5804 : : * @param[in] dev
5805 : : * Pointer to the rte_eth_dev structure.
5806 : : * @param[in] cfg
5807 : : * Pointer to the table_cfg structure.
5808 : : * @param[in] actions
5809 : : * Array of actions to perform on group miss. Supported types:
5810 : : * RTE_FLOW_ACTION_TYPE_JUMP, RTE_FLOW_ACTION_TYPE_VOID, RTE_FLOW_ACTION_TYPE_END.
5811 : : * @param[out] dst_group_id
5812 : : * Pointer to destination group id output. will be set to 0 if actions is END,
5813 : : * otherwise will be set to destination group id.
5814 : : * @param[out] error
5815 : : * Pointer to error structure.
5816 : : *
5817 : : * @return
5818 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5819 : : */
5820 : :
5821 : : static int
5822 : 0 : flow_hw_group_parse_miss_actions(struct rte_eth_dev *dev,
5823 : : struct mlx5_flow_template_table_cfg *cfg,
5824 : : const struct rte_flow_action actions[],
5825 : : uint32_t *dst_group_id,
5826 : : struct rte_flow_error *error)
5827 : : {
5828 : : const struct rte_flow_action_jump *jump_conf;
5829 : 0 : uint32_t temp = 0;
5830 : : uint32_t i;
5831 : :
5832 [ # # ]: 0 : for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
5833 [ # # # ]: 0 : switch (actions[i].type) {
5834 : 0 : case RTE_FLOW_ACTION_TYPE_VOID:
5835 : 0 : continue;
5836 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
5837 [ # # ]: 0 : if (temp)
5838 : 0 : return rte_flow_error_set(error, ENOTSUP,
5839 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, actions,
5840 : : "Miss actions can contain only a single JUMP");
5841 : :
5842 : 0 : jump_conf = (const struct rte_flow_action_jump *)actions[i].conf;
5843 [ # # ]: 0 : if (!jump_conf)
5844 : 0 : return rte_flow_error_set(error, EINVAL,
5845 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5846 : : jump_conf, "Jump conf must not be NULL");
5847 : :
5848 [ # # ]: 0 : if (flow_hw_translate_group(dev, cfg, jump_conf->group, &temp, error))
5849 : 0 : return -rte_errno;
5850 : :
5851 [ # # ]: 0 : if (!temp)
5852 : 0 : return rte_flow_error_set(error, EINVAL,
5853 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5854 : : "Failed to set group miss actions - Invalid target group");
5855 : : break;
5856 : 0 : default:
5857 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
5858 : : &actions[i], "Unsupported default miss action type");
5859 : : }
5860 : : }
5861 : :
5862 : 0 : *dst_group_id = temp;
5863 : 0 : return 0;
5864 : : }
5865 : :
5866 : : /**
5867 : : * Set group's miss group.
5868 : : *
5869 : : * @param[in] dev
5870 : : * Pointer to the rte_eth_dev structure.
5871 : : * @param[in] cfg
5872 : : * Pointer to the table_cfg structure.
5873 : : * @param[in] src_grp
5874 : : * Pointer to source group structure.
5875 : : * if NULL, a new group will be created based on group id from cfg->attr.flow_attr.group.
5876 : : * @param[in] dst_grp
5877 : : * Pointer to destination group structure.
5878 : : * @param[out] error
5879 : : * Pointer to error structure.
5880 : : *
5881 : : * @return
5882 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5883 : : */
5884 : :
5885 : : static int
5886 : 0 : flow_hw_group_set_miss_group(struct rte_eth_dev *dev,
5887 : : struct mlx5_flow_template_table_cfg *cfg,
5888 : : struct mlx5_flow_group *src_grp,
5889 : : struct mlx5_flow_group *dst_grp,
5890 : : struct rte_flow_error *error)
5891 : : {
5892 : 0 : struct rte_flow_error sub_error = {
5893 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
5894 : : .cause = NULL,
5895 : : .message = NULL,
5896 : : };
5897 : 0 : struct mlx5_flow_cb_ctx ctx = {
5898 : : .dev = dev,
5899 : : .error = &sub_error,
5900 : 0 : .data = &cfg->attr.flow_attr,
5901 : 0 : .data2 = &cfg->attr.specialize,
5902 : : };
5903 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5904 : : struct mlx5_list_entry *ge;
5905 : : bool ref = false;
5906 : : int ret;
5907 : :
5908 [ # # ]: 0 : if (!dst_grp)
5909 : : return -EINVAL;
5910 : :
5911 : : /* If group doesn't exist - needs to be created. */
5912 [ # # ]: 0 : if (!src_grp) {
5913 : 0 : ge = mlx5_hlist_register(priv->sh->groups, cfg->attr.flow_attr.group, &ctx);
5914 [ # # ]: 0 : if (!ge)
5915 : 0 : return -rte_errno;
5916 : :
5917 : : src_grp = container_of(ge, struct mlx5_flow_group, entry);
5918 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_grp, src_grp, next);
5919 : : ref = true;
5920 [ # # ]: 0 : } else if (!src_grp->miss_group) {
5921 : : /* If group exists, but has no miss actions - need to increase ref_cnt. */
5922 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_grp, src_grp, next);
5923 : 0 : src_grp->entry.ref_cnt++;
5924 : : ref = true;
5925 : : }
5926 : :
5927 : 0 : ret = mlx5dr_table_set_default_miss(src_grp->tbl, dst_grp->tbl);
5928 [ # # ]: 0 : if (ret)
5929 : 0 : goto mlx5dr_error;
5930 : :
5931 : : /* If group existed and had old miss actions - ref_cnt is already correct.
5932 : : * However, need to reduce ref counter for old miss group.
5933 : : */
5934 [ # # ]: 0 : if (src_grp->miss_group)
5935 : 0 : mlx5_hlist_unregister(priv->sh->groups, &src_grp->miss_group->entry);
5936 : :
5937 : 0 : src_grp->miss_group = dst_grp;
5938 : 0 : return 0;
5939 : :
5940 : : mlx5dr_error:
5941 : : /* Reduce src_grp ref_cnt back & remove from grp list in case of mlx5dr error */
5942 [ # # ]: 0 : if (ref) {
5943 : 0 : mlx5_hlist_unregister(priv->sh->groups, &src_grp->entry);
5944 [ # # ]: 0 : LIST_REMOVE(src_grp, next);
5945 : : }
5946 : :
5947 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5948 : : "Failed to set group miss actions");
5949 : : }
5950 : :
5951 : : /**
5952 : : * Unset group's miss group.
5953 : : *
5954 : : * @param[in] dev
5955 : : * Pointer to the rte_eth_dev structure.
5956 : : * @param[in] grp
5957 : : * Pointer to group structure.
5958 : : * @param[out] error
5959 : : * Pointer to error structure.
5960 : : *
5961 : : * @return
5962 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5963 : : */
5964 : :
5965 : : static int
5966 : 0 : flow_hw_group_unset_miss_group(struct rte_eth_dev *dev,
5967 : : struct mlx5_flow_group *grp,
5968 : : struct rte_flow_error *error)
5969 : : {
5970 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5971 : : int ret;
5972 : :
5973 : : /* If group doesn't exist - no need to change anything. */
5974 [ # # ]: 0 : if (!grp)
5975 : : return 0;
5976 : :
5977 : : /* If group exists, but miss actions is already default behavior -
5978 : : * no need to change anything.
5979 : : */
5980 [ # # ]: 0 : if (!grp->miss_group)
5981 : : return 0;
5982 : :
5983 : 0 : ret = mlx5dr_table_set_default_miss(grp->tbl, NULL);
5984 [ # # ]: 0 : if (ret)
5985 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5986 : : "Failed to unset group miss actions");
5987 : :
5988 : 0 : mlx5_hlist_unregister(priv->sh->groups, &grp->miss_group->entry);
5989 : 0 : grp->miss_group = NULL;
5990 : :
5991 [ # # ]: 0 : LIST_REMOVE(grp, next);
5992 : 0 : mlx5_hlist_unregister(priv->sh->groups, &grp->entry);
5993 : :
5994 : 0 : return 0;
5995 : : }
5996 : :
5997 : : /**
5998 : : * Set group miss actions.
5999 : : *
6000 : : * @param[in] dev
6001 : : * Pointer to the rte_eth_dev structure.
6002 : : * @param[in] group_id
6003 : : * Group id.
6004 : : * @param[in] attr
6005 : : * Pointer to group attributes structure.
6006 : : * @param[in] actions
6007 : : * Array of actions to perform on group miss. Supported types:
6008 : : * RTE_FLOW_ACTION_TYPE_JUMP, RTE_FLOW_ACTION_TYPE_VOID, RTE_FLOW_ACTION_TYPE_END.
6009 : : * @param[out] error
6010 : : * Pointer to error structure.
6011 : : *
6012 : : * @return
6013 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6014 : : */
6015 : :
6016 : : int
6017 : 0 : mlx5_flow_hw_group_set_miss_actions(struct rte_eth_dev *dev,
6018 : : uint32_t group_id,
6019 : : const struct rte_flow_group_attr *attr,
6020 : : const struct rte_flow_action actions[],
6021 : : struct rte_flow_error *error)
6022 : : {
6023 : 0 : struct rte_flow_error sub_error = {
6024 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
6025 : : .cause = NULL,
6026 : : .message = NULL,
6027 : : };
6028 : 0 : struct mlx5_flow_template_table_cfg cfg = {
6029 : : .external = true,
6030 : : .attr = {
6031 : : .flow_attr = {
6032 : : .group = group_id,
6033 : 0 : .ingress = attr->ingress,
6034 : 0 : .egress = attr->egress,
6035 : 0 : .transfer = attr->transfer,
6036 : : },
6037 : : },
6038 : : };
6039 : 0 : struct mlx5_flow_cb_ctx ctx = {
6040 : : .dev = dev,
6041 : : .error = &sub_error,
6042 : : .data = &cfg.attr.flow_attr,
6043 : : .data2 = &cfg.attr.specialize,
6044 : : };
6045 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6046 : : struct mlx5_flow_group *src_grp = NULL;
6047 : : struct mlx5_flow_group *dst_grp = NULL;
6048 : : struct mlx5_list_entry *ge;
6049 : 0 : uint32_t dst_group_id = 0;
6050 : : int ret;
6051 : :
6052 [ # # ]: 0 : if (flow_hw_translate_group(dev, &cfg, group_id, &group_id, error))
6053 : 0 : return -rte_errno;
6054 : :
6055 [ # # ]: 0 : if (!group_id)
6056 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6057 : : NULL, "Failed to set group miss actions - invalid group id");
6058 : :
6059 : 0 : ret = flow_hw_group_parse_miss_actions(dev, &cfg, actions, &dst_group_id, error);
6060 [ # # ]: 0 : if (ret)
6061 : 0 : return -rte_errno;
6062 : :
6063 [ # # ]: 0 : if (dst_group_id == group_id) {
6064 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6065 : : NULL, "Failed to set group miss actions - target group id must differ from group_id");
6066 : : }
6067 : :
6068 : 0 : cfg.attr.flow_attr.group = group_id;
6069 : 0 : ge = mlx5_hlist_lookup(priv->sh->groups, group_id, &ctx);
6070 [ # # ]: 0 : if (ge)
6071 : : src_grp = container_of(ge, struct mlx5_flow_group, entry);
6072 : :
6073 [ # # ]: 0 : if (dst_group_id) {
6074 : : /* Increase ref_cnt for new miss group. */
6075 : 0 : cfg.attr.flow_attr.group = dst_group_id;
6076 : 0 : ge = mlx5_hlist_register(priv->sh->groups, dst_group_id, &ctx);
6077 [ # # ]: 0 : if (!ge)
6078 : 0 : return -rte_errno;
6079 : :
6080 : : dst_grp = container_of(ge, struct mlx5_flow_group, entry);
6081 : :
6082 : 0 : cfg.attr.flow_attr.group = group_id;
6083 : 0 : ret = flow_hw_group_set_miss_group(dev, &cfg, src_grp, dst_grp, error);
6084 [ # # ]: 0 : if (ret)
6085 : 0 : goto error;
6086 : : } else {
6087 : 0 : return flow_hw_group_unset_miss_group(dev, src_grp, error);
6088 : : }
6089 : :
6090 : : return 0;
6091 : :
6092 : : error:
6093 : : if (dst_grp)
6094 : 0 : mlx5_hlist_unregister(priv->sh->groups, &dst_grp->entry);
6095 : 0 : return -rte_errno;
6096 : : }
6097 : :
6098 : : static bool
6099 : : flow_hw_modify_field_is_used(const struct rte_flow_action_modify_field *action,
6100 : : enum rte_flow_field_id field)
6101 : : {
6102 [ # # # # : 0 : return action->src.field == field || action->dst.field == field;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
6103 : : }
6104 : :
6105 : : static bool
6106 : : flow_hw_modify_field_is_geneve_opt(enum rte_flow_field_id field)
6107 : : {
6108 : : return field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
6109 : 0 : field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
6110 : : field == RTE_FLOW_FIELD_GENEVE_OPT_DATA;
6111 : : }
6112 : :
6113 : : static bool
6114 : 0 : flow_hw_modify_field_is_add_dst_valid(const struct rte_flow_action_modify_field *conf)
6115 : : {
6116 [ # # ]: 0 : if (conf->operation != RTE_FLOW_MODIFY_ADD)
6117 : : return true;
6118 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
6119 : : conf->src.field == RTE_FLOW_FIELD_VALUE)
6120 : : return true;
6121 [ # # ]: 0 : switch (conf->dst.field) {
6122 : : case RTE_FLOW_FIELD_IPV4_TTL:
6123 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
6124 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
6125 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
6126 : : case RTE_FLOW_FIELD_TAG:
6127 : : case RTE_FLOW_FIELD_META:
6128 : : case RTE_FLOW_FIELD_FLEX_ITEM:
6129 : : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
6130 : : case RTE_FLOW_FIELD_IPV4_IHL:
6131 : : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
6132 : : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
6133 : : return true;
6134 : : default:
6135 : : break;
6136 : : }
6137 : 0 : return false;
6138 : : }
6139 : :
6140 : : /**
6141 : : * Validate the level value for modify field action.
6142 : : *
6143 : : * @param[in] data
6144 : : * Pointer to the rte_flow_field_data structure either src or dst.
6145 : : * @param[in] inner_supported
6146 : : * Indicator whether inner should be supported.
6147 : : * @param[out] error
6148 : : * Pointer to error structure.
6149 : : *
6150 : : * @return
6151 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6152 : : */
6153 : : static int
6154 : 0 : flow_hw_validate_modify_field_level(const struct rte_flow_field_data *data,
6155 : : bool inner_supported,
6156 : : struct rte_flow_error *error)
6157 : : {
6158 [ # # # # : 0 : switch ((int)data->field) {
# ]
6159 : : case RTE_FLOW_FIELD_START:
6160 : : case RTE_FLOW_FIELD_VLAN_TYPE:
6161 : : case RTE_FLOW_FIELD_RANDOM:
6162 : : case RTE_FLOW_FIELD_FLEX_ITEM:
6163 : : /*
6164 : : * Level shouldn't be valid since field isn't supported or
6165 : : * doesn't use 'level'.
6166 : : */
6167 : : break;
6168 : : case RTE_FLOW_FIELD_MARK:
6169 : : case RTE_FLOW_FIELD_META:
6170 : : case RTE_FLOW_FIELD_METER_COLOR:
6171 : : case RTE_FLOW_FIELD_HASH_RESULT:
6172 : : /* For meta data fields encapsulation level is don't-care. */
6173 : : break;
6174 : 0 : case RTE_FLOW_FIELD_TAG:
6175 : : case MLX5_RTE_FLOW_FIELD_META_REG:
6176 : : /*
6177 : : * The tag array for RTE_FLOW_FIELD_TAG type is provided using
6178 : : * 'tag_index' field. In old API, it was provided using 'level'
6179 : : * field and it is still supported for backwards compatibility.
6180 : : * Therefore, for meta tag field only, level is matter. It is
6181 : : * taken as tag index when 'tag_index' field isn't set, and
6182 : : * return error otherwise.
6183 : : */
6184 [ # # ]: 0 : if (data->level > 0) {
6185 [ # # ]: 0 : if (data->tag_index > 0)
6186 : 0 : return rte_flow_error_set(error, EINVAL,
6187 : : RTE_FLOW_ERROR_TYPE_ACTION,
6188 : : data,
6189 : : "tag array can be provided using 'level' or 'tag_index' fields, not both");
6190 : 0 : DRV_LOG(WARNING,
6191 : : "tag array provided in 'level' field instead of 'tag_index' field.");
6192 : : }
6193 : : break;
6194 : 0 : case RTE_FLOW_FIELD_MAC_DST:
6195 : : case RTE_FLOW_FIELD_MAC_SRC:
6196 : : case RTE_FLOW_FIELD_MAC_TYPE:
6197 : : case RTE_FLOW_FIELD_IPV4_IHL:
6198 : : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
6199 : : case RTE_FLOW_FIELD_IPV4_DSCP:
6200 : : case RTE_FLOW_FIELD_IPV4_ECN:
6201 : : case RTE_FLOW_FIELD_IPV4_TTL:
6202 : : case RTE_FLOW_FIELD_IPV4_SRC:
6203 : : case RTE_FLOW_FIELD_IPV4_DST:
6204 : : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
6205 : : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
6206 : : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
6207 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
6208 : : case RTE_FLOW_FIELD_IPV6_SRC:
6209 : : case RTE_FLOW_FIELD_IPV6_DST:
6210 : : case RTE_FLOW_FIELD_TCP_PORT_SRC:
6211 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
6212 : : case RTE_FLOW_FIELD_TCP_FLAGS:
6213 : : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
6214 : : case RTE_FLOW_FIELD_UDP_PORT_SRC:
6215 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
6216 [ # # ]: 0 : if (data->level > 2)
6217 : 0 : return rte_flow_error_set(error, ENOTSUP,
6218 : : RTE_FLOW_ERROR_TYPE_ACTION,
6219 : : data,
6220 : : "second inner header fields modification is not supported");
6221 [ # # ]: 0 : if (inner_supported)
6222 : : break;
6223 : : /* Fallthrough */
6224 : : case RTE_FLOW_FIELD_VLAN_ID:
6225 : : case RTE_FLOW_FIELD_IPV4_PROTO:
6226 : : case RTE_FLOW_FIELD_IPV6_PROTO:
6227 : : case RTE_FLOW_FIELD_IPV6_DSCP:
6228 : : case RTE_FLOW_FIELD_IPV6_ECN:
6229 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
6230 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
6231 : : case RTE_FLOW_FIELD_ESP_PROTO:
6232 : : case RTE_FLOW_FIELD_ESP_SPI:
6233 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
6234 : : case RTE_FLOW_FIELD_VXLAN_VNI:
6235 : : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
6236 : : case RTE_FLOW_FIELD_GENEVE_VNI:
6237 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
6238 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
6239 : : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
6240 : : case RTE_FLOW_FIELD_GTP_TEID:
6241 : : case RTE_FLOW_FIELD_GTP_PSC_QFI:
6242 [ # # ]: 0 : if (data->level > 1)
6243 : 0 : return rte_flow_error_set(error, ENOTSUP,
6244 : : RTE_FLOW_ERROR_TYPE_ACTION,
6245 : : data,
6246 : : "inner header fields modification is not supported");
6247 : : break;
6248 : 0 : case RTE_FLOW_FIELD_MPLS:
6249 [ # # ]: 0 : if (data->level == 1)
6250 : 0 : return rte_flow_error_set(error, ENOTSUP,
6251 : : RTE_FLOW_ERROR_TYPE_ACTION,
6252 : : data,
6253 : : "outer MPLS header modification is not supported");
6254 [ # # ]: 0 : if (data->level > 2)
6255 : 0 : return rte_flow_error_set(error, ENOTSUP,
6256 : : RTE_FLOW_ERROR_TYPE_ACTION,
6257 : : data,
6258 : : "inner MPLS header modification is not supported");
6259 : : break;
6260 : 0 : case RTE_FLOW_FIELD_POINTER:
6261 : : case RTE_FLOW_FIELD_VALUE:
6262 : : default:
6263 : : MLX5_ASSERT(false);
6264 : : }
6265 : : return 0;
6266 : : }
6267 : :
6268 : : static int
6269 : 0 : flow_hw_validate_action_modify_field(struct rte_eth_dev *dev,
6270 : : const struct rte_flow_action *action,
6271 : : const struct rte_flow_action *mask,
6272 : : struct rte_flow_error *error)
6273 : : {
6274 : 0 : const struct rte_flow_action_modify_field *action_conf = action->conf;
6275 : 0 : const struct rte_flow_action_modify_field *mask_conf = mask->conf;
6276 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6277 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
6278 : : int ret;
6279 : :
6280 [ # # ]: 0 : if (!mask_conf)
6281 : 0 : return rte_flow_error_set(error, EINVAL,
6282 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6283 : : "modify_field mask conf is missing");
6284 [ # # ]: 0 : if (action_conf->operation != mask_conf->operation)
6285 : 0 : return rte_flow_error_set(error, EINVAL,
6286 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6287 : : "modify_field operation mask and template are not equal");
6288 [ # # ]: 0 : if (action_conf->dst.field != mask_conf->dst.field)
6289 : 0 : return rte_flow_error_set(error, EINVAL,
6290 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6291 : : "destination field mask and template are not equal");
6292 : 0 : if (action_conf->dst.field == RTE_FLOW_FIELD_POINTER ||
6293 [ # # ]: 0 : action_conf->dst.field == RTE_FLOW_FIELD_VALUE ||
6294 : : action_conf->dst.field == RTE_FLOW_FIELD_HASH_RESULT)
6295 : 0 : return rte_flow_error_set(error, EINVAL,
6296 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6297 : : "immediate value, pointer and hash result cannot be used as destination");
6298 : 0 : ret = flow_hw_validate_modify_field_level(&action_conf->dst, false, error);
6299 [ # # ]: 0 : if (ret)
6300 : : return ret;
6301 [ # # # # ]: 0 : if (action_conf->dst.field != RTE_FLOW_FIELD_FLEX_ITEM &&
6302 : : !flow_hw_modify_field_is_geneve_opt(action_conf->dst.field)) {
6303 [ # # ]: 0 : if (action_conf->dst.tag_index &&
6304 : : !flow_modify_field_support_tag_array(action_conf->dst.field))
6305 : 0 : return rte_flow_error_set(error, EINVAL,
6306 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6307 : : "destination tag index is not supported");
6308 : : }
6309 [ # # ]: 0 : if (mask_conf->dst.level != UINT8_MAX)
6310 : 0 : return rte_flow_error_set(error, EINVAL,
6311 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6312 : : "destination encapsulation level must be fully masked");
6313 [ # # ]: 0 : if (mask_conf->dst.offset != UINT32_MAX)
6314 : 0 : return rte_flow_error_set(error, EINVAL,
6315 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6316 : : "destination offset level must be fully masked");
6317 [ # # ]: 0 : if (action_conf->src.field != mask_conf->src.field)
6318 : 0 : return rte_flow_error_set(error, EINVAL,
6319 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6320 : : "destination field mask and template are not equal");
6321 [ # # ]: 0 : if (action_conf->src.field != RTE_FLOW_FIELD_POINTER &&
6322 : : action_conf->src.field != RTE_FLOW_FIELD_VALUE) {
6323 [ # # # # ]: 0 : if (action_conf->src.field != RTE_FLOW_FIELD_FLEX_ITEM &&
6324 : : !flow_hw_modify_field_is_geneve_opt(action_conf->src.field)) {
6325 [ # # ]: 0 : if (action_conf->src.tag_index &&
6326 : : !flow_modify_field_support_tag_array(action_conf->src.field))
6327 : 0 : return rte_flow_error_set(error, EINVAL,
6328 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6329 : : "source tag index is not supported");
6330 : : }
6331 [ # # ]: 0 : if (mask_conf->src.level != UINT8_MAX)
6332 : 0 : return rte_flow_error_set(error, EINVAL,
6333 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6334 : : "source encapsulation level must be fully masked");
6335 [ # # ]: 0 : if (mask_conf->src.offset != UINT32_MAX)
6336 : 0 : return rte_flow_error_set(error, EINVAL,
6337 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6338 : : "source offset level must be fully masked");
6339 : 0 : ret = flow_hw_validate_modify_field_level(&action_conf->src, true, error);
6340 [ # # ]: 0 : if (ret)
6341 : : return ret;
6342 : : }
6343 [ # # ]: 0 : if ((action_conf->dst.field == RTE_FLOW_FIELD_TAG &&
6344 [ # # # # ]: 0 : action_conf->dst.tag_index >= MLX5_FLOW_HW_TAGS_MAX &&
6345 : 0 : action_conf->dst.tag_index != RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ||
6346 [ # # ]: 0 : (action_conf->src.field == RTE_FLOW_FIELD_TAG &&
6347 [ # # # # ]: 0 : action_conf->src.tag_index >= MLX5_FLOW_HW_TAGS_MAX &&
6348 : : action_conf->src.tag_index != RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX))
6349 : 0 : return rte_flow_error_set(error, EINVAL,
6350 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6351 : : "tag index is out of range");
6352 [ # # # # ]: 0 : if ((action_conf->dst.field == RTE_FLOW_FIELD_TAG &&
6353 [ # # # # ]: 0 : flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, action_conf->dst.tag_index) == REG_NON) ||
6354 [ # # ]: 0 : (action_conf->src.field == RTE_FLOW_FIELD_TAG &&
6355 [ # # ]: 0 : flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, action_conf->src.tag_index) == REG_NON))
6356 : 0 : return rte_flow_error_set(error, EINVAL,
6357 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6358 : : "tag index is out of range");
6359 [ # # ]: 0 : if (mask_conf->width != UINT32_MAX)
6360 : 0 : return rte_flow_error_set(error, EINVAL,
6361 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6362 : : "modify_field width field must be fully masked");
6363 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_START))
6364 : 0 : return rte_flow_error_set(error, EINVAL,
6365 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6366 : : "modifying arbitrary place in a packet is not supported");
6367 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_VLAN_TYPE))
6368 : 0 : return rte_flow_error_set(error, EINVAL,
6369 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6370 : : "modifying vlan_type is not supported");
6371 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_RANDOM))
6372 : 0 : return rte_flow_error_set(error, EINVAL,
6373 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6374 : : "modifying random value is not supported");
6375 : : /**
6376 : : * Geneve VNI modification is supported only when Geneve header is
6377 : : * parsed natively. When GENEVE options are supported, they both Geneve
6378 : : * and options headers are parsed as a flex parser.
6379 : : */
6380 [ # # ]: 0 : if (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_VNI) &&
6381 [ # # ]: 0 : attr->geneve_tlv_opt)
6382 : 0 : return rte_flow_error_set(error, EINVAL,
6383 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6384 : : "modifying Geneve VNI is not supported when GENEVE opt is supported");
6385 [ # # # # ]: 0 : if (priv->tlv_options == NULL &&
6386 [ # # ]: 0 : (flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_OPT_TYPE) ||
6387 [ # # ]: 0 : flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_OPT_CLASS) ||
6388 : : flow_hw_modify_field_is_used(action_conf, RTE_FLOW_FIELD_GENEVE_OPT_DATA)))
6389 : 0 : return rte_flow_error_set(error, EINVAL,
6390 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6391 : : "modifying Geneve TLV option is supported only after parser configuration");
6392 : : /* Due to HW bug, tunnel MPLS header is read only. */
6393 [ # # ]: 0 : if (action_conf->dst.field == RTE_FLOW_FIELD_MPLS)
6394 : 0 : return rte_flow_error_set(error, EINVAL,
6395 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6396 : : "MPLS cannot be used as destination");
6397 : : /* ADD_FIELD is not supported for all the fields. */
6398 [ # # ]: 0 : if (!flow_hw_modify_field_is_add_dst_valid(action_conf))
6399 : 0 : return rte_flow_error_set(error, EINVAL,
6400 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6401 : : "invalid add_field destination");
6402 : : return 0;
6403 : : }
6404 : :
6405 : : static int
6406 : 0 : flow_hw_validate_action_port_representor(struct rte_eth_dev *dev __rte_unused,
6407 : : const struct rte_flow_actions_template_attr *attr,
6408 : : const struct rte_flow_action *action,
6409 : : const struct rte_flow_action *mask,
6410 : : struct rte_flow_error *error)
6411 : : {
6412 : : const struct rte_flow_action_ethdev *action_conf = NULL;
6413 : : const struct rte_flow_action_ethdev *mask_conf = NULL;
6414 : :
6415 : : /* If transfer is set, port has been validated as proxy port. */
6416 [ # # ]: 0 : if (!attr->transfer)
6417 : 0 : return rte_flow_error_set(error, EINVAL,
6418 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6419 : : "cannot use port_representor actions"
6420 : : " without an E-Switch");
6421 [ # # ]: 0 : if (!action || !mask)
6422 : 0 : return rte_flow_error_set(error, EINVAL,
6423 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6424 : : "actiona and mask configuration must be set");
6425 : 0 : action_conf = action->conf;
6426 : 0 : mask_conf = mask->conf;
6427 [ # # # # : 0 : if (!mask_conf || mask_conf->port_id != MLX5_REPRESENTED_PORT_ESW_MGR ||
# # ]
6428 [ # # ]: 0 : !action_conf || action_conf->port_id != MLX5_REPRESENTED_PORT_ESW_MGR)
6429 : 0 : return rte_flow_error_set(error, EINVAL,
6430 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6431 : : "only eswitch manager port 0xffff is"
6432 : : " supported");
6433 : : return 0;
6434 : : }
6435 : :
6436 : : static int
6437 : 0 : flow_hw_validate_target_port_id(struct rte_eth_dev *dev,
6438 : : uint16_t target_port_id)
6439 : : {
6440 : : struct mlx5_priv *port_priv;
6441 : : struct mlx5_priv *dev_priv;
6442 : :
6443 [ # # ]: 0 : if (target_port_id == MLX5_REPRESENTED_PORT_ESW_MGR)
6444 : : return 0;
6445 : :
6446 : 0 : port_priv = mlx5_port_to_eswitch_info(target_port_id, false);
6447 [ # # ]: 0 : if (!port_priv) {
6448 : 0 : rte_errno = EINVAL;
6449 : 0 : DRV_LOG(ERR, "Port %u Failed to obtain E-Switch info for port %u",
6450 : : dev->data->port_id, target_port_id);
6451 : 0 : return -rte_errno;
6452 : : }
6453 : :
6454 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
6455 [ # # ]: 0 : if (!dev_priv) {
6456 : 0 : rte_errno = EINVAL;
6457 : 0 : DRV_LOG(ERR, "Port %u Failed to obtain E-Switch info for transfer proxy",
6458 : : dev->data->port_id);
6459 : 0 : return -rte_errno;
6460 : : }
6461 : :
6462 [ # # ]: 0 : if (port_priv->domain_id != dev_priv->domain_id) {
6463 : 0 : rte_errno = EINVAL;
6464 : 0 : DRV_LOG(ERR, "Port %u Failed to obtain E-Switch info for transfer proxy",
6465 : : dev->data->port_id);
6466 : 0 : return -rte_errno;
6467 : : }
6468 : :
6469 : : return 0;
6470 : : }
6471 : :
6472 : : static int
6473 : 0 : flow_hw_validate_action_represented_port(struct rte_eth_dev *dev,
6474 : : const struct rte_flow_action *action,
6475 : : const struct rte_flow_action *mask,
6476 : : struct rte_flow_error *error)
6477 : : {
6478 : 0 : const struct rte_flow_action_ethdev *action_conf = action->conf;
6479 : 0 : const struct rte_flow_action_ethdev *mask_conf = mask->conf;
6480 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6481 : :
6482 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
6483 : 0 : return rte_flow_error_set(error, EINVAL,
6484 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6485 : : "cannot use represented_port actions"
6486 : : " without an E-Switch");
6487 [ # # # # ]: 0 : if (mask_conf && mask_conf->port_id) {
6488 [ # # ]: 0 : if (!action_conf)
6489 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
6490 : : action, "port index was not provided");
6491 : :
6492 [ # # ]: 0 : if (flow_hw_validate_target_port_id(dev, action_conf->port_id))
6493 : 0 : return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
6494 : : action, "port index is invalid");
6495 : : }
6496 : : return 0;
6497 : : }
6498 : :
6499 : : /**
6500 : : * Validate AGE action.
6501 : : *
6502 : : * @param[in] dev
6503 : : * Pointer to rte_eth_dev structure.
6504 : : * @param[in] action
6505 : : * Pointer to the indirect action.
6506 : : * @param[in] action_flags
6507 : : * Holds the actions detected until now.
6508 : : * @param[in] fixed_cnt
6509 : : * Indicator if this list has a fixed COUNT action.
6510 : : * @param[out] error
6511 : : * Pointer to error structure.
6512 : : *
6513 : : * @return
6514 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6515 : : */
6516 : : static int
6517 : 0 : flow_hw_validate_action_age(struct rte_eth_dev *dev,
6518 : : const struct rte_flow_action *action,
6519 : : uint64_t action_flags, bool fixed_cnt,
6520 : : struct rte_flow_error *error)
6521 : : {
6522 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6523 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
6524 : :
6525 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
6526 : 0 : return rte_flow_error_set(error, ENOTSUP,
6527 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6528 : : NULL, "AGE action not supported");
6529 [ # # ]: 0 : if (age_info->ages_ipool == NULL)
6530 : 0 : return rte_flow_error_set(error, EINVAL,
6531 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6532 : : "aging pool not initialized");
6533 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_AGE) ||
6534 : : (action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE))
6535 : 0 : return rte_flow_error_set(error, EINVAL,
6536 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6537 : : "duplicate AGE actions set");
6538 [ # # ]: 0 : if (fixed_cnt)
6539 : 0 : return rte_flow_error_set(error, EINVAL,
6540 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6541 : : "AGE and fixed COUNT combination is not supported");
6542 : : return 0;
6543 : : }
6544 : :
6545 : : /**
6546 : : * Validate count action.
6547 : : *
6548 : : * @param[in] dev
6549 : : * Pointer to rte_eth_dev structure.
6550 : : * @param[in] action
6551 : : * Pointer to the indirect action.
6552 : : * @param[in] mask
6553 : : * Pointer to the indirect action mask.
6554 : : * @param[in] action_flags
6555 : : * Holds the actions detected until now.
6556 : : * @param[out] error
6557 : : * Pointer to error structure.
6558 : : *
6559 : : * @return
6560 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6561 : : */
6562 : : static int
6563 : 0 : flow_hw_validate_action_count(struct rte_eth_dev *dev,
6564 : : const struct rte_flow_action *action,
6565 : : const struct rte_flow_action *mask,
6566 : : uint64_t action_flags,
6567 : : struct rte_flow_error *error)
6568 : : {
6569 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6570 : 0 : const struct rte_flow_action_count *count = mask->conf;
6571 : :
6572 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
6573 : 0 : return rte_flow_error_set(error, ENOTSUP,
6574 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6575 : : "count action not supported");
6576 [ # # ]: 0 : if (!priv->hws_cpool)
6577 : 0 : return rte_flow_error_set(error, EINVAL,
6578 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6579 : : "counters pool not initialized");
6580 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_COUNT) ||
6581 : : (action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT))
6582 : 0 : return rte_flow_error_set(error, EINVAL,
6583 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6584 : : "duplicate count actions set");
6585 [ # # # # : 0 : if (count && count->id && (action_flags & MLX5_FLOW_ACTION_AGE))
# # ]
6586 : 0 : return rte_flow_error_set(error, EINVAL,
6587 : : RTE_FLOW_ERROR_TYPE_ACTION, mask,
6588 : : "AGE and COUNT action shared by mask combination is not supported");
6589 : : return 0;
6590 : : }
6591 : :
6592 : : /**
6593 : : * Validate meter_mark action.
6594 : : *
6595 : : * @param[in] dev
6596 : : * Pointer to rte_eth_dev structure.
6597 : : * @param[in] action
6598 : : * Pointer to the indirect action.
6599 : : * @param[in] indirect
6600 : : * If true, then provided action was passed using an indirect action.
6601 : : * @param[out] error
6602 : : * Pointer to error structure.
6603 : : *
6604 : : * @return
6605 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6606 : : */
6607 : : static int
6608 : 0 : flow_hw_validate_action_meter_mark(struct rte_eth_dev *dev,
6609 : : const struct rte_flow_action *action,
6610 : : bool indirect,
6611 : : struct rte_flow_error *error)
6612 : : {
6613 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6614 : :
6615 : : RTE_SET_USED(action);
6616 : :
6617 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
6618 : 0 : return rte_flow_error_set(error, ENOTSUP,
6619 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6620 : : "meter_mark action not supported");
6621 [ # # # # ]: 0 : if (!indirect && priv->shared_host)
6622 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, action,
6623 : : "meter_mark action can only be used on host port");
6624 [ # # ]: 0 : if (!priv->hws_mpool)
6625 : 0 : return rte_flow_error_set(error, EINVAL,
6626 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6627 : : "meter_mark pool not initialized");
6628 : : return 0;
6629 : : }
6630 : :
6631 : : /**
6632 : : * Validate indirect action.
6633 : : *
6634 : : * @param[in] dev
6635 : : * Pointer to rte_eth_dev structure.
6636 : : * @param[in] action
6637 : : * Pointer to the indirect action.
6638 : : * @param[in] mask
6639 : : * Pointer to the indirect action mask.
6640 : : * @param[in] attr
6641 : : * Pointer to the action template attributes.
6642 : : * @param[in, out] action_flags
6643 : : * Holds the actions detected until now.
6644 : : * @param[in, out] fixed_cnt
6645 : : * Pointer to indicator if this list has a fixed COUNT action.
6646 : : * @param[out] error
6647 : : * Pointer to error structure.
6648 : : *
6649 : : * @return
6650 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6651 : : */
6652 : : static int
6653 : 0 : flow_hw_validate_action_indirect(struct rte_eth_dev *dev,
6654 : : const struct rte_flow_action *action,
6655 : : const struct rte_flow_action *mask,
6656 : : const struct rte_flow_actions_template_attr *attr,
6657 : : uint64_t *action_flags, bool *fixed_cnt,
6658 : : struct rte_flow_error *error)
6659 : : {
6660 : : uint32_t type;
6661 : : int ret;
6662 : :
6663 [ # # ]: 0 : if (!mask)
6664 : 0 : return rte_flow_error_set(error, EINVAL,
6665 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6666 : : "Unable to determine indirect action type without a mask specified");
6667 : 0 : type = mask->type;
6668 [ # # # # : 0 : switch (type) {
# # # ]
6669 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
6670 : 0 : ret = flow_hw_validate_action_meter_mark(dev, mask, true, error);
6671 [ # # ]: 0 : if (ret < 0)
6672 : : return ret;
6673 : 0 : *action_flags |= MLX5_FLOW_ACTION_METER;
6674 : 0 : break;
6675 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6676 : 0 : ret = mlx5_hw_validate_action_rss(dev, action, mask, attr,
6677 : : *action_flags, true, error);
6678 [ # # ]: 0 : if (ret < 0)
6679 : : return ret;
6680 : 0 : *action_flags |= MLX5_FLOW_ACTION_RSS;
6681 : 0 : break;
6682 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
6683 : 0 : ret = mlx5_hw_validate_action_conntrack(dev, action, mask, attr,
6684 : : *action_flags, error);
6685 [ # # ]: 0 : if (ret < 0)
6686 : : return ret;
6687 : 0 : *action_flags |= MLX5_FLOW_ACTION_CT;
6688 : 0 : break;
6689 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6690 [ # # # # ]: 0 : if (action->conf && mask->conf) {
6691 [ # # ]: 0 : if ((*action_flags & MLX5_FLOW_ACTION_AGE) ||
6692 : : (*action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE))
6693 : : /*
6694 : : * AGE cannot use indirect counter which is
6695 : : * shared with enother flow rules.
6696 : : */
6697 : 0 : return rte_flow_error_set(error, EINVAL,
6698 : : RTE_FLOW_ERROR_TYPE_ACTION,
6699 : : NULL,
6700 : : "AGE and fixed COUNT combination is not supported");
6701 : 0 : *fixed_cnt = true;
6702 : : }
6703 : 0 : ret = flow_hw_validate_action_count(dev, action, mask,
6704 : : *action_flags, error);
6705 [ # # ]: 0 : if (ret < 0)
6706 : : return ret;
6707 : 0 : *action_flags |= MLX5_FLOW_ACTION_INDIRECT_COUNT;
6708 : 0 : break;
6709 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
6710 [ # # # # ]: 0 : if (action->conf && mask->conf)
6711 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
6712 : : action,
6713 : : "Fixed indirect age action is not supported");
6714 : 0 : ret = flow_hw_validate_action_age(dev, action, *action_flags,
6715 : 0 : *fixed_cnt, error);
6716 [ # # ]: 0 : if (ret < 0)
6717 : : return ret;
6718 : 0 : *action_flags |= MLX5_FLOW_ACTION_INDIRECT_AGE;
6719 : 0 : break;
6720 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
6721 : : /* TODO: add proper quota verification */
6722 : 0 : *action_flags |= MLX5_FLOW_ACTION_QUOTA;
6723 : 0 : break;
6724 : 0 : default:
6725 : 0 : DRV_LOG(WARNING, "Unsupported shared action type: %d", type);
6726 : 0 : return rte_flow_error_set(error, ENOTSUP,
6727 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, mask,
6728 : : "Unsupported indirect action type");
6729 : : }
6730 : : return 0;
6731 : : }
6732 : :
6733 : : /**
6734 : : * Validate ipv6_ext_push action.
6735 : : *
6736 : : * @param[in] dev
6737 : : * Pointer to rte_eth_dev structure.
6738 : : * @param[in] action
6739 : : * Pointer to the indirect action.
6740 : : * @param[out] error
6741 : : * Pointer to error structure.
6742 : : *
6743 : : * @return
6744 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6745 : : */
6746 : : static int
6747 : 0 : flow_hw_validate_action_ipv6_ext_push(struct rte_eth_dev *dev __rte_unused,
6748 : : const struct rte_flow_action *action,
6749 : : struct rte_flow_error *error)
6750 : : {
6751 : 0 : const struct rte_flow_action_ipv6_ext_push *raw_push_data = action->conf;
6752 : :
6753 [ # # # # : 0 : if (!raw_push_data || !raw_push_data->size || !raw_push_data->data)
# # ]
6754 : 0 : return rte_flow_error_set(error, EINVAL,
6755 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6756 : : "invalid ipv6_ext_push data");
6757 [ # # # # ]: 0 : if (raw_push_data->type != IPPROTO_ROUTING ||
6758 : : raw_push_data->size > MLX5_PUSH_MAX_LEN)
6759 : 0 : return rte_flow_error_set(error, EINVAL,
6760 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6761 : : "Unsupported ipv6_ext_push type or length");
6762 : : return 0;
6763 : : }
6764 : :
6765 : : /**
6766 : : * Process `... / raw_decap / raw_encap / ...` actions sequence.
6767 : : * The PMD handles the sequence as a single encap or decap reformat action,
6768 : : * depending on the raw_encap configuration.
6769 : : *
6770 : : * The function assumes that the raw_decap / raw_encap location
6771 : : * in actions template list complies with relative HWS actions order:
6772 : : * for the required reformat configuration:
6773 : : * ENCAP configuration must appear before [JUMP|DROP|PORT]
6774 : : * DECAP configuration must appear at the template head.
6775 : : */
6776 : : static uint64_t
6777 : : mlx5_decap_encap_reformat_type(const struct rte_flow_action *actions,
6778 : : uint32_t encap_ind, uint64_t flags)
6779 : : {
6780 : 0 : const struct rte_flow_action_raw_encap *encap = actions[encap_ind].conf;
6781 : :
6782 [ # # ]: 0 : if ((flags & MLX5_FLOW_ACTION_DECAP) == 0)
6783 : : return MLX5_FLOW_ACTION_ENCAP;
6784 [ # # ]: 0 : if (actions[encap_ind - 1].type != RTE_FLOW_ACTION_TYPE_RAW_DECAP)
6785 : : return MLX5_FLOW_ACTION_ENCAP;
6786 : 0 : return encap->size >= MLX5_ENCAPSULATION_DECISION_SIZE ?
6787 [ # # ]: 0 : MLX5_FLOW_ACTION_ENCAP : MLX5_FLOW_ACTION_DECAP;
6788 : : }
6789 : :
6790 : : enum mlx5_hw_indirect_list_relative_position {
6791 : : MLX5_INDIRECT_LIST_POSITION_UNKNOWN = -1,
6792 : : MLX5_INDIRECT_LIST_POSITION_BEFORE_MH = 0,
6793 : : MLX5_INDIRECT_LIST_POSITION_AFTER_MH,
6794 : : };
6795 : :
6796 : : static enum mlx5_hw_indirect_list_relative_position
6797 : 0 : mlx5_hw_indirect_list_mh_position(const struct rte_flow_action *action)
6798 : : {
6799 : 0 : const struct rte_flow_action_indirect_list *conf = action->conf;
6800 [ # # # # ]: 0 : enum mlx5_indirect_list_type list_type = mlx5_get_indirect_list_type(conf->handle);
6801 : : enum mlx5_hw_indirect_list_relative_position pos = MLX5_INDIRECT_LIST_POSITION_UNKNOWN;
6802 : : const union {
6803 : : struct mlx5_indlst_legacy *legacy;
6804 : : struct mlx5_hw_encap_decap_action *reformat;
6805 : : struct rte_flow_action_list_handle *handle;
6806 : : } h = { .handle = conf->handle};
6807 : :
6808 [ # # # # ]: 0 : switch (list_type) {
6809 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
6810 [ # # # ]: 0 : switch (h.legacy->legacy_type) {
6811 : : case RTE_FLOW_ACTION_TYPE_AGE:
6812 : : case RTE_FLOW_ACTION_TYPE_COUNT:
6813 : : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
6814 : : case RTE_FLOW_ACTION_TYPE_METER_MARK:
6815 : : case RTE_FLOW_ACTION_TYPE_QUOTA:
6816 : : pos = MLX5_INDIRECT_LIST_POSITION_BEFORE_MH;
6817 : : break;
6818 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6819 : : pos = MLX5_INDIRECT_LIST_POSITION_AFTER_MH;
6820 : 0 : break;
6821 : 0 : default:
6822 : : pos = MLX5_INDIRECT_LIST_POSITION_UNKNOWN;
6823 : 0 : break;
6824 : : }
6825 : : break;
6826 : : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
6827 : : pos = MLX5_INDIRECT_LIST_POSITION_AFTER_MH;
6828 : : break;
6829 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
6830 [ # # # ]: 0 : switch (h.reformat->action_type) {
6831 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
6832 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
6833 : : pos = MLX5_INDIRECT_LIST_POSITION_BEFORE_MH;
6834 : : break;
6835 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
6836 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
6837 : : pos = MLX5_INDIRECT_LIST_POSITION_AFTER_MH;
6838 : 0 : break;
6839 : 0 : default:
6840 : : pos = MLX5_INDIRECT_LIST_POSITION_UNKNOWN;
6841 : 0 : break;
6842 : : }
6843 : : break;
6844 : 0 : default:
6845 : : pos = MLX5_INDIRECT_LIST_POSITION_UNKNOWN;
6846 : 0 : break;
6847 : : }
6848 : 0 : return pos;
6849 : : }
6850 : :
6851 : : #define MLX5_HW_EXPAND_MH_FAILED 0xffff
6852 : :
6853 : : static inline uint16_t
6854 : 0 : flow_hw_template_expand_modify_field(struct rte_flow_action actions[],
6855 : : struct rte_flow_action masks[],
6856 : : const struct rte_flow_action *mf_actions,
6857 : : const struct rte_flow_action *mf_masks,
6858 : : uint64_t flags, uint32_t act_num,
6859 : : uint32_t mf_num)
6860 : : {
6861 : : uint32_t i, tail;
6862 : :
6863 : : MLX5_ASSERT(actions && masks);
6864 : : MLX5_ASSERT(mf_num > 0);
6865 [ # # ]: 0 : if (flags & MLX5_FLOW_ACTION_MODIFY_FIELD) {
6866 : : /*
6867 : : * Application action template already has Modify Field.
6868 : : * It's location will be used in DR.
6869 : : * Expanded MF action can be added before the END.
6870 : : */
6871 : 0 : i = act_num - 1;
6872 : 0 : goto insert;
6873 : : }
6874 : : /**
6875 : : * Locate the first action positioned BEFORE the new MF.
6876 : : *
6877 : : * Search for a place to insert modify header
6878 : : * from the END action backwards:
6879 : : * 1. END is always present in actions array
6880 : : * 2. END location is always at action[act_num - 1]
6881 : : * 3. END always positioned AFTER modify field location
6882 : : *
6883 : : * Relative actions order is the same for RX, TX and FDB.
6884 : : *
6885 : : * Current actions order (draft-3)
6886 : : * @see action_order_arr[]
6887 : : */
6888 [ # # ]: 0 : for (i = act_num - 2; (int)i >= 0; i--) {
6889 : : enum mlx5_hw_indirect_list_relative_position pos;
6890 : 0 : enum rte_flow_action_type type = actions[i].type;
6891 : : uint64_t reformat_type;
6892 : :
6893 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_INDIRECT)
6894 : 0 : type = masks[i].type;
6895 [ # # # # ]: 0 : switch (type) {
6896 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6897 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6898 : : case RTE_FLOW_ACTION_TYPE_DROP:
6899 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
6900 : : case RTE_FLOW_ACTION_TYPE_JUMP:
6901 : : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
6902 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
6903 : : case RTE_FLOW_ACTION_TYPE_RSS:
6904 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6905 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
6906 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6907 : : case RTE_FLOW_ACTION_TYPE_VOID:
6908 : : case RTE_FLOW_ACTION_TYPE_END:
6909 : : break;
6910 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6911 : : reformat_type =
6912 : : mlx5_decap_encap_reformat_type(actions, i,
6913 : : flags);
6914 : : if (reformat_type == MLX5_FLOW_ACTION_DECAP) {
6915 : 0 : i++;
6916 : 0 : goto insert;
6917 : : }
6918 [ # # ]: 0 : if (actions[i - 1].type == RTE_FLOW_ACTION_TYPE_RAW_DECAP)
6919 : : i--;
6920 : : break;
6921 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
6922 : 0 : pos = mlx5_hw_indirect_list_mh_position(&actions[i]);
6923 [ # # ]: 0 : if (pos == MLX5_INDIRECT_LIST_POSITION_UNKNOWN)
6924 : : return MLX5_HW_EXPAND_MH_FAILED;
6925 [ # # ]: 0 : if (pos == MLX5_INDIRECT_LIST_POSITION_BEFORE_MH)
6926 : 0 : goto insert;
6927 : : break;
6928 : 0 : default:
6929 : 0 : i++; /* new MF inserted AFTER actions[i] */
6930 : 0 : goto insert;
6931 : : }
6932 : : }
6933 : : i = 0;
6934 : 0 : insert:
6935 : 0 : tail = act_num - i; /* num action to move */
6936 : 0 : memmove(actions + i + mf_num, actions + i, sizeof(actions[0]) * tail);
6937 : 0 : memcpy(actions + i, mf_actions, sizeof(actions[0]) * mf_num);
6938 : 0 : memmove(masks + i + mf_num, masks + i, sizeof(masks[0]) * tail);
6939 : : memcpy(masks + i, mf_masks, sizeof(masks[0]) * mf_num);
6940 : 0 : return i;
6941 : : }
6942 : :
6943 : : static int
6944 : 0 : flow_hw_validate_action_push_vlan(struct rte_eth_dev *dev,
6945 : : const
6946 : : struct rte_flow_actions_template_attr *attr,
6947 : : const struct rte_flow_action *action,
6948 : : const struct rte_flow_action *mask,
6949 : : struct rte_flow_error *error)
6950 : : {
6951 : : #define X_FIELD(ptr, t, f) (((ptr)->conf) && ((t *)((ptr)->conf))->f)
6952 : :
6953 : 0 : const bool masked_push =
6954 [ # # # # ]: 0 : X_FIELD(mask + MLX5_HW_VLAN_PUSH_TYPE_IDX,
6955 : : const struct rte_flow_action_of_push_vlan, ethertype);
6956 : : bool masked_param;
6957 : :
6958 : : /*
6959 : : * Mandatory actions order:
6960 : : * OF_PUSH_VLAN / OF_SET_VLAN_VID [ / OF_SET_VLAN_PCP ]
6961 : : */
6962 : : RTE_SET_USED(dev);
6963 : : RTE_SET_USED(attr);
6964 : : /* Check that mark matches OF_PUSH_VLAN */
6965 [ # # ]: 0 : if (mask[MLX5_HW_VLAN_PUSH_TYPE_IDX].type !=
6966 : : RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
6967 : 0 : return rte_flow_error_set(error, EINVAL,
6968 : : RTE_FLOW_ERROR_TYPE_ACTION,
6969 : : action, "OF_PUSH_VLAN: mask does not match");
6970 : : /* Check that the second template and mask items are SET_VLAN_VID */
6971 [ # # ]: 0 : if (action[MLX5_HW_VLAN_PUSH_VID_IDX].type !=
6972 : 0 : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID ||
6973 [ # # ]: 0 : mask[MLX5_HW_VLAN_PUSH_VID_IDX].type !=
6974 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
6975 : 0 : return rte_flow_error_set(error, EINVAL,
6976 : : RTE_FLOW_ERROR_TYPE_ACTION,
6977 : : action, "OF_PUSH_VLAN: invalid actions order");
6978 [ # # # # ]: 0 : masked_param = X_FIELD(mask + MLX5_HW_VLAN_PUSH_VID_IDX,
6979 : : const struct rte_flow_action_of_set_vlan_vid,
6980 : : vlan_vid);
6981 : : /*
6982 : : * PMD requires OF_SET_VLAN_VID mask to must match OF_PUSH_VLAN
6983 : : */
6984 [ # # ]: 0 : if (masked_push ^ masked_param)
6985 : 0 : return rte_flow_error_set(error, EINVAL,
6986 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6987 : : "OF_SET_VLAN_VID: mask does not match OF_PUSH_VLAN");
6988 [ # # ]: 0 : if (is_of_vlan_pcp_present(action)) {
6989 [ # # ]: 0 : if (mask[MLX5_HW_VLAN_PUSH_PCP_IDX].type !=
6990 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)
6991 : 0 : return rte_flow_error_set(error, EINVAL,
6992 : : RTE_FLOW_ERROR_TYPE_ACTION,
6993 : : action, "OF_SET_VLAN_PCP: missing mask configuration");
6994 [ # # # # ]: 0 : masked_param = X_FIELD(mask + MLX5_HW_VLAN_PUSH_PCP_IDX,
6995 : : const struct
6996 : : rte_flow_action_of_set_vlan_pcp,
6997 : : vlan_pcp);
6998 : : /*
6999 : : * PMD requires OF_SET_VLAN_PCP mask to must match OF_PUSH_VLAN
7000 : : */
7001 [ # # ]: 0 : if (masked_push ^ masked_param)
7002 : 0 : return rte_flow_error_set(error, EINVAL,
7003 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
7004 : : "OF_SET_VLAN_PCP: mask does not match OF_PUSH_VLAN");
7005 : : }
7006 : : return 0;
7007 : : #undef X_FIELD
7008 : : }
7009 : :
7010 : : static int
7011 : 0 : flow_hw_validate_action_default_miss(const struct rte_flow_actions_template_attr *attr,
7012 : : uint64_t action_flags,
7013 : : struct rte_flow_error *error)
7014 : : {
7015 : : /*
7016 : : * The private DEFAULT_MISS action is used internally for LACP in control
7017 : : * flows. So this validation can be ignored. It can be kept right now since
7018 : : * the validation will be done only once.
7019 : : */
7020 [ # # ]: 0 : if (!attr->ingress || attr->egress || attr->transfer)
7021 : 0 : return rte_flow_error_set(error, EINVAL,
7022 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7023 : : "DEFAULT MISS is only supported in ingress.");
7024 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
7025 : 0 : return rte_flow_error_set(error, EINVAL,
7026 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7027 : : "DEFAULT MISS should be the only termination.");
7028 : : return 0;
7029 : : }
7030 : :
7031 : : static int
7032 : 0 : flow_hw_validate_action_nat64(struct rte_eth_dev *dev, struct rte_flow_error *error)
7033 : : {
7034 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7035 : :
7036 [ # # ]: 0 : if (!flow_hw_should_create_nat64_actions(priv))
7037 : 0 : return rte_flow_error_set(error, EOPNOTSUPP,
7038 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7039 : : "NAT64 action is not supported.");
7040 : :
7041 : : return 0;
7042 : : }
7043 : :
7044 : : static int
7045 : 0 : flow_hw_validate_action_jump(struct rte_eth_dev *dev,
7046 : : const struct rte_flow_actions_template_attr *attr,
7047 : : const struct rte_flow_action *action,
7048 : : const struct rte_flow_action *mask,
7049 : : struct rte_flow_error *error)
7050 : : {
7051 : 0 : const struct rte_flow_action_jump *m = mask->conf;
7052 : 0 : const struct rte_flow_action_jump *v = action->conf;
7053 : 0 : struct mlx5_flow_template_table_cfg cfg = {
7054 : : .external = true,
7055 : : .attr = {
7056 : : .flow_attr = {
7057 : 0 : .ingress = attr->ingress,
7058 : 0 : .egress = attr->egress,
7059 : 0 : .transfer = attr->transfer,
7060 : : },
7061 : : },
7062 : : };
7063 : 0 : uint32_t t_group = 0;
7064 : :
7065 [ # # # # ]: 0 : if (!m || !m->group)
7066 : : return 0;
7067 [ # # ]: 0 : if (!v)
7068 : 0 : return rte_flow_error_set(error, EINVAL,
7069 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
7070 : : "Invalid jump action configuration");
7071 [ # # ]: 0 : if (flow_hw_translate_group(dev, &cfg, v->group, &t_group, error))
7072 : 0 : return -rte_errno;
7073 [ # # ]: 0 : if (t_group == 0)
7074 : 0 : return rte_flow_error_set(error, EINVAL,
7075 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
7076 : : "Unsupported action - jump to root table");
7077 : : return 0;
7078 : : }
7079 : :
7080 : : static int
7081 : 0 : mlx5_flow_validate_action_jump_to_table_index(const struct rte_flow_action *action,
7082 : : const struct rte_flow_action *mask,
7083 : : struct rte_flow_error *error)
7084 : : {
7085 : 0 : const struct rte_flow_action_jump_to_table_index *m = mask->conf;
7086 : 0 : const struct rte_flow_action_jump_to_table_index *v = action->conf;
7087 : : struct mlx5dr_action *jump_action;
7088 : : uint32_t t_group = 0;
7089 : :
7090 [ # # # # ]: 0 : if (!m || !m->table)
7091 : : return 0;
7092 [ # # ]: 0 : if (!v)
7093 : 0 : return rte_flow_error_set(error, EINVAL,
7094 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
7095 : : "Invalid jump to matcher action configuration");
7096 : 0 : t_group = v->table->grp->group_id;
7097 [ # # ]: 0 : if (t_group == 0)
7098 : 0 : return rte_flow_error_set(error, EINVAL,
7099 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
7100 : : "Unsupported action - jump to root table");
7101 [ # # ]: 0 : if (likely(!rte_flow_template_table_resizable(0, &v->table->cfg.attr))) {
7102 : 0 : jump_action = v->table->matcher_info[0].jump;
7103 : : } else {
7104 : : uint32_t selector;
7105 : 0 : rte_rwlock_read_lock(&v->table->matcher_replace_rwlk);
7106 : 0 : selector = v->table->matcher_selector;
7107 : 0 : jump_action = v->table->matcher_info[selector].jump;
7108 : : rte_rwlock_read_unlock(&v->table->matcher_replace_rwlk);
7109 : : }
7110 [ # # ]: 0 : if (jump_action == NULL)
7111 : 0 : return rte_flow_error_set(error, EINVAL,
7112 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
7113 : : "Unsupported action - table is not an rule array");
7114 : : return 0;
7115 : : }
7116 : :
7117 : : static int
7118 : 0 : mlx5_hw_validate_action_mark(struct rte_eth_dev *dev,
7119 : : const struct rte_flow_action *template_action,
7120 : : const struct rte_flow_action *template_mask,
7121 : : uint64_t action_flags,
7122 : : const struct rte_flow_actions_template_attr *template_attr,
7123 : : struct rte_flow_error *error)
7124 : : {
7125 : 0 : const struct rte_flow_action_mark *mark_mask = template_mask->conf;
7126 : : const struct rte_flow_action *action =
7127 [ # # # # ]: 0 : mark_mask && mark_mask->id ? template_action :
7128 : 0 : &(const struct rte_flow_action) {
7129 : : .type = RTE_FLOW_ACTION_TYPE_MARK,
7130 : 0 : .conf = &(const struct rte_flow_action_mark) {
7131 : : .id = MLX5_FLOW_MARK_MAX - 1
7132 : : }
7133 : : };
7134 : 0 : const struct rte_flow_attr attr = {
7135 : 0 : .ingress = template_attr->ingress,
7136 : 0 : .egress = template_attr->egress,
7137 : 0 : .transfer = template_attr->transfer
7138 : : };
7139 : :
7140 [ # # ]: 0 : if (template_attr->transfer &&
7141 [ # # ]: 0 : !MLX5_SH(dev)->cdev->config.hca_attr.fdb_rx_set_flow_tag_stc)
7142 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7143 : : action,
7144 : : "mark action not supported for transfer");
7145 : :
7146 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
7147 : : &attr, error);
7148 : : }
7149 : :
7150 : : static int
7151 : 0 : mlx5_hw_validate_action_queue(struct rte_eth_dev *dev,
7152 : : const struct rte_flow_action *template_action,
7153 : : const struct rte_flow_action *template_mask,
7154 : : const struct rte_flow_actions_template_attr *template_attr,
7155 : : uint64_t action_flags,
7156 : : struct rte_flow_error *error)
7157 : : {
7158 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7159 : 0 : const struct rte_flow_action_queue *queue_mask = template_mask->conf;
7160 : 0 : const struct rte_flow_attr attr = {
7161 : 0 : .ingress = template_attr->ingress,
7162 : 0 : .egress = template_attr->egress,
7163 : 0 : .transfer = template_attr->transfer
7164 : : };
7165 [ # # # # ]: 0 : bool masked = queue_mask != NULL && queue_mask->index;
7166 : :
7167 [ # # # # : 0 : if (template_attr->egress || (template_attr->transfer && !priv->jump_fdb_rx_en))
# # ]
7168 : 0 : return rte_flow_error_set(error, EINVAL,
7169 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7170 : : "QUEUE action supported for ingress only");
7171 [ # # ]: 0 : if (masked)
7172 : 0 : return mlx5_flow_validate_action_queue(template_action, action_flags, dev,
7173 : : &attr, error);
7174 : : else
7175 : : return 0;
7176 : : }
7177 : :
7178 : : static int
7179 : 0 : mlx5_hw_validate_action_rss(struct rte_eth_dev *dev,
7180 : : const struct rte_flow_action *template_action,
7181 : : const struct rte_flow_action *template_mask,
7182 : : const struct rte_flow_actions_template_attr *template_attr,
7183 : : __rte_unused uint64_t action_flags,
7184 : : bool is_indirect,
7185 : : struct rte_flow_error *error)
7186 : : {
7187 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7188 : 0 : const struct rte_flow_action_rss *mask = template_mask->conf;
7189 : :
7190 [ # # # # : 0 : if (template_attr->egress || (template_attr->transfer && !priv->jump_fdb_rx_en))
# # ]
7191 : 0 : return rte_flow_error_set(error, EINVAL,
7192 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7193 : : "RSS action supported for ingress only");
7194 [ # # ]: 0 : if (is_indirect)
7195 : : return 0;
7196 [ # # ]: 0 : if (mask != NULL)
7197 : 0 : return mlx5_validate_action_rss(dev, template_action, error);
7198 : : else
7199 : : return 0;
7200 : : }
7201 : :
7202 : : static int
7203 : 0 : mlx5_hw_validate_action_l2_encap(struct rte_eth_dev *dev,
7204 : : const struct rte_flow_action *template_action,
7205 : : const struct rte_flow_action *template_mask,
7206 : : const struct rte_flow_actions_template_attr *template_attr,
7207 : : uint64_t action_flags,
7208 : : struct rte_flow_error *error)
7209 : : {
7210 : 0 : const struct rte_flow_action_vxlan_encap default_action_conf = {
7211 : : .definition = (struct rte_flow_item *)
7212 : 0 : (struct rte_flow_item [1]) {
7213 : : [0] = { .type = RTE_FLOW_ITEM_TYPE_END }
7214 : : }
7215 : : };
7216 : 0 : const struct rte_flow_action *action = template_mask->conf ?
7217 [ # # ]: 0 : template_action : &(const struct rte_flow_action) {
7218 : 0 : .type = template_mask->type,
7219 : : .conf = &default_action_conf
7220 : : };
7221 : 0 : const struct rte_flow_attr attr = {
7222 : 0 : .ingress = template_attr->ingress,
7223 : 0 : .egress = template_attr->egress,
7224 : 0 : .transfer = template_attr->transfer
7225 : : };
7226 : :
7227 : 0 : return mlx5_flow_dv_validate_action_l2_encap(dev, action_flags, action,
7228 : : &attr, error);
7229 : : }
7230 : :
7231 : : static int
7232 : 0 : mlx5_hw_validate_action_l2_decap(struct rte_eth_dev *dev,
7233 : : const struct rte_flow_action *template_action,
7234 : : const struct rte_flow_action *template_mask,
7235 : : const struct rte_flow_actions_template_attr *template_attr,
7236 : : uint64_t action_flags,
7237 : : struct rte_flow_error *error)
7238 : : {
7239 : 0 : const struct rte_flow_action_vxlan_encap default_action_conf = {
7240 : : .definition = (struct rte_flow_item *)
7241 : 0 : (struct rte_flow_item [1]) {
7242 : : [0] = { .type = RTE_FLOW_ITEM_TYPE_END }
7243 : : }
7244 : : };
7245 : 0 : const struct rte_flow_action *action = template_mask->conf ?
7246 [ # # ]: 0 : template_action : &(const struct rte_flow_action) {
7247 : 0 : .type = template_mask->type,
7248 : : .conf = &default_action_conf
7249 : : };
7250 : 0 : const struct rte_flow_attr attr = {
7251 : 0 : .ingress = template_attr->ingress,
7252 : 0 : .egress = template_attr->egress,
7253 : 0 : .transfer = template_attr->transfer
7254 : : };
7255 : : uint64_t item_flags =
7256 : 0 : action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
7257 [ # # ]: 0 : MLX5_FLOW_LAYER_VXLAN : 0;
7258 : :
7259 : 0 : return mlx5_flow_dv_validate_action_decap(dev, action_flags, action,
7260 : : item_flags, &attr, error);
7261 : : }
7262 : :
7263 : : static int
7264 : : mlx5_hw_validate_action_conntrack(struct rte_eth_dev *dev,
7265 : : const struct rte_flow_action *template_action,
7266 : : const struct rte_flow_action *template_mask,
7267 : : const struct rte_flow_actions_template_attr *template_attr,
7268 : : uint64_t action_flags,
7269 : : struct rte_flow_error *error)
7270 : : {
7271 : : RTE_SET_USED(template_action);
7272 : : RTE_SET_USED(template_mask);
7273 : : RTE_SET_USED(template_attr);
7274 : 0 : return mlx5_flow_dv_validate_action_aso_ct(dev, action_flags,
7275 : : MLX5_FLOW_LAYER_OUTER_L4_TCP,
7276 : : false, error);
7277 : : }
7278 : :
7279 : : static int
7280 : 0 : flow_hw_validate_action_raw_encap(const struct rte_flow_action *action,
7281 : : const struct rte_flow_action *mask,
7282 : : struct rte_flow_error *error)
7283 : : {
7284 : 0 : const struct rte_flow_action_raw_encap *mask_conf = mask->conf;
7285 : 0 : const struct rte_flow_action_raw_encap *action_conf = action->conf;
7286 : :
7287 [ # # # # ]: 0 : if (!mask_conf || !mask_conf->size)
7288 : 0 : return rte_flow_error_set(error, EINVAL,
7289 : : RTE_FLOW_ERROR_TYPE_ACTION, mask,
7290 : : "raw_encap: size must be masked");
7291 [ # # # # ]: 0 : if (!action_conf || !action_conf->size)
7292 : 0 : return rte_flow_error_set(error, EINVAL,
7293 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
7294 : : "raw_encap: invalid action configuration");
7295 [ # # # # ]: 0 : if (mask_conf->data && !action_conf->data)
7296 : 0 : return rte_flow_error_set(error, EINVAL,
7297 : : RTE_FLOW_ERROR_TYPE_ACTION,
7298 : : action, "raw_encap: masked data is missing");
7299 : : return 0;
7300 : : }
7301 : :
7302 : :
7303 : : static int
7304 : 0 : flow_hw_validate_action_raw_reformat(struct rte_eth_dev *dev,
7305 : : const struct rte_flow_action *template_action,
7306 : : const struct rte_flow_action *template_mask,
7307 : : const struct
7308 : : rte_flow_actions_template_attr *template_attr,
7309 : : uint64_t *action_flags,
7310 : : struct rte_flow_error *error)
7311 : : {
7312 : : const struct rte_flow_action *encap_action = NULL;
7313 : : const struct rte_flow_action *encap_mask = NULL;
7314 : : const struct rte_flow_action_raw_decap *raw_decap = NULL;
7315 : : const struct rte_flow_action_raw_encap *raw_encap = NULL;
7316 : 0 : const struct rte_flow_attr attr = {
7317 : 0 : .ingress = template_attr->ingress,
7318 : 0 : .egress = template_attr->egress,
7319 : 0 : .transfer = template_attr->transfer
7320 : : };
7321 : : uint64_t item_flags = 0;
7322 : 0 : int ret, actions_n = 0;
7323 : :
7324 [ # # ]: 0 : if (template_action->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP) {
7325 : 0 : raw_decap = template_mask->conf ?
7326 [ # # ]: 0 : template_action->conf : &empty_decap;
7327 [ # # ]: 0 : if ((template_action + 1)->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7328 [ # # ]: 0 : if ((template_mask + 1)->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP)
7329 : 0 : return rte_flow_error_set(error, EINVAL,
7330 : : RTE_FLOW_ERROR_TYPE_ACTION,
7331 : 0 : template_mask + 1, "invalid mask type");
7332 : 0 : encap_action = template_action + 1;
7333 : 0 : encap_mask = template_mask + 1;
7334 : : }
7335 : : } else {
7336 : : encap_action = template_action;
7337 : : encap_mask = template_mask;
7338 : : }
7339 [ # # ]: 0 : if (encap_action) {
7340 : 0 : raw_encap = encap_action->conf;
7341 : 0 : ret = flow_hw_validate_action_raw_encap(encap_action,
7342 : : encap_mask, error);
7343 [ # # ]: 0 : if (ret)
7344 : : return ret;
7345 : : }
7346 : 0 : return mlx5_flow_dv_validate_action_raw_encap_decap(dev, raw_decap,
7347 : : raw_encap, &attr,
7348 : : action_flags,
7349 : : &actions_n,
7350 : : template_action,
7351 : : item_flags, error);
7352 : : }
7353 : :
7354 : :
7355 : :
7356 : : static int
7357 : 0 : mlx5_flow_hw_actions_validate(struct rte_eth_dev *dev,
7358 : : const struct rte_flow_actions_template_attr *attr,
7359 : : const struct rte_flow_action actions[],
7360 : : const struct rte_flow_action masks[],
7361 : : uint64_t *act_flags,
7362 : : struct rte_flow_error *error)
7363 : : {
7364 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7365 : : const struct rte_flow_action_count *count_mask = NULL;
7366 : 0 : bool fixed_cnt = false;
7367 : 0 : uint64_t action_flags = 0;
7368 : : bool actions_end = false;
7369 : : uint16_t i;
7370 : : int ret;
7371 : : const struct rte_flow_action_ipv6_ext_remove *remove_data;
7372 : :
7373 [ # # ]: 0 : if (!mlx5_hw_ctx_validate(dev, error))
7374 : 0 : return -rte_errno;
7375 : : /* FDB actions are only valid to proxy port. */
7376 [ # # # # : 0 : if (attr->transfer && (!priv->sh->config.dv_esw_en || !priv->master))
# # ]
7377 : 0 : return rte_flow_error_set(error, EINVAL,
7378 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7379 : : NULL,
7380 : : "transfer actions are only valid to proxy port");
7381 [ # # ]: 0 : for (i = 0; !actions_end; ++i) {
7382 : 0 : const struct rte_flow_action *action = &actions[i];
7383 : 0 : const struct rte_flow_action *mask = &masks[i];
7384 : :
7385 : : MLX5_ASSERT(i < MLX5_HW_MAX_ACTS);
7386 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_INDIRECT &&
7387 [ # # ]: 0 : action->type != mask->type)
7388 : 0 : return rte_flow_error_set(error, ENOTSUP,
7389 : : RTE_FLOW_ERROR_TYPE_ACTION,
7390 : : action,
7391 : : "mask type does not match action type");
7392 [ # # # # : 0 : switch ((int)action->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
7393 : : case RTE_FLOW_ACTION_TYPE_VOID:
7394 : 0 : break;
7395 : : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
7396 : : break;
7397 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
7398 : 0 : ret = flow_hw_validate_action_indirect(dev, action,
7399 : : mask,
7400 : : attr,
7401 : : &action_flags,
7402 : : &fixed_cnt,
7403 : : error);
7404 [ # # ]: 0 : if (ret < 0)
7405 : 0 : return ret;
7406 : : break;
7407 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
7408 : : /* TODO: Validation logic */
7409 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
7410 : 0 : break;
7411 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
7412 : 0 : ret = mlx5_hw_validate_action_mark(dev, action, mask,
7413 : : action_flags,
7414 : : attr, error);
7415 [ # # ]: 0 : if (ret)
7416 : 0 : return ret;
7417 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
7418 : 0 : break;
7419 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
7420 : 0 : ret = mlx5_flow_validate_action_drop
7421 : : (dev, action_flags,
7422 : 0 : &(struct rte_flow_attr){.egress = attr->egress},
7423 : : error);
7424 [ # # ]: 0 : if (ret)
7425 : 0 : return ret;
7426 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
7427 : 0 : break;
7428 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
7429 : : /* Only validate the jump to root table in template stage. */
7430 : 0 : ret = flow_hw_validate_action_jump(dev, attr, action, mask, error);
7431 [ # # ]: 0 : if (ret)
7432 : 0 : return ret;
7433 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
7434 : 0 : break;
7435 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
7436 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
7437 : : if (priv->shared_host)
7438 : : return rte_flow_error_set(error, ENOTSUP,
7439 : : RTE_FLOW_ERROR_TYPE_ACTION,
7440 : : action,
7441 : : "action not supported in guest port");
7442 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
7443 : : break;
7444 : : #endif
7445 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
7446 : 0 : ret = mlx5_hw_validate_action_queue(dev, action, mask,
7447 : : attr, action_flags,
7448 : : error);
7449 [ # # ]: 0 : if (ret)
7450 : 0 : return ret;
7451 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
7452 : 0 : break;
7453 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
7454 : 0 : ret = mlx5_hw_validate_action_rss(dev, action, mask,
7455 : : attr, action_flags,
7456 : : false, error);
7457 [ # # ]: 0 : if (ret)
7458 : 0 : return ret;
7459 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
7460 : 0 : break;
7461 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7462 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7463 : 0 : ret = mlx5_hw_validate_action_l2_encap(dev, action, mask,
7464 : : attr, action_flags,
7465 : : error);
7466 [ # # ]: 0 : if (ret)
7467 : 0 : return ret;
7468 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
7469 : 0 : break;
7470 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7471 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7472 : 0 : ret = mlx5_hw_validate_action_l2_decap(dev, action, mask,
7473 : : attr, action_flags,
7474 : : error);
7475 [ # # ]: 0 : if (ret)
7476 : 0 : return ret;
7477 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
7478 : 0 : break;
7479 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7480 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7481 : 0 : ret = flow_hw_validate_action_raw_reformat(dev, action,
7482 : : mask, attr,
7483 : : &action_flags,
7484 : : error);
7485 [ # # ]: 0 : if (ret)
7486 : 0 : return ret;
7487 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP &&
7488 [ # # ]: 0 : (action + 1)->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7489 : 0 : action_flags |= MLX5_FLOW_XCAP_ACTIONS;
7490 : 0 : i++;
7491 : : }
7492 : : break;
7493 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
7494 : 0 : ret = flow_hw_validate_action_ipv6_ext_push(dev, action, error);
7495 [ # # ]: 0 : if (ret < 0)
7496 : 0 : return ret;
7497 : 0 : action_flags |= MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH;
7498 : 0 : break;
7499 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE:
7500 : 0 : remove_data = action->conf;
7501 : : /* Remove action must be shared. */
7502 [ # # # # ]: 0 : if (remove_data->type != IPPROTO_ROUTING || !mask) {
7503 : 0 : DRV_LOG(ERR, "Only supports shared IPv6 routing remove");
7504 : 0 : return -EINVAL;
7505 : : }
7506 : 0 : action_flags |= MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE;
7507 : 0 : break;
7508 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
7509 : 0 : ret = flow_hw_validate_action_meter_mark(dev, action, false, error);
7510 [ # # ]: 0 : if (ret < 0)
7511 : 0 : return ret;
7512 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
7513 : 0 : break;
7514 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7515 : 0 : ret = flow_hw_validate_action_modify_field(dev, action, mask,
7516 : : error);
7517 [ # # ]: 0 : if (ret < 0)
7518 : 0 : return ret;
7519 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7520 : 0 : break;
7521 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7522 : 0 : ret = flow_hw_validate_action_represented_port
7523 : : (dev, action, mask, error);
7524 [ # # ]: 0 : if (ret < 0)
7525 : 0 : return ret;
7526 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7527 : 0 : break;
7528 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
7529 : 0 : ret = flow_hw_validate_action_port_representor
7530 : : (dev, attr, action, mask, error);
7531 [ # # ]: 0 : if (ret < 0)
7532 : 0 : return ret;
7533 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_REPRESENTOR;
7534 : 0 : break;
7535 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
7536 [ # # # # ]: 0 : if (count_mask && count_mask->id)
7537 : 0 : fixed_cnt = true;
7538 : 0 : ret = flow_hw_validate_action_age(dev, action,
7539 : : action_flags,
7540 : : fixed_cnt, error);
7541 [ # # ]: 0 : if (ret < 0)
7542 : 0 : return ret;
7543 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
7544 : 0 : break;
7545 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
7546 : 0 : ret = flow_hw_validate_action_count(dev, action, mask,
7547 : : action_flags,
7548 : : error);
7549 [ # # ]: 0 : if (ret < 0)
7550 : 0 : return ret;
7551 : 0 : count_mask = mask->conf;
7552 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
7553 : 0 : break;
7554 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7555 : 0 : ret = mlx5_hw_validate_action_conntrack(dev, action, mask,
7556 : : attr, action_flags,
7557 : : error);
7558 [ # # ]: 0 : if (ret)
7559 : 0 : return ret;
7560 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
7561 : 0 : break;
7562 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7563 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7564 : 0 : break;
7565 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7566 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7567 : 0 : break;
7568 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7569 : 0 : ret = flow_hw_validate_action_push_vlan
7570 : : (dev, attr, action, mask, error);
7571 [ # # ]: 0 : if (ret != 0)
7572 : 0 : return ret;
7573 : 0 : i += is_of_vlan_pcp_present(action) ?
7574 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
7575 : : MLX5_HW_VLAN_PUSH_VID_IDX;
7576 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7577 : 0 : break;
7578 : 0 : case RTE_FLOW_ACTION_TYPE_NAT64:
7579 : 0 : ret = flow_hw_validate_action_nat64(dev, error);
7580 [ # # ]: 0 : if (ret != 0)
7581 : 0 : return ret;
7582 : 0 : action_flags |= MLX5_FLOW_ACTION_NAT64;
7583 : 0 : break;
7584 : 0 : case RTE_FLOW_ACTION_TYPE_END:
7585 : : actions_end = true;
7586 : 0 : break;
7587 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7588 : 0 : ret = flow_hw_validate_action_default_miss(attr, action_flags, error);
7589 [ # # ]: 0 : if (ret < 0)
7590 : 0 : return ret;
7591 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7592 : 0 : break;
7593 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
7594 : 0 : ret = mlx5_flow_validate_action_jump_to_table_index(action, mask, error);
7595 [ # # ]: 0 : if (ret < 0)
7596 : 0 : return ret;
7597 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP_TO_TABLE_INDEX;
7598 : 0 : break;
7599 : 0 : default:
7600 : 0 : return rte_flow_error_set(error, ENOTSUP,
7601 : : RTE_FLOW_ERROR_TYPE_ACTION,
7602 : : action,
7603 : : "action not supported in template API");
7604 : : }
7605 : : }
7606 [ # # ]: 0 : if (act_flags != NULL)
7607 : 0 : *act_flags = action_flags;
7608 : : return 0;
7609 : : }
7610 : :
7611 : : static int
7612 : 0 : flow_hw_actions_validate(struct rte_eth_dev *dev,
7613 : : const struct rte_flow_actions_template_attr *attr,
7614 : : const struct rte_flow_action actions[],
7615 : : const struct rte_flow_action masks[],
7616 : : struct rte_flow_error *error)
7617 : : {
7618 : 0 : return mlx5_flow_hw_actions_validate(dev, attr, actions, masks, NULL, error);
7619 : : }
7620 : :
7621 : :
7622 : : static enum mlx5dr_action_type mlx5_hw_dr_action_types[] = {
7623 : : [RTE_FLOW_ACTION_TYPE_MARK] = MLX5DR_ACTION_TYP_TAG,
7624 : : [RTE_FLOW_ACTION_TYPE_FLAG] = MLX5DR_ACTION_TYP_TAG,
7625 : : [RTE_FLOW_ACTION_TYPE_DROP] = MLX5DR_ACTION_TYP_DROP,
7626 : : [RTE_FLOW_ACTION_TYPE_JUMP] = MLX5DR_ACTION_TYP_TBL,
7627 : : [RTE_FLOW_ACTION_TYPE_QUEUE] = MLX5DR_ACTION_TYP_TIR,
7628 : : [RTE_FLOW_ACTION_TYPE_RSS] = MLX5DR_ACTION_TYP_TIR,
7629 : : [RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP] = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2,
7630 : : [RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP] = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2,
7631 : : [RTE_FLOW_ACTION_TYPE_VXLAN_DECAP] = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2,
7632 : : [RTE_FLOW_ACTION_TYPE_NVGRE_DECAP] = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2,
7633 : : [RTE_FLOW_ACTION_TYPE_MODIFY_FIELD] = MLX5DR_ACTION_TYP_MODIFY_HDR,
7634 : : [RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT] = MLX5DR_ACTION_TYP_VPORT,
7635 : : [RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR] = MLX5DR_ACTION_TYP_MISS,
7636 : : [RTE_FLOW_ACTION_TYPE_CONNTRACK] = MLX5DR_ACTION_TYP_ASO_CT,
7637 : : [RTE_FLOW_ACTION_TYPE_OF_POP_VLAN] = MLX5DR_ACTION_TYP_POP_VLAN,
7638 : : [RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN] = MLX5DR_ACTION_TYP_PUSH_VLAN,
7639 : : [RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL] = MLX5DR_ACTION_TYP_DEST_ROOT,
7640 : : [RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH] = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
7641 : : [RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE] = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
7642 : : [RTE_FLOW_ACTION_TYPE_NAT64] = MLX5DR_ACTION_TYP_NAT64,
7643 : : [RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX] = MLX5DR_ACTION_TYP_JUMP_TO_MATCHER,
7644 : : };
7645 : :
7646 : : static inline void
7647 : : action_template_set_type(struct rte_flow_actions_template *at,
7648 : : enum mlx5dr_action_type *action_types,
7649 : : unsigned int action_src, uint16_t *curr_off,
7650 : : enum mlx5dr_action_type type)
7651 : : {
7652 : 0 : at->dr_off[action_src] = *curr_off;
7653 : 0 : action_types[*curr_off] = type;
7654 : 0 : *curr_off = *curr_off + 1;
7655 : 0 : }
7656 : :
7657 : : static int
7658 : 0 : flow_hw_dr_actions_template_handle_shared(int type, uint32_t action_src,
7659 : : enum mlx5dr_action_type *action_types,
7660 : : uint16_t *curr_off, uint16_t *cnt_off,
7661 : : struct rte_flow_actions_template *at)
7662 : : {
7663 [ # # # # : 0 : switch (type) {
# ]
7664 : : case RTE_FLOW_ACTION_TYPE_RSS:
7665 : : action_template_set_type(at, action_types, action_src, curr_off,
7666 : : MLX5DR_ACTION_TYP_TIR);
7667 : : break;
7668 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
7669 : : case RTE_FLOW_ACTION_TYPE_COUNT:
7670 : : /*
7671 : : * Both AGE and COUNT action need counter, the first one fills
7672 : : * the action_types array, and the second only saves the offset.
7673 : : */
7674 [ # # ]: 0 : if (*cnt_off == UINT16_MAX) {
7675 : 0 : *cnt_off = *curr_off;
7676 : : action_template_set_type(at, action_types,
7677 : : action_src, curr_off,
7678 : : MLX5DR_ACTION_TYP_CTR);
7679 : : }
7680 : 0 : at->dr_off[action_src] = *cnt_off;
7681 : 0 : break;
7682 : : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7683 : : action_template_set_type(at, action_types, action_src, curr_off,
7684 : : MLX5DR_ACTION_TYP_ASO_CT);
7685 : : break;
7686 : : case RTE_FLOW_ACTION_TYPE_QUOTA:
7687 : : case RTE_FLOW_ACTION_TYPE_METER_MARK:
7688 : : action_template_set_type(at, action_types, action_src, curr_off,
7689 : : MLX5DR_ACTION_TYP_ASO_METER);
7690 : : break;
7691 : 0 : default:
7692 : 0 : DRV_LOG(WARNING, "Unsupported shared action type: %d", type);
7693 : 0 : return -EINVAL;
7694 : : }
7695 : : return 0;
7696 : : }
7697 : :
7698 : :
7699 : : static int
7700 : 0 : flow_hw_template_actions_list(struct rte_flow_actions_template *at,
7701 : : unsigned int action_src,
7702 : : enum mlx5dr_action_type *action_types,
7703 : : uint16_t *curr_off, uint16_t *cnt_off)
7704 : : {
7705 : : int ret;
7706 : 0 : const struct rte_flow_action_indirect_list *indlst_conf = at->actions[action_src].conf;
7707 [ # # # # ]: 0 : enum mlx5_indirect_list_type list_type = mlx5_get_indirect_list_type(indlst_conf->handle);
7708 : : const union {
7709 : : struct mlx5_indlst_legacy *legacy;
7710 : : struct rte_flow_action_list_handle *handle;
7711 : : } indlst_obj = { .handle = indlst_conf->handle };
7712 : : enum mlx5dr_action_type type;
7713 : :
7714 [ # # # # ]: 0 : switch (list_type) {
7715 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
7716 : 0 : ret = flow_hw_dr_actions_template_handle_shared
7717 : 0 : (indlst_obj.legacy->legacy_type, action_src,
7718 : : action_types, curr_off, cnt_off, at);
7719 [ # # ]: 0 : if (ret)
7720 : 0 : return ret;
7721 : : break;
7722 : : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
7723 : : action_template_set_type(at, action_types, action_src, curr_off,
7724 : : MLX5DR_ACTION_TYP_DEST_ARRAY);
7725 : : break;
7726 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
7727 : 0 : type = ((struct mlx5_hw_encap_decap_action *)
7728 : : (indlst_conf->handle))->action_type;
7729 : : action_template_set_type(at, action_types, action_src, curr_off, type);
7730 : : break;
7731 : 0 : default:
7732 : 0 : DRV_LOG(ERR, "Unsupported indirect list type");
7733 : 0 : return -EINVAL;
7734 : : }
7735 : : return 0;
7736 : : }
7737 : :
7738 : : /**
7739 : : * Create DR action template based on a provided sequence of flow actions.
7740 : : *
7741 : : * @param[in] dev
7742 : : * Pointer to the rte_eth_dev structure.
7743 : : * @param[in] at
7744 : : * Pointer to flow actions template to be updated.
7745 : : * @param[out] action_types
7746 : : * Action types array to be filled.
7747 : : * @param[out] tmpl_flags
7748 : : * Template DR flags to be filled.
7749 : : *
7750 : : * @return
7751 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7752 : : */
7753 : : static int
7754 : 0 : flow_hw_parse_flow_actions_to_dr_actions(struct rte_eth_dev *dev,
7755 : : struct rte_flow_actions_template *at,
7756 : : enum mlx5dr_action_type action_types[MLX5_HW_MAX_ACTS],
7757 : : uint32_t *tmpl_flags __rte_unused)
7758 : : {
7759 : : unsigned int i;
7760 : : uint16_t curr_off;
7761 : : enum mlx5dr_action_type reformat_act_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
7762 : : uint16_t reformat_off = UINT16_MAX;
7763 : : uint16_t mhdr_off = UINT16_MAX;
7764 : : uint16_t recom_off = UINT16_MAX;
7765 : 0 : uint16_t cnt_off = UINT16_MAX;
7766 : : enum mlx5dr_action_type recom_type = MLX5DR_ACTION_TYP_LAST;
7767 : : int ret;
7768 : :
7769 [ # # ]: 0 : for (i = 0, curr_off = 0; at->actions[i].type != RTE_FLOW_ACTION_TYPE_END; ++i) {
7770 : : const struct rte_flow_action_raw_encap *raw_encap_data;
7771 : : size_t data_size;
7772 : : enum mlx5dr_action_type type;
7773 : :
7774 [ # # ]: 0 : if (curr_off >= MLX5_HW_MAX_ACTS)
7775 : 0 : goto err_actions_num;
7776 [ # # # # : 0 : switch ((int)at->actions[i].type) {
# # # # #
# # # # #
# # # ]
7777 : : case RTE_FLOW_ACTION_TYPE_VOID:
7778 : : break;
7779 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
7780 : 0 : ret = flow_hw_template_actions_list(at, i, action_types,
7781 : : &curr_off, &cnt_off);
7782 [ # # ]: 0 : if (ret)
7783 : 0 : return ret;
7784 : : break;
7785 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
7786 : 0 : ret = flow_hw_dr_actions_template_handle_shared
7787 : 0 : (at->masks[i].type, i, action_types,
7788 : : &curr_off, &cnt_off, at);
7789 [ # # ]: 0 : if (ret)
7790 : 0 : return ret;
7791 : : break;
7792 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7793 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7794 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7795 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7796 : : MLX5_ASSERT(reformat_off == UINT16_MAX);
7797 : 0 : reformat_off = curr_off++;
7798 : 0 : reformat_act_type = mlx5_hw_dr_action_types[at->actions[i].type];
7799 : 0 : break;
7800 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
7801 : : MLX5_ASSERT(recom_off == UINT16_MAX);
7802 : : recom_type = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT;
7803 : 0 : recom_off = curr_off++;
7804 : 0 : break;
7805 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE:
7806 : : MLX5_ASSERT(recom_off == UINT16_MAX);
7807 : : recom_type = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT;
7808 : 0 : recom_off = curr_off++;
7809 : 0 : break;
7810 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7811 : 0 : raw_encap_data = at->actions[i].conf;
7812 : 0 : data_size = raw_encap_data->size;
7813 [ # # ]: 0 : if (reformat_off != UINT16_MAX) {
7814 : : reformat_act_type = data_size < MLX5_ENCAPSULATION_DECISION_SIZE ?
7815 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2 :
7816 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
7817 : : } else {
7818 : 0 : reformat_off = curr_off++;
7819 : : reformat_act_type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
7820 : : }
7821 : : break;
7822 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7823 : 0 : reformat_off = curr_off++;
7824 : : reformat_act_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
7825 : 0 : break;
7826 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7827 [ # # ]: 0 : if (mhdr_off == UINT16_MAX) {
7828 : 0 : mhdr_off = curr_off++;
7829 : 0 : type = mlx5_hw_dr_action_types[at->actions[i].type];
7830 : 0 : action_types[mhdr_off] = type;
7831 : : }
7832 : : break;
7833 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7834 : 0 : type = mlx5_hw_dr_action_types[at->actions[i].type];
7835 : 0 : at->dr_off[i] = curr_off;
7836 : 0 : action_types[curr_off++] = type;
7837 : 0 : i += is_of_vlan_pcp_present(at->actions + i) ?
7838 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
7839 : : MLX5_HW_VLAN_PUSH_VID_IDX;
7840 : 0 : break;
7841 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
7842 : 0 : at->dr_off[i] = curr_off;
7843 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_ASO_METER;
7844 [ # # ]: 0 : if (curr_off >= MLX5_HW_MAX_ACTS)
7845 : 0 : goto err_actions_num;
7846 : : break;
7847 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
7848 : : case RTE_FLOW_ACTION_TYPE_COUNT:
7849 : : /*
7850 : : * Both AGE and COUNT action need counter, the first
7851 : : * one fills the action_types array, and the second only
7852 : : * saves the offset.
7853 : : */
7854 [ # # ]: 0 : if (cnt_off == UINT16_MAX) {
7855 : 0 : cnt_off = curr_off++;
7856 : 0 : action_types[cnt_off] = MLX5DR_ACTION_TYP_CTR;
7857 : : }
7858 : 0 : at->dr_off[i] = cnt_off;
7859 : 0 : break;
7860 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7861 : 0 : at->dr_off[i] = curr_off;
7862 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_MISS;
7863 : 0 : break;
7864 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
7865 : 0 : *tmpl_flags |= MLX5DR_ACTION_TEMPLATE_FLAG_RELAXED_ORDER;
7866 : 0 : at->dr_off[i] = curr_off;
7867 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_JUMP_TO_MATCHER;
7868 : 0 : break;
7869 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_MIRROR:
7870 : 0 : at->dr_off[i] = curr_off;
7871 : 0 : action_types[curr_off++] = MLX5DR_ACTION_TYP_DEST_ARRAY;
7872 : 0 : break;
7873 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
7874 : 0 : DRV_LOG(ERR, "RTE_FLOW_ACTION_TYPE_PORT_ID action is not supported. "
7875 : : "Use RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT instead.");
7876 : 0 : return -EINVAL;
7877 : 0 : default:
7878 : 0 : type = mlx5_hw_dr_action_types[at->actions[i].type];
7879 : 0 : at->dr_off[i] = curr_off;
7880 : 0 : action_types[curr_off++] = type;
7881 : 0 : break;
7882 : : }
7883 : : }
7884 [ # # ]: 0 : if (curr_off >= MLX5_HW_MAX_ACTS)
7885 : 0 : goto err_actions_num;
7886 [ # # ]: 0 : if (mhdr_off != UINT16_MAX)
7887 : 0 : at->mhdr_off = mhdr_off;
7888 [ # # ]: 0 : if (reformat_off != UINT16_MAX) {
7889 : 0 : at->reformat_off = reformat_off;
7890 : 0 : action_types[reformat_off] = reformat_act_type;
7891 : : }
7892 [ # # ]: 0 : if (recom_off != UINT16_MAX) {
7893 : 0 : at->recom_off = recom_off;
7894 : 0 : action_types[recom_off] = recom_type;
7895 : : }
7896 : 0 : at->dr_actions_num = curr_off;
7897 : :
7898 : : /* Create srh flex parser for remove anchor. */
7899 [ # # ]: 0 : if ((recom_type == MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT ||
7900 [ # # ]: 0 : recom_type == MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) &&
7901 : 0 : (ret = mlx5_alloc_srh_flex_parser(dev))) {
7902 : 0 : DRV_LOG(ERR, "Failed to create srv6 flex parser");
7903 : 0 : return ret;
7904 : : }
7905 : : return 0;
7906 : 0 : err_actions_num:
7907 : 0 : DRV_LOG(ERR, "Number of HW actions (%u) exceeded maximum (%u) allowed in template",
7908 : : curr_off, MLX5_HW_MAX_ACTS);
7909 : 0 : return -EINVAL;
7910 : : }
7911 : :
7912 : : static int
7913 : 0 : flow_hw_set_vlan_vid(struct rte_eth_dev *dev,
7914 : : struct rte_flow_action *ra,
7915 : : struct rte_flow_action *rm,
7916 : : struct rte_flow_action_modify_field *spec,
7917 : : struct rte_flow_action_modify_field *mask,
7918 : : int set_vlan_vid_ix,
7919 : : struct rte_flow_error *error)
7920 : : {
7921 [ # # ]: 0 : const bool masked = rm[set_vlan_vid_ix].conf &&
7922 : : (((const struct rte_flow_action_of_set_vlan_vid *)
7923 [ # # ]: 0 : rm[set_vlan_vid_ix].conf)->vlan_vid != 0);
7924 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
7925 : 0 : ra[set_vlan_vid_ix].conf;
7926 : 0 : int width = mlx5_flow_item_field_width(dev, RTE_FLOW_FIELD_VLAN_ID, 0,
7927 : : NULL, error);
7928 : : MLX5_ASSERT(width);
7929 : 0 : *spec = (typeof(*spec)) {
7930 : : .operation = RTE_FLOW_MODIFY_SET,
7931 : : .dst = {
7932 : : .field = RTE_FLOW_FIELD_VLAN_ID,
7933 : : .level = 0, .offset = 0,
7934 : : },
7935 : : .src = {
7936 : : .field = RTE_FLOW_FIELD_VALUE,
7937 : : },
7938 : : .width = width,
7939 : : };
7940 : 0 : *mask = (typeof(*mask)) {
7941 : : .operation = RTE_FLOW_MODIFY_SET,
7942 : : .dst = {
7943 : : .field = RTE_FLOW_FIELD_VLAN_ID,
7944 : : .level = 0xff, .offset = 0xffffffff,
7945 : : },
7946 : : .src = {
7947 : : .field = RTE_FLOW_FIELD_VALUE,
7948 : : },
7949 : : .width = 0xffffffff,
7950 : : };
7951 [ # # ]: 0 : if (masked) {
7952 : : uint32_t mask_val = 0xffffffff;
7953 : :
7954 : : rte_memcpy(spec->src.value, &conf->vlan_vid, sizeof(conf->vlan_vid));
7955 : : rte_memcpy(mask->src.value, &mask_val, sizeof(mask_val));
7956 : : }
7957 : 0 : ra[set_vlan_vid_ix].type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD;
7958 : 0 : ra[set_vlan_vid_ix].conf = spec;
7959 : 0 : rm[set_vlan_vid_ix].type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD;
7960 : 0 : rm[set_vlan_vid_ix].conf = mask;
7961 : 0 : return 0;
7962 : : }
7963 : :
7964 : : static __rte_always_inline int
7965 : : flow_hw_set_vlan_vid_construct(struct rte_eth_dev *dev,
7966 : : struct mlx5_modification_cmd *mhdr_cmd,
7967 : : struct mlx5_action_construct_data *act_data,
7968 : : const struct mlx5_hw_actions *hw_acts,
7969 : : const struct rte_flow_action *action)
7970 : : {
7971 : : struct rte_flow_error error;
7972 : : rte_be16_t vid = ((const struct rte_flow_action_of_set_vlan_vid *)
7973 : 0 : action->conf)->vlan_vid;
7974 : 0 : int width = mlx5_flow_item_field_width(dev, RTE_FLOW_FIELD_VLAN_ID, 0,
7975 : : NULL, &error);
7976 [ # # # # : 0 : struct rte_flow_action_modify_field conf = {
# # # # #
# ]
7977 : : .operation = RTE_FLOW_MODIFY_SET,
7978 : : .dst = {
7979 : : .field = RTE_FLOW_FIELD_VLAN_ID,
7980 : : .level = 0, .offset = 0,
7981 : : },
7982 : : .src = {
7983 : : .field = RTE_FLOW_FIELD_VALUE,
7984 : : },
7985 : : .width = width,
7986 : : };
7987 : : struct rte_flow_action modify_action = {
7988 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
7989 : : .conf = &conf
7990 : : };
7991 : :
7992 : : rte_memcpy(conf.src.value, &vid, sizeof(vid));
7993 : : return flow_hw_modify_field_construct(mhdr_cmd, act_data, hw_acts, &modify_action);
7994 : : }
7995 : :
7996 : : static int
7997 : 0 : flow_hw_flex_item_acquire(struct rte_eth_dev *dev,
7998 : : struct rte_flow_item_flex_handle *handle,
7999 : : uint8_t *flex_item)
8000 : : {
8001 : 0 : int index = mlx5_flex_acquire_index(dev, handle, false);
8002 : :
8003 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
8004 [ # # ]: 0 : if (index < 0)
8005 : : return -1;
8006 [ # # ]: 0 : if (!(*flex_item & RTE_BIT32(index))) {
8007 : : /* Don't count same flex item again. */
8008 : 0 : if (mlx5_flex_acquire_index(dev, handle, true) != index)
8009 : : MLX5_ASSERT(false);
8010 : 0 : *flex_item |= (uint8_t)RTE_BIT32(index);
8011 : : }
8012 : : return 0;
8013 : : }
8014 : :
8015 : : static void
8016 : 0 : flow_hw_flex_item_release(struct rte_eth_dev *dev, uint8_t *flex_item)
8017 : : {
8018 [ # # ]: 0 : while (*flex_item) {
8019 : 0 : int index = rte_bsf32(*flex_item);
8020 : :
8021 : 0 : mlx5_flex_release_index(dev, index);
8022 : 0 : *flex_item &= ~(uint8_t)RTE_BIT32(index);
8023 : : }
8024 : 0 : }
8025 : : static __rte_always_inline void
8026 : : flow_hw_actions_template_replace_container(const
8027 : : struct rte_flow_action *actions,
8028 : : const
8029 : : struct rte_flow_action *masks,
8030 : : struct rte_flow_action *new_actions,
8031 : : struct rte_flow_action *new_masks,
8032 : : struct rte_flow_action **ra,
8033 : : struct rte_flow_action **rm,
8034 : : uint32_t act_num)
8035 : : {
8036 : 0 : memcpy(new_actions, actions, sizeof(actions[0]) * act_num);
8037 : : memcpy(new_masks, masks, sizeof(masks[0]) * act_num);
8038 : : *ra = (void *)(uintptr_t)new_actions;
8039 : : *rm = (void *)(uintptr_t)new_masks;
8040 : 0 : }
8041 : :
8042 : : /* Action template copies these actions in rte_flow_conv() */
8043 : :
8044 : : static const struct rte_flow_action rx_meta_copy_action = {
8045 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8046 : : .conf = &(struct rte_flow_action_modify_field){
8047 : : .operation = RTE_FLOW_MODIFY_SET,
8048 : : .dst = {
8049 : : .field = (enum rte_flow_field_id)
8050 : : MLX5_RTE_FLOW_FIELD_META_REG,
8051 : : .tag_index = REG_B,
8052 : : },
8053 : : .src = {
8054 : : .field = (enum rte_flow_field_id)
8055 : : MLX5_RTE_FLOW_FIELD_META_REG,
8056 : : .tag_index = REG_C_1,
8057 : : },
8058 : : .width = 32,
8059 : : }
8060 : : };
8061 : :
8062 : : static const struct rte_flow_action rx_meta_copy_mask = {
8063 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8064 : : .conf = &(struct rte_flow_action_modify_field){
8065 : : .operation = RTE_FLOW_MODIFY_SET,
8066 : : .dst = {
8067 : : .field = (enum rte_flow_field_id)
8068 : : MLX5_RTE_FLOW_FIELD_META_REG,
8069 : : .level = UINT8_MAX,
8070 : : .tag_index = UINT8_MAX,
8071 : : .offset = UINT32_MAX,
8072 : : },
8073 : : .src = {
8074 : : .field = (enum rte_flow_field_id)
8075 : : MLX5_RTE_FLOW_FIELD_META_REG,
8076 : : .level = UINT8_MAX,
8077 : : .tag_index = UINT8_MAX,
8078 : : .offset = UINT32_MAX,
8079 : : },
8080 : : .width = UINT32_MAX,
8081 : : }
8082 : : };
8083 : :
8084 : : static const struct rte_flow_action quota_color_inc_action = {
8085 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8086 : : .conf = &(struct rte_flow_action_modify_field) {
8087 : : .operation = RTE_FLOW_MODIFY_ADD,
8088 : : .dst = {
8089 : : .field = RTE_FLOW_FIELD_METER_COLOR,
8090 : : .level = 0, .offset = 0
8091 : : },
8092 : : .src = {
8093 : : .field = RTE_FLOW_FIELD_VALUE,
8094 : : .level = 1,
8095 : : .offset = 0,
8096 : : },
8097 : : .width = 2
8098 : : }
8099 : : };
8100 : :
8101 : : static const struct rte_flow_action quota_color_inc_mask = {
8102 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
8103 : : .conf = &(struct rte_flow_action_modify_field) {
8104 : : .operation = RTE_FLOW_MODIFY_ADD,
8105 : : .dst = {
8106 : : .field = RTE_FLOW_FIELD_METER_COLOR,
8107 : : .level = UINT8_MAX,
8108 : : .tag_index = UINT8_MAX,
8109 : : .offset = UINT32_MAX,
8110 : : },
8111 : : .src = {
8112 : : .field = RTE_FLOW_FIELD_VALUE,
8113 : : .level = 3,
8114 : : .offset = 0
8115 : : },
8116 : : .width = UINT32_MAX
8117 : : }
8118 : : };
8119 : :
8120 : : /**
8121 : : * Create flow action template.
8122 : : *
8123 : : * @param[in] dev
8124 : : * Pointer to the rte_eth_dev structure.
8125 : : * @param[in] attr
8126 : : * Pointer to the action template attributes.
8127 : : * @param[in] actions
8128 : : * Associated actions (list terminated by the END action).
8129 : : * @param[in] masks
8130 : : * List of actions that marks which of the action's member is constant.
8131 : : * @param[in] nt_mode
8132 : : * Non template mode.
8133 : : * @param[out] error
8134 : : * Pointer to error structure.
8135 : : *
8136 : : * @return
8137 : : * Action template pointer on success, NULL otherwise and rte_errno is set.
8138 : : */
8139 : : static struct rte_flow_actions_template *
8140 : 0 : __flow_hw_actions_template_create(struct rte_eth_dev *dev,
8141 : : const struct rte_flow_actions_template_attr *attr,
8142 : : const struct rte_flow_action actions[],
8143 : : const struct rte_flow_action masks[],
8144 : : bool nt_mode,
8145 : : struct rte_flow_error *error)
8146 : : {
8147 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8148 : : int len, act_len, mask_len;
8149 : : int orig_act_len;
8150 : : unsigned int act_num;
8151 : : unsigned int i;
8152 : : struct rte_flow_actions_template *at = NULL;
8153 : : uint16_t pos;
8154 : 0 : uint64_t action_flags = 0;
8155 : : struct rte_flow_action tmp_action[MLX5_HW_MAX_ACTS];
8156 : : struct rte_flow_action tmp_mask[MLX5_HW_MAX_ACTS];
8157 : : struct rte_flow_action *ra = (void *)(uintptr_t)actions;
8158 : : struct rte_flow_action *rm = (void *)(uintptr_t)masks;
8159 : : int set_vlan_vid_ix = -1;
8160 : 0 : struct rte_flow_action_modify_field set_vlan_vid_spec = {0, };
8161 : 0 : struct rte_flow_action_modify_field set_vlan_vid_mask = {0, };
8162 : : struct rte_flow_action mf_actions[MLX5_HW_MAX_ACTS];
8163 : : struct rte_flow_action mf_masks[MLX5_HW_MAX_ACTS];
8164 : : uint32_t expand_mf_num = 0;
8165 : 0 : uint16_t src_off[MLX5_HW_MAX_ACTS] = {0, };
8166 : 0 : enum mlx5dr_action_type action_types[MLX5_HW_MAX_ACTS] = { MLX5DR_ACTION_TYP_LAST };
8167 : 0 : uint32_t tmpl_flags = 0;
8168 : : int ret;
8169 : :
8170 [ # # # # ]: 0 : if (!nt_mode && mlx5_flow_hw_actions_validate(dev, attr, actions, masks,
8171 : : &action_flags, error))
8172 : : return NULL;
8173 [ # # ]: 0 : for (i = 0; ra[i].type != RTE_FLOW_ACTION_TYPE_END; ++i) {
8174 [ # # # ]: 0 : switch (ra[i].type) {
8175 : : /* OF_PUSH_VLAN *MUST* come before OF_SET_VLAN_VID */
8176 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8177 : 0 : i += is_of_vlan_pcp_present(ra + i) ?
8178 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
8179 : : MLX5_HW_VLAN_PUSH_VID_IDX;
8180 : 0 : break;
8181 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8182 : 0 : set_vlan_vid_ix = i;
8183 : 0 : break;
8184 : : default:
8185 : : break;
8186 : : }
8187 : : }
8188 : : /*
8189 : : * Count flow actions to allocate required space for storing DR offsets and to check
8190 : : * if temporary buffer would not be overrun.
8191 : : */
8192 : 0 : act_num = i + 1;
8193 [ # # ]: 0 : if (act_num >= MLX5_HW_MAX_ACTS) {
8194 : 0 : rte_flow_error_set(error, EINVAL,
8195 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "Too many actions");
8196 : 0 : return NULL;
8197 : : }
8198 [ # # ]: 0 : if (set_vlan_vid_ix != -1) {
8199 : : /* If temporary action buffer was not used, copy template actions to it */
8200 : : if (ra == actions)
8201 : : flow_hw_actions_template_replace_container(actions,
8202 : : masks,
8203 : : tmp_action,
8204 : : tmp_mask,
8205 : : &ra, &rm,
8206 : : act_num);
8207 : 0 : ret = flow_hw_set_vlan_vid(dev, ra, rm,
8208 : : &set_vlan_vid_spec, &set_vlan_vid_mask,
8209 : : set_vlan_vid_ix, error);
8210 [ # # ]: 0 : if (ret)
8211 : 0 : goto error;
8212 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8213 : : }
8214 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUOTA) {
8215 : 0 : mf_actions[expand_mf_num] = quota_color_inc_action;
8216 : 0 : mf_masks[expand_mf_num] = quota_color_inc_mask;
8217 : : expand_mf_num++;
8218 : : }
8219 [ # # ]: 0 : if (attr->ingress &&
8220 [ # # ]: 0 : (action_flags & (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS))) {
8221 [ # # ]: 0 : if ((priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS &&
8222 [ # # ]: 0 : priv->sh->config.dv_esw_en) ||
8223 : 0 : mlx5_vport_rx_metadata_passing_enabled(priv->sh)) {
8224 : : /* Insert META copy */
8225 : 0 : mf_actions[expand_mf_num] = rx_meta_copy_action;
8226 : 0 : mf_masks[expand_mf_num] = rx_meta_copy_mask;
8227 : 0 : expand_mf_num++;
8228 : : MLX5_ASSERT(expand_mf_num <= MLX5_HW_MAX_ACTS);
8229 : : }
8230 : : }
8231 [ # # ]: 0 : if (expand_mf_num) {
8232 [ # # ]: 0 : if (act_num + expand_mf_num > MLX5_HW_MAX_ACTS) {
8233 : 0 : rte_flow_error_set(error, E2BIG,
8234 : : RTE_FLOW_ERROR_TYPE_ACTION,
8235 : : NULL, "cannot expand: too many actions");
8236 : 0 : return NULL;
8237 : : }
8238 [ # # ]: 0 : if (ra == actions)
8239 : : flow_hw_actions_template_replace_container(actions,
8240 : : masks,
8241 : : tmp_action,
8242 : : tmp_mask,
8243 : : &ra, &rm,
8244 : : act_num);
8245 : : /* Application should make sure only one Q/RSS exist in one rule. */
8246 : 0 : pos = flow_hw_template_expand_modify_field(ra, rm,
8247 : : mf_actions,
8248 : : mf_masks,
8249 : : action_flags,
8250 : : act_num,
8251 : : expand_mf_num);
8252 [ # # ]: 0 : if (pos == MLX5_HW_EXPAND_MH_FAILED) {
8253 : 0 : rte_flow_error_set(error, ENOMEM,
8254 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8255 : : NULL, "modify header expansion failed");
8256 : 0 : return NULL;
8257 : : }
8258 : : act_num += expand_mf_num;
8259 [ # # ]: 0 : for (i = pos + expand_mf_num; i < act_num; i++)
8260 : 0 : src_off[i] += expand_mf_num;
8261 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8262 : : }
8263 : 0 : act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, ra, error);
8264 [ # # ]: 0 : if (act_len <= 0)
8265 : : return NULL;
8266 : 0 : len = RTE_ALIGN(act_len, 16);
8267 : 0 : mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, rm, error);
8268 [ # # ]: 0 : if (mask_len <= 0)
8269 : : return NULL;
8270 : 0 : len += RTE_ALIGN(mask_len, 16);
8271 : 0 : len += RTE_ALIGN(act_num * sizeof(*at->dr_off), 16);
8272 : 0 : len += RTE_ALIGN(act_num * sizeof(*at->src_off), 16);
8273 : 0 : orig_act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, actions, error);
8274 [ # # ]: 0 : if (orig_act_len <= 0)
8275 : : return NULL;
8276 : 0 : len += RTE_ALIGN(orig_act_len, 16);
8277 : 0 : at = mlx5_malloc(MLX5_MEM_ZERO, len + sizeof(*at),
8278 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
8279 [ # # ]: 0 : if (!at) {
8280 : 0 : rte_flow_error_set(error, ENOMEM,
8281 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8282 : : NULL,
8283 : : "cannot allocate action template");
8284 : 0 : return NULL;
8285 : : }
8286 : : /* Actions part is in the first part. */
8287 : 0 : at->attr = *attr;
8288 : 0 : at->actions = (struct rte_flow_action *)(at + 1);
8289 : 0 : act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->actions,
8290 : : len, ra, error);
8291 [ # # ]: 0 : if (act_len <= 0)
8292 : 0 : goto error;
8293 : : /* Masks part is in the second part. */
8294 : 0 : at->masks = (struct rte_flow_action *)(((uint8_t *)at->actions) + act_len);
8295 : 0 : mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->masks,
8296 : 0 : len - act_len, rm, error);
8297 [ # # ]: 0 : if (mask_len <= 0)
8298 : 0 : goto error;
8299 : : /* DR actions offsets in the third part. */
8300 : 0 : at->dr_off = (uint16_t *)((uint8_t *)at->masks + mask_len);
8301 : 0 : at->src_off = RTE_PTR_ADD(at->dr_off,
8302 : : RTE_ALIGN(act_num * sizeof(*at->dr_off), 16));
8303 : : memcpy(at->src_off, src_off, act_num * sizeof(at->src_off[0]));
8304 : 0 : at->orig_actions = RTE_PTR_ADD(at->src_off,
8305 : : RTE_ALIGN(act_num * sizeof(*at->src_off), 16));
8306 : 0 : orig_act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->orig_actions, orig_act_len,
8307 : : actions, error);
8308 [ # # ]: 0 : if (orig_act_len <= 0)
8309 : 0 : goto error;
8310 : 0 : at->actions_num = act_num;
8311 [ # # ]: 0 : for (i = 0; i < at->actions_num; ++i)
8312 : 0 : at->dr_off[i] = UINT16_MAX;
8313 : 0 : at->reformat_off = UINT16_MAX;
8314 : 0 : at->mhdr_off = UINT16_MAX;
8315 : 0 : at->recom_off = UINT16_MAX;
8316 [ # # ]: 0 : for (i = 0; actions->type != RTE_FLOW_ACTION_TYPE_END;
8317 : 0 : actions++, masks++, i++) {
8318 : : const struct rte_flow_action_modify_field *info;
8319 : :
8320 [ # # # ]: 0 : switch (actions->type) {
8321 : : /*
8322 : : * mlx5 PMD hacks indirect action index directly to the action conf.
8323 : : * The rte_flow_conv() function copies the content from conf pointer.
8324 : : * Need to restore the indirect action index from action conf here.
8325 : : */
8326 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
8327 : 0 : at->actions[i].conf = ra[i].conf;
8328 : 0 : at->masks[i].conf = rm[i].conf;
8329 : 0 : break;
8330 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8331 : 0 : info = actions->conf;
8332 [ # # # # ]: 0 : if ((info->dst.field == RTE_FLOW_FIELD_FLEX_ITEM &&
8333 : 0 : flow_hw_flex_item_acquire(dev, info->dst.flex_handle,
8334 : 0 : &at->flex_item)) ||
8335 [ # # # # ]: 0 : (info->src.field == RTE_FLOW_FIELD_FLEX_ITEM &&
8336 : 0 : flow_hw_flex_item_acquire(dev, info->src.flex_handle,
8337 : : &at->flex_item)))
8338 : 0 : goto error;
8339 : : break;
8340 : : default:
8341 : : break;
8342 : : }
8343 : : }
8344 : 0 : ret = flow_hw_parse_flow_actions_to_dr_actions(dev, at, action_types, &tmpl_flags);
8345 [ # # ]: 0 : if (ret)
8346 : 0 : goto error;
8347 : 0 : at->action_flags = action_flags;
8348 : : /* In non template mode there is no need to create the dr template. */
8349 [ # # ]: 0 : if (nt_mode)
8350 : : return at;
8351 : 0 : at->tmpl = mlx5dr_action_template_create(action_types, tmpl_flags);
8352 [ # # ]: 0 : if (!at->tmpl) {
8353 : 0 : DRV_LOG(ERR, "Failed to create DR action template: %d", rte_errno);
8354 : 0 : goto error;
8355 : : }
8356 : 0 : rte_atomic_fetch_add_explicit(&at->refcnt, 1, rte_memory_order_relaxed);
8357 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_at, at, next);
8358 : 0 : return at;
8359 : 0 : error:
8360 : : if (at) {
8361 : 0 : mlx5_free(at);
8362 : : }
8363 : 0 : rte_flow_error_set(error, rte_errno,
8364 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8365 : : "Failed to create action template");
8366 : 0 : return NULL;
8367 : : }
8368 : :
8369 : : /**
8370 : : * Create flow action template.
8371 : : *
8372 : : * @param[in] dev
8373 : : * Pointer to the rte_eth_dev structure.
8374 : : * @param[in] attr
8375 : : * Pointer to the action template attributes.
8376 : : * @param[in] actions
8377 : : * Associated actions (list terminated by the END action).
8378 : : * @param[in] masks
8379 : : * List of actions that marks which of the action's member is constant.
8380 : : * @param[out] error
8381 : : * Pointer to error structure.
8382 : : *
8383 : : * @return
8384 : : * Action template pointer on success, NULL otherwise and rte_errno is set.
8385 : : */
8386 : : static struct rte_flow_actions_template *
8387 : 0 : flow_hw_actions_template_create(struct rte_eth_dev *dev,
8388 : : const struct rte_flow_actions_template_attr *attr,
8389 : : const struct rte_flow_action actions[],
8390 : : const struct rte_flow_action masks[],
8391 : : struct rte_flow_error *error)
8392 : : {
8393 : 0 : return __flow_hw_actions_template_create(dev, attr, actions, masks, false, error);
8394 : : }
8395 : :
8396 : : /**
8397 : : * Destroy flow action template.
8398 : : *
8399 : : * @param[in] dev
8400 : : * Pointer to the rte_eth_dev structure.
8401 : : * @param[in] template
8402 : : * Pointer to the action template to be destroyed.
8403 : : * @param[out] error
8404 : : * Pointer to error structure.
8405 : : *
8406 : : * @return
8407 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8408 : : */
8409 : : static int
8410 : 0 : flow_hw_actions_template_destroy(struct rte_eth_dev *dev,
8411 : : struct rte_flow_actions_template *template,
8412 : : struct rte_flow_error *error __rte_unused)
8413 : : {
8414 : : uint64_t flag = MLX5_FLOW_ACTION_IPV6_ROUTING_REMOVE |
8415 : : MLX5_FLOW_ACTION_IPV6_ROUTING_PUSH;
8416 : :
8417 [ # # ]: 0 : if (rte_atomic_load_explicit(&template->refcnt, rte_memory_order_relaxed) > 1) {
8418 : 0 : DRV_LOG(WARNING, "Action template %p is still in use.",
8419 : : (void *)template);
8420 : 0 : return rte_flow_error_set(error, EBUSY,
8421 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8422 : : NULL,
8423 : : "action template is in use");
8424 : : }
8425 [ # # ]: 0 : if (template->action_flags & flag)
8426 : 0 : mlx5_free_srh_flex_parser(dev);
8427 [ # # ]: 0 : LIST_REMOVE(template, next);
8428 : 0 : flow_hw_flex_item_release(dev, &template->flex_item);
8429 [ # # ]: 0 : if (template->tmpl)
8430 : 0 : mlx5dr_action_template_destroy(template->tmpl);
8431 : 0 : mlx5_free(template);
8432 : 0 : return 0;
8433 : : }
8434 : :
8435 : : /*
8436 : : * Build a new item array prefixed with @p new_item.
8437 : : *
8438 : : * Callers typically build @p new_item on their stack with .spec / .mask
8439 : : * pointing at other stack locals, so a shallow copy of @p new_item would
8440 : : * leave dangling pointers as soon as the caller's frame goes away.
8441 : : *
8442 : : * To make the returned array self-contained, deep-copy @p new_item (item
8443 : : * header + spec/mask/last payloads) into the tail of the same allocation
8444 : : * via rte_flow_conv(RTE_FLOW_CONV_OP_ITEM, ...). The remaining items[]
8445 : : * are still shallow-copied: they reference the application-owned spec/
8446 : : * mask blobs handed to rte_flow_create() / rte_flow_pattern_template_
8447 : : * create(), whose lifetime already covers the returned array's use.
8448 : : *
8449 : : * Layout of the single mlx5_malloc() block:
8450 : : *
8451 : : * +--------------------------------------+ <- returned pointer
8452 : : * | rte_flow_item[nb_items + 1] | slot 0: copy of the deep-
8453 : : * | | copied header below
8454 : : * | | slots 1..nb_items: shallow
8455 : : * | | copies of items[]
8456 : : * +--------------------------------------+ <- new_item_buf
8457 : : * | rte_flow_item header (deep copy) | written by rte_flow_conv;
8458 : : * | + spec / mask / last payloads, | header.spec/.mask/.last point
8459 : : * | contiguous, self-referential | into the payloads right below
8460 : : * +--------------------------------------+
8461 : : *
8462 : : */
8463 : : static struct rte_flow_item *
8464 : 0 : flow_hw_prepend_item(const struct rte_flow_item *items,
8465 : : const uint32_t nb_items,
8466 : : const struct rte_flow_item *new_item,
8467 : : struct rte_flow_error *error)
8468 : : {
8469 : : struct rte_flow_item *copied_items;
8470 : : size_t header_size;
8471 : : size_t total_size;
8472 : : void *new_item_buf;
8473 : : int new_item_size;
8474 : : int rc;
8475 : :
8476 : : /*
8477 : : * Size the deep copy of the prepended item (header + payloads).
8478 : : * On error, rte_flow_conv() already populates @p error.
8479 : : */
8480 : 0 : new_item_size = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM, NULL, 0, new_item, error);
8481 [ # # ]: 0 : if (new_item_size < 0)
8482 : : return NULL;
8483 : :
8484 : 0 : header_size = sizeof(*copied_items) * (nb_items + 1);
8485 : 0 : total_size = header_size + (size_t)new_item_size;
8486 : :
8487 : 0 : copied_items = mlx5_malloc(MLX5_MEM_ZERO, total_size, 0, SOCKET_ID_ANY);
8488 [ # # ]: 0 : if (!copied_items) {
8489 : 0 : rte_flow_error_set(error, ENOMEM,
8490 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8491 : : NULL,
8492 : : "cannot allocate item template");
8493 : 0 : return NULL;
8494 : : }
8495 : :
8496 : : /* Deep-copy the prepended item into the tail region. */
8497 : 0 : new_item_buf = (char *)copied_items + header_size;
8498 : 0 : rc = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM, new_item_buf, (size_t)new_item_size, new_item,
8499 : : error);
8500 [ # # ]: 0 : if (rc < 0) {
8501 : 0 : mlx5_free(copied_items);
8502 : 0 : return NULL;
8503 : : }
8504 : :
8505 : : /*
8506 : : * Slot 0 is the prepended item header just written by rte_flow_conv,
8507 : : * with .spec/.mask/.last already pointing inside the same buffer.
8508 : : * The remaining items[] retain their (caller-owned, longer-lived)
8509 : : * spec/mask pointers via shallow copy.
8510 : : */
8511 : 0 : copied_items[0] = *(const struct rte_flow_item *)new_item_buf;
8512 [ # # ]: 0 : rte_memcpy(&copied_items[1], items, sizeof(*items) * nb_items);
8513 : : return copied_items;
8514 : : }
8515 : :
8516 : : static int
8517 : 0 : flow_hw_item_compare_field_validate(enum rte_flow_field_id arg_field,
8518 : : enum rte_flow_field_id base_field,
8519 : : struct rte_flow_error *error)
8520 : : {
8521 [ # # # ]: 0 : switch (arg_field) {
8522 : : case RTE_FLOW_FIELD_TAG:
8523 : : case RTE_FLOW_FIELD_META:
8524 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
8525 : : break;
8526 : 0 : case RTE_FLOW_FIELD_RANDOM:
8527 [ # # ]: 0 : if (base_field == RTE_FLOW_FIELD_VALUE)
8528 : : return 0;
8529 : 0 : return rte_flow_error_set(error, EINVAL,
8530 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8531 : : NULL,
8532 : : "compare random is supported only with immediate value");
8533 : 0 : default:
8534 : 0 : return rte_flow_error_set(error, ENOTSUP,
8535 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8536 : : NULL,
8537 : : "compare item argument field is not supported");
8538 : : }
8539 [ # # ]: 0 : switch (base_field) {
8540 : : case RTE_FLOW_FIELD_TAG:
8541 : : case RTE_FLOW_FIELD_META:
8542 : : case RTE_FLOW_FIELD_VALUE:
8543 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
8544 : : break;
8545 : 0 : default:
8546 : 0 : return rte_flow_error_set(error, ENOTSUP,
8547 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8548 : : NULL,
8549 : : "compare item base field is not supported");
8550 : : }
8551 : : return 0;
8552 : : }
8553 : :
8554 : : static inline uint32_t
8555 : : flow_hw_item_compare_width_supported(enum rte_flow_field_id field)
8556 : : {
8557 [ # # # ]: 0 : switch (field) {
8558 : : case RTE_FLOW_FIELD_TAG:
8559 : : case RTE_FLOW_FIELD_META:
8560 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
8561 : : return 32;
8562 : 0 : case RTE_FLOW_FIELD_RANDOM:
8563 : 0 : return 16;
8564 : : default:
8565 : : break;
8566 : : }
8567 : 0 : return 0;
8568 : : }
8569 : :
8570 : : static int
8571 : 0 : flow_hw_validate_item_compare(const struct rte_flow_item *item,
8572 : : struct rte_flow_error *error)
8573 : : {
8574 : 0 : const struct rte_flow_item_compare *comp_m = item->mask;
8575 : 0 : const struct rte_flow_item_compare *comp_v = item->spec;
8576 : : int ret;
8577 : :
8578 [ # # ]: 0 : if (unlikely(!comp_m))
8579 : 0 : return rte_flow_error_set(error, EINVAL,
8580 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8581 : : NULL,
8582 : : "compare item mask is missing");
8583 [ # # ]: 0 : if (comp_m->width != UINT32_MAX)
8584 : 0 : return rte_flow_error_set(error, EINVAL,
8585 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8586 : : NULL,
8587 : : "compare item only support full mask");
8588 : 0 : ret = flow_hw_item_compare_field_validate(comp_m->a.field,
8589 : 0 : comp_m->b.field, error);
8590 [ # # ]: 0 : if (ret < 0)
8591 : : return ret;
8592 [ # # ]: 0 : if (comp_v) {
8593 : : uint32_t width;
8594 : :
8595 [ # # ]: 0 : if (comp_v->operation != comp_m->operation ||
8596 [ # # ]: 0 : comp_v->a.field != comp_m->a.field ||
8597 [ # # ]: 0 : comp_v->b.field != comp_m->b.field)
8598 : 0 : return rte_flow_error_set(error, EINVAL,
8599 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8600 : : NULL,
8601 : : "compare item spec/mask not matching");
8602 : : width = flow_hw_item_compare_width_supported(comp_v->a.field);
8603 : : MLX5_ASSERT(width > 0);
8604 [ # # ]: 0 : if ((comp_v->width & comp_m->width) != width)
8605 : 0 : return rte_flow_error_set(error, EINVAL,
8606 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8607 : : NULL,
8608 : : "compare item only support full mask");
8609 : : }
8610 : : return 0;
8611 : : }
8612 : :
8613 : : static inline int
8614 : : mlx5_hw_validate_item_nsh(struct rte_eth_dev *dev,
8615 : : const struct rte_flow_item *item,
8616 : : struct rte_flow_error *error)
8617 : : {
8618 : 0 : return mlx5_flow_validate_item_nsh(dev, item, error);
8619 : : }
8620 : :
8621 : : static inline uint8_t
8622 : 0 : mlx5_hw_flow_get_next_protocol(const struct rte_flow_item *item)
8623 : : {
8624 [ # # # # ]: 0 : if (!item || !item->spec)
8625 : : return 0xff;
8626 : :
8627 [ # # # # ]: 0 : switch (item->type) {
8628 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4: {
8629 : : const struct rte_flow_item_ipv4 *spec = item->spec;
8630 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
8631 : :
8632 : : /* If mask is NULL or next_proto_id field in mask is 0,
8633 : : * then next_protocol in spec should not be read
8634 : : */
8635 [ # # # # ]: 0 : if (!mask || mask->hdr.next_proto_id == 0)
8636 : : return 0xff;
8637 : :
8638 : 0 : return spec->hdr.next_proto_id & mask->hdr.next_proto_id;
8639 : : }
8640 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6: {
8641 : : const struct rte_flow_item_ipv6 *spec = item->spec;
8642 : 0 : const struct rte_flow_item_ipv6 *mask = item->mask;
8643 : :
8644 : : /* If mask is NULL or proto field in mask is 0,
8645 : : * then proto in spec should not be read
8646 : : */
8647 [ # # # # ]: 0 : if (!mask || mask->hdr.proto == 0)
8648 : : return 0xff;
8649 : :
8650 : 0 : return spec->hdr.proto & mask->hdr.proto;
8651 : : }
8652 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT: {
8653 : : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
8654 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
8655 : :
8656 : : /* If mask is NULL or next_header field in mask is 0,
8657 : : * then next_header in spec should not be read
8658 : : */
8659 [ # # # # ]: 0 : if (!mask || mask->hdr.next_header == 0)
8660 : : return 0xff;
8661 : :
8662 : 0 : return spec->hdr.next_header & mask->hdr.next_header;
8663 : : }
8664 : : default:
8665 : : return 0xff;
8666 : : }
8667 : : }
8668 : :
8669 : : static int
8670 : 0 : mlx5_hw_flow_tunnel_ip_check(uint64_t last_item,
8671 : : const struct rte_flow_item *last_l3_item,
8672 : : const struct rte_flow_item *item,
8673 : : uint64_t *item_flags,
8674 : : struct rte_flow_error *error)
8675 : : {
8676 : : uint64_t tunnel_flag = 0;
8677 : : uint8_t outer_protocol;
8678 : :
8679 : : /* IP tunnel detection - only single-level tunneling supported */
8680 [ # # ]: 0 : if (last_l3_item && (last_item == MLX5_FLOW_LAYER_OUTER_L3_IPV4 ||
8681 [ # # ]: 0 : last_item == MLX5_FLOW_LAYER_OUTER_L3_IPV6)) {
8682 : : /*
8683 : : * Tunnel type determination strategy:
8684 : : * 1. If previous L3 item has protocol field specified, use it (RFC compliant)
8685 : : * 2. Otherwise, fall back to inner header type (what's being encapsulated)
8686 : : */
8687 : 0 : outer_protocol = mlx5_hw_flow_get_next_protocol(last_l3_item);
8688 : :
8689 [ # # ]: 0 : if (outer_protocol != 0xff) {
8690 : : /* Proto field specified in outer hdr mask - use RFC-compliant detection */
8691 [ # # # ]: 0 : switch (outer_protocol) {
8692 : 0 : case IPPROTO_IPIP: /* 4 - IP-in-IP */
8693 : : /* Outer header indicates IPv4 payload */
8694 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6)
8695 : 0 : return rte_flow_error_set(error, EINVAL,
8696 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
8697 : : "protocol mismatch: outer proto is IPIP but inner is IPv6");
8698 : : tunnel_flag = MLX5_FLOW_LAYER_IPIP;
8699 : : break;
8700 : 0 : case IPPROTO_IPV6: /* 41 - IPv6-in-IP */
8701 : : /* Outer header indicates IPv6 payload */
8702 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4)
8703 : 0 : return rte_flow_error_set(error, EINVAL,
8704 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
8705 : : "protocol mismatch: outer proto is IPV6 but inner is IPv4");
8706 : : tunnel_flag = MLX5_FLOW_LAYER_IPV6_ENCAP;
8707 : : break;
8708 : 0 : default:
8709 : : /* Unknown/unsupported protocol, fall back to inner header type */
8710 : 0 : goto fallback_classification;
8711 : : }
8712 : : } else {
8713 : 0 : fallback_classification:
8714 : : /*
8715 : : * Protocol field not specified or unknown - classify based on
8716 : : * what is being encapsulated (inner header type)
8717 : : */
8718 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4)
8719 : : tunnel_flag = MLX5_FLOW_LAYER_IPIP;
8720 [ # # ]: 0 : else if (item->type == RTE_FLOW_ITEM_TYPE_IPV6)
8721 : : tunnel_flag = MLX5_FLOW_LAYER_IPV6_ENCAP;
8722 : : else
8723 : : return 0; /* Not an IP item - shouldn't happen, but be defensive */
8724 : : }
8725 : :
8726 : : /* Check for unsupported nested tunneling after tunnel is detected */
8727 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_TUNNEL)
8728 : 0 : return rte_flow_error_set(error, ENOTSUP,
8729 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
8730 : : "multiple tunnel layers not supported");
8731 : :
8732 : 0 : *item_flags |= tunnel_flag;
8733 : 0 : return 1; /* Tunnel detected */
8734 [ # # ]: 0 : } else if (last_item == MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT) {
8735 : : /* Special case: IPv6 routing extension header */
8736 : : /* Check for unsupported nested tunneling */
8737 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_TUNNEL)
8738 : 0 : return rte_flow_error_set(error, ENOTSUP,
8739 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
8740 : : "multiple tunnel layers not supported");
8741 : :
8742 : 0 : *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
8743 : 0 : return 1; /* Tunnel detected */
8744 : : }
8745 : :
8746 : : return 0; /* No tunnel */
8747 : : }
8748 : :
8749 : : const struct rte_flow_item_ipv4 hws_nic_ipv4_mask = {
8750 : : .hdr = {
8751 : : .version = 0xf,
8752 : : .ihl = 0xf,
8753 : : .type_of_service = 0xff,
8754 : : .total_length = RTE_BE16(0xffff),
8755 : : .packet_id = RTE_BE16(0xffff),
8756 : : .fragment_offset = RTE_BE16(0xffff),
8757 : : .time_to_live = 0xff,
8758 : : .next_proto_id = 0xff,
8759 : : .src_addr = RTE_BE32(0xffffffff),
8760 : : .dst_addr = RTE_BE32(0xffffffff),
8761 : : },
8762 : : };
8763 : :
8764 : : const struct rte_flow_item_ipv6 hws_nic_ipv6_mask = {
8765 : : .hdr = {
8766 : : .vtc_flow = RTE_BE32(0xffffffff),
8767 : : .payload_len = RTE_BE16(0xffff),
8768 : : .proto = 0xff,
8769 : : .hop_limits = 0xff,
8770 : : .src_addr = RTE_IPV6_MASK_FULL,
8771 : : .dst_addr = RTE_IPV6_MASK_FULL,
8772 : : },
8773 : : .has_frag_ext = 1,
8774 : : };
8775 : :
8776 : : const struct rte_flow_item_ecpri hws_nic_ecpri_mask = {
8777 : : .hdr = {
8778 : : .common = {
8779 : : .u32 = RTE_BE32(0xffffffff),
8780 : : },
8781 : : .dummy[0] = 0xffffffff,
8782 : : },
8783 : : };
8784 : :
8785 : :
8786 : : static int
8787 : 0 : flow_hw_validate_item_ptype(const struct rte_flow_item *item,
8788 : : struct rte_flow_error *error)
8789 : : {
8790 : 0 : const struct rte_flow_item_ptype *ptype = item->mask;
8791 : :
8792 : : /* HWS does not allow empty PTYPE mask */
8793 [ # # ]: 0 : if (!ptype)
8794 : 0 : return rte_flow_error_set(error, EINVAL,
8795 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8796 : : NULL, "empty ptype mask");
8797 [ # # ]: 0 : if (!(ptype->packet_type &
8798 : : (RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK | RTE_PTYPE_L4_MASK |
8799 : : RTE_PTYPE_INNER_L2_MASK | RTE_PTYPE_INNER_L3_MASK |
8800 : : RTE_PTYPE_INNER_L4_MASK)))
8801 : 0 : return rte_flow_error_set(error, ENOTSUP,
8802 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8803 : : NULL, "ptype mask not supported");
8804 : : return 0;
8805 : : }
8806 : :
8807 : : struct mlx5_hw_pattern_validation_ctx {
8808 : : const struct rte_flow_item *geneve_item;
8809 : : const struct rte_flow_item *flex_item;
8810 : : };
8811 : :
8812 : : static int
8813 : 0 : __flow_hw_pattern_validate(struct rte_eth_dev *dev,
8814 : : const struct rte_flow_pattern_template_attr *attr,
8815 : : const struct rte_flow_item items[],
8816 : : uint64_t *item_flags,
8817 : : bool nt_flow,
8818 : : struct rte_flow_error *error)
8819 : : {
8820 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8821 : : const struct rte_flow_item *last_l3_item = NULL;
8822 : : const struct rte_flow_item *item;
8823 : : const struct rte_flow_item *gtp_item = NULL;
8824 : : const struct rte_flow_item *gre_item = NULL;
8825 : 0 : const struct rte_flow_attr flow_attr = {
8826 : 0 : .ingress = attr->ingress,
8827 : 0 : .egress = attr->egress,
8828 : 0 : .transfer = attr->transfer
8829 : : };
8830 : : int ret, tag_idx;
8831 : : uint32_t tag_bitmap = 0;
8832 : : uint64_t last_item = 0;
8833 : :
8834 [ # # ]: 0 : if (!mlx5_hw_ctx_validate(dev, error))
8835 : 0 : return -rte_errno;
8836 [ # # ]: 0 : if (!attr->ingress && !attr->egress && !attr->transfer)
8837 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR, NULL,
8838 : : "at least one of the direction attributes"
8839 : : " must be specified");
8840 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
8841 : : MLX5_ASSERT(priv->master || priv->representor);
8842 [ # # ]: 0 : if (priv->master) {
8843 [ # # ]: 0 : if ((attr->ingress && attr->egress) ||
8844 [ # # ]: 0 : (attr->ingress && attr->transfer) ||
8845 [ # # ]: 0 : (attr->egress && attr->transfer))
8846 : 0 : return rte_flow_error_set(error, EINVAL,
8847 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
8848 : : "only one direction attribute at once"
8849 : : " can be used on transfer proxy port");
8850 : : } else {
8851 [ # # ]: 0 : if (attr->transfer)
8852 : 0 : return rte_flow_error_set(error, EINVAL,
8853 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, NULL,
8854 : : "transfer attribute cannot be used with"
8855 : : " port representors");
8856 [ # # ]: 0 : if (attr->ingress && attr->egress)
8857 : 0 : return rte_flow_error_set(error, EINVAL,
8858 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
8859 : : "ingress and egress direction attributes"
8860 : : " cannot be used at the same time on"
8861 : : " port representors");
8862 : : }
8863 : : } else {
8864 [ # # ]: 0 : if (attr->transfer)
8865 : 0 : return rte_flow_error_set(error, EINVAL,
8866 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, NULL,
8867 : : "transfer attribute cannot be used when"
8868 : : " E-Switch is disabled");
8869 : : }
8870 [ # # ]: 0 : for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8871 : 0 : bool tunnel = *item_flags & MLX5_FLOW_LAYER_TUNNEL;
8872 : :
8873 [ # # # # : 0 : switch ((int)item->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
8874 : 0 : case RTE_FLOW_ITEM_TYPE_PTYPE:
8875 : 0 : ret = flow_hw_validate_item_ptype(item, error);
8876 [ # # ]: 0 : if (ret)
8877 : 0 : return ret;
8878 : : last_item = MLX5_FLOW_ITEM_PTYPE;
8879 : : break;
8880 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8881 : : {
8882 : 0 : const struct rte_flow_item_tag *tag =
8883 : : (const struct rte_flow_item_tag *)item->spec;
8884 : :
8885 [ # # ]: 0 : if (tag == NULL)
8886 : 0 : return rte_flow_error_set(error, EINVAL,
8887 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8888 : : NULL,
8889 : : "Tag spec is NULL");
8890 [ # # ]: 0 : if (tag->index >= MLX5_FLOW_HW_TAGS_MAX &&
8891 : : tag->index != RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
8892 : 0 : return rte_flow_error_set(error, EINVAL,
8893 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8894 : : NULL,
8895 : : "Invalid tag index");
8896 [ # # ]: 0 : tag_idx = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, tag->index);
8897 [ # # ]: 0 : if (tag_idx == REG_NON)
8898 : 0 : return rte_flow_error_set(error, EINVAL,
8899 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8900 : : NULL,
8901 : : "Unsupported tag index");
8902 [ # # ]: 0 : if (tag_bitmap & (1 << tag_idx))
8903 : 0 : return rte_flow_error_set(error, EINVAL,
8904 : : RTE_FLOW_ERROR_TYPE_ITEM,
8905 : : NULL,
8906 : : "Duplicated tag index");
8907 : 0 : tag_bitmap |= 1 << tag_idx;
8908 : : last_item = MLX5_FLOW_ITEM_TAG;
8909 : 0 : break;
8910 : : }
8911 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8912 : : {
8913 : 0 : const struct rte_flow_item_tag *tag =
8914 : : (const struct rte_flow_item_tag *)item->spec;
8915 : 0 : uint16_t regcs = (uint8_t)priv->sh->cdev->config.hca_attr.set_reg_c;
8916 : :
8917 [ # # ]: 0 : if (!((1 << (tag->index - REG_C_0)) & regcs))
8918 : 0 : return rte_flow_error_set(error, EINVAL,
8919 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8920 : : NULL,
8921 : : "Unsupported internal tag index");
8922 [ # # ]: 0 : if (tag_bitmap & (1 << tag->index))
8923 : 0 : return rte_flow_error_set(error, EINVAL,
8924 : : RTE_FLOW_ERROR_TYPE_ITEM,
8925 : : NULL,
8926 : : "Duplicated tag index");
8927 : 0 : tag_bitmap |= 1 << tag->index;
8928 : 0 : break;
8929 : : }
8930 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
8931 [ # # ]: 0 : if (attr->ingress)
8932 : 0 : return rte_flow_error_set(error, EINVAL,
8933 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
8934 : : "represented port item cannot be used"
8935 : : " when ingress attribute is set");
8936 [ # # ]: 0 : if (attr->egress)
8937 : 0 : return rte_flow_error_set(error, EINVAL,
8938 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
8939 : : "represented port item cannot be used"
8940 : : " when egress attribute is set");
8941 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
8942 : : break;
8943 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8944 : : /* ingress + group 0 is not supported */
8945 : 0 : *item_flags |= MLX5_FLOW_ITEM_METADATA;
8946 : 0 : break;
8947 : : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8948 : : {
8949 : : int reg = flow_hw_get_reg_id(dev,
8950 : : RTE_FLOW_ITEM_TYPE_METER_COLOR,
8951 : : 0);
8952 [ # # ]: 0 : if (reg == REG_NON)
8953 : 0 : return rte_flow_error_set(error, EINVAL,
8954 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8955 : : NULL,
8956 : : "Unsupported meter color register");
8957 [ # # ]: 0 : if (*item_flags &
8958 : : (MLX5_FLOW_ITEM_QUOTA | MLX5_FLOW_LAYER_ASO_CT))
8959 : 0 : return rte_flow_error_set
8960 : : (error, EINVAL,
8961 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL, "Only one ASO item is supported");
8962 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8963 : : break;
8964 : : }
8965 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8966 : : {
8967 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
8968 : 0 : return rte_flow_error_set(error, EINVAL,
8969 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
8970 : : "Unsupported aggregated affinity with Older FW");
8971 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) || attr->egress)
# # ]
8972 : 0 : return rte_flow_error_set(error, EINVAL,
8973 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
8974 : : "Aggregated affinity item not supported"
8975 : : " with egress or transfer"
8976 : : " attribute");
8977 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8978 : : break;
8979 : : }
8980 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8981 : : last_item = MLX5_FLOW_LAYER_GENEVE;
8982 : 0 : break;
8983 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8984 : : {
8985 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8986 : : /*
8987 : : * For non template the parser is internally created before
8988 : : * the flow creation.
8989 : : */
8990 [ # # ]: 0 : if (!nt_flow) {
8991 : 0 : ret = mlx5_flow_geneve_tlv_option_validate(priv, item,
8992 : : error);
8993 [ # # ]: 0 : if (ret < 0)
8994 : 0 : return ret;
8995 : : }
8996 : : break;
8997 : : }
8998 : 0 : case RTE_FLOW_ITEM_TYPE_COMPARE:
8999 : : {
9000 : : last_item = MLX5_FLOW_ITEM_COMPARE;
9001 : 0 : ret = flow_hw_validate_item_compare(item, error);
9002 [ # # ]: 0 : if (ret)
9003 : 0 : return ret;
9004 : : break;
9005 : : }
9006 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
9007 : 0 : ret = mlx5_flow_validate_item_eth(dev, item,
9008 : : *item_flags,
9009 : : true, error);
9010 [ # # ]: 0 : if (ret < 0)
9011 : 0 : return ret;
9012 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
9013 : : MLX5_FLOW_LAYER_OUTER_L2;
9014 : : break;
9015 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
9016 : 0 : ret = mlx5_flow_dv_validate_item_vlan(item, *item_flags,
9017 : : dev, error);
9018 [ # # ]: 0 : if (ret < 0)
9019 : 0 : return ret;
9020 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
9021 : : MLX5_FLOW_LAYER_OUTER_VLAN;
9022 : : break;
9023 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
9024 : 0 : ret = mlx5_hw_flow_tunnel_ip_check(last_item, last_l3_item, item,
9025 : : item_flags, error);
9026 [ # # ]: 0 : if (ret < 0)
9027 : 0 : return ret;
9028 : 0 : tunnel |= (ret > 0);
9029 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, item,
9030 : : *item_flags,
9031 : : last_item, 0,
9032 : : &hws_nic_ipv4_mask,
9033 : : error);
9034 [ # # ]: 0 : if (ret)
9035 : 0 : return ret;
9036 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
9037 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
9038 : : last_l3_item = item;
9039 : : break;
9040 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
9041 : 0 : ret = mlx5_hw_flow_tunnel_ip_check(last_item, last_l3_item, item,
9042 : : item_flags, error);
9043 [ # # ]: 0 : if (ret < 0)
9044 : 0 : return ret;
9045 : 0 : tunnel |= (ret > 0);
9046 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, item,
9047 : : *item_flags,
9048 : : last_item, 0,
9049 : : &hws_nic_ipv6_mask,
9050 : : error);
9051 [ # # ]: 0 : if (ret < 0)
9052 : 0 : return ret;
9053 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
9054 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
9055 : : last_l3_item = item;
9056 : : break;
9057 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
9058 : 0 : ret = mlx5_flow_validate_item_udp(dev, item,
9059 : : *item_flags,
9060 : : 0xff, error);
9061 [ # # ]: 0 : if (ret)
9062 : 0 : return ret;
9063 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
9064 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
9065 : : break;
9066 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
9067 : 0 : ret = mlx5_flow_validate_item_tcp
9068 : : (dev, item, *item_flags,
9069 : : 0xff, &nic_tcp_mask, error);
9070 [ # # ]: 0 : if (ret < 0)
9071 : 0 : return ret;
9072 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
9073 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
9074 : : break;
9075 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
9076 : : gtp_item = item;
9077 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, gtp_item,
9078 : : *item_flags, error);
9079 [ # # ]: 0 : if (ret < 0)
9080 : 0 : return ret;
9081 : : last_item = MLX5_FLOW_LAYER_GTP;
9082 : : break;
9083 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
9084 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, item,
9085 : : last_item,
9086 : : gtp_item,
9087 : : false, error);
9088 [ # # ]: 0 : if (ret < 0)
9089 : 0 : return ret;
9090 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
9091 : : break;
9092 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
9093 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, 0, item,
9094 : : *item_flags,
9095 : : false, error);
9096 [ # # ]: 0 : if (ret < 0)
9097 : 0 : return ret;
9098 : : last_item = MLX5_FLOW_LAYER_VXLAN;
9099 : : break;
9100 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
9101 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(item,
9102 : : *item_flags,
9103 : : dev, error);
9104 [ # # ]: 0 : if (ret < 0)
9105 : 0 : return ret;
9106 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
9107 : : break;
9108 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
9109 : 0 : ret = mlx5_flow_validate_item_mpls(dev, item,
9110 : : *item_flags,
9111 : : last_item, error);
9112 [ # # ]: 0 : if (ret < 0)
9113 : 0 : return ret;
9114 : : last_item = MLX5_FLOW_LAYER_MPLS;
9115 : : break;
9116 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
9117 : : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
9118 : : last_item = MLX5_FLOW_ITEM_SQ;
9119 : 0 : break;
9120 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
9121 : 0 : ret = mlx5_flow_validate_item_gre(dev, item,
9122 : : *item_flags,
9123 : : 0xff, error);
9124 [ # # ]: 0 : if (ret < 0)
9125 : 0 : return ret;
9126 : : gre_item = item;
9127 : : last_item = MLX5_FLOW_LAYER_GRE;
9128 : : break;
9129 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
9130 [ # # ]: 0 : if (!(*item_flags & MLX5_FLOW_LAYER_GRE))
9131 : 0 : return rte_flow_error_set
9132 : : (error, EINVAL,
9133 : : RTE_FLOW_ERROR_TYPE_ITEM, item, "GRE item is missing");
9134 : 0 : ret = mlx5_flow_validate_item_gre_key
9135 : : (dev, item, *item_flags, gre_item, error);
9136 [ # # ]: 0 : if (ret < 0)
9137 : 0 : return ret;
9138 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
9139 : : break;
9140 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
9141 [ # # ]: 0 : if (!(*item_flags & MLX5_FLOW_LAYER_GRE))
9142 : 0 : return rte_flow_error_set
9143 : : (error, EINVAL,
9144 : : RTE_FLOW_ERROR_TYPE_ITEM, item, "GRE item is missing");
9145 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, item,
9146 : : *item_flags,
9147 : : &flow_attr,
9148 : : gre_item,
9149 : : error);
9150 [ # # ]: 0 : if (ret < 0)
9151 : 0 : return ret;
9152 : : last_item = MLX5_FLOW_LAYER_GRE;
9153 : : break;
9154 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
9155 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, item,
9156 : : *item_flags, 0xff,
9157 : : error);
9158 [ # # ]: 0 : if (ret)
9159 : 0 : return ret;
9160 : : last_item = MLX5_FLOW_LAYER_NVGRE;
9161 : : break;
9162 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
9163 : 0 : ret = mlx5_flow_validate_item_icmp(dev, item,
9164 : : *item_flags, 0xff,
9165 : : error);
9166 [ # # ]: 0 : if (ret < 0)
9167 : 0 : return ret;
9168 : : last_item = MLX5_FLOW_LAYER_ICMP;
9169 : : break;
9170 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
9171 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, item,
9172 : : *item_flags, 0xff,
9173 : : error);
9174 [ # # ]: 0 : if (ret < 0)
9175 : 0 : return ret;
9176 : : last_item = MLX5_FLOW_LAYER_ICMP6;
9177 : : break;
9178 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
9179 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
9180 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, item,
9181 : : *item_flags,
9182 : : 0xff, error);
9183 [ # # ]: 0 : if (ret < 0)
9184 : 0 : return ret;
9185 : : last_item = MLX5_FLOW_LAYER_ICMP6;
9186 : : break;
9187 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
9188 [ # # ]: 0 : if (*item_flags &
9189 : : (MLX5_FLOW_ITEM_QUOTA | MLX5_FLOW_LAYER_ASO_CT))
9190 : 0 : return rte_flow_error_set
9191 : : (error, EINVAL,
9192 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL, "Only one ASO item is supported");
9193 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, item,
9194 : : item_flags,
9195 : : error);
9196 [ # # ]: 0 : if (ret < 0)
9197 : 0 : return ret;
9198 : : break;
9199 : 0 : case RTE_FLOW_ITEM_TYPE_QUOTA:
9200 [ # # ]: 0 : if (*item_flags &
9201 : : (MLX5_FLOW_ITEM_METER_COLOR |
9202 : : MLX5_FLOW_LAYER_ASO_CT))
9203 : 0 : return rte_flow_error_set
9204 : : (error, EINVAL,
9205 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL, "Only one ASO item is supported");
9206 : : last_item = MLX5_FLOW_ITEM_QUOTA;
9207 : : break;
9208 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
9209 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, item, *item_flags,
9210 : : 0xff, true, error);
9211 [ # # ]: 0 : if (ret < 0)
9212 : 0 : return ret;
9213 : : last_item = MLX5_FLOW_ITEM_ESP;
9214 : : break;
9215 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_ROUTING_EXT:
9216 : : last_item = tunnel ?
9217 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT :
9218 : : MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT;
9219 : : break;
9220 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX: {
9221 : 0 : enum rte_flow_item_flex_tunnel_mode tunnel_mode = FLEX_TUNNEL_MODE_SINGLE;
9222 : :
9223 : 0 : ret = mlx5_flex_get_tunnel_mode(item, &tunnel_mode);
9224 [ # # ]: 0 : if (ret < 0)
9225 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ITEM,
9226 : : item, "Unable to get flex item mode");
9227 [ # # ]: 0 : if (tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL)
9228 : : last_item = MLX5_FLOW_ITEM_FLEX_TUNNEL;
9229 : : else
9230 : : last_item = tunnel ?
9231 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX :
9232 : : MLX5_FLOW_ITEM_OUTER_FLEX;
9233 : 0 : break;
9234 : : }
9235 : 0 : case RTE_FLOW_ITEM_TYPE_RANDOM:
9236 : : last_item = MLX5_FLOW_ITEM_RANDOM;
9237 : 0 : break;
9238 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
9239 : : last_item = MLX5_FLOW_ITEM_NSH;
9240 : : ret = mlx5_hw_validate_item_nsh(dev, item, error);
9241 [ # # ]: 0 : if (ret < 0)
9242 : 0 : return ret;
9243 : : break;
9244 : : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
9245 : : /*
9246 : : * Integrity flow item validation require access to
9247 : : * both item mask and spec.
9248 : : * Current HWS model allows item mask in pattern
9249 : : * template and item spec in flow rule.
9250 : : */
9251 : : break;
9252 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
9253 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, item, *item_flags, last_item,
9254 : : RTE_ETHER_TYPE_ECPRI,
9255 : : &hws_nic_ecpri_mask, error);
9256 [ # # ]: 0 : if (ret < 0)
9257 : 0 : return ret;
9258 : 0 : *item_flags |= MLX5_FLOW_LAYER_ECPRI;
9259 : 0 : break;
9260 : : case RTE_FLOW_ITEM_TYPE_IB_BTH:
9261 : : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
9262 : : case RTE_FLOW_ITEM_TYPE_VOID:
9263 : : case RTE_FLOW_ITEM_TYPE_END:
9264 : : break;
9265 : 0 : default:
9266 : 0 : return rte_flow_error_set(error, EINVAL,
9267 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9268 : : NULL,
9269 : : "Unsupported item type");
9270 : : }
9271 : 0 : *item_flags |= last_item;
9272 : : }
9273 : 0 : return 1 + RTE_PTR_DIFF(item, items) / sizeof(item[0]);
9274 : : }
9275 : :
9276 : : static int
9277 : 0 : flow_hw_pattern_validate(struct rte_eth_dev *dev,
9278 : : const struct rte_flow_pattern_template_attr *attr,
9279 : : const struct rte_flow_item items[],
9280 : : uint64_t *item_flags,
9281 : : struct rte_flow_error *error)
9282 : : {
9283 : 0 : return __flow_hw_pattern_validate(dev, attr, items, item_flags, false, error);
9284 : : }
9285 : :
9286 : : /*
9287 : : * Verify that the tested flow patterns fits STE size limit in HWS group.
9288 : : *
9289 : : *
9290 : : * Return values:
9291 : : * 0 : Tested patterns fit STE size limit
9292 : : * -EINVAL : Invalid parameters detected
9293 : : * -E2BIG : Tested patterns exceed STE size limit
9294 : : */
9295 : : static int
9296 : 0 : pattern_template_validate(struct rte_eth_dev *dev,
9297 : : struct rte_flow_pattern_template *pt[],
9298 : : uint32_t pt_num,
9299 : : struct rte_flow_error *error)
9300 : : {
9301 : 0 : struct mlx5_flow_template_table_cfg tbl_cfg = {
9302 : : .attr = {
9303 : : .nb_flows = 64,
9304 : : .insertion_type = RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN,
9305 : : .hash_func = RTE_FLOW_TABLE_HASH_FUNC_DEFAULT,
9306 : : .flow_attr = {
9307 : : .group = 1,
9308 : 0 : .ingress = pt[0]->attr.ingress,
9309 : 0 : .egress = pt[0]->attr.egress,
9310 : 0 : .transfer = pt[0]->attr.transfer
9311 : : }
9312 : : }
9313 : : };
9314 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9315 : : struct rte_flow_actions_template *action_template;
9316 : : struct rte_flow_template_table *tmpl_tbl;
9317 : : int ret;
9318 : :
9319 [ # # ]: 0 : if (pt[0]->attr.ingress) {
9320 : 0 : action_template =
9321 : 0 : priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_RX];
9322 [ # # ]: 0 : } else if (pt[0]->attr.egress) {
9323 : 0 : action_template =
9324 : 0 : priv->action_template_drop[MLX5DR_TABLE_TYPE_NIC_TX];
9325 [ # # ]: 0 : } else if (pt[0]->attr.transfer) {
9326 : 0 : action_template =
9327 : 0 : priv->action_template_drop[MLX5DR_TABLE_TYPE_FDB];
9328 : : } else {
9329 : : ret = EINVAL;
9330 : 0 : goto end;
9331 : : }
9332 : :
9333 [ # # ]: 0 : if (pt[0]->item_flags & MLX5_FLOW_ITEM_COMPARE)
9334 : 0 : tbl_cfg.attr.nb_flows = 1;
9335 : 0 : tmpl_tbl = flow_hw_table_create(dev, &tbl_cfg, pt, pt_num,
9336 : : &action_template, 1, error);
9337 [ # # ]: 0 : if (tmpl_tbl) {
9338 : : ret = 0;
9339 : 0 : flow_hw_table_destroy(dev, tmpl_tbl, error);
9340 : : } else {
9341 [ # # # ]: 0 : switch (rte_errno) {
9342 : : case E2BIG:
9343 : : ret = E2BIG;
9344 : : break;
9345 : : case ENOTSUP:
9346 : : ret = EINVAL;
9347 : : break;
9348 : : default:
9349 : : ret = 0;
9350 : : break;
9351 : : }
9352 : : }
9353 : : end:
9354 : : if (ret)
9355 : 0 : rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9356 : : NULL, "failed to validate pattern template");
9357 : 0 : return -ret;
9358 : : }
9359 : :
9360 : : /*
9361 : : * Validate the user-supplied items and, in eSwitch mode, prepend the implicit
9362 : : * scoping item so the rule/template is bound to the current representor port:
9363 : : * - ingress -> RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT (dev->data->port_id)
9364 : : * - egress -> MLX5_RTE_FLOW_ITEM_TYPE_TAG on REG_C_0 (tx vport tag),
9365 : : * skipped when the user already supplied an SQ item.
9366 : : *
9367 : : * @param nt_flow
9368 : : * Selects between the two call paths that share this helper:
9369 : : * false -> pattern template creation (async API). The prepended item's
9370 : : * spec is left zeroed so mlx5dr matches any value; the live
9371 : : * port_id / tx-tag value is substituted later by
9372 : : * flow_hw_get_rule_items() at rule-create time.
9373 : : * true -> sync (non-template) flow creation. The prepended item's spec
9374 : : * is filled immediately with the live values, and the flag is
9375 : : * forwarded to __flow_hw_pattern_validate() so that validation
9376 : : * paths gated on nt_flow (e.g. GENEVE_OPT TLV parser creation)
9377 : : * take the non-template branch.
9378 : : *
9379 : : * Return / ownership:
9380 : : * - NULL on validation or allocation failure (error populated).
9381 : : * - `items` unchanged when no prepending is required; *copied_items == NULL.
9382 : : * - A newly-allocated array otherwise; also stored in *copied_items. The
9383 : : * caller must mlx5_free(*copied_items) on every path (it is safe to call
9384 : : * with NULL). Do not free the returned pointer directly.
9385 : : */
9386 : : static const struct rte_flow_item *
9387 : 0 : flow_hw_adjust_pattern(struct rte_eth_dev *dev, const struct rte_flow_pattern_template_attr *attr,
9388 : : bool nt_flow, const struct rte_flow_item *items, uint64_t *item_flags,
9389 : : uint64_t *nb_items, struct rte_flow_item **copied_items,
9390 : : struct rte_flow_error *error)
9391 : : {
9392 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9393 : 0 : struct rte_flow_item_ethdev port_spec = {.port_id = dev->data->port_id};
9394 : 0 : struct rte_flow_item port = {
9395 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
9396 : : .mask = &rte_flow_item_ethdev_mask,
9397 : : };
9398 : 0 : struct rte_flow_item_tag tag_v = {
9399 : : .data = 0,
9400 : : .index = REG_C_0,
9401 : : };
9402 : 0 : struct rte_flow_item_tag tag_m = {
9403 : : .data = flow_hw_tx_tag_regc_mask(dev),
9404 : : .index = 0xff,
9405 : : };
9406 : 0 : struct rte_flow_item tag = {
9407 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
9408 : : .spec = &tag_v,
9409 : : .mask = &tag_m,
9410 : : .last = NULL,
9411 : : };
9412 : : int rc;
9413 : :
9414 [ # # # # ]: 0 : if (!copied_items || !item_flags || !nb_items)
9415 : : return NULL;
9416 : :
9417 [ # # ]: 0 : if (nt_flow) {
9418 : 0 : port.spec = &port_spec;
9419 : 0 : tag_v.data = flow_hw_tx_tag_regc_value(dev);
9420 : : }
9421 : :
9422 : : /*
9423 : : * item_flags must be zero-initialized: __flow_hw_pattern_validate()
9424 : : * OR-accumulates bits into it and reads it (MLX5_FLOW_LAYER_TUNNEL)
9425 : : * on the first iteration.
9426 : : */
9427 : 0 : *item_flags = 0;
9428 : :
9429 : : /* Validate application items only */
9430 : 0 : rc = __flow_hw_pattern_validate(dev, attr, items, item_flags, nt_flow, error);
9431 [ # # ]: 0 : if (rc < 0)
9432 : : return NULL;
9433 : 0 : *nb_items = rc;
9434 : :
9435 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en && attr->ingress && !attr->egress && !attr->transfer) {
9436 : 0 : *copied_items = flow_hw_prepend_item(items, *nb_items, &port, error);
9437 [ # # ]: 0 : if (!*copied_items)
9438 : : return NULL;
9439 : 0 : return *copied_items;
9440 [ # # # # ]: 0 : } else if (priv->sh->config.dv_esw_en && !attr->ingress && attr->egress &&
9441 : : !attr->transfer) {
9442 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_ITEM_SQ) {
9443 : 0 : DRV_LOG(DEBUG,
9444 : : "Port %u: explicit SQ item present, omitting implicit "
9445 : : "REG_C_0 match for egress pattern",
9446 : : dev->data->port_id);
9447 : 0 : return items;
9448 : : }
9449 : 0 : *copied_items = flow_hw_prepend_item(items, *nb_items, &tag, error);
9450 [ # # ]: 0 : if (!*copied_items)
9451 : : return NULL;
9452 : 0 : return *copied_items;
9453 : : }
9454 : : return items;
9455 : : }
9456 : :
9457 : : /**
9458 : : * Create flow item template.
9459 : : *
9460 : : * @param[in] dev
9461 : : * Pointer to the rte_eth_dev structure.
9462 : : * @param[in] attr
9463 : : * Pointer to the item template attributes.
9464 : : * @param[in] items
9465 : : * The template item pattern.
9466 : : * @param[out] error
9467 : : * Pointer to error structure.
9468 : : *
9469 : : * @return
9470 : : * Item template pointer on success, NULL otherwise and rte_errno is set.
9471 : : */
9472 : : static struct rte_flow_pattern_template *
9473 : 0 : flow_hw_pattern_template_create(struct rte_eth_dev *dev,
9474 : : const struct rte_flow_pattern_template_attr *attr,
9475 : : const struct rte_flow_item items[],
9476 : : bool external,
9477 : : struct rte_flow_error *error)
9478 : : {
9479 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9480 : : struct rte_flow_pattern_template *it;
9481 : 0 : struct rte_flow_item *copied_items = NULL;
9482 : : const struct rte_flow_item *tmpl_items;
9483 : : int it_items_size;
9484 : : uint64_t orig_item_nb, item_flags;
9485 : : unsigned int i = 0;
9486 : : int rc;
9487 : :
9488 : 0 : tmpl_items = flow_hw_adjust_pattern(dev, attr, false, items, &item_flags, &orig_item_nb,
9489 : : &copied_items, error);
9490 [ # # ]: 0 : if (!tmpl_items)
9491 : : return NULL;
9492 : :
9493 : 0 : it = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*it), 0, SOCKET_ID_ANY);
9494 [ # # ]: 0 : if (!it) {
9495 : 0 : rte_flow_error_set(error, ENOMEM,
9496 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9497 : : NULL,
9498 : : "cannot allocate item template");
9499 : 0 : goto error;
9500 : : }
9501 : 0 : it->attr = *attr;
9502 : 0 : it->item_flags = item_flags;
9503 : 0 : it->orig_item_nb = orig_item_nb;
9504 : 0 : it_items_size = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, NULL, 0, tmpl_items, error);
9505 [ # # ]: 0 : if (it_items_size <= 0) {
9506 : 0 : rte_flow_error_set(error, ENOMEM,
9507 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9508 : : NULL,
9509 : : "Failed to determine buffer size for pattern");
9510 : 0 : goto error;
9511 : : }
9512 : 0 : it_items_size = RTE_ALIGN(it_items_size, 16);
9513 : 0 : it->items = mlx5_malloc(MLX5_MEM_ZERO, it_items_size, 0, SOCKET_ID_ANY);
9514 [ # # ]: 0 : if (it->items == NULL) {
9515 : 0 : rte_flow_error_set(error, ENOMEM,
9516 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9517 : : NULL,
9518 : : "Cannot allocate memory for pattern");
9519 : 0 : goto error;
9520 : : }
9521 : 0 : rc = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, it->items, it_items_size, tmpl_items, error);
9522 [ # # ]: 0 : if (rc <= 0) {
9523 : 0 : rte_flow_error_set(error, ENOMEM,
9524 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9525 : : NULL,
9526 : : "Failed to store pattern");
9527 : 0 : goto error;
9528 : : }
9529 : 0 : it->mt = mlx5dr_match_template_create(tmpl_items, attr->relaxed_matching);
9530 [ # # ]: 0 : if (!it->mt) {
9531 : 0 : rte_flow_error_set(error, rte_errno,
9532 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9533 : : NULL,
9534 : : "cannot create match template");
9535 : 0 : goto error;
9536 : : }
9537 [ # # ]: 0 : if (copied_items) {
9538 [ # # ]: 0 : if (attr->ingress)
9539 : 0 : it->implicit_port = true;
9540 [ # # ]: 0 : else if (attr->egress)
9541 : 0 : it->implicit_tag = true;
9542 : 0 : mlx5_free(copied_items);
9543 : 0 : copied_items = NULL;
9544 : : }
9545 : : /* Either inner or outer, can't both. */
9546 [ # # ]: 0 : if (it->item_flags & (MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT |
9547 : : MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT)) {
9548 [ # # ]: 0 : if (((it->item_flags & MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT) &&
9549 [ # # ]: 0 : (it->item_flags & MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT)) ||
9550 : 0 : (mlx5_alloc_srh_flex_parser(dev))) {
9551 : 0 : rte_flow_error_set(error, rte_errno,
9552 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9553 : : "cannot create IPv6 routing extension support");
9554 : 0 : goto error;
9555 : : }
9556 : : }
9557 [ # # ]: 0 : if (it->item_flags & MLX5_FLOW_ITEM_FLEX) {
9558 [ # # ]: 0 : for (i = 0; items[i].type != RTE_FLOW_ITEM_TYPE_END; i++) {
9559 : 0 : const struct rte_flow_item_flex *spec = items[i].spec;
9560 : : struct rte_flow_item_flex_handle *handle;
9561 : :
9562 [ # # ]: 0 : if (items[i].type != RTE_FLOW_ITEM_TYPE_FLEX)
9563 : 0 : continue;
9564 : 0 : handle = spec->handle;
9565 [ # # ]: 0 : if (flow_hw_flex_item_acquire(dev, handle,
9566 : 0 : &it->flex_item)) {
9567 : 0 : rte_flow_error_set(error, EINVAL,
9568 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9569 : : NULL, "cannot create hw FLEX item");
9570 : 0 : goto error;
9571 : : }
9572 : : }
9573 : : }
9574 [ # # ]: 0 : if (it->item_flags & MLX5_FLOW_LAYER_GENEVE_OPT) {
9575 [ # # ]: 0 : for (i = 0; items[i].type != RTE_FLOW_ITEM_TYPE_END; i++) {
9576 : 0 : const struct rte_flow_item_geneve_opt *spec =
9577 : : items[i].spec;
9578 : :
9579 [ # # ]: 0 : if (items[i].type != RTE_FLOW_ITEM_TYPE_GENEVE_OPT)
9580 : 0 : continue;
9581 [ # # ]: 0 : if (mlx5_geneve_tlv_option_register(priv, spec,
9582 : 0 : &it->geneve_opt_mng)) {
9583 : 0 : rte_flow_error_set(error, EINVAL,
9584 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9585 : : NULL, "cannot register GENEVE TLV option");
9586 : 0 : goto error;
9587 : : }
9588 : : }
9589 : : }
9590 : 0 : rte_atomic_fetch_add_explicit(&it->refcnt, 1, rte_memory_order_relaxed);
9591 : : /* AGGR_AFFINITY only supports under group 0 */
9592 [ # # # # ]: 0 : if (external && !(it->item_flags & MLX5_FLOW_ITEM_AGGR_AFFINITY)) {
9593 : 0 : rc = pattern_template_validate(dev, &it, 1, error);
9594 [ # # ]: 0 : if (rc)
9595 : 0 : goto error;
9596 : : }
9597 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_itt, it, next);
9598 : 0 : return it;
9599 : 0 : error:
9600 [ # # ]: 0 : if (it) {
9601 [ # # ]: 0 : if (it->flex_item)
9602 : 0 : flow_hw_flex_item_release(dev, &it->flex_item);
9603 [ # # ]: 0 : if (it->geneve_opt_mng.nb_options)
9604 : 0 : mlx5_geneve_tlv_options_unregister(priv, &it->geneve_opt_mng);
9605 [ # # ]: 0 : if (it->mt)
9606 : 0 : claim_zero(mlx5dr_match_template_destroy(it->mt));
9607 : 0 : mlx5_free(it->items);
9608 : 0 : mlx5_free(it);
9609 : : }
9610 [ # # ]: 0 : if (copied_items)
9611 : 0 : mlx5_free(copied_items);
9612 : : return NULL;
9613 : : }
9614 : :
9615 : : static struct rte_flow_pattern_template *
9616 : 0 : flow_hw_external_pattern_template_create
9617 : : (struct rte_eth_dev *dev,
9618 : : const struct rte_flow_pattern_template_attr *attr,
9619 : : const struct rte_flow_item items[],
9620 : : struct rte_flow_error *error)
9621 : : {
9622 : 0 : return flow_hw_pattern_template_create(dev, attr, items, true, error);
9623 : : }
9624 : :
9625 : : /**
9626 : : * Destroy flow item template.
9627 : : *
9628 : : * @param[in] dev
9629 : : * Pointer to the rte_eth_dev structure.
9630 : : * @param[in] template
9631 : : * Pointer to the item template to be destroyed.
9632 : : * @param[out] error
9633 : : * Pointer to error structure.
9634 : : *
9635 : : * @return
9636 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9637 : : */
9638 : : static int
9639 : 0 : flow_hw_pattern_template_destroy(struct rte_eth_dev *dev,
9640 : : struct rte_flow_pattern_template *template,
9641 : : struct rte_flow_error *error __rte_unused)
9642 : : {
9643 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9644 : :
9645 [ # # ]: 0 : if (rte_atomic_load_explicit(&template->refcnt, rte_memory_order_relaxed) > 1) {
9646 : 0 : DRV_LOG(WARNING, "Item template %p is still in use.",
9647 : : (void *)template);
9648 : 0 : return rte_flow_error_set(error, EBUSY,
9649 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9650 : : NULL,
9651 : : "item template is in use");
9652 : : }
9653 [ # # ]: 0 : if (template->item_flags & (MLX5_FLOW_ITEM_OUTER_IPV6_ROUTING_EXT |
9654 : : MLX5_FLOW_ITEM_INNER_IPV6_ROUTING_EXT))
9655 : 0 : mlx5_free_srh_flex_parser(dev);
9656 [ # # ]: 0 : LIST_REMOVE(template, next);
9657 : 0 : flow_hw_flex_item_release(dev, &template->flex_item);
9658 : 0 : mlx5_geneve_tlv_options_unregister(priv, &template->geneve_opt_mng);
9659 : 0 : claim_zero(mlx5dr_match_template_destroy(template->mt));
9660 : 0 : mlx5_free(template->items);
9661 : 0 : mlx5_free(template);
9662 : 0 : return 0;
9663 : : }
9664 : :
9665 : : /*
9666 : : * Get information about HWS pre-configurable resources.
9667 : : *
9668 : : * @param[in] dev
9669 : : * Pointer to the rte_eth_dev structure.
9670 : : * @param[out] port_info
9671 : : * Pointer to port information.
9672 : : * @param[out] queue_info
9673 : : * Pointer to queue information.
9674 : : * @param[out] error
9675 : : * Pointer to error structure.
9676 : : *
9677 : : * @return
9678 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9679 : : */
9680 : : static int
9681 : 0 : flow_hw_info_get(struct rte_eth_dev *dev,
9682 : : struct rte_flow_port_info *port_info,
9683 : : struct rte_flow_queue_info *queue_info,
9684 : : struct rte_flow_error *error __rte_unused)
9685 : : {
9686 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9687 : 0 : uint16_t port_id = dev->data->port_id;
9688 : : struct rte_mtr_capabilities mtr_cap;
9689 : : int ret;
9690 : :
9691 : : memset(port_info, 0, sizeof(*port_info));
9692 : : /* Queue size is unlimited from low-level. */
9693 : 0 : port_info->max_nb_queues = UINT32_MAX;
9694 : 0 : queue_info->max_size = UINT32_MAX;
9695 : :
9696 : : memset(&mtr_cap, 0, sizeof(struct rte_mtr_capabilities));
9697 : 0 : ret = rte_mtr_capabilities_get(port_id, &mtr_cap, NULL);
9698 [ # # ]: 0 : if (!ret)
9699 : 0 : port_info->max_nb_meters = mtr_cap.n_max;
9700 : 0 : port_info->max_nb_counters = priv->sh->hws_max_nb_counters;
9701 : 0 : port_info->max_nb_aging_objects = port_info->max_nb_counters;
9702 : 0 : return 0;
9703 : : }
9704 : :
9705 : : /**
9706 : : * Create group callback.
9707 : : *
9708 : : * @param[in] tool_ctx
9709 : : * Pointer to the hash list related context.
9710 : : * @param[in] cb_ctx
9711 : : * Pointer to the group creation context.
9712 : : *
9713 : : * @return
9714 : : * Group entry on success, NULL otherwise and rte_errno is set.
9715 : : */
9716 : : struct mlx5_list_entry *
9717 : 0 : mlx5_flow_hw_grp_create_cb(void *tool_ctx, void *cb_ctx)
9718 : : {
9719 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
9720 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9721 : 0 : struct rte_eth_dev *dev = ctx->dev;
9722 : 0 : struct rte_flow_attr *attr = (struct rte_flow_attr *)ctx->data;
9723 : 0 : uint32_t *specialize = (uint32_t *)ctx->data2;
9724 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
9725 : : bool unified_fdb = is_unified_fdb(priv);
9726 : 0 : struct mlx5dr_table_attr dr_tbl_attr = {0};
9727 : 0 : struct rte_flow_error *error = ctx->error;
9728 : : struct mlx5_flow_group *grp_data;
9729 : : struct mlx5dr_table *tbl = NULL;
9730 : : struct mlx5dr_action *jump;
9731 : : uint32_t hws_flags;
9732 : 0 : uint32_t idx = 0;
9733 [ # # # # : 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
# # # # ]
9734 : : attr->transfer ? "FDB" : "NIC", attr->egress ? "egress" : "ingress",
9735 : : attr->group, idx);
9736 : :
9737 : 0 : grp_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_HW_GRP], &idx);
9738 [ # # ]: 0 : if (!grp_data) {
9739 : 0 : rte_flow_error_set(error, ENOMEM,
9740 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9741 : : NULL,
9742 : : "cannot allocate flow table data entry");
9743 : 0 : return NULL;
9744 : : }
9745 : 0 : dr_tbl_attr.level = attr->group;
9746 : 0 : dr_tbl_attr.type = get_mlx5dr_table_type(attr, *specialize, unified_fdb);
9747 : 0 : tbl = mlx5dr_table_create(priv->dr_ctx, &dr_tbl_attr);
9748 [ # # ]: 0 : if (!tbl)
9749 : 0 : goto error;
9750 : 0 : grp_data->tbl = tbl;
9751 [ # # ]: 0 : if (attr->group) {
9752 : 0 : hws_flags = mlx5_hw_act_dest_table_flag[dr_tbl_attr.type];
9753 : : /* For case of jump from FDB Tx to FDB Rx as it is supported now. */
9754 [ # # # # ]: 0 : if (priv->jump_fdb_rx_en &&
9755 : : dr_tbl_attr.type == MLX5DR_TABLE_TYPE_FDB_RX)
9756 : 0 : hws_flags |= MLX5DR_ACTION_FLAG_HWS_FDB_TX;
9757 : : /* Jump action be used by non-root table. */
9758 : 0 : jump = mlx5dr_action_create_dest_table
9759 : : (priv->dr_ctx, tbl,
9760 : : hws_flags);
9761 [ # # ]: 0 : if (!jump)
9762 : 0 : goto error;
9763 : 0 : grp_data->jump.hws_action = jump;
9764 : : /* Jump action be used by root table. */
9765 : 0 : jump = mlx5dr_action_create_dest_table
9766 : : (priv->dr_ctx, tbl,
9767 : : mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_ROOT]
9768 : 0 : [dr_tbl_attr.type]);
9769 [ # # ]: 0 : if (!jump)
9770 : 0 : goto error;
9771 : 0 : grp_data->jump.root_action = jump;
9772 : : }
9773 : :
9774 : 0 : grp_data->matchers = mlx5_list_create(matcher_name, sh, true,
9775 : : mlx5_flow_matcher_create_cb,
9776 : : mlx5_flow_matcher_match_cb,
9777 : : mlx5_flow_matcher_remove_cb,
9778 : : mlx5_flow_matcher_clone_cb,
9779 : : mlx5_flow_matcher_clone_free_cb);
9780 : 0 : grp_data->dev = dev;
9781 : 0 : grp_data->idx = idx;
9782 : 0 : grp_data->group_id = attr->group;
9783 : 0 : grp_data->type = dr_tbl_attr.type;
9784 : 0 : return &grp_data->entry;
9785 : 0 : error:
9786 [ # # ]: 0 : if (grp_data->jump.root_action)
9787 : 0 : mlx5dr_action_destroy(grp_data->jump.root_action);
9788 [ # # ]: 0 : if (grp_data->jump.hws_action)
9789 : 0 : mlx5dr_action_destroy(grp_data->jump.hws_action);
9790 [ # # ]: 0 : if (tbl)
9791 : 0 : mlx5dr_table_destroy(tbl);
9792 [ # # ]: 0 : if (idx)
9793 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_HW_GRP], idx);
9794 : 0 : rte_flow_error_set(error, ENOMEM,
9795 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9796 : : NULL,
9797 : : "cannot allocate flow dr table");
9798 : 0 : return NULL;
9799 : : }
9800 : :
9801 : : /**
9802 : : * Remove group callback.
9803 : : *
9804 : : * @param[in] tool_ctx
9805 : : * Pointer to the hash list related context.
9806 : : * @param[in] entry
9807 : : * Pointer to the entry to be removed.
9808 : : */
9809 : : void
9810 : 0 : mlx5_flow_hw_grp_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
9811 : : {
9812 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
9813 : : struct mlx5_flow_group *grp_data =
9814 : : container_of(entry, struct mlx5_flow_group, entry);
9815 : :
9816 : : MLX5_ASSERT(entry && sh);
9817 : : /* To use the wrapper glue functions instead. */
9818 [ # # ]: 0 : if (grp_data->jump.hws_action)
9819 : 0 : mlx5dr_action_destroy(grp_data->jump.hws_action);
9820 [ # # ]: 0 : if (grp_data->jump.root_action)
9821 : 0 : mlx5dr_action_destroy(grp_data->jump.root_action);
9822 : 0 : mlx5_list_destroy(grp_data->matchers);
9823 : 0 : mlx5dr_table_destroy(grp_data->tbl);
9824 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_HW_GRP], grp_data->idx);
9825 : 0 : }
9826 : :
9827 : : /**
9828 : : * Match group callback.
9829 : : *
9830 : : * @param[in] tool_ctx
9831 : : * Pointer to the hash list related context.
9832 : : * @param[in] entry
9833 : : * Pointer to the group to be matched.
9834 : : * @param[in] cb_ctx
9835 : : * Pointer to the group matching context.
9836 : : *
9837 : : * @return
9838 : : * 0 on matched, 1 on miss matched.
9839 : : */
9840 : : int
9841 : 0 : mlx5_flow_hw_grp_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
9842 : : void *cb_ctx)
9843 : : {
9844 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9845 : : struct mlx5_flow_group *grp_data =
9846 : : container_of(entry, struct mlx5_flow_group, entry);
9847 : 0 : struct rte_flow_attr *attr =
9848 : : (struct rte_flow_attr *)ctx->data;
9849 : :
9850 : 0 : return (grp_data->dev != ctx->dev) ||
9851 [ # # ]: 0 : (grp_data->group_id != attr->group) ||
9852 [ # # # # ]: 0 : ((grp_data->type < MLX5DR_TABLE_TYPE_FDB) &&
9853 [ # # ]: 0 : attr->transfer) ||
9854 [ # # ]: 0 : ((grp_data->type != MLX5DR_TABLE_TYPE_NIC_TX) &&
9855 [ # # # # ]: 0 : attr->egress) ||
9856 [ # # ]: 0 : ((grp_data->type != MLX5DR_TABLE_TYPE_NIC_RX) &&
9857 : : attr->ingress);
9858 : : }
9859 : :
9860 : : /**
9861 : : * Clone group entry callback.
9862 : : *
9863 : : * @param[in] tool_ctx
9864 : : * Pointer to the hash list related context.
9865 : : * @param[in] entry
9866 : : * Pointer to the group to be matched.
9867 : : * @param[in] cb_ctx
9868 : : * Pointer to the group matching context.
9869 : : *
9870 : : * @return
9871 : : * 0 on matched, 1 on miss matched.
9872 : : */
9873 : : struct mlx5_list_entry *
9874 : 0 : mlx5_flow_hw_grp_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
9875 : : void *cb_ctx)
9876 : : {
9877 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
9878 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9879 : : struct mlx5_flow_group *grp_data;
9880 : : struct mlx5_flow_group *old_grp_data;
9881 : 0 : struct rte_flow_error *error = ctx->error;
9882 : 0 : uint32_t idx = 0;
9883 : :
9884 : 0 : grp_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_HW_GRP], &idx);
9885 [ # # ]: 0 : if (!grp_data) {
9886 : 0 : rte_flow_error_set(error, ENOMEM,
9887 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9888 : : NULL,
9889 : : "cannot allocate flow table data entry");
9890 : 0 : return NULL;
9891 : : }
9892 : : old_grp_data = container_of(oentry, typeof(*old_grp_data), entry);
9893 : : memcpy(grp_data, old_grp_data, sizeof(*grp_data));
9894 : 0 : grp_data->idx = idx;
9895 : 0 : return &grp_data->entry;
9896 : : }
9897 : :
9898 : : /**
9899 : : * Free cloned group entry callback.
9900 : : *
9901 : : * @param[in] tool_ctx
9902 : : * Pointer to the hash list related context.
9903 : : * @param[in] entry
9904 : : * Pointer to the group to be freed.
9905 : : */
9906 : : void
9907 : 0 : mlx5_flow_hw_grp_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
9908 : : {
9909 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
9910 : : struct mlx5_flow_group *grp_data =
9911 : : container_of(entry, struct mlx5_flow_group, entry);
9912 : :
9913 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_HW_GRP], grp_data->idx);
9914 : 0 : }
9915 : :
9916 : : /**
9917 : : * Create and cache a vport action for given @p dev port. vport actions
9918 : : * cache is used in HWS with FDB flows.
9919 : : *
9920 : : * This function does not create any function if proxy port for @p dev port
9921 : : * was not configured for HW Steering.
9922 : : *
9923 : : * This function assumes that E-Switch is enabled and PMD is running with
9924 : : * HW Steering configured.
9925 : : *
9926 : : * @param dev
9927 : : * Pointer to Ethernet device which will be the action destination.
9928 : : *
9929 : : * @return
9930 : : * 0 on success, positive value otherwise.
9931 : : */
9932 : : int
9933 : 0 : mlx5_flow_hw_create_vport_action(struct rte_eth_dev *dev)
9934 : : {
9935 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9936 : : struct rte_eth_dev *proxy_dev;
9937 : : struct mlx5_priv *proxy_priv;
9938 : 0 : uint16_t port_id = dev->data->port_id;
9939 : 0 : uint16_t proxy_port_id = port_id;
9940 : : int ret;
9941 : :
9942 : 0 : ret = mlx5_flow_pick_transfer_proxy(dev, &proxy_port_id, NULL);
9943 [ # # ]: 0 : if (ret)
9944 : : return ret;
9945 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
9946 : 0 : proxy_priv = proxy_dev->data->dev_private;
9947 [ # # ]: 0 : if (!proxy_priv->hw_vport)
9948 : : return 0;
9949 [ # # ]: 0 : if (proxy_priv->hw_vport[port_id]) {
9950 : 0 : DRV_LOG(ERR, "port %u HWS vport action already created",
9951 : : port_id);
9952 : 0 : return -EINVAL;
9953 : : }
9954 [ # # ]: 0 : proxy_priv->hw_vport[port_id] = mlx5dr_action_create_dest_vport
9955 : : (proxy_priv->dr_ctx, priv->dev_port,
9956 : : is_unified_fdb(priv) ?
9957 : : (MLX5DR_ACTION_FLAG_HWS_FDB_RX |
9958 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
9959 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) :
9960 : : MLX5DR_ACTION_FLAG_HWS_FDB);
9961 [ # # ]: 0 : if (!proxy_priv->hw_vport[port_id]) {
9962 : 0 : DRV_LOG(ERR, "port %u unable to create HWS vport action",
9963 : : port_id);
9964 : 0 : return -EINVAL;
9965 : : }
9966 : : return 0;
9967 : : }
9968 : :
9969 : : /**
9970 : : * Destroys the vport action associated with @p dev device
9971 : : * from actions' cache.
9972 : : *
9973 : : * This function does not destroy any action if there is no action cached
9974 : : * for @p dev or proxy port was not configured for HW Steering.
9975 : : *
9976 : : * This function assumes that E-Switch is enabled and PMD is running with
9977 : : * HW Steering configured.
9978 : : *
9979 : : * @param dev
9980 : : * Pointer to Ethernet device which will be the action destination.
9981 : : */
9982 : : void
9983 : 0 : mlx5_flow_hw_destroy_vport_action(struct rte_eth_dev *dev)
9984 : : {
9985 : : struct rte_eth_dev *proxy_dev;
9986 : : struct mlx5_priv *proxy_priv;
9987 : 0 : uint16_t port_id = dev->data->port_id;
9988 : 0 : uint16_t proxy_port_id = port_id;
9989 : :
9990 [ # # ]: 0 : if (mlx5_flow_pick_transfer_proxy(dev, &proxy_port_id, NULL))
9991 : 0 : return;
9992 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
9993 : 0 : proxy_priv = proxy_dev->data->dev_private;
9994 [ # # # # ]: 0 : if (!proxy_priv->hw_vport || !proxy_priv->hw_vport[port_id])
9995 : : return;
9996 : 0 : mlx5dr_action_destroy(proxy_priv->hw_vport[port_id]);
9997 : 0 : proxy_priv->hw_vport[port_id] = NULL;
9998 : : }
9999 : :
10000 : : static int
10001 : 0 : flow_hw_create_vport_actions(struct mlx5_priv *priv)
10002 : : {
10003 : : uint16_t port_id;
10004 : :
10005 : : MLX5_ASSERT(!priv->hw_vport);
10006 : : bool unified_fdb = is_unified_fdb(priv);
10007 : 0 : priv->hw_vport = mlx5_malloc(MLX5_MEM_ZERO,
10008 : : sizeof(*priv->hw_vport) * RTE_MAX_ETHPORTS,
10009 : : 0, SOCKET_ID_ANY);
10010 [ # # ]: 0 : if (!priv->hw_vport)
10011 : : return -ENOMEM;
10012 : 0 : DRV_LOG(DEBUG, "port %u :: creating vport actions", priv->dev_data->port_id);
10013 : 0 : DRV_LOG(DEBUG, "port %u :: domain_id=%u", priv->dev_data->port_id, priv->domain_id);
10014 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
10015 : 0 : struct mlx5_priv *port_priv = rte_eth_devices[port_id].data->dev_private;
10016 : :
10017 [ # # ]: 0 : if (!port_priv ||
10018 [ # # ]: 0 : port_priv->domain_id != priv->domain_id)
10019 : 0 : continue;
10020 : 0 : DRV_LOG(DEBUG, "port %u :: for port_id=%u, calling mlx5dr_action_create_dest_vport() with ibport=%u",
10021 : : priv->dev_data->port_id, port_id, port_priv->dev_port);
10022 [ # # ]: 0 : priv->hw_vport[port_id] = mlx5dr_action_create_dest_vport
10023 : : (priv->dr_ctx, port_priv->dev_port,
10024 : : unified_fdb ?
10025 : : (MLX5DR_ACTION_FLAG_HWS_FDB_RX |
10026 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
10027 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) :
10028 : : MLX5DR_ACTION_FLAG_HWS_FDB);
10029 : 0 : DRV_LOG(DEBUG, "port %u :: priv->hw_vport[%u]=%p",
10030 : : priv->dev_data->port_id, port_id, (void *)priv->hw_vport[port_id]);
10031 [ # # ]: 0 : if (!priv->hw_vport[port_id])
10032 : : return -EINVAL;
10033 : : }
10034 : : return 0;
10035 : : }
10036 : :
10037 : : static void
10038 : 0 : flow_hw_free_vport_actions(struct mlx5_priv *priv)
10039 : : {
10040 : : uint16_t port_id;
10041 : :
10042 [ # # ]: 0 : if (!priv->hw_vport)
10043 : : return;
10044 [ # # ]: 0 : for (port_id = 0; port_id < RTE_MAX_ETHPORTS; ++port_id)
10045 [ # # ]: 0 : if (priv->hw_vport[port_id])
10046 : 0 : mlx5dr_action_destroy(priv->hw_vport[port_id]);
10047 : 0 : mlx5_free(priv->hw_vport);
10048 : 0 : priv->hw_vport = NULL;
10049 : : }
10050 : :
10051 : : static bool
10052 : : flow_hw_should_create_nat64_actions(struct mlx5_priv *priv)
10053 : : {
10054 : : int i;
10055 : :
10056 : : /* Check if all registers are available. */
10057 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_NAT64_REGS_MAX; ++i)
10058 [ # # ]: 0 : if (priv->sh->registers.nat64_regs[i] == REG_NON)
10059 : : return false;
10060 : :
10061 : : return true;
10062 : : }
10063 : :
10064 : : /**
10065 : : * Create an egress pattern template matching on source SQ.
10066 : : *
10067 : : * @param dev
10068 : : * Pointer to Ethernet device.
10069 : : * @param[out] error
10070 : : * Pointer to error structure.
10071 : : *
10072 : : * @return
10073 : : * Pointer to pattern template on success. NULL otherwise, and rte_errno is set.
10074 : : */
10075 : : static struct rte_flow_pattern_template *
10076 : 0 : flow_hw_create_tx_repr_sq_pattern_tmpl(struct rte_eth_dev *dev, struct rte_flow_error *error)
10077 : : {
10078 : 0 : struct rte_flow_pattern_template_attr attr = {
10079 : : .relaxed_matching = 0,
10080 : : .egress = 1,
10081 : : };
10082 : 0 : struct mlx5_rte_flow_item_sq sq_mask = {
10083 : : .queue = UINT32_MAX,
10084 : : };
10085 : 0 : struct rte_flow_item items[] = {
10086 : : {
10087 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
10088 : : .mask = &sq_mask,
10089 : : },
10090 : : {
10091 : : .type = RTE_FLOW_ITEM_TYPE_END,
10092 : : },
10093 : : };
10094 : :
10095 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, false, error);
10096 : : }
10097 : :
10098 : : static __rte_always_inline uint32_t
10099 : : flow_hw_tx_tag_regc_mask(struct rte_eth_dev *dev)
10100 : : {
10101 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10102 : :
10103 [ # # ]: 0 : if (priv->vport_meta_mask != 0)
10104 : 0 : return priv->sh->dv_regc0_mask;
10105 : : else
10106 : : return UINT32_MAX;
10107 : : }
10108 : :
10109 : : static __rte_always_inline uint32_t
10110 : : flow_hw_tx_tag_regc_value(struct rte_eth_dev *dev)
10111 : : {
10112 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10113 : :
10114 [ # # # # : 0 : if (priv->vport_meta_mask != 0)
# # ]
10115 : 0 : return priv->vport_meta_tag >> (rte_bsf32(priv->vport_meta_mask));
10116 : :
10117 : : /* Without REG_C match value available, resort to matching vport ID. */
10118 : 0 : return priv->vport_id | (priv->sh->cdev->config.hca_attr.vhca_id << 16);
10119 : : }
10120 : :
10121 : : static void
10122 : : flow_hw_update_action_mask(struct rte_flow_action *action,
10123 : : struct rte_flow_action *mask,
10124 : : enum rte_flow_action_type type,
10125 : : void *conf_v,
10126 : : void *conf_m)
10127 : : {
10128 : 0 : action->type = type;
10129 : 0 : action->conf = conf_v;
10130 : 0 : mask->type = type;
10131 : 0 : mask->conf = conf_m;
10132 : : }
10133 : :
10134 : : /**
10135 : : * Create an egress actions template with MODIFY_FIELD action for setting unused REG_C_0 bits
10136 : : * to vport tag and JUMP action to group 1.
10137 : : *
10138 : : * If extended metadata mode is enabled, then MODIFY_FIELD action for copying software metadata
10139 : : * to REG_C_1 is added as well.
10140 : : *
10141 : : * @param dev
10142 : : * Pointer to Ethernet device.
10143 : : * @param[out] error
10144 : : * Pointer to error structure.
10145 : : *
10146 : : * @return
10147 : : * Pointer to actions template on success. NULL otherwise, and rte_errno is set.
10148 : : */
10149 : : static struct rte_flow_actions_template *
10150 [ # # ]: 0 : flow_hw_create_tx_repr_tag_jump_acts_tmpl(struct rte_eth_dev *dev,
10151 : : struct rte_flow_error *error)
10152 : : {
10153 : : uint32_t tag_mask = flow_hw_tx_tag_regc_mask(dev);
10154 : : uint32_t tag_value = flow_hw_tx_tag_regc_value(dev);
10155 : 0 : struct rte_flow_actions_template_attr attr = {
10156 : : .egress = 1,
10157 : : };
10158 [ # # ]: 0 : struct rte_flow_action_modify_field set_tag_v = {
10159 : : .operation = RTE_FLOW_MODIFY_SET,
10160 : : .dst = {
10161 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10162 : : .tag_index = REG_C_0,
10163 : : .offset = rte_bsf32(tag_mask),
10164 : : },
10165 : : .src = {
10166 : : .field = RTE_FLOW_FIELD_VALUE,
10167 : : },
10168 : : .width = rte_popcount32(tag_mask),
10169 : : };
10170 : 0 : struct rte_flow_action_modify_field set_tag_m = {
10171 : : .operation = RTE_FLOW_MODIFY_SET,
10172 : : .dst = {
10173 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10174 : : .level = UINT8_MAX,
10175 : : .tag_index = UINT8_MAX,
10176 : : .offset = UINT32_MAX,
10177 : : },
10178 : : .src = {
10179 : : .field = RTE_FLOW_FIELD_VALUE,
10180 : : },
10181 : : .width = UINT32_MAX,
10182 : : };
10183 : 0 : struct rte_flow_action_modify_field copy_metadata_v = {
10184 : : .operation = RTE_FLOW_MODIFY_SET,
10185 : : .dst = {
10186 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10187 : : .tag_index = REG_C_1,
10188 : : },
10189 : : .src = {
10190 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10191 : : .tag_index = REG_A,
10192 : : },
10193 : : .width = 32,
10194 : : };
10195 : 0 : struct rte_flow_action_modify_field copy_metadata_m = {
10196 : : .operation = RTE_FLOW_MODIFY_SET,
10197 : : .dst = {
10198 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10199 : : .level = UINT8_MAX,
10200 : : .tag_index = UINT8_MAX,
10201 : : .offset = UINT32_MAX,
10202 : : },
10203 : : .src = {
10204 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10205 : : .level = UINT8_MAX,
10206 : : .tag_index = UINT8_MAX,
10207 : : .offset = UINT32_MAX,
10208 : : },
10209 : : .width = UINT32_MAX,
10210 : : };
10211 : 0 : struct rte_flow_action_jump jump_v = {
10212 : : .group = MLX5_HW_LOWEST_USABLE_GROUP,
10213 : : };
10214 : 0 : struct rte_flow_action_jump jump_m = {
10215 : : .group = UINT32_MAX,
10216 : : };
10217 : 0 : struct rte_flow_action actions_v[4] = { { 0 } };
10218 [ # # ]: 0 : struct rte_flow_action actions_m[4] = { { 0 } };
10219 : : unsigned int idx = 0;
10220 : :
10221 : : rte_memcpy(set_tag_v.src.value, &tag_value, sizeof(tag_value));
10222 : : rte_memcpy(set_tag_m.src.value, &tag_mask, sizeof(tag_mask));
10223 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx],
10224 : : RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
10225 : : &set_tag_v, &set_tag_m);
10226 : : idx++;
10227 [ # # ]: 0 : if (MLX5_SH(dev)->config.dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
10228 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx],
10229 : : RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
10230 : : ©_metadata_v, ©_metadata_m);
10231 : : idx++;
10232 : : }
10233 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx], RTE_FLOW_ACTION_TYPE_JUMP,
10234 : : &jump_v, &jump_m);
10235 : 0 : idx++;
10236 : : flow_hw_update_action_mask(&actions_v[idx], &actions_m[idx], RTE_FLOW_ACTION_TYPE_END,
10237 : : NULL, NULL);
10238 : : idx++;
10239 : : MLX5_ASSERT(idx <= RTE_DIM(actions_v));
10240 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v, actions_m, error);
10241 : : }
10242 : :
10243 : : static void
10244 : 0 : flow_hw_cleanup_tx_repr_tagging(struct rte_eth_dev *dev)
10245 : : {
10246 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10247 : :
10248 [ # # ]: 0 : if (priv->hw_tx_repr_tagging_tbl) {
10249 : 0 : flow_hw_table_destroy(dev, priv->hw_tx_repr_tagging_tbl, NULL);
10250 : 0 : priv->hw_tx_repr_tagging_tbl = NULL;
10251 : : }
10252 [ # # ]: 0 : if (priv->hw_tx_repr_tagging_at) {
10253 : 0 : flow_hw_actions_template_destroy(dev, priv->hw_tx_repr_tagging_at, NULL);
10254 : 0 : priv->hw_tx_repr_tagging_at = NULL;
10255 : : }
10256 [ # # ]: 0 : if (priv->hw_tx_repr_tagging_pt) {
10257 : 0 : flow_hw_pattern_template_destroy(dev, priv->hw_tx_repr_tagging_pt, NULL);
10258 : 0 : priv->hw_tx_repr_tagging_pt = NULL;
10259 : : }
10260 : 0 : }
10261 : :
10262 : : /**
10263 : : * Setup templates and table used to create default Tx flow rules. These default rules
10264 : : * allow for matching Tx representor traffic using a vport tag placed in unused bits of
10265 : : * REG_C_0 register.
10266 : : *
10267 : : * @param dev
10268 : : * Pointer to Ethernet device.
10269 : : * @param[out] error
10270 : : * Pointer to error structure.
10271 : : *
10272 : : * @return
10273 : : * 0 on success, negative errno value otherwise.
10274 : : */
10275 : : static int
10276 : 0 : flow_hw_setup_tx_repr_tagging(struct rte_eth_dev *dev, struct rte_flow_error *error)
10277 : : {
10278 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10279 : 0 : struct rte_flow_template_table_attr attr = {
10280 : : .flow_attr = {
10281 : : .group = 0,
10282 : : .priority = MLX5_HW_LOWEST_PRIO_ROOT,
10283 : : .egress = 1,
10284 : : },
10285 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
10286 : : };
10287 : 0 : struct mlx5_flow_template_table_cfg cfg = {
10288 : : .attr = attr,
10289 : : .external = false,
10290 : : };
10291 : :
10292 : : MLX5_ASSERT(priv->sh->config.dv_esw_en);
10293 : 0 : priv->hw_tx_repr_tagging_pt =
10294 : 0 : flow_hw_create_tx_repr_sq_pattern_tmpl(dev, error);
10295 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_pt)
10296 : 0 : goto err;
10297 : 0 : priv->hw_tx_repr_tagging_at =
10298 : 0 : flow_hw_create_tx_repr_tag_jump_acts_tmpl(dev, error);
10299 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_at)
10300 : 0 : goto err;
10301 : 0 : priv->hw_tx_repr_tagging_tbl = flow_hw_table_create(dev, &cfg,
10302 : : &priv->hw_tx_repr_tagging_pt, 1,
10303 : : &priv->hw_tx_repr_tagging_at, 1,
10304 : : error);
10305 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_tbl)
10306 : 0 : goto err;
10307 : : return 0;
10308 : 0 : err:
10309 : 0 : flow_hw_cleanup_tx_repr_tagging(dev);
10310 : 0 : return -rte_errno;
10311 : : }
10312 : :
10313 : : static uint32_t
10314 : : flow_hw_esw_mgr_regc_marker_mask(struct rte_eth_dev *dev)
10315 : : {
10316 : 0 : uint32_t mask = MLX5_SH(dev)->dv_regc0_mask;
10317 : :
10318 : : /* Mask is verified during device initialization. */
10319 : : MLX5_ASSERT(mask != 0);
10320 : : return mask;
10321 : : }
10322 : :
10323 : : static uint32_t
10324 : : flow_hw_esw_mgr_regc_marker(struct rte_eth_dev *dev)
10325 : : {
10326 : 0 : uint32_t mask = MLX5_SH(dev)->dv_regc0_mask;
10327 : :
10328 : : /* Mask is verified during device initialization. */
10329 : : MLX5_ASSERT(mask != 0);
10330 : 0 : return RTE_BIT32(rte_bsf32(mask));
10331 : : }
10332 : :
10333 : : /**
10334 : : * Creates a flow pattern template used to match on E-Switch Manager.
10335 : : * This template is used to set up a table for SQ miss default flow.
10336 : : *
10337 : : * @param dev
10338 : : * Pointer to Ethernet device.
10339 : : * @param error
10340 : : * Pointer to error structure.
10341 : : *
10342 : : * @return
10343 : : * Pointer to flow pattern template on success, NULL otherwise.
10344 : : */
10345 : : static struct rte_flow_pattern_template *
10346 : 0 : flow_hw_create_ctrl_esw_mgr_pattern_template(struct rte_eth_dev *dev,
10347 : : struct rte_flow_error *error)
10348 : : {
10349 : 0 : struct rte_flow_pattern_template_attr attr = {
10350 : : .relaxed_matching = 0,
10351 : : .transfer = 1,
10352 : : };
10353 : 0 : struct rte_flow_item_ethdev port_spec = {
10354 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
10355 : : };
10356 : 0 : struct rte_flow_item_ethdev port_mask = {
10357 : : .port_id = UINT16_MAX,
10358 : : };
10359 : 0 : struct mlx5_rte_flow_item_sq sq_mask = {
10360 : : .queue = UINT32_MAX,
10361 : : };
10362 : 0 : struct rte_flow_item items[] = {
10363 : : {
10364 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
10365 : : .spec = &port_spec,
10366 : : .mask = &port_mask,
10367 : : },
10368 : : {
10369 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
10370 : : .mask = &sq_mask,
10371 : : },
10372 : : {
10373 : : .type = RTE_FLOW_ITEM_TYPE_END,
10374 : : },
10375 : : };
10376 : :
10377 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, false, error);
10378 : : }
10379 : :
10380 : : /**
10381 : : * Creates a flow pattern template used to match REG_C_0 and a SQ.
10382 : : * Matching on REG_C_0 is set up to match on all bits usable by user-space.
10383 : : * If traffic was sent from E-Switch Manager, then all usable bits will be set to 0,
10384 : : * except the least significant bit, which will be set to 1.
10385 : : *
10386 : : * This template is used to set up a table for SQ miss default flow.
10387 : : *
10388 : : * @param dev
10389 : : * Pointer to Ethernet device.
10390 : : * @param error
10391 : : * Pointer to error structure.
10392 : : *
10393 : : * @return
10394 : : * Pointer to flow pattern template on success, NULL otherwise.
10395 : : */
10396 : : static struct rte_flow_pattern_template *
10397 : 0 : flow_hw_create_ctrl_regc_sq_pattern_template(struct rte_eth_dev *dev,
10398 : : struct rte_flow_error *error)
10399 : : {
10400 : 0 : struct rte_flow_pattern_template_attr attr = {
10401 : : .relaxed_matching = 0,
10402 : : .transfer = 1,
10403 : : };
10404 : 0 : struct rte_flow_item_tag reg_c0_spec = {
10405 : : .index = (uint8_t)REG_C_0,
10406 : : };
10407 : 0 : struct rte_flow_item_tag reg_c0_mask = {
10408 : : .index = 0xff,
10409 : : .data = flow_hw_esw_mgr_regc_marker_mask(dev),
10410 : : };
10411 : 0 : struct mlx5_rte_flow_item_sq queue_mask = {
10412 : : .queue = UINT32_MAX,
10413 : : };
10414 : 0 : struct rte_flow_item items[] = {
10415 : : {
10416 : : .type = (enum rte_flow_item_type)
10417 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
10418 : : .spec = ®_c0_spec,
10419 : : .mask = ®_c0_mask,
10420 : : },
10421 : : {
10422 : : .type = (enum rte_flow_item_type)
10423 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
10424 : : .mask = &queue_mask,
10425 : : },
10426 : : {
10427 : : .type = RTE_FLOW_ITEM_TYPE_END,
10428 : : },
10429 : : };
10430 : :
10431 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, false, error);
10432 : : }
10433 : :
10434 : : /**
10435 : : * Creates a flow pattern template with unmasked represented port matching.
10436 : : * This template is used to set up a table for default transfer flows
10437 : : * directing packets to group 1.
10438 : : *
10439 : : * @param dev
10440 : : * Pointer to Ethernet device.
10441 : : * @param error
10442 : : * Pointer to error structure.
10443 : : *
10444 : : * @return
10445 : : * Pointer to flow pattern template on success, NULL otherwise.
10446 : : */
10447 : : static struct rte_flow_pattern_template *
10448 : 0 : flow_hw_create_ctrl_port_pattern_template(struct rte_eth_dev *dev,
10449 : : struct rte_flow_error *error)
10450 : : {
10451 : 0 : struct rte_flow_pattern_template_attr attr = {
10452 : : .relaxed_matching = 0,
10453 : : .transfer = 1,
10454 : : };
10455 : 0 : struct rte_flow_item_ethdev port_mask = {
10456 : : .port_id = UINT16_MAX,
10457 : : };
10458 : 0 : struct rte_flow_item items[] = {
10459 : : {
10460 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
10461 : : .mask = &port_mask,
10462 : : },
10463 : : {
10464 : : .type = RTE_FLOW_ITEM_TYPE_END,
10465 : : },
10466 : : };
10467 : :
10468 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, false, error);
10469 : : }
10470 : :
10471 : : /*
10472 : : * Creating a flow pattern template with all LACP packets matching, only for NIC
10473 : : * ingress domain.
10474 : : *
10475 : : * @param dev
10476 : : * Pointer to Ethernet device.
10477 : : * @param error
10478 : : * Pointer to error structure.
10479 : : *
10480 : : * @return
10481 : : * Pointer to flow pattern template on success, NULL otherwise.
10482 : : */
10483 : : static struct rte_flow_pattern_template *
10484 : 0 : flow_hw_create_lacp_rx_pattern_template(struct rte_eth_dev *dev, struct rte_flow_error *error)
10485 : : {
10486 : 0 : struct rte_flow_pattern_template_attr pa_attr = {
10487 : : .relaxed_matching = 0,
10488 : : .ingress = 1,
10489 : : };
10490 : 0 : struct rte_flow_item_eth lacp_mask = {
10491 : : .dst.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
10492 : : .src.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
10493 : : .type = 0xFFFF,
10494 : : };
10495 : 0 : struct rte_flow_item eth_all[] = {
10496 : : [0] = {
10497 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
10498 : : .mask = &lacp_mask,
10499 : : },
10500 : : [1] = {
10501 : : .type = RTE_FLOW_ITEM_TYPE_END,
10502 : : },
10503 : : };
10504 : 0 : return flow_hw_pattern_template_create(dev, &pa_attr, eth_all,
10505 : : false, error);
10506 : : }
10507 : :
10508 : : /**
10509 : : * Creates a flow actions template with modify field action and masked jump action.
10510 : : * Modify field action sets the least significant bit of REG_C_0 (usable by user-space)
10511 : : * to 1, meaning that packet was originated from E-Switch Manager. Jump action
10512 : : * transfers steering to group 1.
10513 : : *
10514 : : * @param dev
10515 : : * Pointer to Ethernet device.
10516 : : * @param error
10517 : : * Pointer to error structure.
10518 : : *
10519 : : * @return
10520 : : * Pointer to flow actions template on success, NULL otherwise.
10521 : : */
10522 : : static struct rte_flow_actions_template *
10523 : 0 : flow_hw_create_ctrl_regc_jump_actions_template(struct rte_eth_dev *dev,
10524 : : struct rte_flow_error *error)
10525 : : {
10526 : : uint32_t marker_mask = flow_hw_esw_mgr_regc_marker_mask(dev);
10527 : : uint32_t marker_bits = flow_hw_esw_mgr_regc_marker(dev);
10528 : 0 : struct rte_flow_actions_template_attr attr = {
10529 : : .transfer = 1,
10530 : : };
10531 : 0 : struct rte_flow_action_modify_field set_reg_v = {
10532 : : .operation = RTE_FLOW_MODIFY_SET,
10533 : : .dst = {
10534 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10535 : : .tag_index = REG_C_0,
10536 : : },
10537 : : .src = {
10538 : : .field = RTE_FLOW_FIELD_VALUE,
10539 : : },
10540 : : .width = rte_popcount32(marker_mask),
10541 : : };
10542 : 0 : struct rte_flow_action_modify_field set_reg_m = {
10543 : : .operation = RTE_FLOW_MODIFY_SET,
10544 : : .dst = {
10545 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10546 : : .level = UINT8_MAX,
10547 : : .tag_index = UINT8_MAX,
10548 : : .offset = UINT32_MAX,
10549 : : },
10550 : : .src = {
10551 : : .field = RTE_FLOW_FIELD_VALUE,
10552 : : },
10553 : : .width = UINT32_MAX,
10554 : : };
10555 : 0 : struct rte_flow_action_jump jump_v = {
10556 : : .group = MLX5_HW_LOWEST_USABLE_GROUP,
10557 : : };
10558 : 0 : struct rte_flow_action_jump jump_m = {
10559 : : .group = UINT32_MAX,
10560 : : };
10561 : 0 : struct rte_flow_action actions_v[] = {
10562 : : {
10563 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
10564 : : .conf = &set_reg_v,
10565 : : },
10566 : : {
10567 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10568 : : .conf = &jump_v,
10569 : : },
10570 : : {
10571 : : .type = RTE_FLOW_ACTION_TYPE_END,
10572 : : }
10573 : : };
10574 : 0 : struct rte_flow_action actions_m[] = {
10575 : : {
10576 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
10577 : : .conf = &set_reg_m,
10578 : : },
10579 : : {
10580 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10581 : : .conf = &jump_m,
10582 : : },
10583 : : {
10584 : : .type = RTE_FLOW_ACTION_TYPE_END,
10585 : : }
10586 : : };
10587 : :
10588 : 0 : set_reg_v.dst.offset = rte_bsf32(marker_mask);
10589 : : rte_memcpy(set_reg_v.src.value, &marker_bits, sizeof(marker_bits));
10590 : : rte_memcpy(set_reg_m.src.value, &marker_mask, sizeof(marker_mask));
10591 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v, actions_m, error);
10592 : : }
10593 : :
10594 : : /**
10595 : : * Creates a flow actions template with an unmasked JUMP action. Flows
10596 : : * based on this template will perform a jump to some group. This template
10597 : : * is used to set up tables for control flows.
10598 : : *
10599 : : * @param dev
10600 : : * Pointer to Ethernet device.
10601 : : * @param group
10602 : : * Destination group for this action template.
10603 : : * @param error
10604 : : * Pointer to error structure.
10605 : : *
10606 : : * @return
10607 : : * Pointer to flow actions template on success, NULL otherwise.
10608 : : */
10609 : : static struct rte_flow_actions_template *
10610 : 0 : flow_hw_create_ctrl_jump_actions_template(struct rte_eth_dev *dev,
10611 : : uint32_t group,
10612 : : struct rte_flow_error *error)
10613 : : {
10614 : 0 : struct rte_flow_actions_template_attr attr = {
10615 : : .transfer = 1,
10616 : : };
10617 : 0 : struct rte_flow_action_jump jump_v = {
10618 : : .group = group,
10619 : : };
10620 : 0 : struct rte_flow_action_jump jump_m = {
10621 : : .group = UINT32_MAX,
10622 : : };
10623 : 0 : struct rte_flow_action actions_v[] = {
10624 : : {
10625 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10626 : : .conf = &jump_v,
10627 : : },
10628 : : {
10629 : : .type = RTE_FLOW_ACTION_TYPE_END,
10630 : : }
10631 : : };
10632 : 0 : struct rte_flow_action actions_m[] = {
10633 : : {
10634 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10635 : : .conf = &jump_m,
10636 : : },
10637 : : {
10638 : : .type = RTE_FLOW_ACTION_TYPE_END,
10639 : : }
10640 : : };
10641 : :
10642 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v,
10643 : : actions_m, error);
10644 : : }
10645 : :
10646 : : /**
10647 : : * Creates a flow action template with a unmasked REPRESENTED_PORT action.
10648 : : * It is used to create control flow tables.
10649 : : *
10650 : : * @param dev
10651 : : * Pointer to Ethernet device.
10652 : : * @param error
10653 : : * Pointer to error structure.
10654 : : *
10655 : : * @return
10656 : : * Pointer to flow action template on success, NULL otherwise.
10657 : : */
10658 : : static struct rte_flow_actions_template *
10659 : 0 : flow_hw_create_ctrl_port_actions_template(struct rte_eth_dev *dev,
10660 : : struct rte_flow_error *error)
10661 : : {
10662 : 0 : struct rte_flow_actions_template_attr attr = {
10663 : : .transfer = 1,
10664 : : };
10665 : 0 : struct rte_flow_action_ethdev port_v = {
10666 : : .port_id = 0,
10667 : : };
10668 : 0 : struct rte_flow_action actions_v[] = {
10669 : : {
10670 : : .type = RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
10671 : : .conf = &port_v,
10672 : : },
10673 : : {
10674 : : .type = RTE_FLOW_ACTION_TYPE_END,
10675 : : }
10676 : : };
10677 : 0 : struct rte_flow_action_ethdev port_m = {
10678 : : .port_id = 0,
10679 : : };
10680 : 0 : struct rte_flow_action actions_m[] = {
10681 : : {
10682 : : .type = RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
10683 : : .conf = &port_m,
10684 : : },
10685 : : {
10686 : : .type = RTE_FLOW_ACTION_TYPE_END,
10687 : : }
10688 : : };
10689 : :
10690 : 0 : return flow_hw_actions_template_create(dev, &attr, actions_v, actions_m, error);
10691 : : }
10692 : :
10693 : : /*
10694 : : * Creating an actions template to use header modify action for register
10695 : : * copying. This template is used to set up a table for copy flow.
10696 : : *
10697 : : * @param dev
10698 : : * Pointer to Ethernet device.
10699 : : * @param error
10700 : : * Pointer to error structure.
10701 : : *
10702 : : * @return
10703 : : * Pointer to flow actions template on success, NULL otherwise.
10704 : : */
10705 : : static struct rte_flow_actions_template *
10706 : 0 : flow_hw_create_tx_default_mreg_copy_actions_template(struct rte_eth_dev *dev,
10707 : : struct rte_flow_error *error)
10708 : : {
10709 : 0 : struct rte_flow_actions_template_attr tx_act_attr = {
10710 : : .egress = 1,
10711 : : };
10712 : 0 : const struct rte_flow_action_modify_field mreg_action = {
10713 : : .operation = RTE_FLOW_MODIFY_SET,
10714 : : .dst = {
10715 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10716 : : .tag_index = REG_C_1,
10717 : : },
10718 : : .src = {
10719 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10720 : : .tag_index = REG_A,
10721 : : },
10722 : : .width = 32,
10723 : : };
10724 : 0 : const struct rte_flow_action_modify_field mreg_mask = {
10725 : : .operation = RTE_FLOW_MODIFY_SET,
10726 : : .dst = {
10727 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10728 : : .level = UINT8_MAX,
10729 : : .tag_index = UINT8_MAX,
10730 : : .offset = UINT32_MAX,
10731 : : },
10732 : : .src = {
10733 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
10734 : : .level = UINT8_MAX,
10735 : : .tag_index = UINT8_MAX,
10736 : : .offset = UINT32_MAX,
10737 : : },
10738 : : .width = UINT32_MAX,
10739 : : };
10740 : 0 : const struct rte_flow_action_jump jump_action = {
10741 : : .group = 1,
10742 : : };
10743 : 0 : const struct rte_flow_action_jump jump_mask = {
10744 : : .group = UINT32_MAX,
10745 : : };
10746 : 0 : const struct rte_flow_action actions[] = {
10747 : : [0] = {
10748 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
10749 : : .conf = &mreg_action,
10750 : : },
10751 : : [1] = {
10752 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10753 : : .conf = &jump_action,
10754 : : },
10755 : : [2] = {
10756 : : .type = RTE_FLOW_ACTION_TYPE_END,
10757 : : },
10758 : : };
10759 : 0 : const struct rte_flow_action masks[] = {
10760 : : [0] = {
10761 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
10762 : : .conf = &mreg_mask,
10763 : : },
10764 : : [1] = {
10765 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10766 : : .conf = &jump_mask,
10767 : : },
10768 : : [2] = {
10769 : : .type = RTE_FLOW_ACTION_TYPE_END,
10770 : : },
10771 : : };
10772 : :
10773 : 0 : return flow_hw_actions_template_create(dev, &tx_act_attr, actions,
10774 : : masks, error);
10775 : : }
10776 : :
10777 : : /*
10778 : : * Creating an actions template to use default miss to re-route packets to the
10779 : : * kernel driver stack.
10780 : : * On root table, only DEFAULT_MISS action can be used.
10781 : : *
10782 : : * @param dev
10783 : : * Pointer to Ethernet device.
10784 : : * @param error
10785 : : * Pointer to error structure.
10786 : : *
10787 : : * @return
10788 : : * Pointer to flow actions template on success, NULL otherwise.
10789 : : */
10790 : : static struct rte_flow_actions_template *
10791 : 0 : flow_hw_create_lacp_rx_actions_template(struct rte_eth_dev *dev, struct rte_flow_error *error)
10792 : : {
10793 : 0 : struct rte_flow_actions_template_attr act_attr = {
10794 : : .ingress = 1,
10795 : : };
10796 : 0 : const struct rte_flow_action actions[] = {
10797 : : [0] = {
10798 : : .type = (enum rte_flow_action_type)
10799 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
10800 : : },
10801 : : [1] = {
10802 : : .type = RTE_FLOW_ACTION_TYPE_END,
10803 : : },
10804 : : };
10805 : :
10806 : 0 : return flow_hw_actions_template_create(dev, &act_attr, actions, actions, error);
10807 : : }
10808 : :
10809 : : /**
10810 : : * Creates a control flow table used to transfer traffic from E-Switch Manager
10811 : : * and TX queues from group 0 to group 1.
10812 : : *
10813 : : * @param dev
10814 : : * Pointer to Ethernet device.
10815 : : * @param it
10816 : : * Pointer to flow pattern template.
10817 : : * @param at
10818 : : * Pointer to flow actions template.
10819 : : * @param error
10820 : : * Pointer to error structure.
10821 : : *
10822 : : * @return
10823 : : * Pointer to flow table on success, NULL otherwise.
10824 : : */
10825 : : static struct rte_flow_template_table*
10826 : 0 : flow_hw_create_ctrl_sq_miss_root_table(struct rte_eth_dev *dev,
10827 : : struct rte_flow_pattern_template *it,
10828 : : struct rte_flow_actions_template *at,
10829 : : struct rte_flow_error *error)
10830 : : {
10831 : 0 : struct rte_flow_template_table_attr attr = {
10832 : : .flow_attr = {
10833 : : .group = 0,
10834 : : .priority = MLX5_HW_LOWEST_PRIO_ROOT,
10835 : : .ingress = 0,
10836 : : .egress = 0,
10837 : : .transfer = 1,
10838 : : },
10839 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
10840 : : };
10841 : 0 : struct mlx5_flow_template_table_cfg cfg = {
10842 : : .attr = attr,
10843 : : .external = false,
10844 : : };
10845 : :
10846 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
10847 : : }
10848 : :
10849 : :
10850 : : /**
10851 : : * Creates a control flow table used to transfer traffic from E-Switch Manager
10852 : : * and TX queues from group 0 to group 1.
10853 : : *
10854 : : * @param dev
10855 : : * Pointer to Ethernet device.
10856 : : * @param it
10857 : : * Pointer to flow pattern template.
10858 : : * @param at
10859 : : * Pointer to flow actions template.
10860 : : * @param error
10861 : : * Pointer to error structure.
10862 : : *
10863 : : * @return
10864 : : * Pointer to flow table on success, NULL otherwise.
10865 : : */
10866 : : static struct rte_flow_template_table*
10867 : 0 : flow_hw_create_ctrl_sq_miss_table(struct rte_eth_dev *dev,
10868 : : struct rte_flow_pattern_template *it,
10869 : : struct rte_flow_actions_template *at,
10870 : : struct rte_flow_error *error)
10871 : : {
10872 : 0 : struct rte_flow_template_table_attr attr = {
10873 : : .flow_attr = {
10874 : : .group = 1,
10875 : : .priority = MLX5_HW_LOWEST_PRIO_NON_ROOT,
10876 : : .ingress = 0,
10877 : : .egress = 0,
10878 : : .transfer = 1,
10879 : : },
10880 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
10881 : : };
10882 : 0 : struct mlx5_flow_template_table_cfg cfg = {
10883 : : .attr = attr,
10884 : : .external = false,
10885 : : };
10886 : :
10887 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
10888 : : }
10889 : :
10890 : : /*
10891 : : * Creating the default Tx metadata copy table on NIC Tx group 0.
10892 : : *
10893 : : * @param dev
10894 : : * Pointer to Ethernet device.
10895 : : * @param pt
10896 : : * Pointer to flow pattern template.
10897 : : * @param at
10898 : : * Pointer to flow actions template.
10899 : : * @param error
10900 : : * Pointer to error structure.
10901 : : *
10902 : : * @return
10903 : : * Pointer to flow table on success, NULL otherwise.
10904 : : */
10905 : : static struct rte_flow_template_table*
10906 : 0 : flow_hw_create_tx_default_mreg_copy_table(struct rte_eth_dev *dev,
10907 : : struct rte_flow_pattern_template *pt,
10908 : : struct rte_flow_actions_template *at,
10909 : : struct rte_flow_error *error)
10910 : : {
10911 : 0 : struct rte_flow_template_table_attr tx_tbl_attr = {
10912 : : .flow_attr = {
10913 : : .group = 0, /* Root */
10914 : : .priority = MLX5_HW_LOWEST_PRIO_ROOT,
10915 : : .egress = 1,
10916 : : },
10917 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
10918 : : };
10919 : 0 : struct mlx5_flow_template_table_cfg tx_tbl_cfg = {
10920 : : .attr = tx_tbl_attr,
10921 : : .external = false,
10922 : : };
10923 : :
10924 : 0 : return flow_hw_table_create(dev, &tx_tbl_cfg, &pt, 1, &at, 1, error);
10925 : : }
10926 : :
10927 : : /**
10928 : : * Creates a control flow table used to transfer traffic
10929 : : * from group 0 to group 1.
10930 : : *
10931 : : * @param dev
10932 : : * Pointer to Ethernet device.
10933 : : * @param it
10934 : : * Pointer to flow pattern template.
10935 : : * @param at
10936 : : * Pointer to flow actions template.
10937 : : * @param error
10938 : : * Pointer to error structure.
10939 : : *
10940 : : * @return
10941 : : * Pointer to flow table on success, NULL otherwise.
10942 : : */
10943 : : static struct rte_flow_template_table *
10944 : 0 : flow_hw_create_ctrl_jump_table(struct rte_eth_dev *dev,
10945 : : struct rte_flow_pattern_template *it,
10946 : : struct rte_flow_actions_template *at,
10947 : : struct rte_flow_error *error)
10948 : : {
10949 : 0 : struct rte_flow_template_table_attr attr = {
10950 : : .flow_attr = {
10951 : : .group = 0,
10952 : : .priority = 0,
10953 : : .ingress = 0,
10954 : : .egress = 0,
10955 : : .transfer = 1,
10956 : : },
10957 : : .nb_flows = MLX5_HW_CTRL_FLOW_NB_RULES,
10958 : : };
10959 : 0 : struct mlx5_flow_template_table_cfg cfg = {
10960 : : .attr = attr,
10961 : : .external = false,
10962 : : };
10963 : :
10964 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
10965 : : }
10966 : :
10967 : : /**
10968 : : * Cleans up all template tables and pattern, and actions templates used for
10969 : : * FDB control flow rules.
10970 : : *
10971 : : * @param dev
10972 : : * Pointer to Ethernet device.
10973 : : */
10974 : : static void
10975 : 0 : flow_hw_cleanup_ctrl_fdb_tables(struct rte_eth_dev *dev)
10976 : : {
10977 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10978 : : struct mlx5_flow_hw_ctrl_fdb *hw_ctrl_fdb;
10979 : :
10980 [ # # ]: 0 : if (!priv->hw_ctrl_fdb)
10981 : : return;
10982 : : hw_ctrl_fdb = priv->hw_ctrl_fdb;
10983 : : /* Clean up templates used for default FDB jump rule. */
10984 [ # # ]: 0 : if (hw_ctrl_fdb->hw_esw_zero_tbl)
10985 : 0 : claim_zero(flow_hw_table_destroy(dev, hw_ctrl_fdb->hw_esw_zero_tbl, NULL));
10986 [ # # ]: 0 : if (hw_ctrl_fdb->jump_one_actions_tmpl)
10987 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, hw_ctrl_fdb->jump_one_actions_tmpl,
10988 : : NULL));
10989 [ # # ]: 0 : if (hw_ctrl_fdb->port_items_tmpl)
10990 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, hw_ctrl_fdb->port_items_tmpl,
10991 : : NULL));
10992 : : /* Clean up templates used for default SQ miss flow rules - non-root table. */
10993 [ # # ]: 0 : if (hw_ctrl_fdb->hw_esw_sq_miss_tbl)
10994 : 0 : claim_zero(flow_hw_table_destroy(dev, hw_ctrl_fdb->hw_esw_sq_miss_tbl, NULL));
10995 [ # # ]: 0 : if (hw_ctrl_fdb->regc_sq_items_tmpl)
10996 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, hw_ctrl_fdb->regc_sq_items_tmpl,
10997 : : NULL));
10998 [ # # ]: 0 : if (hw_ctrl_fdb->port_actions_tmpl)
10999 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, hw_ctrl_fdb->port_actions_tmpl,
11000 : : NULL));
11001 : : /* Clean up templates used for default SQ miss flow rules - root table. */
11002 [ # # ]: 0 : if (hw_ctrl_fdb->hw_esw_sq_miss_root_tbl)
11003 : 0 : claim_zero(flow_hw_table_destroy(dev, hw_ctrl_fdb->hw_esw_sq_miss_root_tbl, NULL));
11004 [ # # ]: 0 : if (hw_ctrl_fdb->regc_jump_actions_tmpl)
11005 : 0 : claim_zero(flow_hw_actions_template_destroy(dev,
11006 : : hw_ctrl_fdb->regc_jump_actions_tmpl, NULL));
11007 [ # # ]: 0 : if (hw_ctrl_fdb->esw_mgr_items_tmpl)
11008 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, hw_ctrl_fdb->esw_mgr_items_tmpl,
11009 : : NULL));
11010 : : /* Clean up templates structure for FDB control flow rules. */
11011 : 0 : mlx5_free(hw_ctrl_fdb);
11012 : 0 : priv->hw_ctrl_fdb = NULL;
11013 : : }
11014 : :
11015 : : /*
11016 : : * Create a table on the root group to for the LACP traffic redirecting.
11017 : : *
11018 : : * @param dev
11019 : : * Pointer to Ethernet device.
11020 : : * @param it
11021 : : * Pointer to flow pattern template.
11022 : : * @param at
11023 : : * Pointer to flow actions template.
11024 : : *
11025 : : * @return
11026 : : * Pointer to flow table on success, NULL otherwise.
11027 : : */
11028 : : static struct rte_flow_template_table *
11029 : 0 : flow_hw_create_lacp_rx_table(struct rte_eth_dev *dev,
11030 : : struct rte_flow_pattern_template *it,
11031 : : struct rte_flow_actions_template *at,
11032 : : struct rte_flow_error *error)
11033 : : {
11034 : 0 : struct rte_flow_template_table_attr attr = {
11035 : : .flow_attr = {
11036 : : .group = 0,
11037 : : .priority = 0,
11038 : : .ingress = 1,
11039 : : .egress = 0,
11040 : : .transfer = 0,
11041 : : },
11042 : : .nb_flows = 1,
11043 : : };
11044 : 0 : struct mlx5_flow_template_table_cfg cfg = {
11045 : : .attr = attr,
11046 : : .external = false,
11047 : : };
11048 : :
11049 : 0 : return flow_hw_table_create(dev, &cfg, &it, 1, &at, 1, error);
11050 : : }
11051 : :
11052 : : /*
11053 : : * Clean up templates and table used for redirecting LACP traffic to kernel.
11054 : : *
11055 : : * @param dev
11056 : : * Pointer to Ethernet device.
11057 : : */
11058 : : static void
11059 : 0 : flow_hw_cleanup_lacp_miss_tables(struct rte_eth_dev *dev)
11060 : : {
11061 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11062 : : struct mlx5_flow_hw_lacp_miss *hw_lacp_miss;
11063 : :
11064 [ # # ]: 0 : if (priv->hw_lacp_miss == NULL)
11065 : : return;
11066 : :
11067 : : hw_lacp_miss = priv->hw_lacp_miss;
11068 : :
11069 [ # # ]: 0 : if (hw_lacp_miss->hw_lacp_rx_tbl)
11070 : 0 : claim_zero(flow_hw_table_destroy(dev, hw_lacp_miss->hw_lacp_rx_tbl, NULL));
11071 [ # # ]: 0 : if (hw_lacp_miss->lacp_rx_actions_tmpl)
11072 : 0 : claim_zero(flow_hw_actions_template_destroy(dev,
11073 : : hw_lacp_miss->lacp_rx_actions_tmpl,
11074 : : NULL));
11075 [ # # ]: 0 : if (hw_lacp_miss->lacp_rx_items_tmpl)
11076 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev,
11077 : : hw_lacp_miss->lacp_rx_items_tmpl,
11078 : : NULL));
11079 : :
11080 : 0 : mlx5_free(hw_lacp_miss);
11081 : 0 : priv->hw_lacp_miss = NULL;
11082 : : }
11083 : :
11084 : : /*
11085 : : * Create templates and table for redirecting LACP traffic to kernel.
11086 : : *
11087 : : * LACP traffic redirection is needed whenever LACP bond is managed by the kernel.
11088 : : * Required rule has a following structure:
11089 : : *
11090 : : * - ingress rule on root table
11091 : : * - match EtherType 0x8809
11092 : : * - action DEFAULT_MISS
11093 : : *
11094 : : * @param dev
11095 : : * Pointer to Ethernet device.
11096 : : *
11097 : : * @return
11098 : : * 0 on success. Negative errno otherwise.
11099 : : */
11100 : : static int
11101 : 0 : flow_hw_create_lacp_miss_tables(struct rte_eth_dev *dev)
11102 : : {
11103 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11104 : : struct mlx5_flow_hw_lacp_miss *hw_lacp_miss;
11105 : :
11106 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
11107 : : return 0;
11108 : :
11109 : 0 : hw_lacp_miss = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hw_lacp_miss), 0, SOCKET_ID_ANY);
11110 [ # # ]: 0 : if (!hw_lacp_miss) {
11111 : 0 : DRV_LOG(ERR, "port %u Failed to allocate memory for LACP miss tables",
11112 : : dev->data->port_id);
11113 : 0 : return -ENOMEM;
11114 : : }
11115 : 0 : priv->hw_lacp_miss = hw_lacp_miss;
11116 : :
11117 : 0 : hw_lacp_miss->lacp_rx_items_tmpl = flow_hw_create_lacp_rx_pattern_template(dev, NULL);
11118 [ # # ]: 0 : if (!hw_lacp_miss->lacp_rx_items_tmpl) {
11119 : 0 : DRV_LOG(ERR, "port %u Failed to create pattern template for LACP Rx traffic",
11120 : : dev->data->port_id);
11121 : 0 : goto error;
11122 : : }
11123 : 0 : hw_lacp_miss->lacp_rx_actions_tmpl = flow_hw_create_lacp_rx_actions_template(dev, NULL);
11124 [ # # ]: 0 : if (!hw_lacp_miss->lacp_rx_actions_tmpl) {
11125 : 0 : DRV_LOG(ERR, "port %u Failed to create actions template for LACP Rx traffic",
11126 : : dev->data->port_id);
11127 : 0 : goto error;
11128 : : }
11129 : 0 : hw_lacp_miss->hw_lacp_rx_tbl =
11130 : 0 : flow_hw_create_lacp_rx_table(dev, hw_lacp_miss->lacp_rx_items_tmpl,
11131 : : hw_lacp_miss->lacp_rx_actions_tmpl, NULL);
11132 [ # # ]: 0 : if (!hw_lacp_miss->hw_lacp_rx_tbl) {
11133 : 0 : DRV_LOG(ERR, "port %u Failed to create template table for LACP Rx traffic",
11134 : : dev->data->port_id);
11135 : 0 : goto error;
11136 : : }
11137 : :
11138 : : return 0;
11139 : :
11140 : 0 : error:
11141 : 0 : flow_hw_cleanup_lacp_miss_tables(dev);
11142 : 0 : return -EINVAL;
11143 : : }
11144 : :
11145 : : /**
11146 : : * Creates a set of flow tables used to create control flows used
11147 : : * when E-Switch is engaged.
11148 : : *
11149 : : * @param dev
11150 : : * Pointer to Ethernet device.
11151 : : * @param error
11152 : : * Pointer to error structure.
11153 : : *
11154 : : * @return
11155 : : * 0 on success, negative values otherwise
11156 : : */
11157 : : static int
11158 : 0 : flow_hw_create_fdb_ctrl_tables(struct rte_eth_dev *dev, struct rte_flow_error *error)
11159 : : {
11160 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11161 : : struct mlx5_flow_hw_ctrl_fdb *hw_ctrl_fdb;
11162 : 0 : uint32_t fdb_def_rule = priv->sh->config.fdb_def_rule;
11163 : :
11164 : : MLX5_ASSERT(priv->hw_ctrl_fdb == NULL);
11165 : 0 : hw_ctrl_fdb = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hw_ctrl_fdb), 0, SOCKET_ID_ANY);
11166 [ # # ]: 0 : if (!hw_ctrl_fdb) {
11167 : 0 : DRV_LOG(ERR, "port %u failed to allocate memory for FDB control flow templates",
11168 : : dev->data->port_id);
11169 : 0 : rte_errno = ENOMEM;
11170 : 0 : goto err;
11171 : : }
11172 : 0 : priv->hw_ctrl_fdb = hw_ctrl_fdb;
11173 [ # # ]: 0 : if (fdb_def_rule) {
11174 : : /* Create templates and table for default SQ miss flow rules - root table. */
11175 : 0 : hw_ctrl_fdb->esw_mgr_items_tmpl =
11176 : 0 : flow_hw_create_ctrl_esw_mgr_pattern_template(dev, error);
11177 [ # # ]: 0 : if (!hw_ctrl_fdb->esw_mgr_items_tmpl) {
11178 : 0 : DRV_LOG(ERR, "port %u failed to create E-Switch Manager item"
11179 : : " template for control flows", dev->data->port_id);
11180 : 0 : goto err;
11181 : : }
11182 : 0 : hw_ctrl_fdb->regc_jump_actions_tmpl =
11183 : 0 : flow_hw_create_ctrl_regc_jump_actions_template(dev, error);
11184 [ # # ]: 0 : if (!hw_ctrl_fdb->regc_jump_actions_tmpl) {
11185 : 0 : DRV_LOG(ERR, "port %u failed to create REG_C set and jump action template"
11186 : : " for control flows", dev->data->port_id);
11187 : 0 : goto err;
11188 : : }
11189 : 0 : hw_ctrl_fdb->hw_esw_sq_miss_root_tbl =
11190 : 0 : flow_hw_create_ctrl_sq_miss_root_table
11191 : : (dev, hw_ctrl_fdb->esw_mgr_items_tmpl,
11192 : : hw_ctrl_fdb->regc_jump_actions_tmpl, error);
11193 [ # # ]: 0 : if (!hw_ctrl_fdb->hw_esw_sq_miss_root_tbl) {
11194 : 0 : DRV_LOG(ERR, "port %u failed to create table for default sq miss (root table)"
11195 : : " for control flows", dev->data->port_id);
11196 : 0 : goto err;
11197 : : }
11198 : : /* Create templates and table for default SQ miss flow rules - non-root table. */
11199 : 0 : hw_ctrl_fdb->regc_sq_items_tmpl =
11200 : 0 : flow_hw_create_ctrl_regc_sq_pattern_template(dev, error);
11201 [ # # ]: 0 : if (!hw_ctrl_fdb->regc_sq_items_tmpl) {
11202 : 0 : DRV_LOG(ERR, "port %u failed to create SQ item template for"
11203 : : " control flows", dev->data->port_id);
11204 : 0 : goto err;
11205 : : }
11206 : 0 : hw_ctrl_fdb->port_actions_tmpl =
11207 : 0 : flow_hw_create_ctrl_port_actions_template(dev, error);
11208 [ # # ]: 0 : if (!hw_ctrl_fdb->port_actions_tmpl) {
11209 : 0 : DRV_LOG(ERR, "port %u failed to create port action template"
11210 : : " for control flows", dev->data->port_id);
11211 : 0 : goto err;
11212 : : }
11213 : 0 : hw_ctrl_fdb->hw_esw_sq_miss_tbl =
11214 : 0 : flow_hw_create_ctrl_sq_miss_table
11215 : : (dev, hw_ctrl_fdb->regc_sq_items_tmpl,
11216 : : hw_ctrl_fdb->port_actions_tmpl, error);
11217 [ # # ]: 0 : if (!hw_ctrl_fdb->hw_esw_sq_miss_tbl) {
11218 : 0 : DRV_LOG(ERR, "port %u failed to create table for default sq miss (non-root table)"
11219 : : " for control flows", dev->data->port_id);
11220 : 0 : goto err;
11221 : : }
11222 : : /* Create templates and table for default FDB jump flow rules. */
11223 : 0 : hw_ctrl_fdb->port_items_tmpl =
11224 : 0 : flow_hw_create_ctrl_port_pattern_template(dev, error);
11225 [ # # ]: 0 : if (!hw_ctrl_fdb->port_items_tmpl) {
11226 : 0 : DRV_LOG(ERR, "port %u failed to create SQ item template for"
11227 : : " control flows", dev->data->port_id);
11228 : 0 : goto err;
11229 : : }
11230 : 0 : hw_ctrl_fdb->jump_one_actions_tmpl =
11231 : 0 : flow_hw_create_ctrl_jump_actions_template
11232 : : (dev, MLX5_HW_LOWEST_USABLE_GROUP, error);
11233 [ # # ]: 0 : if (!hw_ctrl_fdb->jump_one_actions_tmpl) {
11234 : 0 : DRV_LOG(ERR, "port %u failed to create jump action template"
11235 : : " for control flows", dev->data->port_id);
11236 : 0 : goto err;
11237 : : }
11238 : 0 : hw_ctrl_fdb->hw_esw_zero_tbl = flow_hw_create_ctrl_jump_table
11239 : : (dev, hw_ctrl_fdb->port_items_tmpl,
11240 : : hw_ctrl_fdb->jump_one_actions_tmpl, error);
11241 [ # # ]: 0 : if (!hw_ctrl_fdb->hw_esw_zero_tbl) {
11242 : 0 : DRV_LOG(ERR, "port %u failed to create table for default jump to group 1"
11243 : : " for control flows", dev->data->port_id);
11244 : 0 : goto err;
11245 : : }
11246 : : }
11247 : : return 0;
11248 : :
11249 : 0 : err:
11250 : 0 : flow_hw_cleanup_ctrl_fdb_tables(dev);
11251 : 0 : return -EINVAL;
11252 : : }
11253 : :
11254 : : static void
11255 : 0 : flow_hw_cleanup_ctrl_nic_tables(struct rte_eth_dev *dev)
11256 : : {
11257 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11258 : 0 : struct mlx5_flow_hw_ctrl_nic *ctrl = priv->hw_ctrl_nic;
11259 : :
11260 [ # # ]: 0 : if (ctrl == NULL)
11261 : : return;
11262 [ # # ]: 0 : if (ctrl->hw_tx_meta_cpy_tbl)
11263 : 0 : claim_zero(flow_hw_table_destroy(dev, ctrl->hw_tx_meta_cpy_tbl, NULL));
11264 [ # # ]: 0 : if (ctrl->tx_meta_items_tmpl != NULL)
11265 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, ctrl->tx_meta_items_tmpl, NULL));
11266 [ # # ]: 0 : if (ctrl->tx_meta_actions_tmpl != NULL)
11267 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, ctrl->tx_meta_actions_tmpl, NULL));
11268 : 0 : mlx5_free(ctrl);
11269 : 0 : priv->hw_ctrl_nic = NULL;
11270 : : }
11271 : :
11272 : : static int
11273 : 0 : flow_hw_create_nic_ctrl_tables(struct rte_eth_dev *dev, struct rte_flow_error *error)
11274 : : {
11275 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11276 : :
11277 : 0 : struct mlx5_flow_hw_ctrl_nic *ctrl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ctrl),
11278 : : 0, SOCKET_ID_ANY);
11279 [ # # ]: 0 : if (!ctrl)
11280 : 0 : return rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11281 : : "failed to allocate port control flow table");
11282 : 0 : priv->hw_ctrl_nic = ctrl;
11283 : 0 : ctrl->tx_meta_items_tmpl = flow_hw_create_tx_repr_sq_pattern_tmpl(dev, error);
11284 [ # # ]: 0 : if (ctrl->tx_meta_items_tmpl == NULL)
11285 : 0 : goto error;
11286 : 0 : ctrl->tx_meta_actions_tmpl =
11287 : 0 : flow_hw_create_tx_default_mreg_copy_actions_template(dev, error);
11288 [ # # ]: 0 : if (ctrl->tx_meta_actions_tmpl == NULL) {
11289 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11290 : : "failed to create default Tx metadata copy actions template");
11291 : 0 : goto error;
11292 : : }
11293 : 0 : ctrl->hw_tx_meta_cpy_tbl =
11294 : 0 : flow_hw_create_tx_default_mreg_copy_table(dev, ctrl->tx_meta_items_tmpl,
11295 : : ctrl->tx_meta_actions_tmpl, error);
11296 [ # # ]: 0 : if (ctrl->hw_tx_meta_cpy_tbl == NULL) {
11297 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11298 : : "failed to create default Tx metadata copy table");
11299 : : }
11300 : : return 0;
11301 : :
11302 : 0 : error:
11303 : 0 : flow_hw_cleanup_ctrl_nic_tables(dev);
11304 : 0 : return -rte_errno;
11305 : : }
11306 : :
11307 : : static void
11308 : : flow_hw_ct_mng_destroy(struct mlx5_aso_ct_pools_mng *ct_mng)
11309 : : {
11310 : 0 : mlx5_aso_ct_queue_uninit(ct_mng);
11311 : 0 : mlx5_free(ct_mng);
11312 : : }
11313 : :
11314 : : static void
11315 : 0 : flow_hw_ct_pool_destroy(struct rte_eth_dev *dev,
11316 : : struct mlx5_aso_ct_pool *pool)
11317 : : {
11318 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11319 : :
11320 [ # # ]: 0 : if (pool->dr_action)
11321 : 0 : mlx5dr_action_destroy(pool->dr_action);
11322 [ # # ]: 0 : if (!priv->shared_host) {
11323 [ # # ]: 0 : if (pool->devx_obj)
11324 : 0 : claim_zero(mlx5_devx_cmd_destroy(pool->devx_obj));
11325 [ # # ]: 0 : if (pool->cts)
11326 : 0 : mlx5_ipool_destroy(pool->cts);
11327 : : }
11328 : 0 : mlx5_free(pool);
11329 : 0 : }
11330 : :
11331 : : static struct mlx5_aso_ct_pool *
11332 : 0 : flow_hw_ct_pool_create(struct rte_eth_dev *dev,
11333 : : uint32_t nb_conn_tracks)
11334 : : {
11335 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
11336 : : struct mlx5_aso_ct_pool *pool;
11337 : : struct mlx5_devx_obj *obj;
11338 : : uint32_t nb_cts = rte_align32pow2(nb_conn_tracks);
11339 : : uint32_t log_obj_size = rte_log2_u32(nb_cts);
11340 : 0 : struct mlx5_indexed_pool_config cfg = {
11341 : : .size = sizeof(struct mlx5_aso_ct_action),
11342 : : .trunk_size = 1 << 12,
11343 : : .per_core_cache = 1 << 13,
11344 : : .need_lock = 1,
11345 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
11346 : : .malloc = mlx5_malloc,
11347 : : .free = mlx5_free,
11348 : : .type = "mlx5_hw_ct_action",
11349 : : };
11350 : : int reg_id;
11351 : : uint32_t flags = 0;
11352 : :
11353 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11354 [ # # ]: 0 : if (!pool) {
11355 : 0 : rte_errno = ENOMEM;
11356 : 0 : return NULL;
11357 : : }
11358 [ # # ]: 0 : if (!priv->shared_host) {
11359 : : /*
11360 : : * No need for local cache if CT number is a small number. Since
11361 : : * flow insertion rate will be very limited in that case. Here let's
11362 : : * set the number to less than default trunk size 4K.
11363 : : */
11364 [ # # ]: 0 : if (nb_cts <= cfg.trunk_size) {
11365 : 0 : cfg.per_core_cache = 0;
11366 : 0 : cfg.trunk_size = nb_cts;
11367 [ # # ]: 0 : } else if (nb_cts <= MLX5_HW_IPOOL_SIZE_THRESHOLD) {
11368 : 0 : cfg.per_core_cache = MLX5_HW_IPOOL_CACHE_MIN;
11369 : : }
11370 : 0 : cfg.max_idx = nb_cts;
11371 : 0 : pool->cts = mlx5_ipool_create(&cfg);
11372 [ # # ]: 0 : if (!pool->cts)
11373 : 0 : goto err;
11374 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
11375 : 0 : priv->sh->cdev->pdn,
11376 : : log_obj_size);
11377 [ # # ]: 0 : if (!obj) {
11378 : 0 : rte_errno = ENODATA;
11379 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
11380 : 0 : goto err;
11381 : : }
11382 : 0 : pool->devx_obj = obj;
11383 : : } else {
11384 : : struct rte_eth_dev *host_dev = priv->shared_host;
11385 : 0 : struct mlx5_priv *host_priv = host_dev->data->dev_private;
11386 : :
11387 : 0 : pool->devx_obj = host_priv->hws_ctpool->devx_obj;
11388 : 0 : pool->cts = host_priv->hws_ctpool->cts;
11389 : : MLX5_ASSERT(pool->cts);
11390 : : MLX5_ASSERT(!nb_conn_tracks);
11391 : : }
11392 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, NULL);
11393 : : flags |= MLX5DR_ACTION_FLAG_HWS_RX | MLX5DR_ACTION_FLAG_HWS_TX;
11394 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en && priv->master) {
11395 : 0 : flags |= ((is_unified_fdb(priv)) ?
11396 : : (MLX5DR_ACTION_FLAG_HWS_FDB_RX |
11397 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
11398 [ # # ]: 0 : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) :
11399 : : MLX5DR_ACTION_FLAG_HWS_FDB);
11400 : : }
11401 : 0 : pool->dr_action = mlx5dr_action_create_aso_ct(priv->dr_ctx,
11402 : 0 : (struct mlx5dr_devx_obj *)pool->devx_obj,
11403 : 0 : reg_id - REG_C_0, flags);
11404 [ # # ]: 0 : if (!pool->dr_action)
11405 : 0 : goto err;
11406 : 0 : pool->sq = priv->ct_mng->aso_sqs;
11407 : : /* Assign the last extra ASO SQ as public SQ. */
11408 : 0 : pool->shared_sq = &priv->ct_mng->aso_sqs[priv->nb_queue - 1];
11409 : 0 : return pool;
11410 : 0 : err:
11411 : 0 : flow_hw_ct_pool_destroy(dev, pool);
11412 : 0 : return NULL;
11413 : : }
11414 : :
11415 : : static int
11416 : 0 : mlx5_flow_ct_init(struct rte_eth_dev *dev,
11417 : : uint32_t nb_conn_tracks,
11418 : : uint16_t nb_queue)
11419 : : {
11420 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11421 : : uint32_t mem_size;
11422 : : int ret = -ENOMEM;
11423 : :
11424 [ # # ]: 0 : if (!priv->shared_host) {
11425 : 0 : mem_size = sizeof(struct mlx5_aso_sq) * nb_queue +
11426 : : sizeof(*priv->ct_mng);
11427 : 0 : priv->ct_mng = mlx5_malloc(MLX5_MEM_ZERO, mem_size,
11428 : : RTE_CACHE_LINE_SIZE,
11429 : : SOCKET_ID_ANY);
11430 [ # # ]: 0 : if (!priv->ct_mng)
11431 : 0 : goto err;
11432 : 0 : ret = mlx5_aso_ct_queue_init(priv->sh, priv->ct_mng,
11433 : : nb_queue);
11434 [ # # ]: 0 : if (ret)
11435 : 0 : goto err;
11436 : : }
11437 : 0 : priv->hws_ctpool = flow_hw_ct_pool_create(dev, nb_conn_tracks);
11438 [ # # ]: 0 : if (!priv->hws_ctpool)
11439 : 0 : goto err;
11440 : 0 : priv->sh->ct_aso_en = 1;
11441 : 0 : return 0;
11442 : :
11443 : 0 : err:
11444 [ # # ]: 0 : if (priv->hws_ctpool) {
11445 : 0 : flow_hw_ct_pool_destroy(dev, priv->hws_ctpool);
11446 : 0 : priv->hws_ctpool = NULL;
11447 : : }
11448 [ # # ]: 0 : if (priv->ct_mng) {
11449 : : flow_hw_ct_mng_destroy(priv->ct_mng);
11450 : 0 : priv->ct_mng = NULL;
11451 : : }
11452 : : return ret;
11453 : : }
11454 : :
11455 : : void
11456 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_tables(struct rte_eth_dev *dev)
11457 : : {
11458 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11459 : : unsigned int i;
11460 : : unsigned int j;
11461 : :
11462 [ # # ]: 0 : if (!priv->hw_ctrl_rx)
11463 : : return;
11464 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
11465 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
11466 : 0 : struct rte_flow_template_table *tbl = priv->hw_ctrl_rx->tables[i][j].tbl;
11467 : 0 : struct rte_flow_pattern_template *pt = priv->hw_ctrl_rx->tables[i][j].pt;
11468 : :
11469 [ # # ]: 0 : if (tbl)
11470 : 0 : claim_zero(flow_hw_table_destroy(dev, tbl, NULL));
11471 [ # # ]: 0 : if (pt)
11472 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, pt, NULL));
11473 : : }
11474 : : }
11475 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++i) {
11476 : 0 : struct rte_flow_actions_template *at = priv->hw_ctrl_rx->rss[i];
11477 : :
11478 [ # # ]: 0 : if (at)
11479 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, at, NULL));
11480 : : }
11481 : 0 : mlx5_free(priv->hw_ctrl_rx);
11482 : 0 : priv->hw_ctrl_rx = NULL;
11483 : : }
11484 : :
11485 : : static uint64_t
11486 : : flow_hw_ctrl_rx_rss_type_hash_types(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11487 : : {
11488 : : switch (rss_type) {
11489 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_NON_IP:
11490 : : return 0;
11491 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4:
11492 : : return RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_NONFRAG_IPV4_OTHER;
11493 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
11494 : : return RTE_ETH_RSS_NONFRAG_IPV4_UDP;
11495 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
11496 : : return RTE_ETH_RSS_NONFRAG_IPV4_TCP;
11497 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6:
11498 : : return RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
11499 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
11500 : : return RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_IPV6_UDP_EX;
11501 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
11502 : : return RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_IPV6_TCP_EX;
11503 : : default:
11504 : : /* Should not reach here. */
11505 : : MLX5_ASSERT(false);
11506 : : return 0;
11507 : : }
11508 : : }
11509 : :
11510 : : static struct rte_flow_actions_template *
11511 : 0 : flow_hw_create_ctrl_rx_rss_template(struct rte_eth_dev *dev,
11512 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11513 : : {
11514 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11515 : 0 : struct rte_flow_actions_template_attr attr = {
11516 : : .ingress = 1,
11517 : : };
11518 : : uint16_t queue[RTE_MAX_QUEUES_PER_PORT];
11519 : 0 : struct rte_flow_action_rss rss_conf = {
11520 : : .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
11521 : : .level = 0,
11522 : : .types = 0,
11523 : 0 : .key_len = priv->rss_conf.rss_key_len,
11524 : 0 : .key = priv->rss_conf.rss_key,
11525 : 0 : .queue_num = priv->reta_idx_n,
11526 : : .queue = queue,
11527 : : };
11528 : 0 : struct rte_flow_action actions[] = {
11529 : : {
11530 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
11531 : : .conf = &rss_conf,
11532 : : },
11533 : : {
11534 : : .type = RTE_FLOW_ACTION_TYPE_END,
11535 : : }
11536 : : };
11537 [ # # ]: 0 : struct rte_flow_action masks[] = {
11538 : : {
11539 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
11540 : : .conf = &rss_conf,
11541 : : },
11542 : : {
11543 : : .type = RTE_FLOW_ACTION_TYPE_END,
11544 : : }
11545 : : };
11546 : : struct rte_flow_actions_template *at;
11547 : : struct rte_flow_error error;
11548 : : unsigned int i;
11549 : :
11550 : : MLX5_ASSERT(priv->reta_idx_n > 0 && priv->reta_idx);
11551 : : /* Select proper RSS hash types and based on that configure the actions template. */
11552 : 0 : rss_conf.types = flow_hw_ctrl_rx_rss_type_hash_types(rss_type);
11553 [ # # ]: 0 : if (rss_conf.types) {
11554 [ # # ]: 0 : for (i = 0; i < priv->reta_idx_n; ++i)
11555 : 0 : queue[i] = (*priv->reta_idx)[i];
11556 : : } else {
11557 : 0 : rss_conf.queue_num = 1;
11558 : 0 : queue[0] = (*priv->reta_idx)[0];
11559 : : }
11560 : : at = flow_hw_actions_template_create(dev, &attr, actions, masks, &error);
11561 [ # # ]: 0 : if (!at)
11562 [ # # ]: 0 : DRV_LOG(ERR,
11563 : : "Failed to create ctrl flow actions template: rte_errno(%d), type(%d): %s",
11564 : : rte_errno, error.type,
11565 : : error.message ? error.message : "(no stated reason)");
11566 : 0 : return at;
11567 : : }
11568 : :
11569 : : static uint32_t ctrl_rx_rss_priority_map[MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX] = {
11570 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_NON_IP] = MLX5_HW_CTRL_RX_PRIO_L2,
11571 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4] = MLX5_HW_CTRL_RX_PRIO_L3,
11572 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP] = MLX5_HW_CTRL_RX_PRIO_L4,
11573 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP] = MLX5_HW_CTRL_RX_PRIO_L4,
11574 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6] = MLX5_HW_CTRL_RX_PRIO_L3,
11575 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP] = MLX5_HW_CTRL_RX_PRIO_L4,
11576 : : [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP] = MLX5_HW_CTRL_RX_PRIO_L4,
11577 : : };
11578 : :
11579 : : static uint32_t ctrl_rx_nb_flows_map[MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX] = {
11580 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL] = 1,
11581 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST] = 1,
11582 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST] = 1,
11583 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN] = MLX5_MAX_VLAN_IDS,
11584 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST] = 1,
11585 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN] = MLX5_MAX_VLAN_IDS,
11586 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST] = 1,
11587 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN] = MLX5_MAX_VLAN_IDS,
11588 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC] = MLX5_MAX_UC_MAC_ADDRESSES,
11589 : : [MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN] =
11590 : : MLX5_MAX_UC_MAC_ADDRESSES * MLX5_MAX_VLAN_IDS,
11591 : : };
11592 : :
11593 : : static struct rte_flow_template_table_attr
11594 : : flow_hw_get_ctrl_rx_table_attr(enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
11595 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11596 : : {
11597 : 0 : return (struct rte_flow_template_table_attr){
11598 : : .flow_attr = {
11599 : : .group = 0,
11600 : 0 : .priority = ctrl_rx_rss_priority_map[rss_type],
11601 : : .ingress = 1,
11602 : : },
11603 : 0 : .nb_flows = ctrl_rx_nb_flows_map[eth_pattern_type],
11604 : : };
11605 : : }
11606 : :
11607 : : static struct rte_flow_item
11608 : : flow_hw_get_ctrl_rx_eth_item(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
11609 : : {
11610 : : struct rte_flow_item item = {
11611 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
11612 : : .mask = NULL,
11613 : : };
11614 : :
11615 : 0 : switch (eth_pattern_type) {
11616 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
11617 : : item.mask = &ctrl_rx_eth_promisc_mask;
11618 : : break;
11619 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
11620 : : item.mask = &ctrl_rx_eth_mcast_mask;
11621 : 0 : break;
11622 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
11623 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
11624 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
11625 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
11626 : : item.mask = &ctrl_rx_eth_dmac_mask;
11627 : 0 : break;
11628 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
11629 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
11630 : : item.mask = &ctrl_rx_eth_ipv4_mcast_mask;
11631 : 0 : break;
11632 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
11633 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
11634 : : item.mask = &ctrl_rx_eth_ipv6_mcast_mask;
11635 : 0 : break;
11636 : 0 : default:
11637 : : /* Should not reach here - ETH mask must be present. */
11638 : : item.type = RTE_FLOW_ITEM_TYPE_END;
11639 : : MLX5_ASSERT(false);
11640 : 0 : break;
11641 : : }
11642 : 0 : return item;
11643 : : }
11644 : :
11645 : : static struct rte_flow_item
11646 : : flow_hw_get_ctrl_rx_vlan_item(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
11647 : : {
11648 : : struct rte_flow_item item = {
11649 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
11650 : : .mask = NULL,
11651 : : };
11652 : :
11653 [ # # ]: 0 : switch (eth_pattern_type) {
11654 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
11655 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
11656 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
11657 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
11658 : : item.type = RTE_FLOW_ITEM_TYPE_VLAN;
11659 : : item.mask = &rte_flow_item_vlan_mask;
11660 : 0 : break;
11661 : : default:
11662 : : /* Nothing to update. */
11663 : : break;
11664 : : }
11665 : 0 : return item;
11666 : : }
11667 : :
11668 : : static struct rte_flow_item
11669 : : flow_hw_get_ctrl_rx_l3_item(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11670 : : {
11671 : : struct rte_flow_item item = {
11672 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
11673 : : .mask = NULL,
11674 : : };
11675 : :
11676 [ # # # ]: 0 : switch (rss_type) {
11677 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4:
11678 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
11679 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
11680 : : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
11681 : 0 : break;
11682 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6:
11683 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
11684 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
11685 : : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
11686 : 0 : break;
11687 : : default:
11688 : : /* Nothing to update. */
11689 : : break;
11690 : : }
11691 : 0 : return item;
11692 : : }
11693 : :
11694 : : static struct rte_flow_item
11695 : : flow_hw_get_ctrl_rx_l4_item(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11696 : : {
11697 : : struct rte_flow_item item = {
11698 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
11699 : : .mask = NULL,
11700 : : };
11701 : :
11702 [ # # # ]: 0 : switch (rss_type) {
11703 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
11704 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
11705 : : item.type = RTE_FLOW_ITEM_TYPE_UDP;
11706 : 0 : break;
11707 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
11708 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
11709 : : item.type = RTE_FLOW_ITEM_TYPE_TCP;
11710 : 0 : break;
11711 : : default:
11712 : : /* Nothing to update. */
11713 : : break;
11714 : : }
11715 : 0 : return item;
11716 : : }
11717 : :
11718 : : static struct rte_flow_pattern_template *
11719 : 0 : flow_hw_create_ctrl_rx_pattern_template
11720 : : (struct rte_eth_dev *dev,
11721 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
11722 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11723 : : {
11724 : 0 : const struct rte_flow_pattern_template_attr attr = {
11725 : : .relaxed_matching = 0,
11726 : : .ingress = 1,
11727 : : };
11728 [ # # # # : 0 : struct rte_flow_item items[] = {
# # ]
11729 : : /* Matching patterns */
11730 : : flow_hw_get_ctrl_rx_eth_item(eth_pattern_type),
11731 : : flow_hw_get_ctrl_rx_vlan_item(eth_pattern_type),
11732 : : flow_hw_get_ctrl_rx_l3_item(rss_type),
11733 : : flow_hw_get_ctrl_rx_l4_item(rss_type),
11734 : : /* Terminate pattern */
11735 : : { .type = RTE_FLOW_ITEM_TYPE_END }
11736 : : };
11737 : :
11738 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, false, NULL);
11739 : : }
11740 : :
11741 : : int
11742 : 0 : mlx5_flow_hw_create_ctrl_rx_tables(struct rte_eth_dev *dev)
11743 : : {
11744 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11745 : : unsigned int i;
11746 : : unsigned int j;
11747 : : int ret;
11748 : :
11749 : : MLX5_ASSERT(!priv->hw_ctrl_rx);
11750 : 0 : priv->hw_ctrl_rx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*priv->hw_ctrl_rx),
11751 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
11752 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
11753 : 0 : DRV_LOG(ERR, "Failed to allocate memory for Rx control flow tables");
11754 : 0 : rte_errno = ENOMEM;
11755 : 0 : return -rte_errno;
11756 : : }
11757 : : /* Create all pattern template variants. */
11758 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
11759 : : enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type = i;
11760 : :
11761 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
11762 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
11763 : : struct rte_flow_template_table_attr attr;
11764 : : struct rte_flow_pattern_template *pt;
11765 : :
11766 : : attr = flow_hw_get_ctrl_rx_table_attr(eth_pattern_type, rss_type);
11767 : 0 : pt = flow_hw_create_ctrl_rx_pattern_template(dev, eth_pattern_type,
11768 : : rss_type);
11769 [ # # ]: 0 : if (!pt)
11770 : 0 : goto err;
11771 : 0 : priv->hw_ctrl_rx->tables[i][j].attr = attr;
11772 : 0 : priv->hw_ctrl_rx->tables[i][j].pt = pt;
11773 : : }
11774 : : }
11775 : : return 0;
11776 : : err:
11777 : 0 : ret = rte_errno;
11778 : 0 : return -ret;
11779 : : }
11780 : :
11781 : : void
11782 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev)
11783 : : {
11784 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11785 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
11786 : : unsigned int i;
11787 : : unsigned int j;
11788 : :
11789 [ # # ]: 0 : if (!priv->dr_ctx)
11790 : : return;
11791 [ # # ]: 0 : if (!priv->hw_ctrl_rx)
11792 : : return;
11793 : : hw_ctrl_rx = priv->hw_ctrl_rx;
11794 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
11795 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
11796 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[i][j];
11797 : :
11798 [ # # ]: 0 : if (tmpls->tbl) {
11799 : 0 : claim_zero(flow_hw_table_destroy(dev, tmpls->tbl, NULL));
11800 : 0 : tmpls->tbl = NULL;
11801 : : }
11802 : : }
11803 : : }
11804 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
11805 [ # # ]: 0 : if (hw_ctrl_rx->rss[j]) {
11806 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, hw_ctrl_rx->rss[j], NULL));
11807 : 0 : hw_ctrl_rx->rss[j] = NULL;
11808 : : }
11809 : : }
11810 : : }
11811 : :
11812 : : /**
11813 : : * Copy the provided HWS configuration to a newly allocated buffer.
11814 : : *
11815 : : * @param[in] port_attr
11816 : : * Port configuration attributes.
11817 : : * @param[in] nb_queue
11818 : : * Number of queue.
11819 : : * @param[in] queue_attr
11820 : : * Array that holds attributes for each flow queue.
11821 : : * @param[in] nt_mode
11822 : : * Non template mode.
11823 : : *
11824 : : * @return
11825 : : * Pointer to copied HWS configuration is returned on success.
11826 : : * Otherwise, NULL is returned and rte_errno is set.
11827 : : */
11828 : : static struct mlx5_flow_hw_attr *
11829 : 0 : flow_hw_alloc_copy_config(const struct rte_flow_port_attr *port_attr,
11830 : : const uint16_t nb_queue,
11831 : : const struct rte_flow_queue_attr *queue_attr[],
11832 : : bool nt_mode,
11833 : : struct rte_flow_error *error)
11834 : : {
11835 : : struct mlx5_flow_hw_attr *hw_attr;
11836 : : size_t hw_attr_size;
11837 : : unsigned int i;
11838 : :
11839 : 0 : hw_attr_size = sizeof(*hw_attr) + nb_queue * sizeof(*hw_attr->queue_attr);
11840 : 0 : hw_attr = mlx5_malloc(MLX5_MEM_ZERO, hw_attr_size, 0, SOCKET_ID_ANY);
11841 [ # # ]: 0 : if (!hw_attr) {
11842 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11843 : : "Not enough memory to store configuration");
11844 : 0 : return NULL;
11845 : : }
11846 : 0 : memcpy(&hw_attr->port_attr, port_attr, sizeof(*port_attr));
11847 : 0 : hw_attr->nb_queue = nb_queue;
11848 : : /* Queue attributes are placed after the mlx5_flow_hw_attr. */
11849 : 0 : hw_attr->queue_attr = (struct rte_flow_queue_attr *)(hw_attr + 1);
11850 [ # # ]: 0 : for (i = 0; i < nb_queue; ++i)
11851 : 0 : memcpy(&hw_attr->queue_attr[i], queue_attr[i], sizeof(hw_attr->queue_attr[i]));
11852 : 0 : hw_attr->nt_mode = nt_mode;
11853 : 0 : return hw_attr;
11854 : : }
11855 : :
11856 : : /**
11857 : : * Compares the preserved HWS configuration with the provided one.
11858 : : *
11859 : : * @param[in] hw_attr
11860 : : * Pointer to preserved HWS configuration.
11861 : : * @param[in] new_pa
11862 : : * Port configuration attributes to compare.
11863 : : * @param[in] new_nbq
11864 : : * Number of queues to compare.
11865 : : * @param[in] new_qa
11866 : : * Array that holds attributes for each flow queue.
11867 : : *
11868 : : * @return
11869 : : * True if configurations are the same, false otherwise.
11870 : : */
11871 : : static bool
11872 : 0 : flow_hw_compare_config(const struct mlx5_flow_hw_attr *hw_attr,
11873 : : const struct rte_flow_port_attr *new_pa,
11874 : : const uint16_t new_nbq,
11875 : : const struct rte_flow_queue_attr *new_qa[])
11876 : : {
11877 : : const struct rte_flow_port_attr *old_pa = &hw_attr->port_attr;
11878 : 0 : const uint16_t old_nbq = hw_attr->nb_queue;
11879 : 0 : const struct rte_flow_queue_attr *old_qa = hw_attr->queue_attr;
11880 : : unsigned int i;
11881 : :
11882 [ # # ]: 0 : if (old_pa->nb_counters != new_pa->nb_counters ||
11883 [ # # ]: 0 : old_pa->nb_aging_objects != new_pa->nb_aging_objects ||
11884 [ # # ]: 0 : old_pa->nb_meters != new_pa->nb_meters ||
11885 [ # # ]: 0 : old_pa->nb_conn_tracks != new_pa->nb_conn_tracks ||
11886 [ # # ]: 0 : old_pa->flags != new_pa->flags)
11887 : : return false;
11888 [ # # ]: 0 : if (old_nbq != new_nbq)
11889 : : return false;
11890 [ # # ]: 0 : for (i = 0; i < old_nbq; ++i)
11891 [ # # ]: 0 : if (old_qa[i].size != new_qa[i]->size)
11892 : : return false;
11893 : : return true;
11894 : : }
11895 : :
11896 : : /*
11897 : : * No need to explicitly release drop action templates on port stop.
11898 : : * Drop action templates release with other action templates during
11899 : : * mlx5_dev_close -> flow_hw_resource_release -> flow_hw_actions_template_destroy
11900 : : */
11901 : : static void
11902 : 0 : flow_hw_action_template_drop_release(struct rte_eth_dev *dev)
11903 : : {
11904 : : int i;
11905 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11906 : :
11907 [ # # ]: 0 : for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) {
11908 [ # # ]: 0 : if (!priv->action_template_drop[i])
11909 : 0 : continue;
11910 : 0 : flow_hw_actions_template_destroy(dev,
11911 : : priv->action_template_drop[i],
11912 : : NULL);
11913 : 0 : priv->action_template_drop[i] = NULL;
11914 : : }
11915 : 0 : }
11916 : :
11917 : : static int
11918 : 0 : flow_hw_action_template_drop_init(struct rte_eth_dev *dev,
11919 : : struct rte_flow_error *error)
11920 : : {
11921 : : uint32_t i, from, to;
11922 : 0 : const struct rte_flow_action drop[2] = {
11923 : : [0] = { .type = RTE_FLOW_ACTION_TYPE_DROP },
11924 : : [1] = { .type = RTE_FLOW_ACTION_TYPE_END },
11925 : : };
11926 : : const struct rte_flow_action *actions = drop;
11927 : : const struct rte_flow_action *masks = drop;
11928 : 0 : const struct rte_flow_actions_template_attr attr[MLX5DR_TABLE_TYPE_MAX] = {
11929 : : [MLX5DR_TABLE_TYPE_NIC_RX] = { .ingress = 1 },
11930 : : [MLX5DR_TABLE_TYPE_NIC_TX] = { .egress = 1 },
11931 : : [MLX5DR_TABLE_TYPE_FDB] = { .transfer = 1 },
11932 : : [MLX5DR_TABLE_TYPE_FDB_RX] = { .transfer = 1 },
11933 : : [MLX5DR_TABLE_TYPE_FDB_TX] = { .transfer = 1 },
11934 : : [MLX5DR_TABLE_TYPE_FDB_UNIFIED] = { .transfer = 1 },
11935 : : };
11936 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11937 : :
11938 : : from = MLX5DR_TABLE_TYPE_NIC_RX;
11939 : : to = MLX5DR_TABLE_TYPE_NIC_TX;
11940 [ # # ]: 0 : for (i = from; i <= to; i++) {
11941 : 0 : priv->action_template_drop[i] =
11942 : 0 : flow_hw_actions_template_create(dev, &attr[i], actions, masks, error);
11943 [ # # ]: 0 : if (!priv->action_template_drop[i])
11944 : : return -1;
11945 : : }
11946 : :
11947 [ # # # # ]: 0 : if (!(priv->sh->config.dv_esw_en && priv->master))
11948 : : return 0;
11949 : :
11950 : : from = MLX5DR_TABLE_TYPE_FDB;
11951 [ # # ]: 0 : to = is_unified_fdb(priv) ? MLX5DR_TABLE_TYPE_FDB_UNIFIED : MLX5DR_TABLE_TYPE_FDB;
11952 [ # # ]: 0 : for (i = from; i <= to; i++) {
11953 : 0 : priv->action_template_drop[i] =
11954 : 0 : flow_hw_actions_template_create(dev, &attr[i], actions, masks, error);
11955 [ # # ]: 0 : if (!priv->action_template_drop[i])
11956 : : return -1;
11957 : : }
11958 : : return 0;
11959 : : }
11960 : :
11961 : : static void
11962 : 0 : __mlx5_flow_hw_resource_release(struct rte_eth_dev *dev, bool ctx_close)
11963 : : {
11964 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11965 : : struct rte_flow_template_table *tbl, *temp_tbl;
11966 : : struct rte_flow_pattern_template *it, *temp_it;
11967 : : struct rte_flow_actions_template *at, *temp_at;
11968 : : struct mlx5_flow_group *grp, *temp_grp;
11969 : : uint32_t i;
11970 : :
11971 : 0 : mlx5_flow_hw_rxq_flag_set(dev, false);
11972 : 0 : flow_hw_flush_all_ctrl_flows(dev);
11973 : 0 : flow_hw_cleanup_lacp_miss_tables(dev);
11974 : 0 : flow_hw_cleanup_ctrl_fdb_tables(dev);
11975 : 0 : flow_hw_cleanup_ctrl_nic_tables(dev);
11976 : 0 : flow_hw_cleanup_tx_repr_tagging(dev);
11977 : 0 : flow_hw_action_template_drop_release(dev);
11978 : 0 : grp = LIST_FIRST(&priv->flow_hw_grp);
11979 [ # # ]: 0 : while (grp) {
11980 : 0 : temp_grp = LIST_NEXT(grp, next);
11981 : 0 : claim_zero(flow_hw_group_unset_miss_group(dev, grp, NULL));
11982 : : grp = temp_grp;
11983 : : }
11984 : 0 : tbl = LIST_FIRST(&priv->flow_hw_tbl_ongo);
11985 [ # # ]: 0 : while (tbl) {
11986 : 0 : temp_tbl = LIST_NEXT(tbl, next);
11987 : 0 : claim_zero(flow_hw_table_destroy(dev, tbl, NULL));
11988 : : tbl = temp_tbl;
11989 : : }
11990 : 0 : tbl = LIST_FIRST(&priv->flow_hw_tbl);
11991 [ # # ]: 0 : while (tbl) {
11992 : 0 : temp_tbl = LIST_NEXT(tbl, next);
11993 : 0 : claim_zero(flow_hw_table_destroy(dev, tbl, NULL));
11994 : : tbl = temp_tbl;
11995 : : }
11996 : 0 : it = LIST_FIRST(&priv->flow_hw_itt);
11997 [ # # ]: 0 : while (it) {
11998 : 0 : temp_it = LIST_NEXT(it, next);
11999 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, it, NULL));
12000 : : it = temp_it;
12001 : : }
12002 : 0 : at = LIST_FIRST(&priv->flow_hw_at);
12003 [ # # ]: 0 : while (at) {
12004 : 0 : temp_at = LIST_NEXT(at, next);
12005 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, at, NULL));
12006 : : at = temp_at;
12007 : : }
12008 : 0 : flow_hw_free_vport_actions(priv);
12009 [ # # ]: 0 : if (priv->acts_ipool) {
12010 : 0 : mlx5_ipool_destroy(priv->acts_ipool);
12011 : 0 : priv->acts_ipool = NULL;
12012 : : }
12013 [ # # ]: 0 : if (priv->hws_age_req)
12014 : 0 : mlx5_hws_age_pool_destroy(priv);
12015 [ # # # # ]: 0 : if (!priv->shared_host && priv->hws_cpool) {
12016 : 0 : mlx5_hws_cnt_pool_destroy(priv->sh, priv->hws_cpool);
12017 : 0 : priv->hws_cpool = NULL;
12018 : : }
12019 [ # # ]: 0 : if (priv->hws_ctpool) {
12020 : 0 : flow_hw_ct_pool_destroy(dev, priv->hws_ctpool);
12021 : 0 : priv->hws_ctpool = NULL;
12022 : : }
12023 [ # # ]: 0 : if (priv->ct_mng) {
12024 : : flow_hw_ct_mng_destroy(priv->ct_mng);
12025 : 0 : priv->ct_mng = NULL;
12026 : : }
12027 : 0 : mlx5_flow_quota_destroy(dev);
12028 : 0 : mlx5_hws_global_actions_cleanup(priv);
12029 [ # # ]: 0 : if (priv->hw_q) {
12030 [ # # ]: 0 : for (i = 0; i < priv->nb_queue; i++) {
12031 : 0 : struct mlx5_hw_q *hwq = &priv->hw_q[i];
12032 : 0 : rte_ring_free(hwq->indir_iq);
12033 : 0 : rte_ring_free(hwq->indir_cq);
12034 : 0 : rte_ring_free(hwq->flow_transfer_pending);
12035 : 0 : rte_ring_free(hwq->flow_transfer_completed);
12036 : : }
12037 : 0 : mlx5_free(priv->hw_q);
12038 : 0 : priv->hw_q = NULL;
12039 : : }
12040 [ # # ]: 0 : if (ctx_close) {
12041 [ # # ]: 0 : if (priv->dr_ctx) {
12042 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
12043 : 0 : priv->dr_ctx = NULL;
12044 : : }
12045 : : }
12046 [ # # ]: 0 : if (priv->shared_host) {
12047 : 0 : struct mlx5_priv *host_priv = priv->shared_host->data->dev_private;
12048 : 0 : rte_atomic_fetch_sub_explicit(&host_priv->shared_refcnt, 1,
12049 : : rte_memory_order_relaxed);
12050 : 0 : priv->shared_host = NULL;
12051 : : }
12052 [ # # ]: 0 : if (priv->hw_attr) {
12053 : 0 : mlx5_free(priv->hw_attr);
12054 : 0 : priv->hw_attr = NULL;
12055 : : }
12056 : 0 : priv->nb_queue = 0;
12057 : 0 : }
12058 : :
12059 : : static __rte_always_inline struct rte_ring *
12060 : : mlx5_hwq_ring_create(uint16_t port_id, uint32_t queue, uint32_t size, const char *str)
12061 : : {
12062 : : char mz_name[RTE_MEMZONE_NAMESIZE];
12063 : :
12064 : : snprintf(mz_name, sizeof(mz_name), "port_%u_%s_%u", port_id, str, queue);
12065 : 0 : return rte_ring_create(mz_name, size, SOCKET_ID_ANY,
12066 : : RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ);
12067 : : }
12068 : :
12069 : : static int
12070 : 0 : flow_hw_queue_setup_rings(struct rte_eth_dev *dev,
12071 : : uint16_t queue,
12072 : : uint32_t queue_size,
12073 : : bool nt_mode)
12074 : : {
12075 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12076 : :
12077 : : /* HWS queue info container must be already allocated. */
12078 : : MLX5_ASSERT(priv->hw_q != NULL);
12079 : :
12080 : : /* Notice ring name length is limited. */
12081 : 0 : priv->hw_q[queue].indir_cq = mlx5_hwq_ring_create
12082 : 0 : (dev->data->port_id, queue, queue_size, "indir_act_cq");
12083 [ # # ]: 0 : if (!priv->hw_q[queue].indir_cq) {
12084 : 0 : DRV_LOG(ERR, "port %u failed to allocate indir_act_cq ring for HWS",
12085 : : dev->data->port_id);
12086 : 0 : return -ENOMEM;
12087 : : }
12088 : :
12089 : 0 : priv->hw_q[queue].indir_iq = mlx5_hwq_ring_create
12090 : 0 : (dev->data->port_id, queue, queue_size, "indir_act_iq");
12091 [ # # ]: 0 : if (!priv->hw_q[queue].indir_iq) {
12092 : 0 : DRV_LOG(ERR, "port %u failed to allocate indir_act_iq ring for HWS",
12093 : : dev->data->port_id);
12094 : 0 : return -ENOMEM;
12095 : : }
12096 : :
12097 : : /*
12098 : : * Sync flow API does not require rings used for table resize handling,
12099 : : * because these rings are only used through async flow APIs.
12100 : : */
12101 [ # # ]: 0 : if (nt_mode)
12102 : : return 0;
12103 : :
12104 : 0 : priv->hw_q[queue].flow_transfer_pending = mlx5_hwq_ring_create
12105 : 0 : (dev->data->port_id, queue, queue_size, "tx_pending");
12106 [ # # ]: 0 : if (!priv->hw_q[queue].flow_transfer_pending) {
12107 : 0 : DRV_LOG(ERR, "port %u failed to allocate tx_pending ring for HWS",
12108 : : dev->data->port_id);
12109 : 0 : return -ENOMEM;
12110 : : }
12111 : :
12112 : 0 : priv->hw_q[queue].flow_transfer_completed = mlx5_hwq_ring_create
12113 : 0 : (dev->data->port_id, queue, queue_size, "tx_done");
12114 [ # # ]: 0 : if (!priv->hw_q[queue].flow_transfer_completed) {
12115 : 0 : DRV_LOG(ERR, "port %u failed to allocate tx_done ring for HWS",
12116 : : dev->data->port_id);
12117 : 0 : return -ENOMEM;
12118 : : }
12119 : :
12120 : : return 0;
12121 : : }
12122 : :
12123 : : static int
12124 : 0 : flow_hw_validate_attributes(const struct rte_flow_port_attr *port_attr,
12125 : : uint16_t nb_queue,
12126 : : const struct rte_flow_queue_attr *queue_attr[],
12127 : : bool nt_mode, struct rte_flow_error *error)
12128 : : {
12129 : : uint32_t size;
12130 : : unsigned int i;
12131 : :
12132 [ # # ]: 0 : if (port_attr == NULL)
12133 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12134 : : "Port attributes must be non-NULL");
12135 : :
12136 [ # # ]: 0 : if (nb_queue == 0 && !nt_mode)
12137 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12138 : : "At least one flow queue is required");
12139 : :
12140 [ # # ]: 0 : if (queue_attr == NULL)
12141 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12142 : : "Queue attributes must be non-NULL");
12143 : :
12144 : 0 : size = queue_attr[0]->size;
12145 [ # # ]: 0 : for (i = 1; i < nb_queue; ++i) {
12146 [ # # ]: 0 : if (queue_attr[i]->size != size)
12147 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12148 : : NULL,
12149 : : "All flow queues must have the same size");
12150 : : }
12151 : :
12152 : : return 0;
12153 : : }
12154 : :
12155 : : /**
12156 : : * Configure port HWS resources.
12157 : : *
12158 : : * @param[in] dev
12159 : : * Pointer to the rte_eth_dev structure.
12160 : : * @param[in] port_attr
12161 : : * Port configuration attributes.
12162 : : * @param[in] nb_queue
12163 : : * Number of queue.
12164 : : * @param[in] queue_attr
12165 : : * Array that holds attributes for each flow queue.
12166 : : * @param[in] nt_mode
12167 : : * Non-template mode.
12168 : : * @param[out] error
12169 : : * Pointer to error structure.
12170 : : *
12171 : : * @return
12172 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12173 : : */
12174 : : static int
12175 : 0 : __flow_hw_configure(struct rte_eth_dev *dev,
12176 : : const struct rte_flow_port_attr *port_attr,
12177 : : uint16_t nb_queue,
12178 : : const struct rte_flow_queue_attr *queue_attr[],
12179 : : bool nt_mode,
12180 : : struct rte_flow_error *error)
12181 : : {
12182 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12183 : : struct mlx5_priv *host_priv = NULL;
12184 : 0 : struct mlx5dr_context_attr dr_ctx_attr = {0};
12185 : : struct mlx5_hw_q *hw_q;
12186 : : struct mlx5_hw_q_job *job = NULL;
12187 : : uint32_t mem_size, i, j;
12188 : 0 : struct mlx5_indexed_pool_config cfg = {
12189 : : .size = sizeof(struct mlx5_action_construct_data),
12190 : : .trunk_size = 4096,
12191 : : .need_lock = 1,
12192 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
12193 : : .malloc = mlx5_malloc,
12194 : : .free = mlx5_free,
12195 : : .type = "mlx5_hw_action_construct_data",
12196 : : };
12197 : : /*
12198 : : * Adds one queue to be used by PMD.
12199 : : * The last queue will be used by the PMD.
12200 : : */
12201 : : uint16_t nb_q_updated = 0;
12202 : : struct rte_flow_queue_attr **_queue_attr = NULL;
12203 : 0 : struct rte_flow_queue_attr ctrl_queue_attr = {0};
12204 [ # # # # ]: 0 : bool is_proxy = !!(priv->sh->config.dv_esw_en && priv->master);
12205 : : int ret = 0;
12206 : : bool strict_queue = false;
12207 : :
12208 : 0 : error->type = RTE_FLOW_ERROR_TYPE_NONE;
12209 [ # # ]: 0 : if (mlx5dr_rule_get_handle_size() != MLX5_DR_RULE_SIZE) {
12210 : 0 : rte_errno = EINVAL;
12211 : 0 : goto err;
12212 : : }
12213 [ # # ]: 0 : if (flow_hw_validate_attributes(port_attr, nb_queue, queue_attr, nt_mode, error))
12214 : 0 : return -rte_errno;
12215 : : /*
12216 : : * Calling rte_flow_configure() again is allowed if
12217 : : * provided configuration matches the initially provided one,
12218 : : * or previous configuration was default non template one.
12219 : : */
12220 [ # # ]: 0 : if (priv->dr_ctx) {
12221 : : MLX5_ASSERT(priv->hw_attr != NULL);
12222 [ # # ]: 0 : for (i = 0; i < priv->nb_queue; i++) {
12223 : 0 : hw_q = &priv->hw_q[i];
12224 : : /* Make sure all queues are empty. */
12225 [ # # ]: 0 : if (hw_q->size != hw_q->job_idx) {
12226 : 0 : rte_errno = EBUSY;
12227 : 0 : goto err;
12228 : : }
12229 : : }
12230 : : /* If previous configuration was not default non template mode config. */
12231 [ # # ]: 0 : if (!priv->hw_attr->nt_mode) {
12232 [ # # ]: 0 : if (flow_hw_compare_config(priv->hw_attr, port_attr, nb_queue, queue_attr))
12233 : : return 0;
12234 : : else
12235 : 0 : return rte_flow_error_set(error, ENOTSUP,
12236 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12237 : : "Changing HWS configuration attributes "
12238 : : "is not supported");
12239 : : }
12240 : : /* Reconfiguration, need to release all resources from previous allocation. */
12241 : 0 : __mlx5_flow_hw_resource_release(dev, true);
12242 : : }
12243 : 0 : priv->hw_attr = flow_hw_alloc_copy_config(port_attr, nb_queue, queue_attr, nt_mode, error);
12244 [ # # ]: 0 : if (!priv->hw_attr) {
12245 : 0 : ret = -rte_errno;
12246 : 0 : goto err;
12247 : : }
12248 : 0 : ctrl_queue_attr.size = queue_attr[0]->size;
12249 : 0 : nb_q_updated = nb_queue + 1;
12250 : 0 : _queue_attr = mlx5_malloc(MLX5_MEM_ZERO,
12251 : : nb_q_updated *
12252 : : sizeof(struct rte_flow_queue_attr *),
12253 : : 64, SOCKET_ID_ANY);
12254 [ # # ]: 0 : if (!_queue_attr) {
12255 : 0 : rte_errno = ENOMEM;
12256 : 0 : goto err;
12257 : : }
12258 : :
12259 : 0 : memcpy(_queue_attr, queue_attr, sizeof(void *) * nb_queue);
12260 : 0 : _queue_attr[nb_queue] = &ctrl_queue_attr;
12261 : 0 : priv->acts_ipool = mlx5_ipool_create(&cfg);
12262 [ # # ]: 0 : if (!priv->acts_ipool)
12263 : 0 : goto err;
12264 : : /* Allocate the queue job descriptor LIFO. */
12265 : 0 : mem_size = sizeof(priv->hw_q[0]) * nb_q_updated;
12266 [ # # ]: 0 : for (i = 0; i < nb_q_updated; i++) {
12267 : 0 : mem_size += (sizeof(struct mlx5_hw_q_job *) +
12268 : 0 : sizeof(struct mlx5_hw_q_job)) * _queue_attr[i]->size;
12269 : : }
12270 : 0 : priv->hw_q = mlx5_malloc(MLX5_MEM_ZERO, mem_size,
12271 : : 64, SOCKET_ID_ANY);
12272 [ # # ]: 0 : if (!priv->hw_q) {
12273 : 0 : rte_errno = ENOMEM;
12274 : 0 : goto err;
12275 : : }
12276 [ # # ]: 0 : for (i = 0; i < nb_q_updated; i++) {
12277 : 0 : priv->hw_q[i].job_idx = _queue_attr[i]->size;
12278 : 0 : priv->hw_q[i].size = _queue_attr[i]->size;
12279 : 0 : priv->hw_q[i].ongoing_flow_ops = 0;
12280 [ # # ]: 0 : if (i == 0)
12281 : 0 : priv->hw_q[i].job = (struct mlx5_hw_q_job **)
12282 : 0 : &priv->hw_q[nb_q_updated];
12283 : : else
12284 : 0 : priv->hw_q[i].job = (struct mlx5_hw_q_job **)&job[_queue_attr[i - 1]->size];
12285 : 0 : job = (struct mlx5_hw_q_job *)
12286 : 0 : &priv->hw_q[i].job[_queue_attr[i]->size];
12287 [ # # ]: 0 : for (j = 0; j < _queue_attr[i]->size; j++)
12288 : 0 : priv->hw_q[i].job[j] = &job[j];
12289 : :
12290 [ # # ]: 0 : if (flow_hw_queue_setup_rings(dev, i, _queue_attr[i]->size, nt_mode) < 0)
12291 : 0 : goto err;
12292 : : }
12293 : 0 : dr_ctx_attr.pd = priv->sh->cdev->pd;
12294 : 0 : dr_ctx_attr.queues = nb_q_updated;
12295 : : /* Assign initial value of STC numbers for representors. */
12296 [ # # ]: 0 : if (priv->representor)
12297 : 0 : dr_ctx_attr.initial_log_stc_memory = MLX5_REPR_STC_MEMORY_LOG;
12298 : : /* Queue size should all be the same. Take the first one. */
12299 : 0 : dr_ctx_attr.queue_size = _queue_attr[0]->size;
12300 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_SHARE_INDIRECT) {
12301 : : struct rte_eth_dev *host_dev = NULL;
12302 : : uint16_t port_id;
12303 : :
12304 : : MLX5_ASSERT(rte_eth_dev_is_valid_port(port_attr->host_port_id));
12305 [ # # ]: 0 : if (is_proxy) {
12306 : 0 : DRV_LOG(ERR, "cross vHCA shared mode not supported "
12307 : : "for E-Switch confgiurations");
12308 : 0 : rte_errno = ENOTSUP;
12309 : 0 : goto err;
12310 : : }
12311 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
12312 [ # # ]: 0 : if (port_id == port_attr->host_port_id) {
12313 : 0 : host_dev = &rte_eth_devices[port_id];
12314 : 0 : break;
12315 : : }
12316 : : }
12317 [ # # ]: 0 : if (!host_dev || host_dev == dev ||
12318 [ # # # # ]: 0 : !host_dev->data || !host_dev->data->dev_private) {
12319 : 0 : DRV_LOG(ERR, "Invalid cross vHCA host port %u",
12320 : : port_attr->host_port_id);
12321 : 0 : rte_errno = EINVAL;
12322 : 0 : goto err;
12323 : : }
12324 : : host_priv = host_dev->data->dev_private;
12325 [ # # ]: 0 : if (host_priv->sh->cdev->ctx == priv->sh->cdev->ctx) {
12326 : 0 : DRV_LOG(ERR, "Sibling ports %u and %u do not "
12327 : : "require cross vHCA sharing mode",
12328 : : dev->data->port_id, port_attr->host_port_id);
12329 : 0 : rte_errno = EINVAL;
12330 : 0 : goto err;
12331 : : }
12332 [ # # ]: 0 : if (host_priv->shared_host) {
12333 : 0 : DRV_LOG(ERR, "Host port %u is not the sharing base",
12334 : : port_attr->host_port_id);
12335 : 0 : rte_errno = EINVAL;
12336 : 0 : goto err;
12337 : : }
12338 [ # # ]: 0 : if (port_attr->nb_counters ||
12339 [ # # ]: 0 : port_attr->nb_aging_objects ||
12340 [ # # ]: 0 : port_attr->nb_meters ||
12341 [ # # ]: 0 : port_attr->nb_conn_tracks) {
12342 : 0 : DRV_LOG(ERR,
12343 : : "Object numbers on guest port must be zeros");
12344 : 0 : rte_errno = EINVAL;
12345 : 0 : goto err;
12346 : : }
12347 : 0 : dr_ctx_attr.shared_ibv_ctx = host_priv->sh->cdev->ctx;
12348 : 0 : priv->shared_host = host_dev;
12349 : 0 : rte_atomic_fetch_add_explicit(&host_priv->shared_refcnt, 1,
12350 : : rte_memory_order_relaxed);
12351 : : }
12352 : : /* Set backward compatibale mode to support non template RTE FLOW API.*/
12353 : 0 : dr_ctx_attr.bwc = true;
12354 : 0 : priv->dr_ctx = mlx5dr_context_open(priv->sh->cdev->ctx, &dr_ctx_attr);
12355 : : /* rte_errno has been updated by HWS layer. */
12356 [ # # ]: 0 : if (!priv->dr_ctx)
12357 : 0 : goto err;
12358 : 0 : priv->nb_queue = nb_q_updated;
12359 : 0 : ret = flow_hw_action_template_drop_init(dev, error);
12360 [ # # ]: 0 : if (ret)
12361 : 0 : goto err;
12362 : : /* Initialize quotas */
12363 [ # # # # : 0 : if (port_attr->nb_quotas || (host_priv && host_priv->quota_ctx.devx_obj)) {
# # ]
12364 : 0 : ret = mlx5_flow_quota_init(dev, port_attr->nb_quotas);
12365 [ # # ]: 0 : if (ret) {
12366 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12367 : : "Failed to initialize quota.");
12368 : 0 : goto err;
12369 : : }
12370 : : }
12371 : : /* Initialize meter library*/
12372 [ # # # # : 0 : if (port_attr->nb_meters || (host_priv && host_priv->hws_mpool))
# # ]
12373 [ # # ]: 0 : if (mlx5_flow_meter_init(dev, port_attr->nb_meters, 0, 0, nb_q_updated))
12374 : 0 : goto err;
12375 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
12376 : 0 : ret = flow_hw_setup_tx_repr_tagging(dev, error);
12377 [ # # ]: 0 : if (ret)
12378 : 0 : goto err;
12379 : : }
12380 [ # # ]: 0 : if (mlx5_flow_lacp_miss_needed(dev)) {
12381 : 0 : ret = flow_hw_create_lacp_miss_tables(dev);
12382 [ # # ]: 0 : if (ret) {
12383 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12384 : : "Unable to create LACP miss flow tables");
12385 : 0 : goto err;
12386 : : }
12387 : : }
12388 [ # # ]: 0 : if (is_proxy) {
12389 : 0 : ret = flow_hw_create_vport_actions(priv);
12390 [ # # ]: 0 : if (ret) {
12391 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12392 : : NULL, "Failed to create vport actions.");
12393 : 0 : goto err;
12394 : : }
12395 : 0 : ret = flow_hw_create_fdb_ctrl_tables(dev, error);
12396 [ # # ]: 0 : if (ret) {
12397 : 0 : rte_errno = -ret;
12398 : 0 : goto err;
12399 : : }
12400 : : }
12401 [ # # ]: 0 : if (mlx5_vport_tx_metadata_passing_enabled(priv->sh)) {
12402 : 0 : ret = flow_hw_create_nic_ctrl_tables(dev, error);
12403 [ # # ]: 0 : if (ret != 0) {
12404 : 0 : rte_errno = -ret;
12405 : 0 : goto err;
12406 : : }
12407 : : }
12408 [ # # # # : 0 : if (port_attr->nb_conn_tracks || (host_priv && host_priv->hws_ctpool)) {
# # ]
12409 [ # # ]: 0 : if (mlx5_flow_ct_init(dev, port_attr->nb_conn_tracks, nb_q_updated))
12410 : 0 : goto err;
12411 : : }
12412 [ # # # # : 0 : if (port_attr->nb_counters || (host_priv && host_priv->hws_cpool)) {
# # ]
12413 [ # # ]: 0 : struct mlx5_hws_cnt_pool *hws_cpool = host_priv ? host_priv->hws_cpool : NULL;
12414 : :
12415 : 0 : ret = mlx5_hws_cnt_pool_create(dev, port_attr->nb_counters,
12416 : : nb_queue, hws_cpool, error);
12417 [ # # ]: 0 : if (ret)
12418 : 0 : goto err;
12419 : : }
12420 [ # # ]: 0 : if (port_attr->nb_aging_objects) {
12421 [ # # ]: 0 : if (port_attr->nb_counters == 0) {
12422 : : /*
12423 : : * Aging management uses counter. Number counters
12424 : : * requesting should take into account a counter for
12425 : : * each flow rules containing AGE without counter.
12426 : : */
12427 : 0 : DRV_LOG(ERR, "Port %u AGE objects are requested (%u) "
12428 : : "without counters requesting.",
12429 : : dev->data->port_id,
12430 : : port_attr->nb_aging_objects);
12431 : 0 : rte_errno = EINVAL;
12432 : 0 : goto err;
12433 : : }
12434 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_SHARE_INDIRECT) {
12435 : 0 : DRV_LOG(ERR, "Aging is not supported "
12436 : : "in cross vHCA sharing mode");
12437 : : ret = -ENOTSUP;
12438 : 0 : goto err;
12439 : : }
12440 : 0 : strict_queue = !!(port_attr->flags & RTE_FLOW_PORT_FLAG_STRICT_QUEUE);
12441 : 0 : ret = mlx5_hws_age_pool_init(dev, port_attr->nb_aging_objects,
12442 : : nb_queue, strict_queue);
12443 [ # # ]: 0 : if (ret < 0)
12444 : 0 : goto err;
12445 : : }
12446 : : if (_queue_attr)
12447 : 0 : mlx5_free(_queue_attr);
12448 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_STRICT_QUEUE)
12449 : 0 : priv->hws_strict_queue = 1;
12450 : 0 : dev->flow_fp_ops = &mlx5_flow_hw_fp_ops;
12451 : 0 : return 0;
12452 : 0 : err:
12453 : 0 : __mlx5_flow_hw_resource_release(dev, true);
12454 [ # # ]: 0 : if (_queue_attr)
12455 : 0 : mlx5_free(_queue_attr);
12456 : : /* Do not overwrite the internal errno information. */
12457 [ # # # # ]: 0 : if (ret && error->type != RTE_FLOW_ERROR_TYPE_NONE)
12458 : : return ret;
12459 : 0 : return rte_flow_error_set(error, rte_errno,
12460 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12461 : : "fail to configure port");
12462 : : }
12463 : :
12464 : : /**
12465 : : * Configure port HWS resources.
12466 : : *
12467 : : * @param[in] dev
12468 : : * Pointer to the rte_eth_dev structure.
12469 : : * @param[in] port_attr
12470 : : * Port configuration attributes.
12471 : : * @param[in] nb_queue
12472 : : * Number of queue.
12473 : : * @param[in] queue_attr
12474 : : * Array that holds attributes for each flow queue.
12475 : : * @param[out] error
12476 : : * Pointer to error structure.
12477 : : *
12478 : : * @return
12479 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12480 : : */
12481 : : static int
12482 : 0 : flow_hw_configure(struct rte_eth_dev *dev,
12483 : : const struct rte_flow_port_attr *port_attr,
12484 : : uint16_t nb_queue,
12485 : : const struct rte_flow_queue_attr *queue_attr[],
12486 : : struct rte_flow_error *error)
12487 : : {
12488 : 0 : struct rte_flow_error shadow_error = {0, };
12489 : :
12490 [ # # ]: 0 : if (!error)
12491 : : error = &shadow_error;
12492 : 0 : return __flow_hw_configure(dev, port_attr, nb_queue, queue_attr, false, error);
12493 : : }
12494 : :
12495 : : /**
12496 : : * Release HWS resources.
12497 : : *
12498 : : * @param[in] dev
12499 : : * Pointer to the rte_eth_dev structure.
12500 : : */
12501 : : void
12502 : 0 : mlx5_flow_hw_resource_release(struct rte_eth_dev *dev)
12503 : : {
12504 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12505 : :
12506 [ # # ]: 0 : if (!priv->dr_ctx)
12507 : : return;
12508 : 0 : __mlx5_flow_hw_resource_release(dev, false);
12509 : : }
12510 : :
12511 : : /* Sets vport tag and mask, for given port, used in HWS rules. */
12512 : : void
12513 : 0 : mlx5_flow_hw_set_port_info(struct rte_eth_dev *dev)
12514 : : {
12515 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12516 : 0 : uint16_t port_id = dev->data->port_id;
12517 : : struct flow_hw_port_info *info;
12518 : :
12519 : : MLX5_ASSERT(port_id < RTE_MAX_ETHPORTS);
12520 : 0 : info = &mlx5_flow_hw_port_infos[port_id];
12521 : 0 : info->regc_mask = priv->vport_meta_mask;
12522 : 0 : info->regc_value = priv->vport_meta_tag;
12523 [ # # ]: 0 : info->vhca_id = priv->vport_vhca_id;
12524 [ # # ]: 0 : info->is_wire = mlx5_is_port_on_mpesw_device(priv) ? priv->mpesw_uplink : priv->master;
12525 : 0 : info->is_set = 1;
12526 : 0 : }
12527 : :
12528 : : /* Clears vport tag and mask used for HWS rules. */
12529 : : void
12530 : 0 : mlx5_flow_hw_clear_port_info(struct rte_eth_dev *dev)
12531 : : {
12532 : 0 : uint16_t port_id = dev->data->port_id;
12533 : : struct flow_hw_port_info *info;
12534 : :
12535 : : MLX5_ASSERT(port_id < RTE_MAX_ETHPORTS);
12536 : 0 : info = &mlx5_flow_hw_port_infos[port_id];
12537 : : memset(info, 0, sizeof(*info));
12538 : 0 : }
12539 : :
12540 : : static int
12541 : 0 : flow_hw_conntrack_destroy(struct rte_eth_dev *dev,
12542 : : uint32_t idx,
12543 : : struct rte_flow_error *error)
12544 : : {
12545 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12546 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12547 : : struct mlx5_aso_ct_action *ct;
12548 : :
12549 [ # # ]: 0 : if (priv->shared_host)
12550 : 0 : return rte_flow_error_set(error, ENOTSUP,
12551 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12552 : : NULL,
12553 : : "CT destruction is not allowed to guest port");
12554 : 0 : ct = mlx5_ipool_get(pool->cts, idx);
12555 [ # # ]: 0 : if (!ct) {
12556 : 0 : return rte_flow_error_set(error, EINVAL,
12557 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12558 : : NULL,
12559 : : "Invalid CT destruction index");
12560 : : }
12561 : 0 : rte_atomic_store_explicit(&ct->state, ASO_CONNTRACK_FREE,
12562 : : rte_memory_order_relaxed);
12563 : 0 : mlx5_ipool_free(pool->cts, idx);
12564 : 0 : return 0;
12565 : : }
12566 : :
12567 : : static int
12568 : 0 : flow_hw_conntrack_query(struct rte_eth_dev *dev, uint32_t queue, uint32_t idx,
12569 : : struct rte_flow_action_conntrack *profile,
12570 : : void *user_data, bool push,
12571 : : struct rte_flow_error *error)
12572 : : {
12573 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12574 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12575 : : struct mlx5_aso_ct_action *ct;
12576 : :
12577 [ # # ]: 0 : if (priv->shared_host)
12578 : 0 : return rte_flow_error_set(error, ENOTSUP,
12579 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12580 : : NULL,
12581 : : "CT query is not allowed to guest port");
12582 : 0 : ct = mlx5_ipool_get(pool->cts, idx);
12583 [ # # ]: 0 : if (!ct) {
12584 : 0 : return rte_flow_error_set(error, EINVAL,
12585 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12586 : : NULL,
12587 : : "Invalid CT query index");
12588 : : }
12589 : 0 : profile->peer_port = ct->peer;
12590 : 0 : profile->is_original_dir = ct->is_original;
12591 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, queue, ct, profile, user_data, push))
12592 : 0 : return rte_flow_error_set(error, EIO,
12593 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12594 : : NULL,
12595 : : "Failed to query CT context");
12596 : : return 0;
12597 : : }
12598 : :
12599 : :
12600 : : static int
12601 : 0 : flow_hw_conntrack_update(struct rte_eth_dev *dev, uint32_t queue,
12602 : : const struct rte_flow_modify_conntrack *action_conf,
12603 : : uint32_t idx, void *user_data, bool push,
12604 : : struct rte_flow_error *error)
12605 : : {
12606 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12607 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12608 : : struct mlx5_aso_ct_action *ct;
12609 : : const struct rte_flow_action_conntrack *new_prf;
12610 : : int ret = 0;
12611 : :
12612 [ # # ]: 0 : if (priv->shared_host)
12613 : 0 : return rte_flow_error_set(error, ENOTSUP,
12614 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12615 : : NULL,
12616 : : "CT update is not allowed to guest port");
12617 : 0 : ct = mlx5_ipool_get(pool->cts, idx);
12618 [ # # ]: 0 : if (!ct) {
12619 : 0 : return rte_flow_error_set(error, EINVAL,
12620 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12621 : : NULL,
12622 : : "Invalid CT update index");
12623 : : }
12624 : 0 : new_prf = &action_conf->new_ct;
12625 [ # # ]: 0 : if (action_conf->direction)
12626 : 0 : ct->is_original = !!new_prf->is_original_dir;
12627 [ # # ]: 0 : if (action_conf->state) {
12628 : : /* Only validate the profile when it needs to be updated. */
12629 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
12630 [ # # ]: 0 : if (ret)
12631 : : return ret;
12632 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, queue, ct, new_prf,
12633 : : user_data, push);
12634 [ # # ]: 0 : if (ret)
12635 : 0 : return rte_flow_error_set(error, EIO,
12636 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12637 : : NULL,
12638 : : "Failed to send CT context update WQE");
12639 [ # # ]: 0 : if (queue != MLX5_HW_INV_QUEUE)
12640 : : return 0;
12641 : : /* Block until ready or a failure in synchronous mode. */
12642 : 0 : ret = mlx5_aso_ct_available(priv->sh, queue, ct);
12643 [ # # ]: 0 : if (ret)
12644 : 0 : rte_flow_error_set(error, rte_errno,
12645 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12646 : : NULL,
12647 : : "Timeout to get the CT update");
12648 : : }
12649 : : return ret;
12650 : : }
12651 : :
12652 : : static struct rte_flow_action_handle *
12653 : 0 : flow_hw_conntrack_create(struct rte_eth_dev *dev, uint32_t queue,
12654 : : const struct rte_flow_action_conntrack *pro,
12655 : : void *user_data, bool push,
12656 : : struct rte_flow_error *error)
12657 : : {
12658 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12659 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12660 : : struct mlx5_aso_ct_action *ct;
12661 : 0 : uint32_t ct_idx = 0;
12662 : : int ret;
12663 : : bool async = !!(queue != MLX5_HW_INV_QUEUE);
12664 : :
12665 [ # # ]: 0 : if (priv->shared_host) {
12666 : 0 : rte_flow_error_set(error, ENOTSUP,
12667 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12668 : : NULL,
12669 : : "CT create is not allowed to guest port");
12670 : 0 : return NULL;
12671 : : }
12672 [ # # ]: 0 : if (!pool) {
12673 : 0 : rte_flow_error_set(error, EINVAL,
12674 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12675 : : "CT is not enabled");
12676 : 0 : return 0;
12677 : : }
12678 : 0 : ct = mlx5_ipool_zmalloc(pool->cts, &ct_idx);
12679 [ # # ]: 0 : if (!ct) {
12680 : 0 : rte_flow_error_set(error, rte_errno,
12681 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12682 : : "Failed to allocate CT object");
12683 : 0 : return 0;
12684 : : }
12685 : 0 : ct->offset = ct_idx - 1;
12686 : 0 : ct->is_original = !!pro->is_original_dir;
12687 : 0 : ct->peer = pro->peer_port;
12688 : 0 : ct->pool = pool;
12689 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(priv->sh, queue, ct, pro, user_data, push)) {
12690 : 0 : mlx5_ipool_free(pool->cts, ct_idx);
12691 : 0 : rte_flow_error_set(error, EBUSY,
12692 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12693 : : "Failed to update CT");
12694 : 0 : return 0;
12695 : : }
12696 [ # # ]: 0 : if (!async) {
12697 : 0 : ret = mlx5_aso_ct_available(priv->sh, queue, ct);
12698 [ # # ]: 0 : if (ret) {
12699 : 0 : mlx5_ipool_free(pool->cts, ct_idx);
12700 : 0 : rte_flow_error_set(error, rte_errno,
12701 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12702 : : NULL,
12703 : : "Timeout to get the CT update");
12704 : 0 : return 0;
12705 : : }
12706 : : }
12707 : 0 : return MLX5_INDIRECT_ACT_HWS_CT_GEN_IDX(ct_idx);
12708 : : }
12709 : :
12710 : : /**
12711 : : * Validate shared action.
12712 : : *
12713 : : * @param[in] dev
12714 : : * Pointer to the rte_eth_dev structure.
12715 : : * @param[in] queue
12716 : : * Which queue to be used.
12717 : : * @param[in] attr
12718 : : * Operation attribute.
12719 : : * @param[in] conf
12720 : : * Indirect action configuration.
12721 : : * @param[in] action
12722 : : * rte_flow action detail.
12723 : : * @param[in] user_data
12724 : : * Pointer to the user_data.
12725 : : * @param[out] error
12726 : : * Pointer to error structure.
12727 : : *
12728 : : * @return
12729 : : * 0 on success, otherwise negative errno value.
12730 : : */
12731 : : static int
12732 : 0 : flow_hw_action_handle_validate(struct rte_eth_dev *dev, uint32_t queue,
12733 : : const struct rte_flow_op_attr *attr,
12734 : : const struct rte_flow_indir_action_conf *conf,
12735 : : const struct rte_flow_action *action,
12736 : : void *user_data,
12737 : : struct rte_flow_error *error)
12738 : : {
12739 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12740 : :
12741 : : RTE_SET_USED(attr);
12742 : : RTE_SET_USED(queue);
12743 : : RTE_SET_USED(user_data);
12744 [ # # # # : 0 : switch (action->type) {
# # # ]
12745 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
12746 [ # # ]: 0 : if (!priv->hws_age_req) {
12747 [ # # ]: 0 : if (flow_hw_allocate_actions(dev, MLX5_FLOW_ACTION_AGE,
12748 : : error))
12749 : 0 : return rte_flow_error_set
12750 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
12751 : : NULL, "aging pool not initialized");
12752 : : }
12753 : : break;
12754 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
12755 [ # # ]: 0 : if (!priv->hws_cpool) {
12756 [ # # ]: 0 : if (flow_hw_allocate_actions(dev, MLX5_FLOW_ACTION_COUNT,
12757 : : error))
12758 : 0 : return rte_flow_error_set
12759 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
12760 : : NULL, "counters pool not initialized");
12761 : : }
12762 : : break;
12763 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12764 [ # # ]: 0 : if (priv->hws_ctpool == NULL) {
12765 [ # # ]: 0 : if (flow_hw_allocate_actions(dev, MLX5_FLOW_ACTION_CT,
12766 : : error))
12767 : 0 : return rte_flow_error_set
12768 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
12769 : : NULL, "CT pool not initialized");
12770 : : }
12771 : 0 : return mlx5_validate_action_ct(dev, action->conf, error);
12772 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
12773 : 0 : return flow_hw_validate_action_meter_mark(dev, action, true, error);
12774 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
12775 : 0 : return mlx5_flow_dv_action_validate(dev, conf, action, error);
12776 : : case RTE_FLOW_ACTION_TYPE_QUOTA:
12777 : : return 0;
12778 : 0 : default:
12779 : 0 : return rte_flow_error_set(error, ENOTSUP,
12780 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12781 : : "action type not supported");
12782 : : }
12783 : : return 0;
12784 : : }
12785 : :
12786 : : static __rte_always_inline bool
12787 : : flow_hw_action_push(const struct rte_flow_op_attr *attr)
12788 : : {
12789 [ # # # # : 0 : return attr ? !attr->postpone : true;
# # # # #
# # # #
# ]
12790 : : }
12791 : :
12792 : : static __rte_always_inline struct mlx5_hw_q_job *
12793 : : flow_hw_action_job_init(struct mlx5_priv *priv, uint32_t queue,
12794 : : const struct rte_flow_action_handle *handle,
12795 : : void *user_data, void *query_data,
12796 : : enum mlx5_hw_job_type type,
12797 : : enum mlx5_hw_indirect_type indirect_type,
12798 : : struct rte_flow_error *error)
12799 : : {
12800 : : struct mlx5_hw_q_job *job;
12801 : :
12802 [ # # # # : 0 : if (queue == MLX5_HW_INV_QUEUE)
# # # # #
# # # #
# ]
12803 [ # # # # : 0 : queue = CTRL_QUEUE_ID(priv);
# # # # #
# # # ]
12804 : : job = flow_hw_job_get(priv, queue);
12805 [ # # # # : 0 : if (!job) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
12806 : 0 : rte_flow_error_set(error, ENOMEM,
12807 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
12808 : : "Action destroy failed due to queue full.");
12809 : 0 : return NULL;
12810 : : }
12811 : 0 : job->type = type;
12812 : 0 : job->action = handle;
12813 : 0 : job->user_data = user_data;
12814 : 0 : job->query.user = query_data;
12815 [ # # # # : 0 : job->indirect_type = indirect_type;
# # # # #
# # # ]
12816 : 0 : return job;
12817 : : }
12818 : :
12819 : : struct mlx5_hw_q_job *
12820 [ # # ]: 0 : mlx5_flow_action_job_init(struct mlx5_priv *priv, uint32_t queue,
12821 : : const struct rte_flow_action_handle *handle,
12822 : : void *user_data, void *query_data,
12823 : : enum mlx5_hw_job_type type,
12824 : : struct rte_flow_error *error)
12825 : : {
12826 : 0 : return flow_hw_action_job_init(priv, queue, handle, user_data, query_data,
12827 : : type, MLX5_HW_INDIRECT_TYPE_LEGACY, error);
12828 : : }
12829 : :
12830 : : static __rte_always_inline void
12831 : : flow_hw_action_finalize(struct rte_eth_dev *dev, uint32_t queue,
12832 : : struct mlx5_hw_q_job *job,
12833 : : bool push, bool aso, bool status)
12834 : : {
12835 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12836 : :
12837 [ # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE)
12838 : 0 : queue = CTRL_QUEUE_ID(priv);
12839 [ # # # # : 0 : if (likely(status)) {
# # # # #
# # # ]
12840 : : /* 1. add new job to a queue */
12841 [ # # # # : 0 : if (!aso)
# # # # #
# ]
12842 [ # # # # : 0 : rte_ring_enqueue(push ?
# # # # #
# # # #
# ]
12843 : 0 : priv->hw_q[queue].indir_cq :
12844 : 0 : priv->hw_q[queue].indir_iq,
12845 : : job);
12846 : : /* 2. send pending jobs */
12847 [ # # # # : 0 : if (push)
# # # # #
# # # #
# ]
12848 : 0 : __flow_hw_push_action(dev, queue);
12849 : : } else {
12850 : : flow_hw_job_put(priv, job, queue);
12851 : : }
12852 : : }
12853 : :
12854 : : /**
12855 : : * Create shared action.
12856 : : *
12857 : : * @param[in] dev
12858 : : * Pointer to the rte_eth_dev structure.
12859 : : * @param[in] queue
12860 : : * Which queue to be used.
12861 : : * @param[in] attr
12862 : : * Operation attribute.
12863 : : * @param[in] conf
12864 : : * Indirect action configuration.
12865 : : * @param[in] action
12866 : : * rte_flow action detail.
12867 : : * @param[in] user_data
12868 : : * Pointer to the user_data.
12869 : : * @param[out] error
12870 : : * Pointer to error structure.
12871 : : *
12872 : : * @return
12873 : : * Action handle on success, NULL otherwise and rte_errno is set.
12874 : : */
12875 : : static struct rte_flow_action_handle *
12876 : 0 : flow_hw_action_handle_create(struct rte_eth_dev *dev, uint32_t queue,
12877 : : const struct rte_flow_op_attr *attr,
12878 : : const struct rte_flow_indir_action_conf *conf,
12879 : : const struct rte_flow_action *action,
12880 : : void *user_data,
12881 : : struct rte_flow_error *error)
12882 : : {
12883 : : struct rte_flow_action_handle *handle = NULL;
12884 : : struct mlx5_hw_q_job *job = NULL;
12885 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
12886 : : const struct rte_flow_action_age *age;
12887 : : struct mlx5_aso_mtr *aso_mtr = NULL;
12888 : : cnt_id_t cnt_id;
12889 : : uint32_t age_idx;
12890 : : bool push = flow_hw_action_push(attr);
12891 : : bool aso = false;
12892 : 0 : bool force_job = action->type == RTE_FLOW_ACTION_TYPE_METER_MARK;
12893 : : int ret;
12894 : :
12895 [ # # ]: 0 : if (!mlx5_hw_ctx_validate(dev, error))
12896 : : return NULL;
12897 [ # # ]: 0 : if (attr || force_job) {
12898 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
12899 : : NULL, MLX5_HW_Q_JOB_TYPE_CREATE,
12900 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
12901 : : if (!job)
12902 : 0 : return NULL;
12903 : : }
12904 [ # # # # : 0 : switch (action->type) {
# # # ]
12905 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
12906 [ # # ]: 0 : if (priv->hws_strict_queue) {
12907 : 0 : struct mlx5_age_info *info = GET_PORT_AGE_INFO(priv);
12908 : :
12909 [ # # ]: 0 : if (queue >= info->hw_q_age->nb_rings) {
12910 : 0 : rte_flow_error_set(error, EINVAL,
12911 : : RTE_FLOW_ERROR_TYPE_ACTION,
12912 : : NULL,
12913 : : "Invalid queue ID for indirect AGE.");
12914 : 0 : rte_errno = EINVAL;
12915 : 0 : return NULL;
12916 : : }
12917 : : }
12918 : 0 : age = action->conf;
12919 : 0 : age_idx = mlx5_hws_age_action_create(priv, queue, true, age,
12920 : : 0, error);
12921 [ # # ]: 0 : if (age_idx == 0) {
12922 : 0 : rte_flow_error_set(error, ENODEV,
12923 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12924 : : "AGE are not configured!");
12925 : : } else {
12926 : 0 : age_idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
12927 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
12928 : 0 : handle =
12929 : 0 : (struct rte_flow_action_handle *)(uintptr_t)age_idx;
12930 : : }
12931 : : break;
12932 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
12933 [ # # ]: 0 : if (mlx5_hws_cnt_shared_get(priv->hws_cpool, &cnt_id, 0))
12934 : 0 : rte_flow_error_set(error, ENODEV,
12935 : : RTE_FLOW_ERROR_TYPE_ACTION,
12936 : : NULL,
12937 : : "counter are not configured!");
12938 : : else
12939 : 0 : handle = (struct rte_flow_action_handle *)
12940 : 0 : (uintptr_t)cnt_id;
12941 : : break;
12942 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12943 : : aso = true;
12944 : 0 : handle = flow_hw_conntrack_create(dev, queue, action->conf, job,
12945 : : push, error);
12946 : 0 : break;
12947 [ # # ]: 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
12948 : : aso = true;
12949 : : ret = flow_hw_meter_mark_alloc(dev, queue, action, job, push, &aso_mtr, error);
12950 [ # # ]: 0 : if (ret) {
12951 [ # # ]: 0 : if (ret != -EIO) {
12952 [ # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE)
12953 : 0 : queue = CTRL_QUEUE_ID(priv);
12954 : : flow_hw_job_put(priv, job, queue);
12955 : : }
12956 : : break;
12957 : : }
12958 : 0 : handle = (void *)(uintptr_t)job->action;
12959 : 0 : break;
12960 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
12961 : 0 : handle = mlx5_flow_dv_action_create(dev, conf, action, error);
12962 : 0 : break;
12963 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
12964 : : aso = true;
12965 : 0 : handle = mlx5_quota_alloc(dev, queue, action->conf,
12966 : : job, push, error);
12967 : 0 : break;
12968 : 0 : default:
12969 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
12970 : : NULL, "action type not supported");
12971 : 0 : break;
12972 : : }
12973 [ # # # # ]: 0 : if (job && (!force_job || handle)) {
12974 [ # # ]: 0 : job->action = handle;
12975 : : flow_hw_action_finalize(dev, queue, job, push, aso,
12976 : : handle != NULL);
12977 : : }
12978 : : return handle;
12979 : : }
12980 : :
12981 : : static int
12982 : 0 : mlx5_flow_update_meter_mark(struct rte_eth_dev *dev, uint32_t queue,
12983 : : const struct rte_flow_update_meter_mark *upd_meter_mark,
12984 : : uint32_t idx, bool push,
12985 : : struct mlx5_hw_q_job *job, struct rte_flow_error *error)
12986 : : {
12987 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12988 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
12989 : : const struct rte_flow_action_meter_mark *meter_mark = &upd_meter_mark->meter_mark;
12990 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
12991 : : struct mlx5_flow_meter_info *fm;
12992 : :
12993 [ # # ]: 0 : if (!aso_mtr)
12994 : 0 : return rte_flow_error_set(error, EINVAL,
12995 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12996 : : NULL, "Invalid meter_mark update index");
12997 : : fm = &aso_mtr->fm;
12998 [ # # ]: 0 : if (upd_meter_mark->profile_valid)
12999 : 0 : fm->profile = (struct mlx5_flow_meter_profile *)
13000 : 0 : (meter_mark->profile);
13001 [ # # ]: 0 : if (upd_meter_mark->color_mode_valid)
13002 : 0 : fm->color_aware = meter_mark->color_mode;
13003 [ # # ]: 0 : if (upd_meter_mark->state_valid)
13004 : 0 : fm->is_enable = meter_mark->state;
13005 [ # # ]: 0 : aso_mtr->state = (queue == MLX5_HW_INV_QUEUE) ?
13006 : : ASO_METER_WAIT : ASO_METER_WAIT_ASYNC;
13007 : : /* Update ASO flow meter by wqe. */
13008 [ # # ]: 0 : if (mlx5_aso_meter_update_by_wqe(priv, queue,
13009 : : aso_mtr, &priv->mtr_bulk, job, push))
13010 : 0 : return rte_flow_error_set(error, EINVAL,
13011 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13012 : : NULL, "Unable to update ASO meter WQE");
13013 : : /* Wait for ASO object completion. */
13014 [ # # # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE &&
13015 : 0 : mlx5_aso_mtr_wait(priv, aso_mtr, true))
13016 : 0 : return rte_flow_error_set(error, EINVAL,
13017 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13018 : : NULL, "Unable to wait for ASO meter CQE");
13019 : : return 0;
13020 : : }
13021 : :
13022 : : /**
13023 : : * Update shared action.
13024 : : *
13025 : : * @param[in] dev
13026 : : * Pointer to the rte_eth_dev structure.
13027 : : * @param[in] queue
13028 : : * Which queue to be used.
13029 : : * @param[in] attr
13030 : : * Operation attribute.
13031 : : * @param[in] handle
13032 : : * Action handle to be updated.
13033 : : * @param[in] update
13034 : : * Update value.
13035 : : * @param[in] user_data
13036 : : * Pointer to the user_data.
13037 : : * @param[out] error
13038 : : * Pointer to error structure.
13039 : : *
13040 : : * @return
13041 : : * 0 on success, negative value otherwise and rte_errno is set.
13042 : : */
13043 : : static int
13044 : 0 : flow_hw_action_handle_update(struct rte_eth_dev *dev, uint32_t queue,
13045 : : const struct rte_flow_op_attr *attr,
13046 : : struct rte_flow_action_handle *handle,
13047 : : const void *update,
13048 : : void *user_data,
13049 : : struct rte_flow_error *error)
13050 : : {
13051 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13052 : : const struct rte_flow_modify_conntrack *ct_conf =
13053 : : (const struct rte_flow_modify_conntrack *)update;
13054 : : struct mlx5_hw_q_job *job = NULL;
13055 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13056 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13057 [ # # ]: 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
13058 : : int ret = 0;
13059 : : bool push = flow_hw_action_push(attr);
13060 : : bool aso = false;
13061 : 0 : bool force_job = type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK;
13062 : :
13063 [ # # ]: 0 : if (attr || force_job) {
13064 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13065 : : NULL, MLX5_HW_Q_JOB_TYPE_UPDATE,
13066 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13067 : : if (!job)
13068 : 0 : return -rte_errno;
13069 : : }
13070 [ # # # # : 0 : switch (type) {
# # ]
13071 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13072 : 0 : ret = mlx5_hws_age_action_update(priv, idx, update, error);
13073 : 0 : break;
13074 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
13075 [ # # ]: 0 : if (ct_conf->state)
13076 : : aso = true;
13077 : 0 : ret = flow_hw_conntrack_update(dev, queue, update, idx,
13078 : : job, push, error);
13079 : 0 : break;
13080 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
13081 : : aso = true;
13082 : 0 : ret = mlx5_flow_update_meter_mark(dev, queue, update, idx, push,
13083 : : job, error);
13084 : 0 : break;
13085 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
13086 : 0 : ret = mlx5_flow_dv_action_update(dev, handle, update, error);
13087 : 0 : break;
13088 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13089 : : aso = true;
13090 : 0 : ret = mlx5_quota_query_update(dev, queue, handle, update, NULL,
13091 : : job, push, error);
13092 : 0 : break;
13093 : 0 : default:
13094 : : ret = -ENOTSUP;
13095 : 0 : rte_flow_error_set(error, ENOTSUP,
13096 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13097 : : "action type not supported");
13098 : 0 : break;
13099 : : }
13100 [ # # ]: 0 : if (job && !force_job)
13101 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13102 : : return ret;
13103 : : }
13104 : :
13105 : : /**
13106 : : * Destroy shared action.
13107 : : *
13108 : : * @param[in] dev
13109 : : * Pointer to the rte_eth_dev structure.
13110 : : * @param[in] queue
13111 : : * Which queue to be used.
13112 : : * @param[in] attr
13113 : : * Operation attribute.
13114 : : * @param[in] handle
13115 : : * Action handle to be destroyed.
13116 : : * @param[in] user_data
13117 : : * Pointer to the user_data.
13118 : : * @param[out] error
13119 : : * Pointer to error structure.
13120 : : *
13121 : : * @return
13122 : : * 0 on success, negative value otherwise and rte_errno is set.
13123 : : */
13124 : : static int
13125 : 0 : flow_hw_action_handle_destroy(struct rte_eth_dev *dev, uint32_t queue,
13126 : : const struct rte_flow_op_attr *attr,
13127 : : struct rte_flow_action_handle *handle,
13128 : : void *user_data,
13129 : : struct rte_flow_error *error)
13130 : : {
13131 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13132 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13133 : 0 : uint32_t age_idx = act_idx & MLX5_HWS_AGE_IDX_MASK;
13134 : : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
13135 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13136 [ # # ]: 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
13137 : : struct mlx5_hw_q_job *job = NULL;
13138 : : struct mlx5_aso_mtr *aso_mtr;
13139 : : struct mlx5_flow_meter_info *fm;
13140 : : bool push = flow_hw_action_push(attr);
13141 : : bool aso = false;
13142 : : int ret = 0;
13143 : 0 : bool force_job = type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK;
13144 : :
13145 [ # # ]: 0 : if (attr || force_job) {
13146 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13147 : : NULL, MLX5_HW_Q_JOB_TYPE_DESTROY,
13148 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13149 : : if (!job)
13150 : 0 : return -rte_errno;
13151 : : }
13152 [ # # # # : 0 : switch (type) {
# # # ]
13153 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13154 : 0 : ret = mlx5_hws_age_action_destroy(priv, age_idx, error);
13155 : 0 : break;
13156 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
13157 [ # # ]: 0 : age_idx = mlx5_hws_cnt_age_get(priv->hws_cpool, act_idx);
13158 [ # # ]: 0 : if (age_idx != 0)
13159 : : /*
13160 : : * If this counter belongs to indirect AGE, here is the
13161 : : * time to update the AGE.
13162 : : */
13163 : : mlx5_hws_age_nb_cnt_decrease(priv, age_idx);
13164 [ # # ]: 0 : mlx5_hws_cnt_shared_put(priv->hws_cpool, &act_idx);
13165 : : break;
13166 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
13167 : 0 : ret = flow_hw_conntrack_destroy(dev, idx, error);
13168 : 0 : break;
13169 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
13170 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
13171 [ # # ]: 0 : if (!aso_mtr) {
13172 : : ret = -EINVAL;
13173 : 0 : rte_flow_error_set(error, EINVAL,
13174 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13175 : : NULL, "Invalid meter_mark destroy index");
13176 : 0 : break;
13177 : : }
13178 : : fm = &aso_mtr->fm;
13179 : 0 : fm->is_enable = 0;
13180 : : /* Update ASO flow meter by wqe. */
13181 [ # # ]: 0 : if (mlx5_aso_meter_update_by_wqe(priv, queue, aso_mtr,
13182 : : &priv->mtr_bulk, job, push)) {
13183 : : ret = -EINVAL;
13184 : 0 : rte_flow_error_set(error, EINVAL,
13185 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13186 : : NULL, "Unable to update ASO meter WQE");
13187 : 0 : break;
13188 : : }
13189 : : /* Wait for ASO object completion. */
13190 [ # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE) {
13191 [ # # ]: 0 : if (mlx5_aso_mtr_wait(priv, aso_mtr, true)) {
13192 : : ret = -EINVAL;
13193 : 0 : rte_flow_error_set(error, EINVAL,
13194 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13195 : : NULL, "Unable to wait for ASO meter CQE");
13196 : : }
13197 : 0 : mlx5_ipool_free(pool->idx_pool, idx);
13198 [ # # ]: 0 : if (ret < 0)
13199 : : break;
13200 : : }
13201 : : aso = true;
13202 : : break;
13203 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
13204 : 0 : ret = mlx5_flow_dv_action_destroy(dev, handle, error);
13205 : 0 : break;
13206 : : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13207 : : break;
13208 : 0 : default:
13209 : : ret = -ENOTSUP;
13210 : 0 : rte_flow_error_set(error, ENOTSUP,
13211 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13212 : : "action type not supported");
13213 : 0 : break;
13214 : : }
13215 [ # # ]: 0 : if (job && !force_job)
13216 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13217 : : return ret;
13218 : : }
13219 : :
13220 : : static int
13221 : 0 : flow_hw_query_counter(const struct rte_eth_dev *dev, uint32_t counter,
13222 : : void *data, struct rte_flow_error *error)
13223 : : {
13224 : : struct mlx5_hws_cnt_pool *hpool;
13225 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13226 : : struct mlx5_hws_cnt *cnt;
13227 : : struct rte_flow_query_count *qc = data;
13228 : : uint32_t iidx;
13229 : : uint64_t pkts, bytes;
13230 : :
13231 [ # # ]: 0 : if (!mlx5_hws_cnt_id_valid(counter))
13232 : 0 : return rte_flow_error_set(error, EINVAL,
13233 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13234 : : "counter are not available");
13235 [ # # ]: 0 : hpool = mlx5_hws_cnt_host_pool(priv->hws_cpool);
13236 : : iidx = mlx5_hws_cnt_iidx(hpool, counter);
13237 : 0 : cnt = &hpool->pool[iidx];
13238 : : __hws_cnt_query_raw(priv->hws_cpool, counter, &pkts, &bytes);
13239 : 0 : qc->hits_set = 1;
13240 : 0 : qc->bytes_set = 1;
13241 : 0 : qc->hits = pkts - cnt->reset.hits;
13242 : 0 : qc->bytes = bytes - cnt->reset.bytes;
13243 [ # # ]: 0 : if (qc->reset) {
13244 : 0 : cnt->reset.bytes = bytes;
13245 : 0 : cnt->reset.hits = pkts;
13246 : : }
13247 : : return 0;
13248 : : }
13249 : :
13250 : : /**
13251 : : * Query a flow rule AGE action for aging information.
13252 : : *
13253 : : * @param[in] dev
13254 : : * Pointer to Ethernet device.
13255 : : * @param[in] age_idx
13256 : : * Index of AGE action parameter.
13257 : : * @param[out] data
13258 : : * Data retrieved by the query.
13259 : : * @param[out] error
13260 : : * Perform verbose error reporting if not NULL.
13261 : : *
13262 : : * @return
13263 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13264 : : */
13265 : : static int
13266 : 0 : flow_hw_query_age(const struct rte_eth_dev *dev, uint32_t age_idx, void *data,
13267 : : struct rte_flow_error *error)
13268 : : {
13269 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13270 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
13271 : 0 : struct mlx5_indexed_pool *ipool = age_info->ages_ipool;
13272 : 0 : struct mlx5_hws_age_param *param = mlx5_ipool_get(ipool, age_idx);
13273 : : struct rte_flow_query_age *resp = data;
13274 : :
13275 [ # # # # ]: 0 : if (!param || !param->timeout)
13276 : 0 : return rte_flow_error_set(error, EINVAL,
13277 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13278 : : NULL, "age data not available");
13279 [ # # # ]: 0 : switch (rte_atomic_load_explicit(¶m->state, rte_memory_order_relaxed)) {
13280 : 0 : case HWS_AGE_AGED_OUT_REPORTED:
13281 : : case HWS_AGE_AGED_OUT_NOT_REPORTED:
13282 : 0 : resp->aged = 1;
13283 : 0 : break;
13284 : 0 : case HWS_AGE_CANDIDATE:
13285 : : case HWS_AGE_CANDIDATE_INSIDE_RING:
13286 : 0 : resp->aged = 0;
13287 : 0 : break;
13288 : : case HWS_AGE_FREE:
13289 : : /*
13290 : : * When state is FREE the flow itself should be invalid.
13291 : : * Fall-through.
13292 : : */
13293 : : default:
13294 : : MLX5_ASSERT(0);
13295 : : break;
13296 : : }
13297 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
13298 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
13299 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
13300 : : (¶m->sec_since_last_hit, rte_memory_order_relaxed);
13301 : : return 0;
13302 : : }
13303 : :
13304 : : static int
13305 : 0 : flow_hw_query(struct rte_eth_dev *dev, struct rte_flow *flow,
13306 : : const struct rte_flow_action *actions, void *data,
13307 : : struct rte_flow_error *error)
13308 : : {
13309 : : int ret = -EINVAL;
13310 : : struct rte_flow_hw *hw_flow = (struct rte_flow_hw *)flow;
13311 : : struct rte_flow_hw_aux *aux;
13312 : :
13313 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
13314 [ # # # # ]: 0 : switch (actions->type) {
13315 : : case RTE_FLOW_ACTION_TYPE_VOID:
13316 : : break;
13317 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13318 [ # # ]: 0 : if (!(hw_flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID))
13319 : 0 : return rte_flow_error_set(error, EINVAL,
13320 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13321 : : "counter not defined in the rule");
13322 : 0 : ret = flow_hw_query_counter(dev, hw_flow->cnt_id, data,
13323 : : error);
13324 : 0 : break;
13325 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
13326 [ # # ]: 0 : if (!(hw_flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX))
13327 : 0 : return rte_flow_error_set(error, EINVAL,
13328 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13329 : : "age data not available");
13330 [ # # ]: 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, hw_flow);
13331 : 0 : ret = flow_hw_query_age(dev, mlx5_flow_hw_aux_get_age_idx(hw_flow, aux),
13332 : : data, error);
13333 : 0 : break;
13334 : 0 : default:
13335 : 0 : return rte_flow_error_set(error, ENOTSUP,
13336 : : RTE_FLOW_ERROR_TYPE_ACTION,
13337 : : actions,
13338 : : "action not supported");
13339 : : }
13340 : : }
13341 : : return ret;
13342 : : }
13343 : :
13344 : : /**
13345 : : * Validate indirect action.
13346 : : *
13347 : : * @param[in] dev
13348 : : * Pointer to the Ethernet device structure.
13349 : : * @param[in] conf
13350 : : * Shared action configuration.
13351 : : * @param[in] action
13352 : : * Action specification used to create indirect action.
13353 : : * @param[out] error
13354 : : * Perform verbose error reporting if not NULL. Initialized in case of
13355 : : * error only.
13356 : : *
13357 : : * @return
13358 : : * 0 on success, otherwise negative errno value.
13359 : : */
13360 : : static int
13361 : 0 : flow_hw_action_validate(struct rte_eth_dev *dev,
13362 : : const struct rte_flow_indir_action_conf *conf,
13363 : : const struct rte_flow_action *action,
13364 : : struct rte_flow_error *err)
13365 : : {
13366 : 0 : struct rte_flow_error shadow_error = {0, };
13367 : :
13368 [ # # ]: 0 : if (!err)
13369 : : err = &shadow_error;
13370 : 0 : return flow_hw_action_handle_validate(dev, MLX5_HW_INV_QUEUE, NULL,
13371 : : conf, action, NULL, err);
13372 : : }
13373 : :
13374 : : /**
13375 : : * Create indirect action.
13376 : : *
13377 : : * @param[in] dev
13378 : : * Pointer to the Ethernet device structure.
13379 : : * @param[in] conf
13380 : : * Shared action configuration.
13381 : : * @param[in] action
13382 : : * Action specification used to create indirect action.
13383 : : * @param[out] error
13384 : : * Perform verbose error reporting if not NULL. Initialized in case of
13385 : : * error only.
13386 : : *
13387 : : * @return
13388 : : * A valid shared action handle in case of success, NULL otherwise and
13389 : : * rte_errno is set.
13390 : : */
13391 : : static struct rte_flow_action_handle *
13392 : 0 : flow_hw_action_create(struct rte_eth_dev *dev,
13393 : : const struct rte_flow_indir_action_conf *conf,
13394 : : const struct rte_flow_action *action,
13395 : : struct rte_flow_error *err)
13396 : : {
13397 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13398 : :
13399 [ # # # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_AGE && priv->hws_strict_queue) {
13400 : 0 : rte_flow_error_set(err, EINVAL, RTE_FLOW_ERROR_TYPE_STATE, NULL,
13401 : : "Cannot create age action synchronously with strict queueing");
13402 : 0 : return NULL;
13403 : : }
13404 : :
13405 : 0 : return flow_hw_action_handle_create(dev, MLX5_HW_INV_QUEUE,
13406 : : NULL, conf, action, NULL, err);
13407 : : }
13408 : :
13409 : : /**
13410 : : * Destroy the indirect action.
13411 : : * Release action related resources on the NIC and the memory.
13412 : : * Lock free, (mutex should be acquired by caller).
13413 : : * Dispatcher for action type specific call.
13414 : : *
13415 : : * @param[in] dev
13416 : : * Pointer to the Ethernet device structure.
13417 : : * @param[in] handle
13418 : : * The indirect action object handle to be removed.
13419 : : * @param[out] error
13420 : : * Perform verbose error reporting if not NULL. Initialized in case of
13421 : : * error only.
13422 : : *
13423 : : * @return
13424 : : * 0 on success, otherwise negative errno value.
13425 : : */
13426 : : static int
13427 : 0 : flow_hw_action_destroy(struct rte_eth_dev *dev,
13428 : : struct rte_flow_action_handle *handle,
13429 : : struct rte_flow_error *error)
13430 : : {
13431 : 0 : return flow_hw_action_handle_destroy(dev, MLX5_HW_INV_QUEUE,
13432 : : NULL, handle, NULL, error);
13433 : : }
13434 : :
13435 : : /**
13436 : : * Updates in place shared action configuration.
13437 : : *
13438 : : * @param[in] dev
13439 : : * Pointer to the Ethernet device structure.
13440 : : * @param[in] handle
13441 : : * The indirect action object handle to be updated.
13442 : : * @param[in] update
13443 : : * Action specification used to modify the action pointed by *handle*.
13444 : : * *update* could be of same type with the action pointed by the *handle*
13445 : : * handle argument, or some other structures like a wrapper, depending on
13446 : : * the indirect action type.
13447 : : * @param[out] error
13448 : : * Perform verbose error reporting if not NULL. Initialized in case of
13449 : : * error only.
13450 : : *
13451 : : * @return
13452 : : * 0 on success, otherwise negative errno value.
13453 : : */
13454 : : static int
13455 : 0 : flow_hw_action_update(struct rte_eth_dev *dev,
13456 : : struct rte_flow_action_handle *handle,
13457 : : const void *update,
13458 : : struct rte_flow_error *err)
13459 : : {
13460 : 0 : return flow_hw_action_handle_update(dev, MLX5_HW_INV_QUEUE,
13461 : : NULL, handle, update, NULL, err);
13462 : : }
13463 : :
13464 : : static int
13465 : 0 : flow_hw_action_handle_query(struct rte_eth_dev *dev, uint32_t queue,
13466 : : const struct rte_flow_op_attr *attr,
13467 : : const struct rte_flow_action_handle *handle,
13468 : : void *data, void *user_data,
13469 : : struct rte_flow_error *error)
13470 : : {
13471 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13472 : : struct mlx5_hw_q_job *job = NULL;
13473 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13474 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13475 [ # # ]: 0 : uint32_t idx = MLX5_INDIRECT_ACTION_IDX_GET(handle);
13476 : : uint32_t age_idx = act_idx & MLX5_HWS_AGE_IDX_MASK;
13477 : : int ret;
13478 : : bool push = flow_hw_action_push(attr);
13479 : : bool aso = false;
13480 : :
13481 [ # # ]: 0 : if (attr) {
13482 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13483 : : data, MLX5_HW_Q_JOB_TYPE_QUERY,
13484 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13485 : : if (!job)
13486 : 0 : return -rte_errno;
13487 : : }
13488 [ # # # # : 0 : switch (type) {
# ]
13489 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13490 : 0 : ret = flow_hw_query_age(dev, age_idx, data, error);
13491 : 0 : break;
13492 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
13493 : 0 : ret = flow_hw_query_counter(dev, act_idx, data, error);
13494 : 0 : break;
13495 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
13496 : : aso = true;
13497 [ # # ]: 0 : if (job)
13498 : 0 : job->query.user = data;
13499 : 0 : ret = flow_hw_conntrack_query(dev, queue, idx, data,
13500 : : job, push, error);
13501 : 0 : break;
13502 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13503 : : aso = true;
13504 : 0 : ret = mlx5_quota_query(dev, queue, handle, data,
13505 : : job, push, error);
13506 : 0 : break;
13507 : 0 : default:
13508 : : ret = -ENOTSUP;
13509 : 0 : rte_flow_error_set(error, ENOTSUP,
13510 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13511 : : "action type not supported");
13512 : 0 : break;
13513 : : }
13514 [ # # ]: 0 : if (job)
13515 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13516 : : return ret;
13517 : : }
13518 : :
13519 : : static int
13520 : 0 : flow_hw_async_action_handle_query_update
13521 : : (struct rte_eth_dev *dev, uint32_t queue,
13522 : : const struct rte_flow_op_attr *attr,
13523 : : struct rte_flow_action_handle *handle,
13524 : : const void *update, void *query,
13525 : : enum rte_flow_query_update_mode qu_mode,
13526 : : void *user_data, struct rte_flow_error *error)
13527 : : {
13528 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13529 : : bool push = flow_hw_action_push(attr);
13530 : : bool aso = false;
13531 : : struct mlx5_hw_q_job *job = NULL;
13532 : : int ret = 0;
13533 : :
13534 [ # # ]: 0 : if (attr) {
13535 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13536 : : query,
13537 : : MLX5_HW_Q_JOB_TYPE_UPDATE_QUERY,
13538 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13539 : : if (!job)
13540 : 0 : return -rte_errno;
13541 : : }
13542 [ # # ]: 0 : switch (MLX5_INDIRECT_ACTION_TYPE_GET(handle)) {
13543 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13544 [ # # ]: 0 : if (qu_mode != RTE_FLOW_QU_QUERY_FIRST) {
13545 : 0 : ret = rte_flow_error_set
13546 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
13547 : : NULL, "quota action must query before update");
13548 : 0 : break;
13549 : : }
13550 : : aso = true;
13551 : 0 : ret = mlx5_quota_query_update(dev, queue, handle,
13552 : : update, query, job, push, error);
13553 : 0 : break;
13554 : 0 : default:
13555 : 0 : ret = rte_flow_error_set(error, ENOTSUP,
13556 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL, "update and query not supportred");
13557 : : }
13558 [ # # ]: 0 : if (job)
13559 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13560 : : return ret;
13561 : : }
13562 : :
13563 : : static int
13564 : 0 : flow_hw_action_query(struct rte_eth_dev *dev,
13565 : : const struct rte_flow_action_handle *handle, void *data,
13566 : : struct rte_flow_error *error)
13567 : : {
13568 : 0 : return flow_hw_action_handle_query(dev, MLX5_HW_INV_QUEUE, NULL,
13569 : : handle, data, NULL, error);
13570 : : }
13571 : :
13572 : : static int
13573 : 0 : flow_hw_action_query_update(struct rte_eth_dev *dev,
13574 : : struct rte_flow_action_handle *handle,
13575 : : const void *update, void *query,
13576 : : enum rte_flow_query_update_mode qu_mode,
13577 : : struct rte_flow_error *error)
13578 : : {
13579 : 0 : return flow_hw_async_action_handle_query_update(dev, MLX5_HW_INV_QUEUE,
13580 : : NULL, handle, update,
13581 : : query, qu_mode, NULL,
13582 : : error);
13583 : : }
13584 : :
13585 : : /**
13586 : : * Get aged-out flows of a given port on the given HWS flow queue.
13587 : : *
13588 : : * @param[in] dev
13589 : : * Pointer to the Ethernet device structure.
13590 : : * @param[in] queue_id
13591 : : * Flow queue to query. Ignored when RTE_FLOW_PORT_FLAG_STRICT_QUEUE not set.
13592 : : * @param[in, out] contexts
13593 : : * The address of an array of pointers to the aged-out flows contexts.
13594 : : * @param[in] nb_contexts
13595 : : * The length of context array pointers.
13596 : : * @param[out] error
13597 : : * Perform verbose error reporting if not NULL. Initialized in case of
13598 : : * error only.
13599 : : *
13600 : : * @return
13601 : : * if nb_contexts is 0, return the amount of all aged contexts.
13602 : : * if nb_contexts is not 0 , return the amount of aged flows reported
13603 : : * in the context array, otherwise negative errno value.
13604 : : */
13605 : : static int
13606 : 0 : flow_hw_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
13607 : : void **contexts, uint32_t nb_contexts,
13608 : : struct rte_flow_error *error)
13609 : : {
13610 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13611 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
13612 : : struct rte_ring *r;
13613 : : int nb_flows = 0;
13614 : :
13615 [ # # ]: 0 : if (nb_contexts && !contexts)
13616 : 0 : return rte_flow_error_set(error, EINVAL,
13617 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13618 : : NULL, "empty context");
13619 [ # # ]: 0 : if (!priv->hws_age_req)
13620 : 0 : return rte_flow_error_set(error, ENOENT,
13621 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13622 : : NULL, "No aging initialized");
13623 [ # # ]: 0 : if (priv->hws_strict_queue) {
13624 : : /* Queue is invalid in sync query. Sync query and strict queueing is disallowed. */
13625 : : MLX5_ASSERT(queue_id != MLX5_HW_INV_QUEUE);
13626 [ # # ]: 0 : if (queue_id >= age_info->hw_q_age->nb_rings)
13627 : 0 : return rte_flow_error_set(error, EINVAL,
13628 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13629 : : NULL, "invalid queue id");
13630 : 0 : r = age_info->hw_q_age->aged_lists[queue_id];
13631 : : } else {
13632 : 0 : r = age_info->hw_age.aged_list;
13633 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
13634 : : }
13635 [ # # ]: 0 : if (nb_contexts == 0)
13636 : 0 : return rte_ring_count(r);
13637 [ # # ]: 0 : while ((uint32_t)nb_flows < nb_contexts) {
13638 : : uint32_t age_idx;
13639 : :
13640 : : if (rte_ring_dequeue_elem(r, &age_idx, sizeof(uint32_t)) < 0)
13641 : : break;
13642 : : /* get the AGE context if the aged-out index is still valid. */
13643 : 0 : contexts[nb_flows] = mlx5_hws_age_context_get(priv, age_idx);
13644 [ # # ]: 0 : if (!contexts[nb_flows])
13645 : 0 : continue;
13646 : 0 : nb_flows++;
13647 : : }
13648 : : return nb_flows;
13649 : : }
13650 : :
13651 : : /**
13652 : : * Get aged-out flows.
13653 : : *
13654 : : * This function is relevant only if RTE_FLOW_PORT_FLAG_STRICT_QUEUE isn't set.
13655 : : *
13656 : : * @param[in] dev
13657 : : * Pointer to the Ethernet device structure.
13658 : : * @param[in] contexts
13659 : : * The address of an array of pointers to the aged-out flows contexts.
13660 : : * @param[in] nb_contexts
13661 : : * The length of context array pointers.
13662 : : * @param[out] error
13663 : : * Perform verbose error reporting if not NULL. Initialized in case of
13664 : : * error only.
13665 : : *
13666 : : * @return
13667 : : * how many contexts get in success, otherwise negative errno value.
13668 : : * if nb_contexts is 0, return the amount of all aged contexts.
13669 : : * if nb_contexts is not 0 , return the amount of aged flows reported
13670 : : * in the context array.
13671 : : */
13672 : : static int
13673 : 0 : flow_hw_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
13674 : : uint32_t nb_contexts, struct rte_flow_error *error)
13675 : : {
13676 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13677 : :
13678 [ # # ]: 0 : if (priv->hws_strict_queue)
13679 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_STATE, NULL,
13680 : : "Cannot get aged flows synchronously with strict queueing");
13681 : :
13682 : 0 : return flow_hw_get_q_aged_flows(dev, MLX5_HW_INV_QUEUE, contexts, nb_contexts, error);
13683 : : }
13684 : : /**
13685 : : * Initialization function for non template API which calls
13686 : : * flow_hw_configure with default values.
13687 : : * Configure non queues cause 1 queue is configured by default for inner usage.
13688 : : *
13689 : : * @param[in] dev
13690 : : * Pointer to the Ethernet device structure.
13691 : : * @param[out] error
13692 : : * Pointer to the error structure.
13693 : : *
13694 : : * @return
13695 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13696 : : */
13697 : : int
13698 : 0 : mlx5_flow_hw_init(struct rte_eth_dev *dev,
13699 : : struct rte_flow_error *error)
13700 : : {
13701 : 0 : const struct rte_flow_port_attr port_attr = {0};
13702 : 0 : const struct rte_flow_queue_attr queue_attr = {.size = MLX5_NT_DEFAULT_QUEUE_SIZE};
13703 : 0 : const struct rte_flow_queue_attr *attr_list = &queue_attr;
13704 : :
13705 : : /**
13706 : : * If user uses template and non template API:
13707 : : * User will call flow_hw_configure and non template
13708 : : * API will use the allocated actions.
13709 : : * Init function will not call flow_hw_configure.
13710 : : *
13711 : : * If user uses only non template API's:
13712 : : * Init function will call flow_hw_configure.
13713 : : * It will not allocate memory for actions.
13714 : : * When needed allocation, it will handle same as for SWS today,
13715 : : * meaning using bulk allocations and resize as needed.
13716 : : */
13717 : : /* Configure hws with default values. */
13718 : 0 : DRV_LOG(DEBUG, "Apply default configuration, zero number of queues, inner control queue size is %u",
13719 : : MLX5_NT_DEFAULT_QUEUE_SIZE);
13720 : 0 : return __flow_hw_configure(dev, &port_attr, 0, &attr_list, true, error);
13721 : : }
13722 : :
13723 : 0 : static int flow_hw_prepare(struct rte_eth_dev *dev,
13724 : : const struct rte_flow_action actions[] __rte_unused,
13725 : : enum mlx5_flow_type type,
13726 : : struct rte_flow_hw **flow,
13727 : : struct rte_flow_error *error)
13728 : : {
13729 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13730 : 0 : uint32_t idx = 0;
13731 : :
13732 : : /*
13733 : : * Notice pool idx size = (sizeof(struct rte_flow_hw)
13734 : : * + sizeof(struct rte_flow_nt2hws)) for HWS mode.
13735 : : */
13736 : 0 : *flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
13737 [ # # ]: 0 : if (!(*flow))
13738 : 0 : return rte_flow_error_set(error, ENOMEM,
13739 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13740 : : "cannot allocate flow memory");
13741 : : /* Allocating 2 structures in one pool slot, updating nt2hw pointer.*/
13742 : 0 : (*flow)->nt2hws = (struct rte_flow_nt2hws *)
13743 : 0 : ((uintptr_t)(*flow) + sizeof(struct rte_flow_hw));
13744 : 0 : (*flow)->idx = idx;
13745 : 0 : (*flow)->nt2hws->flow_aux = (struct rte_flow_hw_aux *)
13746 : 0 : ((uintptr_t)((*flow)->nt2hws) + sizeof(struct rte_flow_nt2hws));
13747 : :
13748 [ # # ]: 0 : if (!(*flow)->nt2hws->flow_aux)
13749 : 0 : return rte_flow_error_set(error, ENOMEM,
13750 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13751 : : "cannot allocate flow aux memory");
13752 : : return 0;
13753 : : }
13754 : :
13755 : : static inline void
13756 : 0 : flow_hw_set_dv_fields(struct rte_flow_template_table_attr *table_attr, uint32_t fdb_unified_en,
13757 : : bool *root, uint8_t *ft_type, uint64_t *flags)
13758 : : {
13759 [ # # ]: 0 : if (table_attr->flow_attr.transfer)
13760 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13761 : : else
13762 : 0 : *ft_type = table_attr->flow_attr.egress ?
13763 : 0 : MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
13764 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13765 : 0 : uint32_t group = table_attr->flow_attr.group;
13766 : 0 : *root = group ? 0 : 1;
13767 : 0 : *flags = mlx5_hw_act_flag[!!group][get_mlx5dr_table_type(&table_attr->flow_attr,
13768 : : table_attr->specialize,
13769 : : fdb_unified_en)];
13770 : 0 : }
13771 : :
13772 : : static int
13773 : 0 : flow_hw_modify_hdr_resource_register
13774 : : (struct rte_eth_dev *dev,
13775 : : struct rte_flow_template_table *table,
13776 : : struct mlx5_hw_actions *hw_acts,
13777 : : struct rte_flow_hw *dev_flow,
13778 : : struct rte_flow_error *error)
13779 : : {
13780 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13781 : : bool unified_fdb = is_unified_fdb(priv);
13782 : 0 : struct rte_flow_template_table_attr *table_attr = &table->cfg.attr;
13783 : 0 : struct mlx5_flow_dv_modify_hdr_resource *dv_resource_ptr = NULL;
13784 : : union {
13785 : : struct mlx5_flow_dv_modify_hdr_resource dv_resource;
13786 : : uint8_t data[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
13787 : : sizeof(struct mlx5_modification_cmd) * MLX5_MHDR_MAX_CMD];
13788 : : } dummy;
13789 : : int ret;
13790 : :
13791 [ # # ]: 0 : if (hw_acts->mhdr) {
13792 : 0 : dummy.dv_resource.actions_num = hw_acts->mhdr->mhdr_cmds_num;
13793 : 0 : memcpy(dummy.dv_resource.actions, hw_acts->mhdr->mhdr_cmds,
13794 : 0 : sizeof(struct mlx5_modification_cmd) * dummy.dv_resource.actions_num);
13795 : : } else {
13796 : : return 0;
13797 : : }
13798 : 0 : flow_hw_set_dv_fields(table_attr, unified_fdb,
13799 : : &dummy.dv_resource.root, &dummy.dv_resource.ft_type,
13800 : : &dummy.dv_resource.flags);
13801 : 0 : dummy.dv_resource.flags |= MLX5DR_ACTION_FLAG_SHARED;
13802 : 0 : ret = mlx5_flow_modify_hdr_resource_register(dev, &dummy.dv_resource,
13803 : : &dv_resource_ptr, error);
13804 [ # # ]: 0 : if (ret)
13805 : : return ret;
13806 : : MLX5_ASSERT(dv_resource_ptr);
13807 : 0 : dev_flow->nt2hws->modify_hdr = dv_resource_ptr;
13808 : : /* keep action for the rule construction. */
13809 : 0 : hw_acts->rule_acts[hw_acts->mhdr->pos].action = dv_resource_ptr->action;
13810 : : /* Bulk size is 1, so index is 1. */
13811 : 0 : dev_flow->res_idx = 1;
13812 : 0 : return 0;
13813 : : }
13814 : :
13815 : : static int
13816 : 0 : flow_hw_encap_decap_resource_register
13817 : : (struct rte_eth_dev *dev,
13818 : : struct rte_flow_template_table *table,
13819 : : struct mlx5_hw_actions *hw_acts,
13820 : : struct rte_flow_hw *dev_flow,
13821 : : struct rte_flow_error *error)
13822 : : {
13823 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13824 : : bool unified_fdb = is_unified_fdb(priv);
13825 : 0 : struct rte_flow_template_table_attr *table_attr = &table->cfg.attr;
13826 : 0 : struct mlx5_flow_dv_encap_decap_resource *dv_resource_ptr = NULL;
13827 : : struct mlx5_flow_dv_encap_decap_resource dv_resource;
13828 : : struct mlx5_tbl_multi_pattern_ctx *mpctx = &table->mpctx;
13829 : : int ret;
13830 : : bool is_root;
13831 : : int ix;
13832 : :
13833 [ # # ]: 0 : if (hw_acts->encap_decap)
13834 : 0 : dv_resource.reformat_type = hw_acts->encap_decap->action_type;
13835 : : else
13836 : : return 0;
13837 : 0 : flow_hw_set_dv_fields(table_attr, unified_fdb, &is_root, &dv_resource.ft_type,
13838 : : &dv_resource.flags);
13839 [ # # ]: 0 : ix = mlx5_bwc_multi_pattern_reformat_to_index((enum mlx5dr_action_type)
13840 : : dv_resource.reformat_type);
13841 : : if (ix < 0)
13842 : 0 : return ix;
13843 [ # # ]: 0 : if (hw_acts->encap_decap->shared) {
13844 : 0 : dv_resource.size = hw_acts->encap_decap->data_size;
13845 : : MLX5_ASSERT(dv_resource.size <= MLX5_ENCAP_MAX_LEN);
13846 : 0 : memcpy(&dv_resource.buf, hw_acts->encap_decap->data, dv_resource.size);
13847 : 0 : dv_resource.flags |= MLX5DR_ACTION_FLAG_SHARED;
13848 : : } else {
13849 : 0 : typeof(mpctx->reformat[0]) *reformat = mpctx->reformat + ix;
13850 [ # # ]: 0 : if (!reformat->elements_num)
13851 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
13852 : : NULL, "No reformat action exist in the table.");
13853 : 0 : dv_resource.size = reformat->reformat_hdr->sz;
13854 : : MLX5_ASSERT(dv_resource.size <= MLX5_ENCAP_MAX_LEN);
13855 : 0 : memcpy(&dv_resource.buf, reformat->reformat_hdr->data, dv_resource.size);
13856 : : }
13857 : 0 : ret = mlx5_flow_encap_decap_resource_register(dev, &dv_resource, is_root,
13858 : : &dv_resource_ptr, error);
13859 [ # # ]: 0 : if (ret)
13860 : : return ret;
13861 : : MLX5_ASSERT(dv_resource_ptr);
13862 : 0 : dev_flow->nt2hws->rix_encap_decap = dv_resource_ptr->idx;
13863 : : /* keep action for the rule construction. */
13864 [ # # ]: 0 : if (hw_acts->encap_decap->shared)
13865 : 0 : hw_acts->rule_acts[hw_acts->encap_decap_pos].action = dv_resource_ptr->action;
13866 : : else
13867 : 0 : mpctx->segments[0].reformat_action[ix] = dv_resource_ptr->action;
13868 : : /* Bulk size is 1, so index is 1. */
13869 : 0 : dev_flow->res_idx = 1;
13870 : 0 : return 0;
13871 : : }
13872 : :
13873 : : static enum rte_flow_action_type
13874 : : flow_nta_get_indirect_action_type(const struct rte_flow_action *action)
13875 : : {
13876 [ # # ]: 0 : switch (MLX5_INDIRECT_ACTION_TYPE_GET(action->conf)) {
13877 : : case MLX5_INDIRECT_ACTION_TYPE_RSS:
13878 : : return RTE_FLOW_ACTION_TYPE_RSS;
13879 : : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13880 : : return RTE_FLOW_ACTION_TYPE_AGE;
13881 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
13882 : : return RTE_FLOW_ACTION_TYPE_COUNT;
13883 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
13884 : : return RTE_FLOW_ACTION_TYPE_CONNTRACK;
13885 : : default:
13886 : : break;
13887 : : }
13888 : : return RTE_FLOW_ACTION_TYPE_END;
13889 : : }
13890 : :
13891 : : static void
13892 : : flow_nta_set_mh_mask_conf(const struct rte_flow_action_modify_field *action_conf,
13893 : : struct rte_flow_action_modify_field *mask_conf)
13894 : : {
13895 : : memset(mask_conf, 0xff, sizeof(*mask_conf));
13896 : 0 : mask_conf->operation = action_conf->operation;
13897 : 0 : mask_conf->dst.field = action_conf->dst.field;
13898 : 0 : mask_conf->src.field = action_conf->src.field;
13899 : : }
13900 : :
13901 : : union actions_conf {
13902 : : struct rte_flow_action_modify_field modify_field;
13903 : : struct rte_flow_action_raw_encap raw_encap;
13904 : : struct rte_flow_action_vxlan_encap vxlan_encap;
13905 : : struct rte_flow_action_nvgre_encap nvgre_encap;
13906 : : };
13907 : :
13908 : : static int
13909 : 0 : flow_nta_build_template_mask(const struct rte_flow_action actions[],
13910 : : struct rte_flow_action masks[MLX5_HW_MAX_ACTS],
13911 : : union actions_conf mask_conf[MLX5_HW_MAX_ACTS])
13912 : : {
13913 : : int i;
13914 : :
13915 [ # # # # ]: 0 : for (i = 0; i == 0 || actions[i - 1].type != RTE_FLOW_ACTION_TYPE_END; i++) {
13916 : 0 : const struct rte_flow_action *action = &actions[i];
13917 : 0 : struct rte_flow_action *mask = &masks[i];
13918 : 0 : union actions_conf *conf = &mask_conf[i];
13919 : :
13920 : 0 : mask->type = action->type;
13921 [ # # # # : 0 : switch (action->type) {
# # # ]
13922 : : case RTE_FLOW_ACTION_TYPE_INDIRECT:
13923 : 0 : mask->type = flow_nta_get_indirect_action_type(action);
13924 [ # # ]: 0 : if (!mask->type)
13925 : : return -EINVAL;
13926 : : break;
13927 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13928 : 0 : flow_nta_set_mh_mask_conf(action->conf, (void *)conf);
13929 : 0 : mask->conf = conf;
13930 : 0 : break;
13931 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13932 : : /* This mask will set this action as shared. */
13933 : : memset(conf, 0xff, sizeof(struct rte_flow_action_raw_encap));
13934 : 0 : mask->conf = conf;
13935 : 0 : break;
13936 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13937 : : /* This mask will set this action as shared. */
13938 : 0 : conf->vxlan_encap.definition =
13939 : : ((const struct rte_flow_action_vxlan_encap *)
13940 : 0 : action->conf)->definition;
13941 : 0 : mask->conf = conf;
13942 : 0 : break;
13943 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13944 : : /* This mask will set this action as shared. */
13945 : 0 : conf->nvgre_encap.definition =
13946 : : ((const struct rte_flow_action_nvgre_encap *)
13947 : 0 : action->conf)->definition;
13948 : 0 : mask->conf = conf;
13949 : 0 : break;
13950 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
13951 : : memset(conf, 0xff, sizeof(struct rte_flow_action_of_set_vlan_vid));
13952 : 0 : mask->conf = conf;
13953 : 0 : break;
13954 : : default:
13955 : : break;
13956 : : }
13957 : : }
13958 : : return 0;
13959 : : #undef NTA_CHECK_CONF_BUF_SIZE
13960 : : }
13961 : :
13962 : : static int
13963 : 0 : flow_hw_translate_flow_actions(struct rte_eth_dev *dev,
13964 : : const struct rte_flow_attr *attr,
13965 : : const struct rte_flow_action actions[],
13966 : : struct rte_flow_hw *flow,
13967 : : struct mlx5_flow_hw_action_params *ap,
13968 : : struct mlx5_hw_actions *hw_acts,
13969 : : uint64_t item_flags, uint64_t action_flags,
13970 : : bool external,
13971 : : struct rte_flow_error *error)
13972 : : {
13973 : : int ret = 0;
13974 : 0 : uint32_t src_group = 0;
13975 : : enum mlx5dr_table_type table_type;
13976 : : struct mlx5_flow_group grp;
13977 : : struct rte_flow_actions_template *at = NULL;
13978 : 0 : struct rte_flow_actions_template_attr template_attr = {
13979 : 0 : .egress = attr->egress,
13980 : 0 : .ingress = attr->ingress,
13981 : 0 : .transfer = attr->transfer,
13982 : : };
13983 : : struct rte_flow_action masks[MLX5_HW_MAX_ACTS];
13984 : : union actions_conf mask_conf[MLX5_HW_MAX_ACTS];
13985 : :
13986 : : RTE_SET_USED(action_flags);
13987 : : memset(masks, 0, sizeof(masks));
13988 : : memset(mask_conf, 0, sizeof(mask_conf));
13989 : : /* Only set the needed fields explicitly. */
13990 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
13991 : : struct rte_flow_template_table *table;
13992 : :
13993 : : /*
13994 : : * Notice All direct actions will be unmasked,
13995 : : * except for modify header and encap,
13996 : : * and therefore will be parsed as part of action construct.
13997 : : * Modify header is always shared in HWS,
13998 : : * encap is masked such that it will be treated as shared.
13999 : : * shared actions will be parsed as part of template translation
14000 : : * and not during action construct.
14001 : : */
14002 [ # # ]: 0 : if (!wks)
14003 : 0 : return rte_flow_error_set(error, ENOMEM,
14004 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14005 : : NULL,
14006 : : "failed to push flow workspace");
14007 : 0 : table = wks->table;
14008 : 0 : flow_nta_build_template_mask(actions, masks, mask_conf);
14009 : : /* The group in the attribute translation was done in advance. */
14010 : 0 : ret = __translate_group(dev, attr, external, attr->group, &src_group, error);
14011 [ # # ]: 0 : if (ret)
14012 : : return ret;
14013 [ # # ]: 0 : if (attr->transfer)
14014 : : table_type = MLX5DR_TABLE_TYPE_FDB;
14015 [ # # ]: 0 : else if (attr->egress)
14016 : : table_type = MLX5DR_TABLE_TYPE_NIC_TX;
14017 : : else
14018 : : table_type = MLX5DR_TABLE_TYPE_NIC_RX;
14019 : 0 : at = __flow_hw_actions_template_create(dev, &template_attr, actions, masks, true, error);
14020 [ # # ]: 0 : if (!at) {
14021 : 0 : ret = -rte_errno;
14022 : 0 : goto end;
14023 : : }
14024 : 0 : grp.group_id = src_group;
14025 : 0 : table->grp = &grp;
14026 : 0 : table->type = table_type;
14027 : 0 : table->cfg.external = external;
14028 : 0 : table->nb_action_templates = 1;
14029 : 0 : memcpy(&table->cfg.attr.flow_attr, attr, sizeof(*attr));
14030 : 0 : table->cfg.attr.flow_attr.group = src_group;
14031 : 0 : table->ats[0].action_template = at;
14032 : 0 : ret = __flow_hw_translate_actions_template(dev, &table->cfg, hw_acts, at,
14033 : : &table->mpctx, true, error);
14034 [ # # ]: 0 : if (ret)
14035 : 0 : goto end;
14036 : : /* handle bulk actions register. */
14037 : 0 : ret = flow_hw_encap_decap_resource_register(dev, table, hw_acts, flow, error);
14038 [ # # ]: 0 : if (ret)
14039 : 0 : goto end;
14040 : 0 : ret = flow_hw_modify_hdr_resource_register(dev, table, hw_acts, flow, error);
14041 [ # # ]: 0 : if (ret)
14042 : 0 : goto end;
14043 : 0 : table->ats[0].acts = *hw_acts;
14044 : 0 : ret = flow_hw_actions_construct(dev, flow, ap,
14045 : : &table->ats[0], item_flags, table,
14046 [ # # ]: 0 : actions, hw_acts->rule_acts, 0, error);
14047 [ # # ]: 0 : if (ret)
14048 : 0 : goto end;
14049 : 0 : goto end;
14050 : 0 : end:
14051 [ # # ]: 0 : if (ret)
14052 : : /* Make sure that there is no garbage in the actions. */
14053 : 0 : __flow_hw_action_template_destroy(dev, hw_acts);
14054 : : else
14055 : 0 : __flow_hw_act_data_flush(dev, hw_acts);
14056 [ # # ]: 0 : if (at)
14057 : 0 : mlx5_free(at);
14058 : 0 : mlx5_flow_pop_thread_workspace();
14059 : 0 : return ret;
14060 : : }
14061 : :
14062 : : static int
14063 : 0 : flow_hw_unregister_matcher(struct rte_eth_dev *dev,
14064 : : struct mlx5_flow_dv_matcher *matcher)
14065 : : {
14066 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14067 : 0 : struct mlx5_flow_group *group = matcher->group;
14068 : : int ret = 0;
14069 : :
14070 [ # # ]: 0 : if (group) {
14071 [ # # ]: 0 : if (matcher->matcher_object)
14072 : 0 : ret |= mlx5_list_unregister(group->matchers, &matcher->entry);
14073 : 0 : ret |= mlx5_hlist_unregister(priv->sh->groups, &group->entry);
14074 : : }
14075 : 0 : return ret;
14076 : : }
14077 : :
14078 : 0 : static int flow_hw_register_matcher(struct rte_eth_dev *dev,
14079 : : const struct rte_flow_attr *attr,
14080 : : const struct rte_flow_item items[],
14081 : : bool external,
14082 : : struct rte_flow_hw *flow,
14083 : : struct mlx5_flow_dv_matcher *matcher,
14084 : : struct rte_flow_error *error)
14085 : : {
14086 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14087 : 0 : struct rte_flow_error sub_error = {
14088 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
14089 : : .cause = NULL,
14090 : : .message = NULL,
14091 : : };
14092 : 0 : struct rte_flow_attr flow_attr = *attr;
14093 : 0 : uint32_t specialize = 0; /* No unified FDB. */
14094 : 0 : struct mlx5_flow_cb_ctx ctx = {
14095 : : .dev = dev,
14096 : : .error = &sub_error,
14097 : : .data = &flow_attr,
14098 : : .data2 = &specialize,
14099 : : };
14100 : : void *items_ptr = &items;
14101 : 0 : struct mlx5_flow_cb_ctx matcher_ctx = {
14102 : : .error = &sub_error,
14103 : : .data = matcher,
14104 : : .data2 = items_ptr,
14105 : : };
14106 : : struct mlx5_list_entry *group_entry = NULL;
14107 : : struct mlx5_list_entry *matcher_entry = NULL;
14108 : : struct mlx5_flow_dv_matcher *resource;
14109 : : struct mlx5_list *matchers_list;
14110 : : struct mlx5_flow_group *flow_group;
14111 : : int ret;
14112 : :
14113 : :
14114 : 0 : matcher->crc = rte_raw_cksum((const void *)matcher->mask.buf,
14115 : : matcher->mask.size);
14116 : 0 : matcher->priority = attr->priority;
14117 : 0 : ret = __translate_group(dev, attr, external, attr->group, &flow_attr.group, error);
14118 [ # # ]: 0 : if (ret)
14119 : : return ret;
14120 : :
14121 : : /* Register the flow group. */
14122 : 0 : group_entry = mlx5_hlist_register(priv->sh->groups, flow_attr.group, &ctx);
14123 [ # # ]: 0 : if (!group_entry)
14124 : 0 : goto error;
14125 : : flow_group = container_of(group_entry, struct mlx5_flow_group, entry);
14126 : :
14127 : 0 : matchers_list = flow_group->matchers;
14128 : 0 : matcher->group = flow_group;
14129 : 0 : matcher_entry = mlx5_list_register(matchers_list, &matcher_ctx);
14130 [ # # ]: 0 : if (!matcher_entry)
14131 : 0 : goto error;
14132 : : resource = container_of(matcher_entry, typeof(*resource), entry);
14133 : 0 : flow->nt2hws->matcher = resource;
14134 : 0 : return 0;
14135 : :
14136 : 0 : error:
14137 [ # # ]: 0 : if (group_entry)
14138 : 0 : mlx5_hlist_unregister(priv->sh->groups, group_entry);
14139 [ # # ]: 0 : if (error) {
14140 [ # # ]: 0 : if (sub_error.type != RTE_FLOW_ERROR_TYPE_NONE)
14141 : : rte_memcpy(error, &sub_error, sizeof(sub_error));
14142 : : }
14143 : 0 : return rte_flow_error_set(error, rte_errno,
14144 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14145 : : NULL, "fail to register matcher");
14146 : : }
14147 : :
14148 : : static int
14149 : 0 : flow_hw_allocate_actions(struct rte_eth_dev *dev,
14150 : : uint64_t action_flags,
14151 : : struct rte_flow_error *error)
14152 : : {
14153 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14154 : : int ret;
14155 : : uint obj_num;
14156 : :
14157 : 0 : error->type = RTE_FLOW_ERROR_TYPE_NONE;
14158 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
14159 : : /* If no age objects were previously allocated. */
14160 [ # # ]: 0 : if (!priv->hws_age_req) {
14161 : : /* If no counters were previously allocated. */
14162 [ # # ]: 0 : if (!priv->hws_cpool) {
14163 : 0 : obj_num = MLX5_CNT_NT_MAX(priv);
14164 : 0 : ret = mlx5_hws_cnt_pool_create(dev, obj_num,
14165 : 0 : priv->nb_queue,
14166 : : NULL, error);
14167 [ # # ]: 0 : if (ret)
14168 : 0 : goto err;
14169 : : }
14170 : : /* Allocate same number of counters. */
14171 : 0 : ret = mlx5_hws_age_pool_init(dev, priv->hws_cpool->cfg.request_num,
14172 : 0 : priv->nb_queue, false);
14173 [ # # ]: 0 : if (ret)
14174 : 0 : goto err;
14175 : : }
14176 : : }
14177 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
14178 : : /* If no counters were previously allocated. */
14179 [ # # ]: 0 : if (!priv->hws_cpool) {
14180 : 0 : obj_num = MLX5_CNT_NT_MAX(priv);
14181 : 0 : ret = mlx5_hws_cnt_pool_create(dev, obj_num,
14182 : 0 : priv->nb_queue, NULL,
14183 : : error);
14184 [ # # ]: 0 : if (ret)
14185 : 0 : goto err;
14186 : : }
14187 : : }
14188 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_CT) {
14189 : : /* If no CT were previously allocated. */
14190 [ # # ]: 0 : if (!priv->hws_ctpool) {
14191 : 0 : obj_num = MLX5_CT_NT_MAX(priv);
14192 : 0 : ret = mlx5_flow_ct_init(dev, obj_num, priv->nb_queue);
14193 [ # # ]: 0 : if (ret)
14194 : 0 : goto err;
14195 : : }
14196 : : }
14197 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER) {
14198 : : /* If no meters were previously allocated. */
14199 [ # # ]: 0 : if (!priv->hws_mpool) {
14200 : 0 : obj_num = MLX5_MTR_NT_MAX(priv);
14201 : 0 : ret = mlx5_flow_meter_init(dev, obj_num, 0, 0,
14202 : : priv->nb_queue);
14203 [ # # ]: 0 : if (ret)
14204 : 0 : goto err;
14205 : : }
14206 : : }
14207 : : return 0;
14208 : 0 : err:
14209 [ # # ]: 0 : if (ret && error->type != RTE_FLOW_ERROR_TYPE_NONE)
14210 : : return ret;
14211 : 0 : return rte_flow_error_set(error, ret,
14212 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14213 : : NULL, "fail to allocate actions");
14214 : : }
14215 : :
14216 : 0 : static int flow_hw_apply(const struct rte_flow_item items[],
14217 : : struct mlx5dr_rule_action rule_actions[],
14218 : : struct rte_flow_hw *flow,
14219 : : struct rte_flow_error *error)
14220 : : {
14221 : : struct mlx5dr_bwc_rule *rule = NULL;
14222 : :
14223 : 0 : rule = mlx5dr_bwc_rule_create((struct mlx5dr_bwc_matcher *)
14224 : 0 : flow->nt2hws->matcher->matcher_object,
14225 : : items, rule_actions);
14226 : 0 : flow->nt2hws->nt_rule = rule;
14227 [ # # ]: 0 : if (!rule) {
14228 : 0 : return rte_flow_error_set(error, EINVAL,
14229 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14230 : : NULL, "fail to create rte flow");
14231 : : }
14232 : : return 0;
14233 : : }
14234 : :
14235 : : #ifdef HAVE_MLX5_HWS_SUPPORT
14236 : : /**
14237 : : * Create a flow.
14238 : : *
14239 : : * @param[in] dev
14240 : : * Pointer to Ethernet device.
14241 : : * @param[in] type
14242 : : * Flow type.
14243 : : * @param[in] attr
14244 : : * Flow rule attributes.
14245 : : * @param[in] items
14246 : : * Pattern specification (list terminated by the END pattern item).
14247 : : * @param[in] actions
14248 : : * Associated actions (list terminated by the END action).
14249 : : * @param[in] external
14250 : : * This flow rule is created by request external to PMD.
14251 : : * @param[out] flow
14252 : : * Flow pointer
14253 : : * @param[out] error
14254 : : * Perform verbose error reporting if not NULL.
14255 : : *
14256 : : * @return
14257 : : * 0 on success, negative errno value otherwise and rte_errno set.
14258 : : */
14259 : : int
14260 : 0 : mlx5_flow_hw_create_flow(struct rte_eth_dev *dev, enum mlx5_flow_type type,
14261 : : const struct rte_flow_attr *attr,
14262 : : const struct rte_flow_item items[],
14263 : : const struct rte_flow_action actions[],
14264 : : uint64_t item_flags, uint64_t action_flags, bool external,
14265 : : struct rte_flow_hw **flow, struct rte_flow_error *error)
14266 : : {
14267 : : int ret;
14268 : 0 : struct mlx5_hw_actions hw_act = { { NULL } };
14269 : : struct mlx5_flow_hw_action_params ap;
14270 : 0 : struct mlx5_flow_dv_matcher matcher = {
14271 : : .mask = {
14272 : : .size = sizeof(matcher.mask.buf),
14273 : : },
14274 : : };
14275 : : uint32_t tbl_type;
14276 : :
14277 : 0 : struct mlx5_flow_attr flow_attr = {
14278 : 0 : .port_id = dev->data->port_id,
14279 : 0 : .group = attr->group,
14280 : 0 : .priority = attr->priority,
14281 : : .rss_level = 0,
14282 : : .act_flags = action_flags,
14283 : : .tbl_type = 0,
14284 : : };
14285 : :
14286 [ # # ]: 0 : if (attr->transfer)
14287 : : tbl_type = MLX5DR_TABLE_TYPE_FDB;
14288 [ # # ]: 0 : else if (attr->egress)
14289 : : tbl_type = MLX5DR_TABLE_TYPE_NIC_TX;
14290 : : else
14291 : : tbl_type = MLX5DR_TABLE_TYPE_NIC_RX;
14292 : 0 : flow_attr.tbl_type = tbl_type;
14293 : :
14294 : : /* Allocate needed memory. */
14295 : 0 : ret = flow_hw_prepare(dev, actions, type, flow, error);
14296 [ # # ]: 0 : if (ret)
14297 : 0 : goto error;
14298 : :
14299 : : /* TODO TBD flow_hw_handle_tunnel_offload(). */
14300 : 0 : (*flow)->nt_rule = true;
14301 : 0 : (*flow)->nt2hws->matcher = &matcher;
14302 : 0 : ret = mlx5_flow_dv_translate_items_hws_impl(items, &flow_attr, &matcher.mask.buf,
14303 : : MLX5_SET_MATCHER_HS_M, NULL,
14304 : : NULL, true, error);
14305 : :
14306 [ # # ]: 0 : if (ret)
14307 : 0 : goto error;
14308 : :
14309 [ # # # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_ECPRI && !mlx5_flex_parser_ecpri_exist(dev))
14310 [ # # ]: 0 : if (mlx5_flex_parser_ecpri_alloc(dev)) {
14311 : 0 : rte_flow_error_set(error, EIO,
14312 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14313 : : NULL,
14314 : : "failed to create Flex parser "
14315 : : "profile for ECPRI");
14316 : 0 : goto error;
14317 : : }
14318 : 0 : ret = flow_hw_register_matcher(dev, attr, items, external, *flow, &matcher, error);
14319 [ # # ]: 0 : if (ret) {
14320 [ # # ]: 0 : if (rte_errno == E2BIG)
14321 : 0 : rte_flow_error_set(error, E2BIG, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14322 : : "flow pattern is too big");
14323 : 0 : goto error;
14324 : : }
14325 : :
14326 : : /*
14327 : : * ASO allocation – iterating on actions list to allocate missing resources.
14328 : : * In the future when validate function in hws will be added,
14329 : : * The output actions bit mask instead of
14330 : : * looping on the actions array twice.
14331 : : */
14332 : 0 : ret = flow_hw_allocate_actions(dev, action_flags, error);
14333 [ # # ]: 0 : if (ret)
14334 : 0 : goto error;
14335 : :
14336 : : /* Note: the actions should be saved in the sub-flow rule itself for reference. */
14337 : 0 : ret = flow_hw_translate_flow_actions(dev, attr, actions, *flow, &ap, &hw_act,
14338 : : item_flags, action_flags, external, error);
14339 [ # # ]: 0 : if (ret)
14340 : 0 : goto error;
14341 : :
14342 : : /*
14343 : : * If the flow is external (from application) OR device is started,
14344 : : * OR mreg discover, then apply immediately.
14345 : : */
14346 [ # # # # ]: 0 : if (external || dev->data->dev_started ||
14347 [ # # ]: 0 : (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
14348 [ # # ]: 0 : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
14349 : 0 : ret = flow_hw_apply(items, hw_act.rule_acts, *flow, error);
14350 [ # # ]: 0 : if (ret)
14351 : 0 : goto error;
14352 : : }
14353 : : ret = 0;
14354 : 0 : error:
14355 : : /*
14356 : : * Release memory allocated.
14357 : : * Cannot use __flow_hw_actions_release(dev, &hw_act);
14358 : : * since it destroys the actions as well.
14359 : : */
14360 [ # # ]: 0 : if (hw_act.encap_decap)
14361 : 0 : mlx5_free(hw_act.encap_decap);
14362 [ # # ]: 0 : if (hw_act.push_remove)
14363 : 0 : mlx5_free(hw_act.push_remove);
14364 [ # # ]: 0 : if (hw_act.mhdr)
14365 : 0 : mlx5_free(hw_act.mhdr);
14366 : 0 : return ret;
14367 : : }
14368 : : #endif
14369 : :
14370 : : void
14371 : 0 : mlx5_flow_hw_destroy(struct rte_eth_dev *dev, struct rte_flow_hw *flow)
14372 : : {
14373 : : int ret;
14374 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14375 : :
14376 [ # # # # ]: 0 : if (!flow || !flow->nt2hws)
14377 : : return;
14378 : :
14379 [ # # ]: 0 : if (flow->nt2hws->nt_rule) {
14380 : 0 : ret = mlx5dr_bwc_rule_destroy(flow->nt2hws->nt_rule);
14381 [ # # ]: 0 : if (ret)
14382 : 0 : DRV_LOG(ERR, "bwc rule destroy failed");
14383 : 0 : flow->nt2hws->nt_rule = NULL;
14384 : : }
14385 [ # # ]: 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY;
14386 : : /* Notice this function does not handle shared/static actions. */
14387 : : hw_cmpl_flow_update_or_destroy(dev, flow, 0, NULL);
14388 : :
14389 : : /**
14390 : : * TODO: TBD - Release tunnel related memory allocations(mlx5_flow_tunnel_free)
14391 : : * – needed only if supporting tunnel offloads, notice update RX queue flags in SWS.
14392 : : */
14393 : :
14394 : : /**
14395 : : * Notice matcher destroy will take place when matcher's list is destroyed
14396 : : * , same as for DV.
14397 : : */
14398 [ # # ]: 0 : if (flow->nt2hws->flow_aux)
14399 : 0 : flow->nt2hws->flow_aux = NULL;
14400 [ # # ]: 0 : if (flow->nt2hws->rix_encap_decap) {
14401 : 0 : mlx5_flow_encap_decap_resource_release(dev, flow->nt2hws->rix_encap_decap);
14402 : 0 : flow->nt2hws->rix_encap_decap = 0;
14403 : : }
14404 [ # # ]: 0 : if (flow->nt2hws->modify_hdr) {
14405 : : MLX5_ASSERT(flow->nt2hws->modify_hdr->action);
14406 : 0 : mlx5_hlist_unregister(priv->sh->modify_cmds,
14407 : : &flow->nt2hws->modify_hdr->entry);
14408 : 0 : flow->nt2hws->modify_hdr = NULL;
14409 : : }
14410 [ # # ]: 0 : if (flow->nt2hws->matcher) {
14411 : 0 : flow_hw_unregister_matcher(dev, flow->nt2hws->matcher);
14412 : 0 : flow->nt2hws->matcher = NULL;
14413 : : }
14414 [ # # ]: 0 : if (flow->nt2hws->sample_release_ctx != NULL) {
14415 : 0 : mlx5_nta_sample_mirror_entry_release(dev, flow->nt2hws->sample_release_ctx);
14416 : 0 : flow->nt2hws->sample_release_ctx = NULL;
14417 : : }
14418 : : }
14419 : :
14420 : : #ifdef HAVE_MLX5_HWS_SUPPORT
14421 : : /**
14422 : : * Destroy a flow.
14423 : : *
14424 : : * @param[in] dev
14425 : : * Pointer to Ethernet device.
14426 : : * @param[in] type
14427 : : * Flow type.
14428 : : * @param[in] flow_addr
14429 : : * Address of flow to destroy.
14430 : : */
14431 : : void
14432 : 0 : mlx5_flow_hw_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
14433 : : uintptr_t flow_addr)
14434 : : {
14435 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14436 : 0 : struct rte_flow_hw *flow = (struct rte_flow_hw *)flow_addr;
14437 : : struct mlx5_nta_rss_flow_head head = { .slh_first = flow };
14438 : :
14439 [ # # # # : 0 : if (!flow || !flow->nt2hws || flow->nt2hws->chaned_flow)
# # ]
14440 : : return;
14441 : 0 : mlx5_flow_nta_del_copy_action(dev, flow->nt2hws->rix_mreg_copy);
14442 [ # # ]: 0 : while (!SLIST_EMPTY(&head)) {
14443 : : flow = SLIST_FIRST(&head);
14444 : 0 : SLIST_REMOVE_HEAD(&head, nt2hws->next);
14445 : 0 : mlx5_flow_hw_destroy(dev, flow);
14446 : : /* Release flow memory by idx */
14447 : 0 : mlx5_ipool_free(priv->flows[type], flow->idx);
14448 : : }
14449 : : }
14450 : : #endif
14451 : :
14452 : : /**
14453 : : * Create a flow.
14454 : : *
14455 : : * @param[in] dev
14456 : : * Pointer to Ethernet device.
14457 : : * @param[in] type
14458 : : * Flow type.
14459 : : * @param[in] attr
14460 : : * Flow rule attributes.
14461 : : * @param[in] items
14462 : : * Pattern specification (list terminated by the END pattern item).
14463 : : * @param[in] actions
14464 : : * Associated actions (list terminated by the END action).
14465 : : * @param[in] external
14466 : : * This flow rule is created by request external to PMD.
14467 : : * @param[out] error
14468 : : * Perform verbose error reporting if not NULL.
14469 : : *
14470 : : * @return
14471 : : * A flow addr on success, 0 otherwise and rte_errno is set.
14472 : : */
14473 : 0 : static uintptr_t flow_hw_list_create(struct rte_eth_dev *dev,
14474 : : enum mlx5_flow_type type,
14475 : : const struct rte_flow_attr *attr,
14476 : : const struct rte_flow_item items[],
14477 : : const struct rte_flow_action actions[],
14478 : : bool external,
14479 : : struct rte_flow_error *error)
14480 : : {
14481 : : int ret;
14482 : : int split;
14483 : : int encap_idx;
14484 : 0 : uint32_t cpy_idx = 0;
14485 : 0 : int actions_n = 0;
14486 : 0 : struct rte_flow_hw *flow = NULL;
14487 : 0 : struct rte_flow_hw *prfx_flow = NULL;
14488 : 0 : const struct rte_flow_action *qrss = NULL;
14489 : 0 : const struct rte_flow_action *mark = NULL;
14490 : 0 : uint64_t action_flags = mlx5_flow_hw_action_flags_get(actions, &qrss, &mark,
14491 : : &encap_idx, &actions_n, error);
14492 : 0 : struct mlx5_flow_hw_split_resource resource = {
14493 : : .suffix = {
14494 : : .attr = attr,
14495 : : .items = items,
14496 : : .actions = actions,
14497 : : },
14498 : : };
14499 : 0 : struct rte_flow_error shadow_error = {0, };
14500 : 0 : const struct rte_flow_pattern_template_attr pattern_template_attr = {
14501 : : .relaxed_matching = 0,
14502 : 0 : .ingress = attr->ingress,
14503 : 0 : .egress = attr->egress,
14504 : 0 : .transfer = attr->transfer,
14505 : : };
14506 : 0 : struct rte_flow_item *copied_items = NULL;
14507 : : const struct rte_flow_item *prepend_items;
14508 : : uint64_t orig_item_nb, item_flags;
14509 : :
14510 : : RTE_SET_USED(encap_idx);
14511 [ # # ]: 0 : if (!error)
14512 : : error = &shadow_error;
14513 : :
14514 : 0 : prepend_items = flow_hw_adjust_pattern(dev, &pattern_template_attr, true, items,
14515 : : &item_flags, &orig_item_nb, &copied_items, error);
14516 [ # # ]: 0 : if (!prepend_items)
14517 : : return 0;
14518 : :
14519 : 0 : split = mlx5_flow_nta_split_metadata(dev, attr, actions, qrss, action_flags,
14520 : : actions_n, external, &resource, error);
14521 [ # # ]: 0 : if (split < 0) {
14522 : 0 : mlx5_free(copied_items);
14523 : 0 : return 0;
14524 [ # # ]: 0 : } else if (!split) {
14525 : 0 : resource.suffix.items = prepend_items;
14526 : : }
14527 : :
14528 : : /* Update the metadata copy table - MLX5_FLOW_MREG_CP_TABLE_GROUP */
14529 [ # # # # : 0 : if (((attr->ingress && attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) ||
# # ]
14530 [ # # ]: 0 : attr->transfer) && external) {
14531 : 0 : ret = mlx5_flow_nta_update_copy_table(dev, &cpy_idx, mark,
14532 : : action_flags, error);
14533 [ # # ]: 0 : if (ret)
14534 : 0 : goto free;
14535 : : }
14536 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
14537 : 0 : flow = mlx5_nta_sample_flow_list_create(dev, type, attr, prepend_items, actions,
14538 : : item_flags, action_flags, error);
14539 [ # # ]: 0 : if (flow != NULL) {
14540 : 0 : mlx5_free(copied_items);
14541 : 0 : return (uintptr_t)flow;
14542 : : }
14543 : 0 : goto free;
14544 : : }
14545 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
14546 : : const struct rte_flow_action_rss
14547 : 0 : *rss_conf = mlx5_flow_nta_locate_rss(dev, actions, error);
14548 : 0 : flow = mlx5_flow_nta_handle_rss(dev, attr, prepend_items, actions, rss_conf,
14549 : : item_flags, action_flags, external, type, error);
14550 [ # # ]: 0 : if (flow) {
14551 : 0 : flow->nt2hws->rix_mreg_copy = cpy_idx;
14552 : 0 : cpy_idx = 0;
14553 [ # # ]: 0 : if (!split) {
14554 : 0 : mlx5_free(copied_items);
14555 : 0 : return (uintptr_t)flow;
14556 : : }
14557 : 0 : goto prefix_flow;
14558 : : }
14559 : 0 : goto free;
14560 : : }
14561 : : /* Create single flow. */
14562 : 0 : ret = mlx5_flow_hw_create_flow(dev, type, resource.suffix.attr, resource.suffix.items,
14563 : : resource.suffix.actions, item_flags, action_flags,
14564 : : external, &flow, error);
14565 [ # # ]: 0 : if (ret)
14566 : 0 : goto free;
14567 [ # # ]: 0 : if (flow) {
14568 : 0 : flow->nt2hws->rix_mreg_copy = cpy_idx;
14569 : 0 : cpy_idx = 0;
14570 [ # # ]: 0 : if (!split) {
14571 : 0 : mlx5_free(copied_items);
14572 : 0 : return (uintptr_t)flow;
14573 : : }
14574 : : /* Fall Through to prefix flow creation. */
14575 : : }
14576 : 0 : prefix_flow:
14577 : 0 : ret = mlx5_flow_hw_create_flow(dev, type, attr, prepend_items, resource.prefix.actions,
14578 : : item_flags, action_flags, external, &prfx_flow, error);
14579 [ # # ]: 0 : if (ret)
14580 : 0 : goto free;
14581 [ # # ]: 0 : if (prfx_flow) {
14582 : 0 : prfx_flow->nt2hws->rix_mreg_copy = flow->nt2hws->rix_mreg_copy;
14583 : 0 : flow->nt2hws->chaned_flow = 1;
14584 : 0 : SLIST_INSERT_AFTER(prfx_flow, flow, nt2hws->next);
14585 : 0 : mlx5_flow_nta_split_resource_free(dev, &resource);
14586 : 0 : mlx5_free(copied_items);
14587 : 0 : return (uintptr_t)prfx_flow;
14588 : : }
14589 : 0 : free:
14590 [ # # ]: 0 : if (prfx_flow)
14591 : 0 : mlx5_flow_hw_list_destroy(dev, type, (uintptr_t)prfx_flow);
14592 [ # # ]: 0 : if (flow)
14593 : 0 : mlx5_flow_hw_list_destroy(dev, type, (uintptr_t)flow);
14594 [ # # ]: 0 : if (cpy_idx)
14595 : 0 : mlx5_flow_nta_del_copy_action(dev, cpy_idx);
14596 [ # # ]: 0 : if (split > 0)
14597 : 0 : mlx5_flow_nta_split_resource_free(dev, &resource);
14598 : 0 : mlx5_free(copied_items);
14599 : 0 : return 0;
14600 : : }
14601 : :
14602 : : static void
14603 : 0 : mlx5_mirror_destroy_clone(struct rte_eth_dev *dev,
14604 : : struct mlx5_mirror_clone *clone)
14605 : : {
14606 [ # # # ]: 0 : switch (clone->type) {
14607 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
14608 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
14609 : 0 : mlx5_hrxq_release(dev,
14610 : 0 : ((struct mlx5_hrxq *)(clone->action_ctx))->idx);
14611 : 0 : break;
14612 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
14613 : 0 : flow_hw_jump_release(dev, clone->action_ctx);
14614 : : break;
14615 : : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
14616 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14617 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14618 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14619 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14620 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14621 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14622 : : default:
14623 : : break;
14624 : : }
14625 : 0 : }
14626 : :
14627 : : void
14628 [ # # ]: 0 : mlx5_hw_mirror_destroy(struct rte_eth_dev *dev, struct mlx5_mirror *mirror)
14629 : : {
14630 : : uint32_t i;
14631 : :
14632 : : mlx5_indirect_list_remove_entry(&mirror->indirect);
14633 [ # # ]: 0 : for (i = 0; i < mirror->clones_num; i++)
14634 : 0 : mlx5_mirror_destroy_clone(dev, &mirror->clone[i]);
14635 [ # # ]: 0 : if (mirror->mirror_action)
14636 : 0 : mlx5dr_action_destroy(mirror->mirror_action);
14637 : 0 : mlx5_free(mirror);
14638 : 0 : }
14639 : :
14640 : : static __rte_always_inline bool
14641 : : mlx5_mirror_terminal_action(const struct rte_flow_action *action)
14642 : : {
14643 : 0 : switch (action->type) {
14644 : : case RTE_FLOW_ACTION_TYPE_JUMP:
14645 : : case RTE_FLOW_ACTION_TYPE_RSS:
14646 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
14647 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14648 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14649 : : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
14650 : : case RTE_FLOW_ACTION_TYPE_DROP:
14651 : : return true;
14652 : : default:
14653 : : break;
14654 : : }
14655 : : return false;
14656 : : }
14657 : :
14658 : : static bool
14659 : 0 : mlx5_mirror_validate_sample_action(struct rte_eth_dev *dev,
14660 : : const struct rte_flow_attr *flow_attr,
14661 : : const struct rte_flow_action *action)
14662 : : {
14663 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14664 : : const struct rte_flow_action_ethdev *port = NULL;
14665 [ # # # # ]: 0 : bool is_proxy = MLX5_HW_PORT_IS_PROXY(priv);
14666 : :
14667 [ # # ]: 0 : if (!action)
14668 : : return false;
14669 [ # # # # : 0 : switch (action->type) {
# ]
14670 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
14671 : : case RTE_FLOW_ACTION_TYPE_RSS:
14672 [ # # ]: 0 : if (flow_attr->transfer)
14673 : : return false;
14674 : : break;
14675 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14676 [ # # # # ]: 0 : if (!is_proxy || !flow_attr->transfer)
14677 : : return false;
14678 : 0 : port = action->conf;
14679 [ # # # # ]: 0 : if (!port || port->port_id != MLX5_REPRESENTED_PORT_ESW_MGR)
14680 : : return false;
14681 : : break;
14682 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14683 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14684 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14685 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14686 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14687 [ # # # # ]: 0 : if (!is_proxy || !flow_attr->transfer)
14688 : : return false;
14689 [ # # ]: 0 : if (action[0].type == RTE_FLOW_ACTION_TYPE_RAW_DECAP &&
14690 [ # # ]: 0 : action[1].type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP)
14691 : : return false;
14692 : : break;
14693 : : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
14694 : : case RTE_FLOW_ACTION_TYPE_JUMP:
14695 : : case RTE_FLOW_ACTION_TYPE_DROP:
14696 : : break;
14697 : : default:
14698 : : return false;
14699 : : }
14700 : 0 : return true;
14701 : : }
14702 : :
14703 : : /**
14704 : : * Valid mirror actions list includes one or two SAMPLE actions
14705 : : * followed by JUMP.
14706 : : *
14707 : : * @return
14708 : : * Number of mirrors *action* list was valid.
14709 : : * -EINVAL otherwise.
14710 : : */
14711 : : static int
14712 : 0 : mlx5_hw_mirror_actions_list_validate(struct rte_eth_dev *dev,
14713 : : const struct rte_flow_attr *flow_attr,
14714 : : const struct rte_flow_action *actions)
14715 : : {
14716 [ # # ]: 0 : if (actions[0].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
14717 : : int i = 1;
14718 : : bool valid;
14719 : 0 : const struct rte_flow_action_sample *sample = actions[0].conf;
14720 : 0 : valid = mlx5_mirror_validate_sample_action(dev, flow_attr,
14721 : 0 : sample->actions);
14722 [ # # ]: 0 : if (!valid)
14723 : : return -EINVAL;
14724 [ # # ]: 0 : if (actions[1].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
14725 : : i = 2;
14726 : 0 : sample = actions[1].conf;
14727 : 0 : valid = mlx5_mirror_validate_sample_action(dev, flow_attr,
14728 : 0 : sample->actions);
14729 [ # # ]: 0 : if (!valid)
14730 : : return -EINVAL;
14731 : : }
14732 [ # # ]: 0 : return mlx5_mirror_terminal_action(actions + i) ? i + 1 : -EINVAL;
14733 : : }
14734 : : return -EINVAL;
14735 : : }
14736 : :
14737 : : static int
14738 : 0 : mirror_format_tir(struct rte_eth_dev *dev,
14739 : : struct mlx5_mirror_clone *clone,
14740 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14741 : : const struct rte_flow_action *action,
14742 : : struct mlx5dr_action_dest_attr *dest_attr,
14743 : : struct rte_flow_error *error)
14744 : : {
14745 : : uint32_t hws_flags;
14746 : : enum mlx5dr_table_type table_type;
14747 : : struct mlx5_hrxq *tir_ctx;
14748 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14749 : : bool unified_fdb = is_unified_fdb(priv);
14750 : :
14751 : 0 : table_type = get_mlx5dr_table_type(&table_cfg->attr.flow_attr, table_cfg->attr.specialize,
14752 : : unified_fdb);
14753 : 0 : hws_flags = mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_NONE_ROOT][table_type];
14754 : 0 : tir_ctx = flow_hw_tir_action_register(dev, hws_flags, action);
14755 [ # # ]: 0 : if (!tir_ctx)
14756 : 0 : return rte_flow_error_set(error, EINVAL,
14757 : : RTE_FLOW_ERROR_TYPE_ACTION,
14758 : : action, "failed to create QUEUE action for mirror clone");
14759 : 0 : dest_attr->dest = tir_ctx->action;
14760 : 0 : clone->action_ctx = tir_ctx;
14761 : 0 : return 0;
14762 : : }
14763 : :
14764 : : static int
14765 : 0 : mirror_format_jump(struct rte_eth_dev *dev,
14766 : : struct mlx5_mirror_clone *clone,
14767 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14768 : : const struct rte_flow_action *action,
14769 : : struct mlx5dr_action_dest_attr *dest_attr,
14770 : : struct rte_flow_error *error)
14771 : : {
14772 : 0 : const struct rte_flow_action_jump *jump_conf = action->conf;
14773 : 0 : struct mlx5_hw_jump_action *jump = flow_hw_jump_action_register
14774 : : (dev, table_cfg,
14775 : 0 : jump_conf->group, error);
14776 : :
14777 [ # # ]: 0 : if (!jump)
14778 : 0 : return rte_flow_error_set(error, EINVAL,
14779 : : RTE_FLOW_ERROR_TYPE_ACTION,
14780 : : action, "failed to create JUMP action for mirror clone");
14781 : 0 : dest_attr->dest = jump->hws_action;
14782 : 0 : clone->action_ctx = jump;
14783 : 0 : return 0;
14784 : : }
14785 : :
14786 : : static int
14787 : : mirror_format_port(struct rte_eth_dev *dev,
14788 : : const struct rte_flow_action *action,
14789 : : struct mlx5dr_action_dest_attr *dest_attr,
14790 : : struct rte_flow_error __rte_unused *error)
14791 : : {
14792 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14793 : 0 : const struct rte_flow_action_ethdev *port_action = action->conf;
14794 : :
14795 : 0 : dest_attr->dest = priv->hw_vport[port_action->port_id];
14796 : : return 0;
14797 : : }
14798 : :
14799 : : static int
14800 : 0 : hw_mirror_clone_reformat(const struct rte_flow_action *actions,
14801 : : struct mlx5dr_action_dest_attr *dest_attr,
14802 : : enum mlx5dr_action_type *action_type,
14803 : : uint8_t *reformat_buf, bool decap)
14804 : : {
14805 : : int ret;
14806 : : const struct rte_flow_item *encap_item = NULL;
14807 : : const struct rte_flow_action_raw_encap *encap_conf = NULL;
14808 : : typeof(dest_attr->reformat) *reformat = &dest_attr->reformat;
14809 : :
14810 [ # # # # ]: 0 : switch (actions[0].type) {
14811 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14812 : 0 : encap_conf = actions[0].conf;
14813 : 0 : break;
14814 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14815 : 0 : encap_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_vxlan_encap,
14816 : : actions);
14817 : 0 : break;
14818 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14819 : 0 : encap_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_nvgre_encap,
14820 : : actions);
14821 : 0 : break;
14822 : : default:
14823 : : return -EINVAL;
14824 : : }
14825 : 0 : *action_type = decap ?
14826 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3 :
14827 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
14828 [ # # ]: 0 : if (encap_item) {
14829 : 0 : ret = mlx5_flow_dv_convert_encap_data(encap_item, reformat_buf,
14830 : : &reformat->reformat_data_sz, NULL);
14831 [ # # ]: 0 : if (ret)
14832 : : return -EINVAL;
14833 : 0 : reformat->reformat_data = reformat_buf;
14834 : : } else {
14835 : 0 : reformat->reformat_data = (void *)(uintptr_t)encap_conf->data;
14836 : 0 : reformat->reformat_data_sz = encap_conf->size;
14837 : : }
14838 : : return 0;
14839 : : }
14840 : :
14841 : : static int
14842 : 0 : hw_mirror_format_clone(struct rte_eth_dev *dev,
14843 : : struct mlx5_mirror_clone *clone,
14844 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14845 : : const struct rte_flow_action *actions,
14846 : : struct mlx5dr_action_dest_attr *dest_attr,
14847 : : uint8_t *reformat_buf,
14848 : : enum mlx5dr_table_type table_type,
14849 : : struct rte_flow_error *error)
14850 : : {
14851 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14852 : : int ret;
14853 : : uint32_t i;
14854 : : bool decap_seen = false;
14855 : :
14856 [ # # ]: 0 : for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
14857 : 0 : dest_attr->action_type[i] = mlx5_hw_dr_action_types[actions[i].type];
14858 [ # # # # : 0 : switch (actions[i].type) {
# # # # ]
14859 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
14860 : : case RTE_FLOW_ACTION_TYPE_RSS:
14861 : 0 : ret = mirror_format_tir(dev, clone, table_cfg,
14862 : : &actions[i], dest_attr, error);
14863 [ # # ]: 0 : if (ret)
14864 : 0 : return ret;
14865 : : break;
14866 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14867 : : ret = mirror_format_port(dev, &actions[i],
14868 : : dest_attr, error);
14869 : : if (ret)
14870 : : return ret;
14871 : : break;
14872 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
14873 : 0 : ret = mirror_format_jump(dev, clone, table_cfg,
14874 : : &actions[i], dest_attr, error);
14875 [ # # ]: 0 : if (ret)
14876 : 0 : return ret;
14877 : : break;
14878 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14879 : 0 : dest_attr->dest = mlx5_hws_global_action_def_miss_get(priv,
14880 : : table_type,
14881 : : false);
14882 [ # # ]: 0 : if (dest_attr->dest == NULL)
14883 : 0 : return rte_flow_error_set(error, ENOMEM,
14884 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
14885 : : "failed to allocate port representor action");
14886 : : break;
14887 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14888 : : decap_seen = true;
14889 : 0 : break;
14890 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14891 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14892 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14893 : 0 : ret = hw_mirror_clone_reformat(&actions[i], dest_attr,
14894 : : &dest_attr->action_type[i],
14895 : : reformat_buf, decap_seen);
14896 [ # # ]: 0 : if (ret < 0)
14897 : 0 : return rte_flow_error_set(error, EINVAL,
14898 : : RTE_FLOW_ERROR_TYPE_ACTION,
14899 : : &actions[i],
14900 : : "failed to create reformat action");
14901 : : break;
14902 : : case RTE_FLOW_ACTION_TYPE_DROP:
14903 : : break;
14904 : 0 : default:
14905 : 0 : return rte_flow_error_set(error, EINVAL,
14906 : : RTE_FLOW_ERROR_TYPE_ACTION,
14907 : : &actions[i], "unsupported sample action");
14908 : : }
14909 : 0 : clone->type = actions->type;
14910 : : }
14911 : 0 : dest_attr->action_type[i] = MLX5DR_ACTION_TYP_LAST;
14912 : 0 : return 0;
14913 : : }
14914 : :
14915 : : struct mlx5_mirror *
14916 : 0 : mlx5_hw_create_mirror(struct rte_eth_dev *dev,
14917 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14918 : : const struct rte_flow_action *actions,
14919 : : struct rte_flow_error *error)
14920 : : {
14921 : : uint32_t hws_flags;
14922 : : int ret = 0, i, clones_num;
14923 : : struct mlx5_mirror *mirror;
14924 : : enum mlx5dr_table_type table_type;
14925 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
14926 : : bool unified_fdb = is_unified_fdb(priv);
14927 [ # # ]: 0 : const struct rte_flow_attr *flow_attr = &table_cfg->attr.flow_attr;
14928 : : uint8_t reformat_buf[MLX5_MIRROR_MAX_CLONES_NUM][MLX5_ENCAP_MAX_LEN];
14929 : : struct mlx5dr_action_dest_attr mirror_attr[MLX5_MIRROR_MAX_CLONES_NUM + 1];
14930 : : enum mlx5dr_action_type array_action_types[MLX5_MIRROR_MAX_CLONES_NUM + 1]
14931 : : [MLX5_MIRROR_MAX_SAMPLE_ACTIONS_LEN + 1];
14932 : :
14933 : : memset(mirror_attr, 0, sizeof(mirror_attr));
14934 : : memset(array_action_types, 0, sizeof(array_action_types));
14935 : 0 : table_type = get_mlx5dr_table_type(flow_attr, table_cfg->attr.specialize, unified_fdb);
14936 : 0 : hws_flags = mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_NONE_ROOT][table_type];
14937 : 0 : clones_num = mlx5_hw_mirror_actions_list_validate(dev, flow_attr,
14938 : : actions);
14939 [ # # ]: 0 : if (clones_num < 0) {
14940 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
14941 : : actions, "Invalid mirror list format");
14942 : 0 : return NULL;
14943 : : }
14944 : 0 : mirror = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mirror),
14945 : : 0, SOCKET_ID_ANY);
14946 [ # # ]: 0 : if (!mirror) {
14947 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ACTION,
14948 : : actions, "Failed to allocate mirror context");
14949 : 0 : return NULL;
14950 : : }
14951 : :
14952 : 0 : mirror->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR;
14953 : 0 : mirror->clones_num = clones_num;
14954 [ # # ]: 0 : for (i = 0; i < clones_num; i++) {
14955 : : const struct rte_flow_action *clone_actions;
14956 : :
14957 : 0 : mirror_attr[i].action_type = array_action_types[i];
14958 [ # # ]: 0 : if (actions[i].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
14959 : 0 : const struct rte_flow_action_sample *sample = actions[i].conf;
14960 : :
14961 : 0 : clone_actions = sample->actions;
14962 : : } else {
14963 : : clone_actions = &actions[i];
14964 : : }
14965 : 0 : ret = hw_mirror_format_clone(dev, &mirror->clone[i], table_cfg,
14966 : : clone_actions, &mirror_attr[i],
14967 : 0 : reformat_buf[i], table_type, error);
14968 : :
14969 [ # # ]: 0 : if (ret)
14970 : 0 : goto error;
14971 : : }
14972 : 0 : hws_flags |= MLX5DR_ACTION_FLAG_SHARED;
14973 : 0 : mirror->mirror_action = mlx5dr_action_create_dest_array(priv->dr_ctx,
14974 : : clones_num,
14975 : : mirror_attr,
14976 : : hws_flags);
14977 [ # # ]: 0 : if (!mirror->mirror_action) {
14978 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
14979 : : actions, "Failed to create HWS mirror action");
14980 : 0 : goto error;
14981 : : }
14982 : : return mirror;
14983 : 0 : error:
14984 : 0 : mlx5_hw_mirror_destroy(dev, mirror);
14985 : 0 : return NULL;
14986 : : }
14987 : :
14988 : : static struct rte_flow_action_list_handle *
14989 : 0 : mlx5_hw_mirror_handle_create(struct rte_eth_dev *dev,
14990 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14991 : : const struct rte_flow_action *actions,
14992 : : struct rte_flow_error *error)
14993 : : {
14994 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14995 : 0 : struct mlx5_mirror *mirror = mlx5_hw_create_mirror(dev, table_cfg, actions, error);
14996 : :
14997 [ # # ]: 0 : if (mirror)
14998 [ # # ]: 0 : mlx5_indirect_list_add_entry(&priv->indirect_list_head, &mirror->indirect);
14999 : 0 : return (struct rte_flow_action_list_handle *)mirror;
15000 : : }
15001 : :
15002 : : void
15003 : 0 : mlx5_destroy_legacy_indirect(__rte_unused struct rte_eth_dev *dev,
15004 : : struct mlx5_indirect_list *ptr)
15005 : : {
15006 : : struct mlx5_indlst_legacy *obj = (typeof(obj))ptr;
15007 : :
15008 : : switch (obj->legacy_type) {
15009 : : case RTE_FLOW_ACTION_TYPE_METER_MARK:
15010 : : break; /* ASO meters were released in mlx5_flow_meter_flush() */
15011 : : default:
15012 : : break;
15013 : : }
15014 : 0 : mlx5_free(obj);
15015 : 0 : }
15016 : :
15017 : : static struct rte_flow_action_list_handle *
15018 : 0 : mlx5_create_legacy_indlst(struct rte_eth_dev *dev, uint32_t queue,
15019 : : const struct rte_flow_op_attr *attr,
15020 : : const struct rte_flow_indir_action_conf *conf,
15021 : : const struct rte_flow_action *actions,
15022 : : void *user_data, struct rte_flow_error *error)
15023 : : {
15024 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15025 : 0 : struct mlx5_indlst_legacy *indlst_obj = mlx5_malloc(MLX5_MEM_ZERO,
15026 : : sizeof(*indlst_obj),
15027 : : 0, SOCKET_ID_ANY);
15028 : :
15029 [ # # ]: 0 : if (!indlst_obj)
15030 : : return NULL;
15031 : 0 : indlst_obj->handle = flow_hw_action_handle_create(dev, queue, attr, conf,
15032 : : actions, user_data,
15033 : : error);
15034 [ # # ]: 0 : if (!indlst_obj->handle) {
15035 : 0 : mlx5_free(indlst_obj);
15036 : 0 : return NULL;
15037 : : }
15038 : 0 : indlst_obj->legacy_type = actions[0].type;
15039 : 0 : indlst_obj->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY;
15040 [ # # ]: 0 : mlx5_indirect_list_add_entry(&priv->indirect_list_head, &indlst_obj->indirect);
15041 : 0 : return (struct rte_flow_action_list_handle *)indlst_obj;
15042 : : }
15043 : :
15044 : : static __rte_always_inline enum mlx5_indirect_list_type
15045 : : flow_hw_inlist_type_get(const struct rte_flow_action *actions)
15046 : : {
15047 [ # # # # ]: 0 : switch (actions[0].type) {
15048 : : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15049 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR;
15050 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
15051 : 0 : return actions[1].type == RTE_FLOW_ACTION_TYPE_END ?
15052 : 0 : MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY :
15053 : : MLX5_INDIRECT_ACTION_LIST_TYPE_ERR;
15054 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15055 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15056 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT;
15057 : : default:
15058 : : break;
15059 : : }
15060 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_ERR;
15061 : : }
15062 : :
15063 : : static struct rte_flow_action_list_handle*
15064 : 0 : mlx5_hw_decap_encap_handle_create(struct rte_eth_dev *dev,
15065 : : const struct mlx5_flow_template_table_cfg *table_cfg,
15066 : : const struct rte_flow_action *actions,
15067 : : struct rte_flow_error *error)
15068 : : {
15069 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15070 : : const struct rte_flow_attr *flow_attr = &table_cfg->attr.flow_attr;
15071 : : const struct rte_flow_action *encap = NULL;
15072 : : const struct rte_flow_action *decap = NULL;
15073 : 0 : struct rte_flow_indir_action_conf indirect_conf = {
15074 : 0 : .ingress = flow_attr->ingress,
15075 : 0 : .egress = flow_attr->egress,
15076 : 0 : .transfer = flow_attr->transfer,
15077 : : };
15078 : : struct mlx5_hw_encap_decap_action *handle;
15079 : : uint64_t action_flags = 0;
15080 : :
15081 : : /*
15082 : : * Allow
15083 : : * 1. raw_decap / raw_encap / end
15084 : : * 2. raw_encap / end
15085 : : * 3. raw_decap / end
15086 : : */
15087 [ # # ]: 0 : while (actions->type != RTE_FLOW_ACTION_TYPE_END) {
15088 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP) {
15089 [ # # ]: 0 : if (action_flags) {
15090 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15091 : : actions, "Invalid indirect action list sequence");
15092 : 0 : return NULL;
15093 : : }
15094 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15095 : : decap = actions;
15096 [ # # ]: 0 : } else if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15097 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP) {
15098 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15099 : : actions, "Invalid indirect action list sequence");
15100 : 0 : return NULL;
15101 : : }
15102 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15103 : : encap = actions;
15104 : : } else {
15105 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15106 : : actions, "Invalid indirect action type in list");
15107 : 0 : return NULL;
15108 : : }
15109 : 0 : actions++;
15110 : : }
15111 [ # # ]: 0 : if (!decap && !encap) {
15112 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15113 : : actions, "Invalid indirect action combinations");
15114 : 0 : return NULL;
15115 : : }
15116 : 0 : handle = mlx5_reformat_action_create(dev, &indirect_conf, encap, decap, error);
15117 [ # # ]: 0 : if (!handle) {
15118 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15119 : : actions, "Failed to create HWS decap_encap action");
15120 : 0 : return NULL;
15121 : : }
15122 : 0 : handle->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT;
15123 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->indirect_list_head, &handle->indirect, entry);
15124 : 0 : return (struct rte_flow_action_list_handle *)handle;
15125 : : }
15126 : :
15127 : : static struct rte_flow_action_list_handle *
15128 [ # # ]: 0 : flow_hw_async_action_list_handle_create(struct rte_eth_dev *dev, uint32_t queue,
15129 : : const struct rte_flow_op_attr *attr,
15130 : : const struct rte_flow_indir_action_conf *conf,
15131 : : const struct rte_flow_action *actions,
15132 : : void *user_data,
15133 : : struct rte_flow_error *error)
15134 : : {
15135 : : struct mlx5_hw_q_job *job = NULL;
15136 : : bool push = flow_hw_action_push(attr);
15137 : : enum mlx5_indirect_list_type list_type;
15138 : : struct rte_flow_action_list_handle *handle;
15139 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15140 : 0 : struct mlx5_flow_template_table_cfg table_cfg = {
15141 : : .external = true,
15142 : : .attr = {
15143 : : .flow_attr = {
15144 : 0 : .ingress = conf->ingress,
15145 : 0 : .egress = conf->egress,
15146 : 0 : .transfer = conf->transfer
15147 : : }
15148 : : }
15149 : : };
15150 : :
15151 [ # # ]: 0 : if (!mlx5_hw_ctx_validate(dev, error))
15152 : : return NULL;
15153 [ # # ]: 0 : if (!actions) {
15154 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15155 : : NULL, "No action list");
15156 : 0 : return NULL;
15157 : : }
15158 : : list_type = flow_hw_inlist_type_get(actions);
15159 [ # # ]: 0 : if (list_type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
15160 : : /*
15161 : : * Legacy indirect actions already have
15162 : : * async resources management. No need to do it twice.
15163 : : */
15164 : 0 : handle = mlx5_create_legacy_indlst(dev, queue, attr, conf,
15165 : : actions, user_data, error);
15166 : 0 : goto end;
15167 : : }
15168 [ # # ]: 0 : if (attr) {
15169 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
15170 : : NULL, MLX5_HW_Q_JOB_TYPE_CREATE,
15171 : : MLX5_HW_INDIRECT_TYPE_LIST, error);
15172 : : if (!job)
15173 : 0 : return NULL;
15174 : : }
15175 [ # # # ]: 0 : switch (list_type) {
15176 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
15177 : : /*
15178 : : * Mirror action is only supported in HWS group. Setting group to
15179 : : * non-zero will ensure that the action resources are allocated correctly.
15180 : : */
15181 : 0 : table_cfg.attr.flow_attr.group = 1;
15182 : 0 : handle = mlx5_hw_mirror_handle_create(dev, &table_cfg,
15183 : : actions, error);
15184 : 0 : break;
15185 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
15186 : 0 : handle = mlx5_hw_decap_encap_handle_create(dev, &table_cfg,
15187 : : actions, error);
15188 : 0 : break;
15189 : 0 : default:
15190 : : handle = NULL;
15191 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15192 : : actions, "Invalid list");
15193 : : }
15194 [ # # ]: 0 : if (job) {
15195 : 0 : job->action = handle;
15196 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, false,
15197 : : handle != NULL);
15198 : : }
15199 : 0 : end:
15200 : : return handle;
15201 : : }
15202 : :
15203 : : static struct rte_flow_action_list_handle *
15204 : 0 : flow_hw_action_list_handle_create(struct rte_eth_dev *dev,
15205 : : const struct rte_flow_indir_action_conf *conf,
15206 : : const struct rte_flow_action *actions,
15207 : : struct rte_flow_error *error)
15208 : : {
15209 : 0 : return flow_hw_async_action_list_handle_create(dev, MLX5_HW_INV_QUEUE,
15210 : : NULL, conf, actions,
15211 : : NULL, error);
15212 : : }
15213 : :
15214 : : static int
15215 [ # # ]: 0 : flow_hw_async_action_list_handle_destroy
15216 : : (struct rte_eth_dev *dev, uint32_t queue,
15217 : : const struct rte_flow_op_attr *attr,
15218 : : struct rte_flow_action_list_handle *handle,
15219 : : void *user_data, struct rte_flow_error *error)
15220 : : {
15221 : : int ret = 0;
15222 : : struct mlx5_hw_q_job *job = NULL;
15223 : : bool push = flow_hw_action_push(attr);
15224 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
15225 : : enum mlx5_indirect_list_type type =
15226 : : mlx5_get_indirect_list_type((void *)handle);
15227 : :
15228 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
15229 : : struct mlx5_indlst_legacy *legacy = (typeof(legacy))handle;
15230 : :
15231 : 0 : ret = flow_hw_action_handle_destroy(dev, queue, attr,
15232 : : legacy->handle,
15233 : : user_data, error);
15234 : : mlx5_indirect_list_remove_entry(&legacy->indirect);
15235 : 0 : mlx5_free(legacy);
15236 : 0 : goto end;
15237 : : }
15238 [ # # ]: 0 : if (attr) {
15239 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
15240 : : NULL, MLX5_HW_Q_JOB_TYPE_DESTROY,
15241 : : MLX5_HW_INDIRECT_TYPE_LIST, error);
15242 : : if (!job)
15243 : 0 : return rte_errno;
15244 : : }
15245 [ # # # ]: 0 : switch (type) {
15246 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
15247 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)handle);
15248 : 0 : break;
15249 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
15250 [ # # ]: 0 : LIST_REMOVE(&((struct mlx5_hw_encap_decap_action *)handle)->indirect,
15251 : : entry);
15252 : 0 : mlx5_reformat_action_destroy(dev, handle, error);
15253 : 0 : break;
15254 : 0 : default:
15255 : 0 : ret = rte_flow_error_set(error, EINVAL,
15256 : : RTE_FLOW_ERROR_TYPE_ACTION,
15257 : : NULL, "Invalid indirect list handle");
15258 : : }
15259 [ # # ]: 0 : if (job) {
15260 : : flow_hw_action_finalize(dev, queue, job, push, false, true);
15261 : : }
15262 : 0 : end:
15263 : : return ret;
15264 : : }
15265 : :
15266 : : static int
15267 : 0 : flow_hw_action_list_handle_destroy(struct rte_eth_dev *dev,
15268 : : struct rte_flow_action_list_handle *handle,
15269 : : struct rte_flow_error *error)
15270 : : {
15271 : 0 : return flow_hw_async_action_list_handle_destroy(dev, MLX5_HW_INV_QUEUE,
15272 : : NULL, handle, NULL,
15273 : : error);
15274 : : }
15275 : :
15276 : : static int
15277 [ # # ]: 0 : flow_hw_async_action_list_handle_query_update
15278 : : (struct rte_eth_dev *dev, uint32_t queue_id,
15279 : : const struct rte_flow_op_attr *attr,
15280 : : const struct rte_flow_action_list_handle *handle,
15281 : : const void **update, void **query,
15282 : : enum rte_flow_query_update_mode mode,
15283 : : void *user_data, struct rte_flow_error *error)
15284 : : {
15285 : : enum mlx5_indirect_list_type type =
15286 : : mlx5_get_indirect_list_type((const void *)handle);
15287 : :
15288 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
15289 : : struct mlx5_indlst_legacy *legacy = (void *)(uintptr_t)handle;
15290 : :
15291 [ # # ]: 0 : if (update && query)
15292 : 0 : return flow_hw_async_action_handle_query_update
15293 : : (dev, queue_id, attr, legacy->handle,
15294 : : update, query, mode, user_data, error);
15295 [ # # # # ]: 0 : else if (update && update[0])
15296 : 0 : return flow_hw_action_handle_update(dev, queue_id, attr,
15297 : : legacy->handle, update[0],
15298 : : user_data, error);
15299 [ # # # # ]: 0 : else if (query && query[0])
15300 : 0 : return flow_hw_action_handle_query(dev, queue_id, attr,
15301 : 0 : legacy->handle, query[0],
15302 : : user_data, error);
15303 : : else
15304 : 0 : return rte_flow_error_set(error, EINVAL,
15305 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15306 : : NULL, "invalid legacy handle query_update parameters");
15307 : : }
15308 : : return -ENOTSUP;
15309 : : }
15310 : :
15311 : : static int
15312 : 0 : flow_hw_action_list_handle_query_update(struct rte_eth_dev *dev,
15313 : : const struct rte_flow_action_list_handle *handle,
15314 : : const void **update, void **query,
15315 : : enum rte_flow_query_update_mode mode,
15316 : : struct rte_flow_error *error)
15317 : : {
15318 : 0 : return flow_hw_async_action_list_handle_query_update
15319 : : (dev, MLX5_HW_INV_QUEUE, NULL, handle,
15320 : : update, query, mode, NULL, error);
15321 : : }
15322 : :
15323 : : static int
15324 : 0 : flow_hw_calc_table_hash(struct rte_eth_dev *dev,
15325 : : const struct rte_flow_template_table *table,
15326 : : const struct rte_flow_item pattern[],
15327 : : uint8_t pattern_template_index,
15328 : : uint32_t *hash, struct rte_flow_error *error)
15329 : : {
15330 : : const struct rte_flow_item *items;
15331 : : struct mlx5_flow_hw_pattern_params pp;
15332 : : int res;
15333 : :
15334 : 0 : items = flow_hw_get_rule_items(dev, table, pattern,
15335 : : pattern_template_index,
15336 : : &pp);
15337 : 0 : res = mlx5dr_rule_hash_calculate(mlx5_table_matcher(table), items,
15338 : : pattern_template_index,
15339 : : MLX5DR_RULE_HASH_CALC_MODE_RAW,
15340 : : hash);
15341 [ # # ]: 0 : if (res)
15342 : 0 : return rte_flow_error_set(error, res,
15343 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15344 : : NULL,
15345 : : "hash could not be calculated");
15346 : : return 0;
15347 : : }
15348 : :
15349 : : static int
15350 : 0 : flow_hw_calc_encap_hash(struct rte_eth_dev *dev,
15351 : : const struct rte_flow_item pattern[],
15352 : : enum rte_flow_encap_hash_field dest_field,
15353 : : uint8_t *hash,
15354 : : struct rte_flow_error *error)
15355 : : {
15356 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15357 : : struct mlx5dr_crc_encap_entropy_hash_fields data;
15358 : 0 : enum mlx5dr_crc_encap_entropy_hash_size res_size =
15359 : : dest_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ?
15360 : 0 : MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16 :
15361 : : MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8;
15362 : : int res;
15363 : :
15364 : : memset(&data, 0, sizeof(struct mlx5dr_crc_encap_entropy_hash_fields));
15365 : :
15366 [ # # ]: 0 : for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
15367 [ # # # # : 0 : switch (pattern->type) {
# # # # ]
15368 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
15369 : 0 : data.dst.ipv4_addr =
15370 : 0 : ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.dst_addr;
15371 : 0 : data.src.ipv4_addr =
15372 : 0 : ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.src_addr;
15373 : 0 : data.next_protocol = ((const struct rte_flow_item_ipv4 *)
15374 : 0 : (pattern->spec))->hdr.next_proto_id;
15375 : 0 : break;
15376 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
15377 : : memcpy(data.dst.ipv6_addr,
15378 : 0 : &((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.dst_addr,
15379 : : sizeof(data.dst.ipv6_addr));
15380 : : memcpy(data.src.ipv6_addr,
15381 : : &((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.src_addr,
15382 : : sizeof(data.src.ipv6_addr));
15383 : 0 : data.next_protocol = ((const struct rte_flow_item_ipv6 *)
15384 : 0 : (pattern->spec))->hdr.proto;
15385 : 0 : break;
15386 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
15387 : 0 : data.next_protocol = IPPROTO_UDP;
15388 : 0 : data.dst_port =
15389 : 0 : ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.dst_port;
15390 : 0 : data.src_port =
15391 : 0 : ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.src_port;
15392 : 0 : break;
15393 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
15394 : 0 : data.next_protocol = IPPROTO_TCP;
15395 : 0 : data.dst_port =
15396 : 0 : ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.dst_port;
15397 : 0 : data.src_port =
15398 : 0 : ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.src_port;
15399 : 0 : break;
15400 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
15401 : 0 : data.next_protocol = IPPROTO_ICMP;
15402 : 0 : break;
15403 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
15404 : 0 : data.next_protocol = IPPROTO_ICMPV6;
15405 : 0 : break;
15406 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
15407 : 0 : data.next_protocol = IPPROTO_GRE;
15408 : 0 : break;
15409 : : default:
15410 : : break;
15411 : : }
15412 : : }
15413 : 0 : res = mlx5dr_crc_encap_entropy_hash_calc(priv->dr_ctx, &data, hash, res_size);
15414 [ # # ]: 0 : if (res)
15415 : 0 : return rte_flow_error_set(error, res,
15416 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15417 : : NULL, "error while calculating encap hash");
15418 : : return 0;
15419 : : }
15420 : :
15421 : : static int
15422 : 0 : flow_hw_table_resize_multi_pattern_actions(struct rte_eth_dev *dev,
15423 : : struct rte_flow_template_table *table,
15424 : : uint32_t nb_flows,
15425 : : struct rte_flow_error *error)
15426 : : {
15427 : 0 : struct mlx5_multi_pattern_segment *segment = table->mpctx.segments;
15428 : : uint32_t bulk_size;
15429 : : int i, ret;
15430 : :
15431 : : /**
15432 : : * Segment always allocates Modify Header Argument Objects number in
15433 : : * powers of 2.
15434 : : * On resize, PMD adds minimal required argument objects number.
15435 : : * For example, if table size was 10, it allocated 16 argument objects.
15436 : : * Resize to 15 will not add new objects.
15437 : : */
15438 : 0 : for (i = 1;
15439 [ # # # # ]: 0 : i < MLX5_MAX_TABLE_RESIZE_NUM && segment->capacity;
15440 : 0 : i++, segment++) {
15441 : : /* keep the devtools/checkpatches.sh happy */
15442 : : }
15443 [ # # ]: 0 : if (i == MLX5_MAX_TABLE_RESIZE_NUM)
15444 : 0 : return rte_flow_error_set(error, EINVAL,
15445 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15446 : : table, "too many resizes");
15447 [ # # ]: 0 : if (segment->head_index - 1 >= nb_flows)
15448 : : return 0;
15449 [ # # ]: 0 : bulk_size = rte_align32pow2(nb_flows - segment->head_index + 1);
15450 : 0 : ret = mlx5_tbl_multi_pattern_process(dev, table, segment,
15451 : : rte_log2_u32(bulk_size),
15452 : : error);
15453 [ # # ]: 0 : if (ret)
15454 : 0 : return rte_flow_error_set(error, EINVAL,
15455 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15456 : : table, "too many resizes");
15457 : : return i;
15458 : : }
15459 : :
15460 : : static int
15461 : 0 : flow_hw_table_resize(struct rte_eth_dev *dev,
15462 : : struct rte_flow_template_table *table,
15463 : : uint32_t nb_flows,
15464 : : struct rte_flow_error *error)
15465 : : {
15466 : : struct mlx5dr_action_template *at[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
15467 : : struct mlx5dr_match_template *mt[MLX5_HW_TBL_MAX_ITEM_TEMPLATE];
15468 : 0 : struct mlx5dr_matcher_attr matcher_attr = table->matcher_attr;
15469 : 0 : struct mlx5dr_action_jump_to_matcher_attr jump_attr = {
15470 : : .type = MLX5DR_ACTION_JUMP_TO_MATCHER_BY_INDEX,
15471 : : .matcher = NULL,
15472 : : };
15473 : : struct mlx5_multi_pattern_segment *segment = NULL;
15474 : : struct mlx5dr_matcher *matcher = NULL;
15475 : : struct mlx5dr_action *jump = NULL;
15476 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15477 : 0 : uint32_t i, selector = table->matcher_selector;
15478 : 0 : uint32_t other_selector = (selector + 1) & 1;
15479 : : int ret;
15480 : :
15481 [ # # ]: 0 : if (!rte_flow_template_table_resizable(dev->data->port_id, &table->cfg.attr))
15482 : 0 : return rte_flow_error_set(error, EINVAL,
15483 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15484 : : table, "no resizable attribute");
15485 [ # # ]: 0 : if (table->matcher_info[other_selector].matcher)
15486 : 0 : return rte_flow_error_set(error, EINVAL,
15487 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15488 : : table, "last table resize was not completed");
15489 [ # # ]: 0 : if (nb_flows <= table->cfg.attr.nb_flows)
15490 : 0 : return rte_flow_error_set(error, EINVAL,
15491 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15492 : : table, "shrinking table is not supported");
15493 : 0 : ret = mlx5_ipool_resize(table->flow_pool, nb_flows, error);
15494 [ # # ]: 0 : if (ret)
15495 : : return ret;
15496 : : /*
15497 : : * A resizable matcher doesn't support rule update. In this case, the ipool
15498 : : * for the resource is not created and there is no need to resize it.
15499 : : */
15500 : : MLX5_ASSERT(!table->resource);
15501 [ # # ]: 0 : if (mlx5_is_multi_pattern_active(&table->mpctx)) {
15502 : 0 : ret = flow_hw_table_resize_multi_pattern_actions(dev, table, nb_flows, error);
15503 [ # # ]: 0 : if (ret < 0)
15504 : : return ret;
15505 [ # # ]: 0 : if (ret > 0)
15506 : 0 : segment = table->mpctx.segments + ret;
15507 : : }
15508 [ # # ]: 0 : for (i = 0; i < table->nb_item_templates; i++)
15509 : 0 : mt[i] = table->its[i]->mt;
15510 [ # # ]: 0 : for (i = 0; i < table->nb_action_templates; i++)
15511 : 0 : at[i] = table->ats[i].action_template->tmpl;
15512 : : nb_flows = rte_align32pow2(nb_flows);
15513 : 0 : matcher_attr.rule.num_log = rte_log2_u32(nb_flows);
15514 : 0 : matcher = mlx5dr_matcher_create(table->grp->tbl, mt,
15515 : : table->nb_item_templates, at,
15516 : : table->nb_action_templates,
15517 : : &matcher_attr);
15518 [ # # ]: 0 : if (!matcher) {
15519 : 0 : ret = rte_flow_error_set(error, rte_errno,
15520 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15521 : : table, "failed to create new matcher");
15522 : 0 : goto error;
15523 : : }
15524 [ # # ]: 0 : if (matcher_attr.isolated) {
15525 : 0 : jump_attr.matcher = matcher;
15526 : 0 : jump = mlx5dr_action_create_jump_to_matcher(priv->dr_ctx, &jump_attr,
15527 : 0 : mlx5_hw_act_flag[!!table->cfg.attr.flow_attr.group][table->type]);
15528 [ # # ]: 0 : if (!jump) {
15529 : 0 : ret = rte_flow_error_set(error, rte_errno,
15530 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15531 : : table, "failed to create jump to matcher action");
15532 : 0 : goto error;
15533 : : }
15534 : : }
15535 : 0 : rte_rwlock_write_lock(&table->matcher_replace_rwlk);
15536 : 0 : ret = mlx5dr_matcher_resize_set_target
15537 : : (table->matcher_info[selector].matcher, matcher);
15538 [ # # ]: 0 : if (ret) {
15539 : : rte_rwlock_write_unlock(&table->matcher_replace_rwlk);
15540 : 0 : ret = rte_flow_error_set(error, rte_errno,
15541 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15542 : : table, "failed to initiate matcher swap");
15543 : 0 : goto error;
15544 : : }
15545 : 0 : table->cfg.attr.nb_flows = nb_flows;
15546 : 0 : table->matcher_info[other_selector].matcher = matcher;
15547 : 0 : table->matcher_info[other_selector].jump = jump;
15548 : 0 : table->matcher_selector = other_selector;
15549 : 0 : rte_atomic_store_explicit(&table->matcher_info[other_selector].refcnt,
15550 : : 0, rte_memory_order_relaxed);
15551 : : rte_rwlock_write_unlock(&table->matcher_replace_rwlk);
15552 : 0 : return 0;
15553 : 0 : error:
15554 [ # # ]: 0 : if (segment)
15555 : 0 : mlx5_destroy_multi_pattern_segment(segment);
15556 [ # # ]: 0 : if (jump)
15557 : 0 : mlx5dr_action_destroy(jump);
15558 [ # # ]: 0 : if (matcher) {
15559 : 0 : ret = mlx5dr_matcher_destroy(matcher);
15560 : 0 : return rte_flow_error_set(error, rte_errno,
15561 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15562 : : table, "failed to destroy new matcher");
15563 : : }
15564 : : return ret;
15565 : : }
15566 : :
15567 : : static int
15568 : 0 : flow_hw_table_resize_complete(struct rte_eth_dev *dev,
15569 : : struct rte_flow_template_table *table,
15570 : : struct rte_flow_error *error)
15571 : : {
15572 : : int ret;
15573 : 0 : uint32_t selector = table->matcher_selector;
15574 : 0 : uint32_t other_selector = (selector + 1) & 1;
15575 : : struct mlx5_matcher_info *matcher_info = &table->matcher_info[other_selector];
15576 : : uint32_t matcher_refcnt;
15577 : :
15578 [ # # ]: 0 : if (!rte_flow_template_table_resizable(dev->data->port_id, &table->cfg.attr))
15579 : 0 : return rte_flow_error_set(error, EINVAL,
15580 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15581 : : table, "no resizable attribute");
15582 [ # # ]: 0 : if (matcher_info->matcher == NULL)
15583 : 0 : return rte_flow_error_set(error, EINVAL,
15584 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15585 : : table, "table resize was not started");
15586 : 0 : matcher_refcnt = rte_atomic_load_explicit(&matcher_info->refcnt,
15587 : : rte_memory_order_relaxed);
15588 [ # # ]: 0 : if (matcher_refcnt > 0)
15589 : 0 : return rte_flow_error_set(error, EBUSY,
15590 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15591 : : table, "all rules not yet updated");
15592 [ # # ]: 0 : if (matcher_info->jump)
15593 : 0 : mlx5dr_action_destroy(matcher_info->jump);
15594 : 0 : ret = mlx5dr_matcher_destroy(matcher_info->matcher);
15595 [ # # ]: 0 : if (ret)
15596 : 0 : return rte_flow_error_set(error, rte_errno,
15597 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15598 : : table, "failed to destroy retired matcher");
15599 : 0 : matcher_info->matcher = NULL;
15600 : 0 : return 0;
15601 : : }
15602 : :
15603 : : static int
15604 : 0 : flow_hw_update_resized(struct rte_eth_dev *dev, uint32_t queue,
15605 : : const struct rte_flow_op_attr *attr,
15606 : : struct rte_flow *flow, void *user_data,
15607 : : struct rte_flow_error *error)
15608 : : {
15609 : : int ret;
15610 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15611 : : struct rte_flow_hw *hw_flow = (struct rte_flow_hw *)flow;
15612 : 0 : struct rte_flow_template_table *table = hw_flow->table;
15613 [ # # ]: 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, hw_flow);
15614 : 0 : uint32_t table_selector = table->matcher_selector;
15615 : 0 : uint32_t rule_selector = aux->matcher_selector;
15616 : : uint32_t other_selector;
15617 : : struct mlx5dr_matcher *other_matcher;
15618 : 0 : struct mlx5dr_rule_attr rule_attr = {
15619 : : .queue_id = queue,
15620 : 0 : .burst = attr->postpone,
15621 : : };
15622 : :
15623 : : MLX5_ASSERT(hw_flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR);
15624 : : /*
15625 : : * Update resized can be called only through async flow API.
15626 : : * These rings are allocated if and only if async flow API was configured.
15627 : : */
15628 : : MLX5_ASSERT(priv->hw_q[queue].flow_transfer_completed != NULL);
15629 : : MLX5_ASSERT(priv->hw_q[queue].flow_transfer_pending != NULL);
15630 : : /**
15631 : : * mlx5dr_matcher_resize_rule_move() accepts original table matcher -
15632 : : * the one that was used BEFORE table resize.
15633 : : * Since the function is called AFTER table resize,
15634 : : * `table->matcher_selector` always points to the new matcher and
15635 : : * `aux->matcher_selector` points to a matcher used to create the flow.
15636 : : */
15637 : : other_selector = rule_selector == table_selector ?
15638 [ # # ]: 0 : (rule_selector + 1) & 1 : rule_selector;
15639 : 0 : other_matcher = table->matcher_info[other_selector].matcher;
15640 [ # # ]: 0 : if (!other_matcher)
15641 : 0 : return rte_flow_error_set(error, EINVAL,
15642 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15643 : : "no active table resize");
15644 : 0 : hw_flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE;
15645 : 0 : hw_flow->user_data = user_data;
15646 : 0 : rule_attr.user_data = hw_flow;
15647 [ # # ]: 0 : if (rule_selector == table_selector) {
15648 : 0 : struct rte_ring *ring = !attr->postpone ?
15649 [ # # ]: 0 : priv->hw_q[queue].flow_transfer_completed :
15650 : 0 : priv->hw_q[queue].flow_transfer_pending;
15651 : 0 : rte_ring_enqueue(ring, hw_flow);
15652 : : flow_hw_q_inc_flow_ops(priv, queue);
15653 : 0 : return 0;
15654 : : }
15655 : 0 : ret = mlx5dr_matcher_resize_rule_move(other_matcher,
15656 : 0 : (struct mlx5dr_rule *)hw_flow->rule,
15657 : : &rule_attr);
15658 [ # # ]: 0 : if (ret) {
15659 : 0 : return rte_flow_error_set(error, rte_errno,
15660 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15661 : : "flow transfer failed");
15662 : : }
15663 : : flow_hw_q_inc_flow_ops(priv, queue);
15664 : 0 : return 0;
15665 : : }
15666 : :
15667 : : /**
15668 : : * Internal validation function. For validating both actions and items.
15669 : : *
15670 : : * @param[in] dev
15671 : : * Pointer to the rte_eth_dev structure.
15672 : : * @param[in] attr
15673 : : * Pointer to the flow attributes.
15674 : : * @param[in] items
15675 : : * Pointer to the list of items.
15676 : : * @param[in] actions
15677 : : * Pointer to the list of actions.
15678 : : * @param[in] external
15679 : : * This flow rule is created by request external to PMD.
15680 : : * @param[in] hairpin
15681 : : * Number of hairpin TX actions, 0 means classic flow.
15682 : : * @param[out] error
15683 : : * Pointer to the error structure.
15684 : : *
15685 : : * @return
15686 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15687 : : */
15688 : : static int
15689 : 0 : flow_hw_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
15690 : : const struct rte_flow_item items[],
15691 : : const struct rte_flow_action actions[] __rte_unused,
15692 : : bool external, int hairpin __rte_unused,
15693 : : struct rte_flow_error *error)
15694 : : {
15695 : 0 : const struct rte_flow_pattern_template_attr pattern_template_attr = {
15696 : : .relaxed_matching = 0,
15697 : 0 : .ingress = attr->ingress,
15698 : 0 : .egress = attr->egress,
15699 : 0 : .transfer = attr->transfer,
15700 : : };
15701 : 0 : uint64_t item_flags = 0;
15702 : : int ret = 0;
15703 : :
15704 [ # # ]: 0 : if (external) {
15705 : : /* Validate application items only */
15706 : 0 : ret = __flow_hw_pattern_validate(dev, &pattern_template_attr, items,
15707 : : &item_flags, true, error);
15708 [ # # ]: 0 : if (ret < 0)
15709 : 0 : return -rte_errno;
15710 : : }
15711 : : return 0;
15712 : : }
15713 : :
15714 : :
15715 : : const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = {
15716 : : .list_create = flow_hw_list_create,
15717 : : .list_destroy = mlx5_flow_hw_list_destroy,
15718 : : .validate = flow_hw_validate,
15719 : : .info_get = flow_hw_info_get,
15720 : : .configure = flow_hw_configure,
15721 : : .pattern_validate = flow_hw_pattern_validate,
15722 : : .pattern_template_create = flow_hw_external_pattern_template_create,
15723 : : .pattern_template_destroy = flow_hw_pattern_template_destroy,
15724 : : .actions_validate = flow_hw_actions_validate,
15725 : : .actions_template_create = flow_hw_actions_template_create,
15726 : : .actions_template_destroy = flow_hw_actions_template_destroy,
15727 : : .template_table_create = flow_hw_template_table_create,
15728 : : .template_table_destroy = flow_hw_table_destroy,
15729 : : .table_resize = flow_hw_table_resize,
15730 : : .group_set_miss_actions = mlx5_flow_hw_group_set_miss_actions,
15731 : : .async_flow_create = flow_hw_async_flow_create,
15732 : : .async_flow_create_by_index = flow_hw_async_flow_create_by_index,
15733 : : .async_flow_update = flow_hw_async_flow_update,
15734 : : .async_flow_destroy = flow_hw_async_flow_destroy,
15735 : : .flow_update_resized = flow_hw_update_resized,
15736 : : .table_resize_complete = flow_hw_table_resize_complete,
15737 : : .pull = flow_hw_pull,
15738 : : .push = flow_hw_push,
15739 : : .async_action_create = flow_hw_action_handle_create,
15740 : : .async_action_destroy = flow_hw_action_handle_destroy,
15741 : : .async_action_update = flow_hw_action_handle_update,
15742 : : .async_action_query_update = flow_hw_async_action_handle_query_update,
15743 : : .async_action_query = flow_hw_action_handle_query,
15744 : : .action_validate = flow_hw_action_validate,
15745 : : .action_create = flow_hw_action_create,
15746 : : .action_destroy = flow_hw_action_destroy,
15747 : : .action_update = flow_hw_action_update,
15748 : : .action_query = flow_hw_action_query,
15749 : : .action_query_update = flow_hw_action_query_update,
15750 : : .action_list_handle_create = flow_hw_action_list_handle_create,
15751 : : .action_list_handle_destroy = flow_hw_action_list_handle_destroy,
15752 : : .action_list_handle_query_update =
15753 : : flow_hw_action_list_handle_query_update,
15754 : : .async_action_list_handle_create =
15755 : : flow_hw_async_action_list_handle_create,
15756 : : .async_action_list_handle_destroy =
15757 : : flow_hw_async_action_list_handle_destroy,
15758 : : .async_action_list_handle_query_update =
15759 : : flow_hw_async_action_list_handle_query_update,
15760 : : .query = flow_hw_query,
15761 : : .get_aged_flows = flow_hw_get_aged_flows,
15762 : : .get_q_aged_flows = flow_hw_get_q_aged_flows,
15763 : : .item_create = mlx5_flow_dv_item_create,
15764 : : .item_release = mlx5_flow_dv_item_release,
15765 : : .flow_calc_table_hash = flow_hw_calc_table_hash,
15766 : : .flow_calc_encap_hash = flow_hw_calc_encap_hash,
15767 : : };
15768 : :
15769 : : /**
15770 : : * Creates a control flow using flow template API on @p proxy_dev device,
15771 : : * on behalf of @p owner_dev device.
15772 : : *
15773 : : * This function uses locks internally to synchronize access to the
15774 : : * flow queue.
15775 : : *
15776 : : * Created flow is stored in private list associated with @p proxy_dev device.
15777 : : *
15778 : : * @param owner_dev
15779 : : * Pointer to Ethernet device on behalf of which flow is created.
15780 : : * @param proxy_dev
15781 : : * Pointer to Ethernet device on which flow is created.
15782 : : * @param table
15783 : : * Pointer to flow table.
15784 : : * @param items
15785 : : * Pointer to flow rule items.
15786 : : * @param item_template_idx
15787 : : * Index of an item template associated with @p table.
15788 : : * @param actions
15789 : : * Pointer to flow rule actions.
15790 : : * @param action_template_idx
15791 : : * Index of an action template associated with @p table.
15792 : : * @param info
15793 : : * Additional info about control flow rule.
15794 : : * @param external
15795 : : * External ctrl flow.
15796 : : *
15797 : : * @return
15798 : : * 0 on success, negative errno value otherwise and rte_errno set.
15799 : : */
15800 : : static __rte_unused int
15801 : 0 : flow_hw_create_ctrl_flow(struct rte_eth_dev *owner_dev,
15802 : : struct rte_eth_dev *proxy_dev,
15803 : : struct rte_flow_template_table *table,
15804 : : struct rte_flow_item items[],
15805 : : uint8_t item_template_idx,
15806 : : struct rte_flow_action actions[],
15807 : : uint8_t action_template_idx,
15808 : : struct mlx5_ctrl_flow_info *info,
15809 : : bool external)
15810 : : {
15811 : 0 : struct mlx5_priv *priv = proxy_dev->data->dev_private;
15812 : 0 : uint32_t queue = CTRL_QUEUE_ID(priv);
15813 : 0 : struct rte_flow_op_attr op_attr = {
15814 : : .postpone = 0,
15815 : : };
15816 : : struct rte_flow *flow = NULL;
15817 : : struct mlx5_ctrl_flow_entry *entry = NULL;
15818 : : int ret;
15819 : :
15820 : 0 : rte_spinlock_lock(&priv->hw_ctrl_lock);
15821 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_SYS, sizeof(*entry),
15822 : : 0, SOCKET_ID_ANY);
15823 [ # # ]: 0 : if (!entry) {
15824 : 0 : DRV_LOG(ERR, "port %u not enough memory to create control flows",
15825 : : proxy_dev->data->port_id);
15826 : 0 : rte_errno = ENOMEM;
15827 : : ret = -rte_errno;
15828 : 0 : goto error;
15829 : : }
15830 : 0 : flow = flow_hw_async_flow_create(proxy_dev, queue, &op_attr, table,
15831 : : items, item_template_idx,
15832 : : actions, action_template_idx,
15833 : : NULL, NULL);
15834 [ # # ]: 0 : if (!flow) {
15835 : 0 : DRV_LOG(ERR, "port %u failed to enqueue create control"
15836 : : " flow operation", proxy_dev->data->port_id);
15837 : 0 : ret = -rte_errno;
15838 : 0 : goto error;
15839 : : }
15840 : 0 : ret = __flow_hw_pull_comp(proxy_dev, queue, NULL);
15841 [ # # ]: 0 : if (ret) {
15842 : 0 : DRV_LOG(ERR, "port %u failed to insert control flow",
15843 : : proxy_dev->data->port_id);
15844 : 0 : rte_errno = EINVAL;
15845 : : ret = -rte_errno;
15846 : 0 : goto error;
15847 : : }
15848 : 0 : entry->owner_dev = owner_dev;
15849 : 0 : entry->flow = flow;
15850 [ # # ]: 0 : if (info)
15851 : 0 : entry->info = *info;
15852 : : else
15853 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_GENERAL;
15854 [ # # ]: 0 : if (external)
15855 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ext_ctrl_flows, entry, next);
15856 : : else
15857 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
15858 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
15859 : 0 : return 0;
15860 : 0 : error:
15861 [ # # ]: 0 : if (entry)
15862 : 0 : mlx5_free(entry);
15863 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
15864 : 0 : return ret;
15865 : : }
15866 : :
15867 : : /**
15868 : : * Destroys a control flow @p flow using flow template API on @p dev device.
15869 : : *
15870 : : * This function uses locks internally to synchronize access to the
15871 : : * flow queue.
15872 : : *
15873 : : * If the @p flow is stored on any private list/pool, then caller must free up
15874 : : * the relevant resources.
15875 : : *
15876 : : * @param dev
15877 : : * Pointer to Ethernet device.
15878 : : * @param flow
15879 : : * Pointer to flow rule.
15880 : : *
15881 : : * @return
15882 : : * 0 on success, non-zero value otherwise.
15883 : : */
15884 : : static int
15885 : 0 : flow_hw_destroy_ctrl_flow(struct rte_eth_dev *dev, struct rte_flow *flow)
15886 : : {
15887 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15888 : 0 : uint32_t queue = CTRL_QUEUE_ID(priv);
15889 : 0 : struct rte_flow_op_attr op_attr = {
15890 : : .postpone = 0,
15891 : : };
15892 : : int ret;
15893 : :
15894 : 0 : rte_spinlock_lock(&priv->hw_ctrl_lock);
15895 : 0 : ret = flow_hw_async_flow_destroy(dev, queue, &op_attr, flow, NULL, NULL);
15896 [ # # ]: 0 : if (ret) {
15897 : 0 : DRV_LOG(ERR, "port %u failed to enqueue destroy control"
15898 : : " flow operation", dev->data->port_id);
15899 : 0 : goto exit;
15900 : : }
15901 : 0 : ret = __flow_hw_pull_comp(dev, queue, NULL);
15902 [ # # ]: 0 : if (ret) {
15903 : 0 : DRV_LOG(ERR, "port %u failed to destroy control flow",
15904 : : dev->data->port_id);
15905 : 0 : rte_errno = EINVAL;
15906 : : ret = -rte_errno;
15907 : 0 : goto exit;
15908 : : }
15909 : 0 : exit:
15910 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
15911 : 0 : return ret;
15912 : : }
15913 : :
15914 : : /**
15915 : : * Destroys control flows created on behalf of @p owner device on @p dev device.
15916 : : *
15917 : : * @param dev
15918 : : * Pointer to Ethernet device on which control flows were created.
15919 : : * @param owner
15920 : : * Pointer to Ethernet device owning control flows.
15921 : : *
15922 : : * @return
15923 : : * 0 on success, otherwise negative error code is returned and
15924 : : * rte_errno is set.
15925 : : */
15926 : : static int
15927 : 0 : flow_hw_flush_ctrl_flows_owned_by(struct rte_eth_dev *dev, struct rte_eth_dev *owner)
15928 : : {
15929 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15930 : : struct mlx5_ctrl_flow_entry *cf;
15931 : : struct mlx5_ctrl_flow_entry *cf_next;
15932 : : int ret;
15933 : :
15934 : 0 : cf = LIST_FIRST(&priv->hw_ctrl_flows);
15935 [ # # ]: 0 : while (cf != NULL) {
15936 : 0 : cf_next = LIST_NEXT(cf, next);
15937 [ # # ]: 0 : if (cf->owner_dev == owner) {
15938 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
15939 [ # # ]: 0 : if (ret) {
15940 : 0 : rte_errno = ret;
15941 : 0 : return -ret;
15942 : : }
15943 [ # # ]: 0 : LIST_REMOVE(cf, next);
15944 : 0 : mlx5_free(cf);
15945 : : }
15946 : : cf = cf_next;
15947 : : }
15948 : : return 0;
15949 : : }
15950 : :
15951 : : /**
15952 : : * Destroys control flows created for @p owner_dev device.
15953 : : *
15954 : : * @param owner_dev
15955 : : * Pointer to Ethernet device owning control flows.
15956 : : *
15957 : : * @return
15958 : : * 0 on success, otherwise negative error code is returned and
15959 : : * rte_errno is set.
15960 : : */
15961 : : int
15962 : 0 : mlx5_flow_hw_flush_ctrl_flows(struct rte_eth_dev *owner_dev)
15963 : : {
15964 : 0 : struct mlx5_priv *owner_priv = owner_dev->data->dev_private;
15965 : : struct rte_eth_dev *proxy_dev;
15966 : 0 : uint16_t owner_port_id = owner_dev->data->port_id;
15967 : 0 : uint16_t proxy_port_id = owner_dev->data->port_id;
15968 : : int ret;
15969 : :
15970 : : /* Flush all flows created by this port for itself. */
15971 : 0 : ret = flow_hw_flush_ctrl_flows_owned_by(owner_dev, owner_dev);
15972 [ # # ]: 0 : if (ret)
15973 : : return ret;
15974 : : /* Flush all flows created for this port on proxy port. */
15975 [ # # ]: 0 : if (owner_priv->sh->config.dv_esw_en) {
15976 : 0 : ret = rte_flow_pick_transfer_proxy(owner_port_id, &proxy_port_id, NULL);
15977 [ # # ]: 0 : if (ret == -ENODEV) {
15978 : 0 : DRV_LOG(DEBUG, "Unable to find transfer proxy port for port %u. It was "
15979 : : "probably closed. Control flows were cleared.",
15980 : : owner_port_id);
15981 : 0 : rte_errno = 0;
15982 : 0 : return 0;
15983 [ # # ]: 0 : } else if (ret) {
15984 : 0 : DRV_LOG(ERR, "Unable to find proxy port for port %u (ret = %d)",
15985 : : owner_port_id, ret);
15986 : 0 : return ret;
15987 : : }
15988 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
15989 : : } else {
15990 : : proxy_dev = owner_dev;
15991 : : }
15992 : 0 : return flow_hw_flush_ctrl_flows_owned_by(proxy_dev, owner_dev);
15993 : : }
15994 : :
15995 : : /**
15996 : : * Destroys all control flows created on @p dev device.
15997 : : *
15998 : : * @param owner_dev
15999 : : * Pointer to Ethernet device.
16000 : : *
16001 : : * @return
16002 : : * 0 on success, otherwise negative error code is returned and
16003 : : * rte_errno is set.
16004 : : */
16005 : : static int
16006 : 0 : flow_hw_flush_all_ctrl_flows(struct rte_eth_dev *dev)
16007 : : {
16008 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16009 : : struct mlx5_ctrl_flow_entry *cf;
16010 : : struct mlx5_ctrl_flow_entry *cf_next;
16011 : : int ret;
16012 : :
16013 : 0 : cf = LIST_FIRST(&priv->hw_ctrl_flows);
16014 [ # # ]: 0 : while (cf != NULL) {
16015 : 0 : cf_next = LIST_NEXT(cf, next);
16016 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
16017 [ # # ]: 0 : if (ret) {
16018 : 0 : rte_errno = ret;
16019 : 0 : return -ret;
16020 : : }
16021 [ # # ]: 0 : LIST_REMOVE(cf, next);
16022 : 0 : mlx5_free(cf);
16023 : : cf = cf_next;
16024 : : }
16025 : 0 : cf = LIST_FIRST(&priv->hw_ext_ctrl_flows);
16026 [ # # ]: 0 : while (cf != NULL) {
16027 : 0 : cf_next = LIST_NEXT(cf, next);
16028 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
16029 [ # # ]: 0 : if (ret) {
16030 : 0 : rte_errno = ret;
16031 : 0 : return -ret;
16032 : : }
16033 [ # # ]: 0 : LIST_REMOVE(cf, next);
16034 : 0 : mlx5_free(cf);
16035 : : cf = cf_next;
16036 : : }
16037 : : return 0;
16038 : : }
16039 : :
16040 : : int
16041 : 0 : mlx5_flow_hw_esw_create_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16042 : : {
16043 : 0 : uint16_t port_id = dev->data->port_id;
16044 : 0 : struct rte_flow_item_ethdev esw_mgr_spec = {
16045 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
16046 : : };
16047 : 0 : struct rte_flow_item_ethdev esw_mgr_mask = {
16048 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
16049 : : };
16050 : 0 : struct rte_flow_item_tag reg_c0_spec = {
16051 : : .index = (uint8_t)REG_C_0,
16052 : : .data = flow_hw_esw_mgr_regc_marker(dev),
16053 : : };
16054 : 0 : struct rte_flow_item_tag reg_c0_mask = {
16055 : : .index = 0xff,
16056 : : .data = flow_hw_esw_mgr_regc_marker_mask(dev),
16057 : : };
16058 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
16059 : : .queue = sqn,
16060 : : };
16061 : 0 : struct rte_flow_action_ethdev port = {
16062 : : .port_id = port_id,
16063 : : };
16064 : 0 : struct rte_flow_item items[3] = { { 0 } };
16065 : 0 : struct rte_flow_action actions[3] = { { 0 } };
16066 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16067 : : .type = MLX5_CTRL_FLOW_TYPE_SQ_MISS_ROOT,
16068 : : .esw_mgr_sq = sqn,
16069 : : };
16070 : : struct rte_eth_dev *proxy_dev;
16071 : : struct mlx5_priv *proxy_priv;
16072 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16073 : : int ret;
16074 : :
16075 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16076 [ # # ]: 0 : if (ret) {
16077 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16078 : : "port must be present to create default SQ miss flows.",
16079 : : port_id);
16080 : 0 : return ret;
16081 : : }
16082 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16083 : 0 : proxy_priv = proxy_dev->data->dev_private;
16084 [ # # ]: 0 : if (!proxy_priv->dr_ctx) {
16085 : 0 : DRV_LOG(DEBUG, "Transfer proxy port (port %u) of port %u must be configured "
16086 : : "for HWS to create default SQ miss flows. Default flows will "
16087 : : "not be created.",
16088 : : proxy_port_id, port_id);
16089 : 0 : return 0;
16090 : : }
16091 [ # # ]: 0 : if (!proxy_priv->hw_ctrl_fdb ||
16092 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_root_tbl ||
16093 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_tbl) {
16094 : 0 : DRV_LOG(ERR, "Transfer proxy port (port %u) of port %u was configured, but "
16095 : : "default flow tables were not created.",
16096 : : proxy_port_id, port_id);
16097 : 0 : rte_errno = ENOMEM;
16098 : 0 : return -rte_errno;
16099 : : }
16100 : : /*
16101 : : * Create a root SQ miss flow rule - match E-Switch Manager and SQ,
16102 : : * and jump to group 1.
16103 : : */
16104 : 0 : items[0] = (struct rte_flow_item){
16105 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
16106 : : .spec = &esw_mgr_spec,
16107 : : .mask = &esw_mgr_mask,
16108 : : };
16109 : 0 : items[1] = (struct rte_flow_item){
16110 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16111 : : .spec = &sq_spec,
16112 : : };
16113 : 0 : items[2] = (struct rte_flow_item){
16114 : : .type = RTE_FLOW_ITEM_TYPE_END,
16115 : : };
16116 : 0 : actions[0] = (struct rte_flow_action){
16117 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
16118 : : };
16119 : 0 : actions[1] = (struct rte_flow_action){
16120 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
16121 : : };
16122 : 0 : actions[2] = (struct rte_flow_action) {
16123 : : .type = RTE_FLOW_ACTION_TYPE_END,
16124 : : };
16125 : 0 : ret = flow_hw_create_ctrl_flow(dev, proxy_dev,
16126 : : proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_root_tbl,
16127 : : items, 0, actions, 0, &flow_info, external);
16128 [ # # ]: 0 : if (ret) {
16129 : 0 : DRV_LOG(ERR, "Port %u failed to create root SQ miss flow rule for SQ %u, ret %d",
16130 : : port_id, sqn, ret);
16131 : 0 : return ret;
16132 : : }
16133 : : /*
16134 : : * Create a non-root SQ miss flow rule - match REG_C_0 marker and SQ,
16135 : : * and forward to port.
16136 : : */
16137 : 0 : items[0] = (struct rte_flow_item){
16138 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
16139 : : .spec = ®_c0_spec,
16140 : : .mask = ®_c0_mask,
16141 : : };
16142 : 0 : items[1] = (struct rte_flow_item){
16143 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16144 : : .spec = &sq_spec,
16145 : : };
16146 : 0 : items[2] = (struct rte_flow_item){
16147 : : .type = RTE_FLOW_ITEM_TYPE_END,
16148 : : };
16149 : 0 : actions[0] = (struct rte_flow_action){
16150 : : .type = RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
16151 : : .conf = &port,
16152 : : };
16153 : 0 : actions[1] = (struct rte_flow_action){
16154 : : .type = RTE_FLOW_ACTION_TYPE_END,
16155 : : };
16156 : 0 : flow_info.type = MLX5_CTRL_FLOW_TYPE_SQ_MISS;
16157 : 0 : ret = flow_hw_create_ctrl_flow(dev, proxy_dev,
16158 : 0 : proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_tbl,
16159 : : items, 0, actions, 0, &flow_info, external);
16160 [ # # ]: 0 : if (ret) {
16161 : 0 : DRV_LOG(ERR, "Port %u failed to create HWS SQ miss flow rule for SQ %u, ret %d",
16162 : : port_id, sqn, ret);
16163 : 0 : return ret;
16164 : : }
16165 : : return 0;
16166 : : }
16167 : :
16168 : : static bool
16169 : : flow_hw_is_matching_sq_miss_flow(struct mlx5_ctrl_flow_entry *cf,
16170 : : struct rte_eth_dev *dev,
16171 : : uint32_t sqn)
16172 : : {
16173 : 0 : if (cf->owner_dev != dev)
16174 : : return false;
16175 [ # # # # ]: 0 : if (cf->info.type == MLX5_CTRL_FLOW_TYPE_SQ_MISS_ROOT && cf->info.esw_mgr_sq == sqn)
16176 : : return true;
16177 [ # # # # ]: 0 : if (cf->info.type == MLX5_CTRL_FLOW_TYPE_SQ_MISS && cf->info.esw_mgr_sq == sqn)
16178 : : return true;
16179 : : return false;
16180 : : }
16181 : :
16182 : : int
16183 : 0 : mlx5_flow_hw_esw_destroy_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16184 : : {
16185 : 0 : uint16_t port_id = dev->data->port_id;
16186 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16187 : : struct rte_eth_dev *proxy_dev;
16188 : : struct mlx5_priv *proxy_priv;
16189 : : struct mlx5_ctrl_flow_entry *cf;
16190 : : struct mlx5_ctrl_flow_entry *cf_next;
16191 : : int ret;
16192 : :
16193 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16194 [ # # ]: 0 : if (ret) {
16195 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16196 : : "port must be present for default SQ miss flow rules to exist.",
16197 : : port_id);
16198 : 0 : return ret;
16199 : : }
16200 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16201 : 0 : proxy_priv = proxy_dev->data->dev_private;
16202 : : /* FDB default flow rules must be enabled. */
16203 : : MLX5_ASSERT(proxy_priv->sh->config.fdb_def_rule);
16204 [ # # ]: 0 : if (!proxy_priv->dr_ctx)
16205 : : return 0;
16206 [ # # ]: 0 : if (!proxy_priv->hw_ctrl_fdb ||
16207 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_root_tbl ||
16208 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_tbl)
16209 : : return 0;
16210 [ # # ]: 0 : cf = external ? LIST_FIRST(&proxy_priv->hw_ext_ctrl_flows) :
16211 : : LIST_FIRST(&proxy_priv->hw_ctrl_flows);
16212 [ # # ]: 0 : while (cf != NULL) {
16213 [ # # ]: 0 : cf_next = LIST_NEXT(cf, next);
16214 : : if (flow_hw_is_matching_sq_miss_flow(cf, dev, sqn)) {
16215 : 0 : claim_zero(flow_hw_destroy_ctrl_flow(proxy_dev, cf->flow));
16216 [ # # ]: 0 : LIST_REMOVE(cf, next);
16217 : 0 : mlx5_free(cf);
16218 : : }
16219 : : cf = cf_next;
16220 : : }
16221 : : return 0;
16222 : : }
16223 : :
16224 : : int
16225 : 0 : mlx5_flow_hw_esw_create_default_jump_flow(struct rte_eth_dev *dev)
16226 : : {
16227 : 0 : uint16_t port_id = dev->data->port_id;
16228 : 0 : struct rte_flow_item_ethdev port_spec = {
16229 : : .port_id = port_id,
16230 : : };
16231 : 0 : struct rte_flow_item items[] = {
16232 : : {
16233 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
16234 : : .spec = &port_spec,
16235 : : },
16236 : : {
16237 : : .type = RTE_FLOW_ITEM_TYPE_END,
16238 : : },
16239 : : };
16240 : 0 : struct rte_flow_action_jump jump = {
16241 : : .group = 1,
16242 : : };
16243 : 0 : struct rte_flow_action actions[] = {
16244 : : {
16245 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
16246 : : .conf = &jump,
16247 : : },
16248 : : {
16249 : : .type = RTE_FLOW_ACTION_TYPE_END,
16250 : : }
16251 : : };
16252 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16253 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_JUMP,
16254 : : };
16255 : : struct rte_eth_dev *proxy_dev;
16256 : : struct mlx5_priv *proxy_priv;
16257 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16258 : : int ret;
16259 : :
16260 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16261 [ # # ]: 0 : if (ret) {
16262 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16263 : : "port must be present to create default FDB jump rule.",
16264 : : port_id);
16265 : 0 : return ret;
16266 : : }
16267 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16268 : 0 : proxy_priv = proxy_dev->data->dev_private;
16269 : : /* FDB default flow rules must be enabled. */
16270 : : MLX5_ASSERT(proxy_priv->sh->config.fdb_def_rule);
16271 [ # # ]: 0 : if (!proxy_priv->dr_ctx) {
16272 : 0 : DRV_LOG(DEBUG, "Transfer proxy port (port %u) of port %u must be configured "
16273 : : "for HWS to create default FDB jump rule. Default rule will "
16274 : : "not be created.",
16275 : : proxy_port_id, port_id);
16276 : 0 : return 0;
16277 : : }
16278 [ # # # # ]: 0 : if (!proxy_priv->hw_ctrl_fdb || !proxy_priv->hw_ctrl_fdb->hw_esw_zero_tbl) {
16279 : 0 : DRV_LOG(ERR, "Transfer proxy port (port %u) of port %u was configured, but "
16280 : : "default flow tables were not created.",
16281 : : proxy_port_id, port_id);
16282 : 0 : rte_errno = EINVAL;
16283 : 0 : return -rte_errno;
16284 : : }
16285 : 0 : return flow_hw_create_ctrl_flow(dev, proxy_dev,
16286 : : proxy_priv->hw_ctrl_fdb->hw_esw_zero_tbl,
16287 : : items, 0, actions, 0, &flow_info, false);
16288 : : }
16289 : :
16290 : : int
16291 : 0 : mlx5_flow_hw_create_nic_tx_default_mreg_copy_flow(struct rte_eth_dev *dev, uint32_t sqn)
16292 : : {
16293 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16294 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
16295 : : .queue = sqn,
16296 : : };
16297 : 0 : struct rte_flow_item items[] = {
16298 : : {
16299 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16300 : : .spec = &sq_spec,
16301 : : },
16302 : : {
16303 : : .type = RTE_FLOW_ITEM_TYPE_END,
16304 : : },
16305 : : };
16306 : 0 : struct rte_flow_action_modify_field mreg_action = {
16307 : : .operation = RTE_FLOW_MODIFY_SET,
16308 : : .dst = {
16309 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
16310 : : .tag_index = REG_C_1,
16311 : : },
16312 : : .src = {
16313 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
16314 : : .tag_index = REG_A,
16315 : : },
16316 : : .width = 32,
16317 : : };
16318 : 0 : struct rte_flow_action copy_reg_action[] = {
16319 : : [0] = {
16320 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
16321 : : .conf = &mreg_action,
16322 : : },
16323 : : [1] = {
16324 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
16325 : : },
16326 : : [2] = {
16327 : : .type = RTE_FLOW_ACTION_TYPE_END,
16328 : : },
16329 : : };
16330 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16331 : : .type = MLX5_CTRL_FLOW_TYPE_TX_META_COPY,
16332 : : .tx_repr_sq = sqn,
16333 : : };
16334 : :
16335 : 0 : return flow_hw_create_ctrl_flow(dev, dev,
16336 : 0 : priv->hw_ctrl_nic->hw_tx_meta_cpy_tbl,
16337 : : items, 0, copy_reg_action, 0, &flow_info, false);
16338 : : }
16339 : :
16340 : : int
16341 : 0 : mlx5_flow_hw_create_tx_repr_matching_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16342 : : {
16343 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16344 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
16345 : : .queue = sqn,
16346 : : };
16347 : 0 : struct rte_flow_item items[] = {
16348 : : {
16349 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16350 : : .spec = &sq_spec,
16351 : : },
16352 : : {
16353 : : .type = RTE_FLOW_ITEM_TYPE_END,
16354 : : },
16355 : : };
16356 : : /*
16357 : : * Allocate actions array suitable for all cases - extended metadata enabled or not.
16358 : : * With extended metadata there will be an additional MODIFY_FIELD action before JUMP.
16359 : : */
16360 : 0 : struct rte_flow_action actions[] = {
16361 : : { .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD },
16362 : : { .type = RTE_FLOW_ACTION_TYPE_JUMP },
16363 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16364 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16365 : : };
16366 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16367 : : .type = MLX5_CTRL_FLOW_TYPE_TX_REPR_MATCH,
16368 : : .tx_repr_sq = sqn,
16369 : : };
16370 : :
16371 [ # # ]: 0 : if (!priv->dr_ctx) {
16372 : 0 : DRV_LOG(DEBUG, "Port %u must be configured for HWS, before creating "
16373 : : "default egress flow rules. Omitting creation.",
16374 : : dev->data->port_id);
16375 : 0 : return 0;
16376 : : }
16377 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_tbl) {
16378 : 0 : DRV_LOG(ERR, "Port %u is configured for HWS, but table for default "
16379 : : "egress flow rules does not exist.",
16380 : : dev->data->port_id);
16381 : 0 : rte_errno = EINVAL;
16382 : 0 : return -rte_errno;
16383 : : }
16384 : : /*
16385 : : * If extended metadata mode is enabled, then an additional MODIFY_FIELD action must be
16386 : : * placed before terminating JUMP action.
16387 : : */
16388 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
16389 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD;
16390 : 0 : actions[2].type = RTE_FLOW_ACTION_TYPE_JUMP;
16391 : : }
16392 : 0 : return flow_hw_create_ctrl_flow(dev, dev, priv->hw_tx_repr_tagging_tbl,
16393 : : items, 0, actions, 0, &flow_info, external);
16394 : : }
16395 : :
16396 : : static bool
16397 : : flow_hw_is_tx_matching_repr_matching_flow(struct mlx5_ctrl_flow_entry *cf,
16398 : : struct rte_eth_dev *dev,
16399 : : uint32_t sqn)
16400 : : {
16401 : 0 : if (cf->owner_dev != dev)
16402 : : return false;
16403 [ # # # # ]: 0 : if (cf->info.type == MLX5_CTRL_FLOW_TYPE_TX_REPR_MATCH && cf->info.tx_repr_sq == sqn)
16404 : : return true;
16405 : : return false;
16406 : : }
16407 : :
16408 : : int
16409 : 0 : mlx5_flow_hw_destroy_tx_repr_matching_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16410 : : {
16411 : 0 : uint16_t port_id = dev->data->port_id;
16412 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16413 : : struct rte_eth_dev *proxy_dev;
16414 : : struct mlx5_priv *proxy_priv;
16415 : : struct mlx5_ctrl_flow_entry *cf;
16416 : : struct mlx5_ctrl_flow_entry *cf_next;
16417 : : int ret;
16418 : :
16419 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16420 [ # # ]: 0 : if (ret) {
16421 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16422 : : "port must be present for default SQ miss flow rules to exist.",
16423 : : port_id);
16424 : 0 : return ret;
16425 : : }
16426 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16427 : 0 : proxy_priv = proxy_dev->data->dev_private;
16428 [ # # ]: 0 : if (!proxy_priv->dr_ctx ||
16429 [ # # ]: 0 : !proxy_priv->hw_tx_repr_tagging_tbl)
16430 : : return 0;
16431 [ # # ]: 0 : cf = external ? LIST_FIRST(&proxy_priv->hw_ext_ctrl_flows) :
16432 : : LIST_FIRST(&proxy_priv->hw_ctrl_flows);
16433 [ # # ]: 0 : while (cf != NULL) {
16434 [ # # ]: 0 : cf_next = LIST_NEXT(cf, next);
16435 : : if (flow_hw_is_tx_matching_repr_matching_flow(cf, dev, sqn)) {
16436 : 0 : claim_zero(flow_hw_destroy_ctrl_flow(proxy_dev, cf->flow));
16437 [ # # ]: 0 : LIST_REMOVE(cf, next);
16438 : 0 : mlx5_free(cf);
16439 : : }
16440 : : cf = cf_next;
16441 : : }
16442 : : return 0;
16443 : : }
16444 : :
16445 : : int
16446 : 0 : mlx5_flow_hw_lacp_rx_flow(struct rte_eth_dev *dev)
16447 : : {
16448 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16449 : 0 : struct rte_flow_item_eth lacp_item = {
16450 : : .type = RTE_BE16(RTE_ETHER_TYPE_SLOW),
16451 : : };
16452 : 0 : struct rte_flow_item eth_lacp[] = {
16453 : : [0] = {
16454 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16455 : : .spec = &lacp_item,
16456 : : .mask = &lacp_item,
16457 : : },
16458 : : [1] = {
16459 : : .type = RTE_FLOW_ITEM_TYPE_END,
16460 : : },
16461 : : };
16462 : 0 : struct rte_flow_action miss_action[] = {
16463 : : [0] = {
16464 : : .type = (enum rte_flow_action_type)
16465 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
16466 : : },
16467 : : [1] = {
16468 : : .type = RTE_FLOW_ACTION_TYPE_END,
16469 : : },
16470 : : };
16471 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16472 : : .type = MLX5_CTRL_FLOW_TYPE_LACP_RX,
16473 : : };
16474 : :
16475 [ # # # # : 0 : if (!priv->dr_ctx || !priv->hw_lacp_miss || !priv->hw_lacp_miss->hw_lacp_rx_tbl)
# # ]
16476 : : return 0;
16477 : 0 : return flow_hw_create_ctrl_flow(dev, dev,
16478 : : priv->hw_lacp_miss->hw_lacp_rx_tbl,
16479 : : eth_lacp, 0, miss_action, 0, &flow_info, false);
16480 : : }
16481 : :
16482 : : static uint32_t
16483 : : __calc_pattern_flags(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
16484 : : {
16485 : : switch (eth_pattern_type) {
16486 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
16487 : : return MLX5_CTRL_PROMISCUOUS;
16488 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
16489 : : return MLX5_CTRL_ALL_MULTICAST;
16490 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
16491 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16492 : : return MLX5_CTRL_BROADCAST;
16493 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
16494 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16495 : : return MLX5_CTRL_IPV4_MULTICAST;
16496 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
16497 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16498 : : return MLX5_CTRL_IPV6_MULTICAST;
16499 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
16500 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
16501 : : return MLX5_CTRL_DMAC;
16502 : : default:
16503 : : /* Should not reach here. */
16504 : : MLX5_ASSERT(false);
16505 : : return 0;
16506 : : }
16507 : : }
16508 : :
16509 : : static uint32_t
16510 : : __calc_vlan_flags(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
16511 : : {
16512 [ # # ]: 0 : switch (eth_pattern_type) {
16513 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16514 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16515 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16516 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
16517 : : return MLX5_CTRL_VLAN_FILTER;
16518 : 0 : default:
16519 : 0 : return 0;
16520 : : }
16521 : : }
16522 : :
16523 : : static bool
16524 [ # # ]: 0 : eth_pattern_type_is_requested(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
16525 : : uint32_t flags)
16526 : : {
16527 : : uint32_t pattern_flags = __calc_pattern_flags(eth_pattern_type);
16528 : : uint32_t vlan_flags = __calc_vlan_flags(eth_pattern_type);
16529 : 0 : bool pattern_requested = !!(pattern_flags & flags);
16530 [ # # # # ]: 0 : bool consider_vlan = vlan_flags || (MLX5_CTRL_VLAN_FILTER & flags);
16531 : 0 : bool vlan_requested = !!(vlan_flags & flags);
16532 : :
16533 [ # # ]: 0 : if (consider_vlan)
16534 : 0 : return pattern_requested && vlan_requested;
16535 : : else
16536 : : return pattern_requested;
16537 : : }
16538 : :
16539 : : static bool
16540 : : rss_type_is_requested(struct mlx5_priv *priv,
16541 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16542 : : {
16543 : 0 : struct rte_flow_actions_template *at = priv->hw_ctrl_rx->rss[rss_type];
16544 : : unsigned int i;
16545 : :
16546 [ # # # # ]: 0 : for (i = 0; at->actions[i].type != RTE_FLOW_ACTION_TYPE_END; ++i) {
16547 [ # # # # ]: 0 : if (at->actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
16548 : 0 : const struct rte_flow_action_rss *rss = at->actions[i].conf;
16549 : 0 : uint64_t rss_types = rss->types;
16550 : :
16551 [ # # # # ]: 0 : if ((rss_types & priv->rss_conf.rss_hf) != rss_types)
16552 : : return false;
16553 : : }
16554 : : }
16555 : : return true;
16556 : : }
16557 : :
16558 : : static const struct rte_flow_item_eth *
16559 : : __get_eth_spec(const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern)
16560 : : {
16561 : 0 : switch (pattern) {
16562 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
16563 : : return &ctrl_rx_eth_promisc_spec;
16564 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
16565 : 0 : return &ctrl_rx_eth_mcast_spec;
16566 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
16567 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16568 : 0 : return &ctrl_rx_eth_bcast_spec;
16569 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
16570 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16571 : 0 : return &ctrl_rx_eth_ipv4_mcast_spec;
16572 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
16573 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16574 : 0 : return &ctrl_rx_eth_ipv6_mcast_spec;
16575 : 0 : default:
16576 : : /* This case should not be reached. */
16577 : : MLX5_ASSERT(false);
16578 : 0 : return NULL;
16579 : : }
16580 : : }
16581 : :
16582 : : static int
16583 [ # # # # : 0 : __flow_hw_ctrl_flows_single(struct rte_eth_dev *dev,
# # ]
16584 : : struct rte_flow_template_table *tbl,
16585 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
16586 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16587 : : {
16588 : : const struct rte_flow_item_eth *eth_spec = __get_eth_spec(pattern_type);
16589 : : struct rte_flow_item items[5];
16590 : 0 : struct rte_flow_action actions[] = {
16591 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16592 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16593 : : };
16594 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16595 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
16596 : : };
16597 : :
16598 [ # # ]: 0 : if (!eth_spec)
16599 : : return -EINVAL;
16600 : : memset(items, 0, sizeof(items));
16601 : 0 : items[0] = (struct rte_flow_item){
16602 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16603 : : .spec = eth_spec,
16604 : : };
16605 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VOID };
16606 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16607 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16608 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16609 : : /* Without VLAN filtering, only a single flow rule must be created. */
16610 : 0 : return flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0, &flow_info, false);
16611 : : }
16612 : :
16613 : : static int
16614 : 0 : __flow_hw_ctrl_flows_single_vlan(struct rte_eth_dev *dev,
16615 : : struct rte_flow_template_table *tbl,
16616 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
16617 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16618 : : {
16619 [ # # # # : 0 : struct mlx5_priv *priv = dev->data->dev_private;
# # ]
16620 : : const struct rte_flow_item_eth *eth_spec = __get_eth_spec(pattern_type);
16621 : : struct rte_flow_item items[5];
16622 : 0 : struct rte_flow_action actions[] = {
16623 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16624 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16625 : : };
16626 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16627 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
16628 : : };
16629 : : unsigned int i;
16630 : :
16631 [ # # ]: 0 : if (!eth_spec)
16632 : : return -EINVAL;
16633 : : memset(items, 0, sizeof(items));
16634 : 0 : items[0] = (struct rte_flow_item){
16635 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16636 : : .spec = eth_spec,
16637 : : };
16638 : : /* Optional VLAN for now will be VOID - will be filled later. */
16639 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VLAN };
16640 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16641 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16642 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16643 : : /* Since VLAN filtering is done, create a single flow rule for each registered vid. */
16644 [ # # ]: 0 : for (i = 0; i < priv->vlan_filter_n; ++i) {
16645 : 0 : uint16_t vlan = priv->vlan_filter[i];
16646 : 0 : struct rte_flow_item_vlan vlan_spec = {
16647 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
16648 : : };
16649 : :
16650 : 0 : items[1].spec = &vlan_spec;
16651 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev,
16652 : : tbl, items, 0, actions, 0, &flow_info, false))
16653 : 0 : return -rte_errno;
16654 : : }
16655 : : return 0;
16656 : : }
16657 : :
16658 : : static int
16659 : 0 : __flow_hw_ctrl_flows_unicast_create(struct rte_eth_dev *dev,
16660 : : struct rte_flow_template_table *tbl,
16661 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type,
16662 : : const struct rte_ether_addr *addr)
16663 : : {
16664 : 0 : struct rte_flow_item_eth eth_spec = {
16665 : : .hdr.dst_addr = *addr,
16666 : : };
16667 : : struct rte_flow_item items[5];
16668 : 0 : struct rte_flow_action actions[] = {
16669 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16670 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16671 : : };
16672 [ # # # ]: 0 : struct mlx5_ctrl_flow_info flow_info = {
16673 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
16674 : : .uc = {
16675 : : .dmac = *addr,
16676 : : },
16677 : : };
16678 : :
16679 : : memset(items, 0, sizeof(items));
16680 : 0 : items[0] = (struct rte_flow_item){
16681 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16682 : : .spec = ð_spec,
16683 : : };
16684 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VOID };
16685 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16686 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16687 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16688 : :
16689 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0, &flow_info, false))
16690 : 0 : return -rte_errno;
16691 : :
16692 : : return 0;
16693 : : }
16694 : :
16695 : : static int
16696 : 0 : __flow_hw_ctrl_flows_unicast(struct rte_eth_dev *dev,
16697 : : struct rte_flow_template_table *tbl,
16698 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16699 : : {
16700 : : unsigned int i;
16701 : : int ret;
16702 : :
16703 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_MAC_ADDRESSES; ++i) {
16704 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
16705 : :
16706 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
16707 : 0 : continue;
16708 : :
16709 : 0 : ret = __flow_hw_ctrl_flows_unicast_create(dev, tbl, rss_type, mac);
16710 [ # # ]: 0 : if (ret < 0)
16711 : 0 : return ret;
16712 : : }
16713 : : return 0;
16714 : : }
16715 : :
16716 : : static int
16717 : 0 : __flow_hw_ctrl_flows_unicast_vlan_create(struct rte_eth_dev *dev,
16718 : : struct rte_flow_template_table *tbl,
16719 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type,
16720 : : const struct rte_ether_addr *addr,
16721 : : const uint16_t vid)
16722 : : {
16723 : 0 : struct rte_flow_item_eth eth_spec = {
16724 : : .hdr.dst_addr = *addr,
16725 : : };
16726 : 0 : struct rte_flow_item_vlan vlan_spec = {
16727 [ # # ]: 0 : .tci = rte_cpu_to_be_16(vid),
16728 : : };
16729 : : struct rte_flow_item items[5];
16730 : 0 : struct rte_flow_action actions[] = {
16731 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16732 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16733 : : };
16734 [ # # # ]: 0 : struct mlx5_ctrl_flow_info flow_info = {
16735 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
16736 : : .uc = {
16737 : : .dmac = *addr,
16738 : : .vlan = vid,
16739 : : },
16740 : : };
16741 : :
16742 : : memset(items, 0, sizeof(items));
16743 : 0 : items[0] = (struct rte_flow_item){
16744 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16745 : : .spec = ð_spec,
16746 : : };
16747 [ # # # ]: 0 : items[1] = (struct rte_flow_item){
16748 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
16749 : : .spec = &vlan_spec,
16750 : : };
16751 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16752 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16753 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16754 : :
16755 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0, &flow_info, false))
16756 : 0 : return -rte_errno;
16757 : :
16758 : : return 0;
16759 : : }
16760 : :
16761 : : static int
16762 : 0 : __flow_hw_ctrl_flows_unicast_vlan(struct rte_eth_dev *dev,
16763 : : struct rte_flow_template_table *tbl,
16764 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16765 : : {
16766 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16767 : : unsigned int i;
16768 : : unsigned int j;
16769 : :
16770 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_MAC_ADDRESSES; ++i) {
16771 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
16772 : :
16773 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
16774 : 0 : continue;
16775 : :
16776 [ # # ]: 0 : for (j = 0; j < priv->vlan_filter_n; ++j) {
16777 : 0 : uint16_t vlan = priv->vlan_filter[j];
16778 : : int ret;
16779 : :
16780 : 0 : ret = __flow_hw_ctrl_flows_unicast_vlan_create(dev, tbl, rss_type,
16781 : : mac, vlan);
16782 [ # # ]: 0 : if (ret < 0)
16783 : 0 : return ret;
16784 : : }
16785 : : }
16786 : : return 0;
16787 : : }
16788 : :
16789 : : static int
16790 : 0 : __flow_hw_ctrl_flows(struct rte_eth_dev *dev,
16791 : : struct rte_flow_template_table *tbl,
16792 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
16793 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16794 : : {
16795 [ # # # # : 0 : switch (pattern_type) {
# ]
16796 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
16797 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
16798 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
16799 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
16800 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
16801 : 0 : return __flow_hw_ctrl_flows_single(dev, tbl, pattern_type, rss_type);
16802 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16803 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16804 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16805 : 0 : return __flow_hw_ctrl_flows_single_vlan(dev, tbl, pattern_type, rss_type);
16806 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
16807 : 0 : return __flow_hw_ctrl_flows_unicast(dev, tbl, rss_type);
16808 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
16809 : 0 : return __flow_hw_ctrl_flows_unicast_vlan(dev, tbl, rss_type);
16810 : 0 : default:
16811 : : /* Should not reach here. */
16812 : : MLX5_ASSERT(false);
16813 : 0 : rte_errno = EINVAL;
16814 : 0 : return -EINVAL;
16815 : : }
16816 : : }
16817 : :
16818 : :
16819 : : int
16820 : 0 : mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags)
16821 : : {
16822 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16823 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
16824 : : unsigned int i;
16825 : : int j;
16826 : : int ret = 0;
16827 : :
16828 : : RTE_SET_USED(priv);
16829 : : RTE_SET_USED(flags);
16830 [ # # ]: 0 : if (!priv->dr_ctx) {
16831 : 0 : DRV_LOG(DEBUG, "port %u Control flow rules will not be created. "
16832 : : "HWS needs to be configured beforehand.",
16833 : : dev->data->port_id);
16834 : 0 : return 0;
16835 : : }
16836 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
16837 : 0 : DRV_LOG(ERR, "port %u Control flow rules templates were not created.",
16838 : : dev->data->port_id);
16839 : 0 : rte_errno = EINVAL;
16840 : 0 : return -rte_errno;
16841 : : }
16842 : : hw_ctrl_rx = priv->hw_ctrl_rx;
16843 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
16844 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type = i;
16845 : :
16846 [ # # ]: 0 : if (!eth_pattern_type_is_requested(eth_pattern_type, flags))
16847 : 0 : continue;
16848 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
16849 : 0 : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
16850 : : struct rte_flow_actions_template *at;
16851 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[i][j];
16852 : 0 : const struct mlx5_flow_template_table_cfg cfg = {
16853 : : .attr = tmpls->attr,
16854 : : .external = 0,
16855 : : };
16856 : :
16857 [ # # ]: 0 : if (!hw_ctrl_rx->rss[rss_type]) {
16858 : 0 : at = flow_hw_create_ctrl_rx_rss_template(dev, rss_type);
16859 [ # # ]: 0 : if (!at)
16860 : 0 : return -rte_errno;
16861 : 0 : hw_ctrl_rx->rss[rss_type] = at;
16862 : : } else {
16863 : 0 : at = hw_ctrl_rx->rss[rss_type];
16864 : : }
16865 [ # # ]: 0 : if (!rss_type_is_requested(priv, rss_type))
16866 : 0 : continue;
16867 [ # # ]: 0 : if (!tmpls->tbl) {
16868 : 0 : tmpls->tbl = flow_hw_table_create(dev, &cfg,
16869 : : &tmpls->pt, 1, &at, 1, NULL);
16870 [ # # ]: 0 : if (!tmpls->tbl) {
16871 : 0 : DRV_LOG(ERR, "port %u Failed to create template table "
16872 : : "for control flow rules. Unable to create "
16873 : : "control flow rules.",
16874 : : dev->data->port_id);
16875 : 0 : return -rte_errno;
16876 : : }
16877 : : }
16878 : :
16879 : 0 : ret = __flow_hw_ctrl_flows(dev, tmpls->tbl, eth_pattern_type, rss_type);
16880 [ # # ]: 0 : if (ret) {
16881 : 0 : DRV_LOG(ERR, "port %u Failed to create control flow rule.",
16882 : : dev->data->port_id);
16883 : 0 : return ret;
16884 : : }
16885 : : }
16886 : : }
16887 : : return 0;
16888 : : }
16889 : :
16890 : : static int
16891 : 0 : mlx5_flow_hw_ctrl_flow_single(struct rte_eth_dev *dev,
16892 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
16893 : : const struct rte_ether_addr *addr,
16894 : : const uint16_t vlan)
16895 : : {
16896 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16897 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
16898 : : unsigned int j;
16899 : : int ret = 0;
16900 : :
16901 [ # # ]: 0 : if (!priv->dr_ctx) {
16902 : 0 : DRV_LOG(DEBUG, "port %u Control flow rules will not be created. "
16903 : : "HWS needs to be configured beforehand.",
16904 : : dev->data->port_id);
16905 : 0 : return 0;
16906 : : }
16907 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
16908 : 0 : DRV_LOG(ERR, "port %u Control flow rules templates were not created.",
16909 : : dev->data->port_id);
16910 : 0 : rte_errno = EINVAL;
16911 : 0 : return -rte_errno;
16912 : : }
16913 : : hw_ctrl_rx = priv->hw_ctrl_rx;
16914 : :
16915 : : /* TODO: this part should be somehow refactored. It's common with common flow creation. */
16916 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
16917 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
16918 : : const unsigned int pti = eth_pattern_type;
16919 : : struct rte_flow_actions_template *at;
16920 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[pti][j];
16921 : 0 : const struct mlx5_flow_template_table_cfg cfg = {
16922 : : .attr = tmpls->attr,
16923 : : .external = 0,
16924 : : };
16925 : :
16926 [ # # ]: 0 : if (!hw_ctrl_rx->rss[rss_type]) {
16927 : 0 : at = flow_hw_create_ctrl_rx_rss_template(dev, rss_type);
16928 [ # # ]: 0 : if (!at)
16929 : 0 : return -rte_errno;
16930 : 0 : hw_ctrl_rx->rss[rss_type] = at;
16931 : : } else {
16932 : 0 : at = hw_ctrl_rx->rss[rss_type];
16933 : : }
16934 [ # # ]: 0 : if (!rss_type_is_requested(priv, rss_type))
16935 : 0 : continue;
16936 [ # # ]: 0 : if (!tmpls->tbl) {
16937 : 0 : tmpls->tbl = flow_hw_table_create(dev, &cfg,
16938 : : &tmpls->pt, 1, &at, 1, NULL);
16939 [ # # ]: 0 : if (!tmpls->tbl) {
16940 : 0 : DRV_LOG(ERR, "port %u Failed to create template table "
16941 : : "for control flow rules. Unable to create "
16942 : : "control flow rules.",
16943 : : dev->data->port_id);
16944 : 0 : return -rte_errno;
16945 : : }
16946 : : }
16947 : :
16948 : : MLX5_ASSERT(eth_pattern_type == MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC ||
16949 : : eth_pattern_type == MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN);
16950 : :
16951 [ # # ]: 0 : if (eth_pattern_type == MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC)
16952 : 0 : ret = __flow_hw_ctrl_flows_unicast_create(dev, tmpls->tbl, rss_type, addr);
16953 : : else
16954 : 0 : ret = __flow_hw_ctrl_flows_unicast_vlan_create(dev, tmpls->tbl, rss_type,
16955 : : addr, vlan);
16956 [ # # ]: 0 : if (ret) {
16957 : 0 : DRV_LOG(ERR, "port %u Failed to create unicast control flow rule.",
16958 : : dev->data->port_id);
16959 : 0 : return ret;
16960 : : }
16961 : : }
16962 : :
16963 : : return 0;
16964 : : }
16965 : :
16966 : : int
16967 : 0 : mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev,
16968 : : const struct rte_ether_addr *addr)
16969 : : {
16970 : 0 : return mlx5_flow_hw_ctrl_flow_single(dev, MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC,
16971 : : addr, 0);
16972 : : }
16973 : :
16974 : :
16975 : : int
16976 : 0 : mlx5_flow_hw_ctrl_flow_dmac_destroy(struct rte_eth_dev *dev,
16977 : : const struct rte_ether_addr *addr)
16978 : : {
16979 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16980 : : struct mlx5_ctrl_flow_entry *entry;
16981 : : struct mlx5_ctrl_flow_entry *tmp;
16982 : : int ret;
16983 : :
16984 : : /*
16985 : : * HWS does not have automatic RSS flow expansion,
16986 : : * so each variant of the control flow rule is a separate entry in the list.
16987 : : * In that case, the whole list must be traversed.
16988 : : */
16989 : 0 : entry = LIST_FIRST(&priv->hw_ctrl_flows);
16990 [ # # ]: 0 : while (entry != NULL) {
16991 : 0 : tmp = LIST_NEXT(entry, next);
16992 : :
16993 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
16994 : : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
16995 : : entry = tmp;
16996 : 0 : continue;
16997 : : }
16998 : :
16999 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, entry->flow);
17000 [ # # ]: 0 : LIST_REMOVE(entry, next);
17001 : 0 : mlx5_free(entry);
17002 [ # # ]: 0 : if (ret)
17003 : 0 : return ret;
17004 : :
17005 : : entry = tmp;
17006 : : }
17007 : : return 0;
17008 : : }
17009 : :
17010 : : int
17011 : 0 : mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev,
17012 : : const struct rte_ether_addr *addr,
17013 : : const uint16_t vlan)
17014 : : {
17015 : 0 : return mlx5_flow_hw_ctrl_flow_single(dev, MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN,
17016 : : addr, vlan);
17017 : : }
17018 : :
17019 : : int
17020 : 0 : mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(struct rte_eth_dev *dev,
17021 : : const struct rte_ether_addr *addr,
17022 : : const uint16_t vlan)
17023 : : {
17024 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17025 : : struct mlx5_ctrl_flow_entry *entry;
17026 : : struct mlx5_ctrl_flow_entry *tmp;
17027 : : int ret;
17028 : :
17029 : : /*
17030 : : * HWS does not have automatic RSS flow expansion,
17031 : : * so each variant of the control flow rule is a separate entry in the list.
17032 : : * In that case, the whole list must be traversed.
17033 : : */
17034 : 0 : entry = LIST_FIRST(&priv->hw_ctrl_flows);
17035 [ # # ]: 0 : while (entry != NULL) {
17036 : 0 : tmp = LIST_NEXT(entry, next);
17037 : :
17038 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
17039 : 0 : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
17040 [ # # ]: 0 : vlan != entry->info.uc.vlan) {
17041 : : entry = tmp;
17042 : 0 : continue;
17043 : : }
17044 : :
17045 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, entry->flow);
17046 [ # # ]: 0 : LIST_REMOVE(entry, next);
17047 : 0 : mlx5_free(entry);
17048 [ # # ]: 0 : if (ret)
17049 : 0 : return ret;
17050 : :
17051 : : entry = tmp;
17052 : : }
17053 : : return 0;
17054 : : }
17055 : :
17056 : : struct mlx5_ecpri_parser_profile *
17057 : 0 : mlx5_flow_hw_get_ecpri_parser_profile(void *dr_ctx)
17058 : : {
17059 : : uint16_t port_id;
17060 : : bool found = false;
17061 : : struct mlx5_priv *priv;
17062 : :
17063 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
17064 : 0 : priv = rte_eth_devices[port_id].data->dev_private;
17065 [ # # ]: 0 : if (priv->dr_ctx == dr_ctx) {
17066 : : found = true;
17067 : : break;
17068 : : }
17069 : : }
17070 [ # # ]: 0 : if (found)
17071 : 0 : return &priv->sh->ecpri_parser;
17072 : 0 : rte_errno = ENODEV;
17073 : 0 : return NULL;
17074 : : }
17075 : :
17076 : :
17077 : : static __rte_always_inline uint32_t
17078 : : mlx5_reformat_domain_to_tbl_type(const struct rte_flow_indir_action_conf *domain,
17079 : : bool fdb_unified_en)
17080 : : {
17081 : : uint32_t tbl_type;
17082 : :
17083 [ # # ]: 0 : if (domain->transfer)
17084 : : tbl_type = (fdb_unified_en ?
17085 : : (MLX5DR_ACTION_FLAG_HWS_FDB_RX |
17086 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
17087 [ # # ]: 0 : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) :
17088 : : MLX5DR_ACTION_FLAG_HWS_FDB);
17089 [ # # ]: 0 : else if (domain->egress)
17090 : : tbl_type = MLX5DR_ACTION_FLAG_HWS_TX;
17091 [ # # ]: 0 : else if (domain->ingress)
17092 : : tbl_type = MLX5DR_ACTION_FLAG_HWS_RX;
17093 : : else
17094 : : tbl_type = UINT32_MAX;
17095 : : return tbl_type;
17096 : : }
17097 : :
17098 : : static struct mlx5_hw_encap_decap_action *
17099 : 0 : __mlx5_reformat_create(struct rte_eth_dev *dev,
17100 : : const struct rte_flow_action_raw_encap *encap_conf,
17101 : : const struct rte_flow_indir_action_conf *domain,
17102 : : enum mlx5dr_action_type type)
17103 : : {
17104 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
17105 : : struct mlx5_hw_encap_decap_action *handle;
17106 : : struct mlx5dr_action_reformat_header hdr;
17107 : : uint32_t flags;
17108 : : bool unified_fdb = is_unified_fdb(priv);
17109 : :
17110 : : flags = mlx5_reformat_domain_to_tbl_type(domain, unified_fdb);
17111 : 0 : flags |= (uint32_t)MLX5DR_ACTION_FLAG_SHARED;
17112 [ # # ]: 0 : if (flags == UINT32_MAX) {
17113 : 0 : DRV_LOG(ERR, "Reformat: invalid indirect action configuration");
17114 : 0 : return NULL;
17115 : : }
17116 : : /* Allocate new list entry. */
17117 : 0 : handle = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*handle), 0, SOCKET_ID_ANY);
17118 [ # # ]: 0 : if (!handle) {
17119 : 0 : DRV_LOG(ERR, "Reformat: failed to allocate reformat entry");
17120 : 0 : return NULL;
17121 : : }
17122 : 0 : handle->action_type = type;
17123 [ # # ]: 0 : hdr.sz = encap_conf ? encap_conf->size : 0;
17124 [ # # ]: 0 : hdr.data = encap_conf ? encap_conf->data : NULL;
17125 : 0 : handle->action = mlx5dr_action_create_reformat(priv->dr_ctx,
17126 : : type, 1, &hdr, 0, flags);
17127 [ # # ]: 0 : if (!handle->action) {
17128 : 0 : DRV_LOG(ERR, "Reformat: failed to create reformat action");
17129 : 0 : mlx5_free(handle);
17130 : 0 : return NULL;
17131 : : }
17132 : : return handle;
17133 : : }
17134 : :
17135 : : /**
17136 : : * Create mlx5 reformat action.
17137 : : *
17138 : : * @param[in] dev
17139 : : * Pointer to rte_eth_dev structure.
17140 : : * @param[in] conf
17141 : : * Pointer to the indirect action parameters.
17142 : : * @param[in] encap_action
17143 : : * Pointer to the raw_encap action configuration.
17144 : : * @param[in] decap_action
17145 : : * Pointer to the raw_decap action configuration.
17146 : : * @param[out] error
17147 : : * Pointer to error structure.
17148 : : *
17149 : : * @return
17150 : : * A valid shared action handle in case of success, NULL otherwise and
17151 : : * rte_errno is set.
17152 : : */
17153 : : struct mlx5_hw_encap_decap_action*
17154 : 0 : mlx5_reformat_action_create(struct rte_eth_dev *dev,
17155 : : const struct rte_flow_indir_action_conf *conf,
17156 : : const struct rte_flow_action *encap_action,
17157 : : const struct rte_flow_action *decap_action,
17158 : : struct rte_flow_error *error)
17159 : : {
17160 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17161 : : struct mlx5_hw_encap_decap_action *handle;
17162 : : const struct rte_flow_action_raw_encap *encap = NULL;
17163 : : const struct rte_flow_action_raw_decap *decap = NULL;
17164 : : enum mlx5dr_action_type type = MLX5DR_ACTION_TYP_LAST;
17165 : :
17166 : : MLX5_ASSERT(!encap_action || encap_action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP);
17167 : : MLX5_ASSERT(!decap_action || decap_action->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP);
17168 [ # # ]: 0 : if (priv->sh->config.dv_flow_en != 2) {
17169 : 0 : rte_flow_error_set(error, ENOTSUP,
17170 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17171 : : "Reformat: hardware does not support");
17172 : 0 : return NULL;
17173 : : }
17174 [ # # # # ]: 0 : if (!conf || (conf->transfer + conf->egress + conf->ingress != 1)) {
17175 : 0 : rte_flow_error_set(error, EINVAL,
17176 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17177 : : "Reformat: domain should be specified");
17178 : 0 : return NULL;
17179 : : }
17180 [ # # # # : 0 : if ((encap_action && !encap_action->conf) || (decap_action && !decap_action->conf)) {
# # # # ]
17181 : 0 : rte_flow_error_set(error, EINVAL,
17182 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17183 : : "Reformat: missed action configuration");
17184 : 0 : return NULL;
17185 : : }
17186 [ # # ]: 0 : if (encap_action && !decap_action) {
17187 : 0 : encap = (const struct rte_flow_action_raw_encap *)encap_action->conf;
17188 [ # # ]: 0 : if (!encap->size || encap->size > MLX5_ENCAP_MAX_LEN ||
17189 : : encap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
17190 : 0 : rte_flow_error_set(error, EINVAL,
17191 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17192 : : "Reformat: Invalid encap length");
17193 : 0 : return NULL;
17194 : : }
17195 : : type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
17196 [ # # ]: 0 : } else if (decap_action && !encap_action) {
17197 : 0 : decap = (const struct rte_flow_action_raw_decap *)decap_action->conf;
17198 [ # # ]: 0 : if (!decap->size || decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
17199 : 0 : rte_flow_error_set(error, EINVAL,
17200 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17201 : : "Reformat: Invalid decap length");
17202 : 0 : return NULL;
17203 : : }
17204 : : type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
17205 [ # # ]: 0 : } else if (encap_action && decap_action) {
17206 : 0 : decap = (const struct rte_flow_action_raw_decap *)decap_action->conf;
17207 : 0 : encap = (const struct rte_flow_action_raw_encap *)encap_action->conf;
17208 [ # # ]: 0 : if (decap->size < MLX5_ENCAPSULATION_DECISION_SIZE &&
17209 [ # # # # ]: 0 : encap->size >= MLX5_ENCAPSULATION_DECISION_SIZE &&
17210 : : encap->size <= MLX5_ENCAP_MAX_LEN) {
17211 : : type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
17212 [ # # ]: 0 : } else if (decap->size >= MLX5_ENCAPSULATION_DECISION_SIZE &&
17213 [ # # ]: 0 : encap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
17214 : : type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2;
17215 : : } else {
17216 : 0 : rte_flow_error_set(error, EINVAL,
17217 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17218 : : "Reformat: Invalid decap & encap length");
17219 : 0 : return NULL;
17220 : : }
17221 [ # # ]: 0 : } else if (!encap_action && !decap_action) {
17222 : 0 : rte_flow_error_set(error, EINVAL,
17223 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17224 : : "Reformat: Invalid decap & encap configurations");
17225 : 0 : return NULL;
17226 : : }
17227 [ # # ]: 0 : if (!priv->dr_ctx) {
17228 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17229 : : encap_action, "Reformat: HWS not supported");
17230 : 0 : return NULL;
17231 : : }
17232 : 0 : handle = __mlx5_reformat_create(dev, encap, conf, type);
17233 [ # # ]: 0 : if (!handle) {
17234 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17235 : : "Reformat: failed to create indirect action");
17236 : 0 : return NULL;
17237 : : }
17238 : : return handle;
17239 : : }
17240 : :
17241 : : /**
17242 : : * Destroy the indirect reformat action.
17243 : : * Release action related resources on the NIC and the memory.
17244 : : * Lock free, (mutex should be acquired by caller).
17245 : : *
17246 : : * @param[in] dev
17247 : : * Pointer to the Ethernet device structure.
17248 : : * @param[in] handle
17249 : : * The indirect action list handle to be removed.
17250 : : * @param[out] error
17251 : : * Perform verbose error reporting if not NULL. Initialized in case of
17252 : : * error only.
17253 : : *
17254 : : * @return
17255 : : * 0 on success, otherwise negative errno value.
17256 : : */
17257 : : int
17258 : 0 : mlx5_reformat_action_destroy(struct rte_eth_dev *dev,
17259 : : struct rte_flow_action_list_handle *handle,
17260 : : struct rte_flow_error *error)
17261 : : {
17262 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17263 : : struct mlx5_hw_encap_decap_action *action;
17264 : :
17265 : : action = (struct mlx5_hw_encap_decap_action *)handle;
17266 [ # # # # ]: 0 : if (!priv->dr_ctx || !action)
17267 : 0 : return rte_flow_error_set(error, ENOTSUP,
17268 : : RTE_FLOW_ERROR_TYPE_ACTION, handle,
17269 : : "Reformat: invalid action handle");
17270 : 0 : mlx5dr_action_destroy(action->action);
17271 : 0 : mlx5_free(handle);
17272 : 0 : return 0;
17273 : : }
17274 : :
17275 : : static bool
17276 : 0 : flow_hw_is_item_masked(const struct rte_flow_item *item)
17277 : : {
17278 : : const uint8_t *byte;
17279 : : int size;
17280 : : int i;
17281 : :
17282 [ # # ]: 0 : if (item->mask == NULL)
17283 : : return false;
17284 : :
17285 [ # # ]: 0 : switch ((int)item->type) {
17286 : : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
17287 : : size = sizeof(struct rte_flow_item_tag);
17288 : : break;
17289 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
17290 : : size = sizeof(struct mlx5_rte_flow_item_sq);
17291 : : break;
17292 : 0 : default:
17293 : 0 : size = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_MASK, NULL, 0, item, NULL);
17294 : : /*
17295 : : * Pattern template items are passed to this function.
17296 : : * These items were already validated, so error is not expected.
17297 : : * Also, if mask is NULL, then spec size is bigger than 0 always.
17298 : : */
17299 : : MLX5_ASSERT(size > 0);
17300 : : }
17301 : :
17302 : 0 : byte = (const uint8_t *)item->mask;
17303 [ # # ]: 0 : for (i = 0; i < size; ++i)
17304 [ # # ]: 0 : if (byte[i])
17305 : : return true;
17306 : :
17307 : : return false;
17308 : : }
17309 : :
17310 : : static int
17311 : 0 : flow_hw_validate_rule_pattern(struct rte_eth_dev *dev,
17312 : : const struct rte_flow_template_table *table,
17313 : : const uint8_t pattern_template_idx,
17314 : : const struct rte_flow_item items[],
17315 : : struct rte_flow_error *error)
17316 : : {
17317 : : const struct rte_flow_pattern_template *pt;
17318 : : const struct rte_flow_item *pt_item;
17319 : :
17320 [ # # ]: 0 : if (pattern_template_idx >= table->nb_item_templates)
17321 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17322 : : "Pattern template index out of range");
17323 : :
17324 : 0 : pt = table->its[pattern_template_idx];
17325 : 0 : pt_item = pt->items;
17326 : :
17327 : : /* If any item was prepended, skip it. */
17328 [ # # ]: 0 : if (pt->implicit_port || pt->implicit_tag)
17329 : 0 : pt_item++;
17330 : :
17331 [ # # ]: 0 : for (; pt_item->type != RTE_FLOW_ITEM_TYPE_END; pt_item++, items++) {
17332 [ # # ]: 0 : if (pt_item->type != items->type)
17333 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
17334 : : items, "Item type does not match the template");
17335 : :
17336 : : /*
17337 : : * Assumptions:
17338 : : * - Currently mlx5dr layer contains info on which fields in masks are supported.
17339 : : * - This info is not exposed to PMD directly.
17340 : : * - Because of that, it is assumed that since pattern template is correct,
17341 : : * then, items' masks in pattern template have nonzero values only in
17342 : : * supported fields.
17343 : : * This is known, because a temporary mlx5dr matcher is created during pattern
17344 : : * template creation to validate the template.
17345 : : * - As a result, it is safe to look for nonzero bytes in mask to determine if
17346 : : * item spec is needed in a flow rule.
17347 : : */
17348 [ # # ]: 0 : if (!flow_hw_is_item_masked(pt_item))
17349 : 0 : continue;
17350 : :
17351 [ # # ]: 0 : if (items->spec == NULL)
17352 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
17353 : : items, "Item spec is required");
17354 : :
17355 [ # # # # ]: 0 : switch (items->type) {
17356 : : const struct rte_flow_item_ethdev *ethdev;
17357 : : const struct rte_flow_item_tx_queue *tx_queue;
17358 : : const struct rte_flow_item_conntrack *spec;
17359 : : struct mlx5_txq_ctrl *txq;
17360 : :
17361 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
17362 : : ethdev = items->spec;
17363 [ # # ]: 0 : if (flow_hw_validate_target_port_id(dev, ethdev->port_id)) {
17364 : 0 : return rte_flow_error_set(error, EINVAL,
17365 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, items,
17366 : : "Invalid port");
17367 : : }
17368 : : break;
17369 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
17370 : : tx_queue = items->spec;
17371 [ # # # # ]: 0 : if (mlx5_is_external_txq(dev, tx_queue->tx_queue))
17372 : 0 : continue;
17373 : 0 : txq = mlx5_txq_get(dev, tx_queue->tx_queue);
17374 [ # # ]: 0 : if (!txq)
17375 : 0 : return rte_flow_error_set(error, EINVAL,
17376 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, items,
17377 : : "Invalid Tx queue");
17378 : 0 : mlx5_txq_release(dev, tx_queue->tx_queue);
17379 : 0 : break;
17380 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
17381 : : spec = items->spec;
17382 [ # # ]: 0 : if (spec->flags & ~MLX5_FLOW_CONNTRACK_PKT_STATE_ALL)
17383 : 0 : return rte_flow_error_set(error, EINVAL,
17384 : : RTE_FLOW_ERROR_TYPE_ITEM,
17385 : : NULL,
17386 : : "Invalid CT item flags");
17387 : : break;
17388 : : default:
17389 : : break;
17390 : : }
17391 : : }
17392 : :
17393 : : return 0;
17394 : : }
17395 : :
17396 : : static bool
17397 : 0 : flow_hw_valid_indirect_action_type(const struct rte_flow_action *user_action,
17398 : : const enum rte_flow_action_type expected_type)
17399 : : {
17400 : 0 : uint32_t user_indirect_type = MLX5_INDIRECT_ACTION_TYPE_GET(user_action->conf);
17401 : : uint32_t expected_indirect_type;
17402 : :
17403 [ # # # # : 0 : switch ((int)expected_type) {
# # # ]
17404 : : case RTE_FLOW_ACTION_TYPE_RSS:
17405 : : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
17406 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_RSS;
17407 : : break;
17408 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17409 : : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
17410 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_COUNT;
17411 : 0 : break;
17412 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17413 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_AGE;
17414 : 0 : break;
17415 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17416 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_CT;
17417 : 0 : break;
17418 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
17419 : : case MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK:
17420 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_METER_MARK;
17421 : 0 : break;
17422 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
17423 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_QUOTA;
17424 : 0 : break;
17425 : : default:
17426 : : return false;
17427 : : }
17428 : :
17429 : 0 : return user_indirect_type == expected_indirect_type;
17430 : : }
17431 : :
17432 : : static int
17433 : 0 : flow_hw_validate_rule_actions(struct rte_eth_dev *dev,
17434 : : const struct rte_flow_template_table *table,
17435 : : const uint8_t actions_template_idx,
17436 : : const struct rte_flow_action actions[],
17437 : : struct rte_flow_error *error)
17438 : : {
17439 : : const struct rte_flow_actions_template *at;
17440 : : const struct mlx5_hw_actions *hw_acts;
17441 : : const struct mlx5_action_construct_data *act_data;
17442 : : unsigned int idx;
17443 : :
17444 [ # # ]: 0 : if (actions_template_idx >= table->nb_action_templates)
17445 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17446 : : "Actions template index out of range");
17447 : :
17448 : 0 : at = table->ats[actions_template_idx].action_template;
17449 : : hw_acts = &table->ats[actions_template_idx].acts;
17450 : :
17451 [ # # ]: 0 : for (idx = 0; actions[idx].type != RTE_FLOW_ACTION_TYPE_END; ++idx) {
17452 : : const struct rte_flow_action *user_action = &actions[idx];
17453 : 0 : const struct rte_flow_action *tmpl_action = &at->orig_actions[idx];
17454 : :
17455 [ # # ]: 0 : if (user_action->type != tmpl_action->type)
17456 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
17457 : : user_action,
17458 : : "Action type does not match type specified in "
17459 : : "actions template");
17460 : : }
17461 : :
17462 : : /*
17463 : : * Only go through unmasked actions and check if configuration is provided.
17464 : : * Configuration of masked actions is ignored.
17465 : : */
17466 [ # # ]: 0 : LIST_FOREACH(act_data, &hw_acts->act_list, next) {
17467 : : const struct rte_flow_action *user_action;
17468 : :
17469 : 0 : user_action = &actions[act_data->action_src];
17470 : :
17471 : : /* Skip actions which do not require conf. */
17472 [ # # ]: 0 : switch ((int)act_data->type) {
17473 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17474 : : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
17475 : : case MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK:
17476 : : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
17477 : 0 : continue;
17478 : : default:
17479 : : break;
17480 : : }
17481 : :
17482 [ # # ]: 0 : if (user_action->conf == NULL)
17483 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
17484 : : user_action,
17485 : : "Action requires configuration");
17486 : :
17487 [ # # # # : 0 : switch ((int)user_action->type) {
# # ]
17488 : : enum rte_flow_action_type expected_type;
17489 : : const struct rte_flow_action_ethdev *ethdev;
17490 : : const struct rte_flow_action_modify_field *mf;
17491 : :
17492 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
17493 : 0 : expected_type = act_data->indirect.expected_type;
17494 [ # # ]: 0 : if (!flow_hw_valid_indirect_action_type(user_action, expected_type))
17495 : 0 : return rte_flow_error_set(error, EINVAL,
17496 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
17497 : : user_action,
17498 : : "Indirect action type does not match "
17499 : : "the type specified in the mask");
17500 : : break;
17501 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17502 [ # # ]: 0 : if (mlx5_flow_validate_target_queue(dev, user_action, error))
17503 : 0 : return -rte_errno;
17504 : : break;
17505 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17506 [ # # ]: 0 : if (mlx5_validate_action_rss(dev, user_action, error))
17507 : 0 : return -rte_errno;
17508 : : break;
17509 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17510 : : /* TODO: Compare other fields if needed. */
17511 : : mf = user_action->conf;
17512 [ # # ]: 0 : if (mf->operation != act_data->modify_header.action.operation ||
17513 [ # # ]: 0 : mf->src.field != act_data->modify_header.action.src.field ||
17514 [ # # ]: 0 : mf->dst.field != act_data->modify_header.action.dst.field ||
17515 [ # # ]: 0 : mf->width != act_data->modify_header.action.width)
17516 : 0 : return rte_flow_error_set(error, EINVAL,
17517 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
17518 : : user_action,
17519 : : "Modify field configuration does not "
17520 : : "match configuration from actions "
17521 : : "template");
17522 : : break;
17523 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17524 : : ethdev = user_action->conf;
17525 [ # # ]: 0 : if (flow_hw_validate_target_port_id(dev, ethdev->port_id)) {
17526 : 0 : return rte_flow_error_set(error, EINVAL,
17527 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
17528 : : user_action, "Invalid port");
17529 : : }
17530 : : break;
17531 : : default:
17532 : : break;
17533 : : }
17534 : : }
17535 : :
17536 : : return 0;
17537 : : }
17538 : :
17539 : : static int
17540 : 0 : flow_hw_async_op_validate(struct rte_eth_dev *dev,
17541 : : const uint32_t queue,
17542 : : const struct rte_flow_template_table *table,
17543 : : struct rte_flow_error *error)
17544 : : {
17545 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17546 : :
17547 : : MLX5_ASSERT(table != NULL);
17548 : :
17549 [ # # # # ]: 0 : if (table->cfg.external && queue >= priv->hw_attr->nb_queue)
17550 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17551 : : "Incorrect queue");
17552 : :
17553 : : return 0;
17554 : : }
17555 : :
17556 : : /**
17557 : : * Validate user input for rte_flow_async_create() implementation.
17558 : : *
17559 : : * If RTE_PMD_MLX5_DEBUG macro is not defined, this function is a no-op.
17560 : : *
17561 : : * @param[in] dev
17562 : : * Pointer to the rte_eth_dev structure.
17563 : : * @param[in] queue
17564 : : * The queue to create the flow.
17565 : : * @param[in] table
17566 : : * Pointer to template table.
17567 : : * @param[in] rule_index
17568 : : * The item pattern flow follows from the table.
17569 : : * @param[in] items
17570 : : * Items with flow spec value.
17571 : : * @param[in] pattern_template_index
17572 : : * The item pattern flow follows from the table.
17573 : : * @param[in] actions
17574 : : * Action with flow spec value.
17575 : : * @param[in] action_template_index
17576 : : * The action pattern flow follows from the table.
17577 : : * @param[out] error
17578 : : * Pointer to error structure.
17579 : : *
17580 : : * @return
17581 : : * 0 if user input is valid.
17582 : : * Negative errno otherwise, rte_errno and error struct is populated.
17583 : : */
17584 : : static int
17585 : 0 : flow_hw_async_create_validate(struct rte_eth_dev *dev,
17586 : : const uint32_t queue,
17587 : : const struct rte_flow_template_table *table,
17588 : : enum rte_flow_table_insertion_type insertion_type,
17589 : : uint32_t rule_index,
17590 : : const struct rte_flow_item items[],
17591 : : const uint8_t pattern_template_index,
17592 : : const struct rte_flow_action actions[],
17593 : : const uint8_t action_template_index,
17594 : : struct rte_flow_error *error)
17595 : : {
17596 [ # # ]: 0 : if (flow_hw_async_op_validate(dev, queue, table, error))
17597 : 0 : return -rte_errno;
17598 : :
17599 [ # # ]: 0 : if (insertion_type != table->cfg.attr.insertion_type)
17600 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17601 : : NULL, "Flow rule insertion type mismatch with table configuration");
17602 : :
17603 [ # # ]: 0 : if (table->cfg.attr.insertion_type != RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN)
17604 [ # # ]: 0 : if (rule_index >= table->cfg.attr.nb_flows)
17605 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17606 : : NULL, "Flow rule index exceeds table size");
17607 : :
17608 [ # # ]: 0 : if (table->cfg.attr.insertion_type != RTE_FLOW_TABLE_INSERTION_TYPE_INDEX)
17609 [ # # ]: 0 : if (flow_hw_validate_rule_pattern(dev, table, pattern_template_index, items, error))
17610 : 0 : return -rte_errno;
17611 : :
17612 [ # # ]: 0 : if (flow_hw_validate_rule_actions(dev, table, action_template_index, actions, error))
17613 : 0 : return -rte_errno;
17614 : :
17615 : : return 0;
17616 : : }
17617 : :
17618 : : /**
17619 : : * Validate user input for rte_flow_async_update() implementation.
17620 : : *
17621 : : * If RTE_PMD_MLX5_DEBUG macro is not defined, this function is a no-op.
17622 : : *
17623 : : * @param[in] dev
17624 : : * Pointer to the rte_eth_dev structure.
17625 : : * @param[in] queue
17626 : : * The queue to create the flow.
17627 : : * @param[in] flow
17628 : : * Flow rule to be updated.
17629 : : * @param[in] actions
17630 : : * Action with flow spec value.
17631 : : * @param[in] action_template_index
17632 : : * The action pattern flow follows from the table.
17633 : : * @param[out] error
17634 : : * Pointer to error structure.
17635 : : *
17636 : : * @return
17637 : : * 0 if user input is valid.
17638 : : * Negative errno otherwise, rte_errno and error struct is set.
17639 : : */
17640 : : static int
17641 : 0 : flow_hw_async_update_validate(struct rte_eth_dev *dev,
17642 : : const uint32_t queue,
17643 : : const struct rte_flow_hw *flow,
17644 : : const struct rte_flow_action actions[],
17645 : : const uint8_t action_template_index,
17646 : : struct rte_flow_error *error)
17647 : : {
17648 [ # # ]: 0 : if (flow_hw_async_op_validate(dev, queue, flow->table, error))
17649 : 0 : return -rte_errno;
17650 : :
17651 [ # # ]: 0 : if (flow_hw_validate_rule_actions(dev, flow->table, action_template_index, actions, error))
17652 : 0 : return -rte_errno;
17653 : :
17654 : : return 0;
17655 : : }
17656 : :
17657 : : /**
17658 : : * Validate user input for rte_flow_async_destroy() implementation.
17659 : : *
17660 : : * If RTE_PMD_MLX5_DEBUG macro is not defined, this function is a no-op.
17661 : : *
17662 : : * @param[in] dev
17663 : : * Pointer to the rte_eth_dev structure.
17664 : : * @param[in] queue
17665 : : * The queue to create the flow.
17666 : : * @param[in] flow
17667 : : * Flow rule to be destroyed.
17668 : : * @param[out] error
17669 : : * Pointer to error structure.
17670 : : *
17671 : : * @return
17672 : : * 0 if user input is valid.
17673 : : * Negative errno otherwise, rte_errno and error struct is set.
17674 : : */
17675 : : static int
17676 : : flow_hw_async_destroy_validate(struct rte_eth_dev *dev,
17677 : : const uint32_t queue,
17678 : : const struct rte_flow_hw *flow,
17679 : : struct rte_flow_error *error)
17680 : : {
17681 : : if (flow_hw_async_op_validate(dev, queue, flow->table, error))
17682 : : return -rte_errno;
17683 : :
17684 : : return 0;
17685 : : }
17686 : :
17687 : : static struct rte_flow_fp_ops mlx5_flow_hw_fp_ops = {
17688 : : .async_create = flow_hw_async_flow_create,
17689 : : .async_create_by_index = flow_hw_async_flow_create_by_index,
17690 : : .async_create_by_index_with_pattern = flow_hw_async_flow_create_by_index_with_pattern,
17691 : : .async_actions_update = flow_hw_async_flow_update,
17692 : : .async_destroy = flow_hw_async_flow_destroy,
17693 : : .push = flow_hw_push,
17694 : : .pull = flow_hw_pull,
17695 : : .async_action_handle_create = flow_hw_action_handle_create,
17696 : : .async_action_handle_destroy = flow_hw_action_handle_destroy,
17697 : : .async_action_handle_update = flow_hw_action_handle_update,
17698 : : .async_action_handle_query = flow_hw_action_handle_query,
17699 : : .async_action_handle_query_update = flow_hw_async_action_handle_query_update,
17700 : : .async_action_list_handle_create = flow_hw_async_action_list_handle_create,
17701 : : .async_action_list_handle_destroy = flow_hw_async_action_list_handle_destroy,
17702 : : .async_action_list_handle_query_update =
17703 : : flow_hw_async_action_list_handle_query_update,
17704 : : };
17705 : :
17706 : : #endif
|