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 [ # # # # ]: 0 : new_cmd.field == last_cmd.field);
1577 : : else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
1578 : : should_insert = false;
1579 : : else
1580 : : MLX5_ASSERT(false); /* Other types are not supported. */
1581 : : break;
1582 : 0 : case MLX5_MODIFICATION_TYPE_COPY:
1583 : : case MLX5_MODIFICATION_TYPE_ADD_FIELD:
1584 [ # # # # ]: 0 : if (last_type == MLX5_MODIFICATION_TYPE_SET ||
1585 : : last_type == MLX5_MODIFICATION_TYPE_ADD)
1586 [ # # # # ]: 0 : should_insert = (new_cmd.field == last_cmd.field ||
1587 [ # # # # ]: 0 : new_cmd.dst_field == last_cmd.field);
1588 : 0 : else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
1589 [ # # # # ]: 0 : last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
1590 : 0 : should_insert = (new_cmd.field == last_cmd.dst_field ||
1591 [ # # # # : 0 : new_cmd.dst_field == last_cmd.dst_field ||
# # # # ]
1592 [ # # # # ]: 0 : new_cmd.dst_field == last_cmd.field);
1593 : : else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
1594 : : should_insert = false;
1595 : : else
1596 : : MLX5_ASSERT(false); /* Other types are not supported. */
1597 : : break;
1598 : : default:
1599 : : /* Other action types should be rejected on AT validation. */
1600 : : MLX5_ASSERT(false);
1601 : : break;
1602 : : }
1603 : : return should_insert;
1604 : : }
1605 : :
1606 : : static __rte_always_inline int
1607 : : flow_hw_mhdr_cmd_nop_append(struct mlx5_hw_modify_header_action *mhdr)
1608 : : {
1609 : : struct mlx5_modification_cmd *nop;
1610 : : uint32_t num = mhdr->mhdr_cmds_num;
1611 : :
1612 [ # # # # ]: 0 : if (num + 1 >= MLX5_MHDR_MAX_CMD)
1613 : : return -ENOMEM;
1614 : 0 : nop = mhdr->mhdr_cmds + num;
1615 : : nop->data0 = 0;
1616 : : nop->action_type = MLX5_MODIFICATION_TYPE_NOP;
1617 : 0 : nop->data0 = rte_cpu_to_be_32(nop->data0);
1618 : 0 : nop->data1 = 0;
1619 : 0 : mhdr->mhdr_cmds_num = num + 1;
1620 : : return 0;
1621 : : }
1622 : :
1623 : : static __rte_always_inline int
1624 : : flow_hw_mhdr_cmd_append(struct mlx5_hw_modify_header_action *mhdr,
1625 : : struct mlx5_modification_cmd *cmd)
1626 : : {
1627 : 0 : uint32_t num = mhdr->mhdr_cmds_num;
1628 : :
1629 [ # # ]: 0 : if (num + 1 >= MLX5_MHDR_MAX_CMD)
1630 : : return -ENOMEM;
1631 : 0 : mhdr->mhdr_cmds[num] = *cmd;
1632 : 0 : mhdr->mhdr_cmds_num = num + 1;
1633 : : return 0;
1634 : : }
1635 : :
1636 : : static __rte_always_inline int
1637 : : flow_hw_converted_mhdr_cmds_append(struct mlx5_hw_modify_header_action *mhdr,
1638 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1639 : : const struct rte_flow_attr *attr)
1640 : : {
1641 : : uint32_t idx;
1642 : : int ret;
1643 : :
1644 [ # # ]: 0 : for (idx = 0; idx < resource->actions_num; ++idx) {
1645 : : struct mlx5_modification_cmd *src = &resource->actions[idx];
1646 : :
1647 [ # # ]: 0 : if (flow_hw_should_insert_nop(mhdr, src, attr)) {
1648 : : ret = flow_hw_mhdr_cmd_nop_append(mhdr);
1649 : : if (ret)
1650 : : return ret;
1651 : : }
1652 : : ret = flow_hw_mhdr_cmd_append(mhdr, src);
1653 : : if (ret)
1654 : : return ret;
1655 : : }
1656 : : return 0;
1657 : : }
1658 : :
1659 : : static __rte_always_inline void
1660 : : flow_hw_modify_field_init(struct mlx5_hw_modify_header_action *mhdr,
1661 : : struct rte_flow_actions_template *at)
1662 : : {
1663 : : memset(mhdr, 0, sizeof(*mhdr));
1664 : : /* Modify header action without any commands is shared by default. */
1665 : 0 : mhdr->shared = true;
1666 : 0 : mhdr->pos = at->mhdr_off;
1667 : : }
1668 : :
1669 : : static __rte_always_inline int
1670 : : flow_hw_modify_field_compile(struct rte_eth_dev *dev,
1671 : : const struct rte_flow_attr *attr,
1672 : : const struct rte_flow_action *action, /* Current action from AT. */
1673 : : const struct rte_flow_action *action_mask, /* Current mask from AT. */
1674 : : struct mlx5_hw_actions *acts,
1675 : : struct mlx5_hw_modify_header_action *mhdr,
1676 : : uint16_t src_pos,
1677 : : struct rte_flow_error *error)
1678 : : {
1679 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1680 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
1681 : : union {
1682 : : struct mlx5_flow_dv_modify_hdr_resource resource;
1683 : : uint8_t data[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
1684 : : sizeof(struct mlx5_modification_cmd) * MLX5_MHDR_MAX_CMD];
1685 : : } dummy;
1686 : : struct mlx5_flow_dv_modify_hdr_resource *resource;
1687 : 0 : struct rte_flow_item item = {
1688 : : .spec = NULL,
1689 : : .mask = NULL
1690 : : };
1691 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1692 : : {0, 0, MLX5_MODI_OUT_NONE} };
1693 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1694 : : {0, 0, MLX5_MODI_OUT_NONE} };
1695 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = { 0 };
1696 : 0 : uint32_t type, value = 0;
1697 : : uint16_t cmds_start, cmds_end;
1698 : : bool shared;
1699 : : int ret;
1700 : :
1701 : : /*
1702 : : * Modify header action is shared if previous modify_field actions
1703 : : * are shared and currently compiled action is shared.
1704 : : */
1705 : : shared = flow_hw_action_modify_field_is_shared(action, action_mask);
1706 : 0 : mhdr->shared &= shared;
1707 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1708 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
1709 [ # # ]: 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ? MLX5_MODIFICATION_TYPE_SET :
1710 : : MLX5_MODIFICATION_TYPE_ADD;
1711 : : /* For SET/ADD fill the destination field (field) first. */
1712 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1713 : 0 : conf->width, dev,
1714 : : attr, error);
1715 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1716 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
1717 : : (void *)(uintptr_t)&conf->src.value;
1718 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
1719 : : conf->dst.field == RTE_FLOW_FIELD_TAG ||
1720 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR ||
1721 : 0 : conf->dst.field == (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
1722 : : uint8_t tag_index = flow_tag_index_get(&conf->dst);
1723 : :
1724 : 0 : value = *(const unaligned_uint32_t *)item.spec;
1725 [ # # # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_TAG &&
1726 : : tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
1727 [ # # ]: 0 : value = rte_cpu_to_be_32(value << 16);
1728 : : else
1729 [ # # ]: 0 : value = rte_cpu_to_be_32(value);
1730 : 0 : item.spec = &value;
1731 : : } else if (conf->dst.field == RTE_FLOW_FIELD_GTP_PSC_QFI ||
1732 : : conf->dst.field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE) {
1733 : : /*
1734 : : * Both QFI and Geneve option type are passed as an uint8_t integer,
1735 : : * but it is accessed through a 2nd least significant byte of a 32-bit
1736 : : * field in modify header command.
1737 : : */
1738 : 0 : value = *(const uint8_t *)item.spec;
1739 [ # # ]: 0 : value = rte_cpu_to_be_32(value << 8);
1740 : 0 : item.spec = &value;
1741 : : } else if (conf->dst.field == RTE_FLOW_FIELD_VXLAN_LAST_RSVD) {
1742 : 0 : value = *(const uint8_t *)item.spec << 24;
1743 [ # # ]: 0 : value = rte_cpu_to_be_32(value);
1744 : 0 : item.spec = &value;
1745 : 0 : } else if (conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
1746 [ # # # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK) &&
1747 [ # # ]: 0 : mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private)) {
1748 : 0 : value = *(const unaligned_uint32_t *)item.spec << MLX5_IPV6_HDR_DSCP_SHIFT;
1749 : 0 : item.spec = &value;
1750 : : }
1751 : : } else {
1752 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
1753 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_COPY : MLX5_MODIFICATION_TYPE_ADD_FIELD;
1754 : : /* For COPY fill the destination field (dcopy) without mask. */
1755 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1756 : 0 : conf->width, dev,
1757 : : attr, error);
1758 : : /* Then construct the source field (field) with mask. */
1759 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1760 : 0 : conf->width, dev,
1761 : : attr, error);
1762 : : }
1763 : 0 : item.mask = &mask;
1764 : : memset(&dummy, 0, sizeof(dummy));
1765 : : resource = &dummy.resource;
1766 : 0 : ret = mlx5_flow_dv_convert_modify_action(&item, field, dcopy, resource, type, error);
1767 [ # # ]: 0 : if (ret)
1768 : : return ret;
1769 : : MLX5_ASSERT(resource->actions_num > 0);
1770 : : /*
1771 : : * If previous modify field action collide with this one, then insert NOP command.
1772 : : * This NOP command will not be a part of action's command range used to update commands
1773 : : * on rule creation.
1774 : : */
1775 [ # # ]: 0 : if (flow_hw_should_insert_nop(mhdr, &resource->actions[0], attr)) {
1776 : : ret = flow_hw_mhdr_cmd_nop_append(mhdr);
1777 : : if (ret)
1778 : 0 : return rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1779 : : NULL, "too many modify field operations specified");
1780 : : }
1781 : 0 : cmds_start = mhdr->mhdr_cmds_num;
1782 : : ret = flow_hw_converted_mhdr_cmds_append(mhdr, resource, attr);
1783 [ # # ]: 0 : if (ret)
1784 : 0 : return rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1785 : : NULL, "too many modify field operations specified");
1786 : :
1787 : 0 : cmds_end = mhdr->mhdr_cmds_num;
1788 [ # # ]: 0 : if (shared)
1789 : : return 0;
1790 : : ret = __flow_hw_act_data_hdr_modify_append(priv, acts, RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
1791 : 0 : src_pos, mhdr->pos, conf,
1792 : : cmds_start, cmds_end, shared,
1793 : : field, dcopy, mask);
1794 : : if (ret)
1795 : 0 : return rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1796 : : NULL, "not enough memory to store modify field metadata");
1797 : : return 0;
1798 : : }
1799 : :
1800 : : static uint32_t
1801 : 0 : flow_hw_count_nop_modify_field(struct mlx5_hw_modify_header_action *mhdr)
1802 : : {
1803 : : uint32_t i;
1804 : : uint32_t nops = 0;
1805 : :
1806 [ # # ]: 0 : for (i = 0; i < mhdr->mhdr_cmds_num; ++i) {
1807 : 0 : struct mlx5_modification_cmd cmd = mhdr->mhdr_cmds[i];
1808 : :
1809 [ # # ]: 0 : cmd.data0 = rte_be_to_cpu_32(cmd.data0);
1810 [ # # ]: 0 : if (cmd.action_type == MLX5_MODIFICATION_TYPE_NOP)
1811 : 0 : ++nops;
1812 : : }
1813 : 0 : return nops;
1814 : : }
1815 : :
1816 : : static int
1817 : 0 : flow_hw_validate_compiled_modify_field(struct rte_eth_dev *dev,
1818 : : const struct mlx5_flow_template_table_cfg *cfg,
1819 : : struct mlx5_hw_modify_header_action *mhdr,
1820 : : struct rte_flow_error *error)
1821 : : {
1822 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1823 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
1824 : :
1825 : : /*
1826 : : * Header modify pattern length limitation is only valid for HWS groups, i.e. groups > 0.
1827 : : * In group 0, MODIFY_FIELD actions are handled with header modify actions
1828 : : * managed by rdma-core.
1829 : : */
1830 [ # # ]: 0 : if (cfg->attr.flow_attr.group != 0 &&
1831 [ # # ]: 0 : mhdr->mhdr_cmds_num > hca_attr->max_header_modify_pattern_length) {
1832 : 0 : uint32_t nops = flow_hw_count_nop_modify_field(mhdr);
1833 : :
1834 : 0 : DRV_LOG(ERR, "Too many modify header commands generated from "
1835 : : "MODIFY_FIELD actions. "
1836 : : "Generated HW commands = %u (amount of NOP commands = %u). "
1837 : : "Maximum supported = %u.",
1838 : : mhdr->mhdr_cmds_num, nops,
1839 : : hca_attr->max_header_modify_pattern_length);
1840 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1841 : : "Number of MODIFY_FIELD actions exceeds maximum "
1842 : : "supported limit of actions");
1843 : : }
1844 : : return 0;
1845 : : }
1846 : :
1847 : : static int
1848 : 0 : flow_hw_represented_port_compile(struct rte_eth_dev *dev,
1849 : : const struct rte_flow_attr *attr,
1850 : : const struct rte_flow_action *action,
1851 : : const struct rte_flow_action *action_mask,
1852 : : struct mlx5_hw_actions *acts,
1853 : : uint16_t action_src, uint16_t action_dst,
1854 : : struct rte_flow_error *error)
1855 : : {
1856 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1857 : 0 : const struct rte_flow_action_ethdev *v = action->conf;
1858 : 0 : const struct rte_flow_action_ethdev *m = action_mask->conf;
1859 : : int ret;
1860 : :
1861 [ # # ]: 0 : if (!attr->group)
1862 : 0 : return rte_flow_error_set(error, EINVAL,
1863 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1864 : : "represented_port action cannot"
1865 : : " be used on group 0");
1866 [ # # ]: 0 : if (!attr->transfer)
1867 : 0 : return rte_flow_error_set(error, EINVAL,
1868 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1869 : : NULL,
1870 : : "represented_port action requires"
1871 : : " transfer attribute");
1872 [ # # ]: 0 : if (attr->ingress || attr->egress)
1873 : 0 : return rte_flow_error_set(error, EINVAL,
1874 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1875 : : "represented_port action cannot"
1876 : : " be used with direction attributes");
1877 [ # # ]: 0 : if (!priv->master)
1878 : 0 : return rte_flow_error_set(error, EINVAL,
1879 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1880 : : "represented_port action must"
1881 : : " be used on proxy port");
1882 [ # # # # ]: 0 : if (m && !!m->port_id) {
1883 : : struct mlx5_priv *port_priv;
1884 : :
1885 [ # # ]: 0 : if (!v)
1886 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1887 : : action, "port index was not provided");
1888 : 0 : port_priv = mlx5_port_to_eswitch_info(v->port_id, false);
1889 [ # # ]: 0 : if (port_priv == NULL)
1890 : 0 : return rte_flow_error_set
1891 : : (error, EINVAL,
1892 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1893 : : "port does not exist or unable to"
1894 : : " obtain E-Switch info for port");
1895 : : MLX5_ASSERT(priv->hw_vport != NULL);
1896 [ # # ]: 0 : if (priv->hw_vport[v->port_id]) {
1897 : 0 : acts->rule_acts[action_dst].action =
1898 : : priv->hw_vport[v->port_id];
1899 : : } else {
1900 : 0 : return rte_flow_error_set
1901 : : (error, EINVAL,
1902 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1903 : : "cannot use represented_port action"
1904 : : " with this port");
1905 : : }
1906 : : } else {
1907 : : ret = __flow_hw_act_data_general_append
1908 : 0 : (priv, acts, action->type,
1909 : : action_src, action_dst);
1910 : : if (ret)
1911 : 0 : return rte_flow_error_set
1912 : : (error, ENOMEM,
1913 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1914 : : "not enough memory to store"
1915 : : " vport action");
1916 : : }
1917 : : return 0;
1918 : : }
1919 : :
1920 : : static __rte_always_inline int
1921 : : flow_hw_cnt_compile(struct rte_eth_dev *dev, uint32_t start_pos,
1922 : : struct mlx5_hw_actions *acts, bool is_root)
1923 : : {
1924 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1925 : : uint32_t pos = start_pos;
1926 : : cnt_id_t cnt_id;
1927 : : int ret;
1928 : :
1929 : 0 : ret = mlx5_hws_cnt_shared_get(priv->hws_cpool, &cnt_id, 0);
1930 : : if (ret != 0)
1931 : : return ret;
1932 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
1933 : : (priv->hws_cpool,
1934 : : cnt_id,
1935 : : &acts->rule_acts[pos].action,
1936 : : &acts->rule_acts[pos].counter.offset,
1937 : : is_root);
1938 : : if (ret != 0)
1939 : : return ret;
1940 : 0 : acts->cnt_id = cnt_id;
1941 : : return 0;
1942 : : }
1943 : :
1944 : : static __rte_always_inline bool
1945 : : is_of_vlan_pcp_present(const struct rte_flow_action *actions)
1946 : : {
1947 : : /*
1948 : : * Order of RTE VLAN push actions is
1949 : : * OF_PUSH_VLAN / OF_SET_VLAN_VID [ / OF_SET_VLAN_PCP ]
1950 : : */
1951 : 0 : return actions[MLX5_HW_VLAN_PUSH_PCP_IDX].type ==
1952 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP;
1953 : : }
1954 : :
1955 : : static __rte_always_inline bool
1956 : : is_template_masked_push_vlan(const struct rte_flow_action_of_push_vlan *mask)
1957 : : {
1958 : : /*
1959 : : * In masked push VLAN template all RTE push actions are masked.
1960 : : */
1961 [ # # ]: 0 : return mask && mask->ethertype != 0;
1962 : : }
1963 : :
1964 : 0 : static rte_be32_t vlan_hdr_to_be32(const struct rte_flow_action *actions)
1965 : : {
1966 : : /*
1967 : : * OpenFlow Switch Specification defines 801.1q VID as 12+1 bits.
1968 : : */
1969 : : rte_be32_t type, vid, pcp;
1970 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1971 : : rte_be32_t vid_lo, vid_hi;
1972 : : #endif
1973 : :
1974 : 0 : type = ((const struct rte_flow_action_of_push_vlan *)
1975 : 0 : actions[MLX5_HW_VLAN_PUSH_TYPE_IDX].conf)->ethertype;
1976 : 0 : vid = ((const struct rte_flow_action_of_set_vlan_vid *)
1977 : 0 : actions[MLX5_HW_VLAN_PUSH_VID_IDX].conf)->vlan_vid;
1978 : : pcp = is_of_vlan_pcp_present(actions) ?
1979 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
1980 [ # # ]: 0 : actions[MLX5_HW_VLAN_PUSH_PCP_IDX].conf)->vlan_pcp : 0;
1981 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1982 : 0 : vid_hi = vid & 0xff;
1983 : : vid_lo = vid >> 8;
1984 : 0 : return (((vid_lo << 8) | (pcp << 5) | vid_hi) << 16) | type;
1985 : : #else
1986 : : return (type << 16) | (pcp << 13) | vid;
1987 : : #endif
1988 : : }
1989 : :
1990 : : static __rte_always_inline int
1991 : : flow_hw_meter_mark_alloc(struct rte_eth_dev *dev, uint32_t queue,
1992 : : const struct rte_flow_action *action,
1993 : : struct mlx5_hw_q_job *job, bool push,
1994 : : struct mlx5_aso_mtr **aso_mtr,
1995 : : struct rte_flow_error *error)
1996 : : {
1997 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1998 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
1999 : 0 : const struct rte_flow_action_meter_mark *meter_mark = action->conf;
2000 : : struct mlx5_flow_meter_info *fm;
2001 : 0 : uint32_t mtr_id = 0;
2002 : : uintptr_t handle = (uintptr_t)MLX5_INDIRECT_ACTION_TYPE_METER_MARK <<
2003 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET;
2004 : :
2005 : 0 : if (priv->shared_host)
2006 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2007 : : "Meter mark actions can only be created on the host port");
2008 : : MLX5_ASSERT(aso_mtr);
2009 [ # # # # : 0 : if (meter_mark->profile == NULL)
# # # # #
# # # #
# ]
2010 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2011 : : "No Meter mark profile");
2012 : :
2013 : 0 : *aso_mtr = mlx5_ipool_malloc(pool->idx_pool, &mtr_id);
2014 [ # # # # : 0 : if (!*aso_mtr) {
# # # # #
# # # #
# ]
2015 [ # # # # : 0 : if (mtr_id)
# # # # #
# # # #
# ]
2016 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
2017 : 0 : return rte_flow_error_set(error, ENOMEM,
2018 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2019 : : NULL,
2020 : : "failed to allocate aso meter entry");
2021 : : }
2022 : : /* Fill the flow meter parameters. */
2023 : 0 : (*aso_mtr)->type = ASO_METER_INDIRECT;
2024 : : fm = &(*aso_mtr)->fm;
2025 : 0 : fm->meter_id = mtr_id;
2026 : 0 : fm->profile = (struct mlx5_flow_meter_profile *)(meter_mark->profile);
2027 : 0 : fm->is_enable = meter_mark->state;
2028 : 0 : fm->color_aware = meter_mark->color_mode;
2029 : 0 : (*aso_mtr)->pool = pool;
2030 [ # # ]: 0 : (*aso_mtr)->state = (queue == MLX5_HW_INV_QUEUE) ?
2031 : : ASO_METER_WAIT : ASO_METER_WAIT_ASYNC;
2032 : 0 : (*aso_mtr)->offset = mtr_id - 1;
2033 [ # # # # : 0 : (*aso_mtr)->init_color = fm->color_aware ? RTE_COLORS : RTE_COLOR_GREEN;
# # # # #
# # # #
# ]
2034 : 0 : job->action = (void *)(handle | mtr_id);
2035 : : /* Update ASO flow meter by wqe. */
2036 [ # # # # : 0 : if (mlx5_aso_meter_update_by_wqe(priv, queue, *aso_mtr,
# # # # #
# # # #
# ]
2037 : : &priv->mtr_bulk, job, push)) {
2038 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
2039 : 0 : return rte_flow_error_set(error, EBUSY,
2040 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2041 : : NULL,
2042 : : "Failed to enqueue ASO meter update");
2043 : : }
2044 : : /* Wait for ASO object completion. */
2045 [ # # # # : 0 : if (queue == MLX5_HW_INV_QUEUE &&
# # # # #
# # # # #
# # ]
2046 : 0 : mlx5_aso_mtr_wait(priv, *aso_mtr, true)) {
2047 : 0 : mlx5_ipool_free(pool->idx_pool, mtr_id);
2048 : : return -EIO;
2049 : : }
2050 : : return 0;
2051 : : }
2052 : :
2053 : : static __rte_always_inline int
2054 : : flow_hw_meter_mark_compile(struct rte_eth_dev *dev,
2055 : : uint16_t aso_mtr_pos,
2056 : : const struct rte_flow_action *action,
2057 : : struct mlx5dr_rule_action *acts,
2058 : : uint32_t *index,
2059 : : uint32_t queue,
2060 : : struct rte_flow_error *error)
2061 : : {
2062 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2063 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
2064 : : struct mlx5_aso_mtr *aso_mtr = NULL;
2065 : : struct mlx5_hw_q_job *job =
2066 : : flow_hw_action_job_init(priv, queue, NULL, NULL, NULL,
2067 : : MLX5_HW_Q_JOB_TYPE_CREATE,
2068 : : MLX5_HW_INDIRECT_TYPE_LEGACY, NULL);
2069 : : int ret;
2070 : :
2071 : : if (!job)
2072 : : return -1;
2073 : : ret = flow_hw_meter_mark_alloc(dev, queue, action, job, true, &aso_mtr, error);
2074 [ # # # # : 0 : if (ret) {
# # # # #
# # # ]
2075 [ # # # # : 0 : if (ret != -EIO) {
# # # # #
# # # ]
2076 : : if (queue == MLX5_HW_INV_QUEUE)
2077 : 0 : queue = CTRL_QUEUE_ID(priv);
2078 : : flow_hw_job_put(priv, job, queue);
2079 : : }
2080 : : return -1;
2081 : : }
2082 : :
2083 : : /* Compile METER_MARK action */
2084 : 0 : acts[aso_mtr_pos].action = pool->action;
2085 : 0 : acts[aso_mtr_pos].aso_meter.offset = aso_mtr->offset;
2086 : 0 : *index = aso_mtr->fm.meter_id;
2087 : : return 0;
2088 : : }
2089 : :
2090 : : static int
2091 : 0 : flow_hw_translate_indirect_mirror(__rte_unused struct rte_eth_dev *dev,
2092 : : __rte_unused const struct mlx5_action_construct_data *act_data,
2093 : : const struct rte_flow_action *action,
2094 : : struct mlx5dr_rule_action *dr_rule)
2095 : : {
2096 : 0 : const struct rte_flow_action_indirect_list *list_conf = action->conf;
2097 : 0 : const struct mlx5_mirror *mirror = (typeof(mirror))list_conf->handle;
2098 : :
2099 : 0 : dr_rule->action = mirror->mirror_action;
2100 : 0 : return 0;
2101 : : }
2102 : :
2103 : : /**
2104 : : * HWS mirror implemented as FW island.
2105 : : * The action does not support indirect list flow configuration.
2106 : : * If template handle was masked, use handle mirror action in flow rules.
2107 : : * Otherwise let flow rule specify mirror handle.
2108 : : */
2109 : : static int
2110 : 0 : hws_table_tmpl_translate_indirect_mirror(struct rte_eth_dev *dev,
2111 : : const struct rte_flow_action *action,
2112 : : const struct rte_flow_action *mask,
2113 : : struct mlx5_hw_actions *acts,
2114 : : uint16_t action_src, uint16_t action_dst)
2115 : : {
2116 : : int ret = 0;
2117 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
2118 : :
2119 [ # # # # ]: 0 : if (mask_conf && mask_conf->handle) {
2120 : : /**
2121 : : * If mirror handle was masked, assign fixed DR5 mirror action.
2122 : : */
2123 : : flow_hw_translate_indirect_mirror(dev, NULL, action,
2124 : 0 : &acts->rule_acts[action_dst]);
2125 : : } else {
2126 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2127 : : ret = flow_hw_act_data_indirect_list_append
2128 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
2129 : : action_src, action_dst,
2130 : : flow_hw_translate_indirect_mirror);
2131 : : }
2132 : :
2133 : 0 : return ret;
2134 : : }
2135 : :
2136 : : static int
2137 : 0 : flow_hw_reformat_action(__rte_unused struct rte_eth_dev *dev,
2138 : : __rte_unused const struct mlx5_action_construct_data *data,
2139 : : const struct rte_flow_action *action,
2140 : : struct mlx5dr_rule_action *dr_rule)
2141 : : {
2142 : 0 : const struct rte_flow_action_indirect_list *indlst_conf = action->conf;
2143 : :
2144 : 0 : dr_rule->action = ((struct mlx5_hw_encap_decap_action *)
2145 : 0 : (indlst_conf->handle))->action;
2146 [ # # ]: 0 : if (!dr_rule->action)
2147 : 0 : return -EINVAL;
2148 : : return 0;
2149 : : }
2150 : :
2151 : : /**
2152 : : * Template conf must not be masked. If handle is masked, use the one in template,
2153 : : * otherwise update per flow rule.
2154 : : */
2155 : : static int
2156 : 0 : hws_table_tmpl_translate_indirect_reformat(struct rte_eth_dev *dev,
2157 : : const struct rte_flow_action *action,
2158 : : const struct rte_flow_action *mask,
2159 : : struct mlx5_hw_actions *acts,
2160 : : uint16_t action_src, uint16_t action_dst)
2161 : : {
2162 : : int ret = -1;
2163 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
2164 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2165 : :
2166 [ # # # # : 0 : if (mask_conf && mask_conf->handle && !mask_conf->conf)
# # ]
2167 : : /**
2168 : : * If handle was masked, assign fixed DR action.
2169 : : */
2170 : : ret = flow_hw_reformat_action(dev, NULL, action,
2171 [ # # ]: 0 : &acts->rule_acts[action_dst]);
2172 [ # # # # : 0 : else if (mask_conf && !mask_conf->handle && !mask_conf->conf)
# # ]
2173 : : ret = flow_hw_act_data_indirect_list_append
2174 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
2175 : : action_src, action_dst, flow_hw_reformat_action);
2176 : 0 : return ret;
2177 : : }
2178 : :
2179 : : static int
2180 : 0 : flow_dr_set_meter(struct mlx5_priv *priv,
2181 : : struct mlx5dr_rule_action *dr_rule,
2182 : : const struct rte_flow_action_indirect_list *action_conf)
2183 : : {
2184 : 0 : const struct mlx5_indlst_legacy *legacy_obj =
2185 : : (typeof(legacy_obj))action_conf->handle;
2186 : 0 : struct mlx5_aso_mtr_pool *mtr_pool = priv->hws_mpool;
2187 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)legacy_obj->handle;
2188 : 0 : uint32_t mtr_id = act_idx & (RTE_BIT32(MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
2189 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_ipool_get(mtr_pool->idx_pool, mtr_id);
2190 : :
2191 [ # # ]: 0 : if (!aso_mtr)
2192 : : return -EINVAL;
2193 : 0 : dr_rule->action = mtr_pool->action;
2194 : 0 : dr_rule->aso_meter.offset = aso_mtr->offset;
2195 : 0 : return 0;
2196 : : }
2197 : :
2198 : : __rte_always_inline static void
2199 : : flow_dr_mtr_flow_color(struct mlx5dr_rule_action *dr_rule, enum rte_color init_color)
2200 : : {
2201 : 0 : dr_rule->aso_meter.init_color =
2202 : 0 : (enum mlx5dr_action_aso_meter_color)rte_col_2_mlx5_col(init_color);
2203 : 0 : }
2204 : :
2205 : : static int
2206 : 0 : flow_hw_translate_indirect_meter(struct rte_eth_dev *dev,
2207 : : const struct mlx5_action_construct_data *act_data,
2208 : : const struct rte_flow_action *action,
2209 : : struct mlx5dr_rule_action *dr_rule)
2210 : : {
2211 : : int ret;
2212 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2213 : 0 : const struct rte_flow_action_indirect_list *action_conf = action->conf;
2214 : 0 : const struct rte_flow_indirect_update_flow_meter_mark **flow_conf =
2215 : : (typeof(flow_conf))action_conf->conf;
2216 : :
2217 : 0 : ret = flow_dr_set_meter(priv, dr_rule, action_conf);
2218 [ # # ]: 0 : if (ret)
2219 : : return ret;
2220 [ # # ]: 0 : if (!act_data->shared_meter.conf_masked) {
2221 [ # # # # : 0 : if (flow_conf && flow_conf[0] && flow_conf[0]->init_color < RTE_COLORS)
# # ]
2222 : : flow_dr_mtr_flow_color(dr_rule, flow_conf[0]->init_color);
2223 : : }
2224 : : return 0;
2225 : : }
2226 : :
2227 : : static int
2228 : 0 : hws_table_tmpl_translate_indirect_meter(struct rte_eth_dev *dev,
2229 : : const struct rte_flow_action *action,
2230 : : const struct rte_flow_action *mask,
2231 : : struct mlx5_hw_actions *acts,
2232 : : uint16_t action_src, uint16_t action_dst)
2233 : : {
2234 : : int ret;
2235 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2236 : 0 : const struct rte_flow_action_indirect_list *action_conf = action->conf;
2237 : 0 : const struct rte_flow_action_indirect_list *mask_conf = mask->conf;
2238 [ # # # # ]: 0 : bool is_handle_masked = mask_conf && mask_conf->handle;
2239 [ # # # # : 0 : bool is_conf_masked = mask_conf && mask_conf->conf && mask_conf->conf[0];
# # ]
2240 : 0 : struct mlx5dr_rule_action *dr_rule = &acts->rule_acts[action_dst];
2241 : :
2242 [ # # ]: 0 : if (is_handle_masked) {
2243 : 0 : ret = flow_dr_set_meter(priv, dr_rule, action->conf);
2244 [ # # ]: 0 : if (ret)
2245 : : return ret;
2246 : : }
2247 [ # # ]: 0 : if (is_conf_masked) {
2248 : : const struct
2249 : 0 : rte_flow_indirect_update_flow_meter_mark **flow_conf =
2250 : : (typeof(flow_conf))action_conf->conf;
2251 : : flow_dr_mtr_flow_color(dr_rule,
2252 [ # # ]: 0 : flow_conf[0]->init_color);
2253 : : }
2254 [ # # ]: 0 : if (!is_handle_masked || !is_conf_masked) {
2255 : : struct mlx5_action_construct_data *act_data;
2256 : :
2257 : : ret = flow_hw_act_data_indirect_list_append
2258 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT_LIST,
2259 : : action_src, action_dst, flow_hw_translate_indirect_meter);
2260 : : if (ret)
2261 : 0 : return ret;
2262 : : act_data = LIST_FIRST(&acts->act_list);
2263 : 0 : act_data->shared_meter.conf_masked = is_conf_masked;
2264 : : }
2265 : : return 0;
2266 : : }
2267 : :
2268 : : static int
2269 : : hws_table_tmpl_translate_indirect_legacy(struct rte_eth_dev *dev,
2270 : : const struct rte_flow_action *action,
2271 : : const struct rte_flow_action *mask,
2272 : : struct mlx5_hw_actions *acts,
2273 : : uint16_t action_src, uint16_t action_dst)
2274 : : {
2275 : : int ret;
2276 : : const struct rte_flow_action_indirect_list *indlst_conf = action->conf;
2277 : : struct mlx5_indlst_legacy *indlst_obj = (typeof(indlst_obj))indlst_conf->handle;
2278 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)indlst_obj->handle;
2279 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
2280 : :
2281 : 0 : switch (type) {
2282 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
2283 : 0 : ret = hws_table_tmpl_translate_indirect_meter(dev, action, mask,
2284 : : acts, action_src,
2285 : : action_dst);
2286 : 0 : break;
2287 : : default:
2288 : : ret = -EINVAL;
2289 : : break;
2290 : : }
2291 : : return ret;
2292 : : }
2293 : :
2294 : : /*
2295 : : * template .. indirect_list handle Ht conf Ct ..
2296 : : * mask .. indirect_list handle Hm conf Cm ..
2297 : : *
2298 : : * PMD requires Ht != 0 to resolve handle type.
2299 : : * If Ht was masked (Hm != 0) DR5 action will be set according to Ht and will
2300 : : * not change. Otherwise, DR5 action will be resolved during flow rule build.
2301 : : * If Ct was masked (Cm != 0), table template processing updates base
2302 : : * indirect action configuration with Ct parameters.
2303 : : */
2304 : : static int
2305 : 0 : table_template_translate_indirect_list(struct rte_eth_dev *dev,
2306 : : const struct rte_flow_action *action,
2307 : : const struct rte_flow_action *mask,
2308 : : struct mlx5_hw_actions *acts,
2309 : : uint16_t action_src, uint16_t action_dst)
2310 : : {
2311 : : int ret = 0;
2312 : : enum mlx5_indirect_list_type type;
2313 : 0 : const struct rte_flow_action_indirect_list *list_conf = action->conf;
2314 : :
2315 [ # # # # ]: 0 : if (!list_conf || !list_conf->handle)
2316 : : return -EINVAL;
2317 : : type = mlx5_get_indirect_list_type(list_conf->handle);
2318 [ # # # # ]: 0 : switch (type) {
2319 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
2320 [ # # ]: 0 : ret = hws_table_tmpl_translate_indirect_legacy(dev, action, mask,
2321 : : acts, action_src,
2322 : : action_dst);
2323 : : break;
2324 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
2325 : 0 : ret = hws_table_tmpl_translate_indirect_mirror(dev, action, mask,
2326 : : acts, action_src,
2327 : : action_dst);
2328 : 0 : break;
2329 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
2330 [ # # ]: 0 : if (list_conf->conf)
2331 : : return -EINVAL;
2332 : 0 : ret = hws_table_tmpl_translate_indirect_reformat(dev, action, mask,
2333 : : acts, action_src,
2334 : : action_dst);
2335 : 0 : break;
2336 : : default:
2337 : : return -EINVAL;
2338 : : }
2339 : : return ret;
2340 : : }
2341 : :
2342 : : /**
2343 : : * Translate given encap action and mask to raw tunnel header buffer.
2344 : : *
2345 : : * @param[in] action
2346 : : * Pointer to encap action.
2347 : : * @param[in] mask
2348 : : * Pointer to encap action's mask.
2349 : : * @param[out] conf_encap_data
2350 : : * Buffer where tunnel header will be written.
2351 : : * @param[out] data_size
2352 : : * Pointer to tunnel header size.
2353 : : * @param[out] error
2354 : : * Pointer to error structure.
2355 : : *
2356 : : * @return
2357 : : * 0 or greater if translation was successful.
2358 : : * Negative errno value otherwise.
2359 : : *
2360 : : * If returned value is 0, then action is not shared in the actions template
2361 : : * If bigger than 0, then it is shared.
2362 : : */
2363 : : static int
2364 : 0 : translate_l2_encap_action(const struct rte_flow_action *action,
2365 : : const struct rte_flow_action *mask,
2366 : : uint8_t conf_encap_data[MLX5_ENCAP_MAX_LEN],
2367 : : size_t *data_size,
2368 : : struct rte_flow_error *error)
2369 : : {
2370 : : struct rte_flow_item *conf_item;
2371 : : int ret;
2372 : :
2373 [ # # ]: 0 : if (action->conf == NULL)
2374 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2375 : : "Missing VXLAN/NVGRE encap action configuration");
2376 : :
2377 : : /* Only these 2 action types receive encap data as flow item pattern. */
2378 : : MLX5_ASSERT(action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ||
2379 : : action->type == RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP);
2380 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
2381 : 0 : conf_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_vxlan_encap, action->conf);
2382 : : else
2383 : 0 : conf_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_nvgre_encap, action->conf);
2384 [ # # ]: 0 : if (conf_item == NULL)
2385 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2386 : : "Missing VXLAN/NVGRE tunnel definition in action config");
2387 : :
2388 : 0 : ret = mlx5_flow_dv_convert_encap_data(conf_item, conf_encap_data, data_size, error);
2389 [ # # ]: 0 : if (ret < 0)
2390 : : return ret;
2391 : :
2392 : : /* If mask is provided, then action is shared */
2393 : 0 : return mask->conf != NULL;
2394 : : }
2395 : :
2396 : : static void
2397 : : mlx5_set_reformat_header(struct mlx5dr_action_reformat_header *hdr,
2398 : : uint8_t *encap_data,
2399 : : size_t data_size)
2400 : : {
2401 : 0 : hdr->sz = data_size;
2402 : 0 : hdr->data = encap_data;
2403 : : }
2404 : :
2405 : : static int
2406 [ # # ]: 0 : mlx5_tbl_translate_reformat(struct mlx5_priv *priv,
2407 : : struct mlx5_hw_actions *acts,
2408 : : struct rte_flow_actions_template *at,
2409 : : uint8_t *encap_data, uint8_t *encap_data_m,
2410 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
2411 : : size_t data_size, uint16_t reformat_src,
2412 : : enum mlx5dr_action_type refmt_type,
2413 : : struct rte_flow_error *error)
2414 : : {
2415 : : int mp_reformat_ix = mlx5_multi_pattern_reformat_to_index(refmt_type);
2416 : : struct mlx5dr_action_reformat_header hdr;
2417 : : bool shared_rfmt = false;
2418 : : int ret;
2419 : :
2420 : : MLX5_ASSERT(at->reformat_off != UINT16_MAX);
2421 [ # # ]: 0 : if (encap_data && encap_data_m)
2422 : : shared_rfmt = true;
2423 : 0 : acts->encap_decap = mlx5_malloc(MLX5_MEM_ZERO,
2424 : : sizeof(*acts->encap_decap) + data_size,
2425 : : 0, SOCKET_ID_ANY);
2426 [ # # ]: 0 : if (!acts->encap_decap)
2427 : 0 : return rte_flow_error_set(error, ENOMEM,
2428 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2429 : : NULL, "no memory for reformat context");
2430 : 0 : acts->encap_decap_pos = at->reformat_off;
2431 : 0 : acts->encap_decap->data_size = data_size;
2432 : 0 : acts->encap_decap->action_type = refmt_type;
2433 [ # # ]: 0 : if (shared_rfmt || mp_reformat_ix < 0) {
2434 : : uint16_t reformat_ix = at->reformat_off;
2435 : : /*
2436 : : * This copy is only needed in non template mode.
2437 : : * In order to create the action later.
2438 : : */
2439 : 0 : memcpy(acts->encap_decap->data, encap_data, data_size);
2440 : 0 : acts->rule_acts[reformat_ix].reformat.data = acts->encap_decap->data;
2441 : 0 : acts->rule_acts[reformat_ix].reformat.offset = 0;
2442 : 0 : acts->encap_decap->shared = true;
2443 : : } else {
2444 : : uint32_t ix;
2445 : 0 : typeof(mp_ctx->reformat[0]) *reformat = mp_ctx->reformat +
2446 : : mp_reformat_ix;
2447 : : mlx5_set_reformat_header(&hdr, encap_data, data_size);
2448 : 0 : ix = reformat->elements_num++;
2449 : 0 : reformat->reformat_hdr[ix] = hdr;
2450 : 0 : acts->rule_acts[at->reformat_off].reformat.hdr_idx = ix;
2451 : 0 : acts->encap_decap->multi_pattern = 1;
2452 : 0 : ret = __flow_hw_act_data_encap_append
2453 : 0 : (priv, acts, (at->actions + reformat_src)->type,
2454 : : reformat_src, at->reformat_off, data_size);
2455 : : if (ret)
2456 : 0 : return -rte_errno;
2457 : : mlx5_multi_pattern_activate(mp_ctx);
2458 : : }
2459 : : return 0;
2460 : : }
2461 : :
2462 : : static int
2463 : 0 : mlx5_tbl_create_reformat_action(struct mlx5_priv *priv,
2464 : : const struct rte_flow_template_table_attr *table_attr,
2465 : : struct mlx5_hw_actions *acts,
2466 : : struct rte_flow_actions_template *at,
2467 : : uint8_t *encap_data,
2468 : : size_t data_size,
2469 : : enum mlx5dr_action_type refmt_type)
2470 : : {
2471 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2472 : : bool unified_fdb = is_unified_fdb(priv);
2473 : 0 : enum mlx5dr_table_type tbl_type = get_mlx5dr_table_type(attr, table_attr->specialize,
2474 : : unified_fdb);
2475 : : struct mlx5dr_action_reformat_header hdr;
2476 : :
2477 : : mlx5_set_reformat_header(&hdr, encap_data, data_size);
2478 : 0 : uint16_t reformat_ix = at->reformat_off;
2479 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][tbl_type] |
2480 : : MLX5DR_ACTION_FLAG_SHARED;
2481 : :
2482 : 0 : acts->encap_decap->action = mlx5dr_action_create_reformat(priv->dr_ctx, refmt_type,
2483 : : 1, &hdr, 0, flags);
2484 [ # # ]: 0 : if (!acts->encap_decap->action)
2485 : 0 : return -rte_errno;
2486 : 0 : acts->rule_acts[reformat_ix].action = acts->encap_decap->action;
2487 : 0 : return 0;
2488 : : }
2489 : :
2490 : : static int
2491 : 0 : mlx5_tbl_translate_modify_header(struct rte_eth_dev *dev,
2492 : : const struct mlx5_flow_template_table_cfg *cfg,
2493 : : struct mlx5_hw_actions *acts,
2494 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
2495 : : struct mlx5_hw_modify_header_action *mhdr,
2496 : : struct rte_flow_error *error)
2497 : : {
2498 : 0 : uint16_t mhdr_ix = mhdr->pos;
2499 : : struct mlx5dr_action_mh_pattern pattern = {
2500 : 0 : .sz = sizeof(struct mlx5_modification_cmd) * mhdr->mhdr_cmds_num
2501 : : };
2502 : :
2503 : 0 : int ret = flow_hw_validate_compiled_modify_field(dev, cfg, mhdr, error);
2504 [ # # ]: 0 : if (ret) {
2505 : : __flow_hw_action_template_destroy(dev, acts);
2506 : 0 : return ret;
2507 : : }
2508 : 0 : acts->mhdr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*acts->mhdr),
2509 : : 0, SOCKET_ID_ANY);
2510 [ # # ]: 0 : if (!acts->mhdr)
2511 : 0 : return rte_flow_error_set(error, ENOMEM,
2512 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2513 : : NULL, "translate modify_header: no memory for modify header context");
2514 : : rte_memcpy(acts->mhdr, mhdr, sizeof(*mhdr));
2515 [ # # ]: 0 : if (!mhdr->shared) {
2516 : 0 : pattern.data = (rte_be64_t *)acts->mhdr->mhdr_cmds;
2517 : : typeof(mp_ctx->mh) *mh = &mp_ctx->mh;
2518 : 0 : uint32_t idx = mh->elements_num;
2519 : 0 : mh->pattern[mh->elements_num++] = pattern;
2520 : 0 : acts->mhdr->multi_pattern = 1;
2521 : 0 : acts->rule_acts[mhdr_ix].modify_header.pattern_idx = idx;
2522 : : mlx5_multi_pattern_activate(mp_ctx);
2523 : : }
2524 : : return 0;
2525 : : }
2526 : :
2527 : : static int
2528 : 0 : mlx5_tbl_ensure_shared_modify_header(struct rte_eth_dev *dev,
2529 : : const struct mlx5_flow_template_table_cfg *cfg,
2530 : : struct mlx5_hw_actions *acts,
2531 : : struct rte_flow_error *error)
2532 : : {
2533 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2534 : : bool unified_fdb = is_unified_fdb(priv);
2535 : : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2536 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2537 : 0 : enum mlx5dr_table_type tbl_type = get_mlx5dr_table_type(attr, table_attr->specialize,
2538 : : unified_fdb);
2539 : : struct mlx5dr_action_mh_pattern pattern;
2540 : :
2541 [ # # ]: 0 : if (!acts->mhdr)
2542 : 0 : return rte_flow_error_set(error, EINVAL,
2543 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2544 : : "translate modify_header: mhdr is NULL");
2545 : :
2546 : 0 : pattern.sz = sizeof(struct mlx5_modification_cmd) * acts->mhdr->mhdr_cmds_num;
2547 : 0 : uint16_t mhdr_ix = acts->mhdr->pos;
2548 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][tbl_type] | MLX5DR_ACTION_FLAG_SHARED;
2549 : :
2550 : 0 : pattern.data = (rte_be64_t *)acts->mhdr->mhdr_cmds;
2551 : 0 : acts->mhdr->action = mlx5dr_action_create_modify_header(priv->dr_ctx, 1,
2552 : : &pattern, 0, flags);
2553 [ # # ]: 0 : if (!acts->mhdr->action)
2554 : 0 : return rte_flow_error_set(error, rte_errno,
2555 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2556 : : "translate modify_header: failed to create DR action");
2557 : 0 : acts->rule_acts[mhdr_ix].action = acts->mhdr->action;
2558 : 0 : return 0;
2559 : : }
2560 : :
2561 : : static int
2562 : 0 : mlx5_create_ipv6_ext_reformat(struct rte_eth_dev *dev,
2563 : : const struct mlx5_flow_template_table_cfg *cfg,
2564 : : struct mlx5_hw_actions *acts,
2565 : : struct rte_flow_actions_template *at,
2566 : : uint8_t *push_data, uint8_t *push_data_m,
2567 : : size_t push_size, uint16_t recom_src,
2568 : : enum mlx5dr_action_type recom_type)
2569 : : {
2570 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2571 : : bool unified_fdb = is_unified_fdb(priv);
2572 : : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2573 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2574 : : enum mlx5dr_table_type type =
2575 : 0 : get_mlx5dr_table_type(attr, table_attr->specialize, unified_fdb);
2576 : : struct mlx5_action_construct_data *act_data;
2577 : 0 : struct mlx5dr_action_reformat_header hdr = {0};
2578 : : uint32_t flag, bulk = 0;
2579 : :
2580 : 0 : flag = mlx5_hw_act_flag[!!attr->group][type];
2581 : 0 : acts->push_remove = mlx5_malloc(MLX5_MEM_ZERO,
2582 : : sizeof(*acts->push_remove) + push_size,
2583 : : 0, SOCKET_ID_ANY);
2584 [ # # ]: 0 : if (!acts->push_remove)
2585 : : return -ENOMEM;
2586 : :
2587 [ # # # ]: 0 : switch (recom_type) {
2588 : 0 : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
2589 [ # # ]: 0 : if (!push_data || !push_size)
2590 : 0 : goto err1;
2591 [ # # ]: 0 : if (!push_data_m) {
2592 [ # # ]: 0 : bulk = rte_log2_u32(table_attr->nb_flows);
2593 : : } else {
2594 : 0 : flag |= MLX5DR_ACTION_FLAG_SHARED;
2595 : 0 : acts->push_remove->shared = 1;
2596 : : }
2597 : 0 : acts->push_remove->data_size = push_size;
2598 : 0 : memcpy(acts->push_remove->data, push_data, push_size);
2599 : 0 : hdr.data = push_data;
2600 : 0 : hdr.sz = push_size;
2601 : 0 : break;
2602 : 0 : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
2603 : 0 : flag |= MLX5DR_ACTION_FLAG_SHARED;
2604 : 0 : acts->push_remove->shared = 1;
2605 : 0 : break;
2606 : : default:
2607 : : break;
2608 : : }
2609 : :
2610 : 0 : acts->push_remove->action =
2611 : 0 : mlx5dr_action_create_reformat_ipv6_ext(priv->dr_ctx,
2612 : : recom_type, &hdr, bulk, flag);
2613 [ # # ]: 0 : if (!acts->push_remove->action)
2614 : 0 : goto err1;
2615 : 0 : acts->rule_acts[at->recom_off].action = acts->push_remove->action;
2616 : 0 : acts->rule_acts[at->recom_off].ipv6_ext.header = acts->push_remove->data;
2617 : 0 : acts->rule_acts[at->recom_off].ipv6_ext.offset = 0;
2618 : 0 : acts->push_remove_pos = at->recom_off;
2619 [ # # ]: 0 : if (!acts->push_remove->shared) {
2620 : 0 : act_data = __flow_hw_act_data_push_append(dev, acts,
2621 : : RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH,
2622 : : recom_src, at->recom_off, push_size);
2623 : : if (!act_data)
2624 : 0 : goto err;
2625 : : }
2626 : : return 0;
2627 : : err:
2628 [ # # ]: 0 : if (acts->push_remove->action)
2629 : 0 : mlx5dr_action_destroy(acts->push_remove->action);
2630 : 0 : err1:
2631 [ # # ]: 0 : if (acts->push_remove) {
2632 : 0 : mlx5_free(acts->push_remove);
2633 : 0 : acts->push_remove = NULL;
2634 : : }
2635 : : return -EINVAL;
2636 : : }
2637 : :
2638 : : static bool
2639 : : is_indirect_action_type_supported_root(const enum rte_flow_action_type type)
2640 : : {
2641 : : switch (type) {
2642 : : case RTE_FLOW_ACTION_TYPE_COUNT:
2643 : : case RTE_FLOW_ACTION_TYPE_AGE:
2644 : : return mlx5dr_action_counter_root_is_supported();
2645 : : default:
2646 : : return false;
2647 : : }
2648 : : }
2649 : :
2650 : : /**
2651 : : * Translate rte_flow actions to DR action.
2652 : : *
2653 : : * As the action template has already indicated the actions. Translate
2654 : : * the rte_flow actions to DR action if possbile. So in flow create
2655 : : * stage we will save cycles from handing the actions' organizing.
2656 : : * For the actions with limited information, need to add these to a
2657 : : * list.
2658 : : *
2659 : : * @param[in] dev
2660 : : * Pointer to the rte_eth_dev structure.
2661 : : * @param[in] cfg
2662 : : * Pointer to the table configuration.
2663 : : * @param[in/out] acts
2664 : : * Pointer to the template HW steering DR actions.
2665 : : * @param[in] at
2666 : : * Action template.
2667 : : * @param[in] nt_mode
2668 : : * Non template rule translate.
2669 : : * @param[out] error
2670 : : * Pointer to error structure.
2671 : : *
2672 : : * @return
2673 : : * 0 on success, a negative errno otherwise and rte_errno is set.
2674 : : */
2675 : : static int
2676 : 0 : __flow_hw_translate_actions_template(struct rte_eth_dev *dev,
2677 : : const struct mlx5_flow_template_table_cfg *cfg,
2678 : : struct mlx5_hw_actions *acts,
2679 : : struct rte_flow_actions_template *at,
2680 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
2681 : : bool nt_mode,
2682 : : struct rte_flow_error *error)
2683 : : {
2684 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2685 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
2686 : 0 : const struct rte_flow_template_table_attr *table_attr = &cfg->attr;
2687 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
2688 : 0 : struct rte_flow_action *actions = at->actions;
2689 : 0 : struct rte_flow_action *masks = at->masks;
2690 : : enum mlx5dr_action_type refmt_type = MLX5DR_ACTION_TYP_LAST;
2691 : : enum mlx5dr_action_type recom_type = MLX5DR_ACTION_TYP_LAST;
2692 : : const struct rte_flow_action_raw_encap *raw_encap_data;
2693 : : const struct rte_flow_action_ipv6_ext_push *ipv6_ext_data;
2694 : : uint16_t reformat_src = 0, recom_src = 0;
2695 : 0 : uint8_t converted_encap_data[MLX5_ENCAP_MAX_LEN] = { 0 };
2696 : : uint8_t *encap_data = NULL, *encap_data_m = NULL;
2697 : : uint8_t *push_data = NULL, *push_data_m = NULL;
2698 : 0 : size_t data_size = 0, push_size = 0;
2699 : : struct mlx5_hw_modify_header_action mhdr = { 0 };
2700 : 0 : struct rte_flow_error sub_error = {
2701 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
2702 : : .cause = NULL,
2703 : : .message = NULL,
2704 : : };
2705 : : bool actions_end = false;
2706 : : uint32_t type;
2707 : : bool reformat_used = false;
2708 : : bool recom_used = false;
2709 : : unsigned int of_vlan_offset;
2710 : : uint32_t ct_idx;
2711 : : int ret, err;
2712 : 0 : bool is_root = mlx5_group_id_is_root(cfg->attr.flow_attr.group);
2713 : : bool unified_fdb = is_unified_fdb(priv);
2714 : : struct mlx5dr_action *dr_action = NULL;
2715 : :
2716 : : flow_hw_modify_field_init(&mhdr, at);
2717 : 0 : type = get_mlx5dr_table_type(attr, cfg->attr.specialize, unified_fdb);
2718 [ # # ]: 0 : for (; !actions_end; actions++, masks++) {
2719 : 0 : uint64_t pos = actions - at->actions;
2720 : 0 : uint16_t src_pos = pos - at->src_off[pos];
2721 : 0 : uint16_t dr_pos = at->dr_off[pos];
2722 : :
2723 [ # # # # : 0 : switch ((int)actions->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2724 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
2725 [ # # ]: 0 : if (is_root) {
2726 : 0 : DRV_LOG(ERR, "Indirect action is not supported in root table.");
2727 : 0 : goto err;
2728 : : }
2729 : 0 : ret = table_template_translate_indirect_list
2730 : : (dev, actions, masks, acts, src_pos, dr_pos);
2731 [ # # ]: 0 : if (ret)
2732 : 0 : goto err;
2733 : : break;
2734 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
2735 [ # # ]: 0 : if (is_root && !is_indirect_action_type_supported_root(masks->type)) {
2736 : 0 : DRV_LOG(ERR, "Indirect action type (%d) is not supported on root.",
2737 : : masks->type);
2738 : 0 : goto err;
2739 : : }
2740 [ # # # # ]: 0 : if (actions->conf && masks->conf) {
2741 [ # # # # : 0 : if (flow_hw_shared_action_translate(dev, actions, acts,
# # # # ]
2742 : : src_pos, dr_pos, &sub_error))
2743 : 0 : goto err;
2744 : 0 : } else if (__flow_hw_act_data_indirect_append
2745 : : (priv, acts, RTE_FLOW_ACTION_TYPE_INDIRECT,
2746 : : masks->type, src_pos, dr_pos)){
2747 : 0 : goto err;
2748 : : }
2749 : : break;
2750 : : case RTE_FLOW_ACTION_TYPE_VOID:
2751 : : break;
2752 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
2753 : 0 : dr_action = mlx5_hws_global_action_drop_get(priv, type, is_root);
2754 [ # # ]: 0 : if (dr_action == NULL) {
2755 : 0 : DRV_LOG(ERR, "port %u failed to allocate drop action",
2756 : : priv->dev_data->port_id);
2757 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2758 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2759 : : "failed to allocate drop action");
2760 : 0 : goto err;
2761 : : }
2762 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2763 : 0 : break;
2764 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
2765 [ # # ]: 0 : if (is_root) {
2766 : 0 : DRV_LOG(ERR, "Port representor is not supported in root table.");
2767 : 0 : goto err;
2768 : : }
2769 : 0 : dr_action = mlx5_hws_global_action_def_miss_get(priv, type, is_root);
2770 [ # # ]: 0 : if (dr_action == NULL) {
2771 : 0 : DRV_LOG(ERR, "port %u failed to allocate port representor action",
2772 : : priv->dev_data->port_id);
2773 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2774 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2775 : : "failed to allocate port representor action");
2776 : 0 : goto err;
2777 : : }
2778 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2779 : 0 : break;
2780 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
2781 : 0 : dr_action = mlx5_hws_global_action_tag_get(priv, type, is_root);
2782 [ # # ]: 0 : if (dr_action == NULL) {
2783 : 0 : DRV_LOG(ERR, "port %u failed to allocate flag action",
2784 : : priv->dev_data->port_id);
2785 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2786 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2787 : : "failed to allocate flag action");
2788 : 0 : goto err;
2789 : : }
2790 : 0 : acts->mark = true;
2791 : 0 : acts->rule_acts[dr_pos].tag.value =
2792 : : mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
2793 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2794 : 0 : rte_atomic_fetch_add_explicit(&priv->hws_mark_refcnt, 1,
2795 : : rte_memory_order_relaxed);
2796 : 0 : mlx5_flow_hw_rxq_flag_set(dev, true);
2797 : 0 : break;
2798 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
2799 : 0 : dr_action = mlx5_hws_global_action_tag_get(priv, type, is_root);
2800 [ # # ]: 0 : if (dr_action == NULL) {
2801 : 0 : DRV_LOG(ERR, "port %u failed to allocate mark action",
2802 : : priv->dev_data->port_id);
2803 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2804 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2805 : : "failed to allocate mark action");
2806 : 0 : goto err;
2807 : : }
2808 : 0 : acts->mark = true;
2809 [ # # ]: 0 : if (masks->conf &&
2810 : : ((const struct rte_flow_action_mark *)
2811 [ # # ]: 0 : masks->conf)->id)
2812 : 0 : acts->rule_acts[dr_pos].tag.value =
2813 : 0 : mlx5_flow_mark_set
2814 : : (((const struct rte_flow_action_mark *)
2815 : 0 : (actions->conf))->id);
2816 : 0 : else if (__flow_hw_act_data_general_append(priv, acts,
2817 : : actions->type,
2818 : : src_pos, dr_pos))
2819 : 0 : goto err;
2820 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2821 : 0 : rte_atomic_fetch_add_explicit(&priv->hws_mark_refcnt, 1,
2822 : : rte_memory_order_relaxed);
2823 : 0 : mlx5_flow_hw_rxq_flag_set(dev, true);
2824 : 0 : break;
2825 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
2826 : 0 : dr_action = mlx5_hws_global_action_push_vlan_get(priv, type, is_root);
2827 [ # # ]: 0 : if (dr_action == NULL) {
2828 : 0 : DRV_LOG(ERR, "port %u failed to allocate push VLAN action",
2829 : : priv->dev_data->port_id);
2830 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2831 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2832 : : "failed to allocate push VLAN action");
2833 : 0 : goto err;
2834 : : }
2835 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2836 [ # # # # ]: 0 : if (is_template_masked_push_vlan(masks->conf))
2837 : 0 : acts->rule_acts[dr_pos].push_vlan.vlan_hdr =
2838 : 0 : vlan_hdr_to_be32(actions);
2839 : 0 : else if (__flow_hw_act_data_general_append
2840 : : (priv, acts, actions->type,
2841 : : src_pos, dr_pos))
2842 : 0 : goto err;
2843 : : of_vlan_offset = is_of_vlan_pcp_present(actions) ?
2844 [ # # ]: 0 : MLX5_HW_VLAN_PUSH_PCP_IDX :
2845 : : MLX5_HW_VLAN_PUSH_VID_IDX;
2846 : 0 : actions += of_vlan_offset;
2847 : 0 : masks += of_vlan_offset;
2848 : 0 : break;
2849 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
2850 : 0 : dr_action = mlx5_hws_global_action_pop_vlan_get(priv, type, is_root);
2851 [ # # ]: 0 : if (dr_action == NULL) {
2852 : 0 : DRV_LOG(ERR, "port %u failed to allocate pop VLAN action",
2853 : : priv->dev_data->port_id);
2854 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
2855 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
2856 : : "failed to allocate pop VLAN action");
2857 : 0 : goto err;
2858 : : }
2859 : 0 : acts->rule_acts[dr_pos].action = dr_action;
2860 : 0 : break;
2861 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
2862 [ # # ]: 0 : if (masks->conf &&
2863 : : ((const struct rte_flow_action_jump *)
2864 [ # # ]: 0 : masks->conf)->group) {
2865 : 0 : uint32_t jump_group =
2866 : : ((const struct rte_flow_action_jump *)
2867 : 0 : actions->conf)->group;
2868 : 0 : acts->jump = flow_hw_jump_action_register
2869 : : (dev, cfg, jump_group, &sub_error);
2870 [ # # ]: 0 : if (!acts->jump)
2871 : 0 : goto err;
2872 : 0 : acts->rule_acts[dr_pos].action = (!!attr->group) ?
2873 [ # # ]: 0 : acts->jump->hws_action :
2874 : : acts->jump->root_action;
2875 : : } else if (__flow_hw_act_data_general_append
2876 : : (priv, acts, actions->type,
2877 : : src_pos, dr_pos)){
2878 : 0 : goto err;
2879 : : }
2880 : : break;
2881 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
2882 [ # # ]: 0 : if (masks->conf &&
2883 : : ((const struct rte_flow_action_queue *)
2884 [ # # ]: 0 : masks->conf)->index) {
2885 : 0 : acts->tir = flow_hw_tir_action_register
2886 : 0 : (dev, mlx5_hw_act_flag[!!attr->group][type],
2887 : : actions);
2888 [ # # ]: 0 : if (!acts->tir)
2889 : 0 : goto err;
2890 : 0 : acts->rule_acts[dr_pos].action =
2891 : 0 : acts->tir->action;
2892 : : } else if (__flow_hw_act_data_general_append
2893 : : (priv, acts, actions->type,
2894 : : src_pos, dr_pos)) {
2895 : 0 : goto err;
2896 : : }
2897 : : break;
2898 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
2899 [ # # # # ]: 0 : if (actions->conf && masks->conf) {
2900 : 0 : acts->tir = flow_hw_tir_action_register
2901 : 0 : (dev, mlx5_hw_act_flag[!!attr->group][type],
2902 : : actions);
2903 [ # # ]: 0 : if (!acts->tir)
2904 : 0 : goto err;
2905 : 0 : acts->rule_acts[dr_pos].action =
2906 : 0 : acts->tir->action;
2907 : : } else if (__flow_hw_act_data_general_append
2908 : : (priv, acts, actions->type,
2909 : : src_pos, dr_pos)) {
2910 : 0 : goto err;
2911 : : }
2912 : : break;
2913 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2914 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2915 : : MLX5_ASSERT(!reformat_used);
2916 : 0 : ret = translate_l2_encap_action(actions, masks, converted_encap_data,
2917 : : &data_size, error);
2918 [ # # ]: 0 : if (ret < 0)
2919 : 0 : goto err;
2920 : : /* If masked action, then use converted encap data for shared action. */
2921 [ # # ]: 0 : if (ret > 0) {
2922 : : encap_data = converted_encap_data;
2923 : : encap_data_m = converted_encap_data;
2924 : : }
2925 : : reformat_used = true;
2926 : : reformat_src = src_pos;
2927 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
2928 : : break;
2929 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2930 : 0 : raw_encap_data =
2931 : : (const struct rte_flow_action_raw_encap *)
2932 : : masks->conf;
2933 [ # # ]: 0 : if (raw_encap_data)
2934 : 0 : encap_data_m = raw_encap_data->data;
2935 : 0 : raw_encap_data =
2936 : : (const struct rte_flow_action_raw_encap *)
2937 : : actions->conf;
2938 : 0 : encap_data = raw_encap_data->data;
2939 : 0 : data_size = raw_encap_data->size;
2940 [ # # ]: 0 : if (reformat_used) {
2941 : : refmt_type = data_size <
2942 : : MLX5_ENCAPSULATION_DECISION_SIZE ?
2943 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2 :
2944 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
2945 : : } else {
2946 : : reformat_used = true;
2947 : : refmt_type =
2948 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
2949 : : }
2950 : : reformat_src = src_pos;
2951 : : break;
2952 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
2953 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
2954 : : MLX5_ASSERT(!reformat_used);
2955 : : reformat_used = true;
2956 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
2957 : 0 : break;
2958 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
2959 : : reformat_used = true;
2960 : : refmt_type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
2961 : 0 : break;
2962 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
2963 [ # # ]: 0 : if (!hca_attr->flex.query_match_sample_info ||
2964 : 0 : !hca_attr->flex.parse_graph_anchor ||
2965 [ # # ]: 0 : !priv->sh->srh_flex_parser.flex.mapnum) {
2966 : 0 : DRV_LOG(ERR, "SRv6 anchor is not supported.");
2967 : 0 : goto err;
2968 : : }
2969 : : MLX5_ASSERT(!recom_used && !recom_type);
2970 : : recom_used = true;
2971 : : recom_type = MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT;
2972 : 0 : ipv6_ext_data =
2973 : : (const struct rte_flow_action_ipv6_ext_push *)masks->conf;
2974 [ # # ]: 0 : if (ipv6_ext_data)
2975 : 0 : push_data_m = ipv6_ext_data->data;
2976 : 0 : ipv6_ext_data =
2977 : : (const struct rte_flow_action_ipv6_ext_push *)actions->conf;
2978 [ # # ]: 0 : if (ipv6_ext_data) {
2979 : 0 : push_data = ipv6_ext_data->data;
2980 : 0 : push_size = ipv6_ext_data->size;
2981 : : }
2982 : : recom_src = src_pos;
2983 : : break;
2984 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_REMOVE:
2985 [ # # ]: 0 : if (!hca_attr->flex.query_match_sample_info ||
2986 : 0 : !hca_attr->flex.parse_graph_anchor ||
2987 [ # # ]: 0 : !priv->sh->srh_flex_parser.flex.mapnum) {
2988 : 0 : DRV_LOG(ERR, "SRv6 anchor is not supported.");
2989 : 0 : goto err;
2990 : : }
2991 : : recom_used = true;
2992 : : recom_type = MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT;
2993 : : break;
2994 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
2995 [ # # ]: 0 : if (is_root) {
2996 : 0 : rte_flow_error_set(&sub_error, ENOTSUP,
2997 : : RTE_FLOW_ERROR_TYPE_ACTION,
2998 : : NULL,
2999 : : "Send to kernel action on root table is not supported in HW steering mode");
3000 : 0 : goto err;
3001 : : }
3002 : 0 : dr_action = mlx5_hws_global_action_send_to_kernel_get(priv,
3003 : : type,
3004 : : MLX5_HW_LOWEST_PRIO_ROOT);
3005 [ # # ]: 0 : if (dr_action == NULL) {
3006 : 0 : DRV_LOG(ERR, "port %u failed to allocate send to kernel action",
3007 : : priv->dev_data->port_id);
3008 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3009 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3010 : : "failed to allocate send to kernel action");
3011 : 0 : goto err;
3012 : : }
3013 : 0 : acts->rule_acts[dr_pos].action = dr_action;
3014 : 0 : break;
3015 [ # # ]: 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3016 : : err = flow_hw_modify_field_compile(dev, attr, actions,
3017 : : masks, acts, &mhdr,
3018 : : src_pos, &sub_error);
3019 [ # # ]: 0 : if (err)
3020 : 0 : goto err;
3021 : : break;
3022 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3023 [ # # ]: 0 : if (flow_hw_represented_port_compile
3024 : : (dev, attr, actions,
3025 : : masks, acts, src_pos, dr_pos, &sub_error))
3026 : 0 : goto err;
3027 : : break;
3028 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
3029 [ # # ]: 0 : if (is_root && !mlx5dr_action_counter_root_is_supported()) {
3030 : 0 : rte_flow_error_set(&sub_error, ENOTSUP,
3031 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3032 : : "Age action is not supported on group 0");
3033 : 0 : goto err;
3034 : : }
3035 : : if (__flow_hw_act_data_general_append(priv, acts,
3036 : : actions->type,
3037 : : src_pos,
3038 : : dr_pos))
3039 : 0 : goto err;
3040 : : break;
3041 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
3042 [ # # ]: 0 : if (is_root && !mlx5dr_action_counter_root_is_supported()) {
3043 : 0 : rte_flow_error_set(&sub_error, ENOTSUP,
3044 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3045 : : "Count action is not supported on root table");
3046 : 0 : goto err;
3047 : : }
3048 [ # # ]: 0 : if ((at->action_flags & MLX5_FLOW_ACTION_AGE) ||
3049 : : (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE))
3050 : : /*
3051 : : * When both COUNT and AGE are requested, it is
3052 : : * saved as AGE action which creates also the
3053 : : * counter.
3054 : : */
3055 : : break;
3056 [ # # ]: 0 : if (masks->conf &&
3057 : : ((const struct rte_flow_action_count *)
3058 [ # # ]: 0 : masks->conf)->id) {
3059 [ # # ]: 0 : err = flow_hw_cnt_compile(dev, dr_pos, acts, is_root);
3060 : : if (err)
3061 : 0 : goto err;
3062 : : } else if (__flow_hw_act_data_general_append
3063 : : (priv, acts, actions->type,
3064 : : src_pos, dr_pos)) {
3065 : 0 : goto err;
3066 : : }
3067 : : break;
3068 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
3069 [ # # ]: 0 : if (masks->conf) {
3070 : 0 : ct_idx = MLX5_INDIRECT_ACTION_IDX_GET(actions->conf);
3071 : : if (flow_hw_ct_compile(dev, MLX5_HW_INV_QUEUE, ct_idx,
3072 : 0 : &acts->rule_acts[dr_pos]))
3073 : 0 : goto err;
3074 : : } else if (__flow_hw_act_data_general_append
3075 : : (priv, acts, actions->type,
3076 : : src_pos, dr_pos)) {
3077 : 0 : goto err;
3078 : : }
3079 : : break;
3080 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
3081 [ # # # # ]: 0 : if (actions->conf && masks->conf &&
3082 : : ((const struct rte_flow_action_meter_mark *)
3083 [ # # ]: 0 : masks->conf)->profile) {
3084 : : err = flow_hw_meter_mark_compile(dev,
3085 : : dr_pos, actions,
3086 : 0 : acts->rule_acts,
3087 : : &acts->mtr_id,
3088 : : MLX5_HW_INV_QUEUE,
3089 : : &sub_error);
3090 : : if (err)
3091 : 0 : goto err;
3092 : : } else if (__flow_hw_act_data_general_append(priv, acts,
3093 : : actions->type,
3094 : : src_pos,
3095 : : dr_pos))
3096 : 0 : goto err;
3097 : : break;
3098 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
3099 : 0 : dr_action = mlx5_hws_global_action_def_miss_get(priv, type, is_root);
3100 [ # # ]: 0 : if (dr_action == NULL) {
3101 : 0 : DRV_LOG(ERR, "port %u failed to allocate default miss action",
3102 : : priv->dev_data->port_id);
3103 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3104 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3105 : : "failed to allocate default miss action");
3106 : 0 : goto err;
3107 : : }
3108 : 0 : acts->rule_acts[dr_pos].action = dr_action;
3109 : 0 : break;
3110 : 0 : case RTE_FLOW_ACTION_TYPE_NAT64:
3111 [ # # ]: 0 : if (masks->conf &&
3112 [ # # ]: 0 : ((const struct rte_flow_action_nat64 *)masks->conf)->type) {
3113 : 0 : const struct rte_flow_action_nat64 *nat64_c =
3114 : : (const struct rte_flow_action_nat64 *)actions->conf;
3115 : 0 : dr_action = mlx5_hws_global_action_nat64_get(priv,
3116 : : type,
3117 : 0 : nat64_c->type);
3118 [ # # ]: 0 : if (dr_action == NULL) {
3119 : 0 : DRV_LOG(ERR, "port %u failed to allocate NAT64 action",
3120 : : priv->dev_data->port_id);
3121 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3122 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3123 : : "failed to allocate NAT64 action");
3124 : 0 : goto err;
3125 : : }
3126 : 0 : acts->rule_acts[dr_pos].action = dr_action;
3127 : 0 : break;
3128 : : }
3129 : 0 : acts->nat64[RTE_FLOW_NAT64_6TO4] = mlx5_hws_global_action_nat64_get(priv,
3130 : : type,
3131 : : RTE_FLOW_NAT64_6TO4);
3132 : 0 : acts->nat64[RTE_FLOW_NAT64_4TO6] = mlx5_hws_global_action_nat64_get(priv,
3133 : : type,
3134 : : RTE_FLOW_NAT64_4TO6);
3135 [ # # # # ]: 0 : if (!acts->nat64[RTE_FLOW_NAT64_6TO4] ||
3136 : : !acts->nat64[RTE_FLOW_NAT64_4TO6]) {
3137 : 0 : DRV_LOG(ERR, "port %u failed to allocate both NAT64 actions",
3138 : : priv->dev_data->port_id);
3139 : 0 : rte_flow_error_set(&sub_error, ENOMEM,
3140 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
3141 : : "failed to allocate both NAT64 actions");
3142 : 0 : goto err;
3143 : : }
3144 : 0 : if (__flow_hw_act_data_general_append(priv, acts,
3145 : : actions->type,
3146 : : src_pos, dr_pos))
3147 : 0 : goto err;
3148 : : break;
3149 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
3150 [ # # ]: 0 : if (masks->conf &&
3151 : : ((const struct rte_flow_action_jump_to_table_index *)
3152 [ # # ]: 0 : masks->conf)->table) {
3153 : 0 : struct rte_flow_template_table *jump_table =
3154 : : ((const struct rte_flow_action_jump_to_table_index *)
3155 : 0 : actions->conf)->table;
3156 : 0 : acts->rule_acts[dr_pos].jump_to_matcher.offset =
3157 : : ((const struct rte_flow_action_jump_to_table_index *)
3158 : 0 : actions->conf)->index;
3159 [ # # ]: 0 : if (likely(!rte_flow_template_table_resizable(dev->data->port_id,
3160 : : &jump_table->cfg.attr))) {
3161 : 0 : acts->rule_acts[dr_pos].action =
3162 : 0 : jump_table->matcher_info[0].jump;
3163 : : } else {
3164 : : uint32_t selector;
3165 : 0 : rte_rwlock_read_lock(&jump_table->matcher_replace_rwlk);
3166 : 0 : selector = jump_table->matcher_selector;
3167 : 0 : acts->rule_acts[dr_pos].action =
3168 : 0 : jump_table->matcher_info[selector].jump;
3169 : : rte_rwlock_read_unlock(&jump_table->matcher_replace_rwlk);
3170 : : }
3171 : : } else if (__flow_hw_act_data_general_append
3172 : : (priv, acts, actions->type,
3173 : : src_pos, dr_pos)){
3174 : 0 : goto err;
3175 : : }
3176 : : break;
3177 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_MIRROR:
3178 : : if (__flow_hw_act_data_general_append(priv, acts,
3179 : : actions->type,
3180 : : src_pos, dr_pos))
3181 : 0 : goto err;
3182 : : break;
3183 : 0 : case RTE_FLOW_ACTION_TYPE_END:
3184 : : actions_end = true;
3185 : 0 : break;
3186 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
3187 : 0 : DRV_LOG(ERR, "RTE_FLOW_ACTION_TYPE_PORT_ID action is not supported. "
3188 : : "Use RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT instead.");
3189 : 0 : goto err;
3190 : : default:
3191 : : break;
3192 : : }
3193 : : }
3194 [ # # ]: 0 : if (mhdr.pos != UINT16_MAX) {
3195 : 0 : ret = mlx5_tbl_translate_modify_header(dev, cfg, acts, mp_ctx, &mhdr, &sub_error);
3196 [ # # ]: 0 : if (ret)
3197 : 0 : goto err;
3198 [ # # # # ]: 0 : if (!nt_mode && mhdr.shared) {
3199 : 0 : ret = mlx5_tbl_ensure_shared_modify_header(dev, cfg, acts, &sub_error);
3200 [ # # ]: 0 : if (ret)
3201 : 0 : goto err;
3202 : : }
3203 : : }
3204 [ # # ]: 0 : if (reformat_used) {
3205 : 0 : ret = mlx5_tbl_translate_reformat(priv, acts, at,
3206 : : encap_data, encap_data_m,
3207 : : mp_ctx, data_size,
3208 : : reformat_src,
3209 : : refmt_type, &sub_error);
3210 [ # # ]: 0 : if (ret)
3211 : 0 : goto err;
3212 [ # # # # ]: 0 : if (!nt_mode && acts->encap_decap->shared) {
3213 : 0 : ret = mlx5_tbl_create_reformat_action(priv, table_attr, acts, at,
3214 : : encap_data, data_size,
3215 : : refmt_type);
3216 [ # # ]: 0 : if (ret)
3217 : 0 : goto err;
3218 : : }
3219 : : }
3220 [ # # ]: 0 : if (recom_used) {
3221 : : MLX5_ASSERT(at->recom_off != UINT16_MAX);
3222 : 0 : ret = mlx5_create_ipv6_ext_reformat(dev, cfg, acts, at, push_data,
3223 : : push_data_m, push_size, recom_src,
3224 : : recom_type);
3225 [ # # ]: 0 : if (ret)
3226 : 0 : goto err;
3227 : : }
3228 : : return 0;
3229 : 0 : err:
3230 : : /* If rte_errno was not initialized and reached error state. */
3231 [ # # ]: 0 : if (!rte_errno)
3232 : 0 : rte_errno = EINVAL;
3233 : 0 : err = rte_errno;
3234 : : __flow_hw_action_template_destroy(dev, acts);
3235 [ # # # # ]: 0 : if (error != NULL && sub_error.type != RTE_FLOW_ERROR_TYPE_NONE) {
3236 : : rte_memcpy(error, &sub_error, sizeof(sub_error));
3237 : 0 : return -EINVAL;
3238 : : }
3239 : 0 : return rte_flow_error_set(error, err,
3240 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3241 : : "fail to create rte table");
3242 : : }
3243 : :
3244 : : /**
3245 : : * Translate rte_flow actions to DR action.
3246 : : *
3247 : : * As the action template has already indicated the actions. Translate
3248 : : * the rte_flow actions to DR action if possible. So in flow create
3249 : : * stage we will save cycles from handing the actions' organizing.
3250 : : * For the actions with limited information, need to add these to a
3251 : : * list.
3252 : : *
3253 : : * @param[in] dev
3254 : : * Pointer to the rte_eth_dev structure.
3255 : : * @param[in] cfg
3256 : : * Pointer to the table configuration.
3257 : : * @param[in/out] acts
3258 : : * Pointer to the template HW steering DR actions.
3259 : : * @param[in] at
3260 : : * Action template.
3261 : : * @param[out] error
3262 : : * Pointer to error structure.
3263 : : *
3264 : : * @return
3265 : : * 0 on success, a negative errno otherwise and rte_errno is set.
3266 : : */
3267 : : static int
3268 : : flow_hw_translate_actions_template(struct rte_eth_dev *dev,
3269 : : const struct mlx5_flow_template_table_cfg *cfg,
3270 : : struct mlx5_hw_actions *acts,
3271 : : struct rte_flow_actions_template *at,
3272 : : struct mlx5_tbl_multi_pattern_ctx *mp_ctx,
3273 : : struct rte_flow_error *error)
3274 : : {
3275 : 0 : return __flow_hw_translate_actions_template(dev, cfg, acts, at, mp_ctx, false, error);
3276 : : }
3277 : :
3278 : : static __rte_always_inline struct mlx5dr_rule_action *
3279 : : flow_hw_get_dr_action_buffer(struct mlx5_priv *priv,
3280 : : struct rte_flow_template_table *table,
3281 : : uint8_t action_template_index,
3282 : : uint32_t queue)
3283 : : {
3284 : 0 : uint32_t offset = action_template_index * priv->nb_queue + queue;
3285 : :
3286 : 0 : return &table->rule_acts[offset].acts[0];
3287 : : }
3288 : :
3289 : : static void
3290 : 0 : flow_hw_populate_rule_acts_caches(struct rte_eth_dev *dev,
3291 : : struct rte_flow_template_table *table,
3292 : : uint8_t at_idx)
3293 : : {
3294 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3295 : : uint32_t q;
3296 : :
3297 [ # # ]: 0 : for (q = 0; q < priv->nb_queue; ++q) {
3298 : : struct mlx5dr_rule_action *rule_acts =
3299 : 0 : flow_hw_get_dr_action_buffer(priv, table, at_idx, q);
3300 : :
3301 [ # # ]: 0 : rte_memcpy(rule_acts, table->ats[at_idx].acts.rule_acts,
3302 : : sizeof(table->ats[at_idx].acts.rule_acts));
3303 : : }
3304 : 0 : }
3305 : :
3306 : : /**
3307 : : * Translate rte_flow actions to DR action.
3308 : : *
3309 : : * @param[in] dev
3310 : : * Pointer to the rte_eth_dev structure.
3311 : : * @param[in] tbl
3312 : : * Pointer to the flow template table.
3313 : : * @param[out] error
3314 : : * Pointer to error structure.
3315 : : *
3316 : : * @return
3317 : : * 0 on success, negative value otherwise and rte_errno is set.
3318 : : */
3319 : : static int
3320 : 0 : flow_hw_translate_all_actions_templates(struct rte_eth_dev *dev,
3321 : : struct rte_flow_template_table *tbl,
3322 : : struct rte_flow_error *error)
3323 : : {
3324 : : int ret;
3325 : : uint32_t i;
3326 : :
3327 [ # # ]: 0 : for (i = 0; i < tbl->nb_action_templates; i++) {
3328 [ # # ]: 0 : if (flow_hw_translate_actions_template(dev, &tbl->cfg,
3329 : : &tbl->ats[i].acts,
3330 : : tbl->ats[i].action_template,
3331 : : &tbl->mpctx, error))
3332 : 0 : goto err;
3333 : 0 : flow_hw_populate_rule_acts_caches(dev, tbl, i);
3334 : : }
3335 [ # # ]: 0 : ret = mlx5_tbl_multi_pattern_process(dev, tbl, &tbl->mpctx.segments[0],
3336 : : rte_log2_u32(tbl->cfg.attr.nb_flows),
3337 : : error);
3338 [ # # ]: 0 : if (ret)
3339 : 0 : goto err;
3340 : : return 0;
3341 : : err:
3342 [ # # ]: 0 : while (i--)
3343 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
3344 : : return -1;
3345 : : }
3346 : :
3347 : : /**
3348 : : * Get shared indirect action.
3349 : : *
3350 : : * @param[in] dev
3351 : : * Pointer to the rte_eth_dev data structure.
3352 : : * @param[in] act_data
3353 : : * Pointer to the recorded action construct data.
3354 : : * @param[in] item_flags
3355 : : * The matcher itme_flags used for RSS lookup.
3356 : : * @param[in] rule_act
3357 : : * Pointer to the shared action's destination rule DR action.
3358 : : *
3359 : : * @return
3360 : : * 0 on success, negative value otherwise and rte_errno is set.
3361 : : */
3362 : : static __rte_always_inline int
3363 : : flow_hw_shared_action_get(struct rte_eth_dev *dev,
3364 : : struct mlx5_action_construct_data *act_data,
3365 : : const uint64_t item_flags,
3366 : : struct mlx5dr_rule_action *rule_act)
3367 : : {
3368 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3369 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
3370 : 0 : uint64_t hash_fields = 0;
3371 : : uint32_t hrxq_idx = 0;
3372 : : struct mlx5_hrxq *hrxq = NULL;
3373 : : int act_type = act_data->type;
3374 : :
3375 : : switch (act_type) {
3376 : : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
3377 : 0 : rss_desc.level = act_data->shared_rss.level;
3378 : 0 : rss_desc.types = act_data->shared_rss.types;
3379 : 0 : rss_desc.symmetric_hash_function = act_data->shared_rss.symmetric_hash_function;
3380 : 0 : mlx5_flow_dv_hashfields_set(item_flags, &rss_desc, &hash_fields);
3381 : 0 : hrxq_idx = mlx5_flow_dv_action_rss_hrxq_lookup
3382 : : (dev, act_data->shared_rss.idx, hash_fields);
3383 [ # # # # : 0 : if (hrxq_idx)
# # # # #
# # # # #
# # # # #
# ]
3384 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
3385 : : hrxq_idx);
3386 [ # # # # : 0 : if (hrxq) {
# # # # #
# # # # #
# # # # #
# ]
3387 : 0 : rule_act->action = hrxq->action;
3388 : : return 0;
3389 : : }
3390 : : break;
3391 : : default:
3392 : : DRV_LOG(WARNING, "Unsupported shared action type:%d",
3393 : : act_data->type);
3394 : : break;
3395 : : }
3396 : : return -1;
3397 : : }
3398 : :
3399 : : static void
3400 : 0 : flow_hw_construct_quota(struct mlx5_priv *priv,
3401 : : struct mlx5dr_rule_action *rule_act, uint32_t qid)
3402 : : {
3403 : 0 : rule_act->action = priv->quota_ctx.dr_action;
3404 : 0 : rule_act->aso_meter.offset = qid - 1;
3405 : 0 : rule_act->aso_meter.init_color =
3406 : : MLX5DR_ACTION_ASO_METER_COLOR_GREEN;
3407 : 0 : }
3408 : :
3409 : : /**
3410 : : * Construct shared indirect action.
3411 : : *
3412 : : * @param[in] dev
3413 : : * Pointer to the rte_eth_dev data structure.
3414 : : * @param[in] queue
3415 : : * The flow creation queue index.
3416 : : * @param[in] action
3417 : : * Pointer to the shared indirect rte_flow action.
3418 : : * @param[in] table
3419 : : * Pointer to the flow table.
3420 : : * @param[in] item_flags
3421 : : * Item flags.
3422 : : * @param[in] action_flags
3423 : : * Actions bit-map detected in this template.
3424 : : * @param[in, out] flow
3425 : : * Pointer to the flow containing the counter.
3426 : : * @param[in] rule_act
3427 : : * Pointer to the shared action's destination rule DR action.
3428 : : *
3429 : : * @return
3430 : : * 0 on success, negative value otherwise and rte_errno is set.
3431 : : */
3432 : : static __rte_always_inline int
3433 : : flow_hw_shared_action_construct(struct rte_eth_dev *dev, uint32_t queue,
3434 : : const struct rte_flow_action *action,
3435 : : struct rte_flow_template_table *table,
3436 : : const uint64_t item_flags, uint64_t action_flags,
3437 : : struct rte_flow_hw *flow,
3438 : : struct mlx5dr_rule_action *rule_act)
3439 : : {
3440 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3441 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
3442 : : struct mlx5_action_construct_data act_data;
3443 : : struct mlx5_shared_action_rss *shared_rss;
3444 : : struct mlx5_aso_mtr *aso_mtr;
3445 : : struct mlx5_age_info *age_info;
3446 : : struct mlx5_hws_age_param *param;
3447 : : struct rte_flow_hw_aux *aux;
3448 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)action->conf;
3449 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3450 : 0 : uint32_t idx = act_idx &
3451 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3452 : : uint32_t *cnt_queue;
3453 : : cnt_id_t age_cnt;
3454 : 0 : bool is_root = mlx5_group_id_is_root(table->grp->group_id);
3455 : :
3456 : : memset(&act_data, 0, sizeof(act_data));
3457 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3458 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
3459 : 0 : act_data.type = MLX5_RTE_FLOW_ACTION_TYPE_RSS;
3460 : 0 : shared_rss = mlx5_ipool_get
3461 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3462 [ # # # # : 0 : if (!shared_rss)
# # # # #
# ]
3463 : : return -1;
3464 : 0 : act_data.shared_rss.idx = idx;
3465 : 0 : act_data.shared_rss.level = shared_rss->origin.level;
3466 : 0 : act_data.shared_rss.types = !shared_rss->origin.types ?
3467 [ # # # # : 0 : RTE_ETH_RSS_IP :
# # # # #
# ]
3468 : : shared_rss->origin.types;
3469 : 0 : act_data.shared_rss.symmetric_hash_function =
3470 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
3471 : :
3472 : : if (flow_hw_shared_action_get
3473 : : (dev, &act_data, item_flags, rule_act))
3474 : : return -1;
3475 : : break;
3476 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3477 [ # # # # : 0 : if (mlx5_hws_cnt_pool_get_action_offset(priv->hws_cpool,
# # # # #
# ]
3478 : : act_idx,
3479 : : &rule_act->action,
3480 : : &rule_act->counter.offset,
3481 : : is_root))
3482 : : return -1;
3483 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3484 : 0 : flow->cnt_id = act_idx;
3485 : : break;
3486 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
3487 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
3488 : : /*
3489 : : * Save the index with the indirect type, to recognize
3490 : : * it in flow destroy.
3491 : : */
3492 : : mlx5_flow_hw_aux_set_age_idx(flow, aux, act_idx);
3493 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX;
3494 [ # # # # : 0 : if (action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT)
# # # # #
# ]
3495 : : /*
3496 : : * The mutual update for idirect AGE & COUNT will be
3497 : : * performed later after we have ID for both of them.
3498 : : */
3499 : : break;
3500 : 0 : age_info = GET_PORT_AGE_INFO(priv);
3501 : 0 : param = mlx5_ipool_get(age_info->ages_ipool, idx);
3502 [ # # # # : 0 : if (param == NULL)
# # # # #
# ]
3503 : : return -1;
3504 [ # # # # : 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
# # # # #
# ]
3505 : : cnt_queue = mlx5_hws_cnt_get_queue(priv, &queue);
3506 [ # # # # : 0 : if (mlx5_hws_cnt_pool_get(priv->hws_cpool, cnt_queue, &age_cnt, idx, 0) < 0)
# # # # #
# ]
3507 : : return -1;
3508 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3509 : 0 : flow->cnt_id = age_cnt;
3510 : 0 : param->nb_cnts++;
3511 : : } else {
3512 : : /*
3513 : : * Get the counter of this indirect AGE or create one
3514 : : * if doesn't exist.
3515 : : */
3516 : : age_cnt = mlx5_hws_age_cnt_get(priv, param, idx);
3517 [ # # # # : 0 : if (age_cnt == 0)
# # # # #
# ]
3518 : : return -1;
3519 : : }
3520 [ # # # # : 0 : if (mlx5_hws_cnt_pool_get_action_offset(priv->hws_cpool,
# # # # #
# ]
3521 : : age_cnt, &rule_act->action,
3522 : : &rule_act->counter.offset, is_root))
3523 : : return -1;
3524 : : break;
3525 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
3526 : : if (flow_hw_ct_compile(dev, queue, idx, rule_act))
3527 : : return -1;
3528 : : break;
3529 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
3530 : : /* Find ASO object. */
3531 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
3532 [ # # # # : 0 : if (!aso_mtr)
# # # # #
# ]
3533 : : return -1;
3534 : 0 : rule_act->action = pool->action;
3535 : 0 : rule_act->aso_meter.offset = aso_mtr->offset;
3536 : : break;
3537 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
3538 : 0 : flow_hw_construct_quota(priv, rule_act, idx);
3539 : : break;
3540 : 0 : default:
3541 : 0 : DRV_LOG(WARNING, "Unsupported shared action type:%d", type);
3542 : : break;
3543 : : }
3544 : : return 0;
3545 : : }
3546 : :
3547 : : static __rte_always_inline int
3548 : : flow_hw_mhdr_cmd_is_nop(const struct mlx5_modification_cmd *cmd)
3549 : : {
3550 : : struct mlx5_modification_cmd cmd_he = {
3551 : 0 : .data0 = rte_be_to_cpu_32(cmd->data0),
3552 : : .data1 = 0,
3553 : : };
3554 : :
3555 : 0 : return cmd_he.action_type == MLX5_MODIFICATION_TYPE_NOP;
3556 : : }
3557 : :
3558 : : /**
3559 : : * Construct flow action array.
3560 : : *
3561 : : * For action template contains dynamic actions, these actions need to
3562 : : * be updated according to the rte_flow action during flow creation.
3563 : : *
3564 : : * @param[in] dev
3565 : : * Pointer to the rte_eth_dev structure.
3566 : : * @param[in] job
3567 : : * Pointer to job descriptor.
3568 : : * @param[in] hw_acts
3569 : : * Pointer to translated actions from template.
3570 : : * @param[in] it_idx
3571 : : * Item template index the action template refer to.
3572 : : * @param[in] actions
3573 : : * Array of rte_flow action need to be checked.
3574 : : * @param[in] rule_acts
3575 : : * Array of DR rule actions to be used during flow creation..
3576 : : * @param[in] acts_num
3577 : : * Pointer to the real acts_num flow has.
3578 : : *
3579 : : * @return
3580 : : * 0 on success, negative value otherwise and rte_errno is set.
3581 : : */
3582 : : static __rte_always_inline int
3583 : : flow_hw_modify_field_construct(struct mlx5_modification_cmd *mhdr_cmd,
3584 : : struct mlx5_action_construct_data *act_data,
3585 : : const struct mlx5_hw_actions *hw_acts,
3586 : : const struct rte_flow_action *action)
3587 : : {
3588 : 0 : const struct rte_flow_action_modify_field *mhdr_action = action->conf;
3589 : 0 : uint8_t values[16] = { 0 };
3590 : : unaligned_uint32_t *value_p;
3591 : : uint32_t i;
3592 : : struct field_modify_info *field;
3593 : :
3594 [ # # # # : 0 : if (!hw_acts->mhdr)
# # # # #
# ]
3595 : : return -1;
3596 [ # # # # : 0 : if (hw_acts->mhdr->shared || act_data->modify_header.shared)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3597 : : return 0;
3598 : : MLX5_ASSERT(mhdr_action->operation == RTE_FLOW_MODIFY_SET ||
3599 : : mhdr_action->operation == RTE_FLOW_MODIFY_ADD);
3600 [ # # # # : 0 : if (mhdr_action->src.field != RTE_FLOW_FIELD_VALUE &&
# # # # #
# ]
3601 : : mhdr_action->src.field != RTE_FLOW_FIELD_POINTER)
3602 : : return 0;
3603 [ # # # # : 0 : if (mhdr_action->src.field == RTE_FLOW_FIELD_VALUE)
# # # # #
# ]
3604 : : rte_memcpy(values, &mhdr_action->src.value, sizeof(values));
3605 : : else
3606 : 0 : rte_memcpy(values, mhdr_action->src.pvalue, sizeof(values));
3607 [ # # # # : 0 : if (mhdr_action->dst.field == RTE_FLOW_FIELD_META ||
# # # # #
# ]
3608 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_TAG ||
# # # # #
# ]
3609 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_METER_COLOR ||
# # # # #
# ]
3610 : : mhdr_action->dst.field == (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
3611 : 0 : uint8_t tag_index = flow_tag_index_get(&mhdr_action->dst);
3612 : :
3613 : : value_p = (unaligned_uint32_t *)values;
3614 [ # # # # : 0 : if (mhdr_action->dst.field == RTE_FLOW_FIELD_TAG &&
# # # # #
# # # # #
# # # # #
# ]
3615 : : tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX)
3616 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(*value_p << 16);
# # # # #
# ]
3617 : : else
3618 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(*value_p);
# # # # #
# ]
3619 [ # # # # : 0 : } else if (mhdr_action->dst.field == RTE_FLOW_FIELD_GTP_PSC_QFI ||
# # # # #
# ]
3620 : : mhdr_action->dst.field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE) {
3621 : : uint32_t tmp;
3622 : :
3623 : : /*
3624 : : * Both QFI and Geneve option type are passed as an uint8_t integer,
3625 : : * but it is accessed through a 2nd least significant byte of a 32-bit
3626 : : * field in modify header command.
3627 : : */
3628 : 0 : tmp = values[0];
3629 : : value_p = (unaligned_uint32_t *)values;
3630 [ # # # # : 0 : *value_p = rte_cpu_to_be_32(tmp << 8);
# # # # #
# ]
3631 : : }
3632 : 0 : i = act_data->modify_header.mhdr_cmds_off;
3633 : 0 : field = act_data->modify_header.field;
3634 : : do {
3635 : : uint32_t off_b;
3636 : : uint32_t mask;
3637 : : uint32_t data;
3638 : : const uint8_t *mask_src;
3639 : :
3640 [ # # # # : 0 : if (i >= act_data->modify_header.mhdr_cmds_end)
# # # # #
# # # # #
# # # # #
# ]
3641 : : return -1;
3642 [ # # # # : 0 : if (flow_hw_mhdr_cmd_is_nop(&mhdr_cmd[i])) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3643 : 0 : ++i;
3644 : 0 : continue;
3645 : : }
3646 : 0 : mask_src = (const uint8_t *)act_data->modify_header.mask;
3647 : 0 : mask = flow_dv_fetch_field(mask_src + field->offset, field->size);
3648 [ # # # # : 0 : if (!mask) {
# # # # #
# # # # #
# # # # #
# ]
3649 : 0 : ++field;
3650 : 0 : continue;
3651 : : }
3652 : 0 : off_b = rte_bsf32(mask);
3653 : 0 : data = flow_dv_fetch_field(values + field->offset, field->size);
3654 : : /*
3655 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
3656 : : * bits left. Shift the data left for IPv6 DSCP
3657 : : */
3658 [ # # # # : 0 : if (field->id == MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS &&
# # # # #
# # # #
# ]
3659 [ # # # # : 0 : mhdr_action->dst.field == RTE_FLOW_FIELD_IPV6_DSCP)
# # ]
3660 : 0 : data <<= MLX5_IPV6_HDR_DSCP_SHIFT;
3661 : 0 : data = (data & mask) >> off_b;
3662 [ # # # # : 0 : mhdr_cmd[i++].data1 = rte_cpu_to_be_32(data);
# # # # #
# # # # #
# # # # #
# ]
3663 : 0 : ++field;
3664 [ # # # # : 0 : } while (field->size);
# # # # #
# # # # #
# # # # #
# ]
3665 : : return 0;
3666 : : }
3667 : :
3668 : : /**
3669 : : * Release any actions allocated for the flow rule during actions construction.
3670 : : *
3671 : : * @param[in] flow
3672 : : * Pointer to flow structure.
3673 : : */
3674 : : static void
3675 : 0 : flow_hw_release_actions(struct rte_eth_dev *dev,
3676 : : uint32_t queue,
3677 : : struct rte_flow_hw *flow)
3678 : : {
3679 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3680 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
3681 [ # # ]: 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
3682 : :
3683 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP)
3684 : 0 : flow_hw_jump_release(dev, flow->jump);
3685 [ # # ]: 0 : else if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ)
3686 : 0 : mlx5_hrxq_obj_release(dev, flow->hrxq);
3687 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID)
3688 : 0 : flow_hw_age_count_release(priv, queue, flow, NULL);
3689 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MTR_ID)
3690 : 0 : mlx5_ipool_free(pool->idx_pool, mlx5_flow_hw_aux_get_mtr_id(flow, aux));
3691 : 0 : }
3692 : :
3693 : : /**
3694 : : * Construct flow action array.
3695 : : *
3696 : : * For action template contains dynamic actions, these actions need to
3697 : : * be updated according to the rte_flow action during flow creation.
3698 : : *
3699 : : * @param[in] dev
3700 : : * Pointer to the rte_eth_dev structure.
3701 : : * @param[in] flow
3702 : : * Pointer to flow structure.
3703 : : * @param[in] ap
3704 : : * Pointer to container for temporarily constructed actions' parameters.
3705 : : * @param[in] hw_acts
3706 : : * Pointer to translated actions from template.
3707 : : * @param[in] items_flags
3708 : : * Item flags.
3709 : : * @param[in] table
3710 : : * Pointer to the template table.
3711 : : * @param[in] actions
3712 : : * Array of rte_flow action need to be checked.
3713 : : * @param[in] rule_acts
3714 : : * Array of DR rule actions to be used during flow creation..
3715 : : * @param[in] acts_num
3716 : : * Pointer to the real acts_num flow has.
3717 : : *
3718 : : * @return
3719 : : * 0 on success, negative value otherwise and rte_errno is set.
3720 : : */
3721 : : static __rte_always_inline int
3722 : : flow_hw_actions_construct(struct rte_eth_dev *dev,
3723 : : struct rte_flow_hw *flow,
3724 : : struct mlx5_flow_hw_action_params *ap,
3725 : : const struct mlx5_hw_action_template *hw_at,
3726 : : uint64_t item_flags,
3727 : : struct rte_flow_template_table *table,
3728 : : const struct rte_flow_action actions[],
3729 : : struct mlx5dr_rule_action *rule_acts,
3730 : : uint32_t queue,
3731 : : struct rte_flow_error *error)
3732 : : {
3733 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3734 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
3735 : : struct mlx5_action_construct_data *act_data;
3736 : 0 : const struct rte_flow_actions_template *at = hw_at->action_template;
3737 : : const struct mlx5_hw_actions *hw_acts = &hw_at->acts;
3738 : : const struct rte_flow_action *action;
3739 : : const struct rte_flow_action_raw_encap *raw_encap_data;
3740 : : const struct rte_flow_action_ipv6_ext_push *ipv6_push;
3741 : : const struct rte_flow_item *enc_item = NULL;
3742 : : const struct rte_flow_action_ethdev *port_action = NULL;
3743 : : const struct rte_flow_action_age *age = NULL;
3744 : : const struct rte_flow_action_nat64 *nat64_c = NULL;
3745 : 0 : struct rte_flow_attr attr = {
3746 : : .ingress = 1,
3747 : : };
3748 : : uint32_t ft_flag;
3749 : : int ret;
3750 : 0 : size_t encap_len = 0;
3751 : : uint32_t age_idx = 0;
3752 : : uint32_t mtr_idx = 0;
3753 : : struct mlx5_aso_mtr *aso_mtr;
3754 : : struct mlx5_multi_pattern_segment *mp_segment = NULL;
3755 : : struct rte_flow_hw_aux *aux;
3756 : 0 : bool is_root = mlx5_group_id_is_root(table->grp->group_id);
3757 : :
3758 : : attr.group = table->grp->group_id;
3759 : 0 : ft_flag = mlx5_hw_act_flag[!!table->grp->group_id][table->type];
3760 : 0 : if (table->type >= MLX5DR_TABLE_TYPE_FDB && table->type < MLX5DR_TABLE_TYPE_MAX) {
3761 : 0 : attr.transfer = 1;
3762 : : attr.ingress = 1;
3763 [ # # # # : 0 : } else if (table->type == MLX5DR_TABLE_TYPE_NIC_TX) {
# # # # #
# ]
3764 : 0 : attr.egress = 1;
3765 : 0 : attr.ingress = 0;
3766 : : } else {
3767 : : attr.ingress = 1;
3768 : : }
3769 [ # # # # : 0 : if (hw_acts->mhdr && hw_acts->mhdr->mhdr_cmds_num > 0 && !hw_acts->mhdr->shared) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3770 : 0 : uint16_t pos = hw_acts->mhdr->pos;
3771 : :
3772 : 0 : mp_segment = mlx5_multi_pattern_segment_find(table, flow->res_idx);
3773 [ # # # # : 0 : if (!mp_segment || !mp_segment->mhdr_action)
# # # # #
# # # # #
# # # # #
# ]
3774 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3775 : : NULL, "No modify header action found");
3776 : 0 : rule_acts[pos].action = mp_segment->mhdr_action;
3777 : : /* offset is relative to DR action */
3778 : 0 : rule_acts[pos].modify_header.offset =
3779 : 0 : flow->res_idx - mp_segment->head_index;
3780 : 0 : rule_acts[pos].modify_header.data =
3781 : 0 : (uint8_t *)ap->mhdr_cmd;
3782 : : MLX5_ASSERT(hw_acts->mhdr->mhdr_cmds_num <= MLX5_MHDR_MAX_CMD);
3783 : 0 : rte_memcpy(ap->mhdr_cmd, hw_acts->mhdr->mhdr_cmds,
3784 [ # # # # : 0 : sizeof(*ap->mhdr_cmd) * hw_acts->mhdr->mhdr_cmds_num);
# # # # #
# ]
3785 : : }
3786 [ # # # # : 0 : LIST_FOREACH(act_data, &hw_acts->act_list, next) {
# # # # #
# ]
3787 : : uint32_t jump_group;
3788 : : uint32_t tag;
3789 : : struct mlx5_hw_jump_action *jump;
3790 : : struct mlx5_hrxq *hrxq;
3791 : : uint32_t ct_idx;
3792 : : cnt_id_t cnt_id;
3793 : : uint32_t *cnt_queue;
3794 : : uint32_t mtr_id;
3795 : : struct rte_flow_template_table *jump_table;
3796 : :
3797 : 0 : action = &actions[act_data->action_src];
3798 : : /*
3799 : : * action template construction replaces
3800 : : * OF_SET_VLAN_VID with MODIFY_FIELD
3801 : : */
3802 : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
3803 : : MLX5_ASSERT(act_data->type ==
3804 : : RTE_FLOW_ACTION_TYPE_MODIFY_FIELD);
3805 : : else
3806 : : MLX5_ASSERT(action->type ==
3807 : : RTE_FLOW_ACTION_TYPE_INDIRECT ||
3808 : : (int)action->type == act_data->type);
3809 [ # # # # : 0 : switch ((int)act_data->type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3810 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT_LIST:
3811 : 0 : act_data->indirect_list_cb(dev, act_data, action,
3812 : 0 : &rule_acts[act_data->action_dst]);
3813 : 0 : break;
3814 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
3815 : 0 : if (flow_hw_shared_action_construct
3816 : : (dev, queue, action, table,
3817 : 0 : item_flags, at->action_flags, flow,
3818 [ # # # # : 0 : &rule_acts[act_data->action_dst]))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3819 : 0 : goto error;
3820 : : break;
3821 : : case RTE_FLOW_ACTION_TYPE_VOID:
3822 : : break;
3823 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
3824 : 0 : tag = mlx5_flow_mark_set
3825 : : (((const struct rte_flow_action_mark *)
3826 : 0 : (action->conf))->id);
3827 : 0 : rule_acts[act_data->action_dst].tag.value = tag;
3828 : 0 : break;
3829 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3830 : 0 : rule_acts[act_data->action_dst].push_vlan.vlan_hdr =
3831 : 0 : vlan_hdr_to_be32(action);
3832 : 0 : break;
3833 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
3834 : 0 : jump_group = ((const struct rte_flow_action_jump *)
3835 : 0 : action->conf)->group;
3836 : 0 : jump = flow_hw_jump_action_register
3837 : 0 : (dev, &table->cfg, jump_group, NULL);
3838 [ # # # # : 0 : if (!jump)
# # # # #
# ]
3839 : 0 : goto error;
3840 : 0 : rule_acts[act_data->action_dst].action =
3841 [ # # # # : 0 : (!!attr.group) ? jump->hws_action : jump->root_action;
# # # # #
# ]
3842 : 0 : flow->jump = jump;
3843 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP;
3844 : 0 : break;
3845 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
3846 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
3847 : 0 : hrxq = flow_hw_tir_action_register(dev, ft_flag, action);
3848 [ # # # # : 0 : if (!hrxq)
# # # # #
# ]
3849 : 0 : goto error;
3850 : 0 : rule_acts[act_data->action_dst].action = hrxq->action;
3851 : 0 : flow->hrxq = hrxq;
3852 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ;
3853 : 0 : break;
3854 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
3855 : 0 : if (flow_hw_shared_action_get
3856 : : (dev, act_data, item_flags,
3857 : 0 : &rule_acts[act_data->action_dst]))
3858 : 0 : goto error;
3859 : : break;
3860 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3861 : 0 : enc_item = ((const struct rte_flow_action_vxlan_encap *)
3862 : 0 : action->conf)->definition;
3863 [ # # # # : 0 : if (mlx5_flow_dv_convert_encap_data(enc_item, ap->encap_data,
# # # # #
# ]
3864 : : &encap_len, NULL))
3865 : 0 : goto error;
3866 : : break;
3867 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3868 : 0 : enc_item = ((const struct rte_flow_action_nvgre_encap *)
3869 : 0 : action->conf)->definition;
3870 [ # # # # : 0 : if (mlx5_flow_dv_convert_encap_data(enc_item, ap->encap_data,
# # # # #
# ]
3871 : : &encap_len, NULL))
3872 : 0 : goto error;
3873 : : break;
3874 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3875 : 0 : raw_encap_data =
3876 : : (const struct rte_flow_action_raw_encap *)
3877 : : action->conf;
3878 : : MLX5_ASSERT(raw_encap_data->size == act_data->encap.len);
3879 [ # # # # : 0 : if (unlikely(act_data->encap.len > MLX5_ENCAP_MAX_LEN))
# # # # #
# ]
3880 : : return -1;
3881 [ # # # # : 0 : rte_memcpy(ap->encap_data, raw_encap_data->data, act_data->encap.len);
# # # # #
# ]
3882 : : break;
3883 : 0 : case RTE_FLOW_ACTION_TYPE_IPV6_EXT_PUSH:
3884 : 0 : ipv6_push =
3885 : : (const struct rte_flow_action_ipv6_ext_push *)action->conf;
3886 : : MLX5_ASSERT(ipv6_push->size == act_data->ipv6_ext.len);
3887 [ # # # # : 0 : if (unlikely(act_data->ipv6_ext.len > MLX5_PUSH_MAX_LEN))
# # # # #
# ]
3888 : : return -1;
3889 [ # # # # : 0 : rte_memcpy(ap->ipv6_push_data, ipv6_push->data,
# # # # #
# ]
3890 : : act_data->ipv6_ext.len);
3891 : : break;
3892 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3893 [ # # # # : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)
# # # # #
# ]
3894 : 0 : ret = flow_hw_set_vlan_vid_construct(dev, ap->mhdr_cmd,
3895 : : act_data,
3896 : : hw_acts,
3897 : : action);
3898 : : else
3899 [ # # # # : 0 : ret = flow_hw_modify_field_construct(ap->mhdr_cmd,
# # # # #
# ]
3900 : : act_data,
3901 : : hw_acts,
3902 : : action);
3903 [ # # # # : 0 : if (ret)
# # # # #
# ]
3904 : 0 : goto error;
3905 : : break;
3906 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3907 : 0 : port_action = action->conf;
3908 [ # # # # : 0 : if (!priv->hw_vport[port_action->port_id])
# # # # #
# ]
3909 : 0 : goto error;
3910 : 0 : rule_acts[act_data->action_dst].action =
3911 : : priv->hw_vport[port_action->port_id];
3912 : 0 : break;
3913 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
3914 : 0 : flow_hw_construct_quota(priv,
3915 : 0 : rule_acts + act_data->action_dst,
3916 : : act_data->shared_meter.id);
3917 : 0 : break;
3918 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
3919 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
3920 : 0 : age = action->conf;
3921 : : /*
3922 : : * First, create the AGE parameter, then create its
3923 : : * counter later:
3924 : : * Regular counter - in next case.
3925 : : * Indirect counter - update it after the loop.
3926 : : */
3927 : 0 : age_idx = mlx5_hws_age_action_create(priv, queue, 0,
3928 : : age,
3929 : : flow->res_idx,
3930 : : error);
3931 [ # # # # : 0 : if (age_idx == 0)
# # # # #
# ]
3932 : 0 : goto error;
3933 : : mlx5_flow_hw_aux_set_age_idx(flow, aux, age_idx);
3934 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX;
3935 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT)
# # # # #
# ]
3936 : : /*
3937 : : * When AGE uses indirect counter, no need to
3938 : : * create counter but need to update it with the
3939 : : * AGE parameter, will be done after the loop.
3940 : : */
3941 : : break;
3942 : : /* Fall-through. */
3943 : : case RTE_FLOW_ACTION_TYPE_COUNT:
3944 : : cnt_queue = mlx5_hws_cnt_get_queue(priv, &queue);
3945 : : ret = mlx5_hws_cnt_pool_get(priv->hws_cpool, cnt_queue, &cnt_id,
3946 : : age_idx, 0);
3947 [ # # # # : 0 : if (ret != 0) {
# # # # #
# ]
3948 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ACTION,
3949 : : action, "Failed to allocate flow counter");
3950 : 0 : goto error;
3951 : : }
3952 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
3953 : : (priv->hws_cpool,
3954 : : cnt_id,
3955 : : &rule_acts[act_data->action_dst].action,
3956 [ # # # # : 0 : &rule_acts[act_data->action_dst].counter.offset,
# # # # #
# ]
3957 : : is_root
3958 : : );
3959 : : if (ret != 0)
3960 : : goto error;
3961 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3962 : 0 : flow->cnt_id = cnt_id;
3963 : 0 : break;
3964 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
3965 : 0 : ret = mlx5_hws_cnt_pool_get_action_offset
3966 : : (priv->hws_cpool,
3967 : : act_data->shared_counter.id,
3968 : : &rule_acts[act_data->action_dst].action,
3969 [ # # # # : 0 : &rule_acts[act_data->action_dst].counter.offset,
# # # # #
# ]
3970 : : is_root
3971 : : );
3972 : : if (ret != 0)
3973 : : goto error;
3974 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
3975 : 0 : flow->cnt_id = act_data->shared_counter.id;
3976 : 0 : break;
3977 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
3978 : 0 : ct_idx = MLX5_INDIRECT_ACTION_IDX_GET(action->conf);
3979 : 0 : if (flow_hw_ct_compile(dev, queue, ct_idx,
3980 : 0 : &rule_acts[act_data->action_dst]))
3981 : 0 : goto error;
3982 : : break;
3983 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK:
3984 : 0 : mtr_id = act_data->shared_meter.id &
3985 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3986 : : /* Find ASO object. */
3987 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, mtr_id);
3988 [ # # # # : 0 : if (!aso_mtr)
# # # # #
# ]
3989 : 0 : goto error;
3990 : 0 : rule_acts[act_data->action_dst].action =
3991 : 0 : pool->action;
3992 : 0 : rule_acts[act_data->action_dst].aso_meter.offset =
3993 : 0 : aso_mtr->offset;
3994 : 0 : break;
3995 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
3996 : : /*
3997 : : * Allocate meter directly will slow down flow
3998 : : * insertion rate.
3999 : : */
4000 : : ret = flow_hw_meter_mark_compile(dev,
4001 : 0 : act_data->action_dst, action,
4002 : : rule_acts, &mtr_idx, MLX5_HW_INV_QUEUE, error);
4003 : : if (ret != 0)
4004 : 0 : goto error;
4005 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
4006 : : mlx5_flow_hw_aux_set_mtr_id(flow, aux, mtr_idx);
4007 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_MTR_ID;
4008 : 0 : break;
4009 : 0 : case RTE_FLOW_ACTION_TYPE_NAT64:
4010 : 0 : nat64_c = action->conf;
4011 : 0 : rule_acts[act_data->action_dst].action = hw_acts->nat64[nat64_c->type];
4012 : 0 : break;
4013 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
4014 : 0 : jump_table = ((const struct rte_flow_action_jump_to_table_index *)
4015 : 0 : action->conf)->table;
4016 [ # # # # : 0 : if (likely(!rte_flow_template_table_resizable(dev->data->port_id,
# # # # #
# ]
4017 : : &table->cfg.attr))) {
4018 : 0 : rule_acts[act_data->action_dst].action =
4019 : 0 : jump_table->matcher_info[0].jump;
4020 : : } else {
4021 : : uint32_t selector;
4022 : 0 : rte_rwlock_read_lock(&table->matcher_replace_rwlk);
4023 : 0 : selector = table->matcher_selector;
4024 : 0 : rule_acts[act_data->action_dst].action =
4025 : 0 : jump_table->matcher_info[selector].jump;
4026 : 0 : rte_rwlock_read_unlock(&table->matcher_replace_rwlk);
4027 : : }
4028 : 0 : rule_acts[act_data->action_dst].jump_to_matcher.offset =
4029 : : ((const struct rte_flow_action_jump_to_table_index *)
4030 : 0 : action->conf)->index;
4031 : 0 : break;
4032 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_MIRROR: {
4033 : 0 : const struct mlx5_mirror *mirror = action->conf;
4034 : :
4035 : 0 : rule_acts[act_data->action_dst].action = mirror->mirror_action;
4036 : 0 : break;
4037 : : }
4038 : : default:
4039 : : break;
4040 : : }
4041 : : }
4042 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_COUNT) {
# # # # #
# ]
4043 : : /* If indirect count is used, then CNT_ID flag should be set. */
4044 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID);
4045 [ # # # # : 0 : if (at->action_flags & MLX5_FLOW_ACTION_INDIRECT_AGE) {
# # # # #
# ]
4046 : : /* If indirect AGE is used, then AGE_IDX flag should be set. */
4047 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX);
4048 [ # # # # : 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # # # #
# ]
4049 : 0 : age_idx = mlx5_flow_hw_aux_get_age_idx(flow, aux) &
4050 : : MLX5_HWS_AGE_IDX_MASK;
4051 [ # # # # : 0 : if (mlx5_hws_cnt_age_get(priv->hws_cpool, flow->cnt_id) != age_idx)
# # # # #
# # # # #
# # # # #
# ]
4052 : : /*
4053 : : * This is first use of this indirect counter
4054 : : * for this indirect AGE, need to increase the
4055 : : * number of counters.
4056 : : */
4057 : : mlx5_hws_age_nb_cnt_increase(priv, age_idx);
4058 : : }
4059 : : /*
4060 : : * Update this indirect counter the indirect/direct AGE in which
4061 : : * using it.
4062 : : */
4063 [ # # # # : 0 : mlx5_hws_cnt_age_set(priv->hws_cpool, flow->cnt_id, age_idx);
# # # # #
# ]
4064 : : }
4065 [ # # # # : 0 : if (hw_acts->encap_decap && !hw_acts->encap_decap->shared) {
# # # # #
# # # # #
# # # # #
# ]
4066 [ # # # # : 0 : int ix = mlx5_multi_pattern_reformat_to_index(hw_acts->encap_decap->action_type);
# # # # #
# ]
4067 : 0 : struct mlx5dr_rule_action *ra = &rule_acts[hw_acts->encap_decap_pos];
4068 : :
4069 [ # # # # : 0 : if (ix < 0)
# # # # #
# ]
4070 : 0 : goto error;
4071 [ # # # # : 0 : if (!mp_segment)
# # # # #
# ]
4072 : 0 : mp_segment = mlx5_multi_pattern_segment_find(table, flow->res_idx);
4073 [ # # # # : 0 : if (!mp_segment || !mp_segment->reformat_action[ix])
# # # # #
# # # # #
# # # # #
# ]
4074 : 0 : goto error;
4075 : 0 : ra->action = mp_segment->reformat_action[ix];
4076 : : /* reformat offset is relative to selected DR action */
4077 : 0 : ra->reformat.offset = flow->res_idx - mp_segment->head_index;
4078 : 0 : ra->reformat.data = ap->encap_data;
4079 : : }
4080 [ # # # # : 0 : if (hw_acts->push_remove && !hw_acts->push_remove->shared) {
# # # # #
# # # # #
# # # # #
# ]
4081 : 0 : rule_acts[hw_acts->push_remove_pos].ipv6_ext.offset =
4082 : 0 : flow->res_idx - 1;
4083 : 0 : rule_acts[hw_acts->push_remove_pos].ipv6_ext.header = ap->ipv6_push_data;
4084 : : }
4085 [ # # # # : 0 : if (mlx5_hws_cnt_id_valid(hw_acts->cnt_id)) {
# # # # #
# ]
4086 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_CNT_ID;
4087 : 0 : flow->cnt_id = hw_acts->cnt_id;
4088 : : }
4089 : : return 0;
4090 : :
4091 : 0 : error:
4092 : 0 : flow_hw_release_actions(dev, queue, flow);
4093 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4094 : : NULL, "Action construction failed");
4095 : : }
4096 : :
4097 : : static const struct rte_flow_item *
4098 : 0 : flow_hw_get_rule_items(struct rte_eth_dev *dev,
4099 : : const struct rte_flow_template_table *table,
4100 : : const struct rte_flow_item items[],
4101 : : uint8_t pattern_template_index,
4102 : : struct mlx5_flow_hw_pattern_params *pp)
4103 : : {
4104 : 0 : struct rte_flow_pattern_template *pt = table->its[pattern_template_index];
4105 : :
4106 : : /* Only one implicit item can be added to flow rule pattern. */
4107 : : MLX5_ASSERT(!pt->implicit_port || !pt->implicit_tag);
4108 : : /* At least one item was allocated in pattern params for items. */
4109 : : MLX5_ASSERT(MLX5_HW_MAX_ITEMS >= 1);
4110 [ # # ]: 0 : if (pt->implicit_port) {
4111 [ # # ]: 0 : if (pt->orig_item_nb + 1 > MLX5_HW_MAX_ITEMS) {
4112 : 0 : rte_errno = ENOMEM;
4113 : 0 : return NULL;
4114 : : }
4115 : : /* Set up represented port item in pattern params. */
4116 : 0 : pp->port_spec = (struct rte_flow_item_ethdev){
4117 : 0 : .port_id = dev->data->port_id,
4118 : : };
4119 : 0 : pp->items[0] = (struct rte_flow_item){
4120 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
4121 : 0 : .spec = &pp->port_spec,
4122 : : };
4123 [ # # ]: 0 : rte_memcpy(&pp->items[1], items, sizeof(*items) * pt->orig_item_nb);
4124 : 0 : return pp->items;
4125 [ # # ]: 0 : } else if (pt->implicit_tag) {
4126 [ # # ]: 0 : if (pt->orig_item_nb + 1 > MLX5_HW_MAX_ITEMS) {
4127 : 0 : rte_errno = ENOMEM;
4128 : 0 : return NULL;
4129 : : }
4130 : : /* Set up tag item in pattern params. */
4131 : 0 : pp->tag_spec = (struct rte_flow_item_tag){
4132 : : .data = flow_hw_tx_tag_regc_value(dev),
4133 : : };
4134 : 0 : pp->items[0] = (struct rte_flow_item){
4135 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4136 : 0 : .spec = &pp->tag_spec,
4137 : : };
4138 [ # # ]: 0 : rte_memcpy(&pp->items[1], items, sizeof(*items) * pt->orig_item_nb);
4139 : 0 : return pp->items;
4140 : : } else {
4141 : : return items;
4142 : : }
4143 : : }
4144 : :
4145 : : /**
4146 : : * Enqueue HW steering flow creation.
4147 : : *
4148 : : * The flow will be applied to the HW only if the postpone bit is not set or
4149 : : * the extra push function is called.
4150 : : * The flow creation status should be checked from dequeue result.
4151 : : *
4152 : : * @param[in] dev
4153 : : * Pointer to the rte_eth_dev structure.
4154 : : * @param[in] queue
4155 : : * The queue to create the flow.
4156 : : * @param[in] attr
4157 : : * Pointer to the flow operation attributes.
4158 : : * @param[in] table
4159 : : * Pointer to the template table.
4160 : : * @param[in] insertion_type
4161 : : * Insertion type for flow rules.
4162 : : * @param[in] rule_index
4163 : : * The item pattern flow follows from the table.
4164 : : * @param[in] items
4165 : : * Items with flow spec value.
4166 : : * @param[in] pattern_template_index
4167 : : * The item pattern flow follows from the table.
4168 : : * @param[in] actions
4169 : : * Action with flow spec value.
4170 : : * @param[in] action_template_index
4171 : : * The action pattern flow follows from the table.
4172 : : * @param[in] user_data
4173 : : * Pointer to the user_data.
4174 : : * @param[out] error
4175 : : * Pointer to error structure.
4176 : : *
4177 : : * @return
4178 : : * Flow pointer on success, NULL otherwise and rte_errno is set.
4179 : : */
4180 : : static __rte_always_inline struct rte_flow *
4181 : : flow_hw_async_flow_create_generic(struct rte_eth_dev *dev,
4182 : : uint32_t queue,
4183 : : const struct rte_flow_op_attr *attr,
4184 : : struct rte_flow_template_table *table,
4185 : : enum rte_flow_table_insertion_type insertion_type,
4186 : : uint32_t rule_index,
4187 : : const struct rte_flow_item items[],
4188 : : uint8_t pattern_template_index,
4189 : : const struct rte_flow_action actions[],
4190 : : uint8_t action_template_index,
4191 : : void *user_data,
4192 : : struct rte_flow_error *error)
4193 : : {
4194 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4195 : 0 : struct mlx5dr_rule_attr rule_attr = {
4196 : : .queue_id = queue,
4197 : : .user_data = user_data,
4198 : 0 : .burst = attr->postpone,
4199 : : };
4200 : : struct mlx5dr_rule_action *rule_acts;
4201 : : struct rte_flow_hw *flow = NULL;
4202 : : const struct rte_flow_item *rule_items;
4203 : 0 : struct rte_flow_error sub_error = { 0 };
4204 : 0 : uint32_t flow_idx = 0;
4205 : 0 : uint32_t res_idx = 0;
4206 : : int ret;
4207 : :
4208 : 0 : if (mlx5_fp_debug_enabled()) {
4209 [ # # # # : 0 : if (flow_hw_async_create_validate(dev, queue, table, insertion_type, rule_index,
# # ]
4210 : : items, pattern_template_index, actions, action_template_index, error))
4211 : : return NULL;
4212 : : }
4213 : 0 : flow = mlx5_ipool_malloc(table->flow_pool, &flow_idx);
4214 [ # # # # : 0 : if (!flow) {
# # ]
4215 : 0 : rte_errno = ENOMEM;
4216 : 0 : goto error;
4217 : : }
4218 : 0 : flow->nt_rule = false;
4219 : : rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
4220 : : /*
4221 : : * Set the table here in order to know the destination table
4222 : : * when free the flow afterward.
4223 : : */
4224 : 0 : flow->table = table;
4225 : 0 : flow->mt_idx = pattern_template_index;
4226 : 0 : flow->idx = flow_idx;
4227 [ # # # # : 0 : if (table->resource) {
# # ]
4228 : 0 : mlx5_ipool_malloc(table->resource, &res_idx);
4229 [ # # # # : 0 : if (!res_idx) {
# # ]
4230 : 0 : rte_errno = ENOMEM;
4231 : 0 : goto error;
4232 : : }
4233 : 0 : flow->res_idx = res_idx;
4234 : : } else {
4235 : 0 : flow->res_idx = flow_idx;
4236 : : }
4237 : 0 : flow->flags = 0;
4238 : : /*
4239 : : * Set the flow operation type here in order to know if the flow memory
4240 : : * should be freed or not when get the result from dequeue.
4241 : : */
4242 : 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_CREATE;
4243 : 0 : flow->user_data = user_data;
4244 : 0 : rule_attr.user_data = flow;
4245 : : /*
4246 : : * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
4247 : : * for rule insertion hints.
4248 : : */
4249 [ # # # # ]: 0 : flow->rule_idx = (rule_index == UINT32_MAX) ? flow->res_idx - 1 : rule_index;
4250 : 0 : rule_attr.rule_idx = flow->rule_idx;
4251 : : /*
4252 : : * Construct the flow actions based on the input actions.
4253 : : * The implicitly appended action is always fixed, like metadata
4254 : : * copy action from FDB to NIC Rx.
4255 : : * No need to copy and contrust a new "actions" list based on the
4256 : : * user's input, in order to save the cost.
4257 : : */
4258 [ # # # # : 0 : if (flow_hw_actions_construct(dev, flow, &priv->hw_q[queue].ap,
# # ]
4259 : 0 : &table->ats[action_template_index],
4260 [ # # # # : 0 : table->its[pattern_template_index]->item_flags,
# # ]
4261 : : flow->table, actions,
4262 : : rule_acts, queue, &sub_error))
4263 : 0 : goto error;
4264 : : if (insertion_type == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX) {
4265 : : rule_items = items;
4266 : : } else {
4267 : 0 : rule_items = flow_hw_get_rule_items(dev, table, items,
4268 : 0 : pattern_template_index, &priv->hw_q[queue].pp);
4269 [ # # # # ]: 0 : if (!rule_items)
4270 : 0 : goto error;
4271 : : }
4272 [ # # # # : 0 : if (likely(!rte_flow_template_table_resizable(dev->data->port_id, &table->cfg.attr))) {
# # ]
4273 : 0 : ret = mlx5dr_rule_create(table->matcher_info[0].matcher,
4274 : : pattern_template_index, rule_items,
4275 : : action_template_index, rule_acts,
4276 : : &rule_attr,
4277 : 0 : (struct mlx5dr_rule *)flow->rule);
4278 : : } else {
4279 [ # # # # : 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # ]
4280 : : uint32_t selector;
4281 : :
4282 : 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE;
4283 : 0 : rte_rwlock_read_lock(&table->matcher_replace_rwlk);
4284 : 0 : selector = table->matcher_selector;
4285 : 0 : ret = mlx5dr_rule_create(table->matcher_info[selector].matcher,
4286 : : pattern_template_index, rule_items,
4287 : : action_template_index, rule_acts,
4288 : : &rule_attr,
4289 : 0 : (struct mlx5dr_rule *)flow->rule);
4290 : 0 : rte_rwlock_read_unlock(&table->matcher_replace_rwlk);
4291 : 0 : aux->matcher_selector = selector;
4292 : 0 : flow->flags |= MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR;
4293 : : }
4294 : :
4295 [ # # # # : 0 : if (likely(!ret)) {
# # ]
4296 : 0 : flow_hw_q_inc_flow_ops(priv, queue);
4297 : 0 : return (struct rte_flow *)flow;
4298 : : }
4299 : 0 : error:
4300 [ # # # # : 0 : if (table->resource && res_idx)
# # # # #
# # # ]
4301 : 0 : mlx5_ipool_free(table->resource, res_idx);
4302 [ # # # # : 0 : if (flow_idx)
# # ]
4303 : 0 : mlx5_ipool_free(table->flow_pool, flow_idx);
4304 [ # # # # : 0 : if (sub_error.cause != RTE_FLOW_ERROR_TYPE_NONE && error != NULL)
# # # # #
# # # ]
4305 : 0 : *error = sub_error;
4306 : : else
4307 : 0 : rte_flow_error_set(error, rte_errno,
4308 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4309 : : "fail to create rte flow");
4310 : : return NULL;
4311 : : }
4312 : :
4313 : : static struct rte_flow *
4314 : 0 : flow_hw_async_flow_create(struct rte_eth_dev *dev,
4315 : : uint32_t queue,
4316 : : const struct rte_flow_op_attr *attr,
4317 : : struct rte_flow_template_table *table,
4318 : : const struct rte_flow_item items[],
4319 : : uint8_t pattern_template_index,
4320 : : const struct rte_flow_action actions[],
4321 : : uint8_t action_template_index,
4322 : : void *user_data,
4323 : : struct rte_flow_error *error)
4324 : : {
4325 : : uint32_t rule_index = UINT32_MAX;
4326 : :
4327 [ # # ]: 0 : return flow_hw_async_flow_create_generic(dev, queue, attr, table,
4328 : : RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN, rule_index,
4329 : : items, pattern_template_index, actions, action_template_index,
4330 : : user_data, error);
4331 : : }
4332 : :
4333 : : static struct rte_flow *
4334 : 0 : flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
4335 : : uint32_t queue,
4336 : : const struct rte_flow_op_attr *attr,
4337 : : struct rte_flow_template_table *table,
4338 : : uint32_t rule_index,
4339 : : const struct rte_flow_action actions[],
4340 : : uint8_t action_template_index,
4341 : : void *user_data,
4342 : : struct rte_flow_error *error)
4343 : : {
4344 : 0 : struct rte_flow_item items[] = {{.type = RTE_FLOW_ITEM_TYPE_END,}};
4345 : : uint8_t pattern_template_index = 0;
4346 : :
4347 [ # # ]: 0 : return flow_hw_async_flow_create_generic(dev, queue, attr, table,
4348 : : RTE_FLOW_TABLE_INSERTION_TYPE_INDEX, rule_index,
4349 : : items, pattern_template_index, actions, action_template_index,
4350 : : user_data, error);
4351 : : }
4352 : :
4353 : : static struct rte_flow *
4354 : 0 : flow_hw_async_flow_create_by_index_with_pattern(struct rte_eth_dev *dev,
4355 : : uint32_t queue,
4356 : : const struct rte_flow_op_attr *attr,
4357 : : struct rte_flow_template_table *table,
4358 : : uint32_t rule_index,
4359 : : const struct rte_flow_item items[],
4360 : : uint8_t pattern_template_index,
4361 : : const struct rte_flow_action actions[],
4362 : : uint8_t action_template_index,
4363 : : void *user_data,
4364 : : struct rte_flow_error *error)
4365 : : {
4366 [ # # ]: 0 : return flow_hw_async_flow_create_generic(dev, queue, attr, table,
4367 : : RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN, rule_index,
4368 : : items, pattern_template_index, actions, action_template_index,
4369 : : user_data, error);
4370 : : }
4371 : :
4372 : : /**
4373 : : * Enqueue HW steering flow update.
4374 : : *
4375 : : * The flow will be applied to the HW only if the postpone bit is not set or
4376 : : * the extra push function is called.
4377 : : * The flow destruction status should be checked from dequeue result.
4378 : : *
4379 : : * @param[in] dev
4380 : : * Pointer to the rte_eth_dev structure.
4381 : : * @param[in] queue
4382 : : * The queue to destroy the flow.
4383 : : * @param[in] attr
4384 : : * Pointer to the flow operation attributes.
4385 : : * @param[in] flow
4386 : : * Pointer to the flow to be destroyed.
4387 : : * @param[in] actions
4388 : : * Action with flow spec value.
4389 : : * @param[in] action_template_index
4390 : : * The action pattern flow follows from the table.
4391 : : * @param[in] user_data
4392 : : * Pointer to the user_data.
4393 : : * @param[out] error
4394 : : * Pointer to error structure.
4395 : : *
4396 : : * @return
4397 : : * 0 on success, negative value otherwise and rte_errno is set.
4398 : : */
4399 : : static int
4400 : 0 : flow_hw_async_flow_update(struct rte_eth_dev *dev,
4401 : : uint32_t queue,
4402 : : const struct rte_flow_op_attr *attr,
4403 : : struct rte_flow *flow,
4404 : : const struct rte_flow_action actions[],
4405 : : uint8_t action_template_index,
4406 : : void *user_data,
4407 : : struct rte_flow_error *error)
4408 : : {
4409 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4410 : 0 : struct mlx5dr_rule_attr rule_attr = {
4411 : : .queue_id = queue,
4412 : : .user_data = user_data,
4413 : 0 : .burst = attr->postpone,
4414 : : };
4415 : : struct mlx5dr_rule_action *rule_acts;
4416 : : struct rte_flow_hw *of = (struct rte_flow_hw *)flow;
4417 : : struct rte_flow_hw *nf;
4418 : : struct rte_flow_hw_aux *aux;
4419 : 0 : struct rte_flow_template_table *table = of->table;
4420 : 0 : uint32_t res_idx = 0;
4421 : : int ret;
4422 : :
4423 [ # # ]: 0 : if (mlx5_fp_debug_enabled()) {
4424 [ # # ]: 0 : if (flow_hw_async_update_validate(dev, queue, of, actions, action_template_index,
4425 : : error))
4426 : 0 : return -rte_errno;
4427 : : }
4428 [ # # ]: 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, of);
4429 : 0 : nf = &aux->upd_flow;
4430 : 0 : nf->nt_rule = false;
4431 : 0 : rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
4432 : : /*
4433 : : * Set the table here in order to know the destination table
4434 : : * when free the flow afterwards.
4435 : : */
4436 : 0 : nf->table = table;
4437 : 0 : nf->mt_idx = of->mt_idx;
4438 : 0 : nf->idx = of->idx;
4439 [ # # ]: 0 : if (table->resource) {
4440 : 0 : mlx5_ipool_malloc(table->resource, &res_idx);
4441 [ # # ]: 0 : if (!res_idx) {
4442 : 0 : rte_errno = ENOMEM;
4443 : 0 : goto error;
4444 : : }
4445 : 0 : nf->res_idx = res_idx;
4446 : : } else {
4447 : 0 : nf->res_idx = of->res_idx;
4448 : : }
4449 : 0 : nf->flags = 0;
4450 : : /* Indicate the construction function to set the proper fields. */
4451 : 0 : nf->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE;
4452 : : /*
4453 : : * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
4454 : : * for rule insertion hints.
4455 : : * If there is only one STE, the update will be atomic by nature.
4456 : : */
4457 : 0 : nf->rule_idx = nf->res_idx - 1;
4458 : 0 : rule_attr.rule_idx = nf->rule_idx;
4459 : : /*
4460 : : * Construct the flow actions based on the input actions.
4461 : : * The implicitly appended action is always fixed, like metadata
4462 : : * copy action from FDB to NIC Rx.
4463 : : * No need to copy and contrust a new "actions" list based on the
4464 : : * user's input, in order to save the cost.
4465 : : */
4466 [ # # ]: 0 : if (flow_hw_actions_construct(dev, nf, &priv->hw_q[queue].ap,
4467 : 0 : &table->ats[action_template_index],
4468 [ # # ]: 0 : table->its[nf->mt_idx]->item_flags,
4469 : : table, actions,
4470 : : rule_acts, queue, error)) {
4471 : 0 : rte_errno = EINVAL;
4472 : 0 : goto error;
4473 : : }
4474 : : /*
4475 : : * Set the flow operation type here in order to know if the flow memory
4476 : : * should be freed or not when get the result from dequeue.
4477 : : */
4478 : 0 : of->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE;
4479 : 0 : of->user_data = user_data;
4480 : 0 : of->flags |= MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW;
4481 : 0 : rule_attr.user_data = of;
4482 : 0 : ret = mlx5dr_rule_action_update((struct mlx5dr_rule *)of->rule,
4483 : : action_template_index, rule_acts, &rule_attr);
4484 [ # # ]: 0 : if (likely(!ret)) {
4485 : 0 : flow_hw_q_inc_flow_ops(priv, queue);
4486 : 0 : return 0;
4487 : : }
4488 : 0 : error:
4489 [ # # # # ]: 0 : if (table->resource && res_idx)
4490 : 0 : mlx5_ipool_free(table->resource, res_idx);
4491 : 0 : return rte_flow_error_set(error, rte_errno,
4492 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4493 : : "fail to update rte flow");
4494 : : }
4495 : :
4496 : : /**
4497 : : * Enqueue HW steering flow destruction.
4498 : : *
4499 : : * The flow will be applied to the HW only if the postpone bit is not set or
4500 : : * the extra push function is called.
4501 : : * The flow destruction status should be checked from dequeue result.
4502 : : *
4503 : : * @param[in] dev
4504 : : * Pointer to the rte_eth_dev structure.
4505 : : * @param[in] queue
4506 : : * The queue to destroy the flow.
4507 : : * @param[in] attr
4508 : : * Pointer to the flow operation attributes.
4509 : : * @param[in] flow
4510 : : * Pointer to the flow to be destroyed.
4511 : : * @param[in] user_data
4512 : : * Pointer to the user_data.
4513 : : * @param[out] error
4514 : : * Pointer to error structure.
4515 : : *
4516 : : * @return
4517 : : * 0 on success, negative value otherwise and rte_errno is set.
4518 : : */
4519 : : static int
4520 : 0 : flow_hw_async_flow_destroy(struct rte_eth_dev *dev,
4521 : : uint32_t queue,
4522 : : const struct rte_flow_op_attr *attr,
4523 : : struct rte_flow *flow,
4524 : : void *user_data,
4525 : : struct rte_flow_error *error)
4526 : : {
4527 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4528 : 0 : struct mlx5dr_rule_attr rule_attr = {
4529 : : .queue_id = queue,
4530 : : .user_data = user_data,
4531 : 0 : .burst = attr->postpone,
4532 : : };
4533 : : struct rte_flow_hw *fh = (struct rte_flow_hw *)flow;
4534 : 0 : bool resizable = rte_flow_template_table_resizable(dev->data->port_id,
4535 : 0 : &fh->table->cfg.attr);
4536 : : int ret;
4537 : :
4538 : : if (mlx5_fp_debug_enabled()) {
4539 : : if (flow_hw_async_destroy_validate(dev, queue, fh, error))
4540 : : return -rte_errno;
4541 : : }
4542 [ # # ]: 0 : fh->operation_type = !resizable ?
4543 : : MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY :
4544 : : MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY;
4545 : 0 : fh->user_data = user_data;
4546 : 0 : rule_attr.user_data = fh;
4547 : 0 : rule_attr.rule_idx = fh->rule_idx;
4548 : 0 : ret = mlx5dr_rule_destroy((struct mlx5dr_rule *)fh->rule, &rule_attr);
4549 [ # # ]: 0 : if (ret) {
4550 : 0 : return rte_flow_error_set(error, rte_errno,
4551 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4552 : : "fail to destroy rte flow");
4553 : : }
4554 : : flow_hw_q_inc_flow_ops(priv, queue);
4555 : 0 : return 0;
4556 : : }
4557 : :
4558 : : /**
4559 : : * Release the AGE and counter for given flow.
4560 : : *
4561 : : * @param[in] priv
4562 : : * Pointer to the port private data structure.
4563 : : * @param[in] queue
4564 : : * The queue to release the counter.
4565 : : * @param[in, out] flow
4566 : : * Pointer to the flow containing the counter.
4567 : : * @param[out] error
4568 : : * Pointer to error structure.
4569 : : */
4570 : : static void
4571 : 0 : flow_hw_age_count_release(struct mlx5_priv *priv, uint32_t queue,
4572 : : struct rte_flow_hw *flow,
4573 : : struct rte_flow_error *error)
4574 : : {
4575 [ # # ]: 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(priv->dev_data->port_id, flow);
4576 : : uint32_t *cnt_queue;
4577 : 0 : uint32_t age_idx = aux->orig.age_idx;
4578 : :
4579 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID);
4580 [ # # # # ]: 0 : if (mlx5_hws_cnt_is_shared(priv->hws_cpool, flow->cnt_id)) {
4581 [ # # # # ]: 0 : if ((flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX) &&
4582 : : !mlx5_hws_age_is_indirect(age_idx)) {
4583 : : /* Remove this AGE parameter from indirect counter. */
4584 [ # # ]: 0 : mlx5_hws_cnt_age_set(priv->hws_cpool, flow->cnt_id, 0);
4585 : : /* Release the AGE parameter. */
4586 : 0 : mlx5_hws_age_action_destroy(priv, age_idx, error);
4587 : : }
4588 : 0 : return;
4589 : : }
4590 : : cnt_queue = mlx5_hws_cnt_get_queue(priv, &queue);
4591 : : /* Put the counter first to reduce the race risk in BG thread. */
4592 [ # # ]: 0 : mlx5_hws_cnt_pool_put(priv->hws_cpool, cnt_queue, &flow->cnt_id);
4593 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX) {
4594 [ # # ]: 0 : if (mlx5_hws_age_is_indirect(age_idx)) {
4595 : 0 : uint32_t idx = age_idx & MLX5_HWS_AGE_IDX_MASK;
4596 : :
4597 : : mlx5_hws_age_nb_cnt_decrease(priv, idx);
4598 : : } else {
4599 : : /* Release the AGE parameter. */
4600 : 0 : mlx5_hws_age_action_destroy(priv, age_idx, error);
4601 : : }
4602 : : }
4603 : : }
4604 : :
4605 : : static __rte_always_inline void
4606 : : flow_hw_pull_legacy_indirect_comp(struct rte_eth_dev *dev, struct mlx5_hw_q_job *job,
4607 : : uint32_t queue)
4608 : : {
4609 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4610 : : struct mlx5_aso_ct_action *aso_ct;
4611 : : struct mlx5_aso_mtr *aso_mtr;
4612 : : uint32_t type, idx;
4613 : :
4614 [ # # ]: 0 : if (MLX5_INDIRECT_ACTION_TYPE_GET(job->action) ==
4615 : : MLX5_INDIRECT_ACTION_TYPE_QUOTA) {
4616 : 0 : mlx5_quota_async_completion(dev, queue, job);
4617 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_DESTROY) {
4618 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
4619 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK) {
4620 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4621 : 0 : mlx5_ipool_free(priv->hws_mpool->idx_pool, idx);
4622 : : }
4623 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_CREATE) {
4624 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
4625 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK) {
4626 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4627 : 0 : aso_mtr = mlx5_ipool_get(priv->hws_mpool->idx_pool, idx);
4628 : 0 : aso_mtr->state = ASO_METER_READY;
4629 [ # # ]: 0 : } else if (type == MLX5_INDIRECT_ACTION_TYPE_CT) {
4630 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4631 : 0 : aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
4632 : 0 : aso_ct->state = ASO_CONNTRACK_READY;
4633 : : }
4634 [ # # ]: 0 : } else if (job->type == MLX5_HW_Q_JOB_TYPE_QUERY) {
4635 : : type = MLX5_INDIRECT_ACTION_TYPE_GET(job->action);
4636 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_TYPE_CT) {
4637 : 0 : idx = MLX5_INDIRECT_ACTION_IDX_GET(job->action);
4638 : 0 : aso_ct = mlx5_ipool_get(priv->hws_ctpool->cts, idx);
4639 : 0 : mlx5_aso_ct_obj_analyze(job->query.user,
4640 : 0 : job->query.hw);
4641 : 0 : aso_ct->state = ASO_CONNTRACK_READY;
4642 : : }
4643 : : }
4644 : : }
4645 : :
4646 : : static __rte_always_inline int
4647 : : mlx5_hw_pull_flow_transfer_comp(struct rte_eth_dev *dev,
4648 : : uint32_t queue, struct rte_flow_op_result res[],
4649 : : uint16_t n_res)
4650 : : {
4651 : : uint32_t size, i;
4652 : 0 : struct rte_flow_hw *flow = NULL;
4653 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4654 : 0 : struct rte_ring *ring = priv->hw_q[queue].flow_transfer_completed;
4655 : :
4656 : 0 : if (ring == NULL)
4657 : : return 0;
4658 : :
4659 : 0 : size = RTE_MIN(rte_ring_count(ring), n_res);
4660 [ # # ]: 0 : for (i = 0; i < size; i++) {
4661 [ # # # # : 0 : res[i].status = RTE_FLOW_OP_SUCCESS;
# ]
4662 : : rte_ring_dequeue(ring, (void **)&flow);
4663 : 0 : res[i].user_data = flow->user_data;
4664 : : flow_hw_q_dec_flow_ops(priv, queue);
4665 : : }
4666 : 0 : return (int)size;
4667 : : }
4668 : :
4669 : : static inline int
4670 : 0 : __flow_hw_pull_indir_action_comp(struct rte_eth_dev *dev,
4671 : : uint32_t queue,
4672 : : struct rte_flow_op_result res[],
4673 : : uint16_t n_res)
4674 : :
4675 : : {
4676 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4677 : 0 : struct rte_ring *r = priv->hw_q[queue].indir_cq;
4678 : 0 : void *user_data = NULL;
4679 : : int ret_comp, i;
4680 : :
4681 : 0 : ret_comp = (int)rte_ring_count(r);
4682 : 0 : if (ret_comp > n_res)
4683 : : ret_comp = n_res;
4684 [ # # ]: 0 : for (i = 0; i < ret_comp; i++) {
4685 : : rte_ring_dequeue(r, &user_data);
4686 : 0 : res[i].user_data = user_data;
4687 : 0 : res[i].status = RTE_FLOW_OP_SUCCESS;
4688 : : }
4689 [ # # ]: 0 : if (!priv->shared_host) {
4690 [ # # # # ]: 0 : if (ret_comp < n_res && priv->hws_mpool)
4691 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->hws_mpool->sq[queue],
4692 : 0 : &res[ret_comp], n_res - ret_comp);
4693 [ # # # # ]: 0 : if (ret_comp < n_res && priv->hws_ctpool)
4694 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->ct_mng->aso_sqs[queue],
4695 : 0 : &res[ret_comp], n_res - ret_comp);
4696 : : }
4697 [ # # # # ]: 0 : if (ret_comp < n_res && priv->quota_ctx.sq)
4698 : 0 : ret_comp += mlx5_aso_pull_completion(&priv->quota_ctx.sq[queue],
4699 : 0 : &res[ret_comp],
4700 : 0 : n_res - ret_comp);
4701 [ # # ]: 0 : for (i = 0; i < ret_comp; i++) {
4702 : 0 : struct mlx5_hw_q_job *job = (struct mlx5_hw_q_job *)res[i].user_data;
4703 : :
4704 : : /* Restore user data. */
4705 : 0 : res[i].user_data = job->user_data;
4706 [ # # ]: 0 : if (job->indirect_type == MLX5_HW_INDIRECT_TYPE_LEGACY)
4707 : : flow_hw_pull_legacy_indirect_comp(dev, job, queue);
4708 : : /*
4709 : : * Current PMD supports 2 indirect action list types - MIRROR and REFORMAT.
4710 : : * These indirect list types do not post WQE to create action.
4711 : : * Future indirect list types that do post WQE will add
4712 : : * completion handlers here.
4713 : : */
4714 : : flow_hw_job_put(priv, job, queue);
4715 : : }
4716 : 0 : return ret_comp;
4717 : : }
4718 : :
4719 : : static __rte_always_inline void
4720 : : hw_cmpl_flow_update_or_destroy(struct rte_eth_dev *dev,
4721 : : struct rte_flow_hw *flow,
4722 : : uint32_t queue, struct rte_flow_error *error)
4723 : : {
4724 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4725 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
4726 : 0 : struct rte_flow_template_table *table = flow->table;
4727 : : /* Release the original resource index in case of update. */
4728 : 0 : uint32_t res_idx = flow->res_idx;
4729 : :
4730 [ # # ]: 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAGS_ALL) {
4731 [ # # # # : 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
# # ]
4732 : :
4733 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP)
# # ]
4734 : 0 : flow_hw_jump_release(dev, flow->jump);
4735 [ # # # # : 0 : else if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ)
# # ]
4736 : 0 : mlx5_hrxq_obj_release(dev, flow->hrxq);
4737 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID)
# # ]
4738 : 0 : flow_hw_age_count_release(priv, queue, flow, error);
4739 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MTR_ID)
# # ]
4740 : 0 : mlx5_ipool_free(pool->idx_pool, aux->orig.mtr_id);
4741 [ # # # # : 0 : if (flow->flags & MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW) {
# # ]
4742 : : struct rte_flow_hw *upd_flow = &aux->upd_flow;
4743 : :
4744 : : rte_memcpy(flow, upd_flow, offsetof(struct rte_flow_hw, rule));
4745 : 0 : aux->orig = aux->upd;
4746 : 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_CREATE;
4747 [ # # # # : 0 : if (!flow->nt_rule && table->resource)
# # # # #
# # # ]
4748 : 0 : mlx5_ipool_free(table->resource, res_idx);
4749 : : }
4750 : : }
4751 [ # # # # : 0 : if (flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY ||
# # ]
4752 : : flow->operation_type == MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY) {
4753 [ # # # # : 0 : if (!flow->nt_rule) {
# # ]
4754 [ # # # # : 0 : if (table->resource)
# # ]
4755 : 0 : mlx5_ipool_free(table->resource, res_idx);
4756 [ # # # # : 0 : if (table->flow_pool)
# # ]
4757 : 0 : mlx5_ipool_free(table->flow_pool, flow->idx);
4758 : : }
4759 : : }
4760 : : }
4761 : :
4762 : : static __rte_always_inline void
4763 : : hw_cmpl_resizable_tbl(struct rte_eth_dev *dev,
4764 : : struct rte_flow_hw *flow,
4765 : : uint32_t queue, enum rte_flow_op_status status,
4766 : : struct rte_flow_error *error)
4767 : : {
4768 : 0 : struct rte_flow_template_table *table = flow->table;
4769 : 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow);
4770 : 0 : uint32_t selector = aux->matcher_selector;
4771 : 0 : uint32_t other_selector = (selector + 1) & 1;
4772 : :
4773 : : MLX5_ASSERT(flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR);
4774 [ # # # # ]: 0 : switch (flow->operation_type) {
4775 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE:
4776 : 0 : rte_atomic_fetch_add_explicit
4777 : : (&table->matcher_info[selector].refcnt, 1,
4778 : : rte_memory_order_relaxed);
4779 : 0 : break;
4780 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY:
4781 [ # # ]: 0 : rte_atomic_fetch_sub_explicit
4782 : : (&table->matcher_info[selector].refcnt, 1,
4783 : : rte_memory_order_relaxed);
4784 : : hw_cmpl_flow_update_or_destroy(dev, flow, queue, error);
4785 : : break;
4786 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE:
4787 [ # # ]: 0 : if (status == RTE_FLOW_OP_SUCCESS) {
4788 : 0 : rte_atomic_fetch_sub_explicit
4789 : : (&table->matcher_info[selector].refcnt, 1,
4790 : : rte_memory_order_relaxed);
4791 : 0 : rte_atomic_fetch_add_explicit
4792 : : (&table->matcher_info[other_selector].refcnt, 1,
4793 : : rte_memory_order_relaxed);
4794 : 0 : aux->matcher_selector = other_selector;
4795 : : }
4796 : : break;
4797 : : default:
4798 : : break;
4799 : : }
4800 : : }
4801 : :
4802 : : /**
4803 : : * Pull the enqueued flows.
4804 : : *
4805 : : * For flows enqueued from creation/destruction, the status should be
4806 : : * checked from the dequeue result.
4807 : : *
4808 : : * @param[in] dev
4809 : : * Pointer to the rte_eth_dev structure.
4810 : : * @param[in] queue
4811 : : * The queue to pull the result.
4812 : : * @param[in/out] res
4813 : : * Array to save the results.
4814 : : * @param[in] n_res
4815 : : * Available result with the array.
4816 : : * @param[out] error
4817 : : * Pointer to error structure.
4818 : : *
4819 : : * @return
4820 : : * Result number on success, negative value otherwise and rte_errno is set.
4821 : : */
4822 : : static int
4823 : 0 : flow_hw_pull(struct rte_eth_dev *dev,
4824 : : uint32_t queue,
4825 : : struct rte_flow_op_result res[],
4826 : : uint16_t n_res,
4827 : : struct rte_flow_error *error)
4828 : : {
4829 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4830 : : int ret, i;
4831 : :
4832 : : /* 1. Pull the flow completion. */
4833 : 0 : ret = mlx5dr_send_queue_poll(priv->dr_ctx, queue, res, n_res);
4834 [ # # ]: 0 : if (ret < 0)
4835 : 0 : return rte_flow_error_set(error, rte_errno,
4836 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4837 : : "fail to query flow queue");
4838 [ # # ]: 0 : for (i = 0; i < ret; i++) {
4839 : 0 : struct rte_flow_hw *flow = res[i].user_data;
4840 : :
4841 : : /* Restore user data. */
4842 : 0 : res[i].user_data = flow->user_data;
4843 [ # # # ]: 0 : switch (flow->operation_type) {
4844 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY:
4845 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE:
4846 : : hw_cmpl_flow_update_or_destroy(dev, flow, queue, error);
4847 : : break;
4848 : 0 : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE:
4849 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY:
4850 : : case MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE:
4851 [ # # ]: 0 : hw_cmpl_resizable_tbl(dev, flow, queue, res[i].status, error);
4852 : : break;
4853 : : default:
4854 : : break;
4855 : : }
4856 : : flow_hw_q_dec_flow_ops(priv, queue);
4857 : : }
4858 : : /* 2. Pull indirect action comp. */
4859 [ # # ]: 0 : if (ret < n_res)
4860 : 0 : ret += __flow_hw_pull_indir_action_comp(dev, queue, &res[ret],
4861 : 0 : n_res - ret);
4862 [ # # ]: 0 : if (ret < n_res)
4863 : 0 : ret += mlx5_hw_pull_flow_transfer_comp(dev, queue, &res[ret],
4864 [ # # ]: 0 : n_res - ret);
4865 : :
4866 : : return ret;
4867 : : }
4868 : :
4869 : : static uint32_t
4870 : 0 : mlx5_hw_push_queue(struct rte_ring *pending_q, struct rte_ring *cmpl_q)
4871 : : {
4872 : 0 : void *job = NULL;
4873 : : uint32_t i, size = rte_ring_count(pending_q);
4874 : :
4875 [ # # ]: 0 : for (i = 0; i < size; i++) {
4876 : : rte_ring_dequeue(pending_q, &job);
4877 [ # # # # : 0 : rte_ring_enqueue(cmpl_q, job);
# ]
4878 : : }
4879 : 0 : return size;
4880 : : }
4881 : :
4882 : : static inline uint32_t
4883 : 0 : __flow_hw_push_action(struct rte_eth_dev *dev,
4884 : : uint32_t queue)
4885 : : {
4886 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4887 : 0 : struct mlx5_hw_q *hw_q = &priv->hw_q[queue];
4888 : :
4889 : 0 : mlx5_hw_push_queue(hw_q->indir_iq, hw_q->indir_cq);
4890 [ # # # # ]: 0 : if (hw_q->flow_transfer_pending != NULL && hw_q->flow_transfer_completed != NULL)
4891 : 0 : mlx5_hw_push_queue(hw_q->flow_transfer_pending,
4892 : : hw_q->flow_transfer_completed);
4893 [ # # ]: 0 : if (!priv->shared_host) {
4894 [ # # ]: 0 : if (priv->hws_ctpool)
4895 : 0 : mlx5_aso_push_wqe(priv->sh,
4896 : 0 : &priv->ct_mng->aso_sqs[queue]);
4897 [ # # ]: 0 : if (priv->hws_mpool)
4898 : 0 : mlx5_aso_push_wqe(priv->sh,
4899 : 0 : &priv->hws_mpool->sq[queue]);
4900 : : }
4901 : 0 : return flow_hw_q_pending(priv, queue);
4902 : : }
4903 : :
4904 : : static int
4905 : 0 : __flow_hw_push(struct rte_eth_dev *dev,
4906 : : uint32_t queue,
4907 : : struct rte_flow_error *error)
4908 : : {
4909 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4910 : : int ret, num;
4911 : :
4912 : 0 : num = __flow_hw_push_action(dev, queue);
4913 : 0 : ret = mlx5dr_send_queue_action(priv->dr_ctx, queue,
4914 : : MLX5DR_SEND_QUEUE_ACTION_DRAIN_ASYNC);
4915 [ # # ]: 0 : if (ret) {
4916 : 0 : rte_flow_error_set(error, rte_errno,
4917 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4918 : : "fail to push flows");
4919 : 0 : return ret;
4920 : : }
4921 : : return num;
4922 : : }
4923 : :
4924 : : /**
4925 : : * Push the enqueued flows to HW.
4926 : : *
4927 : : * Force apply all the enqueued flows to the HW.
4928 : : *
4929 : : * @param[in] dev
4930 : : * Pointer to the rte_eth_dev structure.
4931 : : * @param[in] queue
4932 : : * The queue to push the flow.
4933 : : * @param[out] error
4934 : : * Pointer to error structure.
4935 : : *
4936 : : * @return
4937 : : * 0 on success, negative value otherwise and rte_errno is set.
4938 : : */
4939 : : static int
4940 : 0 : flow_hw_push(struct rte_eth_dev *dev,
4941 : : uint32_t queue, struct rte_flow_error *error)
4942 : : {
4943 : 0 : int ret = __flow_hw_push(dev, queue, error);
4944 : :
4945 : 0 : return ret >= 0 ? 0 : ret;
4946 : : }
4947 : :
4948 : : /**
4949 : : * Drain the enqueued flows' completion.
4950 : : *
4951 : : * @param[in] dev
4952 : : * Pointer to the rte_eth_dev structure.
4953 : : * @param[in] queue
4954 : : * The queue to pull the flow.
4955 : : * @param[out] error
4956 : : * Pointer to error structure.
4957 : : *
4958 : : * @return
4959 : : * 0 on success, negative value otherwise and rte_errno is set.
4960 : : */
4961 : : static int
4962 : 0 : __flow_hw_pull_comp(struct rte_eth_dev *dev,
4963 : : uint32_t queue, struct rte_flow_error *error)
4964 : : {
4965 : : struct rte_flow_op_result comp[BURST_THR];
4966 : : int ret, i, empty_loop = 0;
4967 : : uint32_t pending_rules;
4968 : :
4969 : 0 : ret = __flow_hw_push(dev, queue, error);
4970 [ # # ]: 0 : if (ret < 0)
4971 : : return ret;
4972 : 0 : pending_rules = ret;
4973 [ # # ]: 0 : while (pending_rules) {
4974 : 0 : ret = flow_hw_pull(dev, queue, comp, BURST_THR, error);
4975 [ # # ]: 0 : if (ret < 0)
4976 : : return -1;
4977 [ # # ]: 0 : if (!ret) {
4978 : 0 : rte_delay_us_sleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY);
4979 [ # # ]: 0 : if (++empty_loop > 5) {
4980 : 0 : DRV_LOG(WARNING, "No available dequeue %u, quit.", pending_rules);
4981 : 0 : break;
4982 : : }
4983 : 0 : continue;
4984 : : }
4985 [ # # ]: 0 : for (i = 0; i < ret; i++) {
4986 [ # # ]: 0 : if (comp[i].status == RTE_FLOW_OP_ERROR)
4987 : 0 : DRV_LOG(WARNING, "Flow flush get error CQE.");
4988 : : }
4989 : : /*
4990 : : * Indirect **SYNC** METER_MARK and CT actions do not
4991 : : * remove completion after WQE post.
4992 : : * That implementation avoids HW timeout.
4993 : : * The completion is removed before the following WQE post.
4994 : : * However, HWS queue updates do not reflect that behaviour.
4995 : : * Therefore, during port destruction sync queue may have
4996 : : * pending completions.
4997 : : */
4998 : 0 : pending_rules -= RTE_MIN(pending_rules, (uint32_t)ret);
4999 : : empty_loop = 0;
5000 : : }
5001 : : return 0;
5002 : : }
5003 : :
5004 : : /**
5005 : : * Flush created flows.
5006 : : *
5007 : : * @param[in] dev
5008 : : * Pointer to the rte_eth_dev structure.
5009 : : * @param[out] error
5010 : : * Pointer to error structure.
5011 : : *
5012 : : * @return
5013 : : * 0 on success, negative value otherwise and rte_errno is set.
5014 : : */
5015 : : int
5016 : 0 : mlx5_flow_hw_q_flow_flush(struct rte_eth_dev *dev,
5017 : : struct rte_flow_error *error)
5018 : : {
5019 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5020 : 0 : struct mlx5_hw_q *hw_q = &priv->hw_q[MLX5_DEFAULT_FLUSH_QUEUE];
5021 : : struct rte_flow_template_table *tbl;
5022 : : struct rte_flow_hw *flow;
5023 : 0 : struct rte_flow_op_attr attr = {
5024 : : .postpone = 0,
5025 : : };
5026 : : uint32_t pending_rules = 0;
5027 : : uint32_t queue;
5028 : : uint32_t fidx;
5029 : :
5030 : : /*
5031 : : * Ensure to push and dequeue all the enqueued flow
5032 : : * creation/destruction jobs in case user forgot to
5033 : : * dequeue. Or the enqueued created flows will be
5034 : : * leaked. The forgotten dequeues would also cause
5035 : : * flow flush get extra CQEs as expected and pending_rules
5036 : : * be minus value.
5037 : : */
5038 [ # # ]: 0 : for (queue = 0; queue < priv->nb_queue; queue++) {
5039 [ # # ]: 0 : if (__flow_hw_pull_comp(dev, queue, error))
5040 : : return -1;
5041 : : }
5042 : : /* Flush flow per-table from MLX5_DEFAULT_FLUSH_QUEUE. */
5043 [ # # ]: 0 : LIST_FOREACH(tbl, &priv->flow_hw_tbl, next) {
5044 [ # # ]: 0 : if (!tbl->cfg.external)
5045 : 0 : continue;
5046 [ # # ]: 0 : MLX5_IPOOL_FOREACH(tbl->flow_pool, fidx, flow) {
5047 [ # # ]: 0 : if (flow_hw_async_flow_destroy(dev,
5048 : : MLX5_DEFAULT_FLUSH_QUEUE,
5049 : : &attr,
5050 : : (struct rte_flow *)flow,
5051 : : NULL,
5052 : : error))
5053 : : return -1;
5054 : 0 : pending_rules++;
5055 : : /* Drain completion with queue size. */
5056 [ # # ]: 0 : if (pending_rules >= hw_q->size) {
5057 [ # # ]: 0 : if (__flow_hw_pull_comp(dev,
5058 : : MLX5_DEFAULT_FLUSH_QUEUE,
5059 : : error))
5060 : : return -1;
5061 : : pending_rules = 0;
5062 : : }
5063 : : }
5064 : : }
5065 : : /* Drain left completion. */
5066 [ # # # # ]: 0 : if (pending_rules &&
5067 : 0 : __flow_hw_pull_comp(dev, MLX5_DEFAULT_FLUSH_QUEUE, error))
5068 : 0 : return -1;
5069 : : return 0;
5070 : : }
5071 : :
5072 : : static int
5073 : 0 : mlx5_tbl_multi_pattern_process(struct rte_eth_dev *dev,
5074 : : struct rte_flow_template_table *tbl,
5075 : : struct mlx5_multi_pattern_segment *segment,
5076 : : uint32_t bulk_size,
5077 : : struct rte_flow_error *error)
5078 : : {
5079 : : int ret = 0;
5080 : : uint32_t i;
5081 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5082 : : bool unified_fdb = is_unified_fdb(priv);
5083 : : struct mlx5_tbl_multi_pattern_ctx *mpctx = &tbl->mpctx;
5084 : : const struct rte_flow_template_table_attr *table_attr = &tbl->cfg.attr;
5085 : 0 : const struct rte_flow_attr *attr = &table_attr->flow_attr;
5086 : : enum mlx5dr_table_type type =
5087 : 0 : get_mlx5dr_table_type(attr, table_attr->specialize, unified_fdb);
5088 : 0 : uint32_t flags = mlx5_hw_act_flag[!!attr->group][type];
5089 : : struct mlx5dr_action *dr_action = NULL;
5090 : :
5091 [ # # ]: 0 : for (i = 0; i < MLX5_MULTIPATTERN_ENCAP_NUM; i++) {
5092 [ # # ]: 0 : typeof(mpctx->reformat[0]) *reformat = mpctx->reformat + i;
5093 : : enum mlx5dr_action_type reformat_type =
5094 : : mlx5_multi_pattern_reformat_index_to_type(i);
5095 : :
5096 [ # # ]: 0 : if (!reformat->elements_num)
5097 : 0 : continue;
5098 : : dr_action = reformat_type == MLX5DR_ACTION_TYP_INSERT_HEADER ?
5099 : : mlx5dr_action_create_insert_header
5100 : : (priv->dr_ctx, reformat->elements_num,
5101 : : reformat->insert_hdr, bulk_size, flags) :
5102 : 0 : mlx5dr_action_create_reformat
5103 : : (priv->dr_ctx, reformat_type, reformat->elements_num,
5104 : 0 : reformat->reformat_hdr, bulk_size, flags);
5105 [ # # ]: 0 : if (!dr_action) {
5106 : 0 : ret = rte_flow_error_set(error, rte_errno,
5107 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5108 : : NULL,
5109 : : "failed to create multi-pattern encap action");
5110 : 0 : goto error;
5111 : : }
5112 : 0 : segment->reformat_action[i] = dr_action;
5113 : : }
5114 [ # # ]: 0 : if (mpctx->mh.elements_num) {
5115 : : typeof(mpctx->mh) *mh = &mpctx->mh;
5116 : 0 : dr_action = mlx5dr_action_create_modify_header
5117 : 0 : (priv->dr_ctx, mpctx->mh.elements_num, mh->pattern,
5118 : : bulk_size, flags);
5119 [ # # ]: 0 : if (!dr_action) {
5120 : 0 : ret = rte_flow_error_set(error, rte_errno,
5121 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5122 : : NULL, "failed to create multi-pattern header modify action");
5123 : 0 : goto error;
5124 : : }
5125 : 0 : segment->mhdr_action = dr_action;
5126 : : }
5127 [ # # ]: 0 : if (dr_action) {
5128 : 0 : segment->capacity = RTE_BIT32(bulk_size);
5129 [ # # ]: 0 : if (segment != &mpctx->segments[MLX5_MAX_TABLE_RESIZE_NUM - 1])
5130 : 0 : segment[1].head_index = segment->head_index + segment->capacity;
5131 : : }
5132 : : return 0;
5133 : 0 : error:
5134 : 0 : mlx5_destroy_multi_pattern_segment(segment);
5135 : 0 : return ret;
5136 : : }
5137 : :
5138 : : static int
5139 : 0 : mlx5_hw_build_template_table(struct rte_eth_dev *dev,
5140 : : uint8_t nb_action_templates,
5141 : : struct rte_flow_actions_template *action_templates[],
5142 : : struct mlx5dr_action_template *at[],
5143 : : struct rte_flow_template_table *tbl,
5144 : : struct rte_flow_error *error)
5145 : : {
5146 : : int ret;
5147 : : uint8_t i;
5148 : :
5149 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
5150 : 0 : uint32_t refcnt = rte_atomic_fetch_add_explicit(&action_templates[i]->refcnt, 1,
5151 : : rte_memory_order_relaxed) + 1;
5152 : :
5153 [ # # ]: 0 : if (refcnt <= 1) {
5154 : 0 : rte_flow_error_set(error, EINVAL,
5155 : : RTE_FLOW_ERROR_TYPE_ACTION,
5156 : : &action_templates[i], "invalid AT refcount");
5157 : 0 : goto at_error;
5158 : : }
5159 : 0 : at[i] = action_templates[i]->tmpl;
5160 : 0 : tbl->ats[i].action_template = action_templates[i];
5161 : 0 : LIST_INIT(&tbl->ats[i].acts.act_list);
5162 : : /* do NOT translate table action if `dev` was not started */
5163 [ # # ]: 0 : if (!dev->data->dev_started)
5164 : 0 : continue;
5165 : 0 : ret = flow_hw_translate_actions_template(dev, &tbl->cfg,
5166 : : &tbl->ats[i].acts,
5167 : : action_templates[i],
5168 : : &tbl->mpctx, error);
5169 [ # # ]: 0 : if (ret) {
5170 : 0 : i++;
5171 : 0 : goto at_error;
5172 : : }
5173 : 0 : flow_hw_populate_rule_acts_caches(dev, tbl, i);
5174 : : }
5175 [ # # ]: 0 : tbl->nb_action_templates = nb_action_templates;
5176 [ # # ]: 0 : if (mlx5_is_multi_pattern_active(&tbl->mpctx)) {
5177 [ # # ]: 0 : ret = mlx5_tbl_multi_pattern_process(dev, tbl,
5178 : : &tbl->mpctx.segments[0],
5179 : : rte_log2_u32(tbl->cfg.attr.nb_flows),
5180 : : error);
5181 [ # # ]: 0 : if (ret)
5182 : 0 : goto at_error;
5183 : : }
5184 : : return 0;
5185 : :
5186 : : at_error:
5187 [ # # ]: 0 : while (i--) {
5188 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
5189 : 0 : rte_atomic_fetch_sub_explicit(&action_templates[i]->refcnt,
5190 : : 1, rte_memory_order_relaxed);
5191 : : }
5192 : 0 : return rte_errno;
5193 : : }
5194 : :
5195 : : static bool
5196 : : flow_hw_validate_template_domain(const struct rte_flow_attr *table_attr,
5197 : : uint32_t ingress, uint32_t egress, uint32_t transfer)
5198 : : {
5199 : 0 : if (table_attr->ingress)
5200 : : return ingress != 0;
5201 [ # # # # ]: 0 : else if (table_attr->egress)
5202 : : return egress != 0;
5203 : : else
5204 : 0 : return transfer;
5205 : : }
5206 : :
5207 : : static bool
5208 : : flow_hw_validate_table_domain(const struct rte_flow_attr *table_attr)
5209 : : {
5210 : 0 : return table_attr->ingress + table_attr->egress + table_attr->transfer
5211 : : == 1;
5212 : : }
5213 : :
5214 : : /**
5215 : : * Create flow table.
5216 : : *
5217 : : * The input item and action templates will be binded to the table.
5218 : : * Flow memory will also be allocated. Matcher will be created based
5219 : : * on the item template. Action will be translated to the dedicated
5220 : : * DR action if possible.
5221 : : *
5222 : : * @param[in] dev
5223 : : * Pointer to the rte_eth_dev structure.
5224 : : * @param[in] table_cfg
5225 : : * Pointer to the table configuration.
5226 : : * @param[in] item_templates
5227 : : * Item template array to be binded to the table.
5228 : : * @param[in] nb_item_templates
5229 : : * Number of item template.
5230 : : * @param[in] action_templates
5231 : : * Action template array to be binded to the table.
5232 : : * @param[in] nb_action_templates
5233 : : * Number of action template.
5234 : : * @param[out] error
5235 : : * Pointer to error structure.
5236 : : *
5237 : : * @return
5238 : : * Table on success, NULL otherwise and rte_errno is set.
5239 : : */
5240 : : static struct rte_flow_template_table *
5241 : 0 : flow_hw_table_create(struct rte_eth_dev *dev,
5242 : : const struct mlx5_flow_template_table_cfg *table_cfg,
5243 : : struct rte_flow_pattern_template *item_templates[],
5244 : : uint8_t nb_item_templates,
5245 : : struct rte_flow_actions_template *action_templates[],
5246 : : uint8_t nb_action_templates,
5247 : : struct rte_flow_error *error)
5248 : : {
5249 : 0 : struct rte_flow_error sub_error = {
5250 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
5251 : : .cause = NULL,
5252 : : .message = NULL,
5253 : : };
5254 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
5255 : : bool unified_fdb = is_unified_fdb(priv);
5256 : 0 : struct mlx5dr_matcher_attr matcher_attr = {0};
5257 : 0 : struct mlx5dr_action_jump_to_matcher_attr jump_attr = {
5258 : : .type = MLX5DR_ACTION_JUMP_TO_MATCHER_BY_INDEX,
5259 : : .matcher = NULL,
5260 : : };
5261 : : struct rte_flow_template_table *tbl = NULL;
5262 : : struct mlx5_flow_group *grp;
5263 : : struct mlx5dr_match_template *mt[MLX5_HW_TBL_MAX_ITEM_TEMPLATE];
5264 : : struct mlx5dr_action_template *at[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
5265 : 0 : const struct rte_flow_template_table_attr *attr = &table_cfg->attr;
5266 : 0 : struct rte_flow_attr flow_attr = attr->flow_attr;
5267 : 0 : uint32_t specialize = table_cfg->attr.specialize;
5268 : 0 : struct mlx5_flow_cb_ctx ctx = {
5269 : : .dev = dev,
5270 : : .error = &sub_error,
5271 : : .data = &flow_attr,
5272 : : .data2 = &specialize,
5273 : : };
5274 : 0 : struct mlx5_indexed_pool_config cfg = {
5275 : : .trunk_size = 1 << 12,
5276 : : .per_core_cache = 1 << 13,
5277 : : .need_lock = 1,
5278 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
5279 : : .malloc = mlx5_malloc,
5280 : : .free = mlx5_free,
5281 : : .type = "mlx5_hw_table_flow",
5282 : : };
5283 : : struct mlx5_list_entry *ge;
5284 : : uint32_t i = 0, max_tpl = MLX5_HW_TBL_MAX_ITEM_TEMPLATE;
5285 [ # # ]: 0 : uint32_t nb_flows = rte_align32pow2(attr->nb_flows);
5286 : 0 : bool port_started = !!dev->data->dev_started;
5287 : : bool rpool_needed;
5288 : : size_t tbl_mem_size;
5289 : : enum mlx5dr_table_type table_type;
5290 : : int err;
5291 : :
5292 [ # # ]: 0 : if (!flow_hw_validate_table_domain(&attr->flow_attr)) {
5293 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR,
5294 : : NULL, "invalid table domain attributes");
5295 : 0 : return NULL;
5296 : : }
5297 [ # # ]: 0 : for (i = 0; i < nb_item_templates; i++) {
5298 : : const struct rte_flow_pattern_template_attr *pt_attr =
5299 : 0 : &item_templates[i]->attr;
5300 : : bool match = flow_hw_validate_template_domain(&attr->flow_attr,
5301 : 0 : pt_attr->ingress,
5302 : 0 : pt_attr->egress,
5303 [ # # ]: 0 : pt_attr->transfer);
5304 [ # # ]: 0 : if (!match) {
5305 : 0 : rte_flow_error_set(error, EINVAL,
5306 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5307 : : NULL, "pattern template domain does not match table");
5308 : 0 : return NULL;
5309 : : }
5310 [ # # # # ]: 0 : if (item_templates[i]->item_flags & MLX5_FLOW_LAYER_ECPRI &&
5311 : 0 : !mlx5_flex_parser_ecpri_exist(dev))
5312 [ # # ]: 0 : if (mlx5_flex_parser_ecpri_alloc(dev)) {
5313 : 0 : rte_flow_error_set(error, EIO,
5314 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5315 : : NULL,
5316 : : "failed to create Flex parser "
5317 : : "profile for ECPRI");
5318 : 0 : goto error;
5319 : : }
5320 : : }
5321 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
5322 : 0 : const struct rte_flow_actions_template *at = action_templates[i];
5323 : : bool match = flow_hw_validate_template_domain(&attr->flow_attr,
5324 : 0 : at->attr.ingress,
5325 : 0 : at->attr.egress,
5326 [ # # ]: 0 : at->attr.transfer);
5327 [ # # ]: 0 : if (!match) {
5328 : 0 : rte_flow_error_set(error, EINVAL,
5329 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5330 : : NULL, "action template domain does not match table");
5331 : 0 : return NULL;
5332 : : }
5333 : : }
5334 : : /* HWS layer accepts only 1 item template with root table. */
5335 [ # # ]: 0 : if (!attr->flow_attr.group)
5336 : : max_tpl = 1;
5337 : 0 : cfg.max_idx = nb_flows;
5338 [ # # ]: 0 : cfg.size = !rte_flow_template_table_resizable(dev->data->port_id, attr) ?
5339 : : mlx5_flow_hw_entry_size() :
5340 : : mlx5_flow_hw_auxed_entry_size();
5341 : : /* For table has very limited flows, disable cache. */
5342 [ # # ]: 0 : if (nb_flows < cfg.trunk_size) {
5343 : 0 : cfg.per_core_cache = 0;
5344 : 0 : cfg.trunk_size = nb_flows;
5345 [ # # ]: 0 : } else if (nb_flows <= MLX5_HW_IPOOL_SIZE_THRESHOLD) {
5346 : 0 : cfg.per_core_cache = MLX5_HW_IPOOL_CACHE_MIN;
5347 : : }
5348 : : /* Check if we requires too many templates. */
5349 [ # # # # ]: 0 : if (nb_item_templates > max_tpl ||
5350 : : nb_action_templates > MLX5_HW_TBL_MAX_ACTION_TEMPLATE) {
5351 : 0 : rte_errno = EINVAL;
5352 : 0 : goto error;
5353 : : }
5354 : : /*
5355 : : * Amount of memory required for rte_flow_template_table struct:
5356 : : * - Size of the struct itself.
5357 : : * - VLA of DR rule action containers at the end =
5358 : : * number of actions templates * number of queues * size of DR rule actions container.
5359 : : */
5360 : : tbl_mem_size = sizeof(*tbl);
5361 : 0 : tbl_mem_size += nb_action_templates * priv->nb_queue * sizeof(tbl->rule_acts[0]);
5362 : : /* Allocate the table memory. */
5363 : 0 : tbl = mlx5_malloc(MLX5_MEM_ZERO, tbl_mem_size, RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
5364 [ # # ]: 0 : if (!tbl)
5365 : 0 : goto error;
5366 : 0 : tbl->cfg = *table_cfg;
5367 : : /* Allocate flow indexed pool. */
5368 : 0 : tbl->flow_pool = mlx5_ipool_create(&cfg);
5369 [ # # ]: 0 : if (!tbl->flow_pool)
5370 : 0 : goto error;
5371 : : /* Allocate table of auxiliary flow rule structs. */
5372 : 0 : tbl->flow_aux = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct rte_flow_hw_aux) * nb_flows,
5373 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
5374 [ # # ]: 0 : if (!tbl->flow_aux)
5375 : 0 : goto error;
5376 : : /* Register the flow group. */
5377 : 0 : ge = mlx5_hlist_register(priv->sh->groups, attr->flow_attr.group, &ctx);
5378 [ # # ]: 0 : if (!ge)
5379 : 0 : goto error;
5380 : : grp = container_of(ge, struct mlx5_flow_group, entry);
5381 : : /* Verify unified fdb sub domains consistency */
5382 : 0 : table_type = get_mlx5dr_table_type(&flow_attr, specialize, unified_fdb);
5383 [ # # ]: 0 : if (table_type != grp->type) {
5384 : 0 : DRV_LOG(ERR,
5385 : : "Group %u table type mismatch: group type is fixed on first use. "
5386 : : "This table requires %s but group was first used as %s. "
5387 : : "Create tables with transfer wire_orig or vf_orig before tables jumping to it.",
5388 : : grp->group_id,
5389 : : mlx5dr_table_type_name(table_type),
5390 : : mlx5dr_table_type_name(grp->type));
5391 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5392 : : NULL,
5393 : : "group table type mismatch: type is fixed on first use; "
5394 : : "create transfer wire_orig/vf_orig tables before tables jumping to it");
5395 : 0 : rte_errno = EINVAL;
5396 : 0 : goto error;
5397 : : }
5398 : 0 : tbl->grp = grp;
5399 : : /* Prepare matcher information. */
5400 : 0 : matcher_attr.resizable = !!rte_flow_template_table_resizable
5401 : 0 : (dev->data->port_id, &table_cfg->attr);
5402 : 0 : matcher_attr.optimize_flow_src = MLX5DR_MATCHER_FLOW_SRC_ANY;
5403 : 0 : matcher_attr.priority = attr->flow_attr.priority;
5404 : 0 : matcher_attr.optimize_using_rule_idx = true;
5405 : 0 : matcher_attr.mode = MLX5DR_MATCHER_RESOURCE_MODE_RULE;
5406 [ # # ]: 0 : matcher_attr.insert_mode = flow_hw_matcher_insert_mode_get(attr->insertion_type);
5407 [ # # ]: 0 : if (matcher_attr.insert_mode == MLX5DR_MATCHER_INSERT_BY_INDEX) {
5408 [ # # ]: 0 : if (attr->insertion_type == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN) {
5409 : 0 : matcher_attr.isolated = true;
5410 : 0 : matcher_attr.match_mode = MLX5DR_MATCHER_MATCH_MODE_DEFAULT;
5411 : : } else {
5412 : 0 : matcher_attr.isolated = false;
5413 : 0 : matcher_attr.match_mode = MLX5DR_MATCHER_MATCH_MODE_ALWAYS_HIT;
5414 : : }
5415 : : }
5416 [ # # ]: 0 : if (attr->hash_func == RTE_FLOW_TABLE_HASH_FUNC_CRC16) {
5417 : 0 : DRV_LOG(ERR, "16-bit checksum hash type is not supported");
5418 : 0 : rte_errno = ENOTSUP;
5419 : 0 : goto it_error;
5420 : : }
5421 [ # # ]: 0 : matcher_attr.distribute_mode = flow_hw_matcher_distribute_mode_get(attr->hash_func);
5422 : 0 : matcher_attr.rule.num_log = rte_log2_u32(nb_flows);
5423 : : /* Parse hints information. */
5424 [ # # ]: 0 : if (attr->specialize) {
5425 : : uint32_t val = RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG |
5426 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG;
5427 : :
5428 [ # # ]: 0 : if ((attr->specialize & val) == val) {
5429 : 0 : DRV_LOG(ERR, "Invalid hint value %x",
5430 : : attr->specialize);
5431 : 0 : rte_errno = EINVAL;
5432 : 0 : goto it_error;
5433 : : }
5434 [ # # ]: 0 : if (attr->specialize &
5435 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_WIRE_ORIG) {
5436 : 0 : matcher_attr.optimize_flow_src =
5437 : : MLX5DR_MATCHER_FLOW_SRC_WIRE;
5438 [ # # ]: 0 : } else if (attr->specialize &
5439 : : RTE_FLOW_TABLE_SPECIALIZE_TRANSFER_VPORT_ORIG) {
5440 : 0 : matcher_attr.optimize_flow_src =
5441 : : MLX5DR_MATCHER_FLOW_SRC_VPORT;
5442 : : }
5443 : : }
5444 : : /* Build the item template. */
5445 [ # # ]: 0 : for (i = 0; i < nb_item_templates; i++) {
5446 : : uint32_t ret;
5447 : :
5448 [ # # # # ]: 0 : if ((flow_attr.ingress && !item_templates[i]->attr.ingress) ||
5449 [ # # # # ]: 0 : (flow_attr.egress && !item_templates[i]->attr.egress) ||
5450 [ # # # # ]: 0 : (flow_attr.transfer && !item_templates[i]->attr.transfer)) {
5451 : 0 : DRV_LOG(ERR, "pattern template and template table attribute mismatch");
5452 : 0 : rte_errno = EINVAL;
5453 : 0 : goto it_error;
5454 : : }
5455 [ # # ]: 0 : if (item_templates[i]->item_flags & MLX5_FLOW_ITEM_COMPARE)
5456 : 0 : matcher_attr.mode = MLX5DR_MATCHER_RESOURCE_MODE_HTABLE;
5457 : 0 : ret = rte_atomic_fetch_add_explicit(&item_templates[i]->refcnt, 1,
5458 : : rte_memory_order_relaxed) + 1;
5459 [ # # ]: 0 : if (ret <= 1) {
5460 : 0 : rte_errno = EINVAL;
5461 : 0 : goto it_error;
5462 : : }
5463 : 0 : mt[i] = item_templates[i]->mt;
5464 : 0 : tbl->its[i] = item_templates[i];
5465 : : }
5466 : 0 : tbl->nb_item_templates = nb_item_templates;
5467 : : /* Build the action template. */
5468 : 0 : err = mlx5_hw_build_template_table(dev, nb_action_templates,
5469 : : action_templates, at, tbl, &sub_error);
5470 [ # # ]: 0 : if (err) {
5471 : : i = nb_item_templates;
5472 : 0 : goto it_error;
5473 : : }
5474 : 0 : tbl->matcher_info[0].matcher = mlx5dr_matcher_create
5475 : 0 : (tbl->grp->tbl, mt, nb_item_templates, at, nb_action_templates, &matcher_attr);
5476 [ # # ]: 0 : if (!tbl->matcher_info[0].matcher)
5477 : 0 : goto at_error;
5478 : 0 : tbl->matcher_attr = matcher_attr;
5479 : 0 : tbl->type = table_type;
5480 [ # # ]: 0 : if (matcher_attr.isolated) {
5481 : 0 : jump_attr.matcher = tbl->matcher_info[0].matcher;
5482 : 0 : tbl->matcher_info[0].jump = mlx5dr_action_create_jump_to_matcher(priv->dr_ctx,
5483 : 0 : &jump_attr, mlx5_hw_act_flag[!!attr->flow_attr.group][tbl->type]);
5484 [ # # ]: 0 : if (!tbl->matcher_info[0].jump)
5485 : 0 : goto jtm_error;
5486 : : }
5487 : : /*
5488 : : * Only the matcher supports update and needs more than 1 WQE, an additional
5489 : : * index is needed. Or else the flow index can be reused.
5490 : : */
5491 [ # # # # ]: 0 : rpool_needed = mlx5dr_matcher_is_updatable(tbl->matcher_info[0].matcher) &&
5492 : 0 : mlx5dr_matcher_is_dependent(tbl->matcher_info[0].matcher);
5493 [ # # ]: 0 : if (rpool_needed) {
5494 : : /* Allocate rule indexed pool. */
5495 : 0 : cfg.size = 0;
5496 : 0 : cfg.type = "mlx5_hw_table_rule";
5497 : 0 : cfg.max_idx += priv->hw_q[0].size;
5498 : 0 : tbl->resource = mlx5_ipool_create(&cfg);
5499 [ # # ]: 0 : if (!tbl->resource)
5500 : 0 : goto res_error;
5501 : : }
5502 [ # # ]: 0 : if (port_started)
5503 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
5504 : : else
5505 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl_ongo, tbl, next);
5506 : : rte_rwlock_init(&tbl->matcher_replace_rwlk);
5507 : 0 : return tbl;
5508 : : res_error:
5509 [ # # ]: 0 : if (tbl->matcher_info[0].jump)
5510 : 0 : mlx5dr_action_destroy(tbl->matcher_info[0].jump);
5511 : 0 : jtm_error:
5512 [ # # ]: 0 : if (tbl->matcher_info[0].matcher)
5513 : 0 : (void)mlx5dr_matcher_destroy(tbl->matcher_info[0].matcher);
5514 : 0 : at_error:
5515 [ # # ]: 0 : for (i = 0; i < nb_action_templates; i++) {
5516 : 0 : __flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
5517 : 0 : rte_atomic_fetch_sub_explicit(&action_templates[i]->refcnt,
5518 : : 1, rte_memory_order_relaxed);
5519 : : }
5520 : : i = nb_item_templates;
5521 : : it_error:
5522 [ # # ]: 0 : while (i--)
5523 : 0 : rte_atomic_fetch_sub_explicit(&item_templates[i]->refcnt,
5524 : : 1, rte_memory_order_relaxed);
5525 : 0 : error:
5526 : 0 : err = rte_errno;
5527 [ # # ]: 0 : if (tbl) {
5528 [ # # ]: 0 : if (tbl->grp)
5529 : 0 : mlx5_hlist_unregister(priv->sh->groups,
5530 : : &tbl->grp->entry);
5531 [ # # ]: 0 : if (tbl->flow_aux)
5532 : 0 : mlx5_free(tbl->flow_aux);
5533 [ # # ]: 0 : if (tbl->flow_pool)
5534 : 0 : mlx5_ipool_destroy(tbl->flow_pool);
5535 : 0 : mlx5_free(tbl);
5536 : : }
5537 [ # # ]: 0 : if (error != NULL) {
5538 [ # # ]: 0 : if (sub_error.type == RTE_FLOW_ERROR_TYPE_NONE)
5539 : 0 : rte_flow_error_set(error, err, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5540 : : "Failed to create template table");
5541 : : else
5542 : : rte_memcpy(error, &sub_error, sizeof(sub_error));
5543 : : }
5544 : : return NULL;
5545 : : }
5546 : :
5547 : : /**
5548 : : * Update flow template table.
5549 : : *
5550 : : * @param[in] dev
5551 : : * Pointer to the rte_eth_dev structure.
5552 : : * @param[out] error
5553 : : * Pointer to error structure.
5554 : : *
5555 : : * @return
5556 : : * 0 on success, negative value otherwise and rte_errno is set.
5557 : : */
5558 : : int
5559 : 0 : mlx5_flow_hw_table_update(struct rte_eth_dev *dev,
5560 : : struct rte_flow_error *error)
5561 : : {
5562 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5563 : : struct rte_flow_template_table *tbl;
5564 : :
5565 [ # # ]: 0 : while ((tbl = LIST_FIRST(&priv->flow_hw_tbl_ongo)) != NULL) {
5566 [ # # ]: 0 : if (flow_hw_translate_all_actions_templates(dev, tbl, error))
5567 : : return -1;
5568 [ # # ]: 0 : LIST_REMOVE(tbl, next);
5569 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
5570 : : }
5571 : : return 0;
5572 : : }
5573 : :
5574 : : static inline int
5575 : 0 : __translate_group(struct rte_eth_dev *dev,
5576 : : const struct rte_flow_attr *flow_attr,
5577 : : bool external,
5578 : : uint32_t group,
5579 : : uint32_t *table_group,
5580 : : struct rte_flow_error *error)
5581 : : {
5582 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5583 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5584 : :
5585 [ # # ]: 0 : if (config->dv_esw_en &&
5586 [ # # # # ]: 0 : priv->fdb_def_rule &&
5587 [ # # ]: 0 : external &&
5588 : : flow_attr->transfer) {
5589 [ # # ]: 0 : if (group > MLX5_HW_MAX_TRANSFER_GROUP)
5590 : 0 : return rte_flow_error_set(error, EINVAL,
5591 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5592 : : NULL,
5593 : : "group index not supported");
5594 : 0 : *table_group = group + 1;
5595 [ # # # # ]: 0 : } else if (config->dv_esw_en &&
5596 [ # # ]: 0 : external &&
5597 : : flow_attr->egress) {
5598 : : /*
5599 : : * On E-Switch setups, default egress flow rules are inserted to allow
5600 : : * representor matching and/or preserving metadata across steering domains.
5601 : : * These flow rules are inserted in group 0 and this group is reserved by PMD
5602 : : * for these purposes.
5603 : : *
5604 : : * Representor matching is always enabled, so the group provided by the user
5605 : : * must be incremented to avoid inserting flow rules 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
11580 : 0 : flow_hw_get_ctrl_rx_nb_flows(struct rte_eth_dev *dev,
11581 : : enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
11582 : : {
11583 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11584 : 0 : uint32_t max_uc_mac_addrs = priv->sh->dev_cap.max_uc_mac_addrs;
11585 : :
11586 [ # # # # : 0 : switch (eth_pattern_type) {
# ]
11587 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
11588 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
11589 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
11590 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
11591 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
11592 : : return 1;
11593 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
11594 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
11595 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
11596 : 0 : return MLX5_MAX_VLAN_IDS;
11597 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
11598 : 0 : return max_uc_mac_addrs;
11599 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
11600 : 0 : return max_uc_mac_addrs * MLX5_MAX_VLAN_IDS;
11601 : 0 : default:
11602 : : MLX5_ASSERT(false);
11603 : 0 : return 0;
11604 : : }
11605 : : }
11606 : :
11607 : : static struct rte_flow_template_table_attr
11608 : : flow_hw_get_ctrl_rx_table_attr(struct rte_eth_dev *dev,
11609 : : enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
11610 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11611 : : {
11612 : 0 : return (struct rte_flow_template_table_attr){
11613 : : .flow_attr = {
11614 : : .group = 0,
11615 : 0 : .priority = ctrl_rx_rss_priority_map[rss_type],
11616 : : .ingress = 1,
11617 : : },
11618 : 0 : .nb_flows = flow_hw_get_ctrl_rx_nb_flows(dev, eth_pattern_type),
11619 : : };
11620 : : }
11621 : :
11622 : : static struct rte_flow_item
11623 : : flow_hw_get_ctrl_rx_eth_item(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
11624 : : {
11625 : : struct rte_flow_item item = {
11626 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
11627 : : .mask = NULL,
11628 : : };
11629 : :
11630 : 0 : switch (eth_pattern_type) {
11631 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
11632 : : item.mask = &ctrl_rx_eth_promisc_mask;
11633 : : break;
11634 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
11635 : : item.mask = &ctrl_rx_eth_mcast_mask;
11636 : 0 : break;
11637 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
11638 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
11639 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
11640 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
11641 : : item.mask = &ctrl_rx_eth_dmac_mask;
11642 : 0 : break;
11643 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
11644 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
11645 : : item.mask = &ctrl_rx_eth_ipv4_mcast_mask;
11646 : 0 : break;
11647 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
11648 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
11649 : : item.mask = &ctrl_rx_eth_ipv6_mcast_mask;
11650 : 0 : break;
11651 : 0 : default:
11652 : : /* Should not reach here - ETH mask must be present. */
11653 : : item.type = RTE_FLOW_ITEM_TYPE_END;
11654 : : MLX5_ASSERT(false);
11655 : 0 : break;
11656 : : }
11657 : 0 : return item;
11658 : : }
11659 : :
11660 : : static struct rte_flow_item
11661 : : flow_hw_get_ctrl_rx_vlan_item(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
11662 : : {
11663 : : struct rte_flow_item item = {
11664 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
11665 : : .mask = NULL,
11666 : : };
11667 : :
11668 [ # # ]: 0 : switch (eth_pattern_type) {
11669 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
11670 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
11671 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
11672 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
11673 : : item.type = RTE_FLOW_ITEM_TYPE_VLAN;
11674 : : item.mask = &rte_flow_item_vlan_mask;
11675 : 0 : break;
11676 : : default:
11677 : : /* Nothing to update. */
11678 : : break;
11679 : : }
11680 : 0 : return item;
11681 : : }
11682 : :
11683 : : static struct rte_flow_item
11684 : : flow_hw_get_ctrl_rx_l3_item(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11685 : : {
11686 : : struct rte_flow_item item = {
11687 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
11688 : : .mask = NULL,
11689 : : };
11690 : :
11691 [ # # # ]: 0 : switch (rss_type) {
11692 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4:
11693 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
11694 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
11695 : : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
11696 : 0 : break;
11697 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6:
11698 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
11699 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
11700 : : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
11701 : 0 : break;
11702 : : default:
11703 : : /* Nothing to update. */
11704 : : break;
11705 : : }
11706 : 0 : return item;
11707 : : }
11708 : :
11709 : : static struct rte_flow_item
11710 : : flow_hw_get_ctrl_rx_l4_item(const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11711 : : {
11712 : : struct rte_flow_item item = {
11713 : : .type = RTE_FLOW_ITEM_TYPE_VOID,
11714 : : .mask = NULL,
11715 : : };
11716 : :
11717 [ # # # ]: 0 : switch (rss_type) {
11718 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP:
11719 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP:
11720 : : item.type = RTE_FLOW_ITEM_TYPE_UDP;
11721 : 0 : break;
11722 : 0 : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP:
11723 : : case MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP:
11724 : : item.type = RTE_FLOW_ITEM_TYPE_TCP;
11725 : 0 : break;
11726 : : default:
11727 : : /* Nothing to update. */
11728 : : break;
11729 : : }
11730 : 0 : return item;
11731 : : }
11732 : :
11733 : : static struct rte_flow_pattern_template *
11734 : 0 : flow_hw_create_ctrl_rx_pattern_template
11735 : : (struct rte_eth_dev *dev,
11736 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
11737 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
11738 : : {
11739 : 0 : const struct rte_flow_pattern_template_attr attr = {
11740 : : .relaxed_matching = 0,
11741 : : .ingress = 1,
11742 : : };
11743 [ # # # # : 0 : struct rte_flow_item items[] = {
# # ]
11744 : : /* Matching patterns */
11745 : : flow_hw_get_ctrl_rx_eth_item(eth_pattern_type),
11746 : : flow_hw_get_ctrl_rx_vlan_item(eth_pattern_type),
11747 : : flow_hw_get_ctrl_rx_l3_item(rss_type),
11748 : : flow_hw_get_ctrl_rx_l4_item(rss_type),
11749 : : /* Terminate pattern */
11750 : : { .type = RTE_FLOW_ITEM_TYPE_END }
11751 : : };
11752 : :
11753 : 0 : return flow_hw_pattern_template_create(dev, &attr, items, false, NULL);
11754 : : }
11755 : :
11756 : : int
11757 : 0 : mlx5_flow_hw_create_ctrl_rx_tables(struct rte_eth_dev *dev)
11758 : : {
11759 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11760 : : unsigned int i;
11761 : : unsigned int j;
11762 : : int ret;
11763 : :
11764 : : MLX5_ASSERT(!priv->hw_ctrl_rx);
11765 : 0 : priv->hw_ctrl_rx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*priv->hw_ctrl_rx),
11766 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
11767 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
11768 : 0 : DRV_LOG(ERR, "Failed to allocate memory for Rx control flow tables");
11769 : 0 : rte_errno = ENOMEM;
11770 : 0 : return -rte_errno;
11771 : : }
11772 : : /* Create all pattern template variants. */
11773 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
11774 : : enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type = i;
11775 : :
11776 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
11777 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
11778 : : struct rte_flow_template_table_attr attr;
11779 : : struct rte_flow_pattern_template *pt;
11780 : :
11781 : : attr = flow_hw_get_ctrl_rx_table_attr(dev, eth_pattern_type,
11782 : : rss_type);
11783 : 0 : pt = flow_hw_create_ctrl_rx_pattern_template(dev, eth_pattern_type,
11784 : : rss_type);
11785 [ # # ]: 0 : if (!pt)
11786 : 0 : goto err;
11787 : 0 : priv->hw_ctrl_rx->tables[i][j].attr = attr;
11788 : 0 : priv->hw_ctrl_rx->tables[i][j].pt = pt;
11789 : : }
11790 : : }
11791 : : return 0;
11792 : : err:
11793 : 0 : ret = rte_errno;
11794 : 0 : return -ret;
11795 : : }
11796 : :
11797 : : void
11798 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev)
11799 : : {
11800 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11801 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
11802 : : unsigned int i;
11803 : : unsigned int j;
11804 : :
11805 [ # # ]: 0 : if (!priv->dr_ctx)
11806 : : return;
11807 [ # # ]: 0 : if (!priv->hw_ctrl_rx)
11808 : : return;
11809 : : hw_ctrl_rx = priv->hw_ctrl_rx;
11810 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
11811 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
11812 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[i][j];
11813 : :
11814 [ # # ]: 0 : if (tmpls->tbl) {
11815 : 0 : claim_zero(flow_hw_table_destroy(dev, tmpls->tbl, NULL));
11816 : 0 : tmpls->tbl = NULL;
11817 : : }
11818 : : }
11819 : : }
11820 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
11821 [ # # ]: 0 : if (hw_ctrl_rx->rss[j]) {
11822 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, hw_ctrl_rx->rss[j], NULL));
11823 : 0 : hw_ctrl_rx->rss[j] = NULL;
11824 : : }
11825 : : }
11826 : : }
11827 : :
11828 : : /**
11829 : : * Copy the provided HWS configuration to a newly allocated buffer.
11830 : : *
11831 : : * @param[in] port_attr
11832 : : * Port configuration attributes.
11833 : : * @param[in] nb_queue
11834 : : * Number of queue.
11835 : : * @param[in] queue_attr
11836 : : * Array that holds attributes for each flow queue.
11837 : : * @param[in] nt_mode
11838 : : * Non template mode.
11839 : : *
11840 : : * @return
11841 : : * Pointer to copied HWS configuration is returned on success.
11842 : : * Otherwise, NULL is returned and rte_errno is set.
11843 : : */
11844 : : static struct mlx5_flow_hw_attr *
11845 : 0 : flow_hw_alloc_copy_config(const struct rte_flow_port_attr *port_attr,
11846 : : const uint16_t nb_queue,
11847 : : const struct rte_flow_queue_attr *queue_attr[],
11848 : : bool nt_mode,
11849 : : struct rte_flow_error *error)
11850 : : {
11851 : : struct mlx5_flow_hw_attr *hw_attr;
11852 : : size_t hw_attr_size;
11853 : : unsigned int i;
11854 : :
11855 : 0 : hw_attr_size = sizeof(*hw_attr) + nb_queue * sizeof(*hw_attr->queue_attr);
11856 : 0 : hw_attr = mlx5_malloc(MLX5_MEM_ZERO, hw_attr_size, 0, SOCKET_ID_ANY);
11857 [ # # ]: 0 : if (!hw_attr) {
11858 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11859 : : "Not enough memory to store configuration");
11860 : 0 : return NULL;
11861 : : }
11862 : 0 : memcpy(&hw_attr->port_attr, port_attr, sizeof(*port_attr));
11863 : 0 : hw_attr->nb_queue = nb_queue;
11864 : : /* Queue attributes are placed after the mlx5_flow_hw_attr. */
11865 : 0 : hw_attr->queue_attr = (struct rte_flow_queue_attr *)(hw_attr + 1);
11866 [ # # ]: 0 : for (i = 0; i < nb_queue; ++i)
11867 : 0 : memcpy(&hw_attr->queue_attr[i], queue_attr[i], sizeof(hw_attr->queue_attr[i]));
11868 : 0 : hw_attr->nt_mode = nt_mode;
11869 : 0 : return hw_attr;
11870 : : }
11871 : :
11872 : : /**
11873 : : * Compares the preserved HWS configuration with the provided one.
11874 : : *
11875 : : * @param[in] hw_attr
11876 : : * Pointer to preserved HWS configuration.
11877 : : * @param[in] new_pa
11878 : : * Port configuration attributes to compare.
11879 : : * @param[in] new_nbq
11880 : : * Number of queues to compare.
11881 : : * @param[in] new_qa
11882 : : * Array that holds attributes for each flow queue.
11883 : : *
11884 : : * @return
11885 : : * True if configurations are the same, false otherwise.
11886 : : */
11887 : : static bool
11888 : 0 : flow_hw_compare_config(const struct mlx5_flow_hw_attr *hw_attr,
11889 : : const struct rte_flow_port_attr *new_pa,
11890 : : const uint16_t new_nbq,
11891 : : const struct rte_flow_queue_attr *new_qa[])
11892 : : {
11893 : : const struct rte_flow_port_attr *old_pa = &hw_attr->port_attr;
11894 : 0 : const uint16_t old_nbq = hw_attr->nb_queue;
11895 : 0 : const struct rte_flow_queue_attr *old_qa = hw_attr->queue_attr;
11896 : : unsigned int i;
11897 : :
11898 [ # # ]: 0 : if (old_pa->nb_counters != new_pa->nb_counters ||
11899 [ # # ]: 0 : old_pa->nb_aging_objects != new_pa->nb_aging_objects ||
11900 [ # # ]: 0 : old_pa->nb_meters != new_pa->nb_meters ||
11901 [ # # ]: 0 : old_pa->nb_conn_tracks != new_pa->nb_conn_tracks ||
11902 [ # # ]: 0 : old_pa->flags != new_pa->flags)
11903 : : return false;
11904 [ # # ]: 0 : if (old_nbq != new_nbq)
11905 : : return false;
11906 [ # # ]: 0 : for (i = 0; i < old_nbq; ++i)
11907 [ # # ]: 0 : if (old_qa[i].size != new_qa[i]->size)
11908 : : return false;
11909 : : return true;
11910 : : }
11911 : :
11912 : : /*
11913 : : * No need to explicitly release drop action templates on port stop.
11914 : : * Drop action templates release with other action templates during
11915 : : * mlx5_dev_close -> flow_hw_resource_release -> flow_hw_actions_template_destroy
11916 : : */
11917 : : static void
11918 : 0 : flow_hw_action_template_drop_release(struct rte_eth_dev *dev)
11919 : : {
11920 : : int i;
11921 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11922 : :
11923 [ # # ]: 0 : for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) {
11924 [ # # ]: 0 : if (!priv->action_template_drop[i])
11925 : 0 : continue;
11926 : 0 : flow_hw_actions_template_destroy(dev,
11927 : : priv->action_template_drop[i],
11928 : : NULL);
11929 : 0 : priv->action_template_drop[i] = NULL;
11930 : : }
11931 : 0 : }
11932 : :
11933 : : static int
11934 : 0 : flow_hw_action_template_drop_init(struct rte_eth_dev *dev,
11935 : : struct rte_flow_error *error)
11936 : : {
11937 : : uint32_t i, from, to;
11938 : 0 : const struct rte_flow_action drop[2] = {
11939 : : [0] = { .type = RTE_FLOW_ACTION_TYPE_DROP },
11940 : : [1] = { .type = RTE_FLOW_ACTION_TYPE_END },
11941 : : };
11942 : : const struct rte_flow_action *actions = drop;
11943 : : const struct rte_flow_action *masks = drop;
11944 : 0 : const struct rte_flow_actions_template_attr attr[MLX5DR_TABLE_TYPE_MAX] = {
11945 : : [MLX5DR_TABLE_TYPE_NIC_RX] = { .ingress = 1 },
11946 : : [MLX5DR_TABLE_TYPE_NIC_TX] = { .egress = 1 },
11947 : : [MLX5DR_TABLE_TYPE_FDB] = { .transfer = 1 },
11948 : : [MLX5DR_TABLE_TYPE_FDB_RX] = { .transfer = 1 },
11949 : : [MLX5DR_TABLE_TYPE_FDB_TX] = { .transfer = 1 },
11950 : : [MLX5DR_TABLE_TYPE_FDB_UNIFIED] = { .transfer = 1 },
11951 : : };
11952 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11953 : :
11954 : : from = MLX5DR_TABLE_TYPE_NIC_RX;
11955 : : to = MLX5DR_TABLE_TYPE_NIC_TX;
11956 [ # # ]: 0 : for (i = from; i <= to; i++) {
11957 : 0 : priv->action_template_drop[i] =
11958 : 0 : flow_hw_actions_template_create(dev, &attr[i], actions, masks, error);
11959 [ # # ]: 0 : if (!priv->action_template_drop[i])
11960 : : return -1;
11961 : : }
11962 : :
11963 [ # # # # ]: 0 : if (!(priv->sh->config.dv_esw_en && priv->master))
11964 : : return 0;
11965 : :
11966 : : from = MLX5DR_TABLE_TYPE_FDB;
11967 [ # # ]: 0 : to = is_unified_fdb(priv) ? MLX5DR_TABLE_TYPE_FDB_UNIFIED : MLX5DR_TABLE_TYPE_FDB;
11968 [ # # ]: 0 : for (i = from; i <= to; i++) {
11969 : 0 : priv->action_template_drop[i] =
11970 : 0 : flow_hw_actions_template_create(dev, &attr[i], actions, masks, error);
11971 [ # # ]: 0 : if (!priv->action_template_drop[i])
11972 : : return -1;
11973 : : }
11974 : : return 0;
11975 : : }
11976 : :
11977 : : static void
11978 : 0 : __mlx5_flow_hw_resource_release(struct rte_eth_dev *dev, bool ctx_close)
11979 : : {
11980 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11981 : : struct rte_flow_template_table *tbl, *temp_tbl;
11982 : : struct rte_flow_pattern_template *it, *temp_it;
11983 : : struct rte_flow_actions_template *at, *temp_at;
11984 : : struct mlx5_flow_group *grp, *temp_grp;
11985 : : uint32_t i;
11986 : :
11987 : 0 : mlx5_flow_hw_rxq_flag_set(dev, false);
11988 : 0 : flow_hw_flush_all_ctrl_flows(dev);
11989 : 0 : flow_hw_cleanup_lacp_miss_tables(dev);
11990 : 0 : flow_hw_cleanup_ctrl_fdb_tables(dev);
11991 : 0 : flow_hw_cleanup_ctrl_nic_tables(dev);
11992 : 0 : flow_hw_cleanup_tx_repr_tagging(dev);
11993 : 0 : flow_hw_action_template_drop_release(dev);
11994 : 0 : grp = LIST_FIRST(&priv->flow_hw_grp);
11995 [ # # ]: 0 : while (grp) {
11996 : 0 : temp_grp = LIST_NEXT(grp, next);
11997 : 0 : claim_zero(flow_hw_group_unset_miss_group(dev, grp, NULL));
11998 : : grp = temp_grp;
11999 : : }
12000 : 0 : tbl = LIST_FIRST(&priv->flow_hw_tbl_ongo);
12001 [ # # ]: 0 : while (tbl) {
12002 : 0 : temp_tbl = LIST_NEXT(tbl, next);
12003 : 0 : claim_zero(flow_hw_table_destroy(dev, tbl, NULL));
12004 : : tbl = temp_tbl;
12005 : : }
12006 : 0 : tbl = LIST_FIRST(&priv->flow_hw_tbl);
12007 [ # # ]: 0 : while (tbl) {
12008 : 0 : temp_tbl = LIST_NEXT(tbl, next);
12009 : 0 : claim_zero(flow_hw_table_destroy(dev, tbl, NULL));
12010 : : tbl = temp_tbl;
12011 : : }
12012 : 0 : it = LIST_FIRST(&priv->flow_hw_itt);
12013 [ # # ]: 0 : while (it) {
12014 : 0 : temp_it = LIST_NEXT(it, next);
12015 : 0 : claim_zero(flow_hw_pattern_template_destroy(dev, it, NULL));
12016 : : it = temp_it;
12017 : : }
12018 : 0 : at = LIST_FIRST(&priv->flow_hw_at);
12019 [ # # ]: 0 : while (at) {
12020 : 0 : temp_at = LIST_NEXT(at, next);
12021 : 0 : claim_zero(flow_hw_actions_template_destroy(dev, at, NULL));
12022 : : at = temp_at;
12023 : : }
12024 : 0 : flow_hw_free_vport_actions(priv);
12025 [ # # ]: 0 : if (priv->acts_ipool) {
12026 : 0 : mlx5_ipool_destroy(priv->acts_ipool);
12027 : 0 : priv->acts_ipool = NULL;
12028 : : }
12029 [ # # ]: 0 : if (priv->hws_age_req)
12030 : 0 : mlx5_hws_age_pool_destroy(priv);
12031 [ # # # # ]: 0 : if (!priv->shared_host && priv->hws_cpool) {
12032 : 0 : mlx5_hws_cnt_pool_destroy(priv->sh, priv->hws_cpool);
12033 : 0 : priv->hws_cpool = NULL;
12034 : : }
12035 [ # # ]: 0 : if (priv->hws_ctpool) {
12036 : 0 : flow_hw_ct_pool_destroy(dev, priv->hws_ctpool);
12037 : 0 : priv->hws_ctpool = NULL;
12038 : : }
12039 [ # # ]: 0 : if (priv->ct_mng) {
12040 : : flow_hw_ct_mng_destroy(priv->ct_mng);
12041 : 0 : priv->ct_mng = NULL;
12042 : : }
12043 : 0 : mlx5_flow_quota_destroy(dev);
12044 : 0 : mlx5_hws_global_actions_cleanup(priv);
12045 [ # # ]: 0 : if (priv->hw_q) {
12046 [ # # ]: 0 : for (i = 0; i < priv->nb_queue; i++) {
12047 : 0 : struct mlx5_hw_q *hwq = &priv->hw_q[i];
12048 : 0 : rte_ring_free(hwq->indir_iq);
12049 : 0 : rte_ring_free(hwq->indir_cq);
12050 : 0 : rte_ring_free(hwq->flow_transfer_pending);
12051 : 0 : rte_ring_free(hwq->flow_transfer_completed);
12052 : : }
12053 : 0 : mlx5_free(priv->hw_q);
12054 : 0 : priv->hw_q = NULL;
12055 : : }
12056 [ # # ]: 0 : if (ctx_close) {
12057 [ # # ]: 0 : if (priv->dr_ctx) {
12058 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
12059 : 0 : priv->dr_ctx = NULL;
12060 : : }
12061 : : }
12062 [ # # ]: 0 : if (priv->shared_host) {
12063 : 0 : struct mlx5_priv *host_priv = priv->shared_host->data->dev_private;
12064 : 0 : rte_atomic_fetch_sub_explicit(&host_priv->shared_refcnt, 1,
12065 : : rte_memory_order_relaxed);
12066 : 0 : priv->shared_host = NULL;
12067 : : }
12068 [ # # ]: 0 : if (priv->hw_attr) {
12069 : 0 : mlx5_free(priv->hw_attr);
12070 : 0 : priv->hw_attr = NULL;
12071 : : }
12072 : 0 : priv->nb_queue = 0;
12073 : 0 : }
12074 : :
12075 : : static __rte_always_inline struct rte_ring *
12076 : : mlx5_hwq_ring_create(uint16_t port_id, uint32_t queue, uint32_t size, const char *str)
12077 : : {
12078 : : char mz_name[RTE_MEMZONE_NAMESIZE];
12079 : :
12080 : : snprintf(mz_name, sizeof(mz_name), "port_%u_%s_%u", port_id, str, queue);
12081 : 0 : return rte_ring_create(mz_name, size, SOCKET_ID_ANY,
12082 : : RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ);
12083 : : }
12084 : :
12085 : : static int
12086 : 0 : flow_hw_queue_setup_rings(struct rte_eth_dev *dev,
12087 : : uint16_t queue,
12088 : : uint32_t queue_size,
12089 : : bool nt_mode)
12090 : : {
12091 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12092 : :
12093 : : /* HWS queue info container must be already allocated. */
12094 : : MLX5_ASSERT(priv->hw_q != NULL);
12095 : :
12096 : : /* Notice ring name length is limited. */
12097 : 0 : priv->hw_q[queue].indir_cq = mlx5_hwq_ring_create
12098 : 0 : (dev->data->port_id, queue, queue_size, "indir_act_cq");
12099 [ # # ]: 0 : if (!priv->hw_q[queue].indir_cq) {
12100 : 0 : DRV_LOG(ERR, "port %u failed to allocate indir_act_cq ring for HWS",
12101 : : dev->data->port_id);
12102 : 0 : return -ENOMEM;
12103 : : }
12104 : :
12105 : 0 : priv->hw_q[queue].indir_iq = mlx5_hwq_ring_create
12106 : 0 : (dev->data->port_id, queue, queue_size, "indir_act_iq");
12107 [ # # ]: 0 : if (!priv->hw_q[queue].indir_iq) {
12108 : 0 : DRV_LOG(ERR, "port %u failed to allocate indir_act_iq ring for HWS",
12109 : : dev->data->port_id);
12110 : 0 : return -ENOMEM;
12111 : : }
12112 : :
12113 : : /*
12114 : : * Sync flow API does not require rings used for table resize handling,
12115 : : * because these rings are only used through async flow APIs.
12116 : : */
12117 [ # # ]: 0 : if (nt_mode)
12118 : : return 0;
12119 : :
12120 : 0 : priv->hw_q[queue].flow_transfer_pending = mlx5_hwq_ring_create
12121 : 0 : (dev->data->port_id, queue, queue_size, "tx_pending");
12122 [ # # ]: 0 : if (!priv->hw_q[queue].flow_transfer_pending) {
12123 : 0 : DRV_LOG(ERR, "port %u failed to allocate tx_pending ring for HWS",
12124 : : dev->data->port_id);
12125 : 0 : return -ENOMEM;
12126 : : }
12127 : :
12128 : 0 : priv->hw_q[queue].flow_transfer_completed = mlx5_hwq_ring_create
12129 : 0 : (dev->data->port_id, queue, queue_size, "tx_done");
12130 [ # # ]: 0 : if (!priv->hw_q[queue].flow_transfer_completed) {
12131 : 0 : DRV_LOG(ERR, "port %u failed to allocate tx_done ring for HWS",
12132 : : dev->data->port_id);
12133 : 0 : return -ENOMEM;
12134 : : }
12135 : :
12136 : : return 0;
12137 : : }
12138 : :
12139 : : static int
12140 : 0 : flow_hw_validate_attributes(const struct rte_flow_port_attr *port_attr,
12141 : : uint16_t nb_queue,
12142 : : const struct rte_flow_queue_attr *queue_attr[],
12143 : : bool nt_mode, struct rte_flow_error *error)
12144 : : {
12145 : : uint32_t size;
12146 : : unsigned int i;
12147 : :
12148 [ # # ]: 0 : if (port_attr == NULL)
12149 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12150 : : "Port attributes must be non-NULL");
12151 : :
12152 [ # # ]: 0 : if (nb_queue == 0 && !nt_mode)
12153 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12154 : : "At least one flow queue is required");
12155 : :
12156 [ # # ]: 0 : if (queue_attr == NULL)
12157 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12158 : : "Queue attributes must be non-NULL");
12159 : :
12160 : 0 : size = queue_attr[0]->size;
12161 [ # # ]: 0 : for (i = 1; i < nb_queue; ++i) {
12162 [ # # ]: 0 : if (queue_attr[i]->size != size)
12163 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12164 : : NULL,
12165 : : "All flow queues must have the same size");
12166 : : }
12167 : :
12168 : : return 0;
12169 : : }
12170 : :
12171 : : /**
12172 : : * Configure port HWS resources.
12173 : : *
12174 : : * @param[in] dev
12175 : : * Pointer to the rte_eth_dev structure.
12176 : : * @param[in] port_attr
12177 : : * Port configuration attributes.
12178 : : * @param[in] nb_queue
12179 : : * Number of queue.
12180 : : * @param[in] queue_attr
12181 : : * Array that holds attributes for each flow queue.
12182 : : * @param[in] nt_mode
12183 : : * Non-template mode.
12184 : : * @param[out] error
12185 : : * Pointer to error structure.
12186 : : *
12187 : : * @return
12188 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12189 : : */
12190 : : static int
12191 : 0 : __flow_hw_configure(struct rte_eth_dev *dev,
12192 : : const struct rte_flow_port_attr *port_attr,
12193 : : uint16_t nb_queue,
12194 : : const struct rte_flow_queue_attr *queue_attr[],
12195 : : bool nt_mode,
12196 : : struct rte_flow_error *error)
12197 : : {
12198 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12199 : : struct mlx5_priv *host_priv = NULL;
12200 : 0 : struct mlx5dr_context_attr dr_ctx_attr = {0};
12201 : : struct mlx5_hw_q *hw_q;
12202 : : struct mlx5_hw_q_job *job = NULL;
12203 : : uint32_t mem_size, i, j;
12204 : 0 : struct mlx5_indexed_pool_config cfg = {
12205 : : .size = sizeof(struct mlx5_action_construct_data),
12206 : : .trunk_size = 4096,
12207 : : .need_lock = 1,
12208 : 0 : .release_mem_en = !!priv->sh->config.reclaim_mode,
12209 : : .malloc = mlx5_malloc,
12210 : : .free = mlx5_free,
12211 : : .type = "mlx5_hw_action_construct_data",
12212 : : };
12213 : : /*
12214 : : * Adds one queue to be used by PMD.
12215 : : * The last queue will be used by the PMD.
12216 : : */
12217 : : uint16_t nb_q_updated = 0;
12218 : : struct rte_flow_queue_attr **_queue_attr = NULL;
12219 : 0 : struct rte_flow_queue_attr ctrl_queue_attr = {0};
12220 [ # # # # ]: 0 : bool is_proxy = !!(priv->sh->config.dv_esw_en && priv->master);
12221 : : int ret = 0;
12222 : : bool strict_queue = false;
12223 : :
12224 : 0 : error->type = RTE_FLOW_ERROR_TYPE_NONE;
12225 [ # # ]: 0 : if (mlx5dr_rule_get_handle_size() != MLX5_DR_RULE_SIZE) {
12226 : 0 : rte_errno = EINVAL;
12227 : 0 : goto err;
12228 : : }
12229 [ # # ]: 0 : if (flow_hw_validate_attributes(port_attr, nb_queue, queue_attr, nt_mode, error))
12230 : 0 : return -rte_errno;
12231 : : /*
12232 : : * Calling rte_flow_configure() again is allowed if
12233 : : * provided configuration matches the initially provided one,
12234 : : * or previous configuration was default non template one.
12235 : : */
12236 [ # # ]: 0 : if (priv->dr_ctx) {
12237 : : MLX5_ASSERT(priv->hw_attr != NULL);
12238 [ # # ]: 0 : for (i = 0; i < priv->nb_queue; i++) {
12239 : 0 : hw_q = &priv->hw_q[i];
12240 : : /* Make sure all queues are empty. */
12241 [ # # ]: 0 : if (hw_q->size != hw_q->job_idx) {
12242 : 0 : rte_errno = EBUSY;
12243 : 0 : goto err;
12244 : : }
12245 : : }
12246 : : /* If previous configuration was not default non template mode config. */
12247 [ # # ]: 0 : if (!priv->hw_attr->nt_mode) {
12248 [ # # ]: 0 : if (flow_hw_compare_config(priv->hw_attr, port_attr, nb_queue, queue_attr))
12249 : : return 0;
12250 : : else
12251 : 0 : return rte_flow_error_set(error, ENOTSUP,
12252 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12253 : : "Changing HWS configuration attributes "
12254 : : "is not supported");
12255 : : }
12256 : : /* Reconfiguration, need to release all resources from previous allocation. */
12257 : 0 : __mlx5_flow_hw_resource_release(dev, true);
12258 : : }
12259 : 0 : priv->hw_attr = flow_hw_alloc_copy_config(port_attr, nb_queue, queue_attr, nt_mode, error);
12260 [ # # ]: 0 : if (!priv->hw_attr) {
12261 : 0 : ret = -rte_errno;
12262 : 0 : goto err;
12263 : : }
12264 : 0 : ctrl_queue_attr.size = queue_attr[0]->size;
12265 : 0 : nb_q_updated = nb_queue + 1;
12266 : 0 : _queue_attr = mlx5_malloc(MLX5_MEM_ZERO,
12267 : : nb_q_updated *
12268 : : sizeof(struct rte_flow_queue_attr *),
12269 : : 64, SOCKET_ID_ANY);
12270 [ # # ]: 0 : if (!_queue_attr) {
12271 : 0 : rte_errno = ENOMEM;
12272 : 0 : goto err;
12273 : : }
12274 : :
12275 : 0 : memcpy(_queue_attr, queue_attr, sizeof(void *) * nb_queue);
12276 : 0 : _queue_attr[nb_queue] = &ctrl_queue_attr;
12277 : 0 : priv->acts_ipool = mlx5_ipool_create(&cfg);
12278 [ # # ]: 0 : if (!priv->acts_ipool)
12279 : 0 : goto err;
12280 : : /* Allocate the queue job descriptor LIFO. */
12281 : 0 : mem_size = sizeof(priv->hw_q[0]) * nb_q_updated;
12282 [ # # ]: 0 : for (i = 0; i < nb_q_updated; i++) {
12283 : 0 : mem_size += (sizeof(struct mlx5_hw_q_job *) +
12284 : 0 : sizeof(struct mlx5_hw_q_job)) * _queue_attr[i]->size;
12285 : : }
12286 : 0 : priv->hw_q = mlx5_malloc(MLX5_MEM_ZERO, mem_size,
12287 : : 64, SOCKET_ID_ANY);
12288 [ # # ]: 0 : if (!priv->hw_q) {
12289 : 0 : rte_errno = ENOMEM;
12290 : 0 : goto err;
12291 : : }
12292 [ # # ]: 0 : for (i = 0; i < nb_q_updated; i++) {
12293 : 0 : priv->hw_q[i].job_idx = _queue_attr[i]->size;
12294 : 0 : priv->hw_q[i].size = _queue_attr[i]->size;
12295 : 0 : priv->hw_q[i].ongoing_flow_ops = 0;
12296 [ # # ]: 0 : if (i == 0)
12297 : 0 : priv->hw_q[i].job = (struct mlx5_hw_q_job **)
12298 : 0 : &priv->hw_q[nb_q_updated];
12299 : : else
12300 : 0 : priv->hw_q[i].job = (struct mlx5_hw_q_job **)&job[_queue_attr[i - 1]->size];
12301 : 0 : job = (struct mlx5_hw_q_job *)
12302 : 0 : &priv->hw_q[i].job[_queue_attr[i]->size];
12303 [ # # ]: 0 : for (j = 0; j < _queue_attr[i]->size; j++)
12304 : 0 : priv->hw_q[i].job[j] = &job[j];
12305 : :
12306 [ # # ]: 0 : if (flow_hw_queue_setup_rings(dev, i, _queue_attr[i]->size, nt_mode) < 0)
12307 : 0 : goto err;
12308 : : }
12309 : 0 : dr_ctx_attr.pd = priv->sh->cdev->pd;
12310 : 0 : dr_ctx_attr.queues = nb_q_updated;
12311 : : /* Assign initial value of STC numbers for representors. */
12312 [ # # ]: 0 : if (priv->representor)
12313 : 0 : dr_ctx_attr.initial_log_stc_memory = MLX5_REPR_STC_MEMORY_LOG;
12314 : : /* Queue size should all be the same. Take the first one. */
12315 : 0 : dr_ctx_attr.queue_size = _queue_attr[0]->size;
12316 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_SHARE_INDIRECT) {
12317 : : struct rte_eth_dev *host_dev = NULL;
12318 : : uint16_t port_id;
12319 : :
12320 : : MLX5_ASSERT(rte_eth_dev_is_valid_port(port_attr->host_port_id));
12321 [ # # ]: 0 : if (is_proxy) {
12322 : 0 : DRV_LOG(ERR, "cross vHCA shared mode not supported "
12323 : : "for E-Switch confgiurations");
12324 : 0 : rte_errno = ENOTSUP;
12325 : 0 : goto err;
12326 : : }
12327 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
12328 [ # # ]: 0 : if (port_id == port_attr->host_port_id) {
12329 : 0 : host_dev = &rte_eth_devices[port_id];
12330 : 0 : break;
12331 : : }
12332 : : }
12333 [ # # ]: 0 : if (!host_dev || host_dev == dev ||
12334 [ # # # # ]: 0 : !host_dev->data || !host_dev->data->dev_private) {
12335 : 0 : DRV_LOG(ERR, "Invalid cross vHCA host port %u",
12336 : : port_attr->host_port_id);
12337 : 0 : rte_errno = EINVAL;
12338 : 0 : goto err;
12339 : : }
12340 : : host_priv = host_dev->data->dev_private;
12341 [ # # ]: 0 : if (host_priv->sh->cdev->ctx == priv->sh->cdev->ctx) {
12342 : 0 : DRV_LOG(ERR, "Sibling ports %u and %u do not "
12343 : : "require cross vHCA sharing mode",
12344 : : dev->data->port_id, port_attr->host_port_id);
12345 : 0 : rte_errno = EINVAL;
12346 : 0 : goto err;
12347 : : }
12348 [ # # ]: 0 : if (host_priv->shared_host) {
12349 : 0 : DRV_LOG(ERR, "Host port %u is not the sharing base",
12350 : : port_attr->host_port_id);
12351 : 0 : rte_errno = EINVAL;
12352 : 0 : goto err;
12353 : : }
12354 [ # # ]: 0 : if (port_attr->nb_counters ||
12355 [ # # ]: 0 : port_attr->nb_aging_objects ||
12356 [ # # ]: 0 : port_attr->nb_meters ||
12357 [ # # ]: 0 : port_attr->nb_conn_tracks) {
12358 : 0 : DRV_LOG(ERR,
12359 : : "Object numbers on guest port must be zeros");
12360 : 0 : rte_errno = EINVAL;
12361 : 0 : goto err;
12362 : : }
12363 : 0 : dr_ctx_attr.shared_ibv_ctx = host_priv->sh->cdev->ctx;
12364 : 0 : priv->shared_host = host_dev;
12365 : 0 : rte_atomic_fetch_add_explicit(&host_priv->shared_refcnt, 1,
12366 : : rte_memory_order_relaxed);
12367 : : }
12368 : : /* Set backward compatibale mode to support non template RTE FLOW API.*/
12369 : 0 : dr_ctx_attr.bwc = true;
12370 : 0 : priv->dr_ctx = mlx5dr_context_open(priv->sh->cdev->ctx, &dr_ctx_attr);
12371 : : /* rte_errno has been updated by HWS layer. */
12372 [ # # ]: 0 : if (!priv->dr_ctx)
12373 : 0 : goto err;
12374 : 0 : priv->nb_queue = nb_q_updated;
12375 : 0 : ret = flow_hw_action_template_drop_init(dev, error);
12376 [ # # ]: 0 : if (ret)
12377 : 0 : goto err;
12378 : : /* Initialize quotas */
12379 [ # # # # : 0 : if (port_attr->nb_quotas || (host_priv && host_priv->quota_ctx.devx_obj)) {
# # ]
12380 : 0 : ret = mlx5_flow_quota_init(dev, port_attr->nb_quotas);
12381 [ # # ]: 0 : if (ret) {
12382 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12383 : : "Failed to initialize quota.");
12384 : 0 : goto err;
12385 : : }
12386 : : }
12387 : : /* Initialize meter library*/
12388 [ # # # # : 0 : if (port_attr->nb_meters || (host_priv && host_priv->hws_mpool))
# # ]
12389 [ # # ]: 0 : if (mlx5_flow_meter_init(dev, port_attr->nb_meters, 0, 0, nb_q_updated))
12390 : 0 : goto err;
12391 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
12392 : 0 : ret = flow_hw_setup_tx_repr_tagging(dev, error);
12393 [ # # ]: 0 : if (ret)
12394 : 0 : goto err;
12395 : : }
12396 [ # # ]: 0 : if (mlx5_flow_lacp_miss_needed(dev)) {
12397 : 0 : ret = flow_hw_create_lacp_miss_tables(dev);
12398 [ # # ]: 0 : if (ret) {
12399 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12400 : : "Unable to create LACP miss flow tables");
12401 : 0 : goto err;
12402 : : }
12403 : : }
12404 [ # # ]: 0 : if (is_proxy) {
12405 : 0 : ret = flow_hw_create_vport_actions(priv);
12406 [ # # ]: 0 : if (ret) {
12407 : 0 : rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12408 : : NULL, "Failed to create vport actions.");
12409 : 0 : goto err;
12410 : : }
12411 : 0 : ret = flow_hw_create_fdb_ctrl_tables(dev, error);
12412 [ # # ]: 0 : if (ret) {
12413 : 0 : rte_errno = -ret;
12414 : 0 : goto err;
12415 : : }
12416 : : }
12417 [ # # ]: 0 : if (mlx5_vport_tx_metadata_passing_enabled(priv->sh)) {
12418 : 0 : ret = flow_hw_create_nic_ctrl_tables(dev, error);
12419 [ # # ]: 0 : if (ret != 0) {
12420 : 0 : rte_errno = -ret;
12421 : 0 : goto err;
12422 : : }
12423 : : }
12424 [ # # # # : 0 : if (port_attr->nb_conn_tracks || (host_priv && host_priv->hws_ctpool)) {
# # ]
12425 [ # # ]: 0 : if (mlx5_flow_ct_init(dev, port_attr->nb_conn_tracks, nb_q_updated))
12426 : 0 : goto err;
12427 : : }
12428 [ # # # # : 0 : if (port_attr->nb_counters || (host_priv && host_priv->hws_cpool)) {
# # ]
12429 [ # # ]: 0 : struct mlx5_hws_cnt_pool *hws_cpool = host_priv ? host_priv->hws_cpool : NULL;
12430 : :
12431 : 0 : ret = mlx5_hws_cnt_pool_create(dev, port_attr->nb_counters,
12432 : : nb_queue, hws_cpool, error);
12433 [ # # ]: 0 : if (ret)
12434 : 0 : goto err;
12435 : : }
12436 [ # # ]: 0 : if (port_attr->nb_aging_objects) {
12437 [ # # ]: 0 : if (port_attr->nb_counters == 0) {
12438 : : /*
12439 : : * Aging management uses counter. Number counters
12440 : : * requesting should take into account a counter for
12441 : : * each flow rules containing AGE without counter.
12442 : : */
12443 : 0 : DRV_LOG(ERR, "Port %u AGE objects are requested (%u) "
12444 : : "without counters requesting.",
12445 : : dev->data->port_id,
12446 : : port_attr->nb_aging_objects);
12447 : 0 : rte_errno = EINVAL;
12448 : 0 : goto err;
12449 : : }
12450 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_SHARE_INDIRECT) {
12451 : 0 : DRV_LOG(ERR, "Aging is not supported "
12452 : : "in cross vHCA sharing mode");
12453 : : ret = -ENOTSUP;
12454 : 0 : goto err;
12455 : : }
12456 : 0 : strict_queue = !!(port_attr->flags & RTE_FLOW_PORT_FLAG_STRICT_QUEUE);
12457 : 0 : ret = mlx5_hws_age_pool_init(dev, port_attr->nb_aging_objects,
12458 : : nb_queue, strict_queue);
12459 [ # # ]: 0 : if (ret < 0)
12460 : 0 : goto err;
12461 : : }
12462 : : if (_queue_attr)
12463 : 0 : mlx5_free(_queue_attr);
12464 [ # # ]: 0 : if (port_attr->flags & RTE_FLOW_PORT_FLAG_STRICT_QUEUE)
12465 : 0 : priv->hws_strict_queue = 1;
12466 : 0 : dev->flow_fp_ops = &mlx5_flow_hw_fp_ops;
12467 : 0 : return 0;
12468 : 0 : err:
12469 : 0 : __mlx5_flow_hw_resource_release(dev, true);
12470 [ # # ]: 0 : if (_queue_attr)
12471 : 0 : mlx5_free(_queue_attr);
12472 : : /* Do not overwrite the internal errno information. */
12473 [ # # # # ]: 0 : if (ret && error->type != RTE_FLOW_ERROR_TYPE_NONE)
12474 : : return ret;
12475 : 0 : return rte_flow_error_set(error, rte_errno,
12476 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12477 : : "fail to configure port");
12478 : : }
12479 : :
12480 : : /**
12481 : : * Configure port HWS resources.
12482 : : *
12483 : : * @param[in] dev
12484 : : * Pointer to the rte_eth_dev structure.
12485 : : * @param[in] port_attr
12486 : : * Port configuration attributes.
12487 : : * @param[in] nb_queue
12488 : : * Number of queue.
12489 : : * @param[in] queue_attr
12490 : : * Array that holds attributes for each flow queue.
12491 : : * @param[out] error
12492 : : * Pointer to error structure.
12493 : : *
12494 : : * @return
12495 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12496 : : */
12497 : : static int
12498 : 0 : flow_hw_configure(struct rte_eth_dev *dev,
12499 : : const struct rte_flow_port_attr *port_attr,
12500 : : uint16_t nb_queue,
12501 : : const struct rte_flow_queue_attr *queue_attr[],
12502 : : struct rte_flow_error *error)
12503 : : {
12504 : 0 : struct rte_flow_error shadow_error = {0, };
12505 : :
12506 [ # # ]: 0 : if (!error)
12507 : : error = &shadow_error;
12508 : 0 : return __flow_hw_configure(dev, port_attr, nb_queue, queue_attr, false, error);
12509 : : }
12510 : :
12511 : : /**
12512 : : * Release HWS resources.
12513 : : *
12514 : : * @param[in] dev
12515 : : * Pointer to the rte_eth_dev structure.
12516 : : */
12517 : : void
12518 : 0 : mlx5_flow_hw_resource_release(struct rte_eth_dev *dev)
12519 : : {
12520 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12521 : :
12522 [ # # ]: 0 : if (!priv->dr_ctx)
12523 : : return;
12524 : 0 : __mlx5_flow_hw_resource_release(dev, false);
12525 : : }
12526 : :
12527 : : /* Sets vport tag and mask, for given port, used in HWS rules. */
12528 : : void
12529 : 0 : mlx5_flow_hw_set_port_info(struct rte_eth_dev *dev)
12530 : : {
12531 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
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 : 0 : info->regc_mask = priv->vport_meta_mask;
12538 : 0 : info->regc_value = priv->vport_meta_tag;
12539 [ # # ]: 0 : info->vhca_id = priv->vport_vhca_id;
12540 [ # # ]: 0 : info->is_wire = mlx5_is_port_on_mpesw_device(priv) ? priv->mpesw_uplink : priv->master;
12541 : 0 : info->is_set = 1;
12542 : 0 : }
12543 : :
12544 : : /* Clears vport tag and mask used for HWS rules. */
12545 : : void
12546 : 0 : mlx5_flow_hw_clear_port_info(struct rte_eth_dev *dev)
12547 : : {
12548 : 0 : uint16_t port_id = dev->data->port_id;
12549 : : struct flow_hw_port_info *info;
12550 : :
12551 : : MLX5_ASSERT(port_id < RTE_MAX_ETHPORTS);
12552 : 0 : info = &mlx5_flow_hw_port_infos[port_id];
12553 : : memset(info, 0, sizeof(*info));
12554 : 0 : }
12555 : :
12556 : : static int
12557 : 0 : flow_hw_conntrack_destroy(struct rte_eth_dev *dev,
12558 : : uint32_t idx,
12559 : : struct rte_flow_error *error)
12560 : : {
12561 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12562 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12563 : : struct mlx5_aso_ct_action *ct;
12564 : :
12565 [ # # ]: 0 : if (priv->shared_host)
12566 : 0 : return rte_flow_error_set(error, ENOTSUP,
12567 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12568 : : NULL,
12569 : : "CT destruction is not allowed to guest port");
12570 : 0 : ct = mlx5_ipool_get(pool->cts, idx);
12571 [ # # ]: 0 : if (!ct) {
12572 : 0 : return rte_flow_error_set(error, EINVAL,
12573 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12574 : : NULL,
12575 : : "Invalid CT destruction index");
12576 : : }
12577 : 0 : rte_atomic_store_explicit(&ct->state, ASO_CONNTRACK_FREE,
12578 : : rte_memory_order_relaxed);
12579 : 0 : mlx5_ipool_free(pool->cts, idx);
12580 : 0 : return 0;
12581 : : }
12582 : :
12583 : : static int
12584 : 0 : flow_hw_conntrack_query(struct rte_eth_dev *dev, uint32_t queue, uint32_t idx,
12585 : : struct rte_flow_action_conntrack *profile,
12586 : : void *user_data, bool push,
12587 : : struct rte_flow_error *error)
12588 : : {
12589 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12590 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12591 : : struct mlx5_aso_ct_action *ct;
12592 : :
12593 [ # # ]: 0 : if (priv->shared_host)
12594 : 0 : return rte_flow_error_set(error, ENOTSUP,
12595 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12596 : : NULL,
12597 : : "CT query is not allowed to guest port");
12598 : 0 : ct = mlx5_ipool_get(pool->cts, idx);
12599 [ # # ]: 0 : if (!ct) {
12600 : 0 : return rte_flow_error_set(error, EINVAL,
12601 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12602 : : NULL,
12603 : : "Invalid CT query index");
12604 : : }
12605 : 0 : profile->peer_port = ct->peer;
12606 : 0 : profile->is_original_dir = ct->is_original;
12607 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, queue, ct, profile, user_data, push))
12608 : 0 : return rte_flow_error_set(error, EIO,
12609 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12610 : : NULL,
12611 : : "Failed to query CT context");
12612 : : return 0;
12613 : : }
12614 : :
12615 : :
12616 : : static int
12617 : 0 : flow_hw_conntrack_update(struct rte_eth_dev *dev, uint32_t queue,
12618 : : const struct rte_flow_modify_conntrack *action_conf,
12619 : : uint32_t idx, void *user_data, bool push,
12620 : : struct rte_flow_error *error)
12621 : : {
12622 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12623 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12624 : : struct mlx5_aso_ct_action *ct;
12625 : : const struct rte_flow_action_conntrack *new_prf;
12626 : : int ret = 0;
12627 : :
12628 [ # # ]: 0 : if (priv->shared_host)
12629 : 0 : return rte_flow_error_set(error, ENOTSUP,
12630 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12631 : : NULL,
12632 : : "CT update is not allowed to guest port");
12633 : 0 : ct = mlx5_ipool_get(pool->cts, idx);
12634 [ # # ]: 0 : if (!ct) {
12635 : 0 : return rte_flow_error_set(error, EINVAL,
12636 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12637 : : NULL,
12638 : : "Invalid CT update index");
12639 : : }
12640 : 0 : new_prf = &action_conf->new_ct;
12641 [ # # ]: 0 : if (action_conf->direction)
12642 : 0 : ct->is_original = !!new_prf->is_original_dir;
12643 [ # # ]: 0 : if (action_conf->state) {
12644 : : /* Only validate the profile when it needs to be updated. */
12645 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
12646 [ # # ]: 0 : if (ret)
12647 : : return ret;
12648 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, queue, ct, new_prf,
12649 : : user_data, push);
12650 [ # # ]: 0 : if (ret)
12651 : 0 : return rte_flow_error_set(error, EIO,
12652 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12653 : : NULL,
12654 : : "Failed to send CT context update WQE");
12655 [ # # ]: 0 : if (queue != MLX5_HW_INV_QUEUE)
12656 : : return 0;
12657 : : /* Block until ready or a failure in synchronous mode. */
12658 : 0 : ret = mlx5_aso_ct_available(priv->sh, queue, ct);
12659 [ # # ]: 0 : if (ret)
12660 : 0 : rte_flow_error_set(error, rte_errno,
12661 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12662 : : NULL,
12663 : : "Timeout to get the CT update");
12664 : : }
12665 : : return ret;
12666 : : }
12667 : :
12668 : : static struct rte_flow_action_handle *
12669 : 0 : flow_hw_conntrack_create(struct rte_eth_dev *dev, uint32_t queue,
12670 : : const struct rte_flow_action_conntrack *pro,
12671 : : void *user_data, bool push,
12672 : : struct rte_flow_error *error)
12673 : : {
12674 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12675 : 0 : struct mlx5_aso_ct_pool *pool = priv->hws_ctpool;
12676 : : struct mlx5_aso_ct_action *ct;
12677 : 0 : uint32_t ct_idx = 0;
12678 : : int ret;
12679 : : bool async = !!(queue != MLX5_HW_INV_QUEUE);
12680 : :
12681 [ # # ]: 0 : if (priv->shared_host) {
12682 : 0 : rte_flow_error_set(error, ENOTSUP,
12683 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12684 : : NULL,
12685 : : "CT create is not allowed to guest port");
12686 : 0 : return NULL;
12687 : : }
12688 [ # # ]: 0 : if (!pool) {
12689 : 0 : rte_flow_error_set(error, EINVAL,
12690 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12691 : : "CT is not enabled");
12692 : 0 : return 0;
12693 : : }
12694 : 0 : ct = mlx5_ipool_zmalloc(pool->cts, &ct_idx);
12695 [ # # ]: 0 : if (!ct) {
12696 : 0 : rte_flow_error_set(error, rte_errno,
12697 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12698 : : "Failed to allocate CT object");
12699 : 0 : return 0;
12700 : : }
12701 : 0 : ct->offset = ct_idx - 1;
12702 : 0 : ct->is_original = !!pro->is_original_dir;
12703 : 0 : ct->peer = pro->peer_port;
12704 : 0 : ct->pool = pool;
12705 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(priv->sh, queue, ct, pro, user_data, push)) {
12706 : 0 : mlx5_ipool_free(pool->cts, ct_idx);
12707 : 0 : rte_flow_error_set(error, EBUSY,
12708 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12709 : : "Failed to update CT");
12710 : 0 : return 0;
12711 : : }
12712 [ # # ]: 0 : if (!async) {
12713 : 0 : ret = mlx5_aso_ct_available(priv->sh, queue, ct);
12714 [ # # ]: 0 : if (ret) {
12715 : 0 : mlx5_ipool_free(pool->cts, ct_idx);
12716 : 0 : rte_flow_error_set(error, rte_errno,
12717 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12718 : : NULL,
12719 : : "Timeout to get the CT update");
12720 : 0 : return 0;
12721 : : }
12722 : : }
12723 : 0 : return MLX5_INDIRECT_ACT_HWS_CT_GEN_IDX(ct_idx);
12724 : : }
12725 : :
12726 : : /**
12727 : : * Validate shared action.
12728 : : *
12729 : : * @param[in] dev
12730 : : * Pointer to the rte_eth_dev structure.
12731 : : * @param[in] queue
12732 : : * Which queue to be used.
12733 : : * @param[in] attr
12734 : : * Operation attribute.
12735 : : * @param[in] conf
12736 : : * Indirect action configuration.
12737 : : * @param[in] action
12738 : : * rte_flow action detail.
12739 : : * @param[in] user_data
12740 : : * Pointer to the user_data.
12741 : : * @param[out] error
12742 : : * Pointer to error structure.
12743 : : *
12744 : : * @return
12745 : : * 0 on success, otherwise negative errno value.
12746 : : */
12747 : : static int
12748 : 0 : flow_hw_action_handle_validate(struct rte_eth_dev *dev, uint32_t queue,
12749 : : const struct rte_flow_op_attr *attr,
12750 : : const struct rte_flow_indir_action_conf *conf,
12751 : : const struct rte_flow_action *action,
12752 : : void *user_data,
12753 : : struct rte_flow_error *error)
12754 : : {
12755 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12756 : :
12757 : : RTE_SET_USED(attr);
12758 : : RTE_SET_USED(queue);
12759 : : RTE_SET_USED(user_data);
12760 [ # # # # : 0 : switch (action->type) {
# # # ]
12761 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
12762 [ # # ]: 0 : if (!priv->hws_age_req) {
12763 [ # # ]: 0 : if (flow_hw_allocate_actions(dev, MLX5_FLOW_ACTION_AGE,
12764 : : error))
12765 : 0 : return rte_flow_error_set
12766 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
12767 : : NULL, "aging pool not initialized");
12768 : : }
12769 : : break;
12770 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
12771 [ # # ]: 0 : if (!priv->hws_cpool)
12772 : 0 : return flow_hw_allocate_actions(dev,
12773 : : MLX5_FLOW_ACTION_COUNT,
12774 : : error);
12775 : : break;
12776 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12777 [ # # ]: 0 : if (priv->hws_ctpool == NULL) {
12778 [ # # ]: 0 : if (flow_hw_allocate_actions(dev, MLX5_FLOW_ACTION_CT,
12779 : : error))
12780 : 0 : return rte_flow_error_set
12781 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
12782 : : NULL, "CT pool not initialized");
12783 : : }
12784 : 0 : return mlx5_validate_action_ct(dev, action->conf, error);
12785 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
12786 : 0 : return flow_hw_validate_action_meter_mark(dev, action, true, error);
12787 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
12788 : 0 : return mlx5_flow_dv_action_validate(dev, conf, action, error);
12789 : : case RTE_FLOW_ACTION_TYPE_QUOTA:
12790 : : return 0;
12791 : 0 : default:
12792 : 0 : return rte_flow_error_set(error, ENOTSUP,
12793 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12794 : : "action type not supported");
12795 : : }
12796 : : return 0;
12797 : : }
12798 : :
12799 : : static __rte_always_inline bool
12800 : : flow_hw_action_push(const struct rte_flow_op_attr *attr)
12801 : : {
12802 [ # # # # : 0 : return attr ? !attr->postpone : true;
# # # # #
# # # #
# ]
12803 : : }
12804 : :
12805 : : static __rte_always_inline struct mlx5_hw_q_job *
12806 : : flow_hw_action_job_init(struct mlx5_priv *priv, uint32_t queue,
12807 : : const struct rte_flow_action_handle *handle,
12808 : : void *user_data, void *query_data,
12809 : : enum mlx5_hw_job_type type,
12810 : : enum mlx5_hw_indirect_type indirect_type,
12811 : : struct rte_flow_error *error)
12812 : : {
12813 : : struct mlx5_hw_q_job *job;
12814 : :
12815 [ # # # # : 0 : if (queue == MLX5_HW_INV_QUEUE)
# # # # #
# # # #
# ]
12816 [ # # # # : 0 : queue = CTRL_QUEUE_ID(priv);
# # # # #
# # # ]
12817 : : job = flow_hw_job_get(priv, queue);
12818 [ # # # # : 0 : if (!job) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
12819 : 0 : rte_flow_error_set(error, ENOMEM,
12820 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
12821 : : "Action destroy failed due to queue full.");
12822 : 0 : return NULL;
12823 : : }
12824 : 0 : job->type = type;
12825 : 0 : job->action = handle;
12826 : 0 : job->user_data = user_data;
12827 : 0 : job->query.user = query_data;
12828 [ # # # # : 0 : job->indirect_type = indirect_type;
# # # # #
# # # ]
12829 : 0 : return job;
12830 : : }
12831 : :
12832 : : struct mlx5_hw_q_job *
12833 [ # # ]: 0 : mlx5_flow_action_job_init(struct mlx5_priv *priv, uint32_t queue,
12834 : : const struct rte_flow_action_handle *handle,
12835 : : void *user_data, void *query_data,
12836 : : enum mlx5_hw_job_type type,
12837 : : struct rte_flow_error *error)
12838 : : {
12839 : 0 : return flow_hw_action_job_init(priv, queue, handle, user_data, query_data,
12840 : : type, MLX5_HW_INDIRECT_TYPE_LEGACY, error);
12841 : : }
12842 : :
12843 : : static __rte_always_inline void
12844 : : flow_hw_action_finalize(struct rte_eth_dev *dev, uint32_t queue,
12845 : : struct mlx5_hw_q_job *job,
12846 : : bool push, bool aso, bool status)
12847 : : {
12848 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12849 : :
12850 [ # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE)
12851 : 0 : queue = CTRL_QUEUE_ID(priv);
12852 [ # # # # : 0 : if (likely(status)) {
# # # # #
# # # ]
12853 : : /* 1. add new job to a queue */
12854 [ # # # # : 0 : if (!aso)
# # # # #
# ]
12855 [ # # # # : 0 : rte_ring_enqueue(push ?
# # # # #
# # # #
# ]
12856 : 0 : priv->hw_q[queue].indir_cq :
12857 : 0 : priv->hw_q[queue].indir_iq,
12858 : : job);
12859 : : /* 2. send pending jobs */
12860 [ # # # # : 0 : if (push)
# # # # #
# # # #
# ]
12861 : 0 : __flow_hw_push_action(dev, queue);
12862 : : } else {
12863 : : flow_hw_job_put(priv, job, queue);
12864 : : }
12865 : : }
12866 : :
12867 : : /**
12868 : : * Create shared action.
12869 : : *
12870 : : * @param[in] dev
12871 : : * Pointer to the rte_eth_dev structure.
12872 : : * @param[in] queue
12873 : : * Which queue to be used.
12874 : : * @param[in] attr
12875 : : * Operation attribute.
12876 : : * @param[in] conf
12877 : : * Indirect action configuration.
12878 : : * @param[in] action
12879 : : * rte_flow action detail.
12880 : : * @param[in] user_data
12881 : : * Pointer to the user_data.
12882 : : * @param[out] error
12883 : : * Pointer to error structure.
12884 : : *
12885 : : * @return
12886 : : * Action handle on success, NULL otherwise and rte_errno is set.
12887 : : */
12888 : : static struct rte_flow_action_handle *
12889 : 0 : flow_hw_action_handle_create(struct rte_eth_dev *dev, uint32_t queue,
12890 : : const struct rte_flow_op_attr *attr,
12891 : : const struct rte_flow_indir_action_conf *conf,
12892 : : const struct rte_flow_action *action,
12893 : : void *user_data,
12894 : : struct rte_flow_error *error)
12895 : : {
12896 : : struct rte_flow_action_handle *handle = NULL;
12897 : : struct mlx5_hw_q_job *job = NULL;
12898 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
12899 : : const struct rte_flow_action_age *age;
12900 : : struct mlx5_aso_mtr *aso_mtr = NULL;
12901 : : cnt_id_t cnt_id;
12902 : : uint32_t age_idx;
12903 : : bool push = flow_hw_action_push(attr);
12904 : : bool aso = false;
12905 : 0 : bool force_job = action->type == RTE_FLOW_ACTION_TYPE_METER_MARK;
12906 : : int ret;
12907 : :
12908 [ # # ]: 0 : if (!mlx5_hw_ctx_validate(dev, error))
12909 : : return NULL;
12910 [ # # ]: 0 : if (attr || force_job) {
12911 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
12912 : : NULL, MLX5_HW_Q_JOB_TYPE_CREATE,
12913 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
12914 : : if (!job)
12915 : 0 : return NULL;
12916 : : }
12917 [ # # # # : 0 : switch (action->type) {
# # # ]
12918 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
12919 [ # # ]: 0 : if (priv->hws_strict_queue) {
12920 : 0 : struct mlx5_age_info *info = GET_PORT_AGE_INFO(priv);
12921 : :
12922 [ # # ]: 0 : if (queue >= info->hw_q_age->nb_rings) {
12923 : 0 : rte_flow_error_set(error, EINVAL,
12924 : : RTE_FLOW_ERROR_TYPE_ACTION,
12925 : : NULL,
12926 : : "Invalid queue ID for indirect AGE.");
12927 : 0 : rte_errno = EINVAL;
12928 : 0 : return NULL;
12929 : : }
12930 : : }
12931 : 0 : age = action->conf;
12932 : 0 : age_idx = mlx5_hws_age_action_create(priv, queue, true, age,
12933 : : 0, error);
12934 [ # # ]: 0 : if (age_idx == 0) {
12935 : 0 : rte_flow_error_set(error, ENODEV,
12936 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12937 : : "AGE are not configured!");
12938 : : } else {
12939 : 0 : age_idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
12940 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
12941 : 0 : handle =
12942 : 0 : (struct rte_flow_action_handle *)(uintptr_t)age_idx;
12943 : : }
12944 : : break;
12945 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
12946 [ # # ]: 0 : if (mlx5_hws_cnt_shared_get(priv->hws_cpool, &cnt_id, 0))
12947 : 0 : rte_flow_error_set(error, ENODEV,
12948 : : RTE_FLOW_ERROR_TYPE_ACTION,
12949 : : NULL,
12950 : : "counter are not configured!");
12951 : : else
12952 : 0 : handle = (struct rte_flow_action_handle *)
12953 : 0 : (uintptr_t)cnt_id;
12954 : : break;
12955 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12956 : : aso = true;
12957 : 0 : handle = flow_hw_conntrack_create(dev, queue, action->conf, job,
12958 : : push, error);
12959 : 0 : break;
12960 [ # # ]: 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
12961 : : aso = true;
12962 : : ret = flow_hw_meter_mark_alloc(dev, queue, action, job, push, &aso_mtr, error);
12963 [ # # ]: 0 : if (ret) {
12964 [ # # ]: 0 : if (ret != -EIO) {
12965 [ # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE)
12966 : 0 : queue = CTRL_QUEUE_ID(priv);
12967 : : flow_hw_job_put(priv, job, queue);
12968 : : }
12969 : : break;
12970 : : }
12971 : 0 : handle = (void *)(uintptr_t)job->action;
12972 : 0 : break;
12973 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
12974 : 0 : handle = mlx5_flow_dv_action_create(dev, conf, action, error);
12975 : 0 : break;
12976 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
12977 : : aso = true;
12978 : 0 : handle = mlx5_quota_alloc(dev, queue, action->conf,
12979 : : job, push, error);
12980 : 0 : break;
12981 : 0 : default:
12982 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
12983 : : NULL, "action type not supported");
12984 : 0 : break;
12985 : : }
12986 [ # # # # ]: 0 : if (job && (!force_job || handle)) {
12987 [ # # ]: 0 : job->action = handle;
12988 : : flow_hw_action_finalize(dev, queue, job, push, aso,
12989 : : handle != NULL);
12990 : : }
12991 : : return handle;
12992 : : }
12993 : :
12994 : : static int
12995 : 0 : mlx5_flow_update_meter_mark(struct rte_eth_dev *dev, uint32_t queue,
12996 : : const struct rte_flow_update_meter_mark *upd_meter_mark,
12997 : : uint32_t idx, bool push,
12998 : : struct mlx5_hw_q_job *job, struct rte_flow_error *error)
12999 : : {
13000 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13001 : 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
13002 : : const struct rte_flow_action_meter_mark *meter_mark = &upd_meter_mark->meter_mark;
13003 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
13004 : : struct mlx5_flow_meter_info *fm;
13005 : :
13006 [ # # ]: 0 : if (!aso_mtr)
13007 : 0 : return rte_flow_error_set(error, EINVAL,
13008 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13009 : : NULL, "Invalid meter_mark update index");
13010 : : fm = &aso_mtr->fm;
13011 [ # # ]: 0 : if (upd_meter_mark->profile_valid)
13012 : 0 : fm->profile = (struct mlx5_flow_meter_profile *)
13013 : 0 : (meter_mark->profile);
13014 [ # # ]: 0 : if (upd_meter_mark->color_mode_valid)
13015 : 0 : fm->color_aware = meter_mark->color_mode;
13016 [ # # ]: 0 : if (upd_meter_mark->state_valid)
13017 : 0 : fm->is_enable = meter_mark->state;
13018 [ # # ]: 0 : aso_mtr->state = (queue == MLX5_HW_INV_QUEUE) ?
13019 : : ASO_METER_WAIT : ASO_METER_WAIT_ASYNC;
13020 : : /* Update ASO flow meter by wqe. */
13021 [ # # ]: 0 : if (mlx5_aso_meter_update_by_wqe(priv, queue,
13022 : : aso_mtr, &priv->mtr_bulk, job, push))
13023 : 0 : return rte_flow_error_set(error, EINVAL,
13024 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13025 : : NULL, "Unable to update ASO meter WQE");
13026 : : /* Wait for ASO object completion. */
13027 [ # # # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE &&
13028 : 0 : mlx5_aso_mtr_wait(priv, aso_mtr, true))
13029 : 0 : return rte_flow_error_set(error, EINVAL,
13030 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13031 : : NULL, "Unable to wait for ASO meter CQE");
13032 : : return 0;
13033 : : }
13034 : :
13035 : : /**
13036 : : * Update shared action.
13037 : : *
13038 : : * @param[in] dev
13039 : : * Pointer to the rte_eth_dev structure.
13040 : : * @param[in] queue
13041 : : * Which queue to be used.
13042 : : * @param[in] attr
13043 : : * Operation attribute.
13044 : : * @param[in] handle
13045 : : * Action handle to be updated.
13046 : : * @param[in] update
13047 : : * Update value.
13048 : : * @param[in] user_data
13049 : : * Pointer to the user_data.
13050 : : * @param[out] error
13051 : : * Pointer to error structure.
13052 : : *
13053 : : * @return
13054 : : * 0 on success, negative value otherwise and rte_errno is set.
13055 : : */
13056 : : static int
13057 : 0 : flow_hw_action_handle_update(struct rte_eth_dev *dev, uint32_t queue,
13058 : : const struct rte_flow_op_attr *attr,
13059 : : struct rte_flow_action_handle *handle,
13060 : : const void *update,
13061 : : void *user_data,
13062 : : struct rte_flow_error *error)
13063 : : {
13064 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13065 : : const struct rte_flow_modify_conntrack *ct_conf =
13066 : : (const struct rte_flow_modify_conntrack *)update;
13067 : : struct mlx5_hw_q_job *job = NULL;
13068 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13069 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13070 [ # # ]: 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
13071 : : int ret = 0;
13072 : : bool push = flow_hw_action_push(attr);
13073 : : bool aso = false;
13074 : 0 : bool force_job = type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK;
13075 : :
13076 [ # # ]: 0 : if (attr || force_job) {
13077 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13078 : : NULL, MLX5_HW_Q_JOB_TYPE_UPDATE,
13079 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13080 : : if (!job)
13081 : 0 : return -rte_errno;
13082 : : }
13083 [ # # # # : 0 : switch (type) {
# # ]
13084 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13085 : 0 : ret = mlx5_hws_age_action_update(priv, idx, update, error);
13086 : 0 : break;
13087 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
13088 [ # # ]: 0 : if (ct_conf->state)
13089 : : aso = true;
13090 : 0 : ret = flow_hw_conntrack_update(dev, queue, update, idx,
13091 : : job, push, error);
13092 : 0 : break;
13093 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
13094 : : aso = true;
13095 : 0 : ret = mlx5_flow_update_meter_mark(dev, queue, update, idx, push,
13096 : : job, error);
13097 : 0 : break;
13098 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
13099 : 0 : ret = mlx5_flow_dv_action_update(dev, handle, update, error);
13100 : 0 : break;
13101 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13102 : : aso = true;
13103 : 0 : ret = mlx5_quota_query_update(dev, queue, handle, update, NULL,
13104 : : job, push, error);
13105 : 0 : break;
13106 : 0 : default:
13107 : : ret = -ENOTSUP;
13108 : 0 : rte_flow_error_set(error, ENOTSUP,
13109 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13110 : : "action type not supported");
13111 : 0 : break;
13112 : : }
13113 [ # # ]: 0 : if (job && !force_job)
13114 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13115 : : return ret;
13116 : : }
13117 : :
13118 : : /**
13119 : : * Destroy shared action.
13120 : : *
13121 : : * @param[in] dev
13122 : : * Pointer to the rte_eth_dev structure.
13123 : : * @param[in] queue
13124 : : * Which queue to be used.
13125 : : * @param[in] attr
13126 : : * Operation attribute.
13127 : : * @param[in] handle
13128 : : * Action handle to be destroyed.
13129 : : * @param[in] user_data
13130 : : * Pointer to the user_data.
13131 : : * @param[out] error
13132 : : * Pointer to error structure.
13133 : : *
13134 : : * @return
13135 : : * 0 on success, negative value otherwise and rte_errno is set.
13136 : : */
13137 : : static int
13138 : 0 : flow_hw_action_handle_destroy(struct rte_eth_dev *dev, uint32_t queue,
13139 : : const struct rte_flow_op_attr *attr,
13140 : : struct rte_flow_action_handle *handle,
13141 : : void *user_data,
13142 : : struct rte_flow_error *error)
13143 : : {
13144 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13145 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13146 : 0 : uint32_t age_idx = act_idx & MLX5_HWS_AGE_IDX_MASK;
13147 : : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
13148 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13149 [ # # ]: 0 : struct mlx5_aso_mtr_pool *pool = priv->hws_mpool;
13150 : : struct mlx5_hw_q_job *job = NULL;
13151 : : struct mlx5_aso_mtr *aso_mtr;
13152 : : struct mlx5_flow_meter_info *fm;
13153 : : bool push = flow_hw_action_push(attr);
13154 : : bool aso = false;
13155 : : int ret = 0;
13156 : 0 : bool force_job = type == MLX5_INDIRECT_ACTION_TYPE_METER_MARK;
13157 : :
13158 [ # # ]: 0 : if (attr || force_job) {
13159 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13160 : : NULL, MLX5_HW_Q_JOB_TYPE_DESTROY,
13161 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13162 : : if (!job)
13163 : 0 : return -rte_errno;
13164 : : }
13165 [ # # # # : 0 : switch (type) {
# # # ]
13166 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13167 : 0 : ret = mlx5_hws_age_action_destroy(priv, age_idx, error);
13168 : 0 : break;
13169 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
13170 [ # # ]: 0 : age_idx = mlx5_hws_cnt_age_get(priv->hws_cpool, act_idx);
13171 [ # # ]: 0 : if (age_idx != 0)
13172 : : /*
13173 : : * If this counter belongs to indirect AGE, here is the
13174 : : * time to update the AGE.
13175 : : */
13176 : : mlx5_hws_age_nb_cnt_decrease(priv, age_idx);
13177 [ # # ]: 0 : mlx5_hws_cnt_shared_put(priv->hws_cpool, &act_idx);
13178 : : break;
13179 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
13180 : 0 : ret = flow_hw_conntrack_destroy(dev, idx, error);
13181 : 0 : break;
13182 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
13183 : 0 : aso_mtr = mlx5_ipool_get(pool->idx_pool, idx);
13184 [ # # ]: 0 : if (!aso_mtr) {
13185 : : ret = -EINVAL;
13186 : 0 : rte_flow_error_set(error, EINVAL,
13187 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13188 : : NULL, "Invalid meter_mark destroy index");
13189 : 0 : break;
13190 : : }
13191 : : fm = &aso_mtr->fm;
13192 : 0 : fm->is_enable = 0;
13193 : : /* Update ASO flow meter by wqe. */
13194 [ # # ]: 0 : if (mlx5_aso_meter_update_by_wqe(priv, queue, aso_mtr,
13195 : : &priv->mtr_bulk, job, push)) {
13196 : : ret = -EINVAL;
13197 : 0 : rte_flow_error_set(error, EINVAL,
13198 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13199 : : NULL, "Unable to update ASO meter WQE");
13200 : 0 : break;
13201 : : }
13202 : : /* Wait for ASO object completion. */
13203 [ # # ]: 0 : if (queue == MLX5_HW_INV_QUEUE) {
13204 [ # # ]: 0 : if (mlx5_aso_mtr_wait(priv, aso_mtr, true)) {
13205 : : ret = -EINVAL;
13206 : 0 : rte_flow_error_set(error, EINVAL,
13207 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13208 : : NULL, "Unable to wait for ASO meter CQE");
13209 : : }
13210 : 0 : mlx5_ipool_free(pool->idx_pool, idx);
13211 [ # # ]: 0 : if (ret < 0)
13212 : : break;
13213 : : }
13214 : : aso = true;
13215 : : break;
13216 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
13217 : 0 : ret = mlx5_flow_dv_action_destroy(dev, handle, error);
13218 : 0 : break;
13219 : : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13220 : : break;
13221 : 0 : default:
13222 : : ret = -ENOTSUP;
13223 : 0 : rte_flow_error_set(error, ENOTSUP,
13224 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13225 : : "action type not supported");
13226 : 0 : break;
13227 : : }
13228 [ # # ]: 0 : if (job && !force_job)
13229 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13230 : : return ret;
13231 : : }
13232 : :
13233 : : static int
13234 : 0 : flow_hw_query_counter(const struct rte_eth_dev *dev, uint32_t counter,
13235 : : void *data, struct rte_flow_error *error)
13236 : : {
13237 : : struct mlx5_hws_cnt_pool *hpool;
13238 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13239 : : struct mlx5_hws_cnt *cnt;
13240 : : struct rte_flow_query_count *qc = data;
13241 : : uint32_t iidx;
13242 : : uint64_t pkts, bytes;
13243 : :
13244 [ # # ]: 0 : if (!mlx5_hws_cnt_id_valid(counter))
13245 : 0 : return rte_flow_error_set(error, EINVAL,
13246 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13247 : : "counter are not available");
13248 [ # # ]: 0 : hpool = mlx5_hws_cnt_host_pool(priv->hws_cpool);
13249 : : iidx = mlx5_hws_cnt_iidx(hpool, counter);
13250 : 0 : cnt = &hpool->pool[iidx];
13251 : : __hws_cnt_query_raw(priv->hws_cpool, counter, &pkts, &bytes);
13252 : 0 : qc->hits_set = 1;
13253 : 0 : qc->bytes_set = 1;
13254 : 0 : qc->hits = pkts - cnt->reset.hits;
13255 : 0 : qc->bytes = bytes - cnt->reset.bytes;
13256 [ # # ]: 0 : if (qc->reset) {
13257 : 0 : cnt->reset.bytes = bytes;
13258 : 0 : cnt->reset.hits = pkts;
13259 : : }
13260 : : return 0;
13261 : : }
13262 : :
13263 : : /**
13264 : : * Query a flow rule AGE action for aging information.
13265 : : *
13266 : : * @param[in] dev
13267 : : * Pointer to Ethernet device.
13268 : : * @param[in] age_idx
13269 : : * Index of AGE action parameter.
13270 : : * @param[out] data
13271 : : * Data retrieved by the query.
13272 : : * @param[out] error
13273 : : * Perform verbose error reporting if not NULL.
13274 : : *
13275 : : * @return
13276 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13277 : : */
13278 : : static int
13279 : 0 : flow_hw_query_age(const struct rte_eth_dev *dev, uint32_t age_idx, void *data,
13280 : : struct rte_flow_error *error)
13281 : : {
13282 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13283 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
13284 : 0 : struct mlx5_indexed_pool *ipool = age_info->ages_ipool;
13285 : 0 : struct mlx5_hws_age_param *param = mlx5_ipool_get(ipool, age_idx);
13286 : : struct rte_flow_query_age *resp = data;
13287 : :
13288 [ # # # # ]: 0 : if (!param || !param->timeout)
13289 : 0 : return rte_flow_error_set(error, EINVAL,
13290 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13291 : : NULL, "age data not available");
13292 [ # # # ]: 0 : switch (rte_atomic_load_explicit(¶m->state, rte_memory_order_relaxed)) {
13293 : 0 : case HWS_AGE_AGED_OUT_REPORTED:
13294 : : case HWS_AGE_AGED_OUT_NOT_REPORTED:
13295 : 0 : resp->aged = 1;
13296 : 0 : break;
13297 : 0 : case HWS_AGE_CANDIDATE:
13298 : : case HWS_AGE_CANDIDATE_INSIDE_RING:
13299 : 0 : resp->aged = 0;
13300 : 0 : break;
13301 : : case HWS_AGE_FREE:
13302 : : /*
13303 : : * When state is FREE the flow itself should be invalid.
13304 : : * Fall-through.
13305 : : */
13306 : : default:
13307 : : MLX5_ASSERT(0);
13308 : : break;
13309 : : }
13310 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
13311 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
13312 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
13313 : : (¶m->sec_since_last_hit, rte_memory_order_relaxed);
13314 : : return 0;
13315 : : }
13316 : :
13317 : : static int
13318 : 0 : flow_hw_query(struct rte_eth_dev *dev, struct rte_flow *flow,
13319 : : const struct rte_flow_action *actions, void *data,
13320 : : struct rte_flow_error *error)
13321 : : {
13322 : : int ret = -EINVAL;
13323 : : struct rte_flow_hw *hw_flow = (struct rte_flow_hw *)flow;
13324 : : struct rte_flow_hw_aux *aux;
13325 : :
13326 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
13327 [ # # # # ]: 0 : switch (actions->type) {
13328 : : case RTE_FLOW_ACTION_TYPE_VOID:
13329 : : break;
13330 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13331 [ # # ]: 0 : if (!(hw_flow->flags & MLX5_FLOW_HW_FLOW_FLAG_CNT_ID))
13332 : 0 : return rte_flow_error_set(error, EINVAL,
13333 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13334 : : "counter not defined in the rule");
13335 : 0 : ret = flow_hw_query_counter(dev, hw_flow->cnt_id, data,
13336 : : error);
13337 : 0 : break;
13338 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
13339 [ # # ]: 0 : if (!(hw_flow->flags & MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX))
13340 : 0 : return rte_flow_error_set(error, EINVAL,
13341 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13342 : : "age data not available");
13343 [ # # ]: 0 : aux = mlx5_flow_hw_aux(dev->data->port_id, hw_flow);
13344 : 0 : ret = flow_hw_query_age(dev, mlx5_flow_hw_aux_get_age_idx(hw_flow, aux),
13345 : : data, error);
13346 : 0 : break;
13347 : 0 : default:
13348 : 0 : return rte_flow_error_set(error, ENOTSUP,
13349 : : RTE_FLOW_ERROR_TYPE_ACTION,
13350 : : actions,
13351 : : "action not supported");
13352 : : }
13353 : : }
13354 : : return ret;
13355 : : }
13356 : :
13357 : : /**
13358 : : * Validate indirect action.
13359 : : *
13360 : : * @param[in] dev
13361 : : * Pointer to the Ethernet device structure.
13362 : : * @param[in] conf
13363 : : * Shared action configuration.
13364 : : * @param[in] action
13365 : : * Action specification used to create indirect action.
13366 : : * @param[out] error
13367 : : * Perform verbose error reporting if not NULL. Initialized in case of
13368 : : * error only.
13369 : : *
13370 : : * @return
13371 : : * 0 on success, otherwise negative errno value.
13372 : : */
13373 : : static int
13374 : 0 : flow_hw_action_validate(struct rte_eth_dev *dev,
13375 : : const struct rte_flow_indir_action_conf *conf,
13376 : : const struct rte_flow_action *action,
13377 : : struct rte_flow_error *err)
13378 : : {
13379 : 0 : struct rte_flow_error shadow_error = {0, };
13380 : :
13381 [ # # ]: 0 : if (!err)
13382 : : err = &shadow_error;
13383 : 0 : return flow_hw_action_handle_validate(dev, MLX5_HW_INV_QUEUE, NULL,
13384 : : conf, action, NULL, err);
13385 : : }
13386 : :
13387 : : /**
13388 : : * Create indirect action.
13389 : : *
13390 : : * @param[in] dev
13391 : : * Pointer to the Ethernet device structure.
13392 : : * @param[in] conf
13393 : : * Shared action configuration.
13394 : : * @param[in] action
13395 : : * Action specification used to create indirect action.
13396 : : * @param[out] error
13397 : : * Perform verbose error reporting if not NULL. Initialized in case of
13398 : : * error only.
13399 : : *
13400 : : * @return
13401 : : * A valid shared action handle in case of success, NULL otherwise and
13402 : : * rte_errno is set.
13403 : : */
13404 : : static struct rte_flow_action_handle *
13405 : 0 : flow_hw_action_create(struct rte_eth_dev *dev,
13406 : : const struct rte_flow_indir_action_conf *conf,
13407 : : const struct rte_flow_action *action,
13408 : : struct rte_flow_error *err)
13409 : : {
13410 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13411 : :
13412 [ # # # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_AGE && priv->hws_strict_queue) {
13413 : 0 : rte_flow_error_set(err, EINVAL, RTE_FLOW_ERROR_TYPE_STATE, NULL,
13414 : : "Cannot create age action synchronously with strict queueing");
13415 : 0 : return NULL;
13416 : : }
13417 : :
13418 : 0 : return flow_hw_action_handle_create(dev, MLX5_HW_INV_QUEUE,
13419 : : NULL, conf, action, NULL, err);
13420 : : }
13421 : :
13422 : : /**
13423 : : * Destroy the indirect action.
13424 : : * Release action related resources on the NIC and the memory.
13425 : : * Lock free, (mutex should be acquired by caller).
13426 : : * Dispatcher for action type specific call.
13427 : : *
13428 : : * @param[in] dev
13429 : : * Pointer to the Ethernet device structure.
13430 : : * @param[in] handle
13431 : : * The indirect action object handle to be removed.
13432 : : * @param[out] error
13433 : : * Perform verbose error reporting if not NULL. Initialized in case of
13434 : : * error only.
13435 : : *
13436 : : * @return
13437 : : * 0 on success, otherwise negative errno value.
13438 : : */
13439 : : static int
13440 : 0 : flow_hw_action_destroy(struct rte_eth_dev *dev,
13441 : : struct rte_flow_action_handle *handle,
13442 : : struct rte_flow_error *error)
13443 : : {
13444 : 0 : return flow_hw_action_handle_destroy(dev, MLX5_HW_INV_QUEUE,
13445 : : NULL, handle, NULL, error);
13446 : : }
13447 : :
13448 : : /**
13449 : : * Updates in place shared action configuration.
13450 : : *
13451 : : * @param[in] dev
13452 : : * Pointer to the Ethernet device structure.
13453 : : * @param[in] handle
13454 : : * The indirect action object handle to be updated.
13455 : : * @param[in] update
13456 : : * Action specification used to modify the action pointed by *handle*.
13457 : : * *update* could be of same type with the action pointed by the *handle*
13458 : : * handle argument, or some other structures like a wrapper, depending on
13459 : : * the indirect action type.
13460 : : * @param[out] error
13461 : : * Perform verbose error reporting if not NULL. Initialized in case of
13462 : : * error only.
13463 : : *
13464 : : * @return
13465 : : * 0 on success, otherwise negative errno value.
13466 : : */
13467 : : static int
13468 : 0 : flow_hw_action_update(struct rte_eth_dev *dev,
13469 : : struct rte_flow_action_handle *handle,
13470 : : const void *update,
13471 : : struct rte_flow_error *err)
13472 : : {
13473 : 0 : return flow_hw_action_handle_update(dev, MLX5_HW_INV_QUEUE,
13474 : : NULL, handle, update, NULL, err);
13475 : : }
13476 : :
13477 : : static int
13478 : 0 : flow_hw_action_handle_query(struct rte_eth_dev *dev, uint32_t queue,
13479 : : const struct rte_flow_op_attr *attr,
13480 : : const struct rte_flow_action_handle *handle,
13481 : : void *data, void *user_data,
13482 : : struct rte_flow_error *error)
13483 : : {
13484 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13485 : : struct mlx5_hw_q_job *job = NULL;
13486 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
13487 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
13488 [ # # ]: 0 : uint32_t idx = MLX5_INDIRECT_ACTION_IDX_GET(handle);
13489 : : uint32_t age_idx = act_idx & MLX5_HWS_AGE_IDX_MASK;
13490 : : int ret;
13491 : : bool push = flow_hw_action_push(attr);
13492 : : bool aso = false;
13493 : :
13494 [ # # ]: 0 : if (attr) {
13495 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13496 : : data, MLX5_HW_Q_JOB_TYPE_QUERY,
13497 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13498 : : if (!job)
13499 : 0 : return -rte_errno;
13500 : : }
13501 [ # # # # : 0 : switch (type) {
# ]
13502 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13503 : 0 : ret = flow_hw_query_age(dev, age_idx, data, error);
13504 : 0 : break;
13505 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
13506 : 0 : ret = flow_hw_query_counter(dev, act_idx, data, error);
13507 : 0 : break;
13508 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
13509 : : aso = true;
13510 [ # # ]: 0 : if (job)
13511 : 0 : job->query.user = data;
13512 : 0 : ret = flow_hw_conntrack_query(dev, queue, idx, data,
13513 : : job, push, error);
13514 : 0 : break;
13515 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13516 : : aso = true;
13517 : 0 : ret = mlx5_quota_query(dev, queue, handle, data,
13518 : : job, push, error);
13519 : 0 : break;
13520 : 0 : default:
13521 : : ret = -ENOTSUP;
13522 : 0 : rte_flow_error_set(error, ENOTSUP,
13523 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13524 : : "action type not supported");
13525 : 0 : break;
13526 : : }
13527 [ # # ]: 0 : if (job)
13528 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13529 : : return ret;
13530 : : }
13531 : :
13532 : : static int
13533 : 0 : flow_hw_async_action_handle_query_update
13534 : : (struct rte_eth_dev *dev, uint32_t queue,
13535 : : const struct rte_flow_op_attr *attr,
13536 : : struct rte_flow_action_handle *handle,
13537 : : const void *update, void *query,
13538 : : enum rte_flow_query_update_mode qu_mode,
13539 : : void *user_data, struct rte_flow_error *error)
13540 : : {
13541 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13542 : : bool push = flow_hw_action_push(attr);
13543 : : bool aso = false;
13544 : : struct mlx5_hw_q_job *job = NULL;
13545 : : int ret = 0;
13546 : :
13547 [ # # ]: 0 : if (attr) {
13548 : : job = flow_hw_action_job_init(priv, queue, handle, user_data,
13549 : : query,
13550 : : MLX5_HW_Q_JOB_TYPE_UPDATE_QUERY,
13551 : : MLX5_HW_INDIRECT_TYPE_LEGACY, error);
13552 : : if (!job)
13553 : 0 : return -rte_errno;
13554 : : }
13555 [ # # ]: 0 : switch (MLX5_INDIRECT_ACTION_TYPE_GET(handle)) {
13556 : 0 : case MLX5_INDIRECT_ACTION_TYPE_QUOTA:
13557 [ # # ]: 0 : if (qu_mode != RTE_FLOW_QU_QUERY_FIRST) {
13558 : 0 : ret = rte_flow_error_set
13559 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
13560 : : NULL, "quota action must query before update");
13561 : 0 : break;
13562 : : }
13563 : : aso = true;
13564 : 0 : ret = mlx5_quota_query_update(dev, queue, handle,
13565 : : update, query, job, push, error);
13566 : 0 : break;
13567 : 0 : default:
13568 : 0 : ret = rte_flow_error_set(error, ENOTSUP,
13569 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL, "update and query not supportred");
13570 : : }
13571 [ # # ]: 0 : if (job)
13572 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, aso, ret == 0);
13573 : : return ret;
13574 : : }
13575 : :
13576 : : static int
13577 : 0 : flow_hw_action_query(struct rte_eth_dev *dev,
13578 : : const struct rte_flow_action_handle *handle, void *data,
13579 : : struct rte_flow_error *error)
13580 : : {
13581 : 0 : return flow_hw_action_handle_query(dev, MLX5_HW_INV_QUEUE, NULL,
13582 : : handle, data, NULL, error);
13583 : : }
13584 : :
13585 : : static int
13586 : 0 : flow_hw_action_query_update(struct rte_eth_dev *dev,
13587 : : struct rte_flow_action_handle *handle,
13588 : : const void *update, void *query,
13589 : : enum rte_flow_query_update_mode qu_mode,
13590 : : struct rte_flow_error *error)
13591 : : {
13592 : 0 : return flow_hw_async_action_handle_query_update(dev, MLX5_HW_INV_QUEUE,
13593 : : NULL, handle, update,
13594 : : query, qu_mode, NULL,
13595 : : error);
13596 : : }
13597 : :
13598 : : /**
13599 : : * Get aged-out flows of a given port on the given HWS flow queue.
13600 : : *
13601 : : * @param[in] dev
13602 : : * Pointer to the Ethernet device structure.
13603 : : * @param[in] queue_id
13604 : : * Flow queue to query. Ignored when RTE_FLOW_PORT_FLAG_STRICT_QUEUE not set.
13605 : : * @param[in, out] contexts
13606 : : * The address of an array of pointers to the aged-out flows contexts.
13607 : : * @param[in] nb_contexts
13608 : : * The length of context array pointers.
13609 : : * @param[out] error
13610 : : * Perform verbose error reporting if not NULL. Initialized in case of
13611 : : * error only.
13612 : : *
13613 : : * @return
13614 : : * if nb_contexts is 0, return the amount of all aged contexts.
13615 : : * if nb_contexts is not 0 , return the amount of aged flows reported
13616 : : * in the context array, otherwise negative errno value.
13617 : : */
13618 : : static int
13619 : 0 : flow_hw_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
13620 : : void **contexts, uint32_t nb_contexts,
13621 : : struct rte_flow_error *error)
13622 : : {
13623 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13624 : 0 : struct mlx5_age_info *age_info = GET_PORT_AGE_INFO(priv);
13625 : : struct rte_ring *r;
13626 : : int nb_flows = 0;
13627 : :
13628 [ # # ]: 0 : if (nb_contexts && !contexts)
13629 : 0 : return rte_flow_error_set(error, EINVAL,
13630 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13631 : : NULL, "empty context");
13632 [ # # ]: 0 : if (!priv->hws_age_req)
13633 : 0 : return rte_flow_error_set(error, ENOENT,
13634 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13635 : : NULL, "No aging initialized");
13636 [ # # ]: 0 : if (priv->hws_strict_queue) {
13637 : : /* Queue is invalid in sync query. Sync query and strict queueing is disallowed. */
13638 : : MLX5_ASSERT(queue_id != MLX5_HW_INV_QUEUE);
13639 [ # # ]: 0 : if (queue_id >= age_info->hw_q_age->nb_rings)
13640 : 0 : return rte_flow_error_set(error, EINVAL,
13641 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13642 : : NULL, "invalid queue id");
13643 : 0 : r = age_info->hw_q_age->aged_lists[queue_id];
13644 : : } else {
13645 : 0 : r = age_info->hw_age.aged_list;
13646 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
13647 : : }
13648 [ # # ]: 0 : if (nb_contexts == 0)
13649 : 0 : return rte_ring_count(r);
13650 [ # # ]: 0 : while ((uint32_t)nb_flows < nb_contexts) {
13651 : : uint32_t age_idx;
13652 : :
13653 : : if (rte_ring_dequeue_elem(r, &age_idx, sizeof(uint32_t)) < 0)
13654 : : break;
13655 : : /* get the AGE context if the aged-out index is still valid. */
13656 : 0 : contexts[nb_flows] = mlx5_hws_age_context_get(priv, age_idx);
13657 [ # # ]: 0 : if (!contexts[nb_flows])
13658 : 0 : continue;
13659 : 0 : nb_flows++;
13660 : : }
13661 : : return nb_flows;
13662 : : }
13663 : :
13664 : : /**
13665 : : * Get aged-out flows.
13666 : : *
13667 : : * This function is relevant only if RTE_FLOW_PORT_FLAG_STRICT_QUEUE isn't set.
13668 : : *
13669 : : * @param[in] dev
13670 : : * Pointer to the Ethernet device structure.
13671 : : * @param[in] contexts
13672 : : * The address of an array of pointers to the aged-out flows contexts.
13673 : : * @param[in] nb_contexts
13674 : : * The length of context array pointers.
13675 : : * @param[out] error
13676 : : * Perform verbose error reporting if not NULL. Initialized in case of
13677 : : * error only.
13678 : : *
13679 : : * @return
13680 : : * how many contexts get in success, otherwise negative errno value.
13681 : : * if nb_contexts is 0, return the amount of all aged contexts.
13682 : : * if nb_contexts is not 0 , return the amount of aged flows reported
13683 : : * in the context array.
13684 : : */
13685 : : static int
13686 : 0 : flow_hw_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
13687 : : uint32_t nb_contexts, struct rte_flow_error *error)
13688 : : {
13689 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13690 : :
13691 [ # # ]: 0 : if (priv->hws_strict_queue)
13692 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_STATE, NULL,
13693 : : "Cannot get aged flows synchronously with strict queueing");
13694 : :
13695 : 0 : return flow_hw_get_q_aged_flows(dev, MLX5_HW_INV_QUEUE, contexts, nb_contexts, error);
13696 : : }
13697 : : /**
13698 : : * Initialization function for non template API which calls
13699 : : * flow_hw_configure with default values.
13700 : : * Configure non queues cause 1 queue is configured by default for inner usage.
13701 : : *
13702 : : * @param[in] dev
13703 : : * Pointer to the Ethernet device structure.
13704 : : * @param[out] error
13705 : : * Pointer to the error structure.
13706 : : *
13707 : : * @return
13708 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13709 : : */
13710 : : int
13711 : 0 : mlx5_flow_hw_init(struct rte_eth_dev *dev,
13712 : : struct rte_flow_error *error)
13713 : : {
13714 : 0 : const struct rte_flow_port_attr port_attr = {0};
13715 : 0 : const struct rte_flow_queue_attr queue_attr = {.size = MLX5_NT_DEFAULT_QUEUE_SIZE};
13716 : 0 : const struct rte_flow_queue_attr *attr_list = &queue_attr;
13717 : :
13718 : : /**
13719 : : * If user uses template and non template API:
13720 : : * User will call flow_hw_configure and non template
13721 : : * API will use the allocated actions.
13722 : : * Init function will not call flow_hw_configure.
13723 : : *
13724 : : * If user uses only non template API's:
13725 : : * Init function will call flow_hw_configure.
13726 : : * It will not allocate memory for actions.
13727 : : * When needed allocation, it will handle same as for SWS today,
13728 : : * meaning using bulk allocations and resize as needed.
13729 : : */
13730 : : /* Configure hws with default values. */
13731 : 0 : DRV_LOG(DEBUG, "Apply default configuration, zero number of queues, inner control queue size is %u",
13732 : : MLX5_NT_DEFAULT_QUEUE_SIZE);
13733 : 0 : return __flow_hw_configure(dev, &port_attr, 0, &attr_list, true, error);
13734 : : }
13735 : :
13736 : 0 : static int flow_hw_prepare(struct rte_eth_dev *dev,
13737 : : const struct rte_flow_action actions[] __rte_unused,
13738 : : enum mlx5_flow_type type,
13739 : : struct rte_flow_hw **flow,
13740 : : struct rte_flow_error *error)
13741 : : {
13742 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13743 : 0 : uint32_t idx = 0;
13744 : :
13745 : : /*
13746 : : * Notice pool idx size = (sizeof(struct rte_flow_hw)
13747 : : * + sizeof(struct rte_flow_nt2hws)) for HWS mode.
13748 : : */
13749 : 0 : *flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
13750 [ # # ]: 0 : if (!(*flow))
13751 : 0 : return rte_flow_error_set(error, ENOMEM,
13752 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13753 : : "cannot allocate flow memory");
13754 : : /* Allocating 2 structures in one pool slot, updating nt2hw pointer.*/
13755 : 0 : (*flow)->nt2hws = (struct rte_flow_nt2hws *)
13756 : 0 : ((uintptr_t)(*flow) + sizeof(struct rte_flow_hw));
13757 : 0 : (*flow)->idx = idx;
13758 : 0 : (*flow)->nt2hws->flow_aux = (struct rte_flow_hw_aux *)
13759 : 0 : ((uintptr_t)((*flow)->nt2hws) + sizeof(struct rte_flow_nt2hws));
13760 : :
13761 [ # # ]: 0 : if (!(*flow)->nt2hws->flow_aux)
13762 : 0 : return rte_flow_error_set(error, ENOMEM,
13763 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13764 : : "cannot allocate flow aux memory");
13765 : : return 0;
13766 : : }
13767 : :
13768 : : static inline void
13769 : 0 : flow_hw_set_dv_fields(struct rte_flow_template_table_attr *table_attr, uint32_t fdb_unified_en,
13770 : : bool *root, uint8_t *ft_type, uint64_t *flags)
13771 : : {
13772 [ # # ]: 0 : if (table_attr->flow_attr.transfer)
13773 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13774 : : else
13775 : 0 : *ft_type = table_attr->flow_attr.egress ?
13776 : 0 : MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
13777 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13778 : 0 : uint32_t group = table_attr->flow_attr.group;
13779 : 0 : *root = group ? 0 : 1;
13780 : 0 : *flags = mlx5_hw_act_flag[!!group][get_mlx5dr_table_type(&table_attr->flow_attr,
13781 : : table_attr->specialize,
13782 : : fdb_unified_en)];
13783 : 0 : }
13784 : :
13785 : : static int
13786 : 0 : flow_hw_modify_hdr_resource_register
13787 : : (struct rte_eth_dev *dev,
13788 : : struct rte_flow_template_table *table,
13789 : : struct mlx5_hw_actions *hw_acts,
13790 : : struct rte_flow_hw *dev_flow,
13791 : : struct rte_flow_error *error)
13792 : : {
13793 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13794 : : bool unified_fdb = is_unified_fdb(priv);
13795 : 0 : struct rte_flow_template_table_attr *table_attr = &table->cfg.attr;
13796 : 0 : struct mlx5_flow_dv_modify_hdr_resource *dv_resource_ptr = NULL;
13797 : : union {
13798 : : struct mlx5_flow_dv_modify_hdr_resource dv_resource;
13799 : : uint8_t data[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
13800 : : sizeof(struct mlx5_modification_cmd) * MLX5_MHDR_MAX_CMD];
13801 : : } dummy;
13802 : : int ret;
13803 : :
13804 [ # # ]: 0 : if (hw_acts->mhdr) {
13805 : 0 : dummy.dv_resource.actions_num = hw_acts->mhdr->mhdr_cmds_num;
13806 : 0 : memcpy(dummy.dv_resource.actions, hw_acts->mhdr->mhdr_cmds,
13807 : 0 : sizeof(struct mlx5_modification_cmd) * dummy.dv_resource.actions_num);
13808 : : } else {
13809 : : return 0;
13810 : : }
13811 : 0 : flow_hw_set_dv_fields(table_attr, unified_fdb,
13812 : : &dummy.dv_resource.root, &dummy.dv_resource.ft_type,
13813 : : &dummy.dv_resource.flags);
13814 : 0 : dummy.dv_resource.flags |= MLX5DR_ACTION_FLAG_SHARED;
13815 : 0 : ret = mlx5_flow_modify_hdr_resource_register(dev, &dummy.dv_resource,
13816 : : &dv_resource_ptr, error);
13817 [ # # ]: 0 : if (ret)
13818 : : return ret;
13819 : : MLX5_ASSERT(dv_resource_ptr);
13820 : 0 : dev_flow->nt2hws->modify_hdr = dv_resource_ptr;
13821 : : /* keep action for the rule construction. */
13822 : 0 : hw_acts->rule_acts[hw_acts->mhdr->pos].action = dv_resource_ptr->action;
13823 : : /* Bulk size is 1, so index is 1. */
13824 : 0 : dev_flow->res_idx = 1;
13825 : 0 : return 0;
13826 : : }
13827 : :
13828 : : static int
13829 : 0 : flow_hw_encap_decap_resource_register
13830 : : (struct rte_eth_dev *dev,
13831 : : struct rte_flow_template_table *table,
13832 : : struct mlx5_hw_actions *hw_acts,
13833 : : struct rte_flow_hw *dev_flow,
13834 : : struct rte_flow_error *error)
13835 : : {
13836 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
13837 : : bool unified_fdb = is_unified_fdb(priv);
13838 : 0 : struct rte_flow_template_table_attr *table_attr = &table->cfg.attr;
13839 : 0 : struct mlx5_flow_dv_encap_decap_resource *dv_resource_ptr = NULL;
13840 : : struct mlx5_flow_dv_encap_decap_resource dv_resource;
13841 : : struct mlx5_tbl_multi_pattern_ctx *mpctx = &table->mpctx;
13842 : : int ret;
13843 : : bool is_root;
13844 : : int ix;
13845 : :
13846 [ # # ]: 0 : if (hw_acts->encap_decap)
13847 : 0 : dv_resource.reformat_type = hw_acts->encap_decap->action_type;
13848 : : else
13849 : : return 0;
13850 : 0 : flow_hw_set_dv_fields(table_attr, unified_fdb, &is_root, &dv_resource.ft_type,
13851 : : &dv_resource.flags);
13852 [ # # ]: 0 : ix = mlx5_bwc_multi_pattern_reformat_to_index((enum mlx5dr_action_type)
13853 : : dv_resource.reformat_type);
13854 : : if (ix < 0)
13855 : 0 : return ix;
13856 [ # # ]: 0 : if (hw_acts->encap_decap->shared) {
13857 : 0 : dv_resource.size = hw_acts->encap_decap->data_size;
13858 : : MLX5_ASSERT(dv_resource.size <= MLX5_ENCAP_MAX_LEN);
13859 : 0 : memcpy(&dv_resource.buf, hw_acts->encap_decap->data, dv_resource.size);
13860 : 0 : dv_resource.flags |= MLX5DR_ACTION_FLAG_SHARED;
13861 : : } else {
13862 : 0 : typeof(mpctx->reformat[0]) *reformat = mpctx->reformat + ix;
13863 [ # # ]: 0 : if (!reformat->elements_num)
13864 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
13865 : : NULL, "No reformat action exist in the table.");
13866 : 0 : dv_resource.size = reformat->reformat_hdr->sz;
13867 : : MLX5_ASSERT(dv_resource.size <= MLX5_ENCAP_MAX_LEN);
13868 : 0 : memcpy(&dv_resource.buf, reformat->reformat_hdr->data, dv_resource.size);
13869 : : }
13870 : 0 : ret = mlx5_flow_encap_decap_resource_register(dev, &dv_resource, is_root,
13871 : : &dv_resource_ptr, error);
13872 [ # # ]: 0 : if (ret)
13873 : : return ret;
13874 : : MLX5_ASSERT(dv_resource_ptr);
13875 : 0 : dev_flow->nt2hws->rix_encap_decap = dv_resource_ptr->idx;
13876 : : /* keep action for the rule construction. */
13877 [ # # ]: 0 : if (hw_acts->encap_decap->shared)
13878 : 0 : hw_acts->rule_acts[hw_acts->encap_decap_pos].action = dv_resource_ptr->action;
13879 : : else
13880 : 0 : mpctx->segments[0].reformat_action[ix] = dv_resource_ptr->action;
13881 : : /* Bulk size is 1, so index is 1. */
13882 : 0 : dev_flow->res_idx = 1;
13883 : 0 : return 0;
13884 : : }
13885 : :
13886 : : static enum rte_flow_action_type
13887 : : flow_nta_get_indirect_action_type(const struct rte_flow_action *action)
13888 : : {
13889 [ # # ]: 0 : switch (MLX5_INDIRECT_ACTION_TYPE_GET(action->conf)) {
13890 : : case MLX5_INDIRECT_ACTION_TYPE_RSS:
13891 : : return RTE_FLOW_ACTION_TYPE_RSS;
13892 : : case MLX5_INDIRECT_ACTION_TYPE_AGE:
13893 : : return RTE_FLOW_ACTION_TYPE_AGE;
13894 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
13895 : : return RTE_FLOW_ACTION_TYPE_COUNT;
13896 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
13897 : : return RTE_FLOW_ACTION_TYPE_CONNTRACK;
13898 : : default:
13899 : : break;
13900 : : }
13901 : : return RTE_FLOW_ACTION_TYPE_END;
13902 : : }
13903 : :
13904 : : static void
13905 : : flow_nta_set_mh_mask_conf(const struct rte_flow_action_modify_field *action_conf,
13906 : : struct rte_flow_action_modify_field *mask_conf)
13907 : : {
13908 : : memset(mask_conf, 0xff, sizeof(*mask_conf));
13909 : 0 : mask_conf->operation = action_conf->operation;
13910 : 0 : mask_conf->dst.field = action_conf->dst.field;
13911 : 0 : mask_conf->src.field = action_conf->src.field;
13912 : : }
13913 : :
13914 : : union actions_conf {
13915 : : struct rte_flow_action_modify_field modify_field;
13916 : : struct rte_flow_action_raw_encap raw_encap;
13917 : : struct rte_flow_action_vxlan_encap vxlan_encap;
13918 : : struct rte_flow_action_nvgre_encap nvgre_encap;
13919 : : };
13920 : :
13921 : : static int
13922 : 0 : flow_nta_build_template_mask(const struct rte_flow_action actions[],
13923 : : struct rte_flow_action masks[MLX5_HW_MAX_ACTS],
13924 : : union actions_conf mask_conf[MLX5_HW_MAX_ACTS])
13925 : : {
13926 : : int i;
13927 : :
13928 [ # # # # ]: 0 : for (i = 0; i == 0 || actions[i - 1].type != RTE_FLOW_ACTION_TYPE_END; i++) {
13929 : 0 : const struct rte_flow_action *action = &actions[i];
13930 : 0 : struct rte_flow_action *mask = &masks[i];
13931 : 0 : union actions_conf *conf = &mask_conf[i];
13932 : :
13933 : 0 : mask->type = action->type;
13934 [ # # # # : 0 : switch (action->type) {
# # # ]
13935 : : case RTE_FLOW_ACTION_TYPE_INDIRECT:
13936 : 0 : mask->type = flow_nta_get_indirect_action_type(action);
13937 [ # # ]: 0 : if (!mask->type)
13938 : : return -EINVAL;
13939 : : break;
13940 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13941 : 0 : flow_nta_set_mh_mask_conf(action->conf, (void *)conf);
13942 : 0 : mask->conf = conf;
13943 : 0 : break;
13944 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13945 : : /* This mask will set this action as shared. */
13946 : : memset(conf, 0xff, sizeof(struct rte_flow_action_raw_encap));
13947 : 0 : mask->conf = conf;
13948 : 0 : break;
13949 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13950 : : /* This mask will set this action as shared. */
13951 : 0 : conf->vxlan_encap.definition =
13952 : : ((const struct rte_flow_action_vxlan_encap *)
13953 : 0 : action->conf)->definition;
13954 : 0 : mask->conf = conf;
13955 : 0 : break;
13956 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13957 : : /* This mask will set this action as shared. */
13958 : 0 : conf->nvgre_encap.definition =
13959 : : ((const struct rte_flow_action_nvgre_encap *)
13960 : 0 : action->conf)->definition;
13961 : 0 : mask->conf = conf;
13962 : 0 : break;
13963 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
13964 : : memset(conf, 0xff, sizeof(struct rte_flow_action_of_set_vlan_vid));
13965 : 0 : mask->conf = conf;
13966 : 0 : break;
13967 : : default:
13968 : : break;
13969 : : }
13970 : : }
13971 : : return 0;
13972 : : #undef NTA_CHECK_CONF_BUF_SIZE
13973 : : }
13974 : :
13975 : : static int
13976 : 0 : flow_hw_translate_flow_actions(struct rte_eth_dev *dev,
13977 : : const struct rte_flow_attr *attr,
13978 : : const struct rte_flow_action actions[],
13979 : : struct rte_flow_hw *flow,
13980 : : struct mlx5_flow_hw_action_params *ap,
13981 : : struct mlx5_hw_actions *hw_acts,
13982 : : uint64_t item_flags, uint64_t action_flags,
13983 : : bool external,
13984 : : struct rte_flow_error *error)
13985 : : {
13986 : : int ret = 0;
13987 : 0 : uint32_t src_group = 0;
13988 : : enum mlx5dr_table_type table_type;
13989 : : struct mlx5_flow_group grp;
13990 : : struct rte_flow_actions_template *at = NULL;
13991 : 0 : struct rte_flow_actions_template_attr template_attr = {
13992 : 0 : .egress = attr->egress,
13993 : 0 : .ingress = attr->ingress,
13994 : 0 : .transfer = attr->transfer,
13995 : : };
13996 : : struct rte_flow_action masks[MLX5_HW_MAX_ACTS];
13997 : : union actions_conf mask_conf[MLX5_HW_MAX_ACTS];
13998 : :
13999 : : RTE_SET_USED(action_flags);
14000 : : memset(masks, 0, sizeof(masks));
14001 : : memset(mask_conf, 0, sizeof(mask_conf));
14002 : : /* Only set the needed fields explicitly. */
14003 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
14004 : : struct rte_flow_template_table *table;
14005 : :
14006 : : /*
14007 : : * Notice All direct actions will be unmasked,
14008 : : * except for modify header and encap,
14009 : : * and therefore will be parsed as part of action construct.
14010 : : * Modify header is always shared in HWS,
14011 : : * encap is masked such that it will be treated as shared.
14012 : : * shared actions will be parsed as part of template translation
14013 : : * and not during action construct.
14014 : : */
14015 [ # # ]: 0 : if (!wks)
14016 : 0 : return rte_flow_error_set(error, ENOMEM,
14017 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14018 : : NULL,
14019 : : "failed to push flow workspace");
14020 : 0 : table = wks->table;
14021 : 0 : flow_nta_build_template_mask(actions, masks, mask_conf);
14022 : : /* The group in the attribute translation was done in advance. */
14023 : 0 : ret = __translate_group(dev, attr, external, attr->group, &src_group, error);
14024 [ # # ]: 0 : if (ret)
14025 : : return ret;
14026 [ # # ]: 0 : if (attr->transfer)
14027 : : table_type = MLX5DR_TABLE_TYPE_FDB;
14028 [ # # ]: 0 : else if (attr->egress)
14029 : : table_type = MLX5DR_TABLE_TYPE_NIC_TX;
14030 : : else
14031 : : table_type = MLX5DR_TABLE_TYPE_NIC_RX;
14032 : 0 : at = __flow_hw_actions_template_create(dev, &template_attr, actions, masks, true, error);
14033 [ # # ]: 0 : if (!at) {
14034 : 0 : ret = -rte_errno;
14035 : 0 : goto end;
14036 : : }
14037 : 0 : grp.group_id = src_group;
14038 : 0 : table->grp = &grp;
14039 : 0 : table->type = table_type;
14040 : 0 : table->cfg.external = external;
14041 : 0 : table->nb_action_templates = 1;
14042 : 0 : memcpy(&table->cfg.attr.flow_attr, attr, sizeof(*attr));
14043 : 0 : table->cfg.attr.flow_attr.group = src_group;
14044 : 0 : table->ats[0].action_template = at;
14045 : 0 : ret = __flow_hw_translate_actions_template(dev, &table->cfg, hw_acts, at,
14046 : : &table->mpctx, true, error);
14047 [ # # ]: 0 : if (ret)
14048 : 0 : goto end;
14049 : : /* handle bulk actions register. */
14050 : 0 : ret = flow_hw_encap_decap_resource_register(dev, table, hw_acts, flow, error);
14051 [ # # ]: 0 : if (ret)
14052 : 0 : goto end;
14053 : 0 : ret = flow_hw_modify_hdr_resource_register(dev, table, hw_acts, flow, error);
14054 [ # # ]: 0 : if (ret)
14055 : 0 : goto end;
14056 : 0 : table->ats[0].acts = *hw_acts;
14057 : 0 : ret = flow_hw_actions_construct(dev, flow, ap,
14058 : : &table->ats[0], item_flags, table,
14059 [ # # ]: 0 : actions, hw_acts->rule_acts, 0, error);
14060 [ # # ]: 0 : if (ret)
14061 : 0 : goto end;
14062 : 0 : goto end;
14063 : 0 : end:
14064 [ # # ]: 0 : if (ret)
14065 : : /* Make sure that there is no garbage in the actions. */
14066 : 0 : __flow_hw_action_template_destroy(dev, hw_acts);
14067 : : else
14068 : 0 : __flow_hw_act_data_flush(dev, hw_acts);
14069 [ # # ]: 0 : if (at)
14070 : 0 : mlx5_free(at);
14071 : 0 : mlx5_flow_pop_thread_workspace();
14072 : 0 : return ret;
14073 : : }
14074 : :
14075 : : static int
14076 : 0 : flow_hw_unregister_matcher(struct rte_eth_dev *dev,
14077 : : struct mlx5_flow_dv_matcher *matcher)
14078 : : {
14079 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14080 : 0 : struct mlx5_flow_group *group = matcher->group;
14081 : : int ret = 0;
14082 : :
14083 [ # # ]: 0 : if (group) {
14084 [ # # ]: 0 : if (matcher->matcher_object)
14085 : 0 : ret |= mlx5_list_unregister(group->matchers, &matcher->entry);
14086 : 0 : ret |= mlx5_hlist_unregister(priv->sh->groups, &group->entry);
14087 : : }
14088 : 0 : return ret;
14089 : : }
14090 : :
14091 : 0 : static int flow_hw_register_matcher(struct rte_eth_dev *dev,
14092 : : const struct rte_flow_attr *attr,
14093 : : const struct rte_flow_item items[],
14094 : : bool external,
14095 : : struct rte_flow_hw *flow,
14096 : : struct mlx5_flow_dv_matcher *matcher,
14097 : : struct rte_flow_error *error)
14098 : : {
14099 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14100 : 0 : struct rte_flow_error sub_error = {
14101 : : .type = RTE_FLOW_ERROR_TYPE_NONE,
14102 : : .cause = NULL,
14103 : : .message = NULL,
14104 : : };
14105 : 0 : struct rte_flow_attr flow_attr = *attr;
14106 : 0 : uint32_t specialize = 0; /* No unified FDB. */
14107 : 0 : struct mlx5_flow_cb_ctx ctx = {
14108 : : .dev = dev,
14109 : : .error = &sub_error,
14110 : : .data = &flow_attr,
14111 : : .data2 = &specialize,
14112 : : };
14113 : : void *items_ptr = &items;
14114 : 0 : struct mlx5_flow_cb_ctx matcher_ctx = {
14115 : : .error = &sub_error,
14116 : : .data = matcher,
14117 : : .data2 = items_ptr,
14118 : : };
14119 : : struct mlx5_list_entry *group_entry = NULL;
14120 : : struct mlx5_list_entry *matcher_entry = NULL;
14121 : : struct mlx5_flow_dv_matcher *resource;
14122 : : struct mlx5_list *matchers_list;
14123 : : struct mlx5_flow_group *flow_group;
14124 : : int ret;
14125 : :
14126 : :
14127 : 0 : matcher->crc = rte_raw_cksum((const void *)matcher->mask.buf,
14128 : : matcher->mask.size);
14129 : 0 : matcher->priority = attr->priority;
14130 : 0 : ret = __translate_group(dev, attr, external, attr->group, &flow_attr.group, error);
14131 [ # # ]: 0 : if (ret)
14132 : : return ret;
14133 : :
14134 : : /* Register the flow group. */
14135 : 0 : group_entry = mlx5_hlist_register(priv->sh->groups, flow_attr.group, &ctx);
14136 [ # # ]: 0 : if (!group_entry)
14137 : 0 : goto error;
14138 : : flow_group = container_of(group_entry, struct mlx5_flow_group, entry);
14139 : :
14140 : 0 : matchers_list = flow_group->matchers;
14141 : 0 : matcher->group = flow_group;
14142 : 0 : matcher_entry = mlx5_list_register(matchers_list, &matcher_ctx);
14143 [ # # ]: 0 : if (!matcher_entry)
14144 : 0 : goto error;
14145 : : resource = container_of(matcher_entry, typeof(*resource), entry);
14146 : 0 : flow->nt2hws->matcher = resource;
14147 : 0 : return 0;
14148 : :
14149 : 0 : error:
14150 [ # # ]: 0 : if (group_entry)
14151 : 0 : mlx5_hlist_unregister(priv->sh->groups, group_entry);
14152 [ # # ]: 0 : if (error) {
14153 [ # # ]: 0 : if (sub_error.type != RTE_FLOW_ERROR_TYPE_NONE)
14154 : : rte_memcpy(error, &sub_error, sizeof(sub_error));
14155 : : }
14156 : 0 : return rte_flow_error_set(error, rte_errno,
14157 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14158 : : NULL, "fail to register matcher");
14159 : : }
14160 : :
14161 : : static int
14162 : 0 : flow_hw_allocate_actions(struct rte_eth_dev *dev,
14163 : : uint64_t action_flags,
14164 : : struct rte_flow_error *error)
14165 : : {
14166 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14167 : : int ret;
14168 : : uint obj_num;
14169 : :
14170 : 0 : error->type = RTE_FLOW_ERROR_TYPE_NONE;
14171 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
14172 : : /* If no age objects were previously allocated. */
14173 [ # # ]: 0 : if (!priv->hws_age_req) {
14174 : : /* If no counters were previously allocated. */
14175 [ # # ]: 0 : if (!priv->hws_cpool) {
14176 : 0 : obj_num = MLX5_CNT_NT_MAX(priv);
14177 : 0 : ret = mlx5_hws_cnt_pool_create(dev, obj_num,
14178 : 0 : priv->nb_queue,
14179 : : NULL, error);
14180 [ # # ]: 0 : if (ret)
14181 : 0 : goto err;
14182 : : }
14183 : : /* Allocate same number of counters. */
14184 : 0 : ret = mlx5_hws_age_pool_init(dev, priv->hws_cpool->cfg.request_num,
14185 : 0 : priv->nb_queue, false);
14186 [ # # ]: 0 : if (ret)
14187 : 0 : goto err;
14188 : : }
14189 : : }
14190 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
14191 : : /* If no counters were previously allocated. */
14192 [ # # ]: 0 : if (!priv->hws_cpool) {
14193 : 0 : obj_num = MLX5_CNT_NT_MAX(priv);
14194 : 0 : ret = mlx5_hws_cnt_pool_create(dev, obj_num,
14195 : 0 : priv->nb_queue, NULL,
14196 : : error);
14197 [ # # ]: 0 : if (ret)
14198 : 0 : goto err;
14199 : : }
14200 : : }
14201 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_CT) {
14202 : : /* If no CT were previously allocated. */
14203 [ # # ]: 0 : if (!priv->hws_ctpool) {
14204 : 0 : obj_num = MLX5_CT_NT_MAX(priv);
14205 : 0 : ret = mlx5_flow_ct_init(dev, obj_num, priv->nb_queue);
14206 [ # # ]: 0 : if (ret)
14207 : 0 : goto err;
14208 : : }
14209 : : }
14210 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER) {
14211 : : /* If no meters were previously allocated. */
14212 [ # # ]: 0 : if (!priv->hws_mpool) {
14213 : 0 : obj_num = MLX5_MTR_NT_MAX(priv);
14214 : 0 : ret = mlx5_flow_meter_init(dev, obj_num, 0, 0,
14215 : : priv->nb_queue);
14216 [ # # ]: 0 : if (ret)
14217 : 0 : goto err;
14218 : : }
14219 : : }
14220 : : return 0;
14221 : 0 : err:
14222 [ # # ]: 0 : if (ret && error->type != RTE_FLOW_ERROR_TYPE_NONE)
14223 : : return ret;
14224 : 0 : return rte_flow_error_set(error, ret,
14225 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14226 : : NULL, "fail to allocate actions");
14227 : : }
14228 : :
14229 : 0 : static int flow_hw_apply(const struct rte_flow_item items[],
14230 : : struct mlx5dr_rule_action rule_actions[],
14231 : : struct rte_flow_hw *flow,
14232 : : struct rte_flow_error *error)
14233 : : {
14234 : : struct mlx5dr_bwc_rule *rule = NULL;
14235 : :
14236 : 0 : rule = mlx5dr_bwc_rule_create((struct mlx5dr_bwc_matcher *)
14237 : 0 : flow->nt2hws->matcher->matcher_object,
14238 : : items, rule_actions);
14239 : 0 : flow->nt2hws->nt_rule = rule;
14240 [ # # ]: 0 : if (!rule) {
14241 : 0 : return rte_flow_error_set(error, EINVAL,
14242 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14243 : : NULL, "fail to create rte flow");
14244 : : }
14245 : : return 0;
14246 : : }
14247 : :
14248 : : #ifdef HAVE_MLX5_HWS_SUPPORT
14249 : : /**
14250 : : * Create a flow.
14251 : : *
14252 : : * @param[in] dev
14253 : : * Pointer to Ethernet device.
14254 : : * @param[in] type
14255 : : * Flow type.
14256 : : * @param[in] attr
14257 : : * Flow rule attributes.
14258 : : * @param[in] items
14259 : : * Pattern specification (list terminated by the END pattern item).
14260 : : * @param[in] actions
14261 : : * Associated actions (list terminated by the END action).
14262 : : * @param[in] external
14263 : : * This flow rule is created by request external to PMD.
14264 : : * @param[out] flow
14265 : : * Flow pointer
14266 : : * @param[out] error
14267 : : * Perform verbose error reporting if not NULL.
14268 : : *
14269 : : * @return
14270 : : * 0 on success, negative errno value otherwise and rte_errno set.
14271 : : */
14272 : : int
14273 : 0 : mlx5_flow_hw_create_flow(struct rte_eth_dev *dev, enum mlx5_flow_type type,
14274 : : const struct rte_flow_attr *attr,
14275 : : const struct rte_flow_item items[],
14276 : : const struct rte_flow_action actions[],
14277 : : uint64_t item_flags, uint64_t action_flags, bool external,
14278 : : struct rte_flow_hw **flow, struct rte_flow_error *error)
14279 : : {
14280 : : int ret;
14281 : 0 : struct mlx5_hw_actions hw_act = { { NULL } };
14282 : : struct mlx5_flow_hw_action_params ap;
14283 : 0 : struct mlx5_flow_dv_matcher matcher = {
14284 : : .mask = {
14285 : : .size = sizeof(matcher.mask.buf),
14286 : : },
14287 : : };
14288 : : uint32_t tbl_type;
14289 : :
14290 : 0 : struct mlx5_flow_attr flow_attr = {
14291 : 0 : .port_id = dev->data->port_id,
14292 : 0 : .group = attr->group,
14293 : 0 : .priority = attr->priority,
14294 : : .rss_level = 0,
14295 : : .act_flags = action_flags,
14296 : : .tbl_type = 0,
14297 : : };
14298 : :
14299 [ # # ]: 0 : if (attr->transfer)
14300 : : tbl_type = MLX5DR_TABLE_TYPE_FDB;
14301 [ # # ]: 0 : else if (attr->egress)
14302 : : tbl_type = MLX5DR_TABLE_TYPE_NIC_TX;
14303 : : else
14304 : : tbl_type = MLX5DR_TABLE_TYPE_NIC_RX;
14305 : 0 : flow_attr.tbl_type = tbl_type;
14306 : :
14307 : : /* Allocate needed memory. */
14308 : 0 : ret = flow_hw_prepare(dev, actions, type, flow, error);
14309 [ # # ]: 0 : if (ret)
14310 : 0 : goto error;
14311 : :
14312 : : /* TODO TBD flow_hw_handle_tunnel_offload(). */
14313 : 0 : (*flow)->nt_rule = true;
14314 : 0 : (*flow)->nt2hws->matcher = &matcher;
14315 : 0 : ret = mlx5_flow_dv_translate_items_hws_impl(items, &flow_attr, &matcher.mask.buf,
14316 : : MLX5_SET_MATCHER_HS_M, NULL,
14317 : : NULL, true, error);
14318 : :
14319 [ # # ]: 0 : if (ret)
14320 : 0 : goto error;
14321 : :
14322 [ # # # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_ECPRI && !mlx5_flex_parser_ecpri_exist(dev))
14323 [ # # ]: 0 : if (mlx5_flex_parser_ecpri_alloc(dev)) {
14324 : 0 : rte_flow_error_set(error, EIO,
14325 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14326 : : NULL,
14327 : : "failed to create Flex parser "
14328 : : "profile for ECPRI");
14329 : 0 : goto error;
14330 : : }
14331 : 0 : ret = flow_hw_register_matcher(dev, attr, items, external, *flow, &matcher, error);
14332 [ # # ]: 0 : if (ret) {
14333 [ # # ]: 0 : if (rte_errno == E2BIG)
14334 : 0 : rte_flow_error_set(error, E2BIG, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14335 : : "flow pattern is too big");
14336 : 0 : goto error;
14337 : : }
14338 : :
14339 : : /*
14340 : : * ASO allocation – iterating on actions list to allocate missing resources.
14341 : : * In the future when validate function in hws will be added,
14342 : : * The output actions bit mask instead of
14343 : : * looping on the actions array twice.
14344 : : */
14345 : 0 : ret = flow_hw_allocate_actions(dev, action_flags, error);
14346 [ # # ]: 0 : if (ret)
14347 : 0 : goto error;
14348 : :
14349 : : /* Note: the actions should be saved in the sub-flow rule itself for reference. */
14350 : 0 : ret = flow_hw_translate_flow_actions(dev, attr, actions, *flow, &ap, &hw_act,
14351 : : item_flags, action_flags, external, error);
14352 [ # # ]: 0 : if (ret)
14353 : 0 : goto error;
14354 : :
14355 : : /*
14356 : : * If the flow is external (from application) OR device is started,
14357 : : * OR mreg discover, then apply immediately.
14358 : : */
14359 [ # # # # ]: 0 : if (external || dev->data->dev_started ||
14360 [ # # ]: 0 : (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
14361 [ # # ]: 0 : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
14362 : 0 : ret = flow_hw_apply(items, hw_act.rule_acts, *flow, error);
14363 [ # # ]: 0 : if (ret)
14364 : 0 : goto error;
14365 : : }
14366 : : ret = 0;
14367 : 0 : error:
14368 : : /*
14369 : : * Release memory allocated.
14370 : : * Cannot use __flow_hw_actions_release(dev, &hw_act);
14371 : : * since it destroys the actions as well.
14372 : : */
14373 [ # # ]: 0 : if (hw_act.encap_decap)
14374 : 0 : mlx5_free(hw_act.encap_decap);
14375 [ # # ]: 0 : if (hw_act.push_remove)
14376 : 0 : mlx5_free(hw_act.push_remove);
14377 [ # # ]: 0 : if (hw_act.mhdr)
14378 : 0 : mlx5_free(hw_act.mhdr);
14379 : 0 : return ret;
14380 : : }
14381 : : #endif
14382 : :
14383 : : void
14384 : 0 : mlx5_flow_hw_destroy(struct rte_eth_dev *dev, struct rte_flow_hw *flow)
14385 : : {
14386 : : int ret;
14387 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14388 : :
14389 [ # # # # ]: 0 : if (!flow || !flow->nt2hws)
14390 : : return;
14391 : :
14392 [ # # ]: 0 : if (flow->nt2hws->nt_rule) {
14393 : 0 : ret = mlx5dr_bwc_rule_destroy(flow->nt2hws->nt_rule);
14394 [ # # ]: 0 : if (ret)
14395 : 0 : DRV_LOG(ERR, "bwc rule destroy failed");
14396 : 0 : flow->nt2hws->nt_rule = NULL;
14397 : : }
14398 [ # # ]: 0 : flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY;
14399 : : /* Notice this function does not handle shared/static actions. */
14400 : : hw_cmpl_flow_update_or_destroy(dev, flow, 0, NULL);
14401 : :
14402 : : /**
14403 : : * TODO: TBD - Release tunnel related memory allocations(mlx5_flow_tunnel_free)
14404 : : * – needed only if supporting tunnel offloads, notice update RX queue flags in SWS.
14405 : : */
14406 : :
14407 : : /**
14408 : : * Notice matcher destroy will take place when matcher's list is destroyed
14409 : : * , same as for DV.
14410 : : */
14411 [ # # ]: 0 : if (flow->nt2hws->flow_aux)
14412 : 0 : flow->nt2hws->flow_aux = NULL;
14413 [ # # ]: 0 : if (flow->nt2hws->rix_encap_decap) {
14414 : 0 : mlx5_flow_encap_decap_resource_release(dev, flow->nt2hws->rix_encap_decap);
14415 : 0 : flow->nt2hws->rix_encap_decap = 0;
14416 : : }
14417 [ # # ]: 0 : if (flow->nt2hws->modify_hdr) {
14418 : : MLX5_ASSERT(flow->nt2hws->modify_hdr->action);
14419 : 0 : mlx5_hlist_unregister(priv->sh->modify_cmds,
14420 : : &flow->nt2hws->modify_hdr->entry);
14421 : 0 : flow->nt2hws->modify_hdr = NULL;
14422 : : }
14423 [ # # ]: 0 : if (flow->nt2hws->matcher) {
14424 : 0 : flow_hw_unregister_matcher(dev, flow->nt2hws->matcher);
14425 : 0 : flow->nt2hws->matcher = NULL;
14426 : : }
14427 [ # # ]: 0 : if (flow->nt2hws->sample_release_ctx != NULL) {
14428 : 0 : mlx5_nta_sample_mirror_entry_release(dev, flow->nt2hws->sample_release_ctx);
14429 : 0 : flow->nt2hws->sample_release_ctx = NULL;
14430 : : }
14431 : : }
14432 : :
14433 : : #ifdef HAVE_MLX5_HWS_SUPPORT
14434 : : /**
14435 : : * Destroy a flow.
14436 : : *
14437 : : * @param[in] dev
14438 : : * Pointer to Ethernet device.
14439 : : * @param[in] type
14440 : : * Flow type.
14441 : : * @param[in] flow_addr
14442 : : * Address of flow to destroy.
14443 : : */
14444 : : void
14445 : 0 : mlx5_flow_hw_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
14446 : : uintptr_t flow_addr)
14447 : : {
14448 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14449 : 0 : struct rte_flow_hw *flow = (struct rte_flow_hw *)flow_addr;
14450 : : struct mlx5_nta_rss_flow_head head = { .slh_first = flow };
14451 : :
14452 [ # # # # : 0 : if (!flow || !flow->nt2hws || flow->nt2hws->chaned_flow)
# # ]
14453 : : return;
14454 : 0 : mlx5_flow_nta_del_copy_action(dev, flow->nt2hws->rix_mreg_copy);
14455 [ # # ]: 0 : while (!SLIST_EMPTY(&head)) {
14456 : : flow = SLIST_FIRST(&head);
14457 : 0 : SLIST_REMOVE_HEAD(&head, nt2hws->next);
14458 : 0 : mlx5_flow_hw_destroy(dev, flow);
14459 : : /* Release flow memory by idx */
14460 : 0 : mlx5_ipool_free(priv->flows[type], flow->idx);
14461 : : }
14462 : : }
14463 : : #endif
14464 : :
14465 : : /**
14466 : : * Create a flow.
14467 : : *
14468 : : * @param[in] dev
14469 : : * Pointer to Ethernet device.
14470 : : * @param[in] type
14471 : : * Flow type.
14472 : : * @param[in] attr
14473 : : * Flow rule attributes.
14474 : : * @param[in] items
14475 : : * Pattern specification (list terminated by the END pattern item).
14476 : : * @param[in] actions
14477 : : * Associated actions (list terminated by the END action).
14478 : : * @param[in] external
14479 : : * This flow rule is created by request external to PMD.
14480 : : * @param[out] error
14481 : : * Perform verbose error reporting if not NULL.
14482 : : *
14483 : : * @return
14484 : : * A flow addr on success, 0 otherwise and rte_errno is set.
14485 : : */
14486 : 0 : static uintptr_t flow_hw_list_create(struct rte_eth_dev *dev,
14487 : : enum mlx5_flow_type type,
14488 : : const struct rte_flow_attr *attr,
14489 : : const struct rte_flow_item items[],
14490 : : const struct rte_flow_action actions[],
14491 : : bool external,
14492 : : struct rte_flow_error *error)
14493 : : {
14494 : : int ret;
14495 : : int split;
14496 : : int encap_idx;
14497 : 0 : uint32_t cpy_idx = 0;
14498 : 0 : int actions_n = 0;
14499 : 0 : struct rte_flow_hw *flow = NULL;
14500 : 0 : struct rte_flow_hw *prfx_flow = NULL;
14501 : 0 : const struct rte_flow_action *qrss = NULL;
14502 : 0 : const struct rte_flow_action *mark = NULL;
14503 : 0 : uint64_t action_flags = mlx5_flow_hw_action_flags_get(actions, &qrss, &mark,
14504 : : &encap_idx, &actions_n, error);
14505 : 0 : struct mlx5_flow_hw_split_resource resource = {
14506 : : .suffix = {
14507 : : .attr = attr,
14508 : : .items = items,
14509 : : .actions = actions,
14510 : : },
14511 : : };
14512 : 0 : struct rte_flow_error shadow_error = {0, };
14513 : 0 : const struct rte_flow_pattern_template_attr pattern_template_attr = {
14514 : : .relaxed_matching = 0,
14515 : 0 : .ingress = attr->ingress,
14516 : 0 : .egress = attr->egress,
14517 : 0 : .transfer = attr->transfer,
14518 : : };
14519 : 0 : struct rte_flow_item *copied_items = NULL;
14520 : : const struct rte_flow_item *prepend_items;
14521 : : uint64_t orig_item_nb, item_flags;
14522 : :
14523 : : RTE_SET_USED(encap_idx);
14524 [ # # ]: 0 : if (!error)
14525 : : error = &shadow_error;
14526 : :
14527 : 0 : prepend_items = flow_hw_adjust_pattern(dev, &pattern_template_attr, true, items,
14528 : : &item_flags, &orig_item_nb, &copied_items, error);
14529 [ # # ]: 0 : if (!prepend_items)
14530 : : return 0;
14531 : :
14532 : 0 : split = mlx5_flow_nta_split_metadata(dev, attr, actions, qrss, action_flags,
14533 : : actions_n, external, &resource, error);
14534 [ # # ]: 0 : if (split < 0) {
14535 : 0 : mlx5_free(copied_items);
14536 : 0 : return 0;
14537 [ # # ]: 0 : } else if (!split) {
14538 : 0 : resource.suffix.items = prepend_items;
14539 : : }
14540 : :
14541 : : /* Update the metadata copy table - MLX5_FLOW_MREG_CP_TABLE_GROUP */
14542 [ # # # # : 0 : if (((attr->ingress && attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) ||
# # ]
14543 [ # # ]: 0 : attr->transfer) && external) {
14544 : 0 : ret = mlx5_flow_nta_update_copy_table(dev, &cpy_idx, mark,
14545 : : action_flags, error);
14546 [ # # ]: 0 : if (ret)
14547 : 0 : goto free;
14548 : : }
14549 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
14550 : 0 : flow = mlx5_nta_sample_flow_list_create(dev, type, attr, prepend_items, actions,
14551 : : item_flags, action_flags, error);
14552 [ # # ]: 0 : if (flow != NULL) {
14553 : 0 : mlx5_free(copied_items);
14554 : 0 : return (uintptr_t)flow;
14555 : : }
14556 : 0 : goto free;
14557 : : }
14558 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
14559 : : const struct rte_flow_action_rss
14560 : 0 : *rss_conf = mlx5_flow_nta_locate_rss(dev, actions, error);
14561 : 0 : flow = mlx5_flow_nta_handle_rss(dev, attr, prepend_items, actions, rss_conf,
14562 : : item_flags, action_flags, external, type, error);
14563 [ # # ]: 0 : if (flow) {
14564 : 0 : flow->nt2hws->rix_mreg_copy = cpy_idx;
14565 : 0 : cpy_idx = 0;
14566 [ # # ]: 0 : if (!split) {
14567 : 0 : mlx5_free(copied_items);
14568 : 0 : return (uintptr_t)flow;
14569 : : }
14570 : 0 : goto prefix_flow;
14571 : : }
14572 : 0 : goto free;
14573 : : }
14574 : : /* Create single flow. */
14575 : 0 : ret = mlx5_flow_hw_create_flow(dev, type, resource.suffix.attr, resource.suffix.items,
14576 : : resource.suffix.actions, item_flags, action_flags,
14577 : : external, &flow, error);
14578 [ # # ]: 0 : if (ret)
14579 : 0 : goto free;
14580 [ # # ]: 0 : if (flow) {
14581 : 0 : flow->nt2hws->rix_mreg_copy = cpy_idx;
14582 : 0 : cpy_idx = 0;
14583 [ # # ]: 0 : if (!split) {
14584 : 0 : mlx5_free(copied_items);
14585 : 0 : return (uintptr_t)flow;
14586 : : }
14587 : : /* Fall Through to prefix flow creation. */
14588 : : }
14589 : 0 : prefix_flow:
14590 : 0 : ret = mlx5_flow_hw_create_flow(dev, type, attr, prepend_items, resource.prefix.actions,
14591 : : item_flags, action_flags, external, &prfx_flow, error);
14592 [ # # ]: 0 : if (ret)
14593 : 0 : goto free;
14594 [ # # ]: 0 : if (prfx_flow) {
14595 : 0 : prfx_flow->nt2hws->rix_mreg_copy = flow->nt2hws->rix_mreg_copy;
14596 : 0 : flow->nt2hws->chaned_flow = 1;
14597 : 0 : SLIST_INSERT_AFTER(prfx_flow, flow, nt2hws->next);
14598 : 0 : mlx5_flow_nta_split_resource_free(dev, &resource);
14599 : 0 : mlx5_free(copied_items);
14600 : 0 : return (uintptr_t)prfx_flow;
14601 : : }
14602 : 0 : free:
14603 [ # # ]: 0 : if (prfx_flow)
14604 : 0 : mlx5_flow_hw_list_destroy(dev, type, (uintptr_t)prfx_flow);
14605 [ # # ]: 0 : if (flow)
14606 : 0 : mlx5_flow_hw_list_destroy(dev, type, (uintptr_t)flow);
14607 [ # # ]: 0 : if (cpy_idx)
14608 : 0 : mlx5_flow_nta_del_copy_action(dev, cpy_idx);
14609 [ # # ]: 0 : if (split > 0)
14610 : 0 : mlx5_flow_nta_split_resource_free(dev, &resource);
14611 : 0 : mlx5_free(copied_items);
14612 : 0 : return 0;
14613 : : }
14614 : :
14615 : : static void
14616 : 0 : mlx5_mirror_destroy_clone(struct rte_eth_dev *dev,
14617 : : struct mlx5_mirror_clone *clone)
14618 : : {
14619 [ # # # ]: 0 : switch (clone->type) {
14620 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
14621 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
14622 : 0 : mlx5_hrxq_release(dev,
14623 : 0 : ((struct mlx5_hrxq *)(clone->action_ctx))->idx);
14624 : 0 : break;
14625 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
14626 : 0 : flow_hw_jump_release(dev, clone->action_ctx);
14627 : : break;
14628 : : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
14629 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14630 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14631 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14632 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14633 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14634 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14635 : : default:
14636 : : break;
14637 : : }
14638 : 0 : }
14639 : :
14640 : : void
14641 [ # # ]: 0 : mlx5_hw_mirror_destroy(struct rte_eth_dev *dev, struct mlx5_mirror *mirror)
14642 : : {
14643 : : uint32_t i;
14644 : :
14645 : : mlx5_indirect_list_remove_entry(&mirror->indirect);
14646 : : /*
14647 : : * The mirror action is a composite dest_array that references each
14648 : : * clone destination (jump table or Rx queue). It must be destroyed
14649 : : * before the clones so the underlying destinations are no longer
14650 : : * referenced when they are released; otherwise releasing a clone can
14651 : : * drop the last reference to a group table and destroy it while the
14652 : : * dest_array still points at it, leaking the firmware flow table.
14653 : : */
14654 [ # # ]: 0 : if (mirror->mirror_action)
14655 : 0 : mlx5dr_action_destroy(mirror->mirror_action);
14656 [ # # ]: 0 : for (i = 0; i < mirror->clones_num; i++)
14657 : 0 : mlx5_mirror_destroy_clone(dev, &mirror->clone[i]);
14658 : 0 : mlx5_free(mirror);
14659 : 0 : }
14660 : :
14661 : : static __rte_always_inline bool
14662 : : mlx5_mirror_terminal_action(const struct rte_flow_action *action)
14663 : : {
14664 : 0 : switch (action->type) {
14665 : : case RTE_FLOW_ACTION_TYPE_JUMP:
14666 : : case RTE_FLOW_ACTION_TYPE_RSS:
14667 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
14668 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14669 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14670 : : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
14671 : : case RTE_FLOW_ACTION_TYPE_DROP:
14672 : : return true;
14673 : : default:
14674 : : break;
14675 : : }
14676 : : return false;
14677 : : }
14678 : :
14679 : : static bool
14680 : 0 : mlx5_mirror_validate_sample_action(struct rte_eth_dev *dev,
14681 : : const struct rte_flow_attr *flow_attr,
14682 : : const struct rte_flow_action *action)
14683 : : {
14684 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14685 : : const struct rte_flow_action_ethdev *port = NULL;
14686 [ # # # # ]: 0 : bool is_proxy = MLX5_HW_PORT_IS_PROXY(priv);
14687 : :
14688 [ # # ]: 0 : if (!action)
14689 : : return false;
14690 [ # # # # : 0 : switch (action->type) {
# ]
14691 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
14692 : : case RTE_FLOW_ACTION_TYPE_RSS:
14693 [ # # ]: 0 : if (flow_attr->transfer)
14694 : : return false;
14695 : : break;
14696 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14697 [ # # # # ]: 0 : if (!is_proxy || !flow_attr->transfer)
14698 : : return false;
14699 : 0 : port = action->conf;
14700 [ # # # # ]: 0 : if (!port || port->port_id != MLX5_REPRESENTED_PORT_ESW_MGR)
14701 : : return false;
14702 : : break;
14703 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14704 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14705 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14706 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14707 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14708 [ # # # # ]: 0 : if (!is_proxy || !flow_attr->transfer)
14709 : : return false;
14710 [ # # ]: 0 : if (action[0].type == RTE_FLOW_ACTION_TYPE_RAW_DECAP &&
14711 [ # # ]: 0 : action[1].type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP)
14712 : : return false;
14713 : : break;
14714 : : case RTE_FLOW_ACTION_TYPE_JUMP_TO_TABLE_INDEX:
14715 : : case RTE_FLOW_ACTION_TYPE_JUMP:
14716 : : case RTE_FLOW_ACTION_TYPE_DROP:
14717 : : break;
14718 : : default:
14719 : : return false;
14720 : : }
14721 : 0 : return true;
14722 : : }
14723 : :
14724 : : /**
14725 : : * Valid mirror actions list includes one or two SAMPLE actions
14726 : : * followed by JUMP.
14727 : : *
14728 : : * @return
14729 : : * Number of mirrors *action* list was valid.
14730 : : * -EINVAL otherwise.
14731 : : */
14732 : : static int
14733 : 0 : mlx5_hw_mirror_actions_list_validate(struct rte_eth_dev *dev,
14734 : : const struct rte_flow_attr *flow_attr,
14735 : : const struct rte_flow_action *actions)
14736 : : {
14737 [ # # ]: 0 : if (actions[0].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
14738 : : int i = 1;
14739 : : bool valid;
14740 : 0 : const struct rte_flow_action_sample *sample = actions[0].conf;
14741 : 0 : valid = mlx5_mirror_validate_sample_action(dev, flow_attr,
14742 : 0 : sample->actions);
14743 [ # # ]: 0 : if (!valid)
14744 : : return -EINVAL;
14745 [ # # ]: 0 : if (actions[1].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
14746 : : i = 2;
14747 : 0 : sample = actions[1].conf;
14748 : 0 : valid = mlx5_mirror_validate_sample_action(dev, flow_attr,
14749 : 0 : sample->actions);
14750 [ # # ]: 0 : if (!valid)
14751 : : return -EINVAL;
14752 : : }
14753 [ # # ]: 0 : return mlx5_mirror_terminal_action(actions + i) ? i + 1 : -EINVAL;
14754 : : }
14755 : : return -EINVAL;
14756 : : }
14757 : :
14758 : : static int
14759 : 0 : mirror_format_tir(struct rte_eth_dev *dev,
14760 : : struct mlx5_mirror_clone *clone,
14761 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14762 : : const struct rte_flow_action *action,
14763 : : struct mlx5dr_action_dest_attr *dest_attr,
14764 : : struct rte_flow_error *error)
14765 : : {
14766 : : uint32_t hws_flags;
14767 : : enum mlx5dr_table_type table_type;
14768 : : struct mlx5_hrxq *tir_ctx;
14769 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14770 : : bool unified_fdb = is_unified_fdb(priv);
14771 : :
14772 : 0 : table_type = get_mlx5dr_table_type(&table_cfg->attr.flow_attr, table_cfg->attr.specialize,
14773 : : unified_fdb);
14774 : 0 : hws_flags = mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_NONE_ROOT][table_type];
14775 : 0 : tir_ctx = flow_hw_tir_action_register(dev, hws_flags, action);
14776 [ # # ]: 0 : if (!tir_ctx)
14777 : 0 : return rte_flow_error_set(error, EINVAL,
14778 : : RTE_FLOW_ERROR_TYPE_ACTION,
14779 : : action, "failed to create QUEUE action for mirror clone");
14780 : 0 : dest_attr->dest = tir_ctx->action;
14781 : 0 : clone->action_ctx = tir_ctx;
14782 : 0 : return 0;
14783 : : }
14784 : :
14785 : : static int
14786 : 0 : mirror_format_jump(struct rte_eth_dev *dev,
14787 : : struct mlx5_mirror_clone *clone,
14788 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14789 : : const struct rte_flow_action *action,
14790 : : struct mlx5dr_action_dest_attr *dest_attr,
14791 : : struct rte_flow_error *error)
14792 : : {
14793 : 0 : const struct rte_flow_action_jump *jump_conf = action->conf;
14794 : 0 : struct mlx5_hw_jump_action *jump = flow_hw_jump_action_register
14795 : : (dev, table_cfg,
14796 : 0 : jump_conf->group, error);
14797 : :
14798 [ # # ]: 0 : if (!jump)
14799 : 0 : return rte_flow_error_set(error, EINVAL,
14800 : : RTE_FLOW_ERROR_TYPE_ACTION,
14801 : : action, "failed to create JUMP action for mirror clone");
14802 : 0 : dest_attr->dest = jump->hws_action;
14803 : 0 : clone->action_ctx = jump;
14804 : 0 : return 0;
14805 : : }
14806 : :
14807 : : static int
14808 : : mirror_format_port(struct rte_eth_dev *dev,
14809 : : const struct rte_flow_action *action,
14810 : : struct mlx5dr_action_dest_attr *dest_attr,
14811 : : struct rte_flow_error __rte_unused *error)
14812 : : {
14813 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14814 : 0 : const struct rte_flow_action_ethdev *port_action = action->conf;
14815 : :
14816 : 0 : dest_attr->dest = priv->hw_vport[port_action->port_id];
14817 : : return 0;
14818 : : }
14819 : :
14820 : : static int
14821 : 0 : hw_mirror_clone_reformat(const struct rte_flow_action *actions,
14822 : : struct mlx5dr_action_dest_attr *dest_attr,
14823 : : enum mlx5dr_action_type *action_type,
14824 : : uint8_t *reformat_buf, bool decap)
14825 : : {
14826 : : int ret;
14827 : : const struct rte_flow_item *encap_item = NULL;
14828 : : const struct rte_flow_action_raw_encap *encap_conf = NULL;
14829 : : typeof(dest_attr->reformat) *reformat = &dest_attr->reformat;
14830 : :
14831 [ # # # # ]: 0 : switch (actions[0].type) {
14832 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14833 : 0 : encap_conf = actions[0].conf;
14834 : 0 : break;
14835 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14836 : 0 : encap_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_vxlan_encap,
14837 : : actions);
14838 : 0 : break;
14839 : 0 : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14840 : 0 : encap_item = MLX5_CONST_ENCAP_ITEM(rte_flow_action_nvgre_encap,
14841 : : actions);
14842 : 0 : break;
14843 : : default:
14844 : : return -EINVAL;
14845 : : }
14846 : 0 : *action_type = decap ?
14847 [ # # ]: 0 : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3 :
14848 : : MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
14849 [ # # ]: 0 : if (encap_item) {
14850 : 0 : ret = mlx5_flow_dv_convert_encap_data(encap_item, reformat_buf,
14851 : : &reformat->reformat_data_sz, NULL);
14852 [ # # ]: 0 : if (ret)
14853 : : return -EINVAL;
14854 : 0 : reformat->reformat_data = reformat_buf;
14855 : : } else {
14856 : 0 : reformat->reformat_data = (void *)(uintptr_t)encap_conf->data;
14857 : 0 : reformat->reformat_data_sz = encap_conf->size;
14858 : : }
14859 : : return 0;
14860 : : }
14861 : :
14862 : : static int
14863 : 0 : hw_mirror_format_clone(struct rte_eth_dev *dev,
14864 : : struct mlx5_mirror_clone *clone,
14865 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14866 : : const struct rte_flow_action *actions,
14867 : : struct mlx5dr_action_dest_attr *dest_attr,
14868 : : uint8_t *reformat_buf,
14869 : : enum mlx5dr_table_type table_type,
14870 : : struct rte_flow_error *error)
14871 : : {
14872 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14873 : : int ret;
14874 : : uint32_t i;
14875 : : bool decap_seen = false;
14876 : :
14877 [ # # ]: 0 : for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
14878 : 0 : dest_attr->action_type[i] = mlx5_hw_dr_action_types[actions[i].type];
14879 [ # # # # : 0 : switch (actions[i].type) {
# # # # ]
14880 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
14881 : : case RTE_FLOW_ACTION_TYPE_RSS:
14882 : 0 : ret = mirror_format_tir(dev, clone, table_cfg,
14883 : : &actions[i], dest_attr, error);
14884 [ # # ]: 0 : if (ret)
14885 : 0 : return ret;
14886 : : break;
14887 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14888 : : ret = mirror_format_port(dev, &actions[i],
14889 : : dest_attr, error);
14890 : : if (ret)
14891 : : return ret;
14892 : : break;
14893 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
14894 : 0 : ret = mirror_format_jump(dev, clone, table_cfg,
14895 : : &actions[i], dest_attr, error);
14896 [ # # ]: 0 : if (ret)
14897 : 0 : return ret;
14898 : : break;
14899 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
14900 : 0 : dest_attr->dest = mlx5_hws_global_action_def_miss_get(priv,
14901 : : table_type,
14902 : : false);
14903 [ # # ]: 0 : if (dest_attr->dest == NULL)
14904 : 0 : return rte_flow_error_set(error, ENOMEM,
14905 : : RTE_FLOW_ERROR_TYPE_STATE, NULL,
14906 : : "failed to allocate port representor action");
14907 : : break;
14908 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14909 : : decap_seen = true;
14910 : 0 : break;
14911 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14912 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14913 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14914 : 0 : ret = hw_mirror_clone_reformat(&actions[i], dest_attr,
14915 : : &dest_attr->action_type[i],
14916 : : reformat_buf, decap_seen);
14917 [ # # ]: 0 : if (ret < 0)
14918 : 0 : return rte_flow_error_set(error, EINVAL,
14919 : : RTE_FLOW_ERROR_TYPE_ACTION,
14920 : : &actions[i],
14921 : : "failed to create reformat action");
14922 : : break;
14923 : : case RTE_FLOW_ACTION_TYPE_DROP:
14924 : : break;
14925 : 0 : default:
14926 : 0 : return rte_flow_error_set(error, EINVAL,
14927 : : RTE_FLOW_ERROR_TYPE_ACTION,
14928 : : &actions[i], "unsupported sample action");
14929 : : }
14930 : 0 : clone->type = actions->type;
14931 : : }
14932 : 0 : dest_attr->action_type[i] = MLX5DR_ACTION_TYP_LAST;
14933 : 0 : return 0;
14934 : : }
14935 : :
14936 : : struct mlx5_mirror *
14937 : 0 : mlx5_hw_create_mirror(struct rte_eth_dev *dev,
14938 : : const struct mlx5_flow_template_table_cfg *table_cfg,
14939 : : const struct rte_flow_action *actions,
14940 : : struct rte_flow_error *error)
14941 : : {
14942 : : uint32_t hws_flags;
14943 : : int ret = 0, i, clones_num;
14944 : : struct mlx5_mirror *mirror;
14945 : : enum mlx5dr_table_type table_type;
14946 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
14947 : : bool unified_fdb = is_unified_fdb(priv);
14948 [ # # ]: 0 : const struct rte_flow_attr *flow_attr = &table_cfg->attr.flow_attr;
14949 : : uint8_t reformat_buf[MLX5_MIRROR_MAX_CLONES_NUM][MLX5_ENCAP_MAX_LEN];
14950 : : struct mlx5dr_action_dest_attr mirror_attr[MLX5_MIRROR_MAX_CLONES_NUM + 1];
14951 : : enum mlx5dr_action_type array_action_types[MLX5_MIRROR_MAX_CLONES_NUM + 1]
14952 : : [MLX5_MIRROR_MAX_SAMPLE_ACTIONS_LEN + 1];
14953 : :
14954 : : memset(mirror_attr, 0, sizeof(mirror_attr));
14955 : : memset(array_action_types, 0, sizeof(array_action_types));
14956 : 0 : table_type = get_mlx5dr_table_type(flow_attr, table_cfg->attr.specialize, unified_fdb);
14957 : 0 : hws_flags = mlx5_hw_act_flag[MLX5_HW_ACTION_FLAG_NONE_ROOT][table_type];
14958 : 0 : clones_num = mlx5_hw_mirror_actions_list_validate(dev, flow_attr,
14959 : : actions);
14960 [ # # ]: 0 : if (clones_num < 0) {
14961 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
14962 : : actions, "Invalid mirror list format");
14963 : 0 : return NULL;
14964 : : }
14965 : 0 : mirror = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mirror),
14966 : : 0, SOCKET_ID_ANY);
14967 [ # # ]: 0 : if (!mirror) {
14968 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ACTION,
14969 : : actions, "Failed to allocate mirror context");
14970 : 0 : return NULL;
14971 : : }
14972 : :
14973 : 0 : mirror->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR;
14974 : 0 : mirror->clones_num = clones_num;
14975 [ # # ]: 0 : for (i = 0; i < clones_num; i++) {
14976 : : const struct rte_flow_action *clone_actions;
14977 : :
14978 : 0 : mirror_attr[i].action_type = array_action_types[i];
14979 [ # # ]: 0 : if (actions[i].type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
14980 : 0 : const struct rte_flow_action_sample *sample = actions[i].conf;
14981 : :
14982 : 0 : clone_actions = sample->actions;
14983 : : } else {
14984 : : clone_actions = &actions[i];
14985 : : }
14986 : 0 : ret = hw_mirror_format_clone(dev, &mirror->clone[i], table_cfg,
14987 : : clone_actions, &mirror_attr[i],
14988 : 0 : reformat_buf[i], table_type, error);
14989 : :
14990 [ # # ]: 0 : if (ret)
14991 : 0 : goto error;
14992 : : }
14993 : 0 : hws_flags |= MLX5DR_ACTION_FLAG_SHARED;
14994 : 0 : mirror->mirror_action = mlx5dr_action_create_dest_array(priv->dr_ctx,
14995 : : clones_num,
14996 : : mirror_attr,
14997 : : hws_flags);
14998 [ # # ]: 0 : if (!mirror->mirror_action) {
14999 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15000 : : actions, "Failed to create HWS mirror action");
15001 : 0 : goto error;
15002 : : }
15003 : : return mirror;
15004 : 0 : error:
15005 : 0 : mlx5_hw_mirror_destroy(dev, mirror);
15006 : 0 : return NULL;
15007 : : }
15008 : :
15009 : : static struct rte_flow_action_list_handle *
15010 : 0 : mlx5_hw_mirror_handle_create(struct rte_eth_dev *dev,
15011 : : const struct mlx5_flow_template_table_cfg *table_cfg,
15012 : : const struct rte_flow_action *actions,
15013 : : struct rte_flow_error *error)
15014 : : {
15015 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15016 : 0 : struct mlx5_mirror *mirror = mlx5_hw_create_mirror(dev, table_cfg, actions, error);
15017 : :
15018 [ # # ]: 0 : if (mirror)
15019 [ # # ]: 0 : mlx5_indirect_list_add_entry(&priv->indirect_list_head, &mirror->indirect);
15020 : 0 : return (struct rte_flow_action_list_handle *)mirror;
15021 : : }
15022 : :
15023 : : void
15024 : 0 : mlx5_destroy_legacy_indirect(__rte_unused struct rte_eth_dev *dev,
15025 : : struct mlx5_indirect_list *ptr)
15026 : : {
15027 : : struct mlx5_indlst_legacy *obj = (typeof(obj))ptr;
15028 : :
15029 : : switch (obj->legacy_type) {
15030 : : case RTE_FLOW_ACTION_TYPE_METER_MARK:
15031 : : break; /* ASO meters were released in mlx5_flow_meter_flush() */
15032 : : default:
15033 : : break;
15034 : : }
15035 : 0 : mlx5_free(obj);
15036 : 0 : }
15037 : :
15038 : : static struct rte_flow_action_list_handle *
15039 : 0 : mlx5_create_legacy_indlst(struct rte_eth_dev *dev, uint32_t queue,
15040 : : const struct rte_flow_op_attr *attr,
15041 : : const struct rte_flow_indir_action_conf *conf,
15042 : : const struct rte_flow_action *actions,
15043 : : void *user_data, struct rte_flow_error *error)
15044 : : {
15045 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15046 : 0 : struct mlx5_indlst_legacy *indlst_obj = mlx5_malloc(MLX5_MEM_ZERO,
15047 : : sizeof(*indlst_obj),
15048 : : 0, SOCKET_ID_ANY);
15049 : :
15050 [ # # ]: 0 : if (!indlst_obj)
15051 : : return NULL;
15052 : 0 : indlst_obj->handle = flow_hw_action_handle_create(dev, queue, attr, conf,
15053 : : actions, user_data,
15054 : : error);
15055 [ # # ]: 0 : if (!indlst_obj->handle) {
15056 : 0 : mlx5_free(indlst_obj);
15057 : 0 : return NULL;
15058 : : }
15059 : 0 : indlst_obj->legacy_type = actions[0].type;
15060 : 0 : indlst_obj->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY;
15061 [ # # ]: 0 : mlx5_indirect_list_add_entry(&priv->indirect_list_head, &indlst_obj->indirect);
15062 : 0 : return (struct rte_flow_action_list_handle *)indlst_obj;
15063 : : }
15064 : :
15065 : : static __rte_always_inline enum mlx5_indirect_list_type
15066 : : flow_hw_inlist_type_get(const struct rte_flow_action *actions)
15067 : : {
15068 [ # # # # ]: 0 : switch (actions[0].type) {
15069 : : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15070 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR;
15071 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
15072 : 0 : return actions[1].type == RTE_FLOW_ACTION_TYPE_END ?
15073 : 0 : MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY :
15074 : : MLX5_INDIRECT_ACTION_LIST_TYPE_ERR;
15075 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15076 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15077 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT;
15078 : : default:
15079 : : break;
15080 : : }
15081 : : return MLX5_INDIRECT_ACTION_LIST_TYPE_ERR;
15082 : : }
15083 : :
15084 : : static struct rte_flow_action_list_handle*
15085 : 0 : mlx5_hw_decap_encap_handle_create(struct rte_eth_dev *dev,
15086 : : const struct mlx5_flow_template_table_cfg *table_cfg,
15087 : : const struct rte_flow_action *actions,
15088 : : struct rte_flow_error *error)
15089 : : {
15090 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15091 : : const struct rte_flow_attr *flow_attr = &table_cfg->attr.flow_attr;
15092 : : const struct rte_flow_action *encap = NULL;
15093 : : const struct rte_flow_action *decap = NULL;
15094 : 0 : struct rte_flow_indir_action_conf indirect_conf = {
15095 : 0 : .ingress = flow_attr->ingress,
15096 : 0 : .egress = flow_attr->egress,
15097 : 0 : .transfer = flow_attr->transfer,
15098 : : };
15099 : : struct mlx5_hw_encap_decap_action *handle;
15100 : : uint64_t action_flags = 0;
15101 : :
15102 : : /*
15103 : : * Allow
15104 : : * 1. raw_decap / raw_encap / end
15105 : : * 2. raw_encap / end
15106 : : * 3. raw_decap / end
15107 : : */
15108 [ # # ]: 0 : while (actions->type != RTE_FLOW_ACTION_TYPE_END) {
15109 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP) {
15110 [ # # ]: 0 : if (action_flags) {
15111 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15112 : : actions, "Invalid indirect action list sequence");
15113 : 0 : return NULL;
15114 : : }
15115 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15116 : : decap = actions;
15117 [ # # ]: 0 : } else if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15118 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP) {
15119 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15120 : : actions, "Invalid indirect action list sequence");
15121 : 0 : return NULL;
15122 : : }
15123 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15124 : : encap = actions;
15125 : : } else {
15126 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15127 : : actions, "Invalid indirect action type in list");
15128 : 0 : return NULL;
15129 : : }
15130 : 0 : actions++;
15131 : : }
15132 [ # # ]: 0 : if (!decap && !encap) {
15133 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15134 : : actions, "Invalid indirect action combinations");
15135 : 0 : return NULL;
15136 : : }
15137 : 0 : handle = mlx5_reformat_action_create(dev, &indirect_conf, encap, decap, error);
15138 [ # # ]: 0 : if (!handle) {
15139 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15140 : : actions, "Failed to create HWS decap_encap action");
15141 : 0 : return NULL;
15142 : : }
15143 : 0 : handle->indirect.type = MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT;
15144 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->indirect_list_head, &handle->indirect, entry);
15145 : 0 : return (struct rte_flow_action_list_handle *)handle;
15146 : : }
15147 : :
15148 : : static struct rte_flow_action_list_handle *
15149 [ # # ]: 0 : flow_hw_async_action_list_handle_create(struct rte_eth_dev *dev, uint32_t queue,
15150 : : const struct rte_flow_op_attr *attr,
15151 : : const struct rte_flow_indir_action_conf *conf,
15152 : : const struct rte_flow_action *actions,
15153 : : void *user_data,
15154 : : struct rte_flow_error *error)
15155 : : {
15156 : : struct mlx5_hw_q_job *job = NULL;
15157 : : bool push = flow_hw_action_push(attr);
15158 : : enum mlx5_indirect_list_type list_type;
15159 : : struct rte_flow_action_list_handle *handle;
15160 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15161 : 0 : struct mlx5_flow_template_table_cfg table_cfg = {
15162 : : .external = true,
15163 : : .attr = {
15164 : : .flow_attr = {
15165 : 0 : .ingress = conf->ingress,
15166 : 0 : .egress = conf->egress,
15167 : 0 : .transfer = conf->transfer
15168 : : }
15169 : : }
15170 : : };
15171 : :
15172 [ # # ]: 0 : if (!mlx5_hw_ctx_validate(dev, error))
15173 : : return NULL;
15174 [ # # ]: 0 : if (!actions) {
15175 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15176 : : NULL, "No action list");
15177 : 0 : return NULL;
15178 : : }
15179 : : list_type = flow_hw_inlist_type_get(actions);
15180 [ # # ]: 0 : if (list_type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
15181 : : /*
15182 : : * Legacy indirect actions already have
15183 : : * async resources management. No need to do it twice.
15184 : : */
15185 : 0 : handle = mlx5_create_legacy_indlst(dev, queue, attr, conf,
15186 : : actions, user_data, error);
15187 : 0 : goto end;
15188 : : }
15189 [ # # ]: 0 : if (attr) {
15190 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
15191 : : NULL, MLX5_HW_Q_JOB_TYPE_CREATE,
15192 : : MLX5_HW_INDIRECT_TYPE_LIST, error);
15193 : : if (!job)
15194 : 0 : return NULL;
15195 : : }
15196 [ # # # ]: 0 : switch (list_type) {
15197 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
15198 : : /*
15199 : : * Mirror action is only supported in HWS group. Setting group to
15200 : : * non-zero will ensure that the action resources are allocated correctly.
15201 : : */
15202 : 0 : table_cfg.attr.flow_attr.group = 1;
15203 : 0 : handle = mlx5_hw_mirror_handle_create(dev, &table_cfg,
15204 : : actions, error);
15205 : 0 : break;
15206 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
15207 : 0 : handle = mlx5_hw_decap_encap_handle_create(dev, &table_cfg,
15208 : : actions, error);
15209 : 0 : break;
15210 : 0 : default:
15211 : : handle = NULL;
15212 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
15213 : : actions, "Invalid list");
15214 : : }
15215 [ # # ]: 0 : if (job) {
15216 : 0 : job->action = handle;
15217 [ # # ]: 0 : flow_hw_action_finalize(dev, queue, job, push, false,
15218 : : handle != NULL);
15219 : : }
15220 : 0 : end:
15221 : : return handle;
15222 : : }
15223 : :
15224 : : static struct rte_flow_action_list_handle *
15225 : 0 : flow_hw_action_list_handle_create(struct rte_eth_dev *dev,
15226 : : const struct rte_flow_indir_action_conf *conf,
15227 : : const struct rte_flow_action *actions,
15228 : : struct rte_flow_error *error)
15229 : : {
15230 : 0 : return flow_hw_async_action_list_handle_create(dev, MLX5_HW_INV_QUEUE,
15231 : : NULL, conf, actions,
15232 : : NULL, error);
15233 : : }
15234 : :
15235 : : static int
15236 [ # # ]: 0 : flow_hw_async_action_list_handle_destroy
15237 : : (struct rte_eth_dev *dev, uint32_t queue,
15238 : : const struct rte_flow_op_attr *attr,
15239 : : struct rte_flow_action_list_handle *handle,
15240 : : void *user_data, struct rte_flow_error *error)
15241 : : {
15242 : : int ret = 0;
15243 : : struct mlx5_hw_q_job *job = NULL;
15244 : : bool push = flow_hw_action_push(attr);
15245 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
15246 : : enum mlx5_indirect_list_type type =
15247 : : mlx5_get_indirect_list_type((void *)handle);
15248 : :
15249 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
15250 : : struct mlx5_indlst_legacy *legacy = (typeof(legacy))handle;
15251 : :
15252 : 0 : ret = flow_hw_action_handle_destroy(dev, queue, attr,
15253 : : legacy->handle,
15254 : : user_data, error);
15255 : : mlx5_indirect_list_remove_entry(&legacy->indirect);
15256 : 0 : mlx5_free(legacy);
15257 : 0 : goto end;
15258 : : }
15259 [ # # ]: 0 : if (attr) {
15260 : : job = flow_hw_action_job_init(priv, queue, NULL, user_data,
15261 : : NULL, MLX5_HW_Q_JOB_TYPE_DESTROY,
15262 : : MLX5_HW_INDIRECT_TYPE_LIST, error);
15263 : : if (!job)
15264 : 0 : return rte_errno;
15265 : : }
15266 [ # # # ]: 0 : switch (type) {
15267 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
15268 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)handle);
15269 : 0 : break;
15270 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
15271 [ # # ]: 0 : LIST_REMOVE(&((struct mlx5_hw_encap_decap_action *)handle)->indirect,
15272 : : entry);
15273 : 0 : mlx5_reformat_action_destroy(dev, handle, error);
15274 : 0 : break;
15275 : 0 : default:
15276 : 0 : ret = rte_flow_error_set(error, EINVAL,
15277 : : RTE_FLOW_ERROR_TYPE_ACTION,
15278 : : NULL, "Invalid indirect list handle");
15279 : : }
15280 [ # # ]: 0 : if (job) {
15281 : : flow_hw_action_finalize(dev, queue, job, push, false, true);
15282 : : }
15283 : 0 : end:
15284 : : return ret;
15285 : : }
15286 : :
15287 : : static int
15288 : 0 : flow_hw_action_list_handle_destroy(struct rte_eth_dev *dev,
15289 : : struct rte_flow_action_list_handle *handle,
15290 : : struct rte_flow_error *error)
15291 : : {
15292 : 0 : return flow_hw_async_action_list_handle_destroy(dev, MLX5_HW_INV_QUEUE,
15293 : : NULL, handle, NULL,
15294 : : error);
15295 : : }
15296 : :
15297 : : static int
15298 [ # # ]: 0 : flow_hw_async_action_list_handle_query_update
15299 : : (struct rte_eth_dev *dev, uint32_t queue_id,
15300 : : const struct rte_flow_op_attr *attr,
15301 : : const struct rte_flow_action_list_handle *handle,
15302 : : const void **update, void **query,
15303 : : enum rte_flow_query_update_mode mode,
15304 : : void *user_data, struct rte_flow_error *error)
15305 : : {
15306 : : enum mlx5_indirect_list_type type =
15307 : : mlx5_get_indirect_list_type((const void *)handle);
15308 : :
15309 [ # # ]: 0 : if (type == MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY) {
15310 : : struct mlx5_indlst_legacy *legacy = (void *)(uintptr_t)handle;
15311 : :
15312 [ # # ]: 0 : if (update && query)
15313 : 0 : return flow_hw_async_action_handle_query_update
15314 : : (dev, queue_id, attr, legacy->handle,
15315 : : update, query, mode, user_data, error);
15316 [ # # # # ]: 0 : else if (update && update[0])
15317 : 0 : return flow_hw_action_handle_update(dev, queue_id, attr,
15318 : : legacy->handle, update[0],
15319 : : user_data, error);
15320 [ # # # # ]: 0 : else if (query && query[0])
15321 : 0 : return flow_hw_action_handle_query(dev, queue_id, attr,
15322 : 0 : legacy->handle, query[0],
15323 : : user_data, error);
15324 : : else
15325 : 0 : return rte_flow_error_set(error, EINVAL,
15326 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15327 : : NULL, "invalid legacy handle query_update parameters");
15328 : : }
15329 : : return -ENOTSUP;
15330 : : }
15331 : :
15332 : : static int
15333 : 0 : flow_hw_action_list_handle_query_update(struct rte_eth_dev *dev,
15334 : : const struct rte_flow_action_list_handle *handle,
15335 : : const void **update, void **query,
15336 : : enum rte_flow_query_update_mode mode,
15337 : : struct rte_flow_error *error)
15338 : : {
15339 : 0 : return flow_hw_async_action_list_handle_query_update
15340 : : (dev, MLX5_HW_INV_QUEUE, NULL, handle,
15341 : : update, query, mode, NULL, error);
15342 : : }
15343 : :
15344 : : static int
15345 : 0 : flow_hw_calc_table_hash(struct rte_eth_dev *dev,
15346 : : const struct rte_flow_template_table *table,
15347 : : const struct rte_flow_item pattern[],
15348 : : uint8_t pattern_template_index,
15349 : : uint32_t *hash, struct rte_flow_error *error)
15350 : : {
15351 : : const struct rte_flow_item *items;
15352 : : struct mlx5_flow_hw_pattern_params pp;
15353 : : int res;
15354 : :
15355 : 0 : items = flow_hw_get_rule_items(dev, table, pattern,
15356 : : pattern_template_index,
15357 : : &pp);
15358 : 0 : res = mlx5dr_rule_hash_calculate(mlx5_table_matcher(table), items,
15359 : : pattern_template_index,
15360 : : MLX5DR_RULE_HASH_CALC_MODE_RAW,
15361 : : hash);
15362 [ # # ]: 0 : if (res)
15363 : 0 : return rte_flow_error_set(error, res,
15364 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15365 : : NULL,
15366 : : "hash could not be calculated");
15367 : : return 0;
15368 : : }
15369 : :
15370 : : static int
15371 : 0 : flow_hw_calc_encap_hash(struct rte_eth_dev *dev,
15372 : : const struct rte_flow_item pattern[],
15373 : : enum rte_flow_encap_hash_field dest_field,
15374 : : uint8_t *hash,
15375 : : struct rte_flow_error *error)
15376 : : {
15377 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15378 : : struct mlx5dr_crc_encap_entropy_hash_fields data;
15379 : 0 : enum mlx5dr_crc_encap_entropy_hash_size res_size =
15380 : : dest_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ?
15381 : 0 : MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16 :
15382 : : MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8;
15383 : : int res;
15384 : :
15385 : : memset(&data, 0, sizeof(struct mlx5dr_crc_encap_entropy_hash_fields));
15386 : :
15387 [ # # ]: 0 : for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
15388 [ # # # # : 0 : switch (pattern->type) {
# # # # ]
15389 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
15390 : 0 : data.dst.ipv4_addr =
15391 : 0 : ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.dst_addr;
15392 : 0 : data.src.ipv4_addr =
15393 : 0 : ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.src_addr;
15394 : 0 : data.next_protocol = ((const struct rte_flow_item_ipv4 *)
15395 : 0 : (pattern->spec))->hdr.next_proto_id;
15396 : 0 : break;
15397 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
15398 : : memcpy(data.dst.ipv6_addr,
15399 : 0 : &((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.dst_addr,
15400 : : sizeof(data.dst.ipv6_addr));
15401 : : memcpy(data.src.ipv6_addr,
15402 : : &((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.src_addr,
15403 : : sizeof(data.src.ipv6_addr));
15404 : 0 : data.next_protocol = ((const struct rte_flow_item_ipv6 *)
15405 : 0 : (pattern->spec))->hdr.proto;
15406 : 0 : break;
15407 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
15408 : 0 : data.next_protocol = IPPROTO_UDP;
15409 : 0 : data.dst_port =
15410 : 0 : ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.dst_port;
15411 : 0 : data.src_port =
15412 : 0 : ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.src_port;
15413 : 0 : break;
15414 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
15415 : 0 : data.next_protocol = IPPROTO_TCP;
15416 : 0 : data.dst_port =
15417 : 0 : ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.dst_port;
15418 : 0 : data.src_port =
15419 : 0 : ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.src_port;
15420 : 0 : break;
15421 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
15422 : 0 : data.next_protocol = IPPROTO_ICMP;
15423 : 0 : break;
15424 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
15425 : 0 : data.next_protocol = IPPROTO_ICMPV6;
15426 : 0 : break;
15427 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
15428 : 0 : data.next_protocol = IPPROTO_GRE;
15429 : 0 : break;
15430 : : default:
15431 : : break;
15432 : : }
15433 : : }
15434 : 0 : res = mlx5dr_crc_encap_entropy_hash_calc(priv->dr_ctx, &data, hash, res_size);
15435 [ # # ]: 0 : if (res)
15436 : 0 : return rte_flow_error_set(error, res,
15437 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15438 : : NULL, "error while calculating encap hash");
15439 : : return 0;
15440 : : }
15441 : :
15442 : : static int
15443 : 0 : flow_hw_table_resize_multi_pattern_actions(struct rte_eth_dev *dev,
15444 : : struct rte_flow_template_table *table,
15445 : : uint32_t nb_flows,
15446 : : struct rte_flow_error *error)
15447 : : {
15448 : 0 : struct mlx5_multi_pattern_segment *segment = table->mpctx.segments;
15449 : : uint32_t bulk_size;
15450 : : int i, ret;
15451 : :
15452 : : /**
15453 : : * Segment always allocates Modify Header Argument Objects number in
15454 : : * powers of 2.
15455 : : * On resize, PMD adds minimal required argument objects number.
15456 : : * For example, if table size was 10, it allocated 16 argument objects.
15457 : : * Resize to 15 will not add new objects.
15458 : : */
15459 : 0 : for (i = 1;
15460 [ # # # # ]: 0 : i < MLX5_MAX_TABLE_RESIZE_NUM && segment->capacity;
15461 : 0 : i++, segment++) {
15462 : : /* keep the devtools/checkpatches.sh happy */
15463 : : }
15464 [ # # ]: 0 : if (i == MLX5_MAX_TABLE_RESIZE_NUM)
15465 : 0 : return rte_flow_error_set(error, EINVAL,
15466 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15467 : : table, "too many resizes");
15468 [ # # ]: 0 : if (segment->head_index - 1 >= nb_flows)
15469 : : return 0;
15470 [ # # ]: 0 : bulk_size = rte_align32pow2(nb_flows - segment->head_index + 1);
15471 : 0 : ret = mlx5_tbl_multi_pattern_process(dev, table, segment,
15472 : : rte_log2_u32(bulk_size),
15473 : : error);
15474 [ # # ]: 0 : if (ret)
15475 : 0 : return rte_flow_error_set(error, EINVAL,
15476 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15477 : : table, "too many resizes");
15478 : : return i;
15479 : : }
15480 : :
15481 : : static int
15482 : 0 : flow_hw_table_resize(struct rte_eth_dev *dev,
15483 : : struct rte_flow_template_table *table,
15484 : : uint32_t nb_flows,
15485 : : struct rte_flow_error *error)
15486 : : {
15487 : : struct mlx5dr_action_template *at[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
15488 : : struct mlx5dr_match_template *mt[MLX5_HW_TBL_MAX_ITEM_TEMPLATE];
15489 : 0 : struct mlx5dr_matcher_attr matcher_attr = table->matcher_attr;
15490 : 0 : struct mlx5dr_action_jump_to_matcher_attr jump_attr = {
15491 : : .type = MLX5DR_ACTION_JUMP_TO_MATCHER_BY_INDEX,
15492 : : .matcher = NULL,
15493 : : };
15494 : : struct mlx5_multi_pattern_segment *segment = NULL;
15495 : : struct mlx5dr_matcher *matcher = NULL;
15496 : : struct mlx5dr_action *jump = NULL;
15497 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15498 : 0 : uint32_t i, selector = table->matcher_selector;
15499 : 0 : uint32_t other_selector = (selector + 1) & 1;
15500 : : int ret;
15501 : :
15502 [ # # ]: 0 : if (!rte_flow_template_table_resizable(dev->data->port_id, &table->cfg.attr))
15503 : 0 : return rte_flow_error_set(error, EINVAL,
15504 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15505 : : table, "no resizable attribute");
15506 [ # # ]: 0 : if (table->matcher_info[other_selector].matcher)
15507 : 0 : return rte_flow_error_set(error, EINVAL,
15508 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15509 : : table, "last table resize was not completed");
15510 [ # # ]: 0 : if (nb_flows <= table->cfg.attr.nb_flows)
15511 : 0 : return rte_flow_error_set(error, EINVAL,
15512 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15513 : : table, "shrinking table is not supported");
15514 : 0 : ret = mlx5_ipool_resize(table->flow_pool, nb_flows, error);
15515 [ # # ]: 0 : if (ret)
15516 : : return ret;
15517 : : /*
15518 : : * A resizable matcher doesn't support rule update. In this case, the ipool
15519 : : * for the resource is not created and there is no need to resize it.
15520 : : */
15521 : : MLX5_ASSERT(!table->resource);
15522 [ # # ]: 0 : if (mlx5_is_multi_pattern_active(&table->mpctx)) {
15523 : 0 : ret = flow_hw_table_resize_multi_pattern_actions(dev, table, nb_flows, error);
15524 [ # # ]: 0 : if (ret < 0)
15525 : : return ret;
15526 [ # # ]: 0 : if (ret > 0)
15527 : 0 : segment = table->mpctx.segments + ret;
15528 : : }
15529 [ # # ]: 0 : for (i = 0; i < table->nb_item_templates; i++)
15530 : 0 : mt[i] = table->its[i]->mt;
15531 [ # # ]: 0 : for (i = 0; i < table->nb_action_templates; i++)
15532 : 0 : at[i] = table->ats[i].action_template->tmpl;
15533 : : nb_flows = rte_align32pow2(nb_flows);
15534 : 0 : matcher_attr.rule.num_log = rte_log2_u32(nb_flows);
15535 : 0 : matcher = mlx5dr_matcher_create(table->grp->tbl, mt,
15536 : : table->nb_item_templates, at,
15537 : : table->nb_action_templates,
15538 : : &matcher_attr);
15539 [ # # ]: 0 : if (!matcher) {
15540 : 0 : ret = rte_flow_error_set(error, rte_errno,
15541 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15542 : : table, "failed to create new matcher");
15543 : 0 : goto error;
15544 : : }
15545 [ # # ]: 0 : if (matcher_attr.isolated) {
15546 : 0 : jump_attr.matcher = matcher;
15547 : 0 : jump = mlx5dr_action_create_jump_to_matcher(priv->dr_ctx, &jump_attr,
15548 : 0 : mlx5_hw_act_flag[!!table->cfg.attr.flow_attr.group][table->type]);
15549 [ # # ]: 0 : if (!jump) {
15550 : 0 : ret = rte_flow_error_set(error, rte_errno,
15551 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15552 : : table, "failed to create jump to matcher action");
15553 : 0 : goto error;
15554 : : }
15555 : : }
15556 : 0 : rte_rwlock_write_lock(&table->matcher_replace_rwlk);
15557 : 0 : ret = mlx5dr_matcher_resize_set_target
15558 : : (table->matcher_info[selector].matcher, matcher);
15559 [ # # ]: 0 : if (ret) {
15560 : : rte_rwlock_write_unlock(&table->matcher_replace_rwlk);
15561 : 0 : ret = rte_flow_error_set(error, rte_errno,
15562 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15563 : : table, "failed to initiate matcher swap");
15564 : 0 : goto error;
15565 : : }
15566 : 0 : table->cfg.attr.nb_flows = nb_flows;
15567 : 0 : table->matcher_info[other_selector].matcher = matcher;
15568 : 0 : table->matcher_info[other_selector].jump = jump;
15569 : 0 : table->matcher_selector = other_selector;
15570 : 0 : rte_atomic_store_explicit(&table->matcher_info[other_selector].refcnt,
15571 : : 0, rte_memory_order_relaxed);
15572 : : rte_rwlock_write_unlock(&table->matcher_replace_rwlk);
15573 : 0 : return 0;
15574 : 0 : error:
15575 [ # # ]: 0 : if (segment)
15576 : 0 : mlx5_destroy_multi_pattern_segment(segment);
15577 [ # # ]: 0 : if (jump)
15578 : 0 : mlx5dr_action_destroy(jump);
15579 [ # # ]: 0 : if (matcher) {
15580 : 0 : ret = mlx5dr_matcher_destroy(matcher);
15581 : 0 : return rte_flow_error_set(error, rte_errno,
15582 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15583 : : table, "failed to destroy new matcher");
15584 : : }
15585 : : return ret;
15586 : : }
15587 : :
15588 : : static int
15589 : 0 : flow_hw_table_resize_complete(struct rte_eth_dev *dev,
15590 : : struct rte_flow_template_table *table,
15591 : : struct rte_flow_error *error)
15592 : : {
15593 : : int ret;
15594 : 0 : uint32_t selector = table->matcher_selector;
15595 : 0 : uint32_t other_selector = (selector + 1) & 1;
15596 : : struct mlx5_matcher_info *matcher_info = &table->matcher_info[other_selector];
15597 : : uint32_t matcher_refcnt;
15598 : :
15599 [ # # ]: 0 : if (!rte_flow_template_table_resizable(dev->data->port_id, &table->cfg.attr))
15600 : 0 : return rte_flow_error_set(error, EINVAL,
15601 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15602 : : table, "no resizable attribute");
15603 [ # # ]: 0 : if (matcher_info->matcher == NULL)
15604 : 0 : return rte_flow_error_set(error, EINVAL,
15605 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15606 : : table, "table resize was not started");
15607 : 0 : matcher_refcnt = rte_atomic_load_explicit(&matcher_info->refcnt,
15608 : : rte_memory_order_relaxed);
15609 [ # # ]: 0 : if (matcher_refcnt > 0)
15610 : 0 : return rte_flow_error_set(error, EBUSY,
15611 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15612 : : table, "all rules not yet updated");
15613 [ # # ]: 0 : if (matcher_info->jump)
15614 : 0 : mlx5dr_action_destroy(matcher_info->jump);
15615 : 0 : ret = mlx5dr_matcher_destroy(matcher_info->matcher);
15616 [ # # ]: 0 : if (ret)
15617 : 0 : return rte_flow_error_set(error, rte_errno,
15618 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15619 : : table, "failed to destroy retired matcher");
15620 : 0 : matcher_info->matcher = NULL;
15621 : 0 : return 0;
15622 : : }
15623 : :
15624 : : static int
15625 : 0 : flow_hw_update_resized(struct rte_eth_dev *dev, uint32_t queue,
15626 : : const struct rte_flow_op_attr *attr,
15627 : : struct rte_flow *flow, void *user_data,
15628 : : struct rte_flow_error *error)
15629 : : {
15630 : : int ret;
15631 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15632 : : struct rte_flow_hw *hw_flow = (struct rte_flow_hw *)flow;
15633 : 0 : struct rte_flow_template_table *table = hw_flow->table;
15634 [ # # ]: 0 : struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, hw_flow);
15635 : 0 : uint32_t table_selector = table->matcher_selector;
15636 : 0 : uint32_t rule_selector = aux->matcher_selector;
15637 : : uint32_t other_selector;
15638 : : struct mlx5dr_matcher *other_matcher;
15639 : 0 : struct mlx5dr_rule_attr rule_attr = {
15640 : : .queue_id = queue,
15641 : 0 : .burst = attr->postpone,
15642 : : };
15643 : :
15644 : : MLX5_ASSERT(hw_flow->flags & MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR);
15645 : : /*
15646 : : * Update resized can be called only through async flow API.
15647 : : * These rings are allocated if and only if async flow API was configured.
15648 : : */
15649 : : MLX5_ASSERT(priv->hw_q[queue].flow_transfer_completed != NULL);
15650 : : MLX5_ASSERT(priv->hw_q[queue].flow_transfer_pending != NULL);
15651 : : /**
15652 : : * mlx5dr_matcher_resize_rule_move() accepts original table matcher -
15653 : : * the one that was used BEFORE table resize.
15654 : : * Since the function is called AFTER table resize,
15655 : : * `table->matcher_selector` always points to the new matcher and
15656 : : * `aux->matcher_selector` points to a matcher used to create the flow.
15657 : : */
15658 : : other_selector = rule_selector == table_selector ?
15659 [ # # ]: 0 : (rule_selector + 1) & 1 : rule_selector;
15660 : 0 : other_matcher = table->matcher_info[other_selector].matcher;
15661 [ # # ]: 0 : if (!other_matcher)
15662 : 0 : return rte_flow_error_set(error, EINVAL,
15663 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15664 : : "no active table resize");
15665 : 0 : hw_flow->operation_type = MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE;
15666 : 0 : hw_flow->user_data = user_data;
15667 : 0 : rule_attr.user_data = hw_flow;
15668 [ # # ]: 0 : if (rule_selector == table_selector) {
15669 : 0 : struct rte_ring *ring = !attr->postpone ?
15670 [ # # ]: 0 : priv->hw_q[queue].flow_transfer_completed :
15671 : 0 : priv->hw_q[queue].flow_transfer_pending;
15672 : 0 : rte_ring_enqueue(ring, hw_flow);
15673 : : flow_hw_q_inc_flow_ops(priv, queue);
15674 : 0 : return 0;
15675 : : }
15676 : 0 : ret = mlx5dr_matcher_resize_rule_move(other_matcher,
15677 : 0 : (struct mlx5dr_rule *)hw_flow->rule,
15678 : : &rule_attr);
15679 [ # # ]: 0 : if (ret) {
15680 : 0 : return rte_flow_error_set(error, rte_errno,
15681 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15682 : : "flow transfer failed");
15683 : : }
15684 : : flow_hw_q_inc_flow_ops(priv, queue);
15685 : 0 : return 0;
15686 : : }
15687 : :
15688 : : /**
15689 : : * Internal validation function. For validating both actions and items.
15690 : : *
15691 : : * @param[in] dev
15692 : : * Pointer to the rte_eth_dev structure.
15693 : : * @param[in] attr
15694 : : * Pointer to the flow attributes.
15695 : : * @param[in] items
15696 : : * Pointer to the list of items.
15697 : : * @param[in] actions
15698 : : * Pointer to the list of actions.
15699 : : * @param[in] external
15700 : : * This flow rule is created by request external to PMD.
15701 : : * @param[in] hairpin
15702 : : * Number of hairpin TX actions, 0 means classic flow.
15703 : : * @param[out] error
15704 : : * Pointer to the error structure.
15705 : : *
15706 : : * @return
15707 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15708 : : */
15709 : : static int
15710 : 0 : flow_hw_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
15711 : : const struct rte_flow_item items[],
15712 : : const struct rte_flow_action actions[] __rte_unused,
15713 : : bool external, int hairpin __rte_unused,
15714 : : struct rte_flow_error *error)
15715 : : {
15716 : 0 : const struct rte_flow_pattern_template_attr pattern_template_attr = {
15717 : : .relaxed_matching = 0,
15718 : 0 : .ingress = attr->ingress,
15719 : 0 : .egress = attr->egress,
15720 : 0 : .transfer = attr->transfer,
15721 : : };
15722 : 0 : uint64_t item_flags = 0;
15723 : : int ret = 0;
15724 : :
15725 [ # # ]: 0 : if (external) {
15726 : : /* Validate application items only */
15727 : 0 : ret = __flow_hw_pattern_validate(dev, &pattern_template_attr, items,
15728 : : &item_flags, true, error);
15729 [ # # ]: 0 : if (ret < 0)
15730 : 0 : return -rte_errno;
15731 : : }
15732 : : return 0;
15733 : : }
15734 : :
15735 : :
15736 : : const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = {
15737 : : .list_create = flow_hw_list_create,
15738 : : .list_destroy = mlx5_flow_hw_list_destroy,
15739 : : .validate = flow_hw_validate,
15740 : : .info_get = flow_hw_info_get,
15741 : : .configure = flow_hw_configure,
15742 : : .pattern_validate = flow_hw_pattern_validate,
15743 : : .pattern_template_create = flow_hw_external_pattern_template_create,
15744 : : .pattern_template_destroy = flow_hw_pattern_template_destroy,
15745 : : .actions_validate = flow_hw_actions_validate,
15746 : : .actions_template_create = flow_hw_actions_template_create,
15747 : : .actions_template_destroy = flow_hw_actions_template_destroy,
15748 : : .template_table_create = flow_hw_template_table_create,
15749 : : .template_table_destroy = flow_hw_table_destroy,
15750 : : .table_resize = flow_hw_table_resize,
15751 : : .group_set_miss_actions = mlx5_flow_hw_group_set_miss_actions,
15752 : : .async_flow_create = flow_hw_async_flow_create,
15753 : : .async_flow_create_by_index = flow_hw_async_flow_create_by_index,
15754 : : .async_flow_update = flow_hw_async_flow_update,
15755 : : .async_flow_destroy = flow_hw_async_flow_destroy,
15756 : : .flow_update_resized = flow_hw_update_resized,
15757 : : .table_resize_complete = flow_hw_table_resize_complete,
15758 : : .pull = flow_hw_pull,
15759 : : .push = flow_hw_push,
15760 : : .async_action_create = flow_hw_action_handle_create,
15761 : : .async_action_destroy = flow_hw_action_handle_destroy,
15762 : : .async_action_update = flow_hw_action_handle_update,
15763 : : .async_action_query_update = flow_hw_async_action_handle_query_update,
15764 : : .async_action_query = flow_hw_action_handle_query,
15765 : : .action_validate = flow_hw_action_validate,
15766 : : .action_create = flow_hw_action_create,
15767 : : .action_destroy = flow_hw_action_destroy,
15768 : : .action_update = flow_hw_action_update,
15769 : : .action_query = flow_hw_action_query,
15770 : : .action_query_update = flow_hw_action_query_update,
15771 : : .action_list_handle_create = flow_hw_action_list_handle_create,
15772 : : .action_list_handle_destroy = flow_hw_action_list_handle_destroy,
15773 : : .action_list_handle_query_update =
15774 : : flow_hw_action_list_handle_query_update,
15775 : : .async_action_list_handle_create =
15776 : : flow_hw_async_action_list_handle_create,
15777 : : .async_action_list_handle_destroy =
15778 : : flow_hw_async_action_list_handle_destroy,
15779 : : .async_action_list_handle_query_update =
15780 : : flow_hw_async_action_list_handle_query_update,
15781 : : .query = flow_hw_query,
15782 : : .get_aged_flows = flow_hw_get_aged_flows,
15783 : : .get_q_aged_flows = flow_hw_get_q_aged_flows,
15784 : : .item_create = mlx5_flow_dv_item_create,
15785 : : .item_release = mlx5_flow_dv_item_release,
15786 : : .flow_calc_table_hash = flow_hw_calc_table_hash,
15787 : : .flow_calc_encap_hash = flow_hw_calc_encap_hash,
15788 : : };
15789 : :
15790 : : /**
15791 : : * Creates a control flow using flow template API on @p proxy_dev device,
15792 : : * on behalf of @p owner_dev device.
15793 : : *
15794 : : * This function uses locks internally to synchronize access to the
15795 : : * flow queue.
15796 : : *
15797 : : * Created flow is stored in private list associated with @p proxy_dev device.
15798 : : *
15799 : : * @param owner_dev
15800 : : * Pointer to Ethernet device on behalf of which flow is created.
15801 : : * @param proxy_dev
15802 : : * Pointer to Ethernet device on which flow is created.
15803 : : * @param table
15804 : : * Pointer to flow table.
15805 : : * @param items
15806 : : * Pointer to flow rule items.
15807 : : * @param item_template_idx
15808 : : * Index of an item template associated with @p table.
15809 : : * @param actions
15810 : : * Pointer to flow rule actions.
15811 : : * @param action_template_idx
15812 : : * Index of an action template associated with @p table.
15813 : : * @param info
15814 : : * Additional info about control flow rule.
15815 : : * @param external
15816 : : * External ctrl flow.
15817 : : *
15818 : : * @return
15819 : : * 0 on success, negative errno value otherwise and rte_errno set.
15820 : : */
15821 : : static __rte_unused int
15822 : 0 : flow_hw_create_ctrl_flow(struct rte_eth_dev *owner_dev,
15823 : : struct rte_eth_dev *proxy_dev,
15824 : : struct rte_flow_template_table *table,
15825 : : struct rte_flow_item items[],
15826 : : uint8_t item_template_idx,
15827 : : struct rte_flow_action actions[],
15828 : : uint8_t action_template_idx,
15829 : : struct mlx5_ctrl_flow_info *info,
15830 : : bool external)
15831 : : {
15832 : 0 : struct mlx5_priv *priv = proxy_dev->data->dev_private;
15833 : 0 : uint32_t queue = CTRL_QUEUE_ID(priv);
15834 : 0 : struct rte_flow_op_attr op_attr = {
15835 : : .postpone = 0,
15836 : : };
15837 : : struct rte_flow *flow = NULL;
15838 : : struct mlx5_ctrl_flow_entry *entry = NULL;
15839 : : int ret;
15840 : :
15841 : 0 : rte_spinlock_lock(&priv->hw_ctrl_lock);
15842 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_SYS, sizeof(*entry),
15843 : : 0, SOCKET_ID_ANY);
15844 [ # # ]: 0 : if (!entry) {
15845 : 0 : DRV_LOG(ERR, "port %u not enough memory to create control flows",
15846 : : proxy_dev->data->port_id);
15847 : 0 : rte_errno = ENOMEM;
15848 : : ret = -rte_errno;
15849 : 0 : goto error;
15850 : : }
15851 : 0 : flow = flow_hw_async_flow_create(proxy_dev, queue, &op_attr, table,
15852 : : items, item_template_idx,
15853 : : actions, action_template_idx,
15854 : : NULL, NULL);
15855 [ # # ]: 0 : if (!flow) {
15856 : 0 : DRV_LOG(ERR, "port %u failed to enqueue create control"
15857 : : " flow operation", proxy_dev->data->port_id);
15858 : 0 : ret = -rte_errno;
15859 : 0 : goto error;
15860 : : }
15861 : 0 : ret = __flow_hw_pull_comp(proxy_dev, queue, NULL);
15862 [ # # ]: 0 : if (ret) {
15863 : 0 : DRV_LOG(ERR, "port %u failed to insert control flow",
15864 : : proxy_dev->data->port_id);
15865 : 0 : rte_errno = EINVAL;
15866 : : ret = -rte_errno;
15867 : 0 : goto error;
15868 : : }
15869 : 0 : entry->owner_dev = owner_dev;
15870 : 0 : entry->flow = flow;
15871 [ # # ]: 0 : if (info)
15872 : 0 : entry->info = *info;
15873 : : else
15874 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_GENERAL;
15875 [ # # ]: 0 : if (external)
15876 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ext_ctrl_flows, entry, next);
15877 : : else
15878 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
15879 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
15880 : 0 : return 0;
15881 : 0 : error:
15882 [ # # ]: 0 : if (entry)
15883 : 0 : mlx5_free(entry);
15884 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
15885 : 0 : return ret;
15886 : : }
15887 : :
15888 : : /**
15889 : : * Destroys a control flow @p flow using flow template API on @p dev device.
15890 : : *
15891 : : * This function uses locks internally to synchronize access to the
15892 : : * flow queue.
15893 : : *
15894 : : * If the @p flow is stored on any private list/pool, then caller must free up
15895 : : * the relevant resources.
15896 : : *
15897 : : * @param dev
15898 : : * Pointer to Ethernet device.
15899 : : * @param flow
15900 : : * Pointer to flow rule.
15901 : : *
15902 : : * @return
15903 : : * 0 on success, non-zero value otherwise.
15904 : : */
15905 : : static int
15906 : 0 : flow_hw_destroy_ctrl_flow(struct rte_eth_dev *dev, struct rte_flow *flow)
15907 : : {
15908 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15909 : 0 : uint32_t queue = CTRL_QUEUE_ID(priv);
15910 : 0 : struct rte_flow_op_attr op_attr = {
15911 : : .postpone = 0,
15912 : : };
15913 : : int ret;
15914 : :
15915 : 0 : rte_spinlock_lock(&priv->hw_ctrl_lock);
15916 : 0 : ret = flow_hw_async_flow_destroy(dev, queue, &op_attr, flow, NULL, NULL);
15917 [ # # ]: 0 : if (ret) {
15918 : 0 : DRV_LOG(ERR, "port %u failed to enqueue destroy control"
15919 : : " flow operation", dev->data->port_id);
15920 : 0 : goto exit;
15921 : : }
15922 : 0 : ret = __flow_hw_pull_comp(dev, queue, NULL);
15923 [ # # ]: 0 : if (ret) {
15924 : 0 : DRV_LOG(ERR, "port %u failed to destroy control flow",
15925 : : dev->data->port_id);
15926 : 0 : rte_errno = EINVAL;
15927 : : ret = -rte_errno;
15928 : 0 : goto exit;
15929 : : }
15930 : 0 : exit:
15931 : : rte_spinlock_unlock(&priv->hw_ctrl_lock);
15932 : 0 : return ret;
15933 : : }
15934 : :
15935 : : /**
15936 : : * Destroys control flows created on behalf of @p owner device on @p dev device.
15937 : : *
15938 : : * @param dev
15939 : : * Pointer to Ethernet device on which control flows were created.
15940 : : * @param owner
15941 : : * Pointer to Ethernet device owning control flows.
15942 : : *
15943 : : * @return
15944 : : * 0 on success, otherwise negative error code is returned and
15945 : : * rte_errno is set.
15946 : : */
15947 : : static int
15948 : 0 : flow_hw_flush_ctrl_flows_owned_by(struct rte_eth_dev *dev, struct rte_eth_dev *owner)
15949 : : {
15950 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15951 : : struct mlx5_ctrl_flow_entry *cf;
15952 : : struct mlx5_ctrl_flow_entry *cf_next;
15953 : : int ret;
15954 : :
15955 : 0 : cf = LIST_FIRST(&priv->hw_ctrl_flows);
15956 [ # # ]: 0 : while (cf != NULL) {
15957 : 0 : cf_next = LIST_NEXT(cf, next);
15958 [ # # ]: 0 : if (cf->owner_dev == owner) {
15959 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
15960 [ # # ]: 0 : if (ret) {
15961 : 0 : rte_errno = ret;
15962 : 0 : return -ret;
15963 : : }
15964 [ # # ]: 0 : LIST_REMOVE(cf, next);
15965 : 0 : mlx5_free(cf);
15966 : : }
15967 : : cf = cf_next;
15968 : : }
15969 : : return 0;
15970 : : }
15971 : :
15972 : : /**
15973 : : * Destroys control flows created for @p owner_dev device.
15974 : : *
15975 : : * @param owner_dev
15976 : : * Pointer to Ethernet device owning control flows.
15977 : : *
15978 : : * @return
15979 : : * 0 on success, otherwise negative error code is returned and
15980 : : * rte_errno is set.
15981 : : */
15982 : : int
15983 : 0 : mlx5_flow_hw_flush_ctrl_flows(struct rte_eth_dev *owner_dev)
15984 : : {
15985 : 0 : struct mlx5_priv *owner_priv = owner_dev->data->dev_private;
15986 : : struct rte_eth_dev *proxy_dev;
15987 : 0 : uint16_t owner_port_id = owner_dev->data->port_id;
15988 : 0 : uint16_t proxy_port_id = owner_dev->data->port_id;
15989 : : int ret;
15990 : :
15991 : : /* Flush all flows created by this port for itself. */
15992 : 0 : ret = flow_hw_flush_ctrl_flows_owned_by(owner_dev, owner_dev);
15993 [ # # ]: 0 : if (ret)
15994 : : return ret;
15995 : : /* Flush all flows created for this port on proxy port. */
15996 [ # # ]: 0 : if (owner_priv->sh->config.dv_esw_en) {
15997 : 0 : ret = rte_flow_pick_transfer_proxy(owner_port_id, &proxy_port_id, NULL);
15998 [ # # ]: 0 : if (ret == -ENODEV) {
15999 : 0 : DRV_LOG(DEBUG, "Unable to find transfer proxy port for port %u. It was "
16000 : : "probably closed. Control flows were cleared.",
16001 : : owner_port_id);
16002 : 0 : rte_errno = 0;
16003 : 0 : return 0;
16004 [ # # ]: 0 : } else if (ret) {
16005 : 0 : DRV_LOG(ERR, "Unable to find proxy port for port %u (ret = %d)",
16006 : : owner_port_id, ret);
16007 : 0 : return ret;
16008 : : }
16009 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16010 : : } else {
16011 : : proxy_dev = owner_dev;
16012 : : }
16013 : 0 : return flow_hw_flush_ctrl_flows_owned_by(proxy_dev, owner_dev);
16014 : : }
16015 : :
16016 : : /**
16017 : : * Destroys all control flows created on @p dev device.
16018 : : *
16019 : : * @param owner_dev
16020 : : * Pointer to Ethernet device.
16021 : : *
16022 : : * @return
16023 : : * 0 on success, otherwise negative error code is returned and
16024 : : * rte_errno is set.
16025 : : */
16026 : : static int
16027 : 0 : flow_hw_flush_all_ctrl_flows(struct rte_eth_dev *dev)
16028 : : {
16029 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16030 : : struct mlx5_ctrl_flow_entry *cf;
16031 : : struct mlx5_ctrl_flow_entry *cf_next;
16032 : : int ret;
16033 : :
16034 : 0 : cf = LIST_FIRST(&priv->hw_ctrl_flows);
16035 [ # # ]: 0 : while (cf != NULL) {
16036 : 0 : cf_next = LIST_NEXT(cf, next);
16037 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
16038 [ # # ]: 0 : if (ret) {
16039 : 0 : rte_errno = ret;
16040 : 0 : return -ret;
16041 : : }
16042 [ # # ]: 0 : LIST_REMOVE(cf, next);
16043 : 0 : mlx5_free(cf);
16044 : : cf = cf_next;
16045 : : }
16046 : 0 : cf = LIST_FIRST(&priv->hw_ext_ctrl_flows);
16047 [ # # ]: 0 : while (cf != NULL) {
16048 : 0 : cf_next = LIST_NEXT(cf, next);
16049 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, cf->flow);
16050 [ # # ]: 0 : if (ret) {
16051 : 0 : rte_errno = ret;
16052 : 0 : return -ret;
16053 : : }
16054 [ # # ]: 0 : LIST_REMOVE(cf, next);
16055 : 0 : mlx5_free(cf);
16056 : : cf = cf_next;
16057 : : }
16058 : : return 0;
16059 : : }
16060 : :
16061 : : int
16062 : 0 : mlx5_flow_hw_esw_create_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16063 : : {
16064 : 0 : uint16_t port_id = dev->data->port_id;
16065 : 0 : struct rte_flow_item_ethdev esw_mgr_spec = {
16066 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
16067 : : };
16068 : 0 : struct rte_flow_item_ethdev esw_mgr_mask = {
16069 : : .port_id = MLX5_REPRESENTED_PORT_ESW_MGR,
16070 : : };
16071 : 0 : struct rte_flow_item_tag reg_c0_spec = {
16072 : : .index = (uint8_t)REG_C_0,
16073 : : .data = flow_hw_esw_mgr_regc_marker(dev),
16074 : : };
16075 : 0 : struct rte_flow_item_tag reg_c0_mask = {
16076 : : .index = 0xff,
16077 : : .data = flow_hw_esw_mgr_regc_marker_mask(dev),
16078 : : };
16079 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
16080 : : .queue = sqn,
16081 : : };
16082 : 0 : struct rte_flow_action_ethdev port = {
16083 : : .port_id = port_id,
16084 : : };
16085 : 0 : struct rte_flow_item items[3] = { { 0 } };
16086 : 0 : struct rte_flow_action actions[3] = { { 0 } };
16087 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16088 : : .type = MLX5_CTRL_FLOW_TYPE_SQ_MISS_ROOT,
16089 : : .esw_mgr_sq = sqn,
16090 : : };
16091 : : struct rte_eth_dev *proxy_dev;
16092 : : struct mlx5_priv *proxy_priv;
16093 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16094 : : int ret;
16095 : :
16096 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16097 [ # # ]: 0 : if (ret) {
16098 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16099 : : "port must be present to create default SQ miss flows.",
16100 : : port_id);
16101 : 0 : return ret;
16102 : : }
16103 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16104 : 0 : proxy_priv = proxy_dev->data->dev_private;
16105 [ # # ]: 0 : if (!proxy_priv->dr_ctx) {
16106 : 0 : DRV_LOG(DEBUG, "Transfer proxy port (port %u) of port %u must be configured "
16107 : : "for HWS to create default SQ miss flows. Default flows will "
16108 : : "not be created.",
16109 : : proxy_port_id, port_id);
16110 : 0 : return 0;
16111 : : }
16112 [ # # ]: 0 : if (!proxy_priv->hw_ctrl_fdb ||
16113 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_root_tbl ||
16114 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_tbl) {
16115 : 0 : DRV_LOG(ERR, "Transfer proxy port (port %u) of port %u was configured, but "
16116 : : "default flow tables were not created.",
16117 : : proxy_port_id, port_id);
16118 : 0 : rte_errno = ENOMEM;
16119 : 0 : return -rte_errno;
16120 : : }
16121 : : /*
16122 : : * Create a root SQ miss flow rule - match E-Switch Manager and SQ,
16123 : : * and jump to group 1.
16124 : : */
16125 : 0 : items[0] = (struct rte_flow_item){
16126 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
16127 : : .spec = &esw_mgr_spec,
16128 : : .mask = &esw_mgr_mask,
16129 : : };
16130 : 0 : items[1] = (struct rte_flow_item){
16131 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16132 : : .spec = &sq_spec,
16133 : : };
16134 : 0 : items[2] = (struct rte_flow_item){
16135 : : .type = RTE_FLOW_ITEM_TYPE_END,
16136 : : };
16137 : 0 : actions[0] = (struct rte_flow_action){
16138 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
16139 : : };
16140 : 0 : actions[1] = (struct rte_flow_action){
16141 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
16142 : : };
16143 : 0 : actions[2] = (struct rte_flow_action) {
16144 : : .type = RTE_FLOW_ACTION_TYPE_END,
16145 : : };
16146 : 0 : ret = flow_hw_create_ctrl_flow(dev, proxy_dev,
16147 : : proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_root_tbl,
16148 : : items, 0, actions, 0, &flow_info, external);
16149 [ # # ]: 0 : if (ret) {
16150 : 0 : DRV_LOG(ERR, "Port %u failed to create root SQ miss flow rule for SQ %u, ret %d",
16151 : : port_id, sqn, ret);
16152 : 0 : return ret;
16153 : : }
16154 : : /*
16155 : : * Create a non-root SQ miss flow rule - match REG_C_0 marker and SQ,
16156 : : * and forward to port.
16157 : : */
16158 : 0 : items[0] = (struct rte_flow_item){
16159 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG,
16160 : : .spec = ®_c0_spec,
16161 : : .mask = ®_c0_mask,
16162 : : };
16163 : 0 : items[1] = (struct rte_flow_item){
16164 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16165 : : .spec = &sq_spec,
16166 : : };
16167 : 0 : items[2] = (struct rte_flow_item){
16168 : : .type = RTE_FLOW_ITEM_TYPE_END,
16169 : : };
16170 : 0 : actions[0] = (struct rte_flow_action){
16171 : : .type = RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
16172 : : .conf = &port,
16173 : : };
16174 : 0 : actions[1] = (struct rte_flow_action){
16175 : : .type = RTE_FLOW_ACTION_TYPE_END,
16176 : : };
16177 : 0 : flow_info.type = MLX5_CTRL_FLOW_TYPE_SQ_MISS;
16178 : 0 : ret = flow_hw_create_ctrl_flow(dev, proxy_dev,
16179 : 0 : proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_tbl,
16180 : : items, 0, actions, 0, &flow_info, external);
16181 [ # # ]: 0 : if (ret) {
16182 : 0 : DRV_LOG(ERR, "Port %u failed to create HWS SQ miss flow rule for SQ %u, ret %d",
16183 : : port_id, sqn, ret);
16184 : 0 : return ret;
16185 : : }
16186 : : return 0;
16187 : : }
16188 : :
16189 : : static bool
16190 : : flow_hw_is_matching_sq_miss_flow(struct mlx5_ctrl_flow_entry *cf,
16191 : : struct rte_eth_dev *dev,
16192 : : uint32_t sqn)
16193 : : {
16194 : 0 : if (cf->owner_dev != dev)
16195 : : return false;
16196 [ # # # # ]: 0 : if (cf->info.type == MLX5_CTRL_FLOW_TYPE_SQ_MISS_ROOT && cf->info.esw_mgr_sq == sqn)
16197 : : return true;
16198 [ # # # # ]: 0 : if (cf->info.type == MLX5_CTRL_FLOW_TYPE_SQ_MISS && cf->info.esw_mgr_sq == sqn)
16199 : : return true;
16200 : : return false;
16201 : : }
16202 : :
16203 : : int
16204 : 0 : mlx5_flow_hw_esw_destroy_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16205 : : {
16206 : 0 : uint16_t port_id = dev->data->port_id;
16207 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16208 : : struct rte_eth_dev *proxy_dev;
16209 : : struct mlx5_priv *proxy_priv;
16210 : : struct mlx5_ctrl_flow_entry *cf;
16211 : : struct mlx5_ctrl_flow_entry *cf_next;
16212 : : int ret;
16213 : :
16214 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16215 [ # # ]: 0 : if (ret) {
16216 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16217 : : "port must be present for default SQ miss flow rules to exist.",
16218 : : port_id);
16219 : 0 : return ret;
16220 : : }
16221 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16222 : 0 : proxy_priv = proxy_dev->data->dev_private;
16223 : : /* FDB default flow rules must be enabled. */
16224 : : MLX5_ASSERT(proxy_priv->sh->config.fdb_def_rule);
16225 [ # # ]: 0 : if (!proxy_priv->dr_ctx)
16226 : : return 0;
16227 [ # # ]: 0 : if (!proxy_priv->hw_ctrl_fdb ||
16228 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_root_tbl ||
16229 [ # # ]: 0 : !proxy_priv->hw_ctrl_fdb->hw_esw_sq_miss_tbl)
16230 : : return 0;
16231 [ # # ]: 0 : cf = external ? LIST_FIRST(&proxy_priv->hw_ext_ctrl_flows) :
16232 : : LIST_FIRST(&proxy_priv->hw_ctrl_flows);
16233 [ # # ]: 0 : while (cf != NULL) {
16234 [ # # ]: 0 : cf_next = LIST_NEXT(cf, next);
16235 : : if (flow_hw_is_matching_sq_miss_flow(cf, dev, sqn)) {
16236 : 0 : claim_zero(flow_hw_destroy_ctrl_flow(proxy_dev, cf->flow));
16237 [ # # ]: 0 : LIST_REMOVE(cf, next);
16238 : 0 : mlx5_free(cf);
16239 : : }
16240 : : cf = cf_next;
16241 : : }
16242 : : return 0;
16243 : : }
16244 : :
16245 : : int
16246 : 0 : mlx5_flow_hw_esw_create_default_jump_flow(struct rte_eth_dev *dev)
16247 : : {
16248 : 0 : uint16_t port_id = dev->data->port_id;
16249 : 0 : struct rte_flow_item_ethdev port_spec = {
16250 : : .port_id = port_id,
16251 : : };
16252 : 0 : struct rte_flow_item items[] = {
16253 : : {
16254 : : .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
16255 : : .spec = &port_spec,
16256 : : },
16257 : : {
16258 : : .type = RTE_FLOW_ITEM_TYPE_END,
16259 : : },
16260 : : };
16261 : 0 : struct rte_flow_action_jump jump = {
16262 : : .group = 1,
16263 : : };
16264 : 0 : struct rte_flow_action actions[] = {
16265 : : {
16266 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
16267 : : .conf = &jump,
16268 : : },
16269 : : {
16270 : : .type = RTE_FLOW_ACTION_TYPE_END,
16271 : : }
16272 : : };
16273 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16274 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_JUMP,
16275 : : };
16276 : : struct rte_eth_dev *proxy_dev;
16277 : : struct mlx5_priv *proxy_priv;
16278 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16279 : : int ret;
16280 : :
16281 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16282 [ # # ]: 0 : if (ret) {
16283 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16284 : : "port must be present to create default FDB jump rule.",
16285 : : port_id);
16286 : 0 : return ret;
16287 : : }
16288 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16289 : 0 : proxy_priv = proxy_dev->data->dev_private;
16290 : : /* FDB default flow rules must be enabled. */
16291 : : MLX5_ASSERT(proxy_priv->sh->config.fdb_def_rule);
16292 [ # # ]: 0 : if (!proxy_priv->dr_ctx) {
16293 : 0 : DRV_LOG(DEBUG, "Transfer proxy port (port %u) of port %u must be configured "
16294 : : "for HWS to create default FDB jump rule. Default rule will "
16295 : : "not be created.",
16296 : : proxy_port_id, port_id);
16297 : 0 : return 0;
16298 : : }
16299 [ # # # # ]: 0 : if (!proxy_priv->hw_ctrl_fdb || !proxy_priv->hw_ctrl_fdb->hw_esw_zero_tbl) {
16300 : 0 : DRV_LOG(ERR, "Transfer proxy port (port %u) of port %u was configured, but "
16301 : : "default flow tables were not created.",
16302 : : proxy_port_id, port_id);
16303 : 0 : rte_errno = EINVAL;
16304 : 0 : return -rte_errno;
16305 : : }
16306 : 0 : return flow_hw_create_ctrl_flow(dev, proxy_dev,
16307 : : proxy_priv->hw_ctrl_fdb->hw_esw_zero_tbl,
16308 : : items, 0, actions, 0, &flow_info, false);
16309 : : }
16310 : :
16311 : : int
16312 : 0 : mlx5_flow_hw_create_nic_tx_default_mreg_copy_flow(struct rte_eth_dev *dev, uint32_t sqn)
16313 : : {
16314 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16315 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
16316 : : .queue = sqn,
16317 : : };
16318 : 0 : struct rte_flow_item items[] = {
16319 : : {
16320 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16321 : : .spec = &sq_spec,
16322 : : },
16323 : : {
16324 : : .type = RTE_FLOW_ITEM_TYPE_END,
16325 : : },
16326 : : };
16327 : 0 : struct rte_flow_action_modify_field mreg_action = {
16328 : : .operation = RTE_FLOW_MODIFY_SET,
16329 : : .dst = {
16330 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
16331 : : .tag_index = REG_C_1,
16332 : : },
16333 : : .src = {
16334 : : .field = (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG,
16335 : : .tag_index = REG_A,
16336 : : },
16337 : : .width = 32,
16338 : : };
16339 : 0 : struct rte_flow_action copy_reg_action[] = {
16340 : : [0] = {
16341 : : .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
16342 : : .conf = &mreg_action,
16343 : : },
16344 : : [1] = {
16345 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
16346 : : },
16347 : : [2] = {
16348 : : .type = RTE_FLOW_ACTION_TYPE_END,
16349 : : },
16350 : : };
16351 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16352 : : .type = MLX5_CTRL_FLOW_TYPE_TX_META_COPY,
16353 : : .tx_repr_sq = sqn,
16354 : : };
16355 : :
16356 : 0 : return flow_hw_create_ctrl_flow(dev, dev,
16357 : 0 : priv->hw_ctrl_nic->hw_tx_meta_cpy_tbl,
16358 : : items, 0, copy_reg_action, 0, &flow_info, false);
16359 : : }
16360 : :
16361 : : int
16362 : 0 : mlx5_flow_hw_create_tx_repr_matching_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16363 : : {
16364 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16365 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
16366 : : .queue = sqn,
16367 : : };
16368 : 0 : struct rte_flow_item items[] = {
16369 : : {
16370 : : .type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_SQ,
16371 : : .spec = &sq_spec,
16372 : : },
16373 : : {
16374 : : .type = RTE_FLOW_ITEM_TYPE_END,
16375 : : },
16376 : : };
16377 : : /*
16378 : : * Allocate actions array suitable for all cases - extended metadata enabled or not.
16379 : : * With extended metadata there will be an additional MODIFY_FIELD action before JUMP.
16380 : : */
16381 : 0 : struct rte_flow_action actions[] = {
16382 : : { .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD },
16383 : : { .type = RTE_FLOW_ACTION_TYPE_JUMP },
16384 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16385 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16386 : : };
16387 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16388 : : .type = MLX5_CTRL_FLOW_TYPE_TX_REPR_MATCH,
16389 : : .tx_repr_sq = sqn,
16390 : : };
16391 : :
16392 [ # # ]: 0 : if (!priv->dr_ctx) {
16393 : 0 : DRV_LOG(DEBUG, "Port %u must be configured for HWS, before creating "
16394 : : "default egress flow rules. Omitting creation.",
16395 : : dev->data->port_id);
16396 : 0 : return 0;
16397 : : }
16398 [ # # ]: 0 : if (!priv->hw_tx_repr_tagging_tbl) {
16399 : 0 : DRV_LOG(ERR, "Port %u is configured for HWS, but table for default "
16400 : : "egress flow rules does not exist.",
16401 : : dev->data->port_id);
16402 : 0 : rte_errno = EINVAL;
16403 : 0 : return -rte_errno;
16404 : : }
16405 : : /*
16406 : : * If extended metadata mode is enabled, then an additional MODIFY_FIELD action must be
16407 : : * placed before terminating JUMP action.
16408 : : */
16409 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
16410 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD;
16411 : 0 : actions[2].type = RTE_FLOW_ACTION_TYPE_JUMP;
16412 : : }
16413 : 0 : return flow_hw_create_ctrl_flow(dev, dev, priv->hw_tx_repr_tagging_tbl,
16414 : : items, 0, actions, 0, &flow_info, external);
16415 : : }
16416 : :
16417 : : static bool
16418 : : flow_hw_is_tx_matching_repr_matching_flow(struct mlx5_ctrl_flow_entry *cf,
16419 : : struct rte_eth_dev *dev,
16420 : : uint32_t sqn)
16421 : : {
16422 : 0 : if (cf->owner_dev != dev)
16423 : : return false;
16424 [ # # # # ]: 0 : if (cf->info.type == MLX5_CTRL_FLOW_TYPE_TX_REPR_MATCH && cf->info.tx_repr_sq == sqn)
16425 : : return true;
16426 : : return false;
16427 : : }
16428 : :
16429 : : int
16430 : 0 : mlx5_flow_hw_destroy_tx_repr_matching_flow(struct rte_eth_dev *dev, uint32_t sqn, bool external)
16431 : : {
16432 : 0 : uint16_t port_id = dev->data->port_id;
16433 : 0 : uint16_t proxy_port_id = dev->data->port_id;
16434 : : struct rte_eth_dev *proxy_dev;
16435 : : struct mlx5_priv *proxy_priv;
16436 : : struct mlx5_ctrl_flow_entry *cf;
16437 : : struct mlx5_ctrl_flow_entry *cf_next;
16438 : : int ret;
16439 : :
16440 : 0 : ret = rte_flow_pick_transfer_proxy(port_id, &proxy_port_id, NULL);
16441 [ # # ]: 0 : if (ret) {
16442 : 0 : DRV_LOG(ERR, "Unable to pick transfer proxy port for port %u. Transfer proxy "
16443 : : "port must be present for default SQ miss flow rules to exist.",
16444 : : port_id);
16445 : 0 : return ret;
16446 : : }
16447 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
16448 : 0 : proxy_priv = proxy_dev->data->dev_private;
16449 [ # # ]: 0 : if (!proxy_priv->dr_ctx ||
16450 [ # # ]: 0 : !proxy_priv->hw_tx_repr_tagging_tbl)
16451 : : return 0;
16452 [ # # ]: 0 : cf = external ? LIST_FIRST(&proxy_priv->hw_ext_ctrl_flows) :
16453 : : LIST_FIRST(&proxy_priv->hw_ctrl_flows);
16454 [ # # ]: 0 : while (cf != NULL) {
16455 [ # # ]: 0 : cf_next = LIST_NEXT(cf, next);
16456 : : if (flow_hw_is_tx_matching_repr_matching_flow(cf, dev, sqn)) {
16457 : 0 : claim_zero(flow_hw_destroy_ctrl_flow(proxy_dev, cf->flow));
16458 [ # # ]: 0 : LIST_REMOVE(cf, next);
16459 : 0 : mlx5_free(cf);
16460 : : }
16461 : : cf = cf_next;
16462 : : }
16463 : : return 0;
16464 : : }
16465 : :
16466 : : int
16467 : 0 : mlx5_flow_hw_lacp_rx_flow(struct rte_eth_dev *dev)
16468 : : {
16469 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16470 : 0 : struct rte_flow_item_eth lacp_item = {
16471 : : .type = RTE_BE16(RTE_ETHER_TYPE_SLOW),
16472 : : };
16473 : 0 : struct rte_flow_item eth_lacp[] = {
16474 : : [0] = {
16475 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16476 : : .spec = &lacp_item,
16477 : : .mask = &lacp_item,
16478 : : },
16479 : : [1] = {
16480 : : .type = RTE_FLOW_ITEM_TYPE_END,
16481 : : },
16482 : : };
16483 : 0 : struct rte_flow_action miss_action[] = {
16484 : : [0] = {
16485 : : .type = (enum rte_flow_action_type)
16486 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
16487 : : },
16488 : : [1] = {
16489 : : .type = RTE_FLOW_ACTION_TYPE_END,
16490 : : },
16491 : : };
16492 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16493 : : .type = MLX5_CTRL_FLOW_TYPE_LACP_RX,
16494 : : };
16495 : :
16496 [ # # # # : 0 : if (!priv->dr_ctx || !priv->hw_lacp_miss || !priv->hw_lacp_miss->hw_lacp_rx_tbl)
# # ]
16497 : : return 0;
16498 : 0 : return flow_hw_create_ctrl_flow(dev, dev,
16499 : : priv->hw_lacp_miss->hw_lacp_rx_tbl,
16500 : : eth_lacp, 0, miss_action, 0, &flow_info, false);
16501 : : }
16502 : :
16503 : : static uint32_t
16504 : : __calc_pattern_flags(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
16505 : : {
16506 : : switch (eth_pattern_type) {
16507 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
16508 : : return MLX5_CTRL_PROMISCUOUS;
16509 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
16510 : : return MLX5_CTRL_ALL_MULTICAST;
16511 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
16512 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16513 : : return MLX5_CTRL_BROADCAST;
16514 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
16515 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16516 : : return MLX5_CTRL_IPV4_MULTICAST;
16517 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
16518 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16519 : : return MLX5_CTRL_IPV6_MULTICAST;
16520 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
16521 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
16522 : : return MLX5_CTRL_DMAC;
16523 : : default:
16524 : : /* Should not reach here. */
16525 : : MLX5_ASSERT(false);
16526 : : return 0;
16527 : : }
16528 : : }
16529 : :
16530 : : static uint32_t
16531 : : __calc_vlan_flags(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type)
16532 : : {
16533 [ # # ]: 0 : switch (eth_pattern_type) {
16534 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16535 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16536 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16537 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
16538 : : return MLX5_CTRL_VLAN_FILTER;
16539 : 0 : default:
16540 : 0 : return 0;
16541 : : }
16542 : : }
16543 : :
16544 : : static bool
16545 [ # # ]: 0 : eth_pattern_type_is_requested(const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
16546 : : uint32_t flags)
16547 : : {
16548 : : uint32_t pattern_flags = __calc_pattern_flags(eth_pattern_type);
16549 : : uint32_t vlan_flags = __calc_vlan_flags(eth_pattern_type);
16550 : 0 : bool pattern_requested = !!(pattern_flags & flags);
16551 [ # # # # ]: 0 : bool consider_vlan = vlan_flags || (MLX5_CTRL_VLAN_FILTER & flags);
16552 : 0 : bool vlan_requested = !!(vlan_flags & flags);
16553 : :
16554 [ # # ]: 0 : if (consider_vlan)
16555 : 0 : return pattern_requested && vlan_requested;
16556 : : else
16557 : : return pattern_requested;
16558 : : }
16559 : :
16560 : : static bool
16561 : : rss_type_is_requested(struct mlx5_priv *priv,
16562 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16563 : : {
16564 : 0 : struct rte_flow_actions_template *at = priv->hw_ctrl_rx->rss[rss_type];
16565 : : unsigned int i;
16566 : :
16567 [ # # # # ]: 0 : for (i = 0; at->actions[i].type != RTE_FLOW_ACTION_TYPE_END; ++i) {
16568 [ # # # # ]: 0 : if (at->actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
16569 : 0 : const struct rte_flow_action_rss *rss = at->actions[i].conf;
16570 : 0 : uint64_t rss_types = rss->types;
16571 : :
16572 [ # # # # ]: 0 : if ((rss_types & priv->rss_conf.rss_hf) != rss_types)
16573 : : return false;
16574 : : }
16575 : : }
16576 : : return true;
16577 : : }
16578 : :
16579 : : static const struct rte_flow_item_eth *
16580 : : __get_eth_spec(const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern)
16581 : : {
16582 : 0 : switch (pattern) {
16583 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
16584 : : return &ctrl_rx_eth_promisc_spec;
16585 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
16586 : 0 : return &ctrl_rx_eth_mcast_spec;
16587 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
16588 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16589 : 0 : return &ctrl_rx_eth_bcast_spec;
16590 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
16591 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16592 : 0 : return &ctrl_rx_eth_ipv4_mcast_spec;
16593 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
16594 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16595 : 0 : return &ctrl_rx_eth_ipv6_mcast_spec;
16596 : 0 : default:
16597 : : /* This case should not be reached. */
16598 : : MLX5_ASSERT(false);
16599 : 0 : return NULL;
16600 : : }
16601 : : }
16602 : :
16603 : : static int
16604 [ # # # # : 0 : __flow_hw_ctrl_flows_single(struct rte_eth_dev *dev,
# # ]
16605 : : struct rte_flow_template_table *tbl,
16606 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
16607 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16608 : : {
16609 : : const struct rte_flow_item_eth *eth_spec = __get_eth_spec(pattern_type);
16610 : : struct rte_flow_item items[5];
16611 : 0 : struct rte_flow_action actions[] = {
16612 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16613 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16614 : : };
16615 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16616 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
16617 : : };
16618 : :
16619 [ # # ]: 0 : if (!eth_spec)
16620 : : return -EINVAL;
16621 : : memset(items, 0, sizeof(items));
16622 : 0 : items[0] = (struct rte_flow_item){
16623 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16624 : : .spec = eth_spec,
16625 : : };
16626 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VOID };
16627 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16628 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16629 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16630 : : /* Without VLAN filtering, only a single flow rule must be created. */
16631 : 0 : return flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0, &flow_info, false);
16632 : : }
16633 : :
16634 : : static int
16635 : 0 : __flow_hw_ctrl_flows_single_vlan(struct rte_eth_dev *dev,
16636 : : struct rte_flow_template_table *tbl,
16637 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
16638 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16639 : : {
16640 [ # # # # : 0 : struct mlx5_priv *priv = dev->data->dev_private;
# # ]
16641 : : const struct rte_flow_item_eth *eth_spec = __get_eth_spec(pattern_type);
16642 : : struct rte_flow_item items[5];
16643 : 0 : struct rte_flow_action actions[] = {
16644 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16645 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16646 : : };
16647 : 0 : struct mlx5_ctrl_flow_info flow_info = {
16648 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
16649 : : };
16650 : : unsigned int i;
16651 : :
16652 [ # # ]: 0 : if (!eth_spec)
16653 : : return -EINVAL;
16654 : : memset(items, 0, sizeof(items));
16655 : 0 : items[0] = (struct rte_flow_item){
16656 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16657 : : .spec = eth_spec,
16658 : : };
16659 : : /* Optional VLAN for now will be VOID - will be filled later. */
16660 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VLAN };
16661 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16662 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16663 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16664 : : /* Since VLAN filtering is done, create a single flow rule for each registered vid. */
16665 [ # # ]: 0 : for (i = 0; i < priv->vlan_filter_n; ++i) {
16666 : 0 : uint16_t vlan = priv->vlan_filter[i];
16667 : 0 : struct rte_flow_item_vlan vlan_spec = {
16668 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
16669 : : };
16670 : :
16671 : 0 : items[1].spec = &vlan_spec;
16672 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev,
16673 : : tbl, items, 0, actions, 0, &flow_info, false))
16674 : 0 : return -rte_errno;
16675 : : }
16676 : : return 0;
16677 : : }
16678 : :
16679 : : static int
16680 : 0 : __flow_hw_ctrl_flows_unicast_create(struct rte_eth_dev *dev,
16681 : : struct rte_flow_template_table *tbl,
16682 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type,
16683 : : const struct rte_ether_addr *addr)
16684 : : {
16685 : 0 : struct rte_flow_item_eth eth_spec = {
16686 : : .hdr.dst_addr = *addr,
16687 : : };
16688 : : struct rte_flow_item items[5];
16689 : 0 : struct rte_flow_action actions[] = {
16690 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16691 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16692 : : };
16693 [ # # # ]: 0 : struct mlx5_ctrl_flow_info flow_info = {
16694 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
16695 : : .uc = {
16696 : : .dmac = *addr,
16697 : : },
16698 : : };
16699 : :
16700 : : memset(items, 0, sizeof(items));
16701 : 0 : items[0] = (struct rte_flow_item){
16702 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16703 : : .spec = ð_spec,
16704 : : };
16705 [ # # # ]: 0 : items[1] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_VOID };
16706 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16707 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16708 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16709 : :
16710 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0, &flow_info, false))
16711 : 0 : return -rte_errno;
16712 : :
16713 : : return 0;
16714 : : }
16715 : :
16716 : : static int
16717 : 0 : __flow_hw_ctrl_flows_unicast(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 : : {
16721 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16722 : : unsigned int i;
16723 : : int ret;
16724 : :
16725 [ # # ]: 0 : for (i = 0; i < priv->sh->dev_cap.max_mac_addrs; ++i) {
16726 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
16727 : :
16728 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
16729 : 0 : continue;
16730 : :
16731 : 0 : ret = __flow_hw_ctrl_flows_unicast_create(dev, tbl, rss_type, mac);
16732 [ # # ]: 0 : if (ret < 0)
16733 : 0 : return ret;
16734 : : }
16735 : : return 0;
16736 : : }
16737 : :
16738 : : static int
16739 : 0 : __flow_hw_ctrl_flows_unicast_vlan_create(struct rte_eth_dev *dev,
16740 : : struct rte_flow_template_table *tbl,
16741 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type,
16742 : : const struct rte_ether_addr *addr,
16743 : : const uint16_t vid)
16744 : : {
16745 : 0 : struct rte_flow_item_eth eth_spec = {
16746 : : .hdr.dst_addr = *addr,
16747 : : };
16748 : 0 : struct rte_flow_item_vlan vlan_spec = {
16749 [ # # ]: 0 : .tci = rte_cpu_to_be_16(vid),
16750 : : };
16751 : : struct rte_flow_item items[5];
16752 : 0 : struct rte_flow_action actions[] = {
16753 : : { .type = RTE_FLOW_ACTION_TYPE_RSS },
16754 : : { .type = RTE_FLOW_ACTION_TYPE_END },
16755 : : };
16756 [ # # # ]: 0 : struct mlx5_ctrl_flow_info flow_info = {
16757 : : .type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
16758 : : .uc = {
16759 : : .dmac = *addr,
16760 : : .vlan = vid,
16761 : : },
16762 : : };
16763 : :
16764 : : memset(items, 0, sizeof(items));
16765 : 0 : items[0] = (struct rte_flow_item){
16766 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
16767 : : .spec = ð_spec,
16768 : : };
16769 [ # # # ]: 0 : items[1] = (struct rte_flow_item){
16770 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
16771 : : .spec = &vlan_spec,
16772 : : };
16773 [ # # # ]: 0 : items[2] = flow_hw_get_ctrl_rx_l3_item(rss_type);
16774 : 0 : items[3] = flow_hw_get_ctrl_rx_l4_item(rss_type);
16775 : 0 : items[4] = (struct rte_flow_item){ .type = RTE_FLOW_ITEM_TYPE_END };
16776 : :
16777 [ # # ]: 0 : if (flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0, &flow_info, false))
16778 : 0 : return -rte_errno;
16779 : :
16780 : : return 0;
16781 : : }
16782 : :
16783 : : static int
16784 : 0 : __flow_hw_ctrl_flows_unicast_vlan(struct rte_eth_dev *dev,
16785 : : struct rte_flow_template_table *tbl,
16786 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16787 : : {
16788 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16789 : : unsigned int i;
16790 : : unsigned int j;
16791 : :
16792 [ # # ]: 0 : for (i = 0; i < priv->sh->dev_cap.max_mac_addrs; ++i) {
16793 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
16794 : :
16795 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
16796 : 0 : continue;
16797 : :
16798 [ # # ]: 0 : for (j = 0; j < priv->vlan_filter_n; ++j) {
16799 : 0 : uint16_t vlan = priv->vlan_filter[j];
16800 : : int ret;
16801 : :
16802 : 0 : ret = __flow_hw_ctrl_flows_unicast_vlan_create(dev, tbl, rss_type,
16803 : : mac, vlan);
16804 [ # # ]: 0 : if (ret < 0)
16805 : 0 : return ret;
16806 : : }
16807 : : }
16808 : : return 0;
16809 : : }
16810 : :
16811 : : static int
16812 : 0 : __flow_hw_ctrl_flows(struct rte_eth_dev *dev,
16813 : : struct rte_flow_template_table *tbl,
16814 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type pattern_type,
16815 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type)
16816 : : {
16817 [ # # # # : 0 : switch (pattern_type) {
# ]
16818 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL:
16819 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST:
16820 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST:
16821 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST:
16822 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST:
16823 : 0 : return __flow_hw_ctrl_flows_single(dev, tbl, pattern_type, rss_type);
16824 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN:
16825 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN:
16826 : : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN:
16827 : 0 : return __flow_hw_ctrl_flows_single_vlan(dev, tbl, pattern_type, rss_type);
16828 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC:
16829 : 0 : return __flow_hw_ctrl_flows_unicast(dev, tbl, rss_type);
16830 : 0 : case MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN:
16831 : 0 : return __flow_hw_ctrl_flows_unicast_vlan(dev, tbl, rss_type);
16832 : 0 : default:
16833 : : /* Should not reach here. */
16834 : : MLX5_ASSERT(false);
16835 : 0 : rte_errno = EINVAL;
16836 : 0 : return -EINVAL;
16837 : : }
16838 : : }
16839 : :
16840 : :
16841 : : int
16842 : 0 : mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags)
16843 : : {
16844 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16845 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
16846 : : unsigned int i;
16847 : : int j;
16848 : : int ret = 0;
16849 : :
16850 : : RTE_SET_USED(priv);
16851 : : RTE_SET_USED(flags);
16852 [ # # ]: 0 : if (!priv->dr_ctx) {
16853 : 0 : DRV_LOG(DEBUG, "port %u Control flow rules will not be created. "
16854 : : "HWS needs to be configured beforehand.",
16855 : : dev->data->port_id);
16856 : 0 : return 0;
16857 : : }
16858 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
16859 : 0 : DRV_LOG(ERR, "port %u Control flow rules templates were not created.",
16860 : : dev->data->port_id);
16861 : 0 : rte_errno = EINVAL;
16862 : 0 : return -rte_errno;
16863 : : }
16864 : : hw_ctrl_rx = priv->hw_ctrl_rx;
16865 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX; ++i) {
16866 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type = i;
16867 : :
16868 [ # # ]: 0 : if (!eth_pattern_type_is_requested(eth_pattern_type, flags))
16869 : 0 : continue;
16870 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
16871 : 0 : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
16872 : : struct rte_flow_actions_template *at;
16873 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[i][j];
16874 : 0 : const struct mlx5_flow_template_table_cfg cfg = {
16875 : : .attr = tmpls->attr,
16876 : : .external = 0,
16877 : : };
16878 : :
16879 [ # # ]: 0 : if (!hw_ctrl_rx->rss[rss_type]) {
16880 : 0 : at = flow_hw_create_ctrl_rx_rss_template(dev, rss_type);
16881 [ # # ]: 0 : if (!at)
16882 : 0 : return -rte_errno;
16883 : 0 : hw_ctrl_rx->rss[rss_type] = at;
16884 : : } else {
16885 : 0 : at = hw_ctrl_rx->rss[rss_type];
16886 : : }
16887 [ # # ]: 0 : if (!rss_type_is_requested(priv, rss_type))
16888 : 0 : continue;
16889 [ # # ]: 0 : if (!tmpls->tbl) {
16890 : 0 : tmpls->tbl = flow_hw_table_create(dev, &cfg,
16891 : : &tmpls->pt, 1, &at, 1, NULL);
16892 [ # # ]: 0 : if (!tmpls->tbl) {
16893 : 0 : DRV_LOG(ERR, "port %u Failed to create template table "
16894 : : "for control flow rules. Unable to create "
16895 : : "control flow rules.",
16896 : : dev->data->port_id);
16897 : 0 : return -rte_errno;
16898 : : }
16899 : : }
16900 : :
16901 : 0 : ret = __flow_hw_ctrl_flows(dev, tmpls->tbl, eth_pattern_type, rss_type);
16902 [ # # ]: 0 : if (ret) {
16903 : 0 : DRV_LOG(ERR, "port %u Failed to create control flow rule.",
16904 : : dev->data->port_id);
16905 : 0 : return ret;
16906 : : }
16907 : : }
16908 : : }
16909 : : return 0;
16910 : : }
16911 : :
16912 : : static int
16913 : 0 : mlx5_flow_hw_ctrl_flow_single(struct rte_eth_dev *dev,
16914 : : const enum mlx5_flow_ctrl_rx_eth_pattern_type eth_pattern_type,
16915 : : const struct rte_ether_addr *addr,
16916 : : const uint16_t vlan)
16917 : : {
16918 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16919 : : struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx;
16920 : : unsigned int j;
16921 : : int ret = 0;
16922 : :
16923 [ # # ]: 0 : if (!priv->dr_ctx) {
16924 : 0 : DRV_LOG(DEBUG, "port %u Control flow rules will not be created. "
16925 : : "HWS needs to be configured beforehand.",
16926 : : dev->data->port_id);
16927 : 0 : return 0;
16928 : : }
16929 [ # # ]: 0 : if (!priv->hw_ctrl_rx) {
16930 : 0 : DRV_LOG(ERR, "port %u Control flow rules templates were not created.",
16931 : : dev->data->port_id);
16932 : 0 : rte_errno = EINVAL;
16933 : 0 : return -rte_errno;
16934 : : }
16935 : : hw_ctrl_rx = priv->hw_ctrl_rx;
16936 : :
16937 : : /* TODO: this part should be somehow refactored. It's common with common flow creation. */
16938 [ # # ]: 0 : for (j = 0; j < MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX; ++j) {
16939 : : const enum mlx5_flow_ctrl_rx_expanded_rss_type rss_type = j;
16940 : : const unsigned int pti = eth_pattern_type;
16941 : : struct rte_flow_actions_template *at;
16942 : : struct mlx5_flow_hw_ctrl_rx_table *tmpls = &hw_ctrl_rx->tables[pti][j];
16943 : 0 : const struct mlx5_flow_template_table_cfg cfg = {
16944 : : .attr = tmpls->attr,
16945 : : .external = 0,
16946 : : };
16947 : :
16948 [ # # ]: 0 : if (!hw_ctrl_rx->rss[rss_type]) {
16949 : 0 : at = flow_hw_create_ctrl_rx_rss_template(dev, rss_type);
16950 [ # # ]: 0 : if (!at)
16951 : 0 : return -rte_errno;
16952 : 0 : hw_ctrl_rx->rss[rss_type] = at;
16953 : : } else {
16954 : 0 : at = hw_ctrl_rx->rss[rss_type];
16955 : : }
16956 [ # # ]: 0 : if (!rss_type_is_requested(priv, rss_type))
16957 : 0 : continue;
16958 [ # # ]: 0 : if (!tmpls->tbl) {
16959 : 0 : tmpls->tbl = flow_hw_table_create(dev, &cfg,
16960 : : &tmpls->pt, 1, &at, 1, NULL);
16961 [ # # ]: 0 : if (!tmpls->tbl) {
16962 : 0 : DRV_LOG(ERR, "port %u Failed to create template table "
16963 : : "for control flow rules. Unable to create "
16964 : : "control flow rules.",
16965 : : dev->data->port_id);
16966 : 0 : return -rte_errno;
16967 : : }
16968 : : }
16969 : :
16970 : : MLX5_ASSERT(eth_pattern_type == MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC ||
16971 : : eth_pattern_type == MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN);
16972 : :
16973 [ # # ]: 0 : if (eth_pattern_type == MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC)
16974 : 0 : ret = __flow_hw_ctrl_flows_unicast_create(dev, tmpls->tbl, rss_type, addr);
16975 : : else
16976 : 0 : ret = __flow_hw_ctrl_flows_unicast_vlan_create(dev, tmpls->tbl, rss_type,
16977 : : addr, vlan);
16978 [ # # ]: 0 : if (ret) {
16979 : 0 : DRV_LOG(ERR, "port %u Failed to create unicast control flow rule.",
16980 : : dev->data->port_id);
16981 : 0 : return ret;
16982 : : }
16983 : : }
16984 : :
16985 : : return 0;
16986 : : }
16987 : :
16988 : : int
16989 : 0 : mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev,
16990 : : const struct rte_ether_addr *addr)
16991 : : {
16992 : 0 : return mlx5_flow_hw_ctrl_flow_single(dev, MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC,
16993 : : addr, 0);
16994 : : }
16995 : :
16996 : :
16997 : : int
16998 : 0 : mlx5_flow_hw_ctrl_flow_dmac_destroy(struct rte_eth_dev *dev,
16999 : : const struct rte_ether_addr *addr)
17000 : : {
17001 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17002 : : struct mlx5_ctrl_flow_entry *entry;
17003 : : struct mlx5_ctrl_flow_entry *tmp;
17004 : : int ret;
17005 : :
17006 : : /*
17007 : : * HWS does not have automatic RSS flow expansion,
17008 : : * so each variant of the control flow rule is a separate entry in the list.
17009 : : * In that case, the whole list must be traversed.
17010 : : */
17011 : 0 : entry = LIST_FIRST(&priv->hw_ctrl_flows);
17012 [ # # ]: 0 : while (entry != NULL) {
17013 : 0 : tmp = LIST_NEXT(entry, next);
17014 : :
17015 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
17016 : : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
17017 : : entry = tmp;
17018 : 0 : continue;
17019 : : }
17020 : :
17021 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, entry->flow);
17022 [ # # ]: 0 : LIST_REMOVE(entry, next);
17023 : 0 : mlx5_free(entry);
17024 [ # # ]: 0 : if (ret)
17025 : 0 : return ret;
17026 : :
17027 : : entry = tmp;
17028 : : }
17029 : : return 0;
17030 : : }
17031 : :
17032 : : int
17033 : 0 : mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev,
17034 : : const struct rte_ether_addr *addr,
17035 : : const uint16_t vlan)
17036 : : {
17037 : 0 : return mlx5_flow_hw_ctrl_flow_single(dev, MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN,
17038 : : addr, vlan);
17039 : : }
17040 : :
17041 : : int
17042 : 0 : mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(struct rte_eth_dev *dev,
17043 : : const struct rte_ether_addr *addr,
17044 : : const uint16_t vlan)
17045 : : {
17046 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17047 : : struct mlx5_ctrl_flow_entry *entry;
17048 : : struct mlx5_ctrl_flow_entry *tmp;
17049 : : int ret;
17050 : :
17051 : : /*
17052 : : * HWS does not have automatic RSS flow expansion,
17053 : : * so each variant of the control flow rule is a separate entry in the list.
17054 : : * In that case, the whole list must be traversed.
17055 : : */
17056 : 0 : entry = LIST_FIRST(&priv->hw_ctrl_flows);
17057 [ # # ]: 0 : while (entry != NULL) {
17058 : 0 : tmp = LIST_NEXT(entry, next);
17059 : :
17060 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
17061 : 0 : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
17062 [ # # ]: 0 : vlan != entry->info.uc.vlan) {
17063 : : entry = tmp;
17064 : 0 : continue;
17065 : : }
17066 : :
17067 : 0 : ret = flow_hw_destroy_ctrl_flow(dev, entry->flow);
17068 [ # # ]: 0 : LIST_REMOVE(entry, next);
17069 : 0 : mlx5_free(entry);
17070 [ # # ]: 0 : if (ret)
17071 : 0 : return ret;
17072 : :
17073 : : entry = tmp;
17074 : : }
17075 : : return 0;
17076 : : }
17077 : :
17078 : : struct mlx5_ecpri_parser_profile *
17079 : 0 : mlx5_flow_hw_get_ecpri_parser_profile(void *dr_ctx)
17080 : : {
17081 : : uint16_t port_id;
17082 : : bool found = false;
17083 : : struct mlx5_priv *priv;
17084 : :
17085 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
17086 : 0 : priv = rte_eth_devices[port_id].data->dev_private;
17087 [ # # ]: 0 : if (priv->dr_ctx == dr_ctx) {
17088 : : found = true;
17089 : : break;
17090 : : }
17091 : : }
17092 [ # # ]: 0 : if (found)
17093 : 0 : return &priv->sh->ecpri_parser;
17094 : 0 : rte_errno = ENODEV;
17095 : 0 : return NULL;
17096 : : }
17097 : :
17098 : :
17099 : : static __rte_always_inline uint32_t
17100 : : mlx5_reformat_domain_to_tbl_type(const struct rte_flow_indir_action_conf *domain,
17101 : : bool fdb_unified_en)
17102 : : {
17103 : : uint32_t tbl_type;
17104 : :
17105 [ # # ]: 0 : if (domain->transfer)
17106 : : tbl_type = (fdb_unified_en ?
17107 : : (MLX5DR_ACTION_FLAG_HWS_FDB_RX |
17108 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
17109 [ # # ]: 0 : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) :
17110 : : MLX5DR_ACTION_FLAG_HWS_FDB);
17111 [ # # ]: 0 : else if (domain->egress)
17112 : : tbl_type = MLX5DR_ACTION_FLAG_HWS_TX;
17113 [ # # ]: 0 : else if (domain->ingress)
17114 : : tbl_type = MLX5DR_ACTION_FLAG_HWS_RX;
17115 : : else
17116 : : tbl_type = UINT32_MAX;
17117 : : return tbl_type;
17118 : : }
17119 : :
17120 : : static struct mlx5_hw_encap_decap_action *
17121 : 0 : __mlx5_reformat_create(struct rte_eth_dev *dev,
17122 : : const struct rte_flow_action_raw_encap *encap_conf,
17123 : : const struct rte_flow_indir_action_conf *domain,
17124 : : enum mlx5dr_action_type type)
17125 : : {
17126 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
17127 : : struct mlx5_hw_encap_decap_action *handle;
17128 : : struct mlx5dr_action_reformat_header hdr;
17129 : : uint32_t flags;
17130 : : bool unified_fdb = is_unified_fdb(priv);
17131 : :
17132 : : flags = mlx5_reformat_domain_to_tbl_type(domain, unified_fdb);
17133 : 0 : flags |= (uint32_t)MLX5DR_ACTION_FLAG_SHARED;
17134 [ # # ]: 0 : if (flags == UINT32_MAX) {
17135 : 0 : DRV_LOG(ERR, "Reformat: invalid indirect action configuration");
17136 : 0 : return NULL;
17137 : : }
17138 : : /* Allocate new list entry. */
17139 : 0 : handle = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*handle), 0, SOCKET_ID_ANY);
17140 [ # # ]: 0 : if (!handle) {
17141 : 0 : DRV_LOG(ERR, "Reformat: failed to allocate reformat entry");
17142 : 0 : return NULL;
17143 : : }
17144 : 0 : handle->action_type = type;
17145 [ # # ]: 0 : hdr.sz = encap_conf ? encap_conf->size : 0;
17146 [ # # ]: 0 : hdr.data = encap_conf ? encap_conf->data : NULL;
17147 : 0 : handle->action = mlx5dr_action_create_reformat(priv->dr_ctx,
17148 : : type, 1, &hdr, 0, flags);
17149 [ # # ]: 0 : if (!handle->action) {
17150 : 0 : DRV_LOG(ERR, "Reformat: failed to create reformat action");
17151 : 0 : mlx5_free(handle);
17152 : 0 : return NULL;
17153 : : }
17154 : : return handle;
17155 : : }
17156 : :
17157 : : /**
17158 : : * Create mlx5 reformat action.
17159 : : *
17160 : : * @param[in] dev
17161 : : * Pointer to rte_eth_dev structure.
17162 : : * @param[in] conf
17163 : : * Pointer to the indirect action parameters.
17164 : : * @param[in] encap_action
17165 : : * Pointer to the raw_encap action configuration.
17166 : : * @param[in] decap_action
17167 : : * Pointer to the raw_decap action configuration.
17168 : : * @param[out] error
17169 : : * Pointer to error structure.
17170 : : *
17171 : : * @return
17172 : : * A valid shared action handle in case of success, NULL otherwise and
17173 : : * rte_errno is set.
17174 : : */
17175 : : struct mlx5_hw_encap_decap_action*
17176 : 0 : mlx5_reformat_action_create(struct rte_eth_dev *dev,
17177 : : const struct rte_flow_indir_action_conf *conf,
17178 : : const struct rte_flow_action *encap_action,
17179 : : const struct rte_flow_action *decap_action,
17180 : : struct rte_flow_error *error)
17181 : : {
17182 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17183 : : struct mlx5_hw_encap_decap_action *handle;
17184 : : const struct rte_flow_action_raw_encap *encap = NULL;
17185 : : const struct rte_flow_action_raw_decap *decap = NULL;
17186 : : enum mlx5dr_action_type type = MLX5DR_ACTION_TYP_LAST;
17187 : :
17188 : : MLX5_ASSERT(!encap_action || encap_action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP);
17189 : : MLX5_ASSERT(!decap_action || decap_action->type == RTE_FLOW_ACTION_TYPE_RAW_DECAP);
17190 [ # # ]: 0 : if (priv->sh->config.dv_flow_en != 2) {
17191 : 0 : rte_flow_error_set(error, ENOTSUP,
17192 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17193 : : "Reformat: hardware does not support");
17194 : 0 : return NULL;
17195 : : }
17196 [ # # # # ]: 0 : if (!conf || (conf->transfer + conf->egress + conf->ingress != 1)) {
17197 : 0 : rte_flow_error_set(error, EINVAL,
17198 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17199 : : "Reformat: domain should be specified");
17200 : 0 : return NULL;
17201 : : }
17202 [ # # # # : 0 : if ((encap_action && !encap_action->conf) || (decap_action && !decap_action->conf)) {
# # # # ]
17203 : 0 : rte_flow_error_set(error, EINVAL,
17204 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17205 : : "Reformat: missed action configuration");
17206 : 0 : return NULL;
17207 : : }
17208 [ # # ]: 0 : if (encap_action && !decap_action) {
17209 : 0 : encap = (const struct rte_flow_action_raw_encap *)encap_action->conf;
17210 [ # # ]: 0 : if (!encap->size || encap->size > MLX5_ENCAP_MAX_LEN ||
17211 : : encap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
17212 : 0 : rte_flow_error_set(error, EINVAL,
17213 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17214 : : "Reformat: Invalid encap length");
17215 : 0 : return NULL;
17216 : : }
17217 : : type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2;
17218 [ # # ]: 0 : } else if (decap_action && !encap_action) {
17219 : 0 : decap = (const struct rte_flow_action_raw_decap *)decap_action->conf;
17220 [ # # ]: 0 : if (!decap->size || decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
17221 : 0 : rte_flow_error_set(error, EINVAL,
17222 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17223 : : "Reformat: Invalid decap length");
17224 : 0 : return NULL;
17225 : : }
17226 : : type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
17227 [ # # ]: 0 : } else if (encap_action && decap_action) {
17228 : 0 : decap = (const struct rte_flow_action_raw_decap *)decap_action->conf;
17229 : 0 : encap = (const struct rte_flow_action_raw_encap *)encap_action->conf;
17230 [ # # ]: 0 : if (decap->size < MLX5_ENCAPSULATION_DECISION_SIZE &&
17231 [ # # # # ]: 0 : encap->size >= MLX5_ENCAPSULATION_DECISION_SIZE &&
17232 : : encap->size <= MLX5_ENCAP_MAX_LEN) {
17233 : : type = MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3;
17234 [ # # ]: 0 : } else if (decap->size >= MLX5_ENCAPSULATION_DECISION_SIZE &&
17235 [ # # ]: 0 : encap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
17236 : : type = MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2;
17237 : : } else {
17238 : 0 : rte_flow_error_set(error, EINVAL,
17239 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17240 : : "Reformat: Invalid decap & encap length");
17241 : 0 : return NULL;
17242 : : }
17243 [ # # ]: 0 : } else if (!encap_action && !decap_action) {
17244 : 0 : rte_flow_error_set(error, EINVAL,
17245 : : RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17246 : : "Reformat: Invalid decap & encap configurations");
17247 : 0 : return NULL;
17248 : : }
17249 [ # # ]: 0 : if (!priv->dr_ctx) {
17250 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17251 : : encap_action, "Reformat: HWS not supported");
17252 : 0 : return NULL;
17253 : : }
17254 : 0 : handle = __mlx5_reformat_create(dev, encap, conf, type);
17255 [ # # ]: 0 : if (!handle) {
17256 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, encap_action,
17257 : : "Reformat: failed to create indirect action");
17258 : 0 : return NULL;
17259 : : }
17260 : : return handle;
17261 : : }
17262 : :
17263 : : /**
17264 : : * Destroy the indirect reformat action.
17265 : : * Release action related resources on the NIC and the memory.
17266 : : * Lock free, (mutex should be acquired by caller).
17267 : : *
17268 : : * @param[in] dev
17269 : : * Pointer to the Ethernet device structure.
17270 : : * @param[in] handle
17271 : : * The indirect action list handle to be removed.
17272 : : * @param[out] error
17273 : : * Perform verbose error reporting if not NULL. Initialized in case of
17274 : : * error only.
17275 : : *
17276 : : * @return
17277 : : * 0 on success, otherwise negative errno value.
17278 : : */
17279 : : int
17280 : 0 : mlx5_reformat_action_destroy(struct rte_eth_dev *dev,
17281 : : struct rte_flow_action_list_handle *handle,
17282 : : struct rte_flow_error *error)
17283 : : {
17284 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17285 : : struct mlx5_hw_encap_decap_action *action;
17286 : :
17287 : : action = (struct mlx5_hw_encap_decap_action *)handle;
17288 [ # # # # ]: 0 : if (!priv->dr_ctx || !action)
17289 : 0 : return rte_flow_error_set(error, ENOTSUP,
17290 : : RTE_FLOW_ERROR_TYPE_ACTION, handle,
17291 : : "Reformat: invalid action handle");
17292 : 0 : mlx5dr_action_destroy(action->action);
17293 : 0 : mlx5_free(handle);
17294 : 0 : return 0;
17295 : : }
17296 : :
17297 : : static bool
17298 : 0 : flow_hw_is_item_masked(const struct rte_flow_item *item)
17299 : : {
17300 : : const uint8_t *byte;
17301 : : int size;
17302 : : int i;
17303 : :
17304 [ # # ]: 0 : if (item->mask == NULL)
17305 : : return false;
17306 : :
17307 [ # # ]: 0 : switch ((int)item->type) {
17308 : : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
17309 : : size = sizeof(struct rte_flow_item_tag);
17310 : : break;
17311 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
17312 : : size = sizeof(struct mlx5_rte_flow_item_sq);
17313 : : break;
17314 : 0 : default:
17315 : 0 : size = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_MASK, NULL, 0, item, NULL);
17316 : : /*
17317 : : * Pattern template items are passed to this function.
17318 : : * These items were already validated, so error is not expected.
17319 : : * Also, if mask is NULL, then spec size is bigger than 0 always.
17320 : : */
17321 : : MLX5_ASSERT(size > 0);
17322 : : }
17323 : :
17324 : 0 : byte = (const uint8_t *)item->mask;
17325 [ # # ]: 0 : for (i = 0; i < size; ++i)
17326 [ # # ]: 0 : if (byte[i])
17327 : : return true;
17328 : :
17329 : : return false;
17330 : : }
17331 : :
17332 : : static int
17333 : 0 : flow_hw_validate_rule_pattern(struct rte_eth_dev *dev,
17334 : : const struct rte_flow_template_table *table,
17335 : : const uint8_t pattern_template_idx,
17336 : : const struct rte_flow_item items[],
17337 : : struct rte_flow_error *error)
17338 : : {
17339 : : const struct rte_flow_pattern_template *pt;
17340 : : const struct rte_flow_item *pt_item;
17341 : :
17342 [ # # ]: 0 : if (pattern_template_idx >= table->nb_item_templates)
17343 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17344 : : "Pattern template index out of range");
17345 : :
17346 : 0 : pt = table->its[pattern_template_idx];
17347 : 0 : pt_item = pt->items;
17348 : :
17349 : : /* If any item was prepended, skip it. */
17350 [ # # ]: 0 : if (pt->implicit_port || pt->implicit_tag)
17351 : 0 : pt_item++;
17352 : :
17353 [ # # ]: 0 : for (; pt_item->type != RTE_FLOW_ITEM_TYPE_END; pt_item++, items++) {
17354 [ # # ]: 0 : if (pt_item->type != items->type)
17355 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
17356 : : items, "Item type does not match the template");
17357 : :
17358 : : /*
17359 : : * Assumptions:
17360 : : * - Currently mlx5dr layer contains info on which fields in masks are supported.
17361 : : * - This info is not exposed to PMD directly.
17362 : : * - Because of that, it is assumed that since pattern template is correct,
17363 : : * then, items' masks in pattern template have nonzero values only in
17364 : : * supported fields.
17365 : : * This is known, because a temporary mlx5dr matcher is created during pattern
17366 : : * template creation to validate the template.
17367 : : * - As a result, it is safe to look for nonzero bytes in mask to determine if
17368 : : * item spec is needed in a flow rule.
17369 : : */
17370 [ # # ]: 0 : if (!flow_hw_is_item_masked(pt_item))
17371 : 0 : continue;
17372 : :
17373 [ # # ]: 0 : if (items->spec == NULL)
17374 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
17375 : : items, "Item spec is required");
17376 : :
17377 [ # # # # ]: 0 : switch (items->type) {
17378 : : const struct rte_flow_item_ethdev *ethdev;
17379 : : const struct rte_flow_item_tx_queue *tx_queue;
17380 : : const struct rte_flow_item_conntrack *spec;
17381 : : struct mlx5_txq_ctrl *txq;
17382 : :
17383 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
17384 : : ethdev = items->spec;
17385 [ # # ]: 0 : if (flow_hw_validate_target_port_id(dev, ethdev->port_id)) {
17386 : 0 : return rte_flow_error_set(error, EINVAL,
17387 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, items,
17388 : : "Invalid port");
17389 : : }
17390 : : break;
17391 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
17392 : : tx_queue = items->spec;
17393 [ # # # # ]: 0 : if (mlx5_is_external_txq(dev, tx_queue->tx_queue))
17394 : 0 : continue;
17395 : 0 : txq = mlx5_txq_get(dev, tx_queue->tx_queue);
17396 [ # # ]: 0 : if (!txq)
17397 : 0 : return rte_flow_error_set(error, EINVAL,
17398 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, items,
17399 : : "Invalid Tx queue");
17400 : 0 : mlx5_txq_release(dev, tx_queue->tx_queue);
17401 : 0 : break;
17402 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
17403 : : spec = items->spec;
17404 [ # # ]: 0 : if (spec->flags & ~MLX5_FLOW_CONNTRACK_PKT_STATE_ALL)
17405 : 0 : return rte_flow_error_set(error, EINVAL,
17406 : : RTE_FLOW_ERROR_TYPE_ITEM,
17407 : : NULL,
17408 : : "Invalid CT item flags");
17409 : : break;
17410 : : default:
17411 : : break;
17412 : : }
17413 : : }
17414 : :
17415 : : return 0;
17416 : : }
17417 : :
17418 : : static bool
17419 : 0 : flow_hw_valid_indirect_action_type(const struct rte_flow_action *user_action,
17420 : : const enum rte_flow_action_type expected_type)
17421 : : {
17422 : 0 : uint32_t user_indirect_type = MLX5_INDIRECT_ACTION_TYPE_GET(user_action->conf);
17423 : : uint32_t expected_indirect_type;
17424 : :
17425 [ # # # # : 0 : switch ((int)expected_type) {
# # # ]
17426 : : case RTE_FLOW_ACTION_TYPE_RSS:
17427 : : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
17428 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_RSS;
17429 : : break;
17430 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17431 : : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
17432 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_COUNT;
17433 : 0 : break;
17434 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17435 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_AGE;
17436 : 0 : break;
17437 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17438 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_CT;
17439 : 0 : break;
17440 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
17441 : : case MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK:
17442 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_METER_MARK;
17443 : 0 : break;
17444 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
17445 : : expected_indirect_type = MLX5_INDIRECT_ACTION_TYPE_QUOTA;
17446 : 0 : break;
17447 : : default:
17448 : : return false;
17449 : : }
17450 : :
17451 : 0 : return user_indirect_type == expected_indirect_type;
17452 : : }
17453 : :
17454 : : static int
17455 : 0 : flow_hw_validate_rule_actions(struct rte_eth_dev *dev,
17456 : : const struct rte_flow_template_table *table,
17457 : : const uint8_t actions_template_idx,
17458 : : const struct rte_flow_action actions[],
17459 : : struct rte_flow_error *error)
17460 : : {
17461 : : const struct rte_flow_actions_template *at;
17462 : : const struct mlx5_hw_actions *hw_acts;
17463 : : const struct mlx5_action_construct_data *act_data;
17464 : : unsigned int idx;
17465 : :
17466 [ # # ]: 0 : if (actions_template_idx >= table->nb_action_templates)
17467 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17468 : : "Actions template index out of range");
17469 : :
17470 : 0 : at = table->ats[actions_template_idx].action_template;
17471 : : hw_acts = &table->ats[actions_template_idx].acts;
17472 : :
17473 [ # # ]: 0 : for (idx = 0; actions[idx].type != RTE_FLOW_ACTION_TYPE_END; ++idx) {
17474 : : const struct rte_flow_action *user_action = &actions[idx];
17475 : 0 : const struct rte_flow_action *tmpl_action = &at->orig_actions[idx];
17476 : :
17477 [ # # ]: 0 : if (user_action->type != tmpl_action->type)
17478 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
17479 : : user_action,
17480 : : "Action type does not match type specified in "
17481 : : "actions template");
17482 : : }
17483 : :
17484 : : /*
17485 : : * Only go through unmasked actions and check if configuration is provided.
17486 : : * Configuration of masked actions is ignored.
17487 : : */
17488 [ # # ]: 0 : LIST_FOREACH(act_data, &hw_acts->act_list, next) {
17489 : : const struct rte_flow_action *user_action;
17490 : :
17491 : 0 : user_action = &actions[act_data->action_src];
17492 : :
17493 : : /* Skip actions which do not require conf. */
17494 [ # # ]: 0 : switch ((int)act_data->type) {
17495 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17496 : : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
17497 : : case MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK:
17498 : : case MLX5_RTE_FLOW_ACTION_TYPE_RSS:
17499 : 0 : continue;
17500 : : default:
17501 : : break;
17502 : : }
17503 : :
17504 [ # # ]: 0 : if (user_action->conf == NULL)
17505 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
17506 : : user_action,
17507 : : "Action requires configuration");
17508 : :
17509 [ # # # # : 0 : switch ((int)user_action->type) {
# # ]
17510 : : enum rte_flow_action_type expected_type;
17511 : : const struct rte_flow_action_ethdev *ethdev;
17512 : : const struct rte_flow_action_modify_field *mf;
17513 : :
17514 : 0 : case RTE_FLOW_ACTION_TYPE_INDIRECT:
17515 : 0 : expected_type = act_data->indirect.expected_type;
17516 [ # # ]: 0 : if (!flow_hw_valid_indirect_action_type(user_action, expected_type))
17517 : 0 : return rte_flow_error_set(error, EINVAL,
17518 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
17519 : : user_action,
17520 : : "Indirect action type does not match "
17521 : : "the type specified in the mask");
17522 : : break;
17523 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17524 [ # # ]: 0 : if (mlx5_flow_validate_target_queue(dev, user_action, error))
17525 : 0 : return -rte_errno;
17526 : : break;
17527 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17528 [ # # ]: 0 : if (mlx5_validate_action_rss(dev, user_action, error))
17529 : 0 : return -rte_errno;
17530 : : break;
17531 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17532 : : /* TODO: Compare other fields if needed. */
17533 : : mf = user_action->conf;
17534 [ # # ]: 0 : if (mf->operation != act_data->modify_header.action.operation ||
17535 [ # # ]: 0 : mf->src.field != act_data->modify_header.action.src.field ||
17536 [ # # ]: 0 : mf->dst.field != act_data->modify_header.action.dst.field ||
17537 [ # # ]: 0 : mf->width != act_data->modify_header.action.width)
17538 : 0 : return rte_flow_error_set(error, EINVAL,
17539 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
17540 : : user_action,
17541 : : "Modify field configuration does not "
17542 : : "match configuration from actions "
17543 : : "template");
17544 : : break;
17545 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17546 : : ethdev = user_action->conf;
17547 [ # # ]: 0 : if (flow_hw_validate_target_port_id(dev, ethdev->port_id)) {
17548 : 0 : return rte_flow_error_set(error, EINVAL,
17549 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
17550 : : user_action, "Invalid port");
17551 : : }
17552 : : break;
17553 : : default:
17554 : : break;
17555 : : }
17556 : : }
17557 : :
17558 : : return 0;
17559 : : }
17560 : :
17561 : : static int
17562 : 0 : flow_hw_async_op_validate(struct rte_eth_dev *dev,
17563 : : const uint32_t queue,
17564 : : const struct rte_flow_template_table *table,
17565 : : struct rte_flow_error *error)
17566 : : {
17567 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17568 : :
17569 : : MLX5_ASSERT(table != NULL);
17570 : :
17571 [ # # # # ]: 0 : if (table->cfg.external && queue >= priv->hw_attr->nb_queue)
17572 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17573 : : "Incorrect queue");
17574 : :
17575 : : return 0;
17576 : : }
17577 : :
17578 : : /**
17579 : : * Validate user input for rte_flow_async_create() implementation.
17580 : : *
17581 : : * If RTE_PMD_MLX5_DEBUG macro is not defined, this function is a no-op.
17582 : : *
17583 : : * @param[in] dev
17584 : : * Pointer to the rte_eth_dev structure.
17585 : : * @param[in] queue
17586 : : * The queue to create the flow.
17587 : : * @param[in] table
17588 : : * Pointer to template table.
17589 : : * @param[in] rule_index
17590 : : * The item pattern flow follows from the table.
17591 : : * @param[in] items
17592 : : * Items with flow spec value.
17593 : : * @param[in] pattern_template_index
17594 : : * The item pattern flow follows from the table.
17595 : : * @param[in] actions
17596 : : * Action with flow spec value.
17597 : : * @param[in] action_template_index
17598 : : * The action pattern flow follows from the table.
17599 : : * @param[out] error
17600 : : * Pointer to error structure.
17601 : : *
17602 : : * @return
17603 : : * 0 if user input is valid.
17604 : : * Negative errno otherwise, rte_errno and error struct is populated.
17605 : : */
17606 : : static int
17607 : 0 : flow_hw_async_create_validate(struct rte_eth_dev *dev,
17608 : : const uint32_t queue,
17609 : : const struct rte_flow_template_table *table,
17610 : : enum rte_flow_table_insertion_type insertion_type,
17611 : : uint32_t rule_index,
17612 : : const struct rte_flow_item items[],
17613 : : const uint8_t pattern_template_index,
17614 : : const struct rte_flow_action actions[],
17615 : : const uint8_t action_template_index,
17616 : : struct rte_flow_error *error)
17617 : : {
17618 [ # # ]: 0 : if (flow_hw_async_op_validate(dev, queue, table, error))
17619 : 0 : return -rte_errno;
17620 : :
17621 [ # # ]: 0 : if (insertion_type != table->cfg.attr.insertion_type)
17622 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17623 : : NULL, "Flow rule insertion type mismatch with table configuration");
17624 : :
17625 [ # # ]: 0 : if (table->cfg.attr.insertion_type != RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN)
17626 [ # # ]: 0 : if (rule_index >= table->cfg.attr.nb_flows)
17627 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17628 : : NULL, "Flow rule index exceeds table size");
17629 : :
17630 [ # # ]: 0 : if (table->cfg.attr.insertion_type != RTE_FLOW_TABLE_INSERTION_TYPE_INDEX)
17631 [ # # ]: 0 : if (flow_hw_validate_rule_pattern(dev, table, pattern_template_index, items, error))
17632 : 0 : return -rte_errno;
17633 : :
17634 [ # # ]: 0 : if (flow_hw_validate_rule_actions(dev, table, action_template_index, actions, error))
17635 : 0 : return -rte_errno;
17636 : :
17637 : : return 0;
17638 : : }
17639 : :
17640 : : /**
17641 : : * Validate user input for rte_flow_async_update() implementation.
17642 : : *
17643 : : * If RTE_PMD_MLX5_DEBUG macro is not defined, this function is a no-op.
17644 : : *
17645 : : * @param[in] dev
17646 : : * Pointer to the rte_eth_dev structure.
17647 : : * @param[in] queue
17648 : : * The queue to create the flow.
17649 : : * @param[in] flow
17650 : : * Flow rule to be updated.
17651 : : * @param[in] actions
17652 : : * Action with flow spec value.
17653 : : * @param[in] action_template_index
17654 : : * The action pattern flow follows from the table.
17655 : : * @param[out] error
17656 : : * Pointer to error structure.
17657 : : *
17658 : : * @return
17659 : : * 0 if user input is valid.
17660 : : * Negative errno otherwise, rte_errno and error struct is set.
17661 : : */
17662 : : static int
17663 : 0 : flow_hw_async_update_validate(struct rte_eth_dev *dev,
17664 : : const uint32_t queue,
17665 : : const struct rte_flow_hw *flow,
17666 : : const struct rte_flow_action actions[],
17667 : : const uint8_t action_template_index,
17668 : : struct rte_flow_error *error)
17669 : : {
17670 [ # # ]: 0 : if (flow_hw_async_op_validate(dev, queue, flow->table, error))
17671 : 0 : return -rte_errno;
17672 : :
17673 [ # # ]: 0 : if (flow_hw_validate_rule_actions(dev, flow->table, action_template_index, actions, error))
17674 : 0 : return -rte_errno;
17675 : :
17676 : : return 0;
17677 : : }
17678 : :
17679 : : /**
17680 : : * Validate user input for rte_flow_async_destroy() implementation.
17681 : : *
17682 : : * If RTE_PMD_MLX5_DEBUG macro is not defined, this function is a no-op.
17683 : : *
17684 : : * @param[in] dev
17685 : : * Pointer to the rte_eth_dev structure.
17686 : : * @param[in] queue
17687 : : * The queue to create the flow.
17688 : : * @param[in] flow
17689 : : * Flow rule to be destroyed.
17690 : : * @param[out] error
17691 : : * Pointer to error structure.
17692 : : *
17693 : : * @return
17694 : : * 0 if user input is valid.
17695 : : * Negative errno otherwise, rte_errno and error struct is set.
17696 : : */
17697 : : static int
17698 : : flow_hw_async_destroy_validate(struct rte_eth_dev *dev,
17699 : : const uint32_t queue,
17700 : : const struct rte_flow_hw *flow,
17701 : : struct rte_flow_error *error)
17702 : : {
17703 : : if (flow_hw_async_op_validate(dev, queue, flow->table, error))
17704 : : return -rte_errno;
17705 : :
17706 : : return 0;
17707 : : }
17708 : :
17709 : : static struct rte_flow_fp_ops mlx5_flow_hw_fp_ops = {
17710 : : .async_create = flow_hw_async_flow_create,
17711 : : .async_create_by_index = flow_hw_async_flow_create_by_index,
17712 : : .async_create_by_index_with_pattern = flow_hw_async_flow_create_by_index_with_pattern,
17713 : : .async_actions_update = flow_hw_async_flow_update,
17714 : : .async_destroy = flow_hw_async_flow_destroy,
17715 : : .push = flow_hw_push,
17716 : : .pull = flow_hw_pull,
17717 : : .async_action_handle_create = flow_hw_action_handle_create,
17718 : : .async_action_handle_destroy = flow_hw_action_handle_destroy,
17719 : : .async_action_handle_update = flow_hw_action_handle_update,
17720 : : .async_action_handle_query = flow_hw_action_handle_query,
17721 : : .async_action_handle_query_update = flow_hw_async_action_handle_query_update,
17722 : : .async_action_list_handle_create = flow_hw_async_action_list_handle_create,
17723 : : .async_action_list_handle_destroy = flow_hw_async_action_list_handle_destroy,
17724 : : .async_action_list_handle_query_update =
17725 : : flow_hw_async_action_list_handle_query_update,
17726 : : };
17727 : :
17728 : : #endif
|