Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2022 NVIDIA Corporation & Affiliates
3 : : */
4 : :
5 : : #include "mlx5dr_internal.h"
6 : :
7 : : #define WIRE_PORT 0xFFFF
8 : :
9 : : #define MLX5DR_ACTION_METER_INIT_COLOR_OFFSET 1
10 : : /* Header removal size limited to 128B (64 words) */
11 : : #define MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE 128
12 : :
13 : : static struct mlx5dr_devx_obj *
14 : : mlx5dr_action_get_stc_obj_by_tbl_type(enum mlx5dr_table_type table_type,
15 : : struct mlx5dr_pool *stc_pool,
16 : : struct mlx5dr_pool_chunk *stc,
17 : : bool is_mirror);
18 : :
19 : : /* This is the maximum allowed action order for each table type:
20 : : * TX: POP_VLAN, CTR, ASO_METER, AS_CT, PUSH_VLAN, MODIFY, ENCAP, Term
21 : : * RX: TAG, DECAP, POP_VLAN, CTR, ASO_METER, ASO_CT, PUSH_VLAN, MODIFY,
22 : : * ENCAP, Term
23 : : * FDB: DECAP, POP_VLAN, CTR, ASO_METER, ASO_CT, PUSH_VLAN, MODIFY,
24 : : * ENCAP, Term
25 : : */
26 : : static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_MAX] = {
27 : : [MLX5DR_TABLE_TYPE_NIC_RX] = {
28 : : BIT(MLX5DR_ACTION_TYP_TAG),
29 : : BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) |
30 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
31 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) |
32 : : BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT),
33 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
34 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
35 : : BIT(MLX5DR_ACTION_TYP_CTR),
36 : : BIT(MLX5DR_ACTION_TYP_ASO_METER),
37 : : BIT(MLX5DR_ACTION_TYP_ASO_CT),
38 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
39 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
40 : : BIT(MLX5DR_ACTION_TYP_NAT64),
41 : : BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
42 : : BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
43 : : BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
44 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
45 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
46 : : BIT(MLX5DR_ACTION_TYP_TBL) |
47 : : BIT(MLX5DR_ACTION_TYP_MISS) |
48 : : BIT(MLX5DR_ACTION_TYP_TIR) |
49 : : BIT(MLX5DR_ACTION_TYP_DROP) |
50 : : BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
51 : : BIT(MLX5DR_ACTION_TYP_DEST_ARRAY) |
52 : : BIT(MLX5DR_ACTION_TYP_JUMP_TO_MATCHER),
53 : : BIT(MLX5DR_ACTION_TYP_LAST),
54 : : },
55 : : [MLX5DR_TABLE_TYPE_NIC_TX] = {
56 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
57 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
58 : : BIT(MLX5DR_ACTION_TYP_CTR),
59 : : BIT(MLX5DR_ACTION_TYP_ASO_METER),
60 : : BIT(MLX5DR_ACTION_TYP_ASO_CT),
61 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
62 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
63 : : BIT(MLX5DR_ACTION_TYP_NAT64),
64 : : BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
65 : : BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
66 : : BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
67 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
68 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
69 : : BIT(MLX5DR_ACTION_TYP_TBL) |
70 : : BIT(MLX5DR_ACTION_TYP_MISS) |
71 : : BIT(MLX5DR_ACTION_TYP_DROP) |
72 : : BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
73 : : BIT(MLX5DR_ACTION_TYP_JUMP_TO_MATCHER),
74 : : BIT(MLX5DR_ACTION_TYP_LAST),
75 : : },
76 : : [MLX5DR_TABLE_TYPE_FDB] = {
77 : : BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) |
78 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
79 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) |
80 : : BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT),
81 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
82 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
83 : : BIT(MLX5DR_ACTION_TYP_CTR),
84 : : BIT(MLX5DR_ACTION_TYP_TAG),
85 : : BIT(MLX5DR_ACTION_TYP_ASO_METER),
86 : : BIT(MLX5DR_ACTION_TYP_ASO_CT),
87 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
88 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
89 : : BIT(MLX5DR_ACTION_TYP_NAT64),
90 : : BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
91 : : BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
92 : : BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
93 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
94 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
95 : : BIT(MLX5DR_ACTION_TYP_TBL) |
96 : : BIT(MLX5DR_ACTION_TYP_MISS) |
97 : : BIT(MLX5DR_ACTION_TYP_TIR) |
98 : : BIT(MLX5DR_ACTION_TYP_VPORT) |
99 : : BIT(MLX5DR_ACTION_TYP_DROP) |
100 : : BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
101 : : BIT(MLX5DR_ACTION_TYP_DEST_ARRAY) |
102 : : BIT(MLX5DR_ACTION_TYP_JUMP_TO_MATCHER),
103 : : BIT(MLX5DR_ACTION_TYP_LAST),
104 : : },
105 : : };
106 : :
107 : 0 : static int mlx5dr_action_get_shared_stc_nic(struct mlx5dr_context *ctx,
108 : : enum mlx5dr_context_shared_stc_type stc_type,
109 : : uint8_t tbl_type)
110 : : {
111 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
112 : : struct mlx5dr_action_shared_stc *shared_stc;
113 : : int ret;
114 : :
115 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
116 [ # # ]: 0 : if (ctx->common_res[tbl_type].shared_stc[stc_type]) {
117 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type]->refcount++;
118 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
119 : 0 : return 0;
120 : : }
121 : :
122 : : shared_stc = simple_calloc(1, sizeof(*shared_stc));
123 [ # # ]: 0 : if (!shared_stc) {
124 : 0 : DR_LOG(ERR, "Failed to allocate memory for shared STCs");
125 : 0 : rte_errno = ENOMEM;
126 : 0 : goto unlock_and_out;
127 : : }
128 [ # # # ]: 0 : switch (stc_type) {
129 : 0 : case MLX5DR_CONTEXT_SHARED_STC_DECAP_L3:
130 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
131 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
132 : 0 : stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
133 : 0 : stc_attr.remove_header.decap = 0;
134 : 0 : stc_attr.remove_header.start_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
135 : 0 : stc_attr.remove_header.end_anchor = MLX5_HEADER_ANCHOR_IPV6_IPV4;
136 : 0 : break;
137 : 0 : case MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP:
138 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
139 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
140 : 0 : stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
141 : 0 : stc_attr.remove_words.start_anchor = MLX5_HEADER_ANCHOR_FIRST_VLAN_START;
142 : 0 : stc_attr.remove_words.num_of_words = MLX5DR_ACTION_HDR_LEN_L2_VLAN;
143 : 0 : break;
144 : 0 : default:
145 : 0 : DR_LOG(ERR, "No such type : stc_type");
146 : 0 : assert(false);
147 : : rte_errno = EINVAL;
148 : : goto unlock_and_out;
149 : : }
150 : :
151 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
152 : : &shared_stc->remove_header);
153 [ # # ]: 0 : if (ret) {
154 : 0 : DR_LOG(ERR, "Failed to allocate shared decap l2 STC");
155 : 0 : goto free_shared_stc;
156 : : }
157 : :
158 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type] = shared_stc;
159 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type]->refcount = 1;
160 : :
161 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
162 : :
163 : 0 : return 0;
164 : :
165 : : free_shared_stc:
166 : : simple_free(shared_stc);
167 : 0 : unlock_and_out:
168 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
169 : 0 : return rte_errno;
170 : : }
171 : :
172 : 0 : static void mlx5dr_action_put_shared_stc_nic(struct mlx5dr_context *ctx,
173 : : enum mlx5dr_context_shared_stc_type stc_type,
174 : : uint8_t tbl_type)
175 : : {
176 : : struct mlx5dr_action_shared_stc *shared_stc;
177 : :
178 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
179 [ # # ]: 0 : if (--ctx->common_res[tbl_type].shared_stc[stc_type]->refcount) {
180 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
181 : 0 : return;
182 : : }
183 : :
184 : : shared_stc = ctx->common_res[tbl_type].shared_stc[stc_type];
185 : :
186 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &shared_stc->remove_header);
187 : : simple_free(shared_stc);
188 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type] = NULL;
189 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
190 : : }
191 : :
192 : 0 : static int mlx5dr_action_get_shared_stc(struct mlx5dr_action *action,
193 : : enum mlx5dr_context_shared_stc_type stc_type)
194 : : {
195 : 0 : struct mlx5dr_context *ctx = action->ctx;
196 : : int ret;
197 : :
198 [ # # ]: 0 : if (stc_type >= MLX5DR_CONTEXT_SHARED_STC_MAX) {
199 : 0 : assert(false);
200 : : rte_errno = EINVAL;
201 : : return rte_errno;
202 : : }
203 : :
204 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX) {
205 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
206 [ # # ]: 0 : if (ret) {
207 : 0 : DR_LOG(ERR, "Failed to allocate memory for RX shared STCs (type: %d)",
208 : : stc_type);
209 : 0 : return ret;
210 : : }
211 : : }
212 : :
213 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX) {
214 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
215 [ # # ]: 0 : if (ret) {
216 : 0 : DR_LOG(ERR, "Failed to allocate memory for TX shared STCs(type: %d)",
217 : : stc_type);
218 : 0 : goto clean_nic_rx_stc;
219 : : }
220 : : }
221 : :
222 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB) {
223 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
224 [ # # ]: 0 : if (ret) {
225 : 0 : DR_LOG(ERR, "Failed to allocate memory for FDB shared STCs (type: %d)",
226 : : stc_type);
227 : 0 : goto clean_nic_tx_stc;
228 : : }
229 : : }
230 : :
231 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX) {
232 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type,
233 : : MLX5DR_TABLE_TYPE_FDB_RX);
234 [ # # ]: 0 : if (ret) {
235 : 0 : DR_LOG(ERR, "Failed to allocate FDB_RX shared STCs (type: %d)",
236 : : stc_type);
237 : 0 : goto clean_nic_fdb_stc;
238 : : }
239 : : }
240 : :
241 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX) {
242 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type,
243 : : MLX5DR_TABLE_TYPE_FDB_TX);
244 [ # # ]: 0 : if (ret) {
245 : 0 : DR_LOG(ERR, "Failed to allocate FDB_TX shared STCs (type: %d)",
246 : : stc_type);
247 : 0 : goto clean_nic_fdb_rx_stc;
248 : : }
249 : : }
250 : :
251 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) {
252 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type,
253 : : MLX5DR_TABLE_TYPE_FDB_UNIFIED);
254 [ # # ]: 0 : if (ret) {
255 : 0 : DR_LOG(ERR, "Failed to allocate FDB_UNIFIED shared STCs (type: %d)",
256 : : stc_type);
257 : 0 : goto clean_nic_fdb_tx_stc;
258 : : }
259 : : }
260 : :
261 : : return 0;
262 : :
263 : : clean_nic_fdb_tx_stc:
264 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
265 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_TX);
266 : 0 : clean_nic_fdb_rx_stc:
267 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
268 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_RX);
269 : 0 : clean_nic_fdb_stc:
270 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
271 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
272 : 0 : clean_nic_tx_stc:
273 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
274 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
275 : 0 : clean_nic_rx_stc:
276 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
277 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
278 : :
279 : : return ret;
280 : : }
281 : :
282 : 0 : static void mlx5dr_action_put_shared_stc(struct mlx5dr_action *action,
283 : : enum mlx5dr_context_shared_stc_type stc_type)
284 : : {
285 : 0 : struct mlx5dr_context *ctx = action->ctx;
286 : :
287 [ # # ]: 0 : if (stc_type >= MLX5DR_CONTEXT_SHARED_STC_MAX) {
288 : 0 : assert(false);
289 : : return;
290 : : }
291 : :
292 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
293 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
294 : :
295 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
296 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
297 : :
298 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
299 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
300 : :
301 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
302 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_RX);
303 : :
304 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
305 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_TX);
306 : :
307 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)
308 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_UNIFIED);
309 : : }
310 : :
311 : : static void
312 : 0 : mlx5dr_action_create_nat64_zero_all_addr(uint8_t **action_ptr, bool is_v4_to_v6)
313 : : {
314 [ # # ]: 0 : if (is_v4_to_v6) {
315 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
316 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV4);
317 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
318 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
319 : :
320 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
321 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV4);
322 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
323 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
324 : : } else {
325 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
326 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_127_96);
327 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
328 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
329 : :
330 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
331 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_95_64);
332 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
333 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
334 : :
335 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
336 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_63_32);
337 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
338 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
339 : :
340 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
341 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_31_0);
342 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
343 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
344 : :
345 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
346 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_127_96);
347 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
348 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
349 : :
350 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
351 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_95_64);
352 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
353 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
354 : :
355 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
356 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_63_32);
357 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
358 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
359 : :
360 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
361 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_31_0);
362 [ # # ]: 0 : MLX5_SET(set_action_in, *action_ptr, data, 0);
363 : 0 : *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
364 : : }
365 : 0 : }
366 : :
367 : : static struct mlx5dr_action *
368 : 0 : mlx5dr_action_create_nat64_copy_state(struct mlx5dr_context *ctx,
369 : : struct mlx5dr_action_nat64_attr *attr,
370 : : uint32_t flags)
371 : : {
372 : : __be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
373 : : struct mlx5dr_action_mh_pattern pat[2];
374 : : struct mlx5dr_action *action;
375 : : uint32_t packet_len_field;
376 : : uint8_t *action_ptr;
377 : : uint32_t tos_field;
378 : : uint32_t tos_size;
379 : : uint32_t src_addr;
380 : : uint32_t dst_addr;
381 : : bool is_v4_to_v6;
382 : : uint32_t ecn;
383 : :
384 : 0 : is_v4_to_v6 = attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6;
385 : :
386 [ # # ]: 0 : if (is_v4_to_v6) {
387 : : packet_len_field = MLX5_MODI_OUT_IPV4_TOTAL_LEN;
388 : : tos_field = MLX5_MODI_OUT_IP_DSCP;
389 : : tos_size = 6;
390 : : ecn = MLX5_MODI_OUT_IP_ECN;
391 : : src_addr = MLX5_MODI_OUT_SIPV4;
392 : : dst_addr = MLX5_MODI_OUT_DIPV4;
393 : : } else {
394 : : packet_len_field = MLX5_MODI_OUT_IPV6_PAYLOAD_LEN;
395 : : tos_field = MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS;
396 : : tos_size = 8;
397 : : ecn = 0;
398 : : src_addr = MLX5_MODI_OUT_SIPV6_31_0;
399 : : dst_addr = MLX5_MODI_OUT_DIPV6_31_0;
400 : : }
401 : :
402 : : memset(modify_action_data, 0, sizeof(modify_action_data));
403 : 0 : action_ptr = (uint8_t *)modify_action_data;
404 : :
405 [ # # ]: 0 : if (attr->flags & MLX5DR_ACTION_NAT64_BACKUP_ADDR) {
406 : : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
407 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field, src_addr);
408 : 0 : MLX5_SET(copy_action_in, action_ptr, dst_field,
409 : : attr->registers[MLX5DR_ACTION_NAT64_REG_SRC_IP]);
410 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
411 : :
412 : : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
413 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field, dst_addr);
414 : 0 : MLX5_SET(copy_action_in, action_ptr, dst_field,
415 : : attr->registers[MLX5DR_ACTION_NAT64_REG_DST_IP]);
416 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
417 : : }
418 : :
419 : : /* | 8 bit - 8 bit - 16 bit |
420 : : * | TOS - protocol - packet-len |
421 : : */
422 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
423 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field, packet_len_field);
424 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_field,
425 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
426 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_offset, 0);/* 16 bits in the lsb */
427 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, 16);
428 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
429 : :
430 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
431 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
432 : :
433 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
434 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field, MLX5_MODI_OUT_IP_PROTOCOL);
435 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_field,
436 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
437 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_offset, 16);
438 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, 8);
439 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
440 : :
441 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
442 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
443 : :
444 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
445 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field, tos_field);
446 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_field,
447 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
448 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_offset, 24);
449 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, tos_size);
450 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
451 : : /* in ipv4 TOS = {dscp (6bits) - ecn (2bits) }*/
452 [ # # ]: 0 : if (ecn) {
453 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
454 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
455 : :
456 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
457 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field, ecn);
458 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_field,
459 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
460 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_offset, 24 + tos_size);
461 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, MLX5DR_ACTION_NAT64_ECN_SIZE);
462 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
463 : : }
464 : :
465 : : /* set sip and dip to 0, in order to have new csum */
466 : 0 : mlx5dr_action_create_nat64_zero_all_addr(&action_ptr, is_v4_to_v6);
467 : :
468 : 0 : pat[0].data = modify_action_data;
469 : 0 : pat[0].sz = (action_ptr - (uint8_t *)modify_action_data);
470 : :
471 : 0 : action = mlx5dr_action_create_modify_header(ctx, 1, pat, 0, flags);
472 [ # # ]: 0 : if (!action) {
473 : 0 : DR_LOG(ERR, "Failed to create copy for NAT64: action_sz: %zu, flags: 0x%x\n",
474 : : pat[0].sz, flags);
475 : 0 : return NULL;
476 : : }
477 : :
478 : : return action;
479 : : }
480 : :
481 : : static struct mlx5dr_action *
482 : 0 : mlx5dr_action_create_nat64_repalce_state(struct mlx5dr_context *ctx,
483 : : struct mlx5dr_action_nat64_attr *attr,
484 : : uint32_t flags)
485 : : {
486 : 0 : uint32_t address_prefix[MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE] = {0};
487 : : __be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
488 : : struct mlx5dr_action_mh_pattern pat[2];
489 : : static struct mlx5dr_action *action;
490 : : uint8_t header_size_in_dw;
491 : : uint8_t *action_ptr;
492 : : uint32_t eth_type;
493 : : bool is_v4_to_v6;
494 : : uint32_t ip_ver;
495 : : int i;
496 : :
497 : 0 : is_v4_to_v6 = attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6;
498 : :
499 [ # # ]: 0 : if (is_v4_to_v6) {
500 : : uint32_t nat64_well_known_pref[] = {0x00010000,
501 : : 0x9bff6400, 0x0, 0x0, 0x0,
502 : : 0x9bff6400, 0x0, 0x0, 0x0};
503 : :
504 : : header_size_in_dw = MLX5DR_ACTION_NAT64_IPV6_HEADER;
505 : : ip_ver = MLX5DR_ACTION_NAT64_IPV6_VER;
506 : : eth_type = RTE_ETHER_TYPE_IPV6;
507 : : memcpy(address_prefix, nat64_well_known_pref,
508 : : MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE * sizeof(uint32_t));
509 : : } else {
510 : : /* In order to fix HW csum issue, make the prefix ready */
511 : : uint32_t ipv4_pref[] = {0x0, 0xffba0000, 0x0, 0x0, 0x0};
512 : :
513 : : header_size_in_dw = MLX5DR_ACTION_NAT64_IPV4_HEADER;
514 : : ip_ver = MLX5DR_ACTION_NAT64_IPV4_VER;
515 : : eth_type = RTE_ETHER_TYPE_IPV4;
516 : : memcpy(address_prefix, ipv4_pref,
517 : : MLX5DR_ACTION_NAT64_IPV4_HEADER * sizeof(uint32_t));
518 : : }
519 : :
520 : : memset(modify_action_data, 0, sizeof(modify_action_data));
521 : : action_ptr = (uint8_t *)modify_action_data;
522 : :
523 : : MLX5_SET(set_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
524 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, field, MLX5_MODI_OUT_ETHERTYPE);
525 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, length, 16);
526 : 0 : MLX5_SET(set_action_in, action_ptr, data, eth_type);
527 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
528 : :
529 : : /* push empty header with ipv6 as version */
530 : : MLX5_SET(stc_ste_param_insert, action_ptr, action_type,
531 : : MLX5_MODIFICATION_TYPE_INSERT);
532 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, inline_data, 0x1);
533 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, insert_anchor,
534 : : MLX5_HEADER_ANCHOR_IPV6_IPV4);
535 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, insert_size, 2);
536 : 0 : MLX5_SET(stc_ste_param_insert, action_ptr, insert_argument, ip_ver);
537 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
538 : :
539 [ # # ]: 0 : for (i = 0; i < header_size_in_dw - 1; i++) {
540 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, action_type,
541 : : MLX5_MODIFICATION_TYPE_INSERT);
542 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, inline_data, 0x1);
543 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, insert_anchor,
544 : : MLX5_HEADER_ANCHOR_IPV6_IPV4);
545 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, insert_size, 2);
546 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, action_ptr, insert_argument,
547 : : htobe32(address_prefix[i]));
548 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
549 : : }
550 : :
551 : : /* Remove orig src/dst addr (8 bytes, 4 words) */
552 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, action_ptr, action_type,
553 : : MLX5_MODIFICATION_TYPE_REMOVE);
554 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, action_ptr, remove_start_anchor,
555 : : MLX5_HEADER_ANCHOR_IPV6_IPV4);
556 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, action_ptr, remove_end_anchor,
557 : : MLX5_HEADER_ANCHOR_TCP_UDP);
558 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
559 : :
560 : 0 : pat[0].data = modify_action_data;
561 : 0 : pat[0].sz = action_ptr - (uint8_t *)modify_action_data;
562 : :
563 : 0 : action = mlx5dr_action_create_modify_header(ctx, 1, pat, 0, flags);
564 [ # # ]: 0 : if (!action) {
565 : 0 : DR_LOG(ERR, "Failed to create action: action_sz: %zu flags: 0x%x\n",
566 : : pat[0].sz, flags);
567 : 0 : return NULL;
568 : : }
569 : :
570 : : return action;
571 : : }
572 : :
573 : : static struct mlx5dr_action *
574 : 0 : mlx5dr_action_create_nat64_copy_proto_state(struct mlx5dr_context *ctx,
575 : : struct mlx5dr_action_nat64_attr *attr,
576 : : uint32_t flags)
577 : : {
578 : : __be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
579 : : struct mlx5dr_action_mh_pattern pat[2];
580 : : struct mlx5dr_action *action;
581 : : uint8_t *action_ptr;
582 : :
583 : : memset(modify_action_data, 0, sizeof(modify_action_data));
584 : : action_ptr = (uint8_t *)modify_action_data;
585 : :
586 : 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
587 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field,
588 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
589 : : MLX5_SET(copy_action_in, action_ptr, dst_field,
590 : : MLX5_MODI_OUT_IP_PROTOCOL);
591 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_offset, 16);
592 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_offset, 0);
593 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, 8);
594 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
595 : :
596 : 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
597 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
598 : :
599 : 0 : pat[0].data = modify_action_data;
600 : 0 : pat[0].sz = action_ptr - (uint8_t *)modify_action_data;
601 : :
602 : 0 : action = mlx5dr_action_create_modify_header_reparse(ctx, 1, pat, 0, flags,
603 : : MLX5DR_ACTION_STC_REPARSE_ON);
604 [ # # ]: 0 : if (!action) {
605 : 0 : DR_LOG(ERR, "Failed to create action: action_sz: %zu, flags: 0x%x\n",
606 : : pat[0].sz, flags);
607 : 0 : return NULL;
608 : : }
609 : :
610 : : return action;
611 : : }
612 : :
613 : : static struct mlx5dr_action *
614 : 0 : mlx5dr_action_create_nat64_copy_back_state(struct mlx5dr_context *ctx,
615 : : struct mlx5dr_action_nat64_attr *attr,
616 : : uint32_t flags)
617 : : {
618 : : __be64 modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
619 : : struct mlx5dr_action_mh_pattern pat[2];
620 : : struct mlx5dr_action *action;
621 : : uint32_t packet_len_field;
622 : : uint32_t packet_len_add;
623 : : uint8_t *action_ptr;
624 : : uint32_t tos_field;
625 : : uint32_t ttl_field;
626 : : uint32_t tos_size;
627 : : uint32_t src_addr;
628 : : uint32_t dst_addr;
629 : : bool is_v4_to_v6;
630 : : uint32_t ecn;
631 : :
632 : 0 : is_v4_to_v6 = attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6;
633 : :
634 [ # # ]: 0 : if (is_v4_to_v6) {
635 : : packet_len_field = MLX5_MODI_OUT_IPV6_PAYLOAD_LEN;
636 : : /* 2' comp to 20, to get -20 in add operation */
637 : : packet_len_add = MLX5DR_ACTION_NAT64_DEC_20;
638 : : ttl_field = MLX5_MODI_OUT_IPV6_HOPLIMIT;
639 : : src_addr = MLX5_MODI_OUT_SIPV6_31_0;
640 : : dst_addr = MLX5_MODI_OUT_DIPV6_31_0;
641 : : tos_field = MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS;
642 : : tos_size = 8;
643 : : ecn = 0;
644 : : } else {
645 : : packet_len_field = MLX5_MODI_OUT_IPV4_TOTAL_LEN;
646 : : /* ipv4 len is including 20 bytes of the header, so add 20 over ipv6 len */
647 : : packet_len_add = MLX5DR_ACTION_NAT64_ADD_20;
648 : : ttl_field = MLX5_MODI_OUT_IPV4_TTL;
649 : : src_addr = MLX5_MODI_OUT_SIPV4;
650 : : dst_addr = MLX5_MODI_OUT_DIPV4;
651 : : tos_field = MLX5_MODI_OUT_IP_DSCP;
652 : : tos_size = 6;
653 : : ecn = MLX5_MODI_OUT_IP_ECN;
654 : : }
655 : :
656 : : memset(modify_action_data, 0, sizeof(modify_action_data));
657 : : action_ptr = (uint8_t *)modify_action_data;
658 : :
659 : 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
660 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field,
661 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
662 : 0 : MLX5_SET(copy_action_in, action_ptr, dst_field,
663 : : packet_len_field);
664 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_offset, 32);
665 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, 16);
666 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
667 : :
668 : : MLX5_SET(set_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
669 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, field, ttl_field);
670 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, length, 8);
671 : 0 : MLX5_SET(set_action_in, action_ptr, data, MLX5DR_ACTION_NAT64_TTL_DEFAULT_VAL);
672 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
673 : :
674 : : /* copy TOS */
675 : 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
676 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field,
677 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
678 : 0 : MLX5_SET(copy_action_in, action_ptr, dst_field, tos_field);
679 [ # # # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_offset, 24 + (ecn ?
680 : : MLX5DR_ACTION_NAT64_ECN_SIZE : 0));
681 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, tos_size);
682 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
683 : :
684 [ # # ]: 0 : if (ecn) {
685 : 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
686 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
687 : :
688 : 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
689 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field,
690 : : attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
691 : 0 : MLX5_SET(copy_action_in, action_ptr, dst_field, ecn);
692 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_offset, 24);
693 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, MLX5DR_ACTION_NAT64_ECN_SIZE);
694 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
695 : : }
696 : :
697 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
698 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
699 : :
700 : : /* if required Copy original addresses */
701 [ # # ]: 0 : if (attr->flags & MLX5DR_ACTION_NAT64_BACKUP_ADDR) {
702 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
703 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field,
704 : : attr->registers[MLX5DR_ACTION_NAT64_REG_SRC_IP]);
705 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_field, src_addr);
706 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_offset, 0);
707 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, 32);
708 : : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
709 : :
710 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
711 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_field,
712 : : attr->registers[MLX5DR_ACTION_NAT64_REG_DST_IP]);
713 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, dst_field, dst_addr);
714 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, src_offset, 0);
715 [ # # ]: 0 : MLX5_SET(copy_action_in, action_ptr, length, 32);
716 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
717 : : }
718 : :
719 : : /* take/add off 20 bytes ipv4/6 from/to the total size */
720 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_ADD);
721 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, field, packet_len_field);
722 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, data, packet_len_add);
723 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, length, 16);
724 : 0 : action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
725 : :
726 : 0 : pat[0].data = modify_action_data;
727 : 0 : pat[0].sz = action_ptr - (uint8_t *)modify_action_data;
728 : :
729 : 0 : action = mlx5dr_action_create_modify_header(ctx, 1, pat, 0, flags);
730 [ # # ]: 0 : if (!action) {
731 : 0 : DR_LOG(ERR, "Failed to create action: action_sz: %zu, flags: 0x%x\n",
732 : : pat[0].sz, flags);
733 : 0 : return NULL;
734 : : }
735 : :
736 : : return action;
737 : : }
738 : :
739 : 0 : static void mlx5dr_action_print_combo(enum mlx5dr_action_type *user_actions)
740 : : {
741 : 0 : DR_LOG(ERR, "Invalid action_type sequence");
742 [ # # ]: 0 : while (*user_actions != MLX5DR_ACTION_TYP_LAST) {
743 : 0 : DR_LOG(ERR, "%s", mlx5dr_debug_action_type_to_str(*user_actions));
744 : 0 : user_actions++;
745 : : }
746 : 0 : }
747 : :
748 : : static const uint32_t *
749 : 0 : mlx5dr_action_get_order_entry(enum mlx5dr_table_type table_type)
750 : : {
751 [ # # # # ]: 0 : switch (table_type) {
752 : : case MLX5DR_TABLE_TYPE_NIC_RX:
753 : : return action_order_arr[MLX5DR_TABLE_TYPE_NIC_RX];
754 : 0 : case MLX5DR_TABLE_TYPE_NIC_TX:
755 : 0 : return action_order_arr[MLX5DR_TABLE_TYPE_NIC_TX];
756 : 0 : case MLX5DR_TABLE_TYPE_FDB:
757 : : case MLX5DR_TABLE_TYPE_FDB_RX:
758 : : case MLX5DR_TABLE_TYPE_FDB_TX:
759 : : case MLX5DR_TABLE_TYPE_FDB_UNIFIED:
760 : 0 : return action_order_arr[MLX5DR_TABLE_TYPE_FDB];
761 : 0 : default:
762 : 0 : assert(0);
763 : : DR_LOG(ERR, "no such type: %d", table_type);
764 : : return NULL;
765 : : }
766 : : }
767 : :
768 : 0 : bool mlx5dr_action_check_combo(enum mlx5dr_action_type *user_actions,
769 : : enum mlx5dr_table_type table_type)
770 : : {
771 : 0 : const uint32_t *order_arr = mlx5dr_action_get_order_entry(table_type);
772 : : uint8_t order_idx = 0;
773 : : uint8_t user_idx = 0;
774 : : bool valid_combo;
775 : :
776 [ # # ]: 0 : if (!order_arr)
777 : : return false;
778 : :
779 [ # # ]: 0 : while (order_arr[order_idx] != BIT(MLX5DR_ACTION_TYP_LAST)) {
780 : : /* User action order validated move to next user action */
781 [ # # ]: 0 : if (BIT(user_actions[user_idx]) & order_arr[order_idx])
782 : 0 : user_idx++;
783 : :
784 : : /* Iterate to the next supported action in the order */
785 : 0 : order_idx++;
786 : : }
787 : :
788 : : /* Combination is valid if all user action were processed */
789 : 0 : valid_combo = user_actions[user_idx] == MLX5DR_ACTION_TYP_LAST;
790 [ # # ]: 0 : if (!valid_combo)
791 : 0 : mlx5dr_action_print_combo(user_actions);
792 : :
793 : : return valid_combo;
794 : : }
795 : :
796 : 0 : int mlx5dr_action_root_build_attr(struct mlx5dr_rule_action rule_actions[],
797 : : uint32_t num_actions,
798 : : struct mlx5dv_flow_action_attr *attr)
799 : : {
800 : : struct mlx5dr_action *action;
801 : : uint32_t i;
802 : :
803 [ # # ]: 0 : for (i = 0; i < num_actions; i++) {
804 : 0 : action = rule_actions[i].action;
805 : :
806 [ # # # # : 0 : switch (action->type) {
# # # # ]
807 : 0 : case MLX5DR_ACTION_TYP_TBL:
808 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_DEST_DEVX;
809 : 0 : attr[i].obj = action->dest_tbl.devx_obj->obj;
810 : 0 : break;
811 : 0 : case MLX5DR_ACTION_TYP_TIR:
812 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_DEST_DEVX;
813 : 0 : attr[i].obj = action->devx_obj;
814 : 0 : break;
815 : 0 : case MLX5DR_ACTION_TYP_TAG:
816 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_TAG;
817 : 0 : attr[i].tag_value = rule_actions[i].tag.value;
818 : 0 : break;
819 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS
820 : 0 : case MLX5DR_ACTION_TYP_MISS:
821 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_DEFAULT_MISS;
822 : 0 : break;
823 : : #endif
824 : 0 : case MLX5DR_ACTION_TYP_DROP:
825 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_DROP;
826 : 0 : break;
827 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
828 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
829 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
830 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
831 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
832 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
833 : 0 : attr[i].action = action->flow_action;
834 : 0 : break;
835 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
836 : 0 : case MLX5DR_ACTION_TYP_CTR:
837 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
838 : 0 : attr[i].obj = action->devx_obj;
839 : :
840 [ # # ]: 0 : if (rule_actions[i].counter.offset) {
841 : 0 : DR_LOG(ERR, "Counter offset not supported over root");
842 : 0 : rte_errno = ENOTSUP;
843 : 0 : return rte_errno;
844 : : }
845 : : break;
846 : : #endif
847 : 0 : default:
848 : 0 : DR_LOG(ERR, "Found unsupported action type: %d", action->type);
849 : 0 : rte_errno = ENOTSUP;
850 : 0 : return rte_errno;
851 : : }
852 : : }
853 : :
854 : : return 0;
855 : : }
856 : :
857 : : static bool
858 : 0 : mlx5dr_action_fixup_stc_attr(struct mlx5dr_context *ctx,
859 : : struct mlx5dr_cmd_stc_modify_attr *stc_attr,
860 : : struct mlx5dr_cmd_stc_modify_attr *fixup_stc_attr,
861 : : enum mlx5dr_table_type table_type,
862 : : bool is_mirror)
863 : : {
864 : : struct mlx5dr_devx_obj *devx_obj;
865 : : bool use_fixup = false;
866 : : uint32_t fw_tbl_type;
867 : :
868 : 0 : fw_tbl_type = mlx5dr_table_get_res_fw_ft_type(table_type, is_mirror);
869 : :
870 [ # # # # : 0 : switch (stc_attr->action_type) {
# # ]
871 : 0 : case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_STE_TABLE:
872 : 0 : devx_obj = mlx5dr_action_get_stc_obj_by_tbl_type(table_type,
873 : : stc_attr->ste_table.ste_pool,
874 : : &stc_attr->ste_table.ste,
875 : : is_mirror);
876 : :
877 : 0 : *fixup_stc_attr = *stc_attr;
878 : 0 : fixup_stc_attr->ste_table.ste_obj_id = devx_obj->id;
879 : : use_fixup = true;
880 : 0 : break;
881 : :
882 : 0 : case MLX5_IFC_STC_ACTION_TYPE_TAG:
883 [ # # ]: 0 : if (fw_tbl_type == FS_FT_FDB_TX) {
884 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_NOP;
885 : 0 : fixup_stc_attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
886 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
887 : : use_fixup = true;
888 : : }
889 : : break;
890 : :
891 : : case MLX5_IFC_STC_ACTION_TYPE_ALLOW:
892 : : if (mlx5dr_table_is_fw_fdb_any(fw_tbl_type)) {
893 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT;
894 : 0 : fixup_stc_attr->action_offset = stc_attr->action_offset;
895 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
896 : 0 : fixup_stc_attr->vport.esw_owner_vhca_id = ctx->caps->vhca_id;
897 : 0 : fixup_stc_attr->vport.vport_num = ctx->caps->eswitch_manager_vport_number;
898 : 0 : fixup_stc_attr->vport.eswitch_owner_vhca_id_valid =
899 : 0 : ctx->caps->merged_eswitch;
900 : : use_fixup = true;
901 : : }
902 : : break;
903 : :
904 : 0 : case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT:
905 [ # # ]: 0 : if (stc_attr->vport.vport_num != WIRE_PORT)
906 : : break;
907 : :
908 : : if (mlx5dr_table_is_fw_fdb_any(fw_tbl_type)) {
909 : : /* The FW doesn't allow to go to wire in the TX/RX by JUMP_TO_VPORT */
910 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_UPLINK;
911 : 0 : fixup_stc_attr->action_offset = stc_attr->action_offset;
912 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
913 : 0 : fixup_stc_attr->vport.vport_num = 0;
914 : 0 : fixup_stc_attr->vport.esw_owner_vhca_id = stc_attr->vport.esw_owner_vhca_id;
915 : 0 : fixup_stc_attr->vport.eswitch_owner_vhca_id_valid =
916 : 0 : stc_attr->vport.eswitch_owner_vhca_id_valid;
917 : : }
918 : : use_fixup = true;
919 : : break;
920 : 0 : case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_TIR:
921 : : /* TIR is allowed on RX side, requires mask in case of FDB */
922 [ # # ]: 0 : if (fw_tbl_type == FS_FT_FDB_TX) {
923 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
924 : 0 : fixup_stc_attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
925 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
926 : : use_fixup = true;
927 : : }
928 : : break;
929 : : default:
930 : : break;
931 : : }
932 : :
933 : 0 : return use_fixup;
934 : : }
935 : :
936 : : static struct mlx5dr_devx_obj *
937 : : mlx5dr_action_get_stc_obj_by_tbl_type(enum mlx5dr_table_type table_type,
938 : : struct mlx5dr_pool *stc_pool,
939 : : struct mlx5dr_pool_chunk *stc,
940 : : bool is_mirror)
941 : : {
942 [ # # # # ]: 0 : if (table_type == MLX5DR_TABLE_TYPE_FDB_TX ||
943 [ # # ]: 0 : (is_mirror && table_type == MLX5DR_TABLE_TYPE_FDB)) /* Optimized ORIG in FDB_TX */
944 : 0 : return mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
945 : : else
946 : 0 : return mlx5dr_pool_chunk_get_base_devx_obj(stc_pool, stc);
947 : : }
948 : :
949 : 0 : int mlx5dr_action_alloc_single_stc(struct mlx5dr_context *ctx,
950 : : struct mlx5dr_cmd_stc_modify_attr *stc_attr,
951 : : uint32_t table_type,
952 : : struct mlx5dr_pool_chunk *stc)
953 : : {
954 : 0 : struct mlx5dr_cmd_stc_modify_attr cleanup_stc_attr = {0};
955 : 0 : struct mlx5dr_pool *stc_pool = ctx->stc_pool[table_type];
956 : 0 : struct mlx5dr_cmd_stc_modify_attr fixup_stc_attr = {0};
957 : : struct mlx5dr_devx_obj *devx_obj_0;
958 : : enum mlx5dr_table_type type;
959 : : bool use_fixup;
960 : : int ret;
961 : :
962 : 0 : ret = mlx5dr_pool_chunk_alloc(stc_pool, stc);
963 [ # # ]: 0 : if (ret) {
964 : 0 : DR_LOG(ERR, "Failed to allocate single action STC");
965 : 0 : return ret;
966 : : }
967 : :
968 : 0 : stc_attr->stc_offset = stc->offset;
969 : :
970 : : /* Dynamic reparse not supported, overwrite and use default */
971 [ # # ]: 0 : if (!mlx5dr_context_cap_dynamic_reparse(ctx))
972 : 0 : stc_attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
973 : :
974 : : type = (enum mlx5dr_table_type)table_type;
975 : : devx_obj_0 = mlx5dr_action_get_stc_obj_by_tbl_type(type, stc_pool, stc, false);
976 : :
977 : : /* According to table/action limitation change the stc_attr */
978 : 0 : use_fixup = mlx5dr_action_fixup_stc_attr(ctx, stc_attr, &fixup_stc_attr,
979 : : (enum mlx5dr_table_type)table_type,
980 : : (table_type == MLX5DR_TABLE_TYPE_FDB_TX));
981 [ # # ]: 0 : ret = mlx5dr_cmd_stc_modify(devx_obj_0, use_fixup ? &fixup_stc_attr : stc_attr);
982 [ # # ]: 0 : if (ret) {
983 : 0 : DR_LOG(ERR, "Failed to modify STC action_type %d tbl_type %d",
984 : : stc_attr->action_type, table_type);
985 : 0 : goto free_chunk;
986 : : }
987 : :
988 : : /* Modify the FDB peer */
989 [ # # ]: 0 : if (table_type == MLX5DR_TABLE_TYPE_FDB) {
990 : : struct mlx5dr_devx_obj *devx_obj_1;
991 : :
992 : : devx_obj_1 = mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
993 : :
994 : 0 : use_fixup = mlx5dr_action_fixup_stc_attr(ctx, stc_attr,
995 : : &fixup_stc_attr,
996 : : table_type, true);
997 [ # # ]: 0 : ret = mlx5dr_cmd_stc_modify(devx_obj_1, use_fixup ? &fixup_stc_attr : stc_attr);
998 [ # # ]: 0 : if (ret) {
999 : 0 : DR_LOG(ERR, "Failed to modify peer STC action_type %d tbl_type %d",
1000 : : stc_attr->action_type, table_type);
1001 : 0 : goto clean_devx_obj_0;
1002 : : }
1003 : : }
1004 : :
1005 : : return 0;
1006 : :
1007 : : clean_devx_obj_0:
1008 : 0 : cleanup_stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
1009 : 0 : cleanup_stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
1010 : 0 : cleanup_stc_attr.stc_offset = stc->offset;
1011 : 0 : mlx5dr_cmd_stc_modify(devx_obj_0, &cleanup_stc_attr);
1012 : 0 : free_chunk:
1013 : 0 : mlx5dr_pool_chunk_free(stc_pool, stc);
1014 : 0 : return rte_errno;
1015 : : }
1016 : :
1017 : 0 : void mlx5dr_action_free_single_stc(struct mlx5dr_context *ctx,
1018 : : uint32_t table_type,
1019 : : struct mlx5dr_pool_chunk *stc)
1020 : : {
1021 : 0 : struct mlx5dr_pool *stc_pool = ctx->stc_pool[table_type];
1022 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
1023 : : struct mlx5dr_devx_obj *devx_obj;
1024 : : enum mlx5dr_table_type type;
1025 : :
1026 : : /* Modify the STC not to point to an object */
1027 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
1028 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
1029 [ # # ]: 0 : stc_attr.stc_offset = stc->offset;
1030 : : type = (enum mlx5dr_table_type)table_type;
1031 : : devx_obj = mlx5dr_action_get_stc_obj_by_tbl_type(type, stc_pool, stc, false);
1032 : :
1033 : 0 : mlx5dr_cmd_stc_modify(devx_obj, &stc_attr);
1034 : :
1035 [ # # ]: 0 : if (table_type == MLX5DR_TABLE_TYPE_FDB) {
1036 : : devx_obj = mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
1037 : 0 : mlx5dr_cmd_stc_modify(devx_obj, &stc_attr);
1038 : : }
1039 : :
1040 : 0 : mlx5dr_pool_chunk_free(stc_pool, stc);
1041 : 0 : }
1042 : :
1043 : 0 : static uint32_t mlx5dr_action_get_mh_stc_type(__be64 pattern)
1044 : : {
1045 [ # # ]: 0 : uint8_t action_type = MLX5_GET(set_action_in, &pattern, action_type);
1046 : :
1047 [ # # # # : 0 : switch (action_type) {
# ]
1048 : : case MLX5_MODIFICATION_TYPE_SET:
1049 : : return MLX5_IFC_STC_ACTION_TYPE_SET;
1050 : 0 : case MLX5_MODIFICATION_TYPE_ADD:
1051 : 0 : return MLX5_IFC_STC_ACTION_TYPE_ADD;
1052 : 0 : case MLX5_MODIFICATION_TYPE_COPY:
1053 : 0 : return MLX5_IFC_STC_ACTION_TYPE_COPY;
1054 : 0 : case MLX5_MODIFICATION_TYPE_ADD_FIELD:
1055 : 0 : return MLX5_IFC_STC_ACTION_TYPE_ADD_FIELD;
1056 : 0 : default:
1057 : 0 : assert(false);
1058 : : DR_LOG(ERR, "Unsupported action type: 0x%x", action_type);
1059 : : rte_errno = ENOTSUP;
1060 : : return MLX5_IFC_STC_ACTION_TYPE_NOP;
1061 : : }
1062 : : }
1063 : :
1064 : 0 : static void mlx5dr_action_fill_stc_attr(struct mlx5dr_action *action,
1065 : : struct mlx5dr_devx_obj *obj,
1066 : : struct mlx5dr_cmd_stc_modify_attr *attr)
1067 : : {
1068 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
1069 : :
1070 [ # # # # : 0 : switch (action->type) {
# # # # #
# # # # #
# # # #
# ]
1071 : 0 : case MLX5DR_ACTION_TYP_TAG:
1072 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_TAG;
1073 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
1074 : 0 : break;
1075 : 0 : case MLX5DR_ACTION_TYP_DROP:
1076 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
1077 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1078 : 0 : break;
1079 : 0 : case MLX5DR_ACTION_TYP_MISS:
1080 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
1081 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1082 : 0 : break;
1083 : 0 : case MLX5DR_ACTION_TYP_CTR:
1084 : 0 : attr->id = obj->id;
1085 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_COUNTER;
1086 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW0;
1087 : 0 : break;
1088 : 0 : case MLX5DR_ACTION_TYP_TIR:
1089 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_TIR;
1090 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1091 : 0 : attr->dest_tir_num = obj->id;
1092 : 0 : break;
1093 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
1094 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
1095 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
1096 : : attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
1097 [ # # ]: 0 : if (action->modify_header.require_reparse)
1098 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
1099 : :
1100 [ # # ]: 0 : if (action->modify_header.num_of_actions == 1) {
1101 : 0 : attr->modify_action.data = action->modify_header.single_action;
1102 : 0 : attr->action_type = mlx5dr_action_get_mh_stc_type(attr->modify_action.data);
1103 : :
1104 [ # # ]: 0 : if (attr->action_type == MLX5_IFC_STC_ACTION_TYPE_ADD ||
1105 : : attr->action_type == MLX5_IFC_STC_ACTION_TYPE_SET)
1106 [ # # ]: 0 : MLX5_SET(set_action_in, &attr->modify_action.data, data, 0);
1107 : : } else {
1108 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ACC_MODIFY_LIST;
1109 : 0 : attr->modify_header.arg_id = action->modify_header.arg_obj->id;
1110 : 0 : attr->modify_header.pattern_id = action->modify_header.pat_obj->id;
1111 : : }
1112 : : break;
1113 : 0 : case MLX5DR_ACTION_TYP_TBL:
1114 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1115 : 0 : attr->dest_table_id = obj->id;
1116 : : /* Only for unified FDB Rx case */
1117 [ # # ]: 0 : if (mlx5dr_context_cap_stc(action->ctx,
1118 : 0 : MLX5_IFC_STC_ACTION_TYPE_JUMP_FLOW_TABLE_FDB_RX_BIT_INDEX) &&
1119 [ # # ]: 0 : action->dest_tbl.type == MLX5DR_TABLE_TYPE_FDB_RX)
1120 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FLOW_TABLE_FDB_RX;
1121 : : else
1122 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
1123 : :
1124 : : break;
1125 : 0 : case MLX5DR_ACTION_TYP_DEST_ARRAY:
1126 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
1127 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1128 : 0 : attr->dest_table_id = obj->id;
1129 : 0 : break;
1130 : 0 : case MLX5DR_ACTION_TYP_DEST_ROOT:
1131 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
1132 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1133 : 0 : attr->dest_table_id = action->root_tbl.sa->id;
1134 : 0 : break;
1135 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
1136 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
1137 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
1138 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
1139 : 0 : attr->remove_header.decap = 1;
1140 : 0 : attr->remove_header.start_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
1141 : 0 : attr->remove_header.end_anchor = MLX5_HEADER_ANCHOR_INNER_MAC;
1142 : 0 : break;
1143 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
1144 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
1145 : : case MLX5DR_ACTION_TYP_INSERT_HEADER:
1146 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
1147 [ # # ]: 0 : if (!action->reformat.require_reparse)
1148 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
1149 : :
1150 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_INSERT;
1151 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
1152 : 0 : attr->insert_header.encap = action->reformat.encap;
1153 : 0 : attr->insert_header.push_esp = action->reformat.push_esp;
1154 : 0 : attr->insert_header.insert_anchor = action->reformat.anchor;
1155 : 0 : attr->insert_header.arg_id = action->reformat.arg_obj->id;
1156 : 0 : attr->insert_header.header_size = action->reformat.header_size;
1157 : 0 : attr->insert_header.insert_offset = action->reformat.offset;
1158 : 0 : break;
1159 : 0 : case MLX5DR_ACTION_TYP_ASO_METER:
1160 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
1161 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ASO;
1162 : 0 : attr->aso.aso_type = ASO_OPC_MOD_POLICER;
1163 : 0 : attr->aso.devx_obj_id = obj->id;
1164 : 0 : attr->aso.return_reg_id = action->aso.return_reg_id;
1165 : 0 : break;
1166 : 0 : case MLX5DR_ACTION_TYP_ASO_CT:
1167 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
1168 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ASO;
1169 : 0 : attr->aso.aso_type = ASO_OPC_MOD_CONNECTION_TRACKING;
1170 : 0 : attr->aso.devx_obj_id = obj->id;
1171 : 0 : attr->aso.return_reg_id = action->aso.return_reg_id;
1172 : 0 : break;
1173 : 0 : case MLX5DR_ACTION_TYP_VPORT:
1174 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1175 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT;
1176 : 0 : attr->vport.vport_num = action->vport.vport_num;
1177 : 0 : attr->vport.esw_owner_vhca_id = action->vport.esw_owner_vhca_id;
1178 : 0 : attr->vport.eswitch_owner_vhca_id_valid = action->ctx->caps->merged_eswitch;
1179 : 0 : break;
1180 : 0 : case MLX5DR_ACTION_TYP_POP_VLAN:
1181 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
1182 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
1183 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
1184 : 0 : attr->remove_words.start_anchor = MLX5_HEADER_ANCHOR_FIRST_VLAN_START;
1185 : 0 : attr->remove_words.num_of_words = MLX5DR_ACTION_HDR_LEN_L2_VLAN / 2;
1186 : 0 : break;
1187 : 0 : case MLX5DR_ACTION_TYP_PUSH_VLAN:
1188 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_INSERT;
1189 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
1190 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
1191 : 0 : attr->insert_header.encap = 0;
1192 : 0 : attr->insert_header.push_esp = 0;
1193 : 0 : attr->insert_header.is_inline = 1;
1194 : 0 : attr->insert_header.insert_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
1195 : 0 : attr->insert_header.insert_offset = MLX5DR_ACTION_HDR_LEN_L2_MACS;
1196 : 0 : attr->insert_header.header_size = MLX5DR_ACTION_HDR_LEN_L2_VLAN;
1197 : 0 : break;
1198 : 0 : case MLX5DR_ACTION_TYP_REMOVE_HEADER:
1199 [ # # ]: 0 : if (action->remove_header.type == MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER) {
1200 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
1201 : 0 : attr->remove_header.decap = action->remove_header.decap;
1202 : 0 : attr->remove_header.start_anchor = action->remove_header.start_anchor;
1203 : 0 : attr->remove_header.end_anchor = action->remove_header.end_anchor;
1204 : : } else {
1205 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
1206 : 0 : attr->remove_words.start_anchor = action->remove_header.start_anchor;
1207 : 0 : attr->remove_words.num_of_words = action->remove_header.num_of_words;
1208 : : }
1209 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
1210 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
1211 : 0 : break;
1212 : 0 : case MLX5DR_ACTION_TYP_JUMP_TO_MATCHER:
1213 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_STE_TABLE;
1214 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
1215 : 0 : attr->ste_table.ste = action->jump_to_matcher.matcher->match_ste.ste;
1216 : 0 : attr->ste_table.ste_pool = action->jump_to_matcher.matcher->match_ste.pool;
1217 : 0 : attr->ste_table.match_definer_id = action->ctx->caps->trivial_match_definer;
1218 : 0 : break;
1219 : 0 : default:
1220 : 0 : DR_LOG(ERR, "Invalid action type %d", action->type);
1221 : 0 : assert(false);
1222 : : }
1223 : 0 : }
1224 : :
1225 : : static int
1226 : 0 : mlx5dr_action_create_stcs(struct mlx5dr_action *action,
1227 : : struct mlx5dr_devx_obj *obj)
1228 : : {
1229 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
1230 : 0 : struct mlx5dr_context *ctx = action->ctx;
1231 : : int ret;
1232 : :
1233 : 0 : mlx5dr_action_fill_stc_attr(action, obj, &stc_attr);
1234 : :
1235 : : /* Block unsupported parallel devx obj modify over the same base */
1236 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
1237 : :
1238 : : /* Allocate STC for RX */
1239 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX) {
1240 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
1241 : : MLX5DR_TABLE_TYPE_NIC_RX,
1242 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
1243 [ # # ]: 0 : if (ret)
1244 : 0 : goto out_err;
1245 : : }
1246 : :
1247 : : /* Allocate STC for TX */
1248 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX) {
1249 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
1250 : : MLX5DR_TABLE_TYPE_NIC_TX,
1251 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
1252 [ # # ]: 0 : if (ret)
1253 : 0 : goto free_stcs_rx;
1254 : : }
1255 : :
1256 : : /* Allocate STC for FDB */
1257 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB) {
1258 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
1259 : : MLX5DR_TABLE_TYPE_FDB,
1260 : : &action->stc[MLX5DR_TABLE_TYPE_FDB]);
1261 [ # # ]: 0 : if (ret)
1262 : 0 : goto free_stcs_tx;
1263 : : }
1264 : :
1265 : : /* Allocate STC for FDB-RX */
1266 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX) {
1267 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
1268 : : MLX5DR_TABLE_TYPE_FDB_RX,
1269 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_RX]);
1270 [ # # ]: 0 : if (ret)
1271 : 0 : goto free_stcs_fdb;
1272 : : }
1273 : :
1274 : : /* Allocate STC for FDB-TX */
1275 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX) {
1276 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
1277 : : MLX5DR_TABLE_TYPE_FDB_TX,
1278 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_TX]);
1279 [ # # ]: 0 : if (ret)
1280 : 0 : goto free_stcs_fdb_rx;
1281 : : }
1282 : :
1283 : : /* Allocate STC for FDB Unified */
1284 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) {
1285 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
1286 : : MLX5DR_TABLE_TYPE_FDB_UNIFIED,
1287 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_UNIFIED]);
1288 [ # # ]: 0 : if (ret)
1289 : 0 : goto free_stcs_fdb_tx;
1290 : : }
1291 : :
1292 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
1293 : :
1294 : 0 : return 0;
1295 : :
1296 : : free_stcs_fdb_tx:
1297 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
1298 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_TX,
1299 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_TX]);
1300 : 0 : free_stcs_fdb_rx:
1301 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
1302 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_RX,
1303 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_RX]);
1304 : 0 : free_stcs_fdb:
1305 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
1306 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB,
1307 : : &action->stc[MLX5DR_TABLE_TYPE_FDB]);
1308 : 0 : free_stcs_tx:
1309 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
1310 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_TX,
1311 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
1312 : 0 : free_stcs_rx:
1313 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
1314 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_RX,
1315 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
1316 : 0 : out_err:
1317 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
1318 : 0 : return rte_errno;
1319 : : }
1320 : :
1321 : : static void
1322 : 0 : mlx5dr_action_destroy_stcs(struct mlx5dr_action *action)
1323 : : {
1324 : 0 : struct mlx5dr_context *ctx = action->ctx;
1325 : :
1326 : : /* Block unsupported parallel devx obj modify over the same base */
1327 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
1328 : :
1329 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
1330 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_RX,
1331 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
1332 : :
1333 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
1334 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_TX,
1335 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
1336 : :
1337 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
1338 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB,
1339 : : &action->stc[MLX5DR_TABLE_TYPE_FDB]);
1340 : :
1341 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
1342 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_RX,
1343 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_RX]);
1344 : :
1345 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
1346 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_TX,
1347 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_TX]);
1348 : :
1349 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)
1350 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_UNIFIED,
1351 : : &action->stc[MLX5DR_TABLE_TYPE_FDB_UNIFIED]);
1352 : :
1353 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
1354 : 0 : }
1355 : :
1356 : : static bool
1357 : : mlx5dr_action_is_root_flags(uint32_t flags)
1358 : : {
1359 : 0 : return flags & (MLX5DR_ACTION_FLAG_ROOT_RX |
1360 : : MLX5DR_ACTION_FLAG_ROOT_TX |
1361 : : MLX5DR_ACTION_FLAG_ROOT_FDB);
1362 : : }
1363 : :
1364 : : static bool
1365 : : mlx5dr_action_is_hws_flags(uint32_t flags)
1366 : : {
1367 : 0 : return flags & (MLX5DR_ACTION_FLAG_HWS_RX |
1368 : : MLX5DR_ACTION_FLAG_HWS_TX |
1369 : : MLX5DR_ACTION_FLAG_HWS_FDB |
1370 : : MLX5DR_ACTION_FLAG_HWS_FDB_RX |
1371 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
1372 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED);
1373 : : }
1374 : :
1375 : : static struct mlx5dr_action *
1376 : 0 : mlx5dr_action_create_generic_bulk(struct mlx5dr_context *ctx,
1377 : : uint32_t flags,
1378 : : enum mlx5dr_action_type action_type,
1379 : : uint8_t bulk_sz)
1380 : : {
1381 : : struct mlx5dr_action *action;
1382 : : int i;
1383 : :
1384 [ # # # # ]: 0 : if (!mlx5dr_action_is_root_flags(flags) &&
1385 : : !mlx5dr_action_is_hws_flags(flags)) {
1386 : 0 : DR_LOG(ERR, "Action flags must specify root or non root (HWS)");
1387 : 0 : rte_errno = ENOTSUP;
1388 : 0 : return NULL;
1389 : : }
1390 : :
1391 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
1392 [ # # ]: 0 : !(ctx->flags & MLX5DR_CONTEXT_FLAG_HWS_SUPPORT)) {
1393 : 0 : DR_LOG(ERR, "Cannot create HWS action since HWS is not supported");
1394 : 0 : rte_errno = ENOTSUP;
1395 : 0 : return NULL;
1396 : : }
1397 : :
1398 : 0 : action = simple_calloc(bulk_sz, sizeof(*action));
1399 [ # # ]: 0 : if (!action) {
1400 : 0 : DR_LOG(ERR, "Failed to allocate memory for action [%d]", action_type);
1401 : 0 : rte_errno = ENOMEM;
1402 : 0 : return NULL;
1403 : : }
1404 : :
1405 [ # # ]: 0 : for (i = 0; i < bulk_sz; i++) {
1406 : 0 : action[i].ctx = ctx;
1407 : 0 : action[i].flags = flags;
1408 : 0 : action[i].type = action_type;
1409 : : }
1410 : :
1411 : : return action;
1412 : : }
1413 : :
1414 : : static struct mlx5dr_action *
1415 : : mlx5dr_action_create_generic(struct mlx5dr_context *ctx,
1416 : : uint32_t flags,
1417 : : enum mlx5dr_action_type action_type)
1418 : : {
1419 : 0 : return mlx5dr_action_create_generic_bulk(ctx, flags, action_type, 1);
1420 : : }
1421 : :
1422 : : struct mlx5dr_action *
1423 [ # # ]: 0 : mlx5dr_action_create_dest_table(struct mlx5dr_context *ctx,
1424 : : struct mlx5dr_table *tbl,
1425 : : uint32_t flags)
1426 : : {
1427 : : struct mlx5dr_action *action;
1428 : : int ret;
1429 : :
1430 [ # # ]: 0 : if (mlx5dr_table_is_root(tbl)) {
1431 : 0 : DR_LOG(ERR, "Root table cannot be set as destination");
1432 : 0 : rte_errno = ENOTSUP;
1433 : 0 : return NULL;
1434 : : }
1435 : :
1436 [ # # # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
1437 : : mlx5dr_action_is_root_flags(flags)) {
1438 : 0 : DR_LOG(ERR, "Same action cannot be used for root and non root");
1439 : 0 : rte_errno = ENOTSUP;
1440 : 0 : return NULL;
1441 : : }
1442 : :
1443 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TBL);
1444 [ # # ]: 0 : if (!action)
1445 : : return NULL;
1446 : :
1447 : 0 : action->dest_tbl.type = tbl->type;
1448 : :
1449 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1450 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx))
1451 : 0 : action->dest_tbl.devx_obj = tbl->local_ft;
1452 : : else
1453 : 0 : action->dest_tbl.devx_obj = tbl->ft;
1454 : : } else {
1455 : 0 : action->dest_tbl.devx_obj = tbl->ft;
1456 : :
1457 : 0 : ret = mlx5dr_action_create_stcs(action, tbl->ft);
1458 [ # # ]: 0 : if (ret)
1459 : 0 : goto free_action;
1460 : : }
1461 : :
1462 : : return action;
1463 : :
1464 : : free_action:
1465 : : simple_free(action);
1466 : 0 : return NULL;
1467 : : }
1468 : :
1469 [ # # ]: 0 : static int mlx5dr_action_get_dest_tir_obj(struct mlx5dr_context *ctx,
1470 : : struct mlx5dr_action *action,
1471 : : struct mlx5dr_devx_obj *obj,
1472 : : struct mlx5dr_devx_obj **ret_obj)
1473 : : {
1474 : : int ret;
1475 : :
1476 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx)) {
1477 : 0 : ret = mlx5dr_matcher_create_aliased_obj(ctx,
1478 : : ctx->local_ibv_ctx,
1479 : : ctx->ibv_ctx,
1480 : 0 : ctx->caps->vhca_id,
1481 : : obj->id,
1482 : : MLX5_GENERAL_OBJ_TYPE_TIR_ALIAS,
1483 : : &action->alias.devx_obj);
1484 [ # # ]: 0 : if (ret) {
1485 : 0 : DR_LOG(ERR, "Failed to create tir alias");
1486 : 0 : return rte_errno;
1487 : : }
1488 : 0 : *ret_obj = action->alias.devx_obj;
1489 : : } else {
1490 : 0 : *ret_obj = obj;
1491 : : }
1492 : :
1493 : : return 0;
1494 : : }
1495 : :
1496 : : struct mlx5dr_action *
1497 : 0 : mlx5dr_action_create_dest_tir(struct mlx5dr_context *ctx,
1498 : : struct mlx5dr_devx_obj *obj,
1499 : : uint32_t flags,
1500 : : bool is_local)
1501 : : {
1502 : : struct mlx5dr_action *action;
1503 : : int ret;
1504 : :
1505 [ # # # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
1506 : : mlx5dr_action_is_root_flags(flags)) {
1507 : 0 : DR_LOG(ERR, "Same action cannot be used for root and non root");
1508 : 0 : rte_errno = ENOTSUP;
1509 : 0 : return NULL;
1510 : : }
1511 : :
1512 [ # # ]: 0 : if ((flags & (MLX5DR_ACTION_FLAG_ROOT_FDB |
1513 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
1514 : 0 : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)) ||
1515 [ # # ]: 0 : ((flags & (MLX5DR_ACTION_FLAG_HWS_FDB |
1516 : 0 : MLX5DR_ACTION_FLAG_HWS_FDB_RX)) &&
1517 [ # # ]: 0 : !ctx->caps->fdb_tir_stc)) {
1518 : 0 : DR_LOG(ERR, "TIR action not support on FDB or FDB_TX or UNIFIED");
1519 : 0 : rte_errno = ENOTSUP;
1520 : 0 : return NULL;
1521 : : }
1522 : :
1523 [ # # ]: 0 : if (!is_local) {
1524 : 0 : DR_LOG(ERR, "TIR should be created on local ibv_device, flags: 0x%x",
1525 : : flags);
1526 : 0 : rte_errno = ENOTSUP;
1527 : 0 : return NULL;
1528 : : }
1529 : :
1530 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TIR);
1531 [ # # ]: 0 : if (!action)
1532 : : return NULL;
1533 : :
1534 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1535 : 0 : action->devx_obj = obj->obj;
1536 : : } else {
1537 : 0 : struct mlx5dr_devx_obj *cur_obj = NULL; /*compilation warn*/
1538 : :
1539 : 0 : ret = mlx5dr_action_get_dest_tir_obj(ctx, action, obj, &cur_obj);
1540 [ # # ]: 0 : if (ret) {
1541 : 0 : DR_LOG(ERR, "Failed to create tir alias (flags: %d)", flags);
1542 : 0 : goto free_action;
1543 : : }
1544 : :
1545 : 0 : ret = mlx5dr_action_create_stcs(action, cur_obj);
1546 [ # # ]: 0 : if (ret)
1547 : 0 : goto clean_obj;
1548 : :
1549 : 0 : action->devx_dest.devx_obj = cur_obj;
1550 : : }
1551 : :
1552 : : return action;
1553 : :
1554 : : clean_obj:
1555 : 0 : mlx5dr_cmd_destroy_obj(action->alias.devx_obj);
1556 : 0 : free_action:
1557 : : simple_free(action);
1558 : 0 : return NULL;
1559 : : }
1560 : :
1561 : : struct mlx5dr_action *
1562 : 0 : mlx5dr_action_create_dest_drop(struct mlx5dr_context *ctx,
1563 : : uint32_t flags)
1564 : : {
1565 : : struct mlx5dr_action *action;
1566 : : int ret;
1567 : :
1568 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DROP);
1569 [ # # ]: 0 : if (!action)
1570 : : return NULL;
1571 : :
1572 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags)) {
1573 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1574 [ # # ]: 0 : if (ret)
1575 : 0 : goto free_action;
1576 : : }
1577 : :
1578 : : return action;
1579 : :
1580 : : free_action:
1581 : : simple_free(action);
1582 : 0 : return NULL;
1583 : : }
1584 : :
1585 : : struct mlx5dr_action *
1586 : 0 : mlx5dr_action_create_default_miss(struct mlx5dr_context *ctx,
1587 : : uint32_t flags)
1588 : : {
1589 : : struct mlx5dr_action *action;
1590 : : int ret;
1591 : :
1592 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_MISS);
1593 [ # # ]: 0 : if (!action)
1594 : : return NULL;
1595 : :
1596 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags)) {
1597 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1598 [ # # ]: 0 : if (ret)
1599 : 0 : goto free_action;
1600 : : }
1601 : :
1602 : : return action;
1603 : :
1604 : : free_action:
1605 : : simple_free(action);
1606 : 0 : return NULL;
1607 : : }
1608 : :
1609 : : struct mlx5dr_action *
1610 : 0 : mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
1611 : : uint32_t flags)
1612 : : {
1613 : : struct mlx5dr_action *action;
1614 : : int ret;
1615 : :
1616 [ # # ]: 0 : if (flags & (MLX5DR_ACTION_FLAG_HWS_FDB_TX | MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)) {
1617 : 0 : DR_LOG(ERR, "TAG action not supported for UNIFIED or FDB_TX");
1618 : 0 : rte_errno = ENOTSUP;
1619 : 0 : return NULL;
1620 : : }
1621 : :
1622 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TAG);
1623 [ # # ]: 0 : if (!action)
1624 : : return NULL;
1625 : :
1626 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags)) {
1627 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1628 [ # # ]: 0 : if (ret)
1629 : 0 : goto free_action;
1630 : : }
1631 : :
1632 : : return action;
1633 : :
1634 : : free_action:
1635 : : simple_free(action);
1636 : 0 : return NULL;
1637 : : }
1638 : :
1639 : : struct mlx5dr_action *
1640 : 0 : mlx5dr_action_create_last(struct mlx5dr_context *ctx,
1641 : : uint32_t flags)
1642 : : {
1643 : 0 : return mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_LAST);
1644 : : }
1645 : :
1646 : : static struct mlx5dr_action *
1647 : 0 : mlx5dr_action_create_aso(struct mlx5dr_context *ctx,
1648 : : enum mlx5dr_action_type action_type,
1649 : : struct mlx5dr_devx_obj *devx_obj,
1650 : : uint8_t return_reg_id,
1651 : : uint32_t flags)
1652 : : {
1653 : : struct mlx5dr_action *action;
1654 : : int ret;
1655 : :
1656 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1657 : 0 : DR_LOG(ERR, "ASO action cannot be used over root table");
1658 : 0 : rte_errno = ENOTSUP;
1659 : 0 : return NULL;
1660 : : }
1661 : :
1662 : : action = mlx5dr_action_create_generic(ctx, flags, action_type);
1663 [ # # ]: 0 : if (!action)
1664 : : return NULL;
1665 : :
1666 : 0 : action->aso.devx_obj = devx_obj;
1667 : 0 : action->aso.return_reg_id = return_reg_id;
1668 : :
1669 : 0 : ret = mlx5dr_action_create_stcs(action, devx_obj);
1670 [ # # ]: 0 : if (ret)
1671 : 0 : goto free_action;
1672 : :
1673 : : return action;
1674 : :
1675 : : free_action:
1676 : : simple_free(action);
1677 : 0 : return NULL;
1678 : : }
1679 : :
1680 : : struct mlx5dr_action *
1681 : 0 : mlx5dr_action_create_aso_meter(struct mlx5dr_context *ctx,
1682 : : struct mlx5dr_devx_obj *devx_obj,
1683 : : uint8_t return_reg_id,
1684 : : uint32_t flags)
1685 : : {
1686 : 0 : return mlx5dr_action_create_aso(ctx, MLX5DR_ACTION_TYP_ASO_METER,
1687 : : devx_obj, return_reg_id, flags);
1688 : : }
1689 : :
1690 : : struct mlx5dr_action *
1691 : 0 : mlx5dr_action_create_aso_ct(struct mlx5dr_context *ctx,
1692 : : struct mlx5dr_devx_obj *devx_obj,
1693 : : uint8_t return_reg_id,
1694 : : uint32_t flags)
1695 : : {
1696 : 0 : return mlx5dr_action_create_aso(ctx, MLX5DR_ACTION_TYP_ASO_CT,
1697 : : devx_obj, return_reg_id, flags);
1698 : : }
1699 : :
1700 : : struct mlx5dr_action *
1701 : 0 : mlx5dr_action_create_counter(struct mlx5dr_context *ctx,
1702 : : struct mlx5dr_devx_obj *obj,
1703 : : uint32_t flags)
1704 : : {
1705 : : struct mlx5dr_action *action;
1706 : : int ret;
1707 : :
1708 [ # # # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
1709 : : mlx5dr_action_is_root_flags(flags)) {
1710 : 0 : DR_LOG(ERR, "Same action cannot be used for root and non root");
1711 : 0 : rte_errno = ENOTSUP;
1712 : 0 : return NULL;
1713 : : }
1714 : :
1715 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_CTR);
1716 [ # # ]: 0 : if (!action)
1717 : : return NULL;
1718 : :
1719 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1720 : 0 : action->devx_obj = obj->obj;
1721 : : } else {
1722 : 0 : ret = mlx5dr_action_create_stcs(action, obj);
1723 [ # # ]: 0 : if (ret)
1724 : 0 : goto free_action;
1725 : : }
1726 : :
1727 : : return action;
1728 : :
1729 : : free_action:
1730 : : simple_free(action);
1731 : 0 : return NULL;
1732 : : }
1733 : :
1734 : 0 : static int mlx5dr_action_create_dest_vport_hws(struct mlx5dr_context *ctx,
1735 : : struct mlx5dr_action *action,
1736 : : uint32_t ib_port_num)
1737 : : {
1738 : 0 : struct mlx5dr_cmd_query_vport_caps vport_caps = {0};
1739 : : int ret;
1740 : :
1741 : 0 : ret = mlx5dr_cmd_query_ib_port(ctx->ibv_ctx, &vport_caps, ib_port_num);
1742 [ # # ]: 0 : if (ret) {
1743 : 0 : DR_LOG(ERR, "Failed querying port %d", ib_port_num);
1744 : 0 : return ret;
1745 : : }
1746 : 0 : action->vport.vport_num = vport_caps.vport_num;
1747 : 0 : action->vport.esw_owner_vhca_id = vport_caps.esw_owner_vhca_id;
1748 : :
1749 [ # # ]: 0 : if (!ctx->caps->merged_eswitch &&
1750 [ # # ]: 0 : action->vport.esw_owner_vhca_id != ctx->caps->vhca_id) {
1751 : 0 : DR_LOG(ERR, "Not merged-eswitch (%d), not allowed to send to other vhca_id (%d)",
1752 : : ctx->caps->vhca_id, action->vport.esw_owner_vhca_id);
1753 : 0 : rte_errno = ENOTSUP;
1754 : 0 : return rte_errno;
1755 : : }
1756 : :
1757 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1758 [ # # ]: 0 : if (ret) {
1759 : 0 : DR_LOG(ERR, "Failed creating stc for port %d", ib_port_num);
1760 : 0 : return ret;
1761 : : }
1762 : :
1763 : : return 0;
1764 : : }
1765 : :
1766 : : struct mlx5dr_action *
1767 : 0 : mlx5dr_action_create_dest_vport(struct mlx5dr_context *ctx,
1768 : : uint32_t ib_port_num,
1769 : : uint32_t flags)
1770 : : {
1771 : : struct mlx5dr_action *action;
1772 : : int ret;
1773 : :
1774 [ # # ]: 0 : if (!(flags & (MLX5DR_ACTION_FLAG_HWS_FDB | MLX5DR_ACTION_FLAG_HWS_FDB_RX |
1775 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
1776 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED))) {
1777 : 0 : DR_LOG(ERR, "Vport action is supported for FDB only");
1778 : 0 : rte_errno = EINVAL;
1779 : 0 : return NULL;
1780 : : }
1781 : :
1782 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_VPORT);
1783 [ # # ]: 0 : if (!action)
1784 : : return NULL;
1785 : :
1786 : 0 : ret = mlx5dr_action_create_dest_vport_hws(ctx, action, ib_port_num);
1787 [ # # ]: 0 : if (ret) {
1788 : 0 : DR_LOG(ERR, "Failed to create vport action HWS");
1789 : 0 : goto free_action;
1790 : : }
1791 : :
1792 : : return action;
1793 : :
1794 : : free_action:
1795 : : simple_free(action);
1796 : 0 : return NULL;
1797 : : }
1798 : :
1799 : : struct mlx5dr_action *
1800 : 0 : mlx5dr_action_create_push_vlan(struct mlx5dr_context *ctx, uint32_t flags)
1801 : : {
1802 : : struct mlx5dr_action *action;
1803 : : int ret;
1804 : :
1805 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1806 : 0 : DR_LOG(ERR, "Push vlan action not supported for root");
1807 : 0 : rte_errno = ENOTSUP;
1808 : 0 : return NULL;
1809 : : }
1810 : :
1811 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_PUSH_VLAN);
1812 [ # # ]: 0 : if (!action)
1813 : : return NULL;
1814 : :
1815 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1816 [ # # ]: 0 : if (ret) {
1817 : 0 : DR_LOG(ERR, "Failed creating stc for push vlan");
1818 : 0 : goto free_action;
1819 : : }
1820 : :
1821 : : return action;
1822 : :
1823 : : free_action:
1824 : : simple_free(action);
1825 : 0 : return NULL;
1826 : : }
1827 : :
1828 : : struct mlx5dr_action *
1829 : 0 : mlx5dr_action_create_pop_vlan(struct mlx5dr_context *ctx, uint32_t flags)
1830 : : {
1831 : : struct mlx5dr_action *action;
1832 : : int ret;
1833 : :
1834 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1835 : 0 : DR_LOG(ERR, "Pop vlan action not supported for root");
1836 : 0 : rte_errno = ENOTSUP;
1837 : 0 : return NULL;
1838 : : }
1839 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_POP_VLAN);
1840 [ # # ]: 0 : if (!action)
1841 : : return NULL;
1842 : :
1843 : 0 : ret = mlx5dr_action_get_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
1844 [ # # ]: 0 : if (ret) {
1845 : 0 : DR_LOG(ERR, "Failed to create remove stc for reformat");
1846 : 0 : goto free_action;
1847 : : }
1848 : :
1849 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1850 [ # # ]: 0 : if (ret) {
1851 : 0 : DR_LOG(ERR, "Failed creating stc for pop vlan");
1852 : 0 : goto free_shared;
1853 : : }
1854 : :
1855 : : return action;
1856 : :
1857 : : free_shared:
1858 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
1859 : 0 : free_action:
1860 : : simple_free(action);
1861 : 0 : return NULL;
1862 : : }
1863 : :
1864 : : static int
1865 : 0 : mlx5dr_action_conv_reformat_to_verbs(uint32_t action_type,
1866 : : uint32_t *verb_reformat_type)
1867 : : {
1868 [ # # # # : 0 : switch (action_type) {
# ]
1869 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
1870 : 0 : *verb_reformat_type =
1871 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2;
1872 : 0 : return 0;
1873 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
1874 : 0 : *verb_reformat_type =
1875 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL;
1876 : 0 : return 0;
1877 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
1878 : 0 : *verb_reformat_type =
1879 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2;
1880 : 0 : return 0;
1881 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
1882 : 0 : *verb_reformat_type =
1883 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
1884 : 0 : return 0;
1885 : 0 : default:
1886 : 0 : DR_LOG(ERR, "Invalid root reformat action type");
1887 : 0 : rte_errno = EINVAL;
1888 : 0 : return rte_errno;
1889 : : }
1890 : : }
1891 : :
1892 : : static int
1893 : 0 : mlx5dr_action_conv_root_flags_to_dv_ft(uint32_t flags,
1894 : : enum mlx5dv_flow_table_type *ft_type)
1895 : : {
1896 : : uint8_t is_rx, is_tx, is_fdb;
1897 : :
1898 : 0 : is_rx = !!(flags & MLX5DR_ACTION_FLAG_ROOT_RX);
1899 : 0 : is_tx = !!(flags & MLX5DR_ACTION_FLAG_ROOT_TX);
1900 : 0 : is_fdb = !!(flags & MLX5DR_ACTION_FLAG_ROOT_FDB);
1901 : :
1902 [ # # ]: 0 : if (is_rx + is_tx + is_fdb != 1) {
1903 : 0 : DR_LOG(ERR, "Root action flags must be converted to a single ft type");
1904 : 0 : rte_errno = ENOTSUP;
1905 : 0 : return -rte_errno;
1906 : : }
1907 : :
1908 [ # # ]: 0 : if (is_rx) {
1909 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
1910 [ # # ]: 0 : } else if (is_tx) {
1911 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
1912 : : #ifdef HAVE_MLX5DV_FLOW_MATCHER_FT_TYPE
1913 [ # # ]: 0 : } else if (is_fdb) {
1914 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
1915 : : #endif
1916 : : } else {
1917 : 0 : rte_errno = ENOTSUP;
1918 : 0 : return -rte_errno;
1919 : : }
1920 : :
1921 : : return 0;
1922 : : }
1923 : :
1924 : : static int
1925 : 0 : mlx5dr_action_conv_hws_flags_to_dv_ft(uint32_t flags,
1926 : : enum mlx5dv_flow_table_type *ft_type)
1927 : : {
1928 : : uint8_t is_rx, is_tx, is_fdb;
1929 : :
1930 : 0 : is_rx = !!(flags & MLX5DR_ACTION_FLAG_HWS_RX);
1931 : 0 : is_tx = !!(flags & MLX5DR_ACTION_FLAG_HWS_TX);
1932 : 0 : is_fdb = !!(flags & (MLX5DR_ACTION_FLAG_HWS_FDB |
1933 : : MLX5DR_ACTION_FLAG_HWS_FDB_RX |
1934 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
1935 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED));
1936 : :
1937 [ # # ]: 0 : if (is_rx + is_tx + is_fdb != 1) {
1938 : 0 : DR_LOG(ERR, "Action flags must be converted to a single ft type");
1939 : 0 : rte_errno = ENOTSUP;
1940 : 0 : return -rte_errno;
1941 : : }
1942 : :
1943 [ # # ]: 0 : if (is_rx) {
1944 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
1945 [ # # ]: 0 : } else if (is_tx) {
1946 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
1947 : : #ifdef HAVE_MLX5DV_FLOW_MATCHER_FT_TYPE
1948 [ # # ]: 0 : } else if (is_fdb) {
1949 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
1950 : : #endif
1951 : : } else {
1952 : 0 : rte_errno = ENOTSUP;
1953 : 0 : return -rte_errno;
1954 : : }
1955 : :
1956 : : return 0;
1957 : : }
1958 : :
1959 : : static int
1960 : 0 : mlx5dr_action_create_reformat_root(struct mlx5dr_action *action,
1961 : : size_t data_sz,
1962 : : void *data)
1963 : : {
1964 : 0 : enum mlx5dv_flow_table_type ft_type = 0; /*fix compilation warn*/
1965 : 0 : uint32_t verb_reformat_type = 0;
1966 : : struct ibv_context *ibv_ctx;
1967 : : int ret;
1968 : :
1969 : : /* Convert action to FT type and verbs reformat type */
1970 : 0 : ret = mlx5dr_action_conv_root_flags_to_dv_ft(action->flags, &ft_type);
1971 [ # # ]: 0 : if (ret)
1972 : : return ret;
1973 : :
1974 : 0 : ret = mlx5dr_action_conv_reformat_to_verbs(action->type, &verb_reformat_type);
1975 [ # # ]: 0 : if (ret)
1976 : 0 : return rte_errno;
1977 : :
1978 : : /* Create the reformat type for root table */
1979 [ # # ]: 0 : ibv_ctx = mlx5dr_context_get_local_ibv(action->ctx);
1980 : 0 : action->flow_action =
1981 : 0 : mlx5_glue->dv_create_flow_action_packet_reformat_root(ibv_ctx,
1982 : : data_sz,
1983 : : data,
1984 : : verb_reformat_type,
1985 : : ft_type);
1986 [ # # ]: 0 : if (!action->flow_action) {
1987 : 0 : DR_LOG(ERR, "Failed to create dv_create_flow reformat");
1988 : 0 : rte_errno = errno;
1989 : 0 : return rte_errno;
1990 : : }
1991 : :
1992 : : return 0;
1993 : : }
1994 : :
1995 : : static int
1996 : 0 : mlx5dr_action_handle_insert_with_ptr(struct mlx5dr_action *action,
1997 : : uint8_t num_of_hdrs,
1998 : : struct mlx5dr_action_reformat_header *hdrs,
1999 : : uint32_t log_bulk_sz, uint32_t reparse)
2000 : : {
2001 : : struct mlx5dr_devx_obj *arg_obj;
2002 : : size_t max_sz = 0;
2003 : : int ret, i;
2004 : :
2005 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
2006 [ # # ]: 0 : if (hdrs[i].sz % W_SIZE != 0) {
2007 : 0 : DR_LOG(ERR, "Header data size should be in WORD granularity");
2008 : 0 : rte_errno = EINVAL;
2009 : 0 : return rte_errno;
2010 : : }
2011 : 0 : max_sz = RTE_MAX(hdrs[i].sz, max_sz);
2012 : : }
2013 : :
2014 : : /* Allocate single shared arg object for all headers */
2015 : 0 : arg_obj = mlx5dr_arg_create(action->ctx,
2016 : 0 : hdrs->data,
2017 : : max_sz,
2018 : : log_bulk_sz,
2019 : 0 : action->flags & MLX5DR_ACTION_FLAG_SHARED);
2020 [ # # ]: 0 : if (!arg_obj)
2021 : 0 : return rte_errno;
2022 : :
2023 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
2024 : 0 : action[i].reformat.arg_obj = arg_obj;
2025 : 0 : action[i].reformat.header_size = hdrs[i].sz;
2026 : 0 : action[i].reformat.num_of_hdrs = num_of_hdrs;
2027 : 0 : action[i].reformat.max_hdr_sz = max_sz;
2028 : :
2029 [ # # ]: 0 : if (action[i].type == MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2 ||
2030 : : action[i].type == MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3) {
2031 : 0 : action[i].reformat.anchor = MLX5_HEADER_ANCHOR_PACKET_START;
2032 : 0 : action[i].reformat.offset = 0;
2033 : 0 : action[i].reformat.encap = 1;
2034 : 0 : action[i].reformat.push_esp = 0;
2035 : : }
2036 : :
2037 [ # # ]: 0 : if (likely(reparse == MLX5DR_ACTION_STC_REPARSE_DEFAULT))
2038 : 0 : action[i].reformat.require_reparse = true;
2039 [ # # ]: 0 : else if (reparse == MLX5DR_ACTION_STC_REPARSE_ON)
2040 : 0 : action[i].reformat.require_reparse = true;
2041 : :
2042 : 0 : ret = mlx5dr_action_create_stcs(&action[i], NULL);
2043 [ # # ]: 0 : if (ret) {
2044 : 0 : DR_LOG(ERR, "Failed to create stc for reformat");
2045 : 0 : goto free_stc;
2046 : : }
2047 : : }
2048 : :
2049 : : return 0;
2050 : :
2051 : : free_stc:
2052 [ # # ]: 0 : while (i--)
2053 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
2054 : :
2055 : 0 : mlx5dr_cmd_destroy_obj(arg_obj);
2056 : 0 : return ret;
2057 : : }
2058 : :
2059 : : static int
2060 : 0 : mlx5dr_action_handle_l2_to_tunnel_l3(struct mlx5dr_action *action,
2061 : : uint8_t num_of_hdrs,
2062 : : struct mlx5dr_action_reformat_header *hdrs,
2063 : : uint32_t log_bulk_sz)
2064 : : {
2065 : : int ret;
2066 : :
2067 : : /* The action is remove-l2-header + insert-l3-header */
2068 : 0 : ret = mlx5dr_action_get_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
2069 [ # # ]: 0 : if (ret) {
2070 : 0 : DR_LOG(ERR, "Failed to create remove stc for reformat");
2071 : 0 : return ret;
2072 : : }
2073 : :
2074 : : /* Reuse the insert with pointer for the L2L3 header */
2075 : 0 : ret = mlx5dr_action_handle_insert_with_ptr(action,
2076 : : num_of_hdrs,
2077 : : hdrs,
2078 : : log_bulk_sz,
2079 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
2080 [ # # ]: 0 : if (ret)
2081 : 0 : goto put_shared_stc;
2082 : :
2083 : : return 0;
2084 : :
2085 : : put_shared_stc:
2086 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
2087 : 0 : return ret;
2088 : : }
2089 : :
2090 : 0 : static void mlx5dr_action_prepare_decap_l3_actions(size_t data_sz,
2091 : : uint8_t *mh_data,
2092 : : int *num_of_actions)
2093 : : {
2094 : : int actions;
2095 : : uint32_t i;
2096 : :
2097 : : /* Remove L2L3 outer headers */
2098 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, action_type,
2099 : : MLX5_MODIFICATION_TYPE_REMOVE);
2100 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, decap, 0x1);
2101 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, remove_start_anchor,
2102 : : MLX5_HEADER_ANCHOR_PACKET_START);
2103 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, remove_end_anchor,
2104 : : MLX5_HEADER_ANCHOR_INNER_IPV6_IPV4);
2105 : 0 : mh_data += MLX5DR_ACTION_DOUBLE_SIZE; /* Assume every action is 2 dw */
2106 : : actions = 1;
2107 : :
2108 : : /* Add the new header using inline action 4Byte at a time, the header
2109 : : * is added in reversed order to the beginning of the packet to avoid
2110 : : * incorrect parsing by the HW. Since header is 14B or 18B an extra
2111 : : * two bytes are padded and later removed.
2112 : : */
2113 [ # # ]: 0 : for (i = 0; i < data_sz / MLX5DR_ACTION_INLINE_DATA_SIZE + 1; i++) {
2114 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, action_type,
2115 : : MLX5_MODIFICATION_TYPE_INSERT);
2116 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, inline_data, 0x1);
2117 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, insert_anchor,
2118 : : MLX5_HEADER_ANCHOR_PACKET_START);
2119 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, insert_size, 2);
2120 : 0 : mh_data += MLX5DR_ACTION_DOUBLE_SIZE;
2121 : 0 : actions++;
2122 : : }
2123 : :
2124 : : /* Remove first 2 extra bytes */
2125 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove_words, mh_data, action_type,
2126 : : MLX5_MODIFICATION_TYPE_REMOVE_WORDS);
2127 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove_words, mh_data, remove_start_anchor,
2128 : : MLX5_HEADER_ANCHOR_PACKET_START);
2129 : : /* The hardware expects here size in words (2 bytes) */
2130 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove_words, mh_data, remove_size, 1);
2131 : 0 : actions++;
2132 : :
2133 : 0 : *num_of_actions = actions;
2134 : 0 : }
2135 : :
2136 : : static int
2137 : 0 : mlx5dr_action_handle_tunnel_l3_to_l2(struct mlx5dr_action *action,
2138 : : uint8_t num_of_hdrs,
2139 : : struct mlx5dr_action_reformat_header *hdrs,
2140 : : uint32_t log_bulk_sz)
2141 : : {
2142 : 0 : uint8_t mh_data[MLX5DR_ACTION_REFORMAT_DATA_SIZE] = {0};
2143 : : struct mlx5dr_devx_obj *arg_obj, *pat_obj;
2144 : 0 : struct mlx5dr_context *ctx = action->ctx;
2145 : : int num_of_actions;
2146 : : int mh_data_size;
2147 : : int ret, i;
2148 : :
2149 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
2150 [ # # ]: 0 : if (hdrs[i].sz != MLX5DR_ACTION_HDR_LEN_L2 &&
2151 : : hdrs[i].sz != MLX5DR_ACTION_HDR_LEN_L2_W_VLAN) {
2152 : 0 : DR_LOG(ERR, "Data size is not supported for decap-l3");
2153 : 0 : rte_errno = EINVAL;
2154 : 0 : return rte_errno;
2155 : : }
2156 : : }
2157 : :
2158 : : /* Create a full modify header action list in case shared */
2159 : 0 : mlx5dr_action_prepare_decap_l3_actions(hdrs->sz, mh_data, &num_of_actions);
2160 : :
2161 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
2162 : 0 : mlx5dr_action_prepare_decap_l3_data(hdrs->data, mh_data, num_of_actions);
2163 : :
2164 : : /* All DecapL3 cases require the same max arg size */
2165 : 0 : arg_obj = mlx5dr_arg_create_modify_header_arg(ctx,
2166 : : (__be64 *)mh_data,
2167 : : num_of_actions,
2168 : : log_bulk_sz,
2169 : 0 : action->flags & MLX5DR_ACTION_FLAG_SHARED);
2170 [ # # ]: 0 : if (!arg_obj)
2171 : 0 : return rte_errno;
2172 : :
2173 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
2174 : : memset(mh_data, 0, MLX5DR_ACTION_REFORMAT_DATA_SIZE);
2175 : 0 : mlx5dr_action_prepare_decap_l3_actions(hdrs[i].sz, mh_data, &num_of_actions);
2176 : 0 : mh_data_size = num_of_actions * MLX5DR_MODIFY_ACTION_SIZE;
2177 : :
2178 : 0 : pat_obj = mlx5dr_pat_get_pattern(ctx, (__be64 *)mh_data, mh_data_size);
2179 [ # # ]: 0 : if (!pat_obj) {
2180 : 0 : DR_LOG(ERR, "Failed to allocate pattern for DecapL3");
2181 : 0 : goto free_stc_and_pat;
2182 : : }
2183 : :
2184 : 0 : action[i].modify_header.max_num_of_actions = num_of_actions;
2185 : 0 : action[i].modify_header.num_of_actions = num_of_actions;
2186 : 0 : action[i].modify_header.num_of_patterns = num_of_hdrs;
2187 : 0 : action[i].modify_header.arg_obj = arg_obj;
2188 : 0 : action[i].modify_header.pat_obj = pat_obj;
2189 : 0 : action[i].modify_header.require_reparse =
2190 : 0 : mlx5dr_pat_require_reparse((__be64 *)mh_data, num_of_actions);
2191 : :
2192 : 0 : ret = mlx5dr_action_create_stcs(&action[i], NULL);
2193 [ # # ]: 0 : if (ret) {
2194 : 0 : mlx5dr_pat_put_pattern(ctx, pat_obj);
2195 : 0 : goto free_stc_and_pat;
2196 : : }
2197 : : }
2198 : :
2199 : : return 0;
2200 : :
2201 : :
2202 : : free_stc_and_pat:
2203 [ # # ]: 0 : while (i--) {
2204 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
2205 : 0 : mlx5dr_pat_put_pattern(ctx, action[i].modify_header.pat_obj);
2206 : : }
2207 : :
2208 : 0 : mlx5dr_cmd_destroy_obj(arg_obj);
2209 : 0 : return 0;
2210 : : }
2211 : :
2212 : : static int
2213 : 0 : mlx5dr_action_create_reformat_hws(struct mlx5dr_action *action,
2214 : : uint8_t num_of_hdrs,
2215 : : struct mlx5dr_action_reformat_header *hdrs,
2216 : : uint32_t bulk_size)
2217 : : {
2218 : : int ret;
2219 : :
2220 [ # # # # : 0 : switch (action->type) {
# ]
2221 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
2222 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
2223 : 0 : break;
2224 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
2225 : 0 : ret = mlx5dr_action_handle_insert_with_ptr(action, num_of_hdrs, hdrs, bulk_size,
2226 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
2227 : 0 : break;
2228 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
2229 : 0 : ret = mlx5dr_action_handle_l2_to_tunnel_l3(action, num_of_hdrs, hdrs, bulk_size);
2230 : 0 : break;
2231 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
2232 : 0 : ret = mlx5dr_action_handle_tunnel_l3_to_l2(action, num_of_hdrs, hdrs, bulk_size);
2233 : 0 : break;
2234 : 0 : default:
2235 : 0 : DR_LOG(ERR, "Invalid HWS reformat action type");
2236 : 0 : rte_errno = EINVAL;
2237 : 0 : return rte_errno;
2238 : : }
2239 : :
2240 : : return ret;
2241 : : }
2242 : :
2243 : : struct mlx5dr_action *
2244 : 0 : mlx5dr_action_create_reformat(struct mlx5dr_context *ctx,
2245 : : enum mlx5dr_action_type reformat_type,
2246 : : uint8_t num_of_hdrs,
2247 : : struct mlx5dr_action_reformat_header *hdrs,
2248 : : uint32_t log_bulk_size,
2249 : : uint32_t flags)
2250 : : {
2251 : : struct mlx5dr_action *action;
2252 : : int ret;
2253 : :
2254 [ # # ]: 0 : if (!num_of_hdrs) {
2255 : 0 : DR_LOG(ERR, "Reformat num_of_hdrs cannot be zero");
2256 : 0 : rte_errno = EINVAL;
2257 : 0 : return NULL;
2258 : : }
2259 : :
2260 : 0 : action = mlx5dr_action_create_generic_bulk(ctx, flags, reformat_type, num_of_hdrs);
2261 [ # # ]: 0 : if (!action)
2262 : : return NULL;
2263 : :
2264 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
2265 [ # # ]: 0 : if (log_bulk_size) {
2266 : 0 : DR_LOG(ERR, "Bulk reformat not supported over root");
2267 : 0 : rte_errno = ENOTSUP;
2268 : 0 : goto free_action;
2269 : : }
2270 : :
2271 [ # # # # ]: 0 : ret = mlx5dr_action_create_reformat_root(action,
2272 : : hdrs ? hdrs->sz : 0,
2273 : : hdrs ? hdrs->data : NULL);
2274 [ # # ]: 0 : if (ret) {
2275 : 0 : DR_LOG(ERR, "Failed to create root reformat action");
2276 : 0 : goto free_action;
2277 : : }
2278 : :
2279 : : return action;
2280 : : }
2281 : :
2282 [ # # ]: 0 : if (!mlx5dr_action_is_hws_flags(flags) ||
2283 [ # # # # ]: 0 : ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_hdrs > 1))) {
2284 : 0 : DR_LOG(ERR, "Reformat flags don't fit HWS (flags: 0x%x)", flags);
2285 : 0 : rte_errno = EINVAL;
2286 : 0 : goto free_action;
2287 : : }
2288 : :
2289 : 0 : ret = mlx5dr_action_create_reformat_hws(action, num_of_hdrs, hdrs, log_bulk_size);
2290 [ # # ]: 0 : if (ret) {
2291 : 0 : DR_LOG(ERR, "Failed to create HWS reformat action");
2292 : 0 : goto free_action;
2293 : : }
2294 : :
2295 : : return action;
2296 : :
2297 : 0 : free_action:
2298 : : simple_free(action);
2299 : 0 : return NULL;
2300 : : }
2301 : :
2302 : : static int
2303 : 0 : mlx5dr_action_create_modify_header_root(struct mlx5dr_action *action,
2304 : : size_t actions_sz,
2305 : : __be64 *actions)
2306 : : {
2307 : 0 : enum mlx5dv_flow_table_type ft_type = 0;
2308 : : struct ibv_context *local_ibv_ctx;
2309 : : int ret;
2310 : :
2311 : 0 : ret = mlx5dr_action_conv_root_flags_to_dv_ft(action->flags, &ft_type);
2312 [ # # ]: 0 : if (ret)
2313 : : return ret;
2314 : :
2315 [ # # ]: 0 : local_ibv_ctx = mlx5dr_context_get_local_ibv(action->ctx);
2316 : :
2317 : 0 : action->flow_action =
2318 : 0 : mlx5_glue->dv_create_flow_action_modify_header_root(local_ibv_ctx,
2319 : : actions_sz,
2320 : : (uint64_t *)actions,
2321 : : ft_type);
2322 [ # # ]: 0 : if (!action->flow_action) {
2323 : 0 : rte_errno = errno;
2324 : 0 : return rte_errno;
2325 : : }
2326 : :
2327 : : return 0;
2328 : : }
2329 : :
2330 : : static int
2331 : 0 : mlx5dr_action_create_modify_header_hws(struct mlx5dr_action *action,
2332 : : uint8_t num_of_patterns,
2333 : : struct mlx5dr_action_mh_pattern *pattern,
2334 : : uint32_t log_bulk_size,
2335 : : uint32_t reparse)
2336 : : {
2337 : : struct mlx5dr_devx_obj *pat_obj, *arg_obj = NULL;
2338 : 0 : struct mlx5dr_context *ctx = action->ctx;
2339 : : uint16_t num_actions, max_mh_actions = 0;
2340 : : int i, ret;
2341 : :
2342 : : /* Calculate maximum number of mh actions for shared arg allocation */
2343 [ # # ]: 0 : for (i = 0; i < num_of_patterns; i++)
2344 : 0 : max_mh_actions = RTE_MAX(max_mh_actions, pattern[i].sz / MLX5DR_MODIFY_ACTION_SIZE);
2345 : :
2346 : : /* Allocate single shared arg for all patterns based on the max size */
2347 [ # # ]: 0 : if (max_mh_actions > 1) {
2348 : 0 : arg_obj = mlx5dr_arg_create_modify_header_arg(ctx,
2349 : : pattern->data,
2350 : : max_mh_actions,
2351 : : log_bulk_size,
2352 : 0 : action->flags &
2353 : : MLX5DR_ACTION_FLAG_SHARED);
2354 [ # # ]: 0 : if (!arg_obj)
2355 : 0 : return rte_errno;
2356 : : }
2357 : :
2358 [ # # ]: 0 : for (i = 0; i < num_of_patterns; i++) {
2359 [ # # ]: 0 : if (!mlx5dr_pat_verify_actions(pattern[i].data, pattern[i].sz)) {
2360 : 0 : DR_LOG(ERR, "Fail to verify pattern modify actions");
2361 : 0 : rte_errno = EINVAL;
2362 : 0 : goto free_stc_and_pat;
2363 : : }
2364 : :
2365 : 0 : num_actions = pattern[i].sz / MLX5DR_MODIFY_ACTION_SIZE;
2366 : 0 : action[i].modify_header.num_of_patterns = num_of_patterns;
2367 : 0 : action[i].modify_header.max_num_of_actions = max_mh_actions;
2368 : 0 : action[i].modify_header.num_of_actions = num_actions;
2369 : :
2370 [ # # ]: 0 : if (likely(reparse == MLX5DR_ACTION_STC_REPARSE_DEFAULT))
2371 : 0 : action[i].modify_header.require_reparse =
2372 : 0 : mlx5dr_pat_require_reparse(pattern[i].data, num_actions);
2373 [ # # ]: 0 : else if (reparse == MLX5DR_ACTION_STC_REPARSE_ON)
2374 : 0 : action[i].modify_header.require_reparse = true;
2375 : :
2376 [ # # ]: 0 : if (num_actions == 1) {
2377 : : pat_obj = NULL;
2378 : : /* Optimize single modify action to be used inline */
2379 : 0 : action[i].modify_header.single_action = pattern[i].data[0];
2380 : 0 : action[i].modify_header.single_action_type =
2381 [ # # ]: 0 : MLX5_GET(set_action_in, pattern[i].data, action_type);
2382 : : } else {
2383 : : /* Multiple modify actions require a pattern */
2384 : 0 : pat_obj = mlx5dr_pat_get_pattern(ctx, pattern[i].data, pattern[i].sz);
2385 [ # # ]: 0 : if (!pat_obj) {
2386 : 0 : DR_LOG(ERR, "Failed to allocate pattern for modify header");
2387 : 0 : goto free_stc_and_pat;
2388 : : }
2389 : :
2390 : 0 : action[i].modify_header.arg_obj = arg_obj;
2391 : 0 : action[i].modify_header.pat_obj = pat_obj;
2392 : : }
2393 : : /* Allocate STC for each action representing a header */
2394 : 0 : ret = mlx5dr_action_create_stcs(&action[i], NULL);
2395 [ # # ]: 0 : if (ret) {
2396 [ # # ]: 0 : if (pat_obj)
2397 : 0 : mlx5dr_pat_put_pattern(ctx, pat_obj);
2398 : 0 : goto free_stc_and_pat;
2399 : : }
2400 : : }
2401 : :
2402 : : return 0;
2403 : :
2404 : : free_stc_and_pat:
2405 [ # # ]: 0 : while (i--) {
2406 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
2407 [ # # ]: 0 : if (action[i].modify_header.pat_obj)
2408 : 0 : mlx5dr_pat_put_pattern(ctx, action[i].modify_header.pat_obj);
2409 : : }
2410 : :
2411 [ # # ]: 0 : if (arg_obj)
2412 : 0 : mlx5dr_cmd_destroy_obj(arg_obj);
2413 : :
2414 : 0 : return rte_errno;
2415 : : }
2416 : :
2417 : : struct mlx5dr_action *
2418 : 0 : mlx5dr_action_create_modify_header_reparse(struct mlx5dr_context *ctx,
2419 : : uint8_t num_of_patterns,
2420 : : struct mlx5dr_action_mh_pattern *patterns,
2421 : : uint32_t log_bulk_size,
2422 : : uint32_t flags, uint32_t reparse)
2423 : : {
2424 : : struct mlx5dr_action *action;
2425 : : int ret;
2426 : :
2427 [ # # ]: 0 : if (!num_of_patterns) {
2428 : 0 : DR_LOG(ERR, "Invalid number of patterns");
2429 : 0 : rte_errno = ENOTSUP;
2430 : 0 : return NULL;
2431 : : }
2432 : :
2433 : 0 : action = mlx5dr_action_create_generic_bulk(ctx, flags,
2434 : : MLX5DR_ACTION_TYP_MODIFY_HDR,
2435 : : num_of_patterns);
2436 [ # # ]: 0 : if (!action)
2437 : : return NULL;
2438 : :
2439 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
2440 [ # # ]: 0 : if (log_bulk_size) {
2441 : 0 : DR_LOG(ERR, "Bulk modify-header not supported over root");
2442 : 0 : rte_errno = ENOTSUP;
2443 : 0 : goto free_action;
2444 : : }
2445 : :
2446 [ # # ]: 0 : if (num_of_patterns != 1) {
2447 : 0 : DR_LOG(ERR, "Only a single pattern supported over root");
2448 : 0 : rte_errno = ENOTSUP;
2449 : 0 : goto free_action;
2450 : : }
2451 : :
2452 : 0 : ret = mlx5dr_action_create_modify_header_root(action,
2453 : : patterns->sz,
2454 : : patterns->data);
2455 [ # # ]: 0 : if (ret)
2456 : 0 : goto free_action;
2457 : :
2458 : : return action;
2459 : : }
2460 : :
2461 [ # # # # ]: 0 : if ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_patterns > 1)) {
2462 : 0 : DR_LOG(ERR, "Action cannot be shared with requested pattern or size");
2463 : 0 : rte_errno = EINVAL;
2464 : 0 : goto free_action;
2465 : : }
2466 : :
2467 : 0 : ret = mlx5dr_action_create_modify_header_hws(action,
2468 : : num_of_patterns,
2469 : : patterns,
2470 : : log_bulk_size,
2471 : : reparse);
2472 [ # # ]: 0 : if (ret)
2473 : 0 : goto free_action;
2474 : :
2475 : : return action;
2476 : :
2477 : 0 : free_action:
2478 : : simple_free(action);
2479 : 0 : return NULL;
2480 : : }
2481 : :
2482 : : struct mlx5dr_action *
2483 : 0 : mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
2484 : : uint8_t num_of_patterns,
2485 : : struct mlx5dr_action_mh_pattern *patterns,
2486 : : uint32_t log_bulk_size,
2487 : : uint32_t flags)
2488 : : {
2489 : 0 : return mlx5dr_action_create_modify_header_reparse(ctx, num_of_patterns, patterns,
2490 : : log_bulk_size, flags,
2491 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
2492 : : }
2493 : : static struct mlx5dr_devx_obj *
2494 : 0 : mlx5dr_action_dest_array_process_reformat(struct mlx5dr_context *ctx,
2495 : : enum mlx5dr_action_type type,
2496 : : void *reformat_data,
2497 : : size_t reformat_data_sz)
2498 : : {
2499 : 0 : struct mlx5dr_cmd_packet_reformat_create_attr pr_attr = {0};
2500 : : struct mlx5dr_devx_obj *reformat_devx_obj;
2501 : :
2502 [ # # ]: 0 : if (!reformat_data || !reformat_data_sz) {
2503 : 0 : DR_LOG(ERR, "Empty reformat action or data");
2504 : 0 : rte_errno = EINVAL;
2505 : 0 : return NULL;
2506 : : }
2507 : :
2508 [ # # # ]: 0 : switch (type) {
2509 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
2510 : 0 : pr_attr.type = MLX5_PACKET_REFORMAT_CONTEXT_REFORMAT_TYPE_L2_TO_L2_TUNNEL;
2511 : 0 : break;
2512 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
2513 : 0 : pr_attr.type = MLX5_PACKET_REFORMAT_CONTEXT_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
2514 : 0 : break;
2515 : 0 : default:
2516 : 0 : DR_LOG(ERR, "Invalid value for reformat type");
2517 : 0 : rte_errno = EINVAL;
2518 : 0 : return NULL;
2519 : : }
2520 : : pr_attr.reformat_param_0 = 0;
2521 : 0 : pr_attr.data_sz = reformat_data_sz;
2522 : 0 : pr_attr.data = reformat_data;
2523 : :
2524 : 0 : reformat_devx_obj = mlx5dr_cmd_packet_reformat_create(ctx->ibv_ctx, &pr_attr);
2525 [ # # ]: 0 : if (!reformat_devx_obj)
2526 : 0 : return NULL;
2527 : :
2528 : : return reformat_devx_obj;
2529 : : }
2530 : :
2531 : : struct mlx5dr_action *
2532 : 0 : mlx5dr_action_create_dest_array(struct mlx5dr_context *ctx,
2533 : : size_t num_dest,
2534 : : struct mlx5dr_action_dest_attr *dests,
2535 : : uint32_t flags)
2536 : : {
2537 : : struct mlx5dr_cmd_set_fte_dest *dest_list = NULL;
2538 : : struct mlx5dr_devx_obj *packet_reformat = NULL;
2539 : 0 : struct mlx5dr_cmd_ft_create_attr ft_attr = {0};
2540 : 0 : struct mlx5dr_cmd_set_fte_attr fte_attr = {0};
2541 : : struct mlx5dr_cmd_forward_tbl *fw_island;
2542 : : enum mlx5dr_table_type table_type;
2543 : : struct mlx5dr_action *action;
2544 : : uint32_t i;
2545 : : int ret;
2546 : :
2547 [ # # ]: 0 : if (num_dest <= 1) {
2548 : 0 : rte_errno = EINVAL;
2549 : 0 : DR_LOG(ERR, "Action must have multiple dests");
2550 : 0 : return NULL;
2551 : : }
2552 : :
2553 [ # # ]: 0 : if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) {
2554 : 0 : DR_LOG(ERR, "Action flags not supported, should include SHARED");
2555 : 0 : rte_errno = ENOTSUP;
2556 : 0 : return NULL;
2557 : : }
2558 : :
2559 : 0 : flags = flags & ~MLX5DR_ACTION_FLAG_SHARED;
2560 : :
2561 [ # # ]: 0 : if (flags == MLX5DR_ACTION_FLAG_HWS_RX) {
2562 : : ft_attr.type = FS_FT_NIC_RX;
2563 : 0 : ft_attr.level = MLX5_IFC_MULTI_PATH_FT_MAX_LEVEL - 1;
2564 : : table_type = MLX5DR_TABLE_TYPE_NIC_RX;
2565 [ # # ]: 0 : } else if (flags & (MLX5DR_ACTION_FLAG_HWS_FDB | MLX5DR_ACTION_FLAG_HWS_FDB_RX |
2566 : : MLX5DR_ACTION_FLAG_HWS_FDB_TX |
2567 : : MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)) {
2568 : 0 : ft_attr.type = FS_FT_FDB;
2569 : 0 : ft_attr.level = ctx->caps->fdb_ft.max_level - 1;
2570 : : table_type = MLX5DR_TABLE_TYPE_FDB;
2571 : : } else {
2572 : 0 : DR_LOG(ERR, "Action flags not supported");
2573 : 0 : rte_errno = ENOTSUP;
2574 : 0 : return NULL;
2575 : : }
2576 : :
2577 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx)) {
2578 : 0 : DR_LOG(ERR, "Cannot use this action in shared GVMI context");
2579 : 0 : rte_errno = ENOTSUP;
2580 : 0 : return NULL;
2581 : : }
2582 : :
2583 : : dest_list = simple_calloc(num_dest, sizeof(*dest_list));
2584 [ # # ]: 0 : if (!dest_list) {
2585 : 0 : DR_LOG(ERR, "Failed to allocate memory for destinations");
2586 : 0 : rte_errno = ENOMEM;
2587 : 0 : return NULL;
2588 : : }
2589 : :
2590 [ # # ]: 0 : for (i = 0; i < num_dest; i++) {
2591 : 0 : enum mlx5dr_action_type *action_type = dests[i].action_type;
2592 : :
2593 [ # # ]: 0 : if (!mlx5dr_action_check_combo(dests[i].action_type, table_type)) {
2594 : 0 : DR_LOG(ERR, "Invalid combination of actions");
2595 : 0 : rte_errno = EINVAL;
2596 : 0 : goto free_dest_list;
2597 : : }
2598 : :
2599 [ # # ]: 0 : for (; *action_type != MLX5DR_ACTION_TYP_LAST; action_type++) {
2600 [ # # # # : 0 : switch (*action_type) {
# # # ]
2601 : 0 : case MLX5DR_ACTION_TYP_TBL:
2602 : 0 : dest_list[i].destination_type =
2603 : : MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
2604 : 0 : dest_list[i].destination_id = dests[i].dest->dest_tbl.devx_obj->id;
2605 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
2606 : 0 : fte_attr.ignore_flow_level = 1;
2607 : 0 : break;
2608 : : case MLX5DR_ACTION_TYP_MISS:
2609 : : if (!mlx5dr_table_is_fdb_any(table_type)) {
2610 : 0 : DR_LOG(ERR, "Miss action supported for FDB only");
2611 : 0 : rte_errno = ENOTSUP;
2612 : 0 : goto free_dest_list;
2613 : : }
2614 : 0 : dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
2615 : 0 : dest_list[i].destination_id =
2616 : 0 : ctx->caps->eswitch_manager_vport_number;
2617 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
2618 : 0 : break;
2619 : 0 : case MLX5DR_ACTION_TYP_VPORT:
2620 : 0 : dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
2621 : 0 : dest_list[i].destination_id = dests[i].dest->vport.vport_num;
2622 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
2623 [ # # ]: 0 : if (ctx->caps->merged_eswitch) {
2624 : 0 : dest_list[i].ext_flags |=
2625 : : MLX5DR_CMD_EXT_DEST_ESW_OWNER_VHCA_ID;
2626 : 0 : dest_list[i].esw_owner_vhca_id =
2627 : 0 : dests[i].dest->vport.esw_owner_vhca_id;
2628 : : }
2629 : : break;
2630 : 0 : case MLX5DR_ACTION_TYP_TIR:
2631 : 0 : dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_TIR;
2632 : 0 : dest_list[i].destination_id = dests[i].dest->devx_dest.devx_obj->id;
2633 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
2634 : 0 : break;
2635 : 0 : case MLX5DR_ACTION_TYP_DROP:
2636 : 0 : dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_NOP;
2637 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
2638 : 0 : break;
2639 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
2640 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
2641 : 0 : packet_reformat = mlx5dr_action_dest_array_process_reformat
2642 : : (ctx,
2643 : : *action_type,
2644 : : dests[i].reformat.reformat_data,
2645 : : dests[i].reformat.reformat_data_sz);
2646 [ # # ]: 0 : if (!packet_reformat)
2647 : 0 : goto free_dest_list;
2648 : :
2649 : 0 : dest_list[i].ext_flags |= MLX5DR_CMD_EXT_DEST_REFORMAT;
2650 : 0 : dest_list[i].ext_reformat = packet_reformat;
2651 : 0 : ft_attr.reformat_en = true;
2652 : 0 : fte_attr.extended_dest = 1;
2653 : 0 : break;
2654 : 0 : default:
2655 : 0 : DR_LOG(ERR, "Unsupported action in dest_array");
2656 : 0 : rte_errno = ENOTSUP;
2657 : 0 : goto free_dest_list;
2658 : : }
2659 : : }
2660 : : }
2661 : 0 : fte_attr.dests_num = num_dest;
2662 : 0 : fte_attr.dests = dest_list;
2663 : :
2664 : 0 : fw_island = mlx5dr_cmd_forward_tbl_create(ctx->ibv_ctx, &ft_attr, &fte_attr);
2665 [ # # ]: 0 : if (!fw_island)
2666 : 0 : goto free_dest_list;
2667 : :
2668 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DEST_ARRAY);
2669 [ # # ]: 0 : if (!action)
2670 : 0 : goto destroy_fw_island;
2671 : :
2672 : 0 : ret = mlx5dr_action_create_stcs(action, fw_island->ft);
2673 [ # # ]: 0 : if (ret)
2674 : 0 : goto free_action;
2675 : :
2676 : 0 : action->dest_array.fw_island = fw_island;
2677 : 0 : action->dest_array.num_dest = num_dest;
2678 : 0 : action->dest_array.dest_list = dest_list;
2679 : :
2680 : 0 : return action;
2681 : :
2682 : : free_action:
2683 : : simple_free(action);
2684 : 0 : destroy_fw_island:
2685 : 0 : mlx5dr_cmd_forward_tbl_destroy(fw_island);
2686 : : free_dest_list:
2687 [ # # ]: 0 : for (i = 0; i < num_dest; i++) {
2688 [ # # ]: 0 : if (dest_list[i].ext_reformat)
2689 : 0 : mlx5dr_cmd_destroy_obj(dest_list[i].ext_reformat);
2690 : : }
2691 : : simple_free(dest_list);
2692 : 0 : return NULL;
2693 : : }
2694 : :
2695 : : struct mlx5dr_action *
2696 : 0 : mlx5dr_action_create_dest_root(struct mlx5dr_context *ctx,
2697 : : uint16_t priority,
2698 : : uint32_t flags)
2699 : : {
2700 : 0 : struct mlx5dv_steering_anchor_attr attr = {0};
2701 : : struct mlx5dv_steering_anchor *sa;
2702 : : struct mlx5dr_action *action;
2703 : : int ret;
2704 : :
2705 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
2706 : 0 : DR_LOG(ERR, "Action flags must be only non root (HWS)");
2707 : 0 : rte_errno = ENOTSUP;
2708 : 0 : return NULL;
2709 : : }
2710 : :
2711 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx)) {
2712 : 0 : DR_LOG(ERR, "Cannot use this action in shared GVMI context");
2713 : 0 : rte_errno = ENOTSUP;
2714 : 0 : return NULL;
2715 : : }
2716 : :
2717 [ # # ]: 0 : if (mlx5dr_action_conv_hws_flags_to_dv_ft(flags, &attr.ft_type))
2718 : : return NULL;
2719 : :
2720 : 0 : attr.priority = priority;
2721 : :
2722 : 0 : sa = mlx5_glue->create_steering_anchor(ctx->ibv_ctx, &attr);
2723 [ # # ]: 0 : if (!sa) {
2724 : 0 : DR_LOG(ERR, "Creation of steering anchor failed");
2725 : 0 : return NULL;
2726 : : }
2727 : :
2728 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DEST_ROOT);
2729 [ # # ]: 0 : if (!action)
2730 : 0 : goto free_steering_anchor;
2731 : :
2732 : 0 : action->root_tbl.sa = sa;
2733 : :
2734 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
2735 [ # # ]: 0 : if (ret)
2736 : 0 : goto free_action;
2737 : :
2738 : : return action;
2739 : :
2740 : : free_action:
2741 : : simple_free(action);
2742 : 0 : free_steering_anchor:
2743 : 0 : mlx5_glue->destroy_steering_anchor(sa);
2744 : 0 : return NULL;
2745 : : }
2746 : :
2747 : : static struct mlx5dr_action *
2748 : 0 : mlx5dr_action_create_insert_header_reparse(struct mlx5dr_context *ctx,
2749 : : uint8_t num_of_hdrs,
2750 : : struct mlx5dr_action_insert_header *hdrs,
2751 : : uint32_t log_bulk_size,
2752 : : uint32_t flags, uint32_t reparse)
2753 : : {
2754 : : struct mlx5dr_action_reformat_header *reformat_hdrs;
2755 : : struct mlx5dr_action *action;
2756 : : int i, ret;
2757 : :
2758 [ # # ]: 0 : if (!num_of_hdrs) {
2759 : 0 : DR_LOG(ERR, "Reformat num_of_hdrs cannot be zero");
2760 : 0 : rte_errno = EINVAL;
2761 : 0 : return NULL;
2762 : : }
2763 : :
2764 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
2765 : 0 : DR_LOG(ERR, "Dynamic reformat action not supported over root");
2766 : 0 : rte_errno = ENOTSUP;
2767 : 0 : return NULL;
2768 : : }
2769 : :
2770 [ # # ]: 0 : if (!mlx5dr_action_is_hws_flags(flags) ||
2771 [ # # # # ]: 0 : ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_hdrs > 1))) {
2772 : 0 : DR_LOG(ERR, "Reformat flags don't fit HWS (flags: 0x%x)", flags);
2773 : 0 : rte_errno = EINVAL;
2774 : 0 : return NULL;
2775 : : }
2776 : :
2777 : 0 : action = mlx5dr_action_create_generic_bulk(ctx, flags,
2778 : : MLX5DR_ACTION_TYP_INSERT_HEADER,
2779 : : num_of_hdrs);
2780 [ # # ]: 0 : if (!action)
2781 : : return NULL;
2782 : :
2783 : 0 : reformat_hdrs = simple_calloc(num_of_hdrs, sizeof(*reformat_hdrs));
2784 [ # # ]: 0 : if (!reformat_hdrs) {
2785 : 0 : DR_LOG(ERR, "Failed to allocate memory for reformat_hdrs");
2786 : 0 : rte_errno = ENOMEM;
2787 : 0 : goto free_action;
2788 : : }
2789 : :
2790 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
2791 [ # # ]: 0 : if (hdrs[i].offset % W_SIZE != 0) {
2792 : 0 : DR_LOG(ERR, "Header offset should be in WORD granularity");
2793 : 0 : rte_errno = EINVAL;
2794 : 0 : goto free_reformat_hdrs;
2795 : : }
2796 : :
2797 : 0 : action[i].reformat.anchor = hdrs[i].anchor;
2798 : 0 : action[i].reformat.encap = hdrs[i].encap;
2799 : 0 : action[i].reformat.push_esp = hdrs[i].push_esp;
2800 : 0 : action[i].reformat.offset = hdrs[i].offset;
2801 : 0 : reformat_hdrs[i].sz = hdrs[i].hdr.sz;
2802 : 0 : reformat_hdrs[i].data = hdrs[i].hdr.data;
2803 : : }
2804 : :
2805 : 0 : ret = mlx5dr_action_handle_insert_with_ptr(action, num_of_hdrs,
2806 : : reformat_hdrs, log_bulk_size,
2807 : : reparse);
2808 [ # # ]: 0 : if (ret) {
2809 : 0 : DR_LOG(ERR, "Failed to create HWS reformat action");
2810 : 0 : goto free_reformat_hdrs;
2811 : : }
2812 : :
2813 : : simple_free(reformat_hdrs);
2814 : :
2815 : 0 : return action;
2816 : :
2817 : 0 : free_reformat_hdrs:
2818 : : simple_free(reformat_hdrs);
2819 : 0 : free_action:
2820 : : simple_free(action);
2821 : 0 : return NULL;
2822 : : }
2823 : :
2824 : : struct mlx5dr_action *
2825 : 0 : mlx5dr_action_create_insert_header(struct mlx5dr_context *ctx,
2826 : : uint8_t num_of_hdrs,
2827 : : struct mlx5dr_action_insert_header *hdrs,
2828 : : uint32_t log_bulk_size,
2829 : : uint32_t flags)
2830 : : {
2831 : 0 : return mlx5dr_action_create_insert_header_reparse(ctx, num_of_hdrs, hdrs,
2832 : : log_bulk_size, flags,
2833 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
2834 : : }
2835 : :
2836 : : struct mlx5dr_action *
2837 : 0 : mlx5dr_action_create_remove_header(struct mlx5dr_context *ctx,
2838 : : struct mlx5dr_action_remove_header_attr *attr,
2839 : : uint32_t flags)
2840 : : {
2841 : : struct mlx5dr_action *action;
2842 : :
2843 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
2844 : 0 : DR_LOG(ERR, "Remove header action not supported over root");
2845 : 0 : rte_errno = ENOTSUP;
2846 : 0 : return NULL;
2847 : : }
2848 : :
2849 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_REMOVE_HEADER);
2850 [ # # ]: 0 : if (!action)
2851 : : return NULL;
2852 : :
2853 [ # # # ]: 0 : switch (attr->type) {
2854 : 0 : case MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER:
2855 : 0 : action->remove_header.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER;
2856 : 0 : action->remove_header.start_anchor = attr->by_anchor.start_anchor;
2857 : 0 : action->remove_header.end_anchor = attr->by_anchor.end_anchor;
2858 : 0 : action->remove_header.decap = attr->by_anchor.decap;
2859 : 0 : break;
2860 : 0 : case MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET:
2861 [ # # ]: 0 : if (attr->by_offset.size % W_SIZE != 0) {
2862 : 0 : DR_LOG(ERR, "Invalid size, HW supports header remove in WORD granularity");
2863 : 0 : rte_errno = EINVAL;
2864 : 0 : goto free_action;
2865 : : }
2866 : :
2867 [ # # ]: 0 : if (attr->by_offset.size > MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE) {
2868 : 0 : DR_LOG(ERR, "Header removal size limited to %u bytes",
2869 : : MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE);
2870 : 0 : rte_errno = EINVAL;
2871 : 0 : goto free_action;
2872 : : }
2873 : :
2874 : 0 : action->remove_header.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET;
2875 : 0 : action->remove_header.start_anchor = attr->by_offset.start_anchor;
2876 : 0 : action->remove_header.num_of_words = attr->by_offset.size / W_SIZE;
2877 : 0 : break;
2878 : 0 : default:
2879 : 0 : DR_LOG(ERR, "Unsupported remove header type %u", attr->type);
2880 : 0 : rte_errno = ENOTSUP;
2881 : 0 : goto free_action;
2882 : : }
2883 : :
2884 [ # # ]: 0 : if (mlx5dr_action_create_stcs(action, NULL))
2885 : 0 : goto free_action;
2886 : :
2887 : : return action;
2888 : :
2889 : 0 : free_action:
2890 : : simple_free(action);
2891 : 0 : return NULL;
2892 : : }
2893 : :
2894 : : static void *
2895 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
2896 : : {
2897 : : struct mlx5dr_action_mh_pattern pattern;
2898 : 0 : __be64 cmd[3] = {0};
2899 : : uint16_t mod_id;
2900 : :
2901 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
2902 [ # # ]: 0 : if (!mod_id) {
2903 : 0 : rte_errno = EINVAL;
2904 : 0 : return NULL;
2905 : : }
2906 : :
2907 : : /*
2908 : : * Backup ipv6_route_ext.next_hdr to ipv6_route_ext.seg_left.
2909 : : * Next_hdr will be copied to ipv6.protocol after pop done.
2910 : : */
2911 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], action_type, MLX5_MODIFICATION_TYPE_COPY);
2912 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], length, 8);
2913 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], src_offset, 24);
2914 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], src_field, mod_id);
2915 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], dst_field, mod_id);
2916 : :
2917 : : /* Add nop between the continuous same modify field id */
2918 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[1], action_type, MLX5_MODIFICATION_TYPE_NOP);
2919 : :
2920 : : /* Clear next_hdr for right checksum */
2921 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], action_type, MLX5_MODIFICATION_TYPE_SET);
2922 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], length, 8);
2923 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], offset, 24);
2924 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], field, mod_id);
2925 : :
2926 : 0 : pattern.data = cmd;
2927 : 0 : pattern.sz = sizeof(cmd);
2928 : :
2929 : 0 : return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
2930 : 0 : action->flags,
2931 : : MLX5DR_ACTION_STC_REPARSE_ON);
2932 : : }
2933 : :
2934 : : static void *
2935 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(struct mlx5dr_action *action)
2936 : : {
2937 : 0 : enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = {
2938 : : MLX5_MODI_OUT_DIPV6_127_96,
2939 : : MLX5_MODI_OUT_DIPV6_95_64,
2940 : : MLX5_MODI_OUT_DIPV6_63_32,
2941 : : MLX5_MODI_OUT_DIPV6_31_0
2942 : : };
2943 : : struct mlx5dr_action_mh_pattern pattern;
2944 : 0 : __be64 cmd[5] = {0};
2945 : : uint16_t mod_id;
2946 : : uint32_t i;
2947 : :
2948 : : /* Copy ipv6_route_ext[first_segment].dst_addr by flex parser to ipv6.dst_addr */
2949 [ # # ]: 0 : for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
2950 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, i + 1);
2951 [ # # ]: 0 : if (!mod_id) {
2952 : 0 : rte_errno = EINVAL;
2953 : 0 : return NULL;
2954 : : }
2955 : :
2956 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_COPY);
2957 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[i], dst_field, field[i]);
2958 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[i], src_field, mod_id);
2959 : : }
2960 : :
2961 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
2962 [ # # ]: 0 : if (!mod_id) {
2963 : 0 : rte_errno = EINVAL;
2964 : 0 : return NULL;
2965 : : }
2966 : :
2967 : : /* Restore next_hdr from seg_left for flex parser identifying */
2968 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_COPY);
2969 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], length, 8);
2970 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], dst_offset, 24);
2971 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], src_field, mod_id);
2972 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], dst_field, mod_id);
2973 : :
2974 : 0 : pattern.data = cmd;
2975 : 0 : pattern.sz = sizeof(cmd);
2976 : :
2977 : 0 : return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
2978 : 0 : action->flags,
2979 : : MLX5DR_ACTION_STC_REPARSE_ON);
2980 : : }
2981 : :
2982 : : static void *
2983 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(struct mlx5dr_action *action)
2984 : : {
2985 : 0 : uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0};
2986 : : struct mlx5dr_action_mh_pattern pattern;
2987 : : uint16_t mod_id;
2988 : :
2989 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
2990 [ # # ]: 0 : if (!mod_id) {
2991 : 0 : rte_errno = EINVAL;
2992 : 0 : return NULL;
2993 : : }
2994 : :
2995 : : /* Copy ipv6_route_ext.next_hdr to ipv6.protocol */
2996 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_COPY);
2997 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, length, 8);
2998 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, src_offset, 24);
2999 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, src_field, mod_id);
3000 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, dst_field, MLX5_MODI_OUT_IP_PROTOCOL);
3001 : :
3002 : 0 : pattern.data = (__be64 *)cmd;
3003 : 0 : pattern.sz = sizeof(cmd);
3004 : :
3005 : 0 : return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
3006 : 0 : action->flags,
3007 : : MLX5DR_ACTION_STC_REPARSE_OFF);
3008 : : }
3009 : :
3010 : : static int
3011 : 0 : mlx5dr_action_create_pop_ipv6_route_ext(struct mlx5dr_action *action)
3012 : : {
3013 : 0 : uint8_t anchor_id = flow_hw_get_ipv6_route_ext_anchor_from_ctx(action->ctx);
3014 : : struct mlx5dr_action_remove_header_attr hdr_attr;
3015 : : uint32_t i;
3016 : :
3017 [ # # ]: 0 : if (!anchor_id) {
3018 : 0 : rte_errno = EINVAL;
3019 : 0 : return rte_errno;
3020 : : }
3021 : :
3022 : 0 : action->ipv6_route_ext.action[0] =
3023 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(action);
3024 : 0 : action->ipv6_route_ext.action[1] =
3025 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(action);
3026 : 0 : action->ipv6_route_ext.action[2] =
3027 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(action);
3028 : :
3029 : 0 : hdr_attr.by_anchor.decap = 1;
3030 : 0 : hdr_attr.by_anchor.start_anchor = anchor_id;
3031 : 0 : hdr_attr.by_anchor.end_anchor = MLX5_HEADER_ANCHOR_TCP_UDP;
3032 : 0 : hdr_attr.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER;
3033 : 0 : action->ipv6_route_ext.action[3] =
3034 : 0 : mlx5dr_action_create_remove_header(action->ctx, &hdr_attr, action->flags);
3035 : :
3036 [ # # # # ]: 0 : if (!action->ipv6_route_ext.action[0] || !action->ipv6_route_ext.action[1] ||
3037 [ # # # # ]: 0 : !action->ipv6_route_ext.action[2] || !action->ipv6_route_ext.action[3]) {
3038 : 0 : DR_LOG(ERR, "Failed to create ipv6_route_ext pop subaction");
3039 : 0 : goto err;
3040 : : }
3041 : :
3042 : : return 0;
3043 : :
3044 : : err:
3045 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
3046 [ # # ]: 0 : if (action->ipv6_route_ext.action[i])
3047 : 0 : mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
3048 : :
3049 : 0 : return rte_errno;
3050 : : }
3051 : :
3052 : : static void *
3053 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
3054 : : {
3055 : : uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0};
3056 : : struct mlx5dr_action_mh_pattern pattern;
3057 : :
3058 : : /* Set ipv6.protocol to IPPROTO_ROUTING */
3059 : : MLX5_SET(set_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_SET);
3060 [ # # ]: 0 : MLX5_SET(set_action_in, cmd, length, 8);
3061 [ # # ]: 0 : MLX5_SET(set_action_in, cmd, field, MLX5_MODI_OUT_IP_PROTOCOL);
3062 : 0 : MLX5_SET(set_action_in, cmd, data, IPPROTO_ROUTING);
3063 : :
3064 : 0 : pattern.data = (__be64 *)cmd;
3065 : 0 : pattern.sz = sizeof(cmd);
3066 : :
3067 : 0 : return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, 0,
3068 : 0 : action->flags | MLX5DR_ACTION_FLAG_SHARED);
3069 : : }
3070 : :
3071 : : static void *
3072 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr2(struct mlx5dr_action *action,
3073 : : uint32_t bulk_size,
3074 : : uint8_t *data)
3075 : : {
3076 : 0 : enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = {
3077 : : MLX5_MODI_OUT_DIPV6_127_96,
3078 : : MLX5_MODI_OUT_DIPV6_95_64,
3079 : : MLX5_MODI_OUT_DIPV6_63_32,
3080 : : MLX5_MODI_OUT_DIPV6_31_0
3081 : : };
3082 : : struct mlx5dr_action_mh_pattern pattern;
3083 : : uint32_t *ipv6_dst_addr = NULL;
3084 : : uint8_t seg_left, next_hdr;
3085 : 0 : __be64 cmd[5] = {0};
3086 : : uint16_t mod_id;
3087 : : uint32_t i;
3088 : :
3089 : : /* Fetch the last IPv6 address in the segment list */
3090 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
3091 [ # # ]: 0 : seg_left = MLX5_GET(header_ipv6_routing_ext, data, segments_left) - 1;
3092 : 0 : ipv6_dst_addr = (uint32_t *)data + MLX5_ST_SZ_DW(header_ipv6_routing_ext) +
3093 : : seg_left * MLX5_ST_SZ_DW(definer_hl_ipv6_addr);
3094 : : }
3095 : :
3096 : : /* Copy IPv6 destination address from ipv6_route_ext.last_segment */
3097 [ # # ]: 0 : for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
3098 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_SET);
3099 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[i], field, field[i]);
3100 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
3101 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[i], data, be32toh(*ipv6_dst_addr++));
3102 : : }
3103 : :
3104 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
3105 [ # # ]: 0 : if (!mod_id) {
3106 : 0 : rte_errno = EINVAL;
3107 : 0 : return NULL;
3108 : : }
3109 : :
3110 : : /* Set ipv6_route_ext.next_hdr since initially pushed as 0 for right checksum */
3111 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_SET);
3112 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], length, 8);
3113 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], offset, 24);
3114 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], field, mod_id);
3115 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
3116 [ # # ]: 0 : next_hdr = MLX5_GET(header_ipv6_routing_ext, data, next_hdr);
3117 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], data, next_hdr);
3118 : : }
3119 : :
3120 : 0 : pattern.data = cmd;
3121 : 0 : pattern.sz = sizeof(cmd);
3122 : :
3123 : 0 : return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern,
3124 : : bulk_size, action->flags);
3125 : : }
3126 : :
3127 : : static int
3128 : 0 : mlx5dr_action_create_push_ipv6_route_ext(struct mlx5dr_action *action,
3129 : : struct mlx5dr_action_reformat_header *hdr,
3130 : : uint32_t bulk_size)
3131 : : {
3132 : 0 : struct mlx5dr_action_insert_header insert_hdr = { {0} };
3133 : : uint8_t header[MLX5_PUSH_MAX_LEN];
3134 : : uint32_t i;
3135 : :
3136 [ # # # # : 0 : if (!hdr || !hdr->sz || hdr->sz > MLX5_PUSH_MAX_LEN ||
# # ]
3137 [ # # # # ]: 0 : ((action->flags & MLX5DR_ACTION_FLAG_SHARED) && !hdr->data)) {
3138 : 0 : DR_LOG(ERR, "Invalid ipv6_route_ext header");
3139 : 0 : rte_errno = EINVAL;
3140 : 0 : return rte_errno;
3141 : : }
3142 : :
3143 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
3144 [ # # ]: 0 : memcpy(header, hdr->data, hdr->sz);
3145 : : /* Clear ipv6_route_ext.next_hdr for right checksum */
3146 [ # # ]: 0 : MLX5_SET(header_ipv6_routing_ext, header, next_hdr, 0);
3147 : : }
3148 : :
3149 : 0 : insert_hdr.anchor = MLX5_HEADER_ANCHOR_TCP_UDP;
3150 : 0 : insert_hdr.encap = 1;
3151 : 0 : insert_hdr.hdr.sz = hdr->sz;
3152 : 0 : insert_hdr.hdr.data = header;
3153 : 0 : action->ipv6_route_ext.action[0] =
3154 : 0 : mlx5dr_action_create_insert_header_reparse(action->ctx, 1, &insert_hdr,
3155 : : bulk_size, action->flags,
3156 : : MLX5DR_ACTION_STC_REPARSE_OFF);
3157 : 0 : action->ipv6_route_ext.action[1] =
3158 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr1(action);
3159 : 0 : action->ipv6_route_ext.action[2] =
3160 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr2(action, bulk_size, hdr->data);
3161 : :
3162 [ # # ]: 0 : if (!action->ipv6_route_ext.action[0] ||
3163 [ # # # # ]: 0 : !action->ipv6_route_ext.action[1] ||
3164 : : !action->ipv6_route_ext.action[2]) {
3165 : 0 : DR_LOG(ERR, "Failed to create ipv6_route_ext push subaction");
3166 : 0 : goto err;
3167 : : }
3168 : :
3169 : : return 0;
3170 : :
3171 : : err:
3172 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
3173 [ # # ]: 0 : if (action->ipv6_route_ext.action[i])
3174 : 0 : mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
3175 : :
3176 : 0 : return rte_errno;
3177 : : }
3178 : :
3179 : : struct mlx5dr_action *
3180 : 0 : mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
3181 : : enum mlx5dr_action_type action_type,
3182 : : struct mlx5dr_action_reformat_header *hdr,
3183 : : uint32_t log_bulk_size,
3184 : : uint32_t flags)
3185 : : {
3186 : : struct mlx5dr_action *action;
3187 : : int ret;
3188 : :
3189 [ # # ]: 0 : if (!mlx5dr_action_is_hws_flags(flags) ||
3190 [ # # # # ]: 0 : ((flags & MLX5DR_ACTION_FLAG_SHARED) && log_bulk_size)) {
3191 : 0 : DR_LOG(ERR, "IPv6 extension flags don't fit HWS (flags: 0x%x)", flags);
3192 : 0 : rte_errno = EINVAL;
3193 : 0 : return NULL;
3194 : : }
3195 : :
3196 : : action = mlx5dr_action_create_generic(ctx, flags, action_type);
3197 [ # # ]: 0 : if (!action) {
3198 : 0 : rte_errno = ENOMEM;
3199 : 0 : return NULL;
3200 : : }
3201 : :
3202 [ # # # ]: 0 : switch (action_type) {
3203 : 0 : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
3204 [ # # ]: 0 : if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) {
3205 : 0 : DR_LOG(ERR, "Pop ipv6_route_ext must be shared");
3206 : 0 : rte_errno = EINVAL;
3207 : 0 : goto free_action;
3208 : : }
3209 : :
3210 : 0 : ret = mlx5dr_action_create_pop_ipv6_route_ext(action);
3211 : 0 : break;
3212 : 0 : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
3213 [ # # ]: 0 : if (!mlx5dr_context_cap_dynamic_reparse(ctx)) {
3214 : 0 : DR_LOG(ERR, "IPv6 routing extension push actions is not supported");
3215 : 0 : rte_errno = ENOTSUP;
3216 : 0 : goto free_action;
3217 : : }
3218 : :
3219 : 0 : ret = mlx5dr_action_create_push_ipv6_route_ext(action, hdr, log_bulk_size);
3220 : 0 : break;
3221 : 0 : default:
3222 : 0 : DR_LOG(ERR, "Unsupported action type %d\n", action_type);
3223 : 0 : rte_errno = ENOTSUP;
3224 : 0 : goto free_action;
3225 : : }
3226 : :
3227 [ # # ]: 0 : if (ret) {
3228 : 0 : DR_LOG(ERR, "Failed to create IPv6 extension reformat action");
3229 : 0 : goto free_action;
3230 : : }
3231 : :
3232 : : return action;
3233 : :
3234 : 0 : free_action:
3235 : : simple_free(action);
3236 : 0 : return NULL;
3237 : : }
3238 : :
3239 : : static bool
3240 : 0 : mlx5dr_action_nat64_validate_param(struct mlx5dr_action_nat64_attr *attr,
3241 : : uint32_t flags)
3242 : : {
3243 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
3244 : 0 : DR_LOG(ERR, "Nat64 action not supported for root");
3245 : 0 : rte_errno = ENOTSUP;
3246 : 0 : return false;
3247 : : }
3248 : :
3249 [ # # ]: 0 : if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) {
3250 : 0 : DR_LOG(ERR, "Nat64 action must be with SHARED flag");
3251 : 0 : rte_errno = EINVAL;
3252 : 0 : return false;
3253 : : }
3254 : :
3255 [ # # ]: 0 : if (attr->num_of_registers > MLX5DR_ACTION_NAT64_REG_MAX) {
3256 : 0 : DR_LOG(ERR, "Nat64 action doesn't support more than %d registers",
3257 : : MLX5DR_ACTION_NAT64_REG_MAX);
3258 : 0 : rte_errno = EINVAL;
3259 : 0 : return false;
3260 : : }
3261 : :
3262 [ # # # # ]: 0 : if (attr->flags & MLX5DR_ACTION_NAT64_BACKUP_ADDR &&
3263 : : attr->num_of_registers != MLX5DR_ACTION_NAT64_REG_MAX) {
3264 : 0 : DR_LOG(ERR, "Nat64 backup addr requires %d registers",
3265 : : MLX5DR_ACTION_NAT64_REG_MAX);
3266 : 0 : rte_errno = EINVAL;
3267 : 0 : return false;
3268 : : }
3269 : :
3270 [ # # ]: 0 : if (!(attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6 ||
3271 : : attr->flags & MLX5DR_ACTION_NAT64_V6_TO_V4)) {
3272 : 0 : DR_LOG(ERR, "Nat64 backup addr requires one mode at least");
3273 : 0 : rte_errno = EINVAL;
3274 : 0 : return false;
3275 : : }
3276 : :
3277 : : return true;
3278 : : }
3279 : :
3280 : : struct mlx5dr_action *
3281 : 0 : mlx5dr_action_create_nat64(struct mlx5dr_context *ctx,
3282 : : struct mlx5dr_action_nat64_attr *attr,
3283 : : uint32_t flags)
3284 : : {
3285 : : struct mlx5dr_action *action;
3286 : :
3287 [ # # ]: 0 : if (!mlx5dr_action_nat64_validate_param(attr, flags))
3288 : : return NULL;
3289 : :
3290 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_NAT64);
3291 [ # # ]: 0 : if (!action)
3292 : : return NULL;
3293 : :
3294 : 0 : action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY] =
3295 : 0 : mlx5dr_action_create_nat64_copy_state(ctx, attr, flags);
3296 [ # # ]: 0 : if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY]) {
3297 : 0 : DR_LOG(ERR, "Nat64 failed creating copy state");
3298 : 0 : goto free_action;
3299 : : }
3300 : :
3301 : 0 : action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_REPLACE] =
3302 : 0 : mlx5dr_action_create_nat64_repalce_state(ctx, attr, flags);
3303 [ # # ]: 0 : if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_REPLACE]) {
3304 : 0 : DR_LOG(ERR, "Nat64 failed creating replace state");
3305 : 0 : goto free_copy;
3306 : : }
3307 : 0 : action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY_PROTOCOL] =
3308 : 0 : mlx5dr_action_create_nat64_copy_proto_state(ctx, attr, flags);
3309 [ # # ]: 0 : if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY_PROTOCOL]) {
3310 : 0 : DR_LOG(ERR, "Nat64 failed creating copy protocol state");
3311 : 0 : goto free_replace;
3312 : : }
3313 : :
3314 : 0 : action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPYBACK] =
3315 : 0 : mlx5dr_action_create_nat64_copy_back_state(ctx, attr, flags);
3316 [ # # ]: 0 : if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPYBACK]) {
3317 : 0 : DR_LOG(ERR, "Nat64 failed creating copyback state");
3318 : 0 : goto free_copy_proto;
3319 : : }
3320 : :
3321 : : return action;
3322 : :
3323 : : free_copy_proto:
3324 : 0 : mlx5dr_action_destroy(action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY_PROTOCOL]);
3325 : 0 : free_replace:
3326 : 0 : mlx5dr_action_destroy(action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_REPLACE]);
3327 : 0 : free_copy:
3328 : 0 : mlx5dr_action_destroy(action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY]);
3329 : 0 : free_action:
3330 : : simple_free(action);
3331 : 0 : return NULL;
3332 : : }
3333 : :
3334 : : struct mlx5dr_action *
3335 : 0 : mlx5dr_action_create_jump_to_matcher(struct mlx5dr_context *ctx,
3336 : : struct mlx5dr_action_jump_to_matcher_attr *attr,
3337 : : uint32_t flags)
3338 : : {
3339 : 0 : struct mlx5dr_matcher *matcher = attr->matcher;
3340 : : struct mlx5dr_matcher_attr *m_attr;
3341 : : struct mlx5dr_action *action;
3342 : :
3343 [ # # ]: 0 : if (attr->type != MLX5DR_ACTION_JUMP_TO_MATCHER_BY_INDEX) {
3344 : 0 : DR_LOG(ERR, "Only jump to matcher by index is supported");
3345 : 0 : goto enotsup;
3346 : : }
3347 : :
3348 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
3349 : 0 : DR_LOG(ERR, "Action flags must be only non root (HWS)");
3350 : 0 : goto enotsup;
3351 : : }
3352 : :
3353 [ # # ]: 0 : if (mlx5dr_table_is_root(matcher->tbl)) {
3354 : 0 : DR_LOG(ERR, "Root matcher cannot be set as destination");
3355 : 0 : goto enotsup;
3356 : : }
3357 : :
3358 : : m_attr = &matcher->attr;
3359 : :
3360 [ # # ]: 0 : if (!(matcher->flags & MLX5DR_MATCHER_FLAGS_STE_ARRAY) &&
3361 [ # # ]: 0 : (m_attr->resizable || m_attr->table.sz_col_log || m_attr->table.sz_row_log)) {
3362 : 0 : DR_LOG(ERR, "Only STE array or matcher of size 1 can be set as destination");
3363 : 0 : goto enotsup;
3364 : : }
3365 : :
3366 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_JUMP_TO_MATCHER);
3367 [ # # ]: 0 : if (!action)
3368 : : return NULL;
3369 : :
3370 : 0 : action->jump_to_matcher.matcher = matcher;
3371 : :
3372 [ # # ]: 0 : if (mlx5dr_action_create_stcs(action, NULL)) {
3373 : 0 : DR_LOG(ERR, "Failed to create action jump to matcher STC");
3374 : : simple_free(action);
3375 : 0 : return NULL;
3376 : : }
3377 : :
3378 : : return action;
3379 : :
3380 : 0 : enotsup:
3381 : 0 : rte_errno = ENOTSUP;
3382 : 0 : return NULL;
3383 : : }
3384 : :
3385 : 0 : static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action)
3386 : : {
3387 : : struct mlx5dr_devx_obj *obj = NULL;
3388 : : uint32_t i;
3389 : :
3390 [ # # # # : 0 : switch (action->type) {
# # # # #
# # # ]
3391 : 0 : case MLX5DR_ACTION_TYP_TIR:
3392 : 0 : mlx5dr_action_destroy_stcs(action);
3393 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(action->ctx))
3394 : 0 : mlx5dr_cmd_destroy_obj(action->alias.devx_obj);
3395 : : break;
3396 : 0 : case MLX5DR_ACTION_TYP_MISS:
3397 : : case MLX5DR_ACTION_TYP_TAG:
3398 : : case MLX5DR_ACTION_TYP_DROP:
3399 : : case MLX5DR_ACTION_TYP_CTR:
3400 : : case MLX5DR_ACTION_TYP_TBL:
3401 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
3402 : : case MLX5DR_ACTION_TYP_ASO_METER:
3403 : : case MLX5DR_ACTION_TYP_ASO_CT:
3404 : : case MLX5DR_ACTION_TYP_PUSH_VLAN:
3405 : : case MLX5DR_ACTION_TYP_REMOVE_HEADER:
3406 : : case MLX5DR_ACTION_TYP_VPORT:
3407 : : case MLX5DR_ACTION_TYP_JUMP_TO_MATCHER:
3408 : 0 : mlx5dr_action_destroy_stcs(action);
3409 : 0 : break;
3410 : 0 : case MLX5DR_ACTION_TYP_DEST_ROOT:
3411 : 0 : mlx5dr_action_destroy_stcs(action);
3412 : 0 : mlx5_glue->destroy_steering_anchor(action->root_tbl.sa);
3413 : 0 : break;
3414 : 0 : case MLX5DR_ACTION_TYP_POP_VLAN:
3415 : 0 : mlx5dr_action_destroy_stcs(action);
3416 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
3417 : 0 : break;
3418 : 0 : case MLX5DR_ACTION_TYP_DEST_ARRAY:
3419 : 0 : mlx5dr_action_destroy_stcs(action);
3420 : 0 : mlx5dr_cmd_forward_tbl_destroy(action->dest_array.fw_island);
3421 [ # # ]: 0 : for (i = 0; i < action->dest_array.num_dest; i++) {
3422 [ # # ]: 0 : if (action->dest_array.dest_list[i].ext_reformat)
3423 : 0 : mlx5dr_cmd_destroy_obj
3424 : : (action->dest_array.dest_list[i].ext_reformat);
3425 : : }
3426 : 0 : simple_free(action->dest_array.dest_list);
3427 : : break;
3428 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
3429 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
3430 [ # # ]: 0 : for (i = 0; i < action->modify_header.num_of_patterns; i++) {
3431 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
3432 [ # # ]: 0 : if (action[i].modify_header.num_of_actions > 1) {
3433 : 0 : mlx5dr_pat_put_pattern(action[i].ctx,
3434 : : action[i].modify_header.pat_obj);
3435 : : /* Save shared arg object if was used to free */
3436 [ # # ]: 0 : if (action[i].modify_header.arg_obj)
3437 : : obj = action[i].modify_header.arg_obj;
3438 : : }
3439 : : }
3440 [ # # ]: 0 : if (obj)
3441 : 0 : mlx5dr_cmd_destroy_obj(obj);
3442 : : break;
3443 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
3444 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
3445 [ # # ]: 0 : for (i = 0; i < action->reformat.num_of_hdrs; i++)
3446 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
3447 : 0 : mlx5dr_cmd_destroy_obj(action->reformat.arg_obj);
3448 : 0 : break;
3449 : : case MLX5DR_ACTION_TYP_INSERT_HEADER:
3450 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
3451 [ # # ]: 0 : for (i = 0; i < action->reformat.num_of_hdrs; i++)
3452 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
3453 : 0 : mlx5dr_cmd_destroy_obj(action->reformat.arg_obj);
3454 : 0 : break;
3455 : : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
3456 : : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
3457 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
3458 [ # # ]: 0 : if (action->ipv6_route_ext.action[i])
3459 : 0 : mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
3460 : : break;
3461 : : case MLX5DR_ACTION_TYP_NAT64:
3462 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_NAT64_STAGES; i++)
3463 : 0 : mlx5dr_action_destroy(action->nat64.stages[i]);
3464 : : break;
3465 : : case MLX5DR_ACTION_TYP_LAST:
3466 : : break;
3467 : 0 : default:
3468 : 0 : DR_LOG(ERR, "Not supported action type: %d", action->type);
3469 : 0 : assert(false);
3470 : : }
3471 : 0 : }
3472 : :
3473 : 0 : static void mlx5dr_action_destroy_root(struct mlx5dr_action *action)
3474 : : {
3475 [ # # ]: 0 : switch (action->type) {
3476 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
3477 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
3478 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
3479 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
3480 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
3481 [ # # ]: 0 : ibv_destroy_flow_action(action->flow_action);
3482 : : break;
3483 : : }
3484 : 0 : }
3485 : :
3486 : 0 : int mlx5dr_action_destroy(struct mlx5dr_action *action)
3487 : : {
3488 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(action->flags))
3489 : 0 : mlx5dr_action_destroy_root(action);
3490 : : else
3491 : 0 : mlx5dr_action_destroy_hws(action);
3492 : :
3493 : : simple_free(action);
3494 : 0 : return 0;
3495 : : }
3496 : :
3497 : : /* Called under pthread_spin_lock(&ctx->ctrl_lock) */
3498 : 0 : int mlx5dr_action_get_default_stc(struct mlx5dr_context *ctx,
3499 : : uint8_t tbl_type)
3500 : : {
3501 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
3502 : : struct mlx5dr_action_default_stc *default_stc;
3503 : : int ret;
3504 : :
3505 [ # # ]: 0 : if (ctx->common_res[tbl_type].default_stc) {
3506 : 0 : ctx->common_res[tbl_type].default_stc->refcount++;
3507 : 0 : return 0;
3508 : : }
3509 : :
3510 : : default_stc = simple_calloc(1, sizeof(*default_stc));
3511 [ # # ]: 0 : if (!default_stc) {
3512 : 0 : DR_LOG(ERR, "Failed to allocate memory for default STCs");
3513 : 0 : rte_errno = ENOMEM;
3514 : 0 : return rte_errno;
3515 : : }
3516 : :
3517 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_NOP;
3518 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW0;
3519 : 0 : stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
3520 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
3521 : : &default_stc->nop_ctr);
3522 [ # # ]: 0 : if (ret) {
3523 : 0 : DR_LOG(ERR, "Failed to allocate default counter STC");
3524 : 0 : goto free_default_stc;
3525 : : }
3526 : :
3527 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
3528 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
3529 : : &default_stc->nop_dw5);
3530 [ # # ]: 0 : if (ret) {
3531 : 0 : DR_LOG(ERR, "Failed to allocate default NOP DW5 STC");
3532 : 0 : goto free_nop_ctr;
3533 : : }
3534 : :
3535 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW6;
3536 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
3537 : : &default_stc->nop_dw6);
3538 [ # # ]: 0 : if (ret) {
3539 : 0 : DR_LOG(ERR, "Failed to allocate default NOP DW6 STC");
3540 : 0 : goto free_nop_dw5;
3541 : : }
3542 : :
3543 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW7;
3544 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
3545 : : &default_stc->nop_dw7);
3546 [ # # ]: 0 : if (ret) {
3547 : 0 : DR_LOG(ERR, "Failed to allocate default NOP DW7 STC");
3548 : 0 : goto free_nop_dw6;
3549 : : }
3550 : :
3551 [ # # ]: 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
3552 [ # # ]: 0 : if (!mlx5dr_context_shared_gvmi_used(ctx)) {
3553 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
3554 : : } else {
3555 : : /* On shared gvmi the default hit behavior is jump to alias end ft */
3556 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
3557 : 0 : stc_attr.dest_table_id = ctx->gvmi_res[tbl_type].aliased_end_ft->id;
3558 : : }
3559 : :
3560 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
3561 : : &default_stc->default_hit);
3562 [ # # ]: 0 : if (ret) {
3563 : 0 : DR_LOG(ERR, "Failed to allocate default allow STC");
3564 : 0 : goto free_nop_dw7;
3565 : : }
3566 : :
3567 : 0 : ctx->common_res[tbl_type].default_stc = default_stc;
3568 : 0 : ctx->common_res[tbl_type].default_stc->refcount++;
3569 : :
3570 : 0 : return 0;
3571 : :
3572 : : free_nop_dw7:
3573 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw7);
3574 : 0 : free_nop_dw6:
3575 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw6);
3576 : 0 : free_nop_dw5:
3577 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw5);
3578 : 0 : free_nop_ctr:
3579 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_ctr);
3580 : 0 : free_default_stc:
3581 : : simple_free(default_stc);
3582 : 0 : return rte_errno;
3583 : : }
3584 : :
3585 : 0 : void mlx5dr_action_put_default_stc(struct mlx5dr_context *ctx,
3586 : : uint8_t tbl_type)
3587 : : {
3588 : : struct mlx5dr_action_default_stc *default_stc;
3589 : :
3590 : 0 : default_stc = ctx->common_res[tbl_type].default_stc;
3591 : :
3592 : : default_stc = ctx->common_res[tbl_type].default_stc;
3593 [ # # ]: 0 : if (--default_stc->refcount)
3594 : : return;
3595 : :
3596 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->default_hit);
3597 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw7);
3598 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw6);
3599 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw5);
3600 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_ctr);
3601 : : simple_free(default_stc);
3602 : 0 : ctx->common_res[tbl_type].default_stc = NULL;
3603 : : }
3604 : :
3605 : : static void mlx5dr_action_modify_write(struct mlx5dr_send_engine *queue,
3606 : : uint32_t arg_idx,
3607 : : uint8_t *arg_data,
3608 : : uint16_t num_of_actions)
3609 : : {
3610 : 0 : mlx5dr_arg_write(queue, NULL, arg_idx, arg_data,
3611 : 0 : num_of_actions * MLX5DR_MODIFY_ACTION_SIZE);
3612 : 0 : }
3613 : :
3614 : : void
3615 : 0 : mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,
3616 : : uint16_t num_of_actions)
3617 : : {
3618 : : uint8_t *e_src;
3619 : : int i;
3620 : :
3621 : : /* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes
3622 : : * copy from end of src to the start of dst.
3623 : : * move to the end, 2 is the leftover from 14B or 18B
3624 : : */
3625 [ # # ]: 0 : if (num_of_actions == DECAP_L3_NUM_ACTIONS_W_NO_VLAN)
3626 : 0 : e_src = src + MLX5DR_ACTION_HDR_LEN_L2;
3627 : : else
3628 : 0 : e_src = src + MLX5DR_ACTION_HDR_LEN_L2_W_VLAN;
3629 : :
3630 : : /* Move dst over the first remove action + zero data */
3631 : : dst += MLX5DR_ACTION_DOUBLE_SIZE;
3632 : : /* Move dst over the first insert ctrl action */
3633 : 0 : dst += MLX5DR_ACTION_DOUBLE_SIZE / 2;
3634 : : /* Actions:
3635 : : * no vlan: r_h-insert_4b-insert_4b-insert_4b-insert_4b-remove_2b.
3636 : : * with vlan: r_h-insert_4b-insert_4b-insert_4b-insert_4b-insert_4b-remove_2b.
3637 : : * the loop is without the last insertion.
3638 : : */
3639 [ # # ]: 0 : for (i = 0; i < num_of_actions - 3; i++) {
3640 : 0 : e_src -= MLX5DR_ACTION_INLINE_DATA_SIZE;
3641 : : memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE); /* data */
3642 : 0 : dst += MLX5DR_ACTION_DOUBLE_SIZE;
3643 : : }
3644 : : /* Copy the last 2 bytes after a gap of 2 bytes which will be removed */
3645 : 0 : e_src -= MLX5DR_ACTION_INLINE_DATA_SIZE / 2;
3646 : 0 : dst += MLX5DR_ACTION_INLINE_DATA_SIZE / 2;
3647 : : memcpy(dst, e_src, 2);
3648 : 0 : }
3649 : :
3650 : : static int mlx5dr_action_get_shared_stc_offset(struct mlx5dr_context_common_res *common_res,
3651 : : enum mlx5dr_context_shared_stc_type stc_type)
3652 : : {
3653 : 0 : return common_res->shared_stc[stc_type]->remove_header.offset;
3654 : : }
3655 : :
3656 : : static struct mlx5dr_actions_wqe_setter *
3657 : : mlx5dr_action_setter_find_first(struct mlx5dr_actions_wqe_setter *setter,
3658 : : uint8_t req_flags)
3659 : : {
3660 : : /* Use a new setter if requested flags are taken */
3661 [ # # # # : 0 : while (setter->flags & req_flags)
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
3662 : 0 : setter++;
3663 : :
3664 : : /* Use current setter in required flags are not used */
3665 : : return setter;
3666 : : }
3667 : :
3668 : : static void
3669 : : mlx5dr_action_apply_stc(struct mlx5dr_actions_apply_data *apply,
3670 : : enum mlx5dr_action_stc_idx stc_idx,
3671 : : uint8_t action_idx)
3672 : : {
3673 : 0 : struct mlx5dr_action *action = apply->rule_action[action_idx].action;
3674 : :
3675 : 0 : apply->wqe_ctrl->stc_ix[stc_idx] =
3676 : 0 : htobe32(action->stc[apply->tbl_type].offset);
3677 : : }
3678 : :
3679 : : static void
3680 : 0 : mlx5dr_action_setter_push_vlan(struct mlx5dr_actions_apply_data *apply,
3681 : : struct mlx5dr_actions_wqe_setter *setter)
3682 : : {
3683 : : struct mlx5dr_rule_action *rule_action;
3684 : :
3685 : 0 : rule_action = &apply->rule_action[setter->idx_double];
3686 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
3687 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = rule_action->push_vlan.vlan_hdr;
3688 : :
3689 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW6, setter->idx_double);
3690 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
3691 : 0 : }
3692 : :
3693 : : static void
3694 : 0 : mlx5dr_action_setter_modify_header(struct mlx5dr_actions_apply_data *apply,
3695 : : struct mlx5dr_actions_wqe_setter *setter)
3696 : : {
3697 : : struct mlx5dr_rule_action *rule_action;
3698 : : uint32_t stc_idx, arg_sz, arg_idx;
3699 : : struct mlx5dr_action *action;
3700 : : uint8_t *single_action;
3701 : :
3702 : 0 : rule_action = &apply->rule_action[setter->idx_double];
3703 : 0 : action = rule_action->action + rule_action->modify_header.pattern_idx;
3704 : :
3705 [ # # ]: 0 : stc_idx = htobe32(action->stc[apply->tbl_type].offset);
3706 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
3707 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
3708 : :
3709 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
3710 : :
3711 [ # # ]: 0 : if (action->modify_header.num_of_actions == 1) {
3712 : 0 : if (action->modify_header.single_action_type ==
3713 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_COPY ||
3714 : : action->modify_header.single_action_type ==
3715 : : MLX5_MODIFICATION_TYPE_ADD_FIELD) {
3716 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = 0;
3717 : 0 : return;
3718 : : }
3719 : :
3720 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
3721 : 0 : single_action = (uint8_t *)&action->modify_header.single_action;
3722 : : else
3723 : 0 : single_action = rule_action->modify_header.data;
3724 : :
3725 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] =
3726 : : *(__be32 *)MLX5_ADDR_OF(set_action_in, single_action, data);
3727 : : } else {
3728 : : /* Argument offset multiple with number of args per these actions */
3729 : 0 : arg_sz = mlx5dr_arg_get_arg_size(action->modify_header.max_num_of_actions);
3730 : 0 : arg_idx = rule_action->modify_header.offset * arg_sz;
3731 : :
3732 [ # # ]: 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
3733 : :
3734 [ # # ]: 0 : if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
3735 : 0 : apply->require_dep = 1;
3736 : 0 : mlx5dr_action_modify_write(apply->queue,
3737 : 0 : action->modify_header.arg_obj->id + arg_idx,
3738 : : rule_action->modify_header.data,
3739 : 0 : action->modify_header.num_of_actions);
3740 : : }
3741 : : }
3742 : : }
3743 : :
3744 : : static void
3745 : 0 : mlx5dr_action_setter_nat64(struct mlx5dr_actions_apply_data *apply,
3746 : : struct mlx5dr_actions_wqe_setter *setter)
3747 : : {
3748 : : struct mlx5dr_rule_action *rule_action;
3749 : : struct mlx5dr_action *cur_stage_action;
3750 : : struct mlx5dr_action *action;
3751 : : uint32_t stc_idx;
3752 : :
3753 : 0 : rule_action = &apply->rule_action[setter->idx_double];
3754 : 0 : action = rule_action->action;
3755 : 0 : cur_stage_action = action->nat64.stages[setter->stage_idx];
3756 : :
3757 : 0 : stc_idx = htobe32(cur_stage_action->stc[apply->tbl_type].offset);
3758 : :
3759 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
3760 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
3761 : :
3762 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
3763 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = 0;
3764 : 0 : }
3765 : :
3766 : : static void
3767 : 0 : mlx5dr_action_setter_insert_ptr(struct mlx5dr_actions_apply_data *apply,
3768 : : struct mlx5dr_actions_wqe_setter *setter)
3769 : : {
3770 : : struct mlx5dr_rule_action *rule_action;
3771 : : uint32_t stc_idx, arg_idx, arg_sz;
3772 : : struct mlx5dr_action *action;
3773 : :
3774 : 0 : rule_action = &apply->rule_action[setter->idx_double];
3775 : 0 : action = rule_action->action + rule_action->reformat.hdr_idx;
3776 : :
3777 : : /* Argument offset multiple on args required for header size */
3778 : 0 : arg_sz = mlx5dr_arg_data_size_to_arg_size(action->reformat.max_hdr_sz);
3779 : 0 : arg_idx = rule_action->reformat.offset * arg_sz;
3780 : :
3781 [ # # ]: 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
3782 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
3783 : :
3784 : 0 : stc_idx = htobe32(action->stc[apply->tbl_type].offset);
3785 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
3786 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
3787 : :
3788 [ # # ]: 0 : if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
3789 : 0 : apply->require_dep = 1;
3790 : 0 : mlx5dr_arg_write(apply->queue, NULL,
3791 : 0 : action->reformat.arg_obj->id + arg_idx,
3792 : : rule_action->reformat.data,
3793 : 0 : action->reformat.header_size);
3794 : : }
3795 : 0 : }
3796 : :
3797 : : static void
3798 : 0 : mlx5dr_action_setter_tnl_l3_to_l2(struct mlx5dr_actions_apply_data *apply,
3799 : : struct mlx5dr_actions_wqe_setter *setter)
3800 : : {
3801 : : struct mlx5dr_rule_action *rule_action;
3802 : : uint32_t stc_idx, arg_sz, arg_idx;
3803 : : struct mlx5dr_action *action;
3804 : :
3805 : 0 : rule_action = &apply->rule_action[setter->idx_double];
3806 : 0 : action = rule_action->action + rule_action->reformat.hdr_idx;
3807 : :
3808 : : /* Argument offset multiple on args required for num of actions */
3809 : 0 : arg_sz = mlx5dr_arg_get_arg_size(action->modify_header.max_num_of_actions);
3810 : 0 : arg_idx = rule_action->reformat.offset * arg_sz;
3811 : :
3812 [ # # ]: 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
3813 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
3814 : :
3815 : 0 : stc_idx = htobe32(action->stc[apply->tbl_type].offset);
3816 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
3817 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
3818 : :
3819 [ # # ]: 0 : if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
3820 : 0 : apply->require_dep = 1;
3821 : 0 : mlx5dr_arg_decapl3_write(apply->queue,
3822 : 0 : action->modify_header.arg_obj->id + arg_idx,
3823 : : rule_action->reformat.data,
3824 : 0 : action->modify_header.num_of_actions);
3825 : : }
3826 : 0 : }
3827 : :
3828 : : static void
3829 : 0 : mlx5dr_action_setter_aso(struct mlx5dr_actions_apply_data *apply,
3830 : : struct mlx5dr_actions_wqe_setter *setter)
3831 : : {
3832 : : struct mlx5dr_rule_action *rule_action;
3833 : : uint32_t exe_aso_ctrl;
3834 : : uint32_t offset;
3835 : :
3836 : 0 : rule_action = &apply->rule_action[setter->idx_double];
3837 : :
3838 [ # # # ]: 0 : switch (rule_action->action->type) {
3839 : 0 : case MLX5DR_ACTION_TYP_ASO_METER:
3840 : : /* exe_aso_ctrl format:
3841 : : * [STC only and reserved bits 29b][init_color 2b][meter_id 1b]
3842 : : */
3843 : 0 : offset = rule_action->aso_meter.offset / MLX5_ASO_METER_NUM_PER_OBJ;
3844 : 0 : exe_aso_ctrl = rule_action->aso_meter.offset % MLX5_ASO_METER_NUM_PER_OBJ;
3845 : 0 : exe_aso_ctrl |= rule_action->aso_meter.init_color <<
3846 : : MLX5DR_ACTION_METER_INIT_COLOR_OFFSET;
3847 : 0 : break;
3848 : 0 : case MLX5DR_ACTION_TYP_ASO_CT:
3849 : : /* exe_aso_ctrl CT format:
3850 : : * [STC only and reserved bits 31b][direction 1b]
3851 : : */
3852 : 0 : offset = rule_action->aso_ct.offset / MLX5_ASO_CT_NUM_PER_OBJ;
3853 : 0 : exe_aso_ctrl = rule_action->aso_ct.direction;
3854 : 0 : break;
3855 : 0 : default:
3856 : 0 : DR_LOG(ERR, "Unsupported ASO action type: %d", rule_action->action->type);
3857 : 0 : rte_errno = ENOTSUP;
3858 : 0 : return;
3859 : : }
3860 : :
3861 : : /* aso_object_offset format: [24B] */
3862 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = htobe32(offset);
3863 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(exe_aso_ctrl);
3864 : :
3865 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW6, setter->idx_double);
3866 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
3867 : : }
3868 : :
3869 : : static void
3870 : 0 : mlx5dr_action_setter_tag(struct mlx5dr_actions_apply_data *apply,
3871 : : struct mlx5dr_actions_wqe_setter *setter)
3872 : : {
3873 : : struct mlx5dr_rule_action *rule_action;
3874 : :
3875 : 0 : rule_action = &apply->rule_action[setter->idx_single];
3876 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = htobe32(rule_action->tag.value);
3877 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW5, setter->idx_single);
3878 : 0 : }
3879 : :
3880 : : static void
3881 : 0 : mlx5dr_action_setter_ctrl_ctr(struct mlx5dr_actions_apply_data *apply,
3882 : : struct mlx5dr_actions_wqe_setter *setter)
3883 : : {
3884 : : struct mlx5dr_rule_action *rule_action;
3885 : :
3886 : 0 : rule_action = &apply->rule_action[setter->idx_ctr];
3887 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW0] = htobe32(rule_action->counter.offset);
3888 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_CTRL, setter->idx_ctr);
3889 : 0 : }
3890 : :
3891 : : static void
3892 : 0 : mlx5dr_action_setter_single(struct mlx5dr_actions_apply_data *apply,
3893 : : struct mlx5dr_actions_wqe_setter *setter)
3894 : : {
3895 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
3896 : 0 : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW5, setter->idx_single);
3897 : 0 : }
3898 : :
3899 : : static void
3900 : 0 : mlx5dr_action_setter_single_double_pop(struct mlx5dr_actions_apply_data *apply,
3901 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3902 : : {
3903 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
3904 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
3905 : 0 : htobe32(mlx5dr_action_get_shared_stc_offset(apply->common_res,
3906 : : MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP));
3907 : 0 : }
3908 : :
3909 : : static void
3910 : 0 : mlx5dr_action_setter_hit(struct mlx5dr_actions_apply_data *apply,
3911 : : struct mlx5dr_actions_wqe_setter *setter)
3912 : : {
3913 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = 0;
3914 : 0 : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_HIT, setter->idx_hit);
3915 : 0 : }
3916 : :
3917 : : static void
3918 : 0 : mlx5dr_action_setter_default_hit(struct mlx5dr_actions_apply_data *apply,
3919 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3920 : : {
3921 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = 0;
3922 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_HIT] =
3923 : 0 : htobe32(apply->common_res->default_stc->default_hit.offset);
3924 : 0 : }
3925 : :
3926 : : static void
3927 : 0 : mlx5dr_action_setter_hit_matcher(struct mlx5dr_actions_apply_data *apply,
3928 : : struct mlx5dr_actions_wqe_setter *setter)
3929 : : {
3930 : : struct mlx5dr_rule_action *rule_action;
3931 : :
3932 : 0 : rule_action = &apply->rule_action[setter->idx_hit];
3933 : :
3934 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] =
3935 : 0 : htobe32(rule_action->jump_to_matcher.offset << 6);
3936 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_HIT, setter->idx_hit);
3937 : 0 : }
3938 : :
3939 : : static void
3940 : 0 : mlx5dr_action_setter_hit_next_action(struct mlx5dr_actions_apply_data *apply,
3941 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3942 : : {
3943 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = htobe32(apply->next_direct_idx << 6);
3944 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_HIT] = htobe32(apply->jump_to_action_stc);
3945 : 0 : }
3946 : :
3947 : : static void
3948 : 0 : mlx5dr_action_setter_common_decap(struct mlx5dr_actions_apply_data *apply,
3949 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3950 : : {
3951 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
3952 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
3953 : 0 : htobe32(mlx5dr_action_get_shared_stc_offset(apply->common_res,
3954 : : MLX5DR_CONTEXT_SHARED_STC_DECAP_L3));
3955 : 0 : }
3956 : :
3957 : : static void
3958 : 0 : mlx5dr_action_setter_ipv6_route_ext_gen_push_mhdr(uint8_t *data, void *mh_data)
3959 : : {
3960 : : uint8_t *action_ptr = mh_data;
3961 : : uint32_t *ipv6_dst_addr;
3962 : : uint8_t seg_left;
3963 : : uint32_t i;
3964 : :
3965 : : /* Fetch the last IPv6 address in the segment list which is the next hop */
3966 [ # # ]: 0 : seg_left = MLX5_GET(header_ipv6_routing_ext, data, segments_left) - 1;
3967 : 0 : ipv6_dst_addr = (uint32_t *)data + MLX5_ST_SZ_DW(header_ipv6_routing_ext)
3968 : 0 : + seg_left * MLX5_ST_SZ_DW(definer_hl_ipv6_addr);
3969 : :
3970 : : /* Load next hop IPv6 address in reverse order to ipv6.dst_address */
3971 [ # # ]: 0 : for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
3972 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, data, be32toh(*ipv6_dst_addr++));
3973 : 0 : action_ptr += MLX5DR_MODIFY_ACTION_SIZE;
3974 : : }
3975 : :
3976 : : /* Set ipv6_route_ext.next_hdr per user input */
3977 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, data, *data);
3978 : 0 : }
3979 : :
3980 : : static void
3981 : 0 : mlx5dr_action_setter_ipv6_route_ext_mhdr(struct mlx5dr_actions_apply_data *apply,
3982 : : struct mlx5dr_actions_wqe_setter *setter)
3983 : : {
3984 : 0 : struct mlx5dr_rule_action *rule_action = apply->rule_action;
3985 : 0 : struct mlx5dr_actions_wqe_setter tmp_setter = {0};
3986 : : struct mlx5dr_rule_action tmp_rule_action;
3987 : 0 : __be64 cmd[MLX5_SRV6_SAMPLE_NUM] = {0};
3988 : : struct mlx5dr_action *ipv6_ext_action;
3989 : : uint8_t *header;
3990 : :
3991 : 0 : header = rule_action[setter->idx_double].ipv6_ext.header;
3992 : 0 : ipv6_ext_action = rule_action[setter->idx_double].action;
3993 : 0 : tmp_rule_action.action = ipv6_ext_action->ipv6_route_ext.action[setter->extra_data];
3994 : :
3995 [ # # ]: 0 : if (tmp_rule_action.action->flags & MLX5DR_ACTION_FLAG_SHARED) {
3996 : 0 : tmp_rule_action.modify_header.offset = 0;
3997 : 0 : tmp_rule_action.modify_header.pattern_idx = 0;
3998 : 0 : tmp_rule_action.modify_header.data = NULL;
3999 : : } else {
4000 : : /*
4001 : : * Copy ipv6_dst from ipv6_route_ext.last_seg.
4002 : : * Set ipv6_route_ext.next_hdr.
4003 : : */
4004 : 0 : mlx5dr_action_setter_ipv6_route_ext_gen_push_mhdr(header, cmd);
4005 : 0 : tmp_rule_action.modify_header.data = (uint8_t *)cmd;
4006 : 0 : tmp_rule_action.modify_header.pattern_idx = 0;
4007 : 0 : tmp_rule_action.modify_header.offset =
4008 : 0 : rule_action[setter->idx_double].ipv6_ext.offset;
4009 : : }
4010 : :
4011 : 0 : apply->rule_action = &tmp_rule_action;
4012 : :
4013 : : /* Reuse regular */
4014 : 0 : mlx5dr_action_setter_modify_header(apply, &tmp_setter);
4015 : :
4016 : : /* Swap rule actions from backup */
4017 : 0 : apply->rule_action = rule_action;
4018 : 0 : }
4019 : :
4020 : : static void
4021 : 0 : mlx5dr_action_setter_ipv6_route_ext_insert_ptr(struct mlx5dr_actions_apply_data *apply,
4022 : : struct mlx5dr_actions_wqe_setter *setter)
4023 : : {
4024 : 0 : struct mlx5dr_rule_action *rule_action = apply->rule_action;
4025 : 0 : struct mlx5dr_actions_wqe_setter tmp_setter = {0};
4026 : : struct mlx5dr_rule_action tmp_rule_action;
4027 : : struct mlx5dr_action *ipv6_ext_action;
4028 : : uint8_t header[MLX5_PUSH_MAX_LEN];
4029 : :
4030 : 0 : ipv6_ext_action = rule_action[setter->idx_double].action;
4031 : 0 : tmp_rule_action.action = ipv6_ext_action->ipv6_route_ext.action[setter->extra_data];
4032 : :
4033 [ # # ]: 0 : if (tmp_rule_action.action->flags & MLX5DR_ACTION_FLAG_SHARED) {
4034 : 0 : tmp_rule_action.reformat.offset = 0;
4035 : 0 : tmp_rule_action.reformat.hdr_idx = 0;
4036 : 0 : tmp_rule_action.reformat.data = NULL;
4037 : : } else {
4038 : 0 : memcpy(header, rule_action[setter->idx_double].ipv6_ext.header,
4039 [ # # ]: 0 : tmp_rule_action.action->reformat.header_size);
4040 : : /* Clear ipv6_route_ext.next_hdr for right checksum */
4041 [ # # ]: 0 : MLX5_SET(header_ipv6_routing_ext, header, next_hdr, 0);
4042 : 0 : tmp_rule_action.reformat.data = header;
4043 : 0 : tmp_rule_action.reformat.hdr_idx = 0;
4044 : 0 : tmp_rule_action.reformat.offset =
4045 : 0 : rule_action[setter->idx_double].ipv6_ext.offset;
4046 : : }
4047 : :
4048 : 0 : apply->rule_action = &tmp_rule_action;
4049 : :
4050 : : /* Reuse regular */
4051 : 0 : mlx5dr_action_setter_insert_ptr(apply, &tmp_setter);
4052 : :
4053 : : /* Swap rule actions from backup */
4054 : 0 : apply->rule_action = rule_action;
4055 : 0 : }
4056 : :
4057 : : static void
4058 : 0 : mlx5dr_action_setter_ipv6_route_ext_pop(struct mlx5dr_actions_apply_data *apply,
4059 : : struct mlx5dr_actions_wqe_setter *setter)
4060 : : {
4061 : 0 : struct mlx5dr_rule_action *rule_action = &apply->rule_action[setter->idx_single];
4062 : : uint8_t idx = MLX5DR_ACTION_IPV6_EXT_MAX_SA - 1;
4063 : : struct mlx5dr_action *action;
4064 : :
4065 : : /* Pop the ipv6_route_ext as set_single logic */
4066 : 0 : action = rule_action->action->ipv6_route_ext.action[idx];
4067 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
4068 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
4069 : 0 : htobe32(action->stc[apply->tbl_type].offset);
4070 : 0 : }
4071 : :
4072 : 0 : int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
4073 : : {
4074 : 0 : struct mlx5dr_actions_wqe_setter *start_setter = at->setters + 1;
4075 : 0 : enum mlx5dr_action_type *action_type = at->action_type_arr;
4076 : 0 : struct mlx5dr_actions_wqe_setter *setter = at->setters;
4077 : : struct mlx5dr_actions_wqe_setter *pop_setter = NULL;
4078 : : struct mlx5dr_actions_wqe_setter *last_setter;
4079 : : int i, j;
4080 : :
4081 : : /* Note: Given action combination must be valid */
4082 : :
4083 : : /* Check if action were already processed */
4084 [ # # ]: 0 : if (at->num_of_action_stes)
4085 : : return 0;
4086 : :
4087 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_MAX_STE; i++)
4088 : 0 : setter[i].set_hit = &mlx5dr_action_setter_hit_next_action;
4089 : :
4090 : : /* The same action template setters can be used with jumbo or match
4091 : : * STE, to support both cases we reseve the first setter for cases
4092 : : * with jumbo STE to allow jump to the first action STE.
4093 : : * This extra setter can be reduced in some cases on rule creation.
4094 : : */
4095 : : setter = start_setter;
4096 : : last_setter = start_setter;
4097 : :
4098 [ # # ]: 0 : for (i = 0; i < at->num_actions; i++) {
4099 [ # # # # : 0 : switch (action_type[i]) {
# # # # #
# # # # #
# # ]
4100 : 0 : case MLX5DR_ACTION_TYP_DROP:
4101 : : case MLX5DR_ACTION_TYP_TIR:
4102 : : case MLX5DR_ACTION_TYP_TBL:
4103 : : case MLX5DR_ACTION_TYP_DEST_ROOT:
4104 : : case MLX5DR_ACTION_TYP_DEST_ARRAY:
4105 : : case MLX5DR_ACTION_TYP_VPORT:
4106 : : case MLX5DR_ACTION_TYP_MISS:
4107 : : /* Hit action */
4108 : 0 : last_setter->flags |= ASF_HIT;
4109 : 0 : last_setter->set_hit = &mlx5dr_action_setter_hit;
4110 : 0 : last_setter->idx_hit = i;
4111 : 0 : break;
4112 : :
4113 : 0 : case MLX5DR_ACTION_TYP_POP_VLAN:
4114 : : /* Single remove header to header */
4115 [ # # ]: 0 : if (pop_setter) {
4116 : : /* We have 2 pops, use the shared */
4117 : 0 : pop_setter->set_single = &mlx5dr_action_setter_single_double_pop;
4118 : 0 : break;
4119 : : }
4120 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_SINGLE1 | ASF_MODIFY | ASF_INSERT);
4121 : 0 : setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
4122 : 0 : setter->set_single = &mlx5dr_action_setter_single;
4123 : 0 : setter->idx_single = i;
4124 : : pop_setter = setter;
4125 : 0 : break;
4126 : :
4127 : : case MLX5DR_ACTION_TYP_PUSH_VLAN:
4128 : : /* Double insert inline */
4129 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
4130 : 0 : setter->flags |= ASF_DOUBLE | ASF_INSERT;
4131 : 0 : setter->set_double = &mlx5dr_action_setter_push_vlan;
4132 : 0 : setter->idx_double = i;
4133 : 0 : break;
4134 : :
4135 : : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
4136 : : /*
4137 : : * Backup ipv6_route_ext.next_hdr to ipv6_route_ext.seg_left.
4138 : : * Set ipv6_route_ext.next_hdr to 0 for checksum bug.
4139 : : */
4140 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
4141 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
4142 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
4143 : 0 : setter->idx_double = i;
4144 : 0 : setter->extra_data = 0;
4145 : : setter++;
4146 : :
4147 : : /*
4148 : : * Restore ipv6_route_ext.next_hdr from ipv6_route_ext.seg_left.
4149 : : * Load the final destination address from flex parser sample 1->4.
4150 : : */
4151 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
4152 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
4153 : 0 : setter->idx_double = i;
4154 : 0 : setter->extra_data = 1;
4155 : 0 : setter++;
4156 : :
4157 : : /* Set the ipv6.protocol per ipv6_route_ext.next_hdr */
4158 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
4159 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
4160 : 0 : setter->idx_double = i;
4161 : 0 : setter->extra_data = 2;
4162 : : /* Pop ipv6_route_ext */
4163 : 0 : setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
4164 : 0 : setter->set_single = &mlx5dr_action_setter_ipv6_route_ext_pop;
4165 : 0 : setter->idx_single = i;
4166 : 0 : at->need_dep_write = true;
4167 : 0 : break;
4168 : :
4169 : : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
4170 : : /* Insert ipv6_route_ext with next_hdr as 0 due to checksum bug */
4171 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
4172 : 0 : setter->flags |= ASF_DOUBLE | ASF_INSERT;
4173 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_insert_ptr;
4174 : 0 : setter->idx_double = i;
4175 : 0 : setter->extra_data = 0;
4176 : : setter++;
4177 : :
4178 : : /* Set ipv6.protocol as IPPROTO_ROUTING: 0x2b */
4179 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
4180 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
4181 : 0 : setter->idx_double = i;
4182 : 0 : setter->extra_data = 1;
4183 : 0 : setter++;
4184 : :
4185 : : /*
4186 : : * Load the right ipv6_route_ext.next_hdr per user input buffer.
4187 : : * Load the next dest_addr from the ipv6_route_ext.seg_list[last].
4188 : : */
4189 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
4190 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
4191 : 0 : setter->idx_double = i;
4192 : 0 : setter->extra_data = 2;
4193 : 0 : at->need_dep_write = true;
4194 : 0 : break;
4195 : :
4196 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
4197 : : /* Double modify header list */
4198 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
4199 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
4200 : 0 : setter->set_double = &mlx5dr_action_setter_modify_header;
4201 : 0 : setter->idx_double = i;
4202 : 0 : at->need_dep_write = true;
4203 : 0 : break;
4204 : :
4205 : : case MLX5DR_ACTION_TYP_ASO_METER:
4206 : : case MLX5DR_ACTION_TYP_ASO_CT:
4207 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE);
4208 : 0 : setter->flags |= ASF_DOUBLE;
4209 : 0 : setter->set_double = &mlx5dr_action_setter_aso;
4210 : 0 : setter->idx_double = i;
4211 : 0 : break;
4212 : :
4213 : : case MLX5DR_ACTION_TYP_REMOVE_HEADER:
4214 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
4215 : : /* Single remove header to header */
4216 : : setter = mlx5dr_action_setter_find_first(last_setter,
4217 : : ASF_SINGLE1 | ASF_MODIFY | ASF_INSERT);
4218 : 0 : setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
4219 : 0 : setter->set_single = &mlx5dr_action_setter_single;
4220 : 0 : setter->idx_single = i;
4221 : 0 : break;
4222 : :
4223 : : case MLX5DR_ACTION_TYP_INSERT_HEADER:
4224 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
4225 : : /* Double insert header with pointer */
4226 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
4227 : 0 : setter->flags |= ASF_DOUBLE | ASF_INSERT;
4228 : 0 : setter->set_double = &mlx5dr_action_setter_insert_ptr;
4229 : 0 : setter->idx_double = i;
4230 : 0 : at->need_dep_write = true;
4231 : 0 : break;
4232 : :
4233 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
4234 : : /* Single remove + Double insert header with pointer */
4235 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_SINGLE1 | ASF_DOUBLE);
4236 : 0 : setter->flags |= ASF_SINGLE1 | ASF_DOUBLE;
4237 : 0 : setter->set_double = &mlx5dr_action_setter_insert_ptr;
4238 : 0 : setter->idx_double = i;
4239 : 0 : setter->set_single = &mlx5dr_action_setter_common_decap;
4240 : 0 : setter->idx_single = i;
4241 : 0 : at->need_dep_write = true;
4242 : 0 : break;
4243 : :
4244 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
4245 : : /* Double modify header list with remove and push inline */
4246 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
4247 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY | ASF_INSERT;
4248 : 0 : setter->set_double = &mlx5dr_action_setter_tnl_l3_to_l2;
4249 : 0 : setter->idx_double = i;
4250 : 0 : at->need_dep_write = true;
4251 : 0 : break;
4252 : :
4253 : : case MLX5DR_ACTION_TYP_TAG:
4254 : : /* Single TAG action, search for any room from the start */
4255 : : setter = mlx5dr_action_setter_find_first(start_setter, ASF_SINGLE1);
4256 : 0 : setter->flags |= ASF_SINGLE1;
4257 : 0 : setter->set_single = &mlx5dr_action_setter_tag;
4258 : 0 : setter->idx_single = i;
4259 : 0 : break;
4260 : :
4261 : : case MLX5DR_ACTION_TYP_CTR:
4262 : : /* Control counter action
4263 : : * TODO: Current counter executed first. Support is needed
4264 : : * for single ation counter action which is done last.
4265 : : * Example: Decap + CTR
4266 : : */
4267 : : setter = mlx5dr_action_setter_find_first(start_setter, ASF_CTR);
4268 : 0 : setter->flags |= ASF_CTR;
4269 : 0 : setter->set_ctr = &mlx5dr_action_setter_ctrl_ctr;
4270 : 0 : setter->idx_ctr = i;
4271 : 0 : break;
4272 : :
4273 : : case MLX5DR_ACTION_TYP_NAT64:
4274 : : /* NAT64 requires 3 setters, each of them does specific modify header */
4275 [ # # ]: 0 : for (j = 0; j < MLX5DR_ACTION_NAT64_STAGES; j++) {
4276 : : setter = mlx5dr_action_setter_find_first(last_setter,
4277 : : ASF_DOUBLE | ASF_REMOVE);
4278 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
4279 : 0 : setter->set_double = &mlx5dr_action_setter_nat64;
4280 : 0 : setter->idx_double = i;
4281 : : /* The stage indicates which modify-header to push */
4282 : 0 : setter->stage_idx = j;
4283 : : }
4284 : : break;
4285 : :
4286 : 0 : case MLX5DR_ACTION_TYP_JUMP_TO_MATCHER:
4287 : 0 : last_setter->flags |= ASF_HIT;
4288 : 0 : last_setter->set_hit = &mlx5dr_action_setter_hit_matcher;
4289 : 0 : last_setter->idx_hit = i;
4290 : 0 : break;
4291 : :
4292 : 0 : default:
4293 : 0 : DR_LOG(ERR, "Unsupported action type: %d", action_type[i]);
4294 : 0 : rte_errno = ENOTSUP;
4295 : 0 : assert(false);
4296 : : return rte_errno;
4297 : : }
4298 : :
4299 : 0 : last_setter = RTE_MAX(setter, last_setter);
4300 : : }
4301 : :
4302 : : /* Set default hit on the last STE if no hit action provided */
4303 [ # # ]: 0 : if (!(last_setter->flags & ASF_HIT))
4304 : 0 : last_setter->set_hit = &mlx5dr_action_setter_default_hit;
4305 : :
4306 : 0 : at->num_of_action_stes = last_setter - start_setter + 1;
4307 : :
4308 : : /* Check if action template doesn't require any action DWs */
4309 [ # # ]: 0 : at->only_term = (at->num_of_action_stes == 1) &&
4310 [ # # ]: 0 : !(last_setter->flags & ~(ASF_CTR | ASF_HIT));
4311 : :
4312 : 0 : return 0;
4313 : : }
4314 : :
4315 : : struct mlx5dr_action_template *
4316 : 0 : mlx5dr_action_template_create(const enum mlx5dr_action_type action_type[],
4317 : : uint32_t flags)
4318 : : {
4319 : : struct mlx5dr_action_template *at;
4320 : : uint8_t num_actions = 0;
4321 : : int i;
4322 : :
4323 [ # # ]: 0 : if (flags > MLX5DR_ACTION_TEMPLATE_FLAG_RELAXED_ORDER) {
4324 : 0 : DR_LOG(ERR, "Unsupported action template flag provided");
4325 : 0 : rte_errno = EINVAL;
4326 : 0 : return NULL;
4327 : : }
4328 : :
4329 : : at = simple_calloc(1, sizeof(*at));
4330 [ # # ]: 0 : if (!at) {
4331 : 0 : DR_LOG(ERR, "Failed to allocate action template");
4332 : 0 : rte_errno = ENOMEM;
4333 : 0 : return NULL;
4334 : : }
4335 : :
4336 : 0 : at->flags = flags;
4337 : :
4338 [ # # ]: 0 : while (action_type[num_actions++] != MLX5DR_ACTION_TYP_LAST)
4339 : : ;
4340 : :
4341 : 0 : at->num_actions = num_actions - 1;
4342 : 0 : at->action_type_arr = simple_calloc(num_actions, sizeof(*action_type));
4343 [ # # ]: 0 : if (!at->action_type_arr) {
4344 : 0 : DR_LOG(ERR, "Failed to allocate action type array");
4345 : 0 : rte_errno = ENOMEM;
4346 : 0 : goto free_at;
4347 : : }
4348 : :
4349 [ # # ]: 0 : for (i = 0; i < num_actions; i++)
4350 : 0 : at->action_type_arr[i] = action_type[i];
4351 : :
4352 : : return at;
4353 : :
4354 : : free_at:
4355 : : simple_free(at);
4356 : 0 : return NULL;
4357 : : }
4358 : :
4359 : 0 : int mlx5dr_action_template_destroy(struct mlx5dr_action_template *at)
4360 : : {
4361 : 0 : simple_free(at->action_type_arr);
4362 : : simple_free(at);
4363 : 0 : return 0;
4364 : : }
|