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 : : /* This is the maximum allowed action order for each table type:
14 : : * TX: POP_VLAN, CTR, ASO_METER, AS_CT, PUSH_VLAN, MODIFY, ENCAP, Term
15 : : * RX: TAG, DECAP, POP_VLAN, CTR, ASO_METER, ASO_CT, PUSH_VLAN, MODIFY,
16 : : * ENCAP, Term
17 : : * FDB: DECAP, POP_VLAN, CTR, ASO_METER, ASO_CT, PUSH_VLAN, MODIFY,
18 : : * ENCAP, Term
19 : : */
20 : : static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_MAX] = {
21 : : [MLX5DR_TABLE_TYPE_NIC_RX] = {
22 : : BIT(MLX5DR_ACTION_TYP_TAG),
23 : : BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) |
24 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
25 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) |
26 : : BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT),
27 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
28 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
29 : : BIT(MLX5DR_ACTION_TYP_CTR),
30 : : BIT(MLX5DR_ACTION_TYP_ASO_METER),
31 : : BIT(MLX5DR_ACTION_TYP_ASO_CT),
32 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
33 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
34 : : BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
35 : : BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
36 : : BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
37 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
38 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
39 : : BIT(MLX5DR_ACTION_TYP_TBL) |
40 : : BIT(MLX5DR_ACTION_TYP_MISS) |
41 : : BIT(MLX5DR_ACTION_TYP_TIR) |
42 : : BIT(MLX5DR_ACTION_TYP_DROP) |
43 : : BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
44 : : BIT(MLX5DR_ACTION_TYP_DEST_ARRAY),
45 : : BIT(MLX5DR_ACTION_TYP_LAST),
46 : : },
47 : : [MLX5DR_TABLE_TYPE_NIC_TX] = {
48 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
49 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
50 : : BIT(MLX5DR_ACTION_TYP_CTR),
51 : : BIT(MLX5DR_ACTION_TYP_ASO_METER),
52 : : BIT(MLX5DR_ACTION_TYP_ASO_CT),
53 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
54 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
55 : : BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
56 : : BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
57 : : BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
58 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
59 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
60 : : BIT(MLX5DR_ACTION_TYP_TBL) |
61 : : BIT(MLX5DR_ACTION_TYP_MISS) |
62 : : BIT(MLX5DR_ACTION_TYP_DROP) |
63 : : BIT(MLX5DR_ACTION_TYP_DEST_ROOT),
64 : : BIT(MLX5DR_ACTION_TYP_LAST),
65 : : },
66 : : [MLX5DR_TABLE_TYPE_FDB] = {
67 : : BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) |
68 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
69 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) |
70 : : BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT),
71 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
72 : : BIT(MLX5DR_ACTION_TYP_POP_VLAN),
73 : : BIT(MLX5DR_ACTION_TYP_CTR),
74 : : BIT(MLX5DR_ACTION_TYP_ASO_METER),
75 : : BIT(MLX5DR_ACTION_TYP_ASO_CT),
76 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
77 : : BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
78 : : BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
79 : : BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
80 : : BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
81 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
82 : : BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
83 : : BIT(MLX5DR_ACTION_TYP_TBL) |
84 : : BIT(MLX5DR_ACTION_TYP_MISS) |
85 : : BIT(MLX5DR_ACTION_TYP_VPORT) |
86 : : BIT(MLX5DR_ACTION_TYP_DROP) |
87 : : BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
88 : : BIT(MLX5DR_ACTION_TYP_DEST_ARRAY),
89 : : BIT(MLX5DR_ACTION_TYP_LAST),
90 : : },
91 : : };
92 : :
93 : 0 : static int mlx5dr_action_get_shared_stc_nic(struct mlx5dr_context *ctx,
94 : : enum mlx5dr_context_shared_stc_type stc_type,
95 : : uint8_t tbl_type)
96 : : {
97 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
98 : : struct mlx5dr_action_shared_stc *shared_stc;
99 : : int ret;
100 : :
101 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
102 [ # # ]: 0 : if (ctx->common_res[tbl_type].shared_stc[stc_type]) {
103 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type]->refcount++;
104 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
105 : 0 : return 0;
106 : : }
107 : :
108 : : shared_stc = simple_calloc(1, sizeof(*shared_stc));
109 [ # # ]: 0 : if (!shared_stc) {
110 : 0 : DR_LOG(ERR, "Failed to allocate memory for shared STCs");
111 : 0 : rte_errno = ENOMEM;
112 : 0 : goto unlock_and_out;
113 : : }
114 [ # # # ]: 0 : switch (stc_type) {
115 : 0 : case MLX5DR_CONTEXT_SHARED_STC_DECAP_L3:
116 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
117 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
118 : 0 : stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
119 : 0 : stc_attr.remove_header.decap = 0;
120 : 0 : stc_attr.remove_header.start_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
121 : 0 : stc_attr.remove_header.end_anchor = MLX5_HEADER_ANCHOR_IPV6_IPV4;
122 : 0 : break;
123 : 0 : case MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP:
124 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
125 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
126 : 0 : stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
127 : 0 : stc_attr.remove_words.start_anchor = MLX5_HEADER_ANCHOR_FIRST_VLAN_START;
128 : 0 : stc_attr.remove_words.num_of_words = MLX5DR_ACTION_HDR_LEN_L2_VLAN;
129 : 0 : break;
130 : 0 : default:
131 : 0 : DR_LOG(ERR, "No such type : stc_type");
132 : 0 : assert(false);
133 : : rte_errno = EINVAL;
134 : : goto unlock_and_out;
135 : : }
136 : :
137 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
138 : : &shared_stc->remove_header);
139 [ # # ]: 0 : if (ret) {
140 : 0 : DR_LOG(ERR, "Failed to allocate shared decap l2 STC");
141 : 0 : goto free_shared_stc;
142 : : }
143 : :
144 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type] = shared_stc;
145 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type]->refcount = 1;
146 : :
147 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
148 : :
149 : 0 : return 0;
150 : :
151 : : free_shared_stc:
152 : : simple_free(shared_stc);
153 : 0 : unlock_and_out:
154 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
155 : 0 : return rte_errno;
156 : : }
157 : :
158 : 0 : static void mlx5dr_action_put_shared_stc_nic(struct mlx5dr_context *ctx,
159 : : enum mlx5dr_context_shared_stc_type stc_type,
160 : : uint8_t tbl_type)
161 : : {
162 : : struct mlx5dr_action_shared_stc *shared_stc;
163 : :
164 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
165 [ # # ]: 0 : if (--ctx->common_res[tbl_type].shared_stc[stc_type]->refcount) {
166 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
167 : 0 : return;
168 : : }
169 : :
170 : : shared_stc = ctx->common_res[tbl_type].shared_stc[stc_type];
171 : :
172 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &shared_stc->remove_header);
173 : : simple_free(shared_stc);
174 : 0 : ctx->common_res[tbl_type].shared_stc[stc_type] = NULL;
175 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
176 : : }
177 : :
178 : 0 : static int mlx5dr_action_get_shared_stc(struct mlx5dr_action *action,
179 : : enum mlx5dr_context_shared_stc_type stc_type)
180 : : {
181 : 0 : struct mlx5dr_context *ctx = action->ctx;
182 : : int ret;
183 : :
184 [ # # ]: 0 : if (stc_type >= MLX5DR_CONTEXT_SHARED_STC_MAX) {
185 : 0 : assert(false);
186 : : rte_errno = EINVAL;
187 : : return rte_errno;
188 : : }
189 : :
190 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX) {
191 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
192 [ # # ]: 0 : if (ret) {
193 : 0 : DR_LOG(ERR, "Failed to allocate memory for RX shared STCs (type: %d)",
194 : : stc_type);
195 : 0 : return ret;
196 : : }
197 : : }
198 : :
199 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX) {
200 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
201 [ # # ]: 0 : if (ret) {
202 : 0 : DR_LOG(ERR, "Failed to allocate memory for TX shared STCs(type: %d)",
203 : : stc_type);
204 : 0 : goto clean_nic_rx_stc;
205 : : }
206 : : }
207 : :
208 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB) {
209 : 0 : ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
210 [ # # ]: 0 : if (ret) {
211 : 0 : DR_LOG(ERR, "Failed to allocate memory for FDB shared STCs (type: %d)",
212 : : stc_type);
213 : 0 : goto clean_nic_tx_stc;
214 : : }
215 : : }
216 : :
217 : : return 0;
218 : :
219 : : clean_nic_tx_stc:
220 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
221 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
222 : 0 : clean_nic_rx_stc:
223 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
224 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
225 : :
226 : : return ret;
227 : : }
228 : :
229 : 0 : static void mlx5dr_action_put_shared_stc(struct mlx5dr_action *action,
230 : : enum mlx5dr_context_shared_stc_type stc_type)
231 : : {
232 : 0 : struct mlx5dr_context *ctx = action->ctx;
233 : :
234 [ # # ]: 0 : if (stc_type >= MLX5DR_CONTEXT_SHARED_STC_MAX) {
235 : 0 : assert(false);
236 : : return;
237 : : }
238 : :
239 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
240 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
241 : :
242 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
243 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
244 : :
245 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
246 : 0 : mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
247 : : }
248 : :
249 : 0 : static void mlx5dr_action_print_combo(enum mlx5dr_action_type *user_actions)
250 : : {
251 : 0 : DR_LOG(ERR, "Invalid action_type sequence");
252 [ # # ]: 0 : while (*user_actions != MLX5DR_ACTION_TYP_LAST) {
253 : 0 : DR_LOG(ERR, "%s", mlx5dr_debug_action_type_to_str(*user_actions));
254 : 0 : user_actions++;
255 : : }
256 : 0 : }
257 : :
258 : 0 : bool mlx5dr_action_check_combo(enum mlx5dr_action_type *user_actions,
259 : : enum mlx5dr_table_type table_type)
260 : : {
261 : 0 : const uint32_t *order_arr = action_order_arr[table_type];
262 : : uint8_t order_idx = 0;
263 : : uint8_t user_idx = 0;
264 : : bool valid_combo;
265 : :
266 [ # # ]: 0 : while (order_arr[order_idx] != BIT(MLX5DR_ACTION_TYP_LAST)) {
267 : : /* User action order validated move to next user action */
268 [ # # ]: 0 : if (BIT(user_actions[user_idx]) & order_arr[order_idx])
269 : 0 : user_idx++;
270 : :
271 : : /* Iterate to the next supported action in the order */
272 : 0 : order_idx++;
273 : : }
274 : :
275 : : /* Combination is valid if all user action were processed */
276 : 0 : valid_combo = user_actions[user_idx] == MLX5DR_ACTION_TYP_LAST;
277 [ # # ]: 0 : if (!valid_combo)
278 : 0 : mlx5dr_action_print_combo(user_actions);
279 : :
280 : 0 : return valid_combo;
281 : : }
282 : :
283 : 0 : int mlx5dr_action_root_build_attr(struct mlx5dr_rule_action rule_actions[],
284 : : uint32_t num_actions,
285 : : struct mlx5dv_flow_action_attr *attr)
286 : : {
287 : : struct mlx5dr_action *action;
288 : : uint32_t i;
289 : :
290 [ # # ]: 0 : for (i = 0; i < num_actions; i++) {
291 : 0 : action = rule_actions[i].action;
292 : :
293 [ # # # # : 0 : switch (action->type) {
# # # ]
294 : 0 : case MLX5DR_ACTION_TYP_TBL:
295 : : case MLX5DR_ACTION_TYP_TIR:
296 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_DEST_DEVX;
297 : 0 : attr[i].obj = action->devx_obj;
298 : 0 : break;
299 : 0 : case MLX5DR_ACTION_TYP_TAG:
300 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_TAG;
301 : 0 : attr[i].tag_value = rule_actions[i].tag.value;
302 : 0 : break;
303 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS
304 : 0 : case MLX5DR_ACTION_TYP_MISS:
305 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_DEFAULT_MISS;
306 : 0 : break;
307 : : #endif
308 : 0 : case MLX5DR_ACTION_TYP_DROP:
309 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_DROP;
310 : 0 : break;
311 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
312 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
313 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
314 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
315 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
316 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
317 : 0 : attr[i].action = action->flow_action;
318 : 0 : break;
319 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
320 : 0 : case MLX5DR_ACTION_TYP_CTR:
321 : 0 : attr[i].type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
322 : 0 : attr[i].obj = action->devx_obj;
323 : :
324 [ # # ]: 0 : if (rule_actions[i].counter.offset) {
325 : 0 : DR_LOG(ERR, "Counter offset not supported over root");
326 : 0 : rte_errno = ENOTSUP;
327 : 0 : return rte_errno;
328 : : }
329 : : break;
330 : : #endif
331 : 0 : default:
332 : 0 : DR_LOG(ERR, "Found unsupported action type: %d", action->type);
333 : 0 : rte_errno = ENOTSUP;
334 : 0 : return rte_errno;
335 : : }
336 : : }
337 : :
338 : : return 0;
339 : : }
340 : :
341 : : static bool
342 : 0 : mlx5dr_action_fixup_stc_attr(struct mlx5dr_context *ctx,
343 : : struct mlx5dr_cmd_stc_modify_attr *stc_attr,
344 : : struct mlx5dr_cmd_stc_modify_attr *fixup_stc_attr,
345 : : enum mlx5dr_table_type table_type,
346 : : bool is_mirror)
347 : : {
348 : : struct mlx5dr_devx_obj *devx_obj;
349 : : bool use_fixup = false;
350 : : uint32_t fw_tbl_type;
351 : :
352 : 0 : fw_tbl_type = mlx5dr_table_get_res_fw_ft_type(table_type, is_mirror);
353 : :
354 [ # # # # : 0 : switch (stc_attr->action_type) {
# ]
355 : 0 : case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_STE_TABLE:
356 [ # # ]: 0 : if (!is_mirror)
357 : 0 : devx_obj = mlx5dr_pool_chunk_get_base_devx_obj(stc_attr->ste_table.ste_pool,
358 : : &stc_attr->ste_table.ste);
359 : : else
360 : : devx_obj =
361 : 0 : mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_attr->ste_table.ste_pool,
362 : : &stc_attr->ste_table.ste);
363 : :
364 : 0 : *fixup_stc_attr = *stc_attr;
365 : 0 : fixup_stc_attr->ste_table.ste_obj_id = devx_obj->id;
366 : : use_fixup = true;
367 : 0 : break;
368 : :
369 : 0 : case MLX5_IFC_STC_ACTION_TYPE_ALLOW:
370 [ # # ]: 0 : if (fw_tbl_type == FS_FT_FDB_TX || fw_tbl_type == FS_FT_FDB_RX) {
371 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT;
372 : 0 : fixup_stc_attr->action_offset = stc_attr->action_offset;
373 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
374 : 0 : fixup_stc_attr->vport.esw_owner_vhca_id = ctx->caps->vhca_id;
375 : 0 : fixup_stc_attr->vport.vport_num = ctx->caps->eswitch_manager_vport_number;
376 : : use_fixup = true;
377 : : }
378 : : break;
379 : :
380 : 0 : case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT:
381 [ # # ]: 0 : if (stc_attr->vport.vport_num != WIRE_PORT)
382 : : break;
383 : :
384 [ # # ]: 0 : if (fw_tbl_type == FS_FT_FDB_RX) {
385 : : /* The FW doesn't allow to go back to wire in RX, so change it to DROP */
386 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
387 : 0 : fixup_stc_attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
388 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
389 [ # # ]: 0 : } else if (fw_tbl_type == FS_FT_FDB_TX) {
390 : : /*The FW doesn't allow to go to wire in the TX by JUMP_TO_VPORT*/
391 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_UPLINK;
392 : 0 : fixup_stc_attr->action_offset = stc_attr->action_offset;
393 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
394 : 0 : fixup_stc_attr->vport.vport_num = 0;
395 : 0 : fixup_stc_attr->vport.esw_owner_vhca_id = stc_attr->vport.esw_owner_vhca_id;
396 : : }
397 : : use_fixup = true;
398 : : break;
399 : 0 : case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_TIR:
400 : : /* TIR is allowed on RX side, requires mask in case of FDB */
401 [ # # ]: 0 : if (fw_tbl_type == FS_FT_FDB_TX) {
402 : 0 : fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
403 : 0 : fixup_stc_attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
404 : 0 : fixup_stc_attr->stc_offset = stc_attr->stc_offset;
405 : : use_fixup = true;
406 : : }
407 : : break;
408 : : default:
409 : : break;
410 : : }
411 : :
412 : 0 : return use_fixup;
413 : : }
414 : :
415 : 0 : int mlx5dr_action_alloc_single_stc(struct mlx5dr_context *ctx,
416 : : struct mlx5dr_cmd_stc_modify_attr *stc_attr,
417 : : uint32_t table_type,
418 : : struct mlx5dr_pool_chunk *stc)
419 : : {
420 : 0 : struct mlx5dr_cmd_stc_modify_attr cleanup_stc_attr = {0};
421 : 0 : struct mlx5dr_pool *stc_pool = ctx->stc_pool[table_type];
422 : 0 : struct mlx5dr_cmd_stc_modify_attr fixup_stc_attr = {0};
423 : : struct mlx5dr_devx_obj *devx_obj_0;
424 : : bool use_fixup;
425 : : int ret;
426 : :
427 : 0 : ret = mlx5dr_pool_chunk_alloc(stc_pool, stc);
428 [ # # ]: 0 : if (ret) {
429 : 0 : DR_LOG(ERR, "Failed to allocate single action STC");
430 : 0 : return ret;
431 : : }
432 : :
433 : 0 : stc_attr->stc_offset = stc->offset;
434 : :
435 : : /* Dynamic reparse not supported, overwrite and use default */
436 [ # # ]: 0 : if (!mlx5dr_context_cap_dynamic_reparse(ctx))
437 : 0 : stc_attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
438 : :
439 : : devx_obj_0 = mlx5dr_pool_chunk_get_base_devx_obj(stc_pool, stc);
440 : :
441 : : /* According to table/action limitation change the stc_attr */
442 : 0 : use_fixup = mlx5dr_action_fixup_stc_attr(ctx, stc_attr, &fixup_stc_attr, table_type, false);
443 [ # # ]: 0 : ret = mlx5dr_cmd_stc_modify(devx_obj_0, use_fixup ? &fixup_stc_attr : stc_attr);
444 [ # # ]: 0 : if (ret) {
445 : 0 : DR_LOG(ERR, "Failed to modify STC action_type %d tbl_type %d",
446 : : stc_attr->action_type, table_type);
447 : 0 : goto free_chunk;
448 : : }
449 : :
450 : : /* Modify the FDB peer */
451 [ # # ]: 0 : if (table_type == MLX5DR_TABLE_TYPE_FDB) {
452 : : struct mlx5dr_devx_obj *devx_obj_1;
453 : :
454 : : devx_obj_1 = mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
455 : :
456 : 0 : use_fixup = mlx5dr_action_fixup_stc_attr(ctx, stc_attr,
457 : : &fixup_stc_attr,
458 : : table_type, true);
459 [ # # ]: 0 : ret = mlx5dr_cmd_stc_modify(devx_obj_1, use_fixup ? &fixup_stc_attr : stc_attr);
460 [ # # ]: 0 : if (ret) {
461 : 0 : DR_LOG(ERR, "Failed to modify peer STC action_type %d tbl_type %d",
462 : : stc_attr->action_type, table_type);
463 : 0 : goto clean_devx_obj_0;
464 : : }
465 : : }
466 : :
467 : : return 0;
468 : :
469 : : clean_devx_obj_0:
470 : 0 : cleanup_stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
471 : 0 : cleanup_stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
472 : 0 : cleanup_stc_attr.stc_offset = stc->offset;
473 : 0 : mlx5dr_cmd_stc_modify(devx_obj_0, &cleanup_stc_attr);
474 : 0 : free_chunk:
475 : 0 : mlx5dr_pool_chunk_free(stc_pool, stc);
476 : 0 : return rte_errno;
477 : : }
478 : :
479 : 0 : void mlx5dr_action_free_single_stc(struct mlx5dr_context *ctx,
480 : : uint32_t table_type,
481 : : struct mlx5dr_pool_chunk *stc)
482 : : {
483 : 0 : struct mlx5dr_pool *stc_pool = ctx->stc_pool[table_type];
484 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
485 : : struct mlx5dr_devx_obj *devx_obj;
486 : :
487 : : /* Modify the STC not to point to an object */
488 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
489 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
490 : 0 : stc_attr.stc_offset = stc->offset;
491 : : devx_obj = mlx5dr_pool_chunk_get_base_devx_obj(stc_pool, stc);
492 : 0 : mlx5dr_cmd_stc_modify(devx_obj, &stc_attr);
493 : :
494 [ # # ]: 0 : if (table_type == MLX5DR_TABLE_TYPE_FDB) {
495 : : devx_obj = mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
496 : 0 : mlx5dr_cmd_stc_modify(devx_obj, &stc_attr);
497 : : }
498 : :
499 : 0 : mlx5dr_pool_chunk_free(stc_pool, stc);
500 : 0 : }
501 : :
502 : 0 : static uint32_t mlx5dr_action_get_mh_stc_type(__be64 pattern)
503 : : {
504 [ # # ]: 0 : uint8_t action_type = MLX5_GET(set_action_in, &pattern, action_type);
505 : :
506 [ # # # # : 0 : switch (action_type) {
# ]
507 : : case MLX5_MODIFICATION_TYPE_SET:
508 : : return MLX5_IFC_STC_ACTION_TYPE_SET;
509 : 0 : case MLX5_MODIFICATION_TYPE_ADD:
510 : 0 : return MLX5_IFC_STC_ACTION_TYPE_ADD;
511 : 0 : case MLX5_MODIFICATION_TYPE_COPY:
512 : 0 : return MLX5_IFC_STC_ACTION_TYPE_COPY;
513 : 0 : case MLX5_MODIFICATION_TYPE_ADD_FIELD:
514 : 0 : return MLX5_IFC_STC_ACTION_TYPE_ADD_FIELD;
515 : 0 : default:
516 : 0 : assert(false);
517 : : DR_LOG(ERR, "Unsupported action type: 0x%x", action_type);
518 : : rte_errno = ENOTSUP;
519 : : return MLX5_IFC_STC_ACTION_TYPE_NOP;
520 : : }
521 : : }
522 : :
523 : 0 : static void mlx5dr_action_fill_stc_attr(struct mlx5dr_action *action,
524 : : struct mlx5dr_devx_obj *obj,
525 : : struct mlx5dr_cmd_stc_modify_attr *attr)
526 : : {
527 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
528 : :
529 [ # # # # : 0 : switch (action->type) {
# # # # #
# # # # #
# # # ]
530 : 0 : case MLX5DR_ACTION_TYP_TAG:
531 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_TAG;
532 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
533 : 0 : break;
534 : 0 : case MLX5DR_ACTION_TYP_DROP:
535 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
536 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
537 : 0 : break;
538 : 0 : case MLX5DR_ACTION_TYP_MISS:
539 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
540 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
541 : 0 : break;
542 : 0 : case MLX5DR_ACTION_TYP_CTR:
543 : 0 : attr->id = obj->id;
544 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_COUNTER;
545 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW0;
546 : 0 : break;
547 : 0 : case MLX5DR_ACTION_TYP_TIR:
548 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_TIR;
549 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
550 : 0 : attr->dest_tir_num = obj->id;
551 : 0 : break;
552 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
553 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
554 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
555 : : attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
556 [ # # ]: 0 : if (action->modify_header.require_reparse)
557 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
558 : :
559 [ # # ]: 0 : if (action->modify_header.num_of_actions == 1) {
560 : 0 : attr->modify_action.data = action->modify_header.single_action;
561 : 0 : attr->action_type = mlx5dr_action_get_mh_stc_type(attr->modify_action.data);
562 : :
563 [ # # ]: 0 : if (attr->action_type == MLX5_IFC_STC_ACTION_TYPE_ADD ||
564 : : attr->action_type == MLX5_IFC_STC_ACTION_TYPE_SET)
565 [ # # ]: 0 : MLX5_SET(set_action_in, &attr->modify_action.data, data, 0);
566 : : } else {
567 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ACC_MODIFY_LIST;
568 : 0 : attr->modify_header.arg_id = action->modify_header.arg_obj->id;
569 : 0 : attr->modify_header.pattern_id = action->modify_header.pat_obj->id;
570 : : }
571 : : break;
572 : 0 : case MLX5DR_ACTION_TYP_TBL:
573 : : case MLX5DR_ACTION_TYP_DEST_ARRAY:
574 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
575 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
576 : 0 : attr->dest_table_id = obj->id;
577 : 0 : break;
578 : 0 : case MLX5DR_ACTION_TYP_DEST_ROOT:
579 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
580 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
581 : 0 : attr->dest_table_id = action->root_tbl.sa->id;
582 : 0 : break;
583 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
584 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
585 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
586 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
587 : 0 : attr->remove_header.decap = 1;
588 : 0 : attr->remove_header.start_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
589 : 0 : attr->remove_header.end_anchor = MLX5_HEADER_ANCHOR_INNER_MAC;
590 : 0 : break;
591 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
592 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
593 : : case MLX5DR_ACTION_TYP_INSERT_HEADER:
594 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
595 [ # # ]: 0 : if (!action->reformat.require_reparse)
596 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
597 : :
598 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_INSERT;
599 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
600 : 0 : attr->insert_header.encap = action->reformat.encap;
601 : 0 : attr->insert_header.insert_anchor = action->reformat.anchor;
602 : 0 : attr->insert_header.arg_id = action->reformat.arg_obj->id;
603 : 0 : attr->insert_header.header_size = action->reformat.header_size;
604 : 0 : attr->insert_header.insert_offset = action->reformat.offset;
605 : 0 : break;
606 : 0 : case MLX5DR_ACTION_TYP_ASO_METER:
607 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
608 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ASO;
609 : 0 : attr->aso.aso_type = ASO_OPC_MOD_POLICER;
610 : 0 : attr->aso.devx_obj_id = obj->id;
611 : 0 : attr->aso.return_reg_id = action->aso.return_reg_id;
612 : 0 : break;
613 : 0 : case MLX5DR_ACTION_TYP_ASO_CT:
614 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
615 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ASO;
616 : 0 : attr->aso.aso_type = ASO_OPC_MOD_CONNECTION_TRACKING;
617 : 0 : attr->aso.devx_obj_id = obj->id;
618 : 0 : attr->aso.return_reg_id = action->aso.return_reg_id;
619 : 0 : break;
620 : 0 : case MLX5DR_ACTION_TYP_VPORT:
621 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
622 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT;
623 : 0 : attr->vport.vport_num = action->vport.vport_num;
624 : 0 : attr->vport.esw_owner_vhca_id = action->vport.esw_owner_vhca_id;
625 : 0 : break;
626 : 0 : case MLX5DR_ACTION_TYP_POP_VLAN:
627 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
628 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
629 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
630 : 0 : attr->remove_words.start_anchor = MLX5_HEADER_ANCHOR_FIRST_VLAN_START;
631 : 0 : attr->remove_words.num_of_words = MLX5DR_ACTION_HDR_LEN_L2_VLAN / 2;
632 : 0 : break;
633 : 0 : case MLX5DR_ACTION_TYP_PUSH_VLAN:
634 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_INSERT;
635 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
636 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
637 : 0 : attr->insert_header.encap = 0;
638 : 0 : attr->insert_header.is_inline = 1;
639 : 0 : attr->insert_header.insert_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
640 : 0 : attr->insert_header.insert_offset = MLX5DR_ACTION_HDR_LEN_L2_MACS;
641 : 0 : attr->insert_header.header_size = MLX5DR_ACTION_HDR_LEN_L2_VLAN;
642 : 0 : break;
643 : 0 : case MLX5DR_ACTION_TYP_REMOVE_HEADER:
644 [ # # ]: 0 : if (action->remove_header.type == MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER) {
645 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
646 : 0 : attr->remove_header.decap = action->remove_header.decap;
647 : 0 : attr->remove_header.start_anchor = action->remove_header.start_anchor;
648 : 0 : attr->remove_header.end_anchor = action->remove_header.end_anchor;
649 : : } else {
650 : 0 : attr->action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
651 : 0 : attr->remove_words.start_anchor = action->remove_header.start_anchor;
652 : 0 : attr->remove_words.num_of_words = action->remove_header.num_of_words;
653 : : }
654 : 0 : attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
655 : 0 : attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
656 : 0 : break;
657 : 0 : default:
658 : 0 : DR_LOG(ERR, "Invalid action type %d", action->type);
659 : 0 : assert(false);
660 : : }
661 : 0 : }
662 : :
663 : : static int
664 : 0 : mlx5dr_action_create_stcs(struct mlx5dr_action *action,
665 : : struct mlx5dr_devx_obj *obj)
666 : : {
667 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
668 : 0 : struct mlx5dr_context *ctx = action->ctx;
669 : : int ret;
670 : :
671 : 0 : mlx5dr_action_fill_stc_attr(action, obj, &stc_attr);
672 : :
673 : : /* Block unsupported parallel devx obj modify over the same base */
674 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
675 : :
676 : : /* Allocate STC for RX */
677 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX) {
678 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
679 : : MLX5DR_TABLE_TYPE_NIC_RX,
680 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
681 [ # # ]: 0 : if (ret)
682 : 0 : goto out_err;
683 : : }
684 : :
685 : : /* Allocate STC for TX */
686 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX) {
687 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
688 : : MLX5DR_TABLE_TYPE_NIC_TX,
689 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
690 [ # # ]: 0 : if (ret)
691 : 0 : goto free_nic_rx_stc;
692 : : }
693 : :
694 : : /* Allocate STC for FDB */
695 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB) {
696 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
697 : : MLX5DR_TABLE_TYPE_FDB,
698 : : &action->stc[MLX5DR_TABLE_TYPE_FDB]);
699 [ # # ]: 0 : if (ret)
700 : 0 : goto free_nic_tx_stc;
701 : : }
702 : :
703 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
704 : :
705 : 0 : return 0;
706 : :
707 : : free_nic_tx_stc:
708 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
709 : 0 : mlx5dr_action_free_single_stc(ctx,
710 : : MLX5DR_TABLE_TYPE_NIC_TX,
711 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
712 : 0 : free_nic_rx_stc:
713 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
714 : 0 : mlx5dr_action_free_single_stc(ctx,
715 : : MLX5DR_TABLE_TYPE_NIC_RX,
716 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
717 : 0 : out_err:
718 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
719 : 0 : return rte_errno;
720 : : }
721 : :
722 : : static void
723 : 0 : mlx5dr_action_destroy_stcs(struct mlx5dr_action *action)
724 : : {
725 : 0 : struct mlx5dr_context *ctx = action->ctx;
726 : :
727 : : /* Block unsupported parallel devx obj modify over the same base */
728 : 0 : pthread_spin_lock(&ctx->ctrl_lock);
729 : :
730 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
731 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_RX,
732 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
733 : :
734 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
735 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_TX,
736 : : &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
737 : :
738 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
739 : 0 : mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB,
740 : : &action->stc[MLX5DR_TABLE_TYPE_FDB]);
741 : :
742 : 0 : pthread_spin_unlock(&ctx->ctrl_lock);
743 : 0 : }
744 : :
745 : : static bool
746 : : mlx5dr_action_is_root_flags(uint32_t flags)
747 : : {
748 : 0 : return flags & (MLX5DR_ACTION_FLAG_ROOT_RX |
749 : : MLX5DR_ACTION_FLAG_ROOT_TX |
750 : : MLX5DR_ACTION_FLAG_ROOT_FDB);
751 : : }
752 : :
753 : : static bool
754 : : mlx5dr_action_is_hws_flags(uint32_t flags)
755 : : {
756 : 0 : return flags & (MLX5DR_ACTION_FLAG_HWS_RX |
757 : : MLX5DR_ACTION_FLAG_HWS_TX |
758 : : MLX5DR_ACTION_FLAG_HWS_FDB);
759 : : }
760 : :
761 : : static struct mlx5dr_action *
762 : 0 : mlx5dr_action_create_generic_bulk(struct mlx5dr_context *ctx,
763 : : uint32_t flags,
764 : : enum mlx5dr_action_type action_type,
765 : : uint8_t bulk_sz)
766 : : {
767 : : struct mlx5dr_action *action;
768 : : int i;
769 : :
770 [ # # # # ]: 0 : if (!mlx5dr_action_is_root_flags(flags) &&
771 : : !mlx5dr_action_is_hws_flags(flags)) {
772 : 0 : DR_LOG(ERR, "Action flags must specify root or non root (HWS)");
773 : 0 : rte_errno = ENOTSUP;
774 : 0 : return NULL;
775 : : }
776 : :
777 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
778 [ # # ]: 0 : !(ctx->flags & MLX5DR_CONTEXT_FLAG_HWS_SUPPORT)) {
779 : 0 : DR_LOG(ERR, "Cannot create HWS action since HWS is not supported");
780 : 0 : rte_errno = ENOTSUP;
781 : 0 : return NULL;
782 : : }
783 : :
784 : 0 : action = simple_calloc(bulk_sz, sizeof(*action));
785 [ # # ]: 0 : if (!action) {
786 : 0 : DR_LOG(ERR, "Failed to allocate memory for action [%d]", action_type);
787 : 0 : rte_errno = ENOMEM;
788 : 0 : return NULL;
789 : : }
790 : :
791 [ # # ]: 0 : for (i = 0; i < bulk_sz; i++) {
792 : 0 : action[i].ctx = ctx;
793 : 0 : action[i].flags = flags;
794 : 0 : action[i].type = action_type;
795 : : }
796 : :
797 : : return action;
798 : : }
799 : :
800 : : static struct mlx5dr_action *
801 : : mlx5dr_action_create_generic(struct mlx5dr_context *ctx,
802 : : uint32_t flags,
803 : : enum mlx5dr_action_type action_type)
804 : : {
805 : 0 : return mlx5dr_action_create_generic_bulk(ctx, flags, action_type, 1);
806 : : }
807 : :
808 : : struct mlx5dr_action *
809 [ # # ]: 0 : mlx5dr_action_create_dest_table(struct mlx5dr_context *ctx,
810 : : struct mlx5dr_table *tbl,
811 : : uint32_t flags)
812 : : {
813 : : struct mlx5dr_action *action;
814 : : int ret;
815 : :
816 [ # # ]: 0 : if (mlx5dr_table_is_root(tbl)) {
817 : 0 : DR_LOG(ERR, "Root table cannot be set as destination");
818 : 0 : rte_errno = ENOTSUP;
819 : 0 : return NULL;
820 : : }
821 : :
822 [ # # # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
823 : : mlx5dr_action_is_root_flags(flags)) {
824 : 0 : DR_LOG(ERR, "Same action cannot be used for root and non root");
825 : 0 : rte_errno = ENOTSUP;
826 : 0 : return NULL;
827 : : }
828 : :
829 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TBL);
830 [ # # ]: 0 : if (!action)
831 : : return NULL;
832 : :
833 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
834 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx))
835 : 0 : action->devx_obj = tbl->local_ft->obj;
836 : : else
837 : 0 : action->devx_obj = tbl->ft->obj;
838 : : } else {
839 : 0 : ret = mlx5dr_action_create_stcs(action, tbl->ft);
840 [ # # ]: 0 : if (ret)
841 : 0 : goto free_action;
842 : :
843 : 0 : action->devx_dest.devx_obj = tbl->ft;
844 : : }
845 : :
846 : : return action;
847 : :
848 : : free_action:
849 : : simple_free(action);
850 : 0 : return NULL;
851 : : }
852 : :
853 [ # # ]: 0 : static int mlx5dr_action_get_dest_tir_obj(struct mlx5dr_context *ctx,
854 : : struct mlx5dr_action *action,
855 : : struct mlx5dr_devx_obj *obj,
856 : : struct mlx5dr_devx_obj **ret_obj)
857 : : {
858 : : int ret;
859 : :
860 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx)) {
861 : 0 : ret = mlx5dr_matcher_create_aliased_obj(ctx,
862 : : ctx->local_ibv_ctx,
863 : : ctx->ibv_ctx,
864 : 0 : ctx->caps->vhca_id,
865 : : obj->id,
866 : : MLX5_GENERAL_OBJ_TYPE_TIR_ALIAS,
867 : : &action->alias.devx_obj);
868 [ # # ]: 0 : if (ret) {
869 : 0 : DR_LOG(ERR, "Failed to create tir alias");
870 : 0 : return rte_errno;
871 : : }
872 : 0 : *ret_obj = action->alias.devx_obj;
873 : : } else {
874 : 0 : *ret_obj = obj;
875 : : }
876 : :
877 : : return 0;
878 : : }
879 : :
880 : : struct mlx5dr_action *
881 : 0 : mlx5dr_action_create_dest_tir(struct mlx5dr_context *ctx,
882 : : struct mlx5dr_devx_obj *obj,
883 : : uint32_t flags,
884 : : bool is_local)
885 : : {
886 : : struct mlx5dr_action *action;
887 : : int ret;
888 : :
889 [ # # # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
890 : : mlx5dr_action_is_root_flags(flags)) {
891 : 0 : DR_LOG(ERR, "Same action cannot be used for root and non root");
892 : 0 : rte_errno = ENOTSUP;
893 : 0 : return NULL;
894 : : }
895 : :
896 [ # # ]: 0 : if ((flags & MLX5DR_ACTION_FLAG_ROOT_FDB) ||
897 [ # # # # ]: 0 : (flags & MLX5DR_ACTION_FLAG_HWS_FDB && !ctx->caps->fdb_tir_stc)) {
898 : 0 : DR_LOG(ERR, "TIR action not support on FDB");
899 : 0 : rte_errno = ENOTSUP;
900 : 0 : return NULL;
901 : : }
902 : :
903 [ # # ]: 0 : if (!is_local) {
904 : 0 : DR_LOG(ERR, "TIR should be created on local ibv_device, flags: 0x%x",
905 : : flags);
906 : 0 : rte_errno = ENOTSUP;
907 : 0 : return NULL;
908 : : }
909 : :
910 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TIR);
911 [ # # ]: 0 : if (!action)
912 : : return NULL;
913 : :
914 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
915 : 0 : action->devx_obj = obj->obj;
916 : : } else {
917 : 0 : struct mlx5dr_devx_obj *cur_obj = NULL; /*compilation warn*/
918 : :
919 : 0 : ret = mlx5dr_action_get_dest_tir_obj(ctx, action, obj, &cur_obj);
920 [ # # ]: 0 : if (ret) {
921 : 0 : DR_LOG(ERR, "Failed to create tir alias (flags: %d)", flags);
922 : 0 : goto free_action;
923 : : }
924 : :
925 : 0 : ret = mlx5dr_action_create_stcs(action, cur_obj);
926 [ # # ]: 0 : if (ret)
927 : 0 : goto clean_obj;
928 : :
929 : 0 : action->devx_dest.devx_obj = cur_obj;
930 : : }
931 : :
932 : : return action;
933 : :
934 : : clean_obj:
935 : 0 : mlx5dr_cmd_destroy_obj(action->alias.devx_obj);
936 : 0 : free_action:
937 : : simple_free(action);
938 : 0 : return NULL;
939 : : }
940 : :
941 : : struct mlx5dr_action *
942 : 0 : mlx5dr_action_create_dest_drop(struct mlx5dr_context *ctx,
943 : : uint32_t flags)
944 : : {
945 : : struct mlx5dr_action *action;
946 : : int ret;
947 : :
948 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DROP);
949 [ # # ]: 0 : if (!action)
950 : : return NULL;
951 : :
952 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags)) {
953 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
954 [ # # ]: 0 : if (ret)
955 : 0 : goto free_action;
956 : : }
957 : :
958 : : return action;
959 : :
960 : : free_action:
961 : : simple_free(action);
962 : 0 : return NULL;
963 : : }
964 : :
965 : : struct mlx5dr_action *
966 : 0 : mlx5dr_action_create_default_miss(struct mlx5dr_context *ctx,
967 : : uint32_t flags)
968 : : {
969 : : struct mlx5dr_action *action;
970 : : int ret;
971 : :
972 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_MISS);
973 [ # # ]: 0 : if (!action)
974 : : return NULL;
975 : :
976 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags)) {
977 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
978 [ # # ]: 0 : if (ret)
979 : 0 : goto free_action;
980 : : }
981 : :
982 : : return action;
983 : :
984 : : free_action:
985 : : simple_free(action);
986 : 0 : return NULL;
987 : : }
988 : :
989 : : struct mlx5dr_action *
990 : 0 : mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
991 : : uint32_t flags)
992 : : {
993 : : struct mlx5dr_action *action;
994 : : int ret;
995 : :
996 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TAG);
997 [ # # ]: 0 : if (!action)
998 : : return NULL;
999 : :
1000 [ # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags)) {
1001 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1002 [ # # ]: 0 : if (ret)
1003 : 0 : goto free_action;
1004 : : }
1005 : :
1006 : : return action;
1007 : :
1008 : : free_action:
1009 : : simple_free(action);
1010 : 0 : return NULL;
1011 : : }
1012 : :
1013 : : static struct mlx5dr_action *
1014 : 0 : mlx5dr_action_create_aso(struct mlx5dr_context *ctx,
1015 : : enum mlx5dr_action_type action_type,
1016 : : struct mlx5dr_devx_obj *devx_obj,
1017 : : uint8_t return_reg_id,
1018 : : uint32_t flags)
1019 : : {
1020 : : struct mlx5dr_action *action;
1021 : : int ret;
1022 : :
1023 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1024 : 0 : DR_LOG(ERR, "ASO action cannot be used over root table");
1025 : 0 : rte_errno = ENOTSUP;
1026 : 0 : return NULL;
1027 : : }
1028 : :
1029 : : action = mlx5dr_action_create_generic(ctx, flags, action_type);
1030 [ # # ]: 0 : if (!action)
1031 : : return NULL;
1032 : :
1033 : 0 : action->aso.devx_obj = devx_obj;
1034 : 0 : action->aso.return_reg_id = return_reg_id;
1035 : :
1036 : 0 : ret = mlx5dr_action_create_stcs(action, devx_obj);
1037 [ # # ]: 0 : if (ret)
1038 : 0 : goto free_action;
1039 : :
1040 : : return action;
1041 : :
1042 : : free_action:
1043 : : simple_free(action);
1044 : 0 : return NULL;
1045 : : }
1046 : :
1047 : : struct mlx5dr_action *
1048 : 0 : mlx5dr_action_create_aso_meter(struct mlx5dr_context *ctx,
1049 : : struct mlx5dr_devx_obj *devx_obj,
1050 : : uint8_t return_reg_id,
1051 : : uint32_t flags)
1052 : : {
1053 : 0 : return mlx5dr_action_create_aso(ctx, MLX5DR_ACTION_TYP_ASO_METER,
1054 : : devx_obj, return_reg_id, flags);
1055 : : }
1056 : :
1057 : : struct mlx5dr_action *
1058 : 0 : mlx5dr_action_create_aso_ct(struct mlx5dr_context *ctx,
1059 : : struct mlx5dr_devx_obj *devx_obj,
1060 : : uint8_t return_reg_id,
1061 : : uint32_t flags)
1062 : : {
1063 : 0 : return mlx5dr_action_create_aso(ctx, MLX5DR_ACTION_TYP_ASO_CT,
1064 : : devx_obj, return_reg_id, flags);
1065 : : }
1066 : :
1067 : : struct mlx5dr_action *
1068 : 0 : mlx5dr_action_create_counter(struct mlx5dr_context *ctx,
1069 : : struct mlx5dr_devx_obj *obj,
1070 : : uint32_t flags)
1071 : : {
1072 : : struct mlx5dr_action *action;
1073 : : int ret;
1074 : :
1075 [ # # # # ]: 0 : if (mlx5dr_action_is_hws_flags(flags) &&
1076 : : mlx5dr_action_is_root_flags(flags)) {
1077 : 0 : DR_LOG(ERR, "Same action cannot be used for root and non root");
1078 : 0 : rte_errno = ENOTSUP;
1079 : 0 : return NULL;
1080 : : }
1081 : :
1082 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_CTR);
1083 [ # # ]: 0 : if (!action)
1084 : : return NULL;
1085 : :
1086 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1087 : 0 : action->devx_obj = obj->obj;
1088 : : } else {
1089 : 0 : ret = mlx5dr_action_create_stcs(action, obj);
1090 [ # # ]: 0 : if (ret)
1091 : 0 : goto free_action;
1092 : : }
1093 : :
1094 : : return action;
1095 : :
1096 : : free_action:
1097 : : simple_free(action);
1098 : 0 : return NULL;
1099 : : }
1100 : :
1101 : 0 : static int mlx5dr_action_create_dest_vport_hws(struct mlx5dr_context *ctx,
1102 : : struct mlx5dr_action *action,
1103 : : uint32_t ib_port_num)
1104 : : {
1105 : 0 : struct mlx5dr_cmd_query_vport_caps vport_caps = {0};
1106 : : int ret;
1107 : :
1108 : 0 : ret = mlx5dr_cmd_query_ib_port(ctx->ibv_ctx, &vport_caps, ib_port_num);
1109 [ # # ]: 0 : if (ret) {
1110 : 0 : DR_LOG(ERR, "Failed querying port %d", ib_port_num);
1111 : 0 : return ret;
1112 : : }
1113 : 0 : action->vport.vport_num = vport_caps.vport_num;
1114 : 0 : action->vport.esw_owner_vhca_id = vport_caps.esw_owner_vhca_id;
1115 : :
1116 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1117 [ # # ]: 0 : if (ret) {
1118 : 0 : DR_LOG(ERR, "Failed creating stc for port %d", ib_port_num);
1119 : 0 : return ret;
1120 : : }
1121 : :
1122 : : return 0;
1123 : : }
1124 : :
1125 : : struct mlx5dr_action *
1126 : 0 : mlx5dr_action_create_dest_vport(struct mlx5dr_context *ctx,
1127 : : uint32_t ib_port_num,
1128 : : uint32_t flags)
1129 : : {
1130 : : struct mlx5dr_action *action;
1131 : : int ret;
1132 : :
1133 [ # # ]: 0 : if (!(flags & MLX5DR_ACTION_FLAG_HWS_FDB)) {
1134 : 0 : DR_LOG(ERR, "Vport action is supported for FDB only");
1135 : 0 : rte_errno = EINVAL;
1136 : 0 : return NULL;
1137 : : }
1138 : :
1139 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_VPORT);
1140 [ # # ]: 0 : if (!action)
1141 : : return NULL;
1142 : :
1143 : 0 : ret = mlx5dr_action_create_dest_vport_hws(ctx, action, ib_port_num);
1144 [ # # ]: 0 : if (ret) {
1145 : 0 : DR_LOG(ERR, "Failed to create vport action HWS");
1146 : 0 : goto free_action;
1147 : : }
1148 : :
1149 : : return action;
1150 : :
1151 : : free_action:
1152 : : simple_free(action);
1153 : 0 : return NULL;
1154 : : }
1155 : :
1156 : : struct mlx5dr_action *
1157 : 0 : mlx5dr_action_create_push_vlan(struct mlx5dr_context *ctx, uint32_t flags)
1158 : : {
1159 : : struct mlx5dr_action *action;
1160 : : int ret;
1161 : :
1162 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1163 : 0 : DR_LOG(ERR, "Push vlan action not supported for root");
1164 : 0 : rte_errno = ENOTSUP;
1165 : 0 : return NULL;
1166 : : }
1167 : :
1168 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_PUSH_VLAN);
1169 [ # # ]: 0 : if (!action)
1170 : : return NULL;
1171 : :
1172 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1173 [ # # ]: 0 : if (ret) {
1174 : 0 : DR_LOG(ERR, "Failed creating stc for push vlan");
1175 : 0 : goto free_action;
1176 : : }
1177 : :
1178 : : return action;
1179 : :
1180 : : free_action:
1181 : : simple_free(action);
1182 : 0 : return NULL;
1183 : : }
1184 : :
1185 : : struct mlx5dr_action *
1186 : 0 : mlx5dr_action_create_pop_vlan(struct mlx5dr_context *ctx, uint32_t flags)
1187 : : {
1188 : : struct mlx5dr_action *action;
1189 : : int ret;
1190 : :
1191 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1192 : 0 : DR_LOG(ERR, "Pop vlan action not supported for root");
1193 : 0 : rte_errno = ENOTSUP;
1194 : 0 : return NULL;
1195 : : }
1196 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_POP_VLAN);
1197 [ # # ]: 0 : if (!action)
1198 : : return NULL;
1199 : :
1200 : 0 : ret = mlx5dr_action_get_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
1201 [ # # ]: 0 : if (ret) {
1202 : 0 : DR_LOG(ERR, "Failed to create remove stc for reformat");
1203 : 0 : goto free_action;
1204 : : }
1205 : :
1206 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1207 [ # # ]: 0 : if (ret) {
1208 : 0 : DR_LOG(ERR, "Failed creating stc for pop vlan");
1209 : 0 : goto free_shared;
1210 : : }
1211 : :
1212 : : return action;
1213 : :
1214 : : free_shared:
1215 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
1216 : 0 : free_action:
1217 : : simple_free(action);
1218 : 0 : return NULL;
1219 : : }
1220 : :
1221 : : static int
1222 : 0 : mlx5dr_action_conv_reformat_to_verbs(uint32_t action_type,
1223 : : uint32_t *verb_reformat_type)
1224 : : {
1225 [ # # # # : 0 : switch (action_type) {
# ]
1226 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
1227 : 0 : *verb_reformat_type =
1228 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2;
1229 : 0 : return 0;
1230 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
1231 : 0 : *verb_reformat_type =
1232 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL;
1233 : 0 : return 0;
1234 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
1235 : 0 : *verb_reformat_type =
1236 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2;
1237 : 0 : return 0;
1238 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
1239 : 0 : *verb_reformat_type =
1240 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
1241 : 0 : return 0;
1242 : 0 : default:
1243 : 0 : DR_LOG(ERR, "Invalid root reformat action type");
1244 : 0 : rte_errno = EINVAL;
1245 : 0 : return rte_errno;
1246 : : }
1247 : : }
1248 : :
1249 : : static int
1250 : : mlx5dr_action_conv_flags_to_ft_type(uint32_t flags, enum mlx5dv_flow_table_type *ft_type)
1251 : : {
1252 [ # # ]: 0 : if (flags & (MLX5DR_ACTION_FLAG_ROOT_RX | MLX5DR_ACTION_FLAG_HWS_RX)) {
1253 : : *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
1254 [ # # # # : 0 : } else if (flags & (MLX5DR_ACTION_FLAG_ROOT_TX | MLX5DR_ACTION_FLAG_HWS_TX)) {
# # ]
1255 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
1256 : : #ifdef HAVE_MLX5DV_FLOW_MATCHER_FT_TYPE
1257 [ # # # # : 0 : } else if (flags & (MLX5DR_ACTION_FLAG_ROOT_FDB | MLX5DR_ACTION_FLAG_HWS_FDB)) {
# # ]
1258 : 0 : *ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
1259 : : #endif
1260 : : } else {
1261 : 0 : rte_errno = ENOTSUP;
1262 : : return 1;
1263 : : }
1264 : :
1265 : : return 0;
1266 : : }
1267 : :
1268 : : static int
1269 : 0 : mlx5dr_action_create_reformat_root(struct mlx5dr_action *action,
1270 : : size_t data_sz,
1271 : : void *data)
1272 : : {
1273 : : enum mlx5dv_flow_table_type ft_type = 0; /*fix compilation warn*/
1274 : 0 : uint32_t verb_reformat_type = 0;
1275 : : struct ibv_context *ibv_ctx;
1276 : : int ret;
1277 : :
1278 : : /* Convert action to FT type and verbs reformat type */
1279 [ # # ]: 0 : ret = mlx5dr_action_conv_flags_to_ft_type(action->flags, &ft_type);
1280 : : if (ret)
1281 : 0 : return rte_errno;
1282 : :
1283 : 0 : ret = mlx5dr_action_conv_reformat_to_verbs(action->type, &verb_reformat_type);
1284 [ # # ]: 0 : if (ret)
1285 : 0 : return rte_errno;
1286 : :
1287 : : /* Create the reformat type for root table */
1288 [ # # ]: 0 : ibv_ctx = mlx5dr_context_get_local_ibv(action->ctx);
1289 : 0 : action->flow_action =
1290 : 0 : mlx5_glue->dv_create_flow_action_packet_reformat_root(ibv_ctx,
1291 : : data_sz,
1292 : : data,
1293 : : verb_reformat_type,
1294 : : ft_type);
1295 [ # # ]: 0 : if (!action->flow_action) {
1296 : 0 : DR_LOG(ERR, "Failed to create dv_create_flow reformat");
1297 : 0 : rte_errno = errno;
1298 : 0 : return rte_errno;
1299 : : }
1300 : :
1301 : : return 0;
1302 : : }
1303 : :
1304 : : static int
1305 : 0 : mlx5dr_action_handle_insert_with_ptr(struct mlx5dr_action *action,
1306 : : uint8_t num_of_hdrs,
1307 : : struct mlx5dr_action_reformat_header *hdrs,
1308 : : uint32_t log_bulk_sz, uint32_t reparse)
1309 : : {
1310 : : struct mlx5dr_devx_obj *arg_obj;
1311 : : size_t max_sz = 0;
1312 : : int ret, i;
1313 : :
1314 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
1315 [ # # ]: 0 : if (hdrs[i].sz % W_SIZE != 0) {
1316 : 0 : DR_LOG(ERR, "Header data size should be in WORD granularity");
1317 : 0 : rte_errno = EINVAL;
1318 : 0 : return rte_errno;
1319 : : }
1320 : 0 : max_sz = RTE_MAX(hdrs[i].sz, max_sz);
1321 : : }
1322 : :
1323 : : /* Allocate single shared arg object for all headers */
1324 : 0 : arg_obj = mlx5dr_arg_create(action->ctx,
1325 : 0 : hdrs->data,
1326 : : max_sz,
1327 : : log_bulk_sz,
1328 : 0 : action->flags & MLX5DR_ACTION_FLAG_SHARED);
1329 [ # # ]: 0 : if (!arg_obj)
1330 : 0 : return rte_errno;
1331 : :
1332 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
1333 : 0 : action[i].reformat.arg_obj = arg_obj;
1334 : 0 : action[i].reformat.header_size = hdrs[i].sz;
1335 : 0 : action[i].reformat.num_of_hdrs = num_of_hdrs;
1336 : 0 : action[i].reformat.max_hdr_sz = max_sz;
1337 : :
1338 [ # # ]: 0 : if (action[i].type == MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2 ||
1339 : : action[i].type == MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3) {
1340 : 0 : action[i].reformat.anchor = MLX5_HEADER_ANCHOR_PACKET_START;
1341 : 0 : action[i].reformat.offset = 0;
1342 : 0 : action[i].reformat.encap = 1;
1343 : : }
1344 : :
1345 [ # # ]: 0 : if (likely(reparse == MLX5DR_ACTION_STC_REPARSE_DEFAULT))
1346 : 0 : action[i].reformat.require_reparse = true;
1347 [ # # ]: 0 : else if (reparse == MLX5DR_ACTION_STC_REPARSE_ON)
1348 : 0 : action[i].reformat.require_reparse = true;
1349 : :
1350 : 0 : ret = mlx5dr_action_create_stcs(&action[i], NULL);
1351 [ # # ]: 0 : if (ret) {
1352 : 0 : DR_LOG(ERR, "Failed to create stc for reformat");
1353 : 0 : goto free_stc;
1354 : : }
1355 : : }
1356 : :
1357 : : return 0;
1358 : :
1359 : : free_stc:
1360 [ # # ]: 0 : while (i--)
1361 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
1362 : :
1363 : 0 : mlx5dr_cmd_destroy_obj(arg_obj);
1364 : 0 : return ret;
1365 : : }
1366 : :
1367 : : static int
1368 : 0 : mlx5dr_action_handle_l2_to_tunnel_l3(struct mlx5dr_action *action,
1369 : : uint8_t num_of_hdrs,
1370 : : struct mlx5dr_action_reformat_header *hdrs,
1371 : : uint32_t log_bulk_sz)
1372 : : {
1373 : : int ret;
1374 : :
1375 : : /* The action is remove-l2-header + insert-l3-header */
1376 : 0 : ret = mlx5dr_action_get_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
1377 [ # # ]: 0 : if (ret) {
1378 : 0 : DR_LOG(ERR, "Failed to create remove stc for reformat");
1379 : 0 : return ret;
1380 : : }
1381 : :
1382 : : /* Reuse the insert with pointer for the L2L3 header */
1383 : 0 : ret = mlx5dr_action_handle_insert_with_ptr(action,
1384 : : num_of_hdrs,
1385 : : hdrs,
1386 : : log_bulk_sz,
1387 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
1388 [ # # ]: 0 : if (ret)
1389 : 0 : goto put_shared_stc;
1390 : :
1391 : : return 0;
1392 : :
1393 : : put_shared_stc:
1394 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
1395 : 0 : return ret;
1396 : : }
1397 : :
1398 : 0 : static void mlx5dr_action_prepare_decap_l3_actions(size_t data_sz,
1399 : : uint8_t *mh_data,
1400 : : int *num_of_actions)
1401 : : {
1402 : : int actions;
1403 : : uint32_t i;
1404 : :
1405 : : /* Remove L2L3 outer headers */
1406 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, action_type,
1407 : : MLX5_MODIFICATION_TYPE_REMOVE);
1408 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, decap, 0x1);
1409 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, remove_start_anchor,
1410 : : MLX5_HEADER_ANCHOR_PACKET_START);
1411 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove, mh_data, remove_end_anchor,
1412 : : MLX5_HEADER_ANCHOR_INNER_IPV6_IPV4);
1413 : 0 : mh_data += MLX5DR_ACTION_DOUBLE_SIZE; /* Assume every action is 2 dw */
1414 : : actions = 1;
1415 : :
1416 : : /* Add the new header using inline action 4Byte at a time, the header
1417 : : * is added in reversed order to the beginning of the packet to avoid
1418 : : * incorrect parsing by the HW. Since header is 14B or 18B an extra
1419 : : * two bytes are padded and later removed.
1420 : : */
1421 [ # # ]: 0 : for (i = 0; i < data_sz / MLX5DR_ACTION_INLINE_DATA_SIZE + 1; i++) {
1422 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, action_type,
1423 : : MLX5_MODIFICATION_TYPE_INSERT);
1424 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, inline_data, 0x1);
1425 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, insert_anchor,
1426 : : MLX5_HEADER_ANCHOR_PACKET_START);
1427 [ # # ]: 0 : MLX5_SET(stc_ste_param_insert, mh_data, insert_size, 2);
1428 : 0 : mh_data += MLX5DR_ACTION_DOUBLE_SIZE;
1429 : 0 : actions++;
1430 : : }
1431 : :
1432 : : /* Remove first 2 extra bytes */
1433 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove_words, mh_data, action_type,
1434 : : MLX5_MODIFICATION_TYPE_REMOVE_WORDS);
1435 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove_words, mh_data, remove_start_anchor,
1436 : : MLX5_HEADER_ANCHOR_PACKET_START);
1437 : : /* The hardware expects here size in words (2 bytes) */
1438 [ # # ]: 0 : MLX5_SET(stc_ste_param_remove_words, mh_data, remove_size, 1);
1439 : 0 : actions++;
1440 : :
1441 : 0 : *num_of_actions = actions;
1442 : 0 : }
1443 : :
1444 : : static int
1445 : 0 : mlx5dr_action_handle_tunnel_l3_to_l2(struct mlx5dr_action *action,
1446 : : uint8_t num_of_hdrs,
1447 : : struct mlx5dr_action_reformat_header *hdrs,
1448 : : uint32_t log_bulk_sz)
1449 : : {
1450 : 0 : uint8_t mh_data[MLX5DR_ACTION_REFORMAT_DATA_SIZE] = {0};
1451 : : struct mlx5dr_devx_obj *arg_obj, *pat_obj;
1452 : 0 : struct mlx5dr_context *ctx = action->ctx;
1453 : : int num_of_actions;
1454 : : int mh_data_size;
1455 : : int ret, i;
1456 : :
1457 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
1458 [ # # ]: 0 : if (hdrs[i].sz != MLX5DR_ACTION_HDR_LEN_L2 &&
1459 : : hdrs[i].sz != MLX5DR_ACTION_HDR_LEN_L2_W_VLAN) {
1460 : 0 : DR_LOG(ERR, "Data size is not supported for decap-l3");
1461 : 0 : rte_errno = EINVAL;
1462 : 0 : return rte_errno;
1463 : : }
1464 : : }
1465 : :
1466 : : /* Create a full modify header action list in case shared */
1467 : 0 : mlx5dr_action_prepare_decap_l3_actions(hdrs->sz, mh_data, &num_of_actions);
1468 : 0 : mlx5dr_action_prepare_decap_l3_data(hdrs->data, mh_data, num_of_actions);
1469 : :
1470 : : /* All DecapL3 cases require the same max arg size */
1471 : 0 : arg_obj = mlx5dr_arg_create_modify_header_arg(ctx,
1472 : : (__be64 *)mh_data,
1473 : : num_of_actions,
1474 : : log_bulk_sz,
1475 : 0 : action->flags & MLX5DR_ACTION_FLAG_SHARED);
1476 [ # # ]: 0 : if (!arg_obj)
1477 : 0 : return rte_errno;
1478 : :
1479 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
1480 : : memset(mh_data, 0, MLX5DR_ACTION_REFORMAT_DATA_SIZE);
1481 : 0 : mlx5dr_action_prepare_decap_l3_actions(hdrs[i].sz, mh_data, &num_of_actions);
1482 : 0 : mh_data_size = num_of_actions * MLX5DR_MODIFY_ACTION_SIZE;
1483 : :
1484 : 0 : pat_obj = mlx5dr_pat_get_pattern(ctx, (__be64 *)mh_data, mh_data_size);
1485 [ # # ]: 0 : if (!pat_obj) {
1486 : 0 : DR_LOG(ERR, "Failed to allocate pattern for DecapL3");
1487 : 0 : goto free_stc_and_pat;
1488 : : }
1489 : :
1490 : 0 : action[i].modify_header.max_num_of_actions = num_of_actions;
1491 : 0 : action[i].modify_header.num_of_actions = num_of_actions;
1492 : 0 : action[i].modify_header.arg_obj = arg_obj;
1493 : 0 : action[i].modify_header.pat_obj = pat_obj;
1494 : 0 : action[i].modify_header.require_reparse =
1495 : 0 : mlx5dr_pat_require_reparse((__be64 *)mh_data, num_of_actions);
1496 : :
1497 : 0 : ret = mlx5dr_action_create_stcs(&action[i], NULL);
1498 [ # # ]: 0 : if (ret) {
1499 : 0 : mlx5dr_pat_put_pattern(ctx, pat_obj);
1500 : 0 : goto free_stc_and_pat;
1501 : : }
1502 : : }
1503 : :
1504 : : return 0;
1505 : :
1506 : :
1507 : : free_stc_and_pat:
1508 [ # # ]: 0 : while (i--) {
1509 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
1510 : 0 : mlx5dr_pat_put_pattern(ctx, action[i].modify_header.pat_obj);
1511 : : }
1512 : :
1513 : 0 : mlx5dr_cmd_destroy_obj(arg_obj);
1514 : 0 : return 0;
1515 : : }
1516 : :
1517 : : static int
1518 : 0 : mlx5dr_action_create_reformat_hws(struct mlx5dr_action *action,
1519 : : uint8_t num_of_hdrs,
1520 : : struct mlx5dr_action_reformat_header *hdrs,
1521 : : uint32_t bulk_size)
1522 : : {
1523 : : int ret;
1524 : :
1525 [ # # # # : 0 : switch (action->type) {
# ]
1526 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
1527 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
1528 : 0 : break;
1529 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
1530 : 0 : ret = mlx5dr_action_handle_insert_with_ptr(action, num_of_hdrs, hdrs, bulk_size,
1531 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
1532 : 0 : break;
1533 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
1534 : 0 : ret = mlx5dr_action_handle_l2_to_tunnel_l3(action, num_of_hdrs, hdrs, bulk_size);
1535 : 0 : break;
1536 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
1537 : 0 : ret = mlx5dr_action_handle_tunnel_l3_to_l2(action, num_of_hdrs, hdrs, bulk_size);
1538 : 0 : break;
1539 : 0 : default:
1540 : 0 : DR_LOG(ERR, "Invalid HWS reformat action type");
1541 : 0 : rte_errno = EINVAL;
1542 : 0 : return rte_errno;
1543 : : }
1544 : :
1545 : : return ret;
1546 : : }
1547 : :
1548 : : struct mlx5dr_action *
1549 : 0 : mlx5dr_action_create_reformat(struct mlx5dr_context *ctx,
1550 : : enum mlx5dr_action_type reformat_type,
1551 : : uint8_t num_of_hdrs,
1552 : : struct mlx5dr_action_reformat_header *hdrs,
1553 : : uint32_t log_bulk_size,
1554 : : uint32_t flags)
1555 : : {
1556 : : struct mlx5dr_action *action;
1557 : : int ret;
1558 : :
1559 [ # # ]: 0 : if (!num_of_hdrs) {
1560 : 0 : DR_LOG(ERR, "Reformat num_of_hdrs cannot be zero");
1561 : 0 : rte_errno = EINVAL;
1562 : 0 : return NULL;
1563 : : }
1564 : :
1565 : 0 : action = mlx5dr_action_create_generic_bulk(ctx, flags, reformat_type, num_of_hdrs);
1566 [ # # ]: 0 : if (!action)
1567 : : return NULL;
1568 : :
1569 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1570 [ # # ]: 0 : if (log_bulk_size) {
1571 : 0 : DR_LOG(ERR, "Bulk reformat not supported over root");
1572 : 0 : rte_errno = ENOTSUP;
1573 : 0 : goto free_action;
1574 : : }
1575 : :
1576 [ # # # # ]: 0 : ret = mlx5dr_action_create_reformat_root(action,
1577 : : hdrs ? hdrs->sz : 0,
1578 : : hdrs ? hdrs->data : NULL);
1579 [ # # ]: 0 : if (ret) {
1580 : 0 : DR_LOG(ERR, "Failed to create root reformat action");
1581 : 0 : goto free_action;
1582 : : }
1583 : :
1584 : : return action;
1585 : : }
1586 : :
1587 [ # # ]: 0 : if (!mlx5dr_action_is_hws_flags(flags) ||
1588 [ # # # # ]: 0 : ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_hdrs > 1))) {
1589 : 0 : DR_LOG(ERR, "Reformat flags don't fit HWS (flags: 0x%x)", flags);
1590 : 0 : rte_errno = EINVAL;
1591 : 0 : goto free_action;
1592 : : }
1593 : :
1594 : 0 : ret = mlx5dr_action_create_reformat_hws(action, num_of_hdrs, hdrs, log_bulk_size);
1595 [ # # ]: 0 : if (ret) {
1596 : 0 : DR_LOG(ERR, "Failed to create HWS reformat action");
1597 : 0 : goto free_action;
1598 : : }
1599 : :
1600 : : return action;
1601 : :
1602 : 0 : free_action:
1603 : : simple_free(action);
1604 : 0 : return NULL;
1605 : : }
1606 : :
1607 : : static int
1608 : 0 : mlx5dr_action_create_modify_header_root(struct mlx5dr_action *action,
1609 : : size_t actions_sz,
1610 : : __be64 *actions)
1611 : : {
1612 : : enum mlx5dv_flow_table_type ft_type = 0;
1613 : : struct ibv_context *local_ibv_ctx;
1614 : : int ret;
1615 : :
1616 [ # # ]: 0 : ret = mlx5dr_action_conv_flags_to_ft_type(action->flags, &ft_type);
1617 : : if (ret)
1618 : 0 : return rte_errno;
1619 : :
1620 [ # # ]: 0 : local_ibv_ctx = mlx5dr_context_get_local_ibv(action->ctx);
1621 : :
1622 : 0 : action->flow_action =
1623 : 0 : mlx5_glue->dv_create_flow_action_modify_header_root(local_ibv_ctx,
1624 : : actions_sz,
1625 : : (uint64_t *)actions,
1626 : : ft_type);
1627 [ # # ]: 0 : if (!action->flow_action) {
1628 : 0 : rte_errno = errno;
1629 : 0 : return rte_errno;
1630 : : }
1631 : :
1632 : : return 0;
1633 : : }
1634 : :
1635 : : static int
1636 : 0 : mlx5dr_action_create_modify_header_hws(struct mlx5dr_action *action,
1637 : : uint8_t num_of_patterns,
1638 : : struct mlx5dr_action_mh_pattern *pattern,
1639 : : uint32_t log_bulk_size,
1640 : : uint32_t reparse)
1641 : : {
1642 : : struct mlx5dr_devx_obj *pat_obj, *arg_obj = NULL;
1643 : 0 : struct mlx5dr_context *ctx = action->ctx;
1644 : : uint16_t num_actions, max_mh_actions = 0;
1645 : : int i, ret;
1646 : :
1647 : : /* Calculate maximum number of mh actions for shared arg allocation */
1648 [ # # ]: 0 : for (i = 0; i < num_of_patterns; i++)
1649 : 0 : max_mh_actions = RTE_MAX(max_mh_actions, pattern[i].sz / MLX5DR_MODIFY_ACTION_SIZE);
1650 : :
1651 : : /* Allocate single shared arg for all patterns based on the max size */
1652 [ # # ]: 0 : if (max_mh_actions > 1) {
1653 : 0 : arg_obj = mlx5dr_arg_create_modify_header_arg(ctx,
1654 : : pattern->data,
1655 : : max_mh_actions,
1656 : : log_bulk_size,
1657 : 0 : action->flags &
1658 : : MLX5DR_ACTION_FLAG_SHARED);
1659 [ # # ]: 0 : if (!arg_obj)
1660 : 0 : return rte_errno;
1661 : : }
1662 : :
1663 [ # # ]: 0 : for (i = 0; i < num_of_patterns; i++) {
1664 [ # # ]: 0 : if (!mlx5dr_pat_verify_actions(pattern[i].data, pattern[i].sz)) {
1665 : 0 : DR_LOG(ERR, "Fail to verify pattern modify actions");
1666 : 0 : rte_errno = EINVAL;
1667 : 0 : goto free_stc_and_pat;
1668 : : }
1669 : :
1670 : 0 : num_actions = pattern[i].sz / MLX5DR_MODIFY_ACTION_SIZE;
1671 : 0 : action[i].modify_header.num_of_patterns = num_of_patterns;
1672 : 0 : action[i].modify_header.max_num_of_actions = max_mh_actions;
1673 : 0 : action[i].modify_header.num_of_actions = num_actions;
1674 : :
1675 [ # # ]: 0 : if (likely(reparse == MLX5DR_ACTION_STC_REPARSE_DEFAULT))
1676 : 0 : action[i].modify_header.require_reparse =
1677 : 0 : mlx5dr_pat_require_reparse(pattern[i].data, num_actions);
1678 [ # # ]: 0 : else if (reparse == MLX5DR_ACTION_STC_REPARSE_ON)
1679 : 0 : action[i].modify_header.require_reparse = true;
1680 : :
1681 [ # # ]: 0 : if (num_actions == 1) {
1682 : : pat_obj = NULL;
1683 : : /* Optimize single modify action to be used inline */
1684 : 0 : action[i].modify_header.single_action = pattern[i].data[0];
1685 : 0 : action[i].modify_header.single_action_type =
1686 [ # # ]: 0 : MLX5_GET(set_action_in, pattern[i].data, action_type);
1687 : : } else {
1688 : : /* Multiple modify actions require a pattern */
1689 : 0 : pat_obj = mlx5dr_pat_get_pattern(ctx, pattern[i].data, pattern[i].sz);
1690 [ # # ]: 0 : if (!pat_obj) {
1691 : 0 : DR_LOG(ERR, "Failed to allocate pattern for modify header");
1692 : 0 : goto free_stc_and_pat;
1693 : : }
1694 : :
1695 : 0 : action[i].modify_header.arg_obj = arg_obj;
1696 : 0 : action[i].modify_header.pat_obj = pat_obj;
1697 : : }
1698 : : /* Allocate STC for each action representing a header */
1699 : 0 : ret = mlx5dr_action_create_stcs(&action[i], NULL);
1700 [ # # ]: 0 : if (ret) {
1701 [ # # ]: 0 : if (pat_obj)
1702 : 0 : mlx5dr_pat_put_pattern(ctx, pat_obj);
1703 : 0 : goto free_stc_and_pat;
1704 : : }
1705 : : }
1706 : :
1707 : : return 0;
1708 : :
1709 : : free_stc_and_pat:
1710 [ # # ]: 0 : while (i--) {
1711 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
1712 [ # # ]: 0 : if (action[i].modify_header.pat_obj)
1713 : 0 : mlx5dr_pat_put_pattern(ctx, action[i].modify_header.pat_obj);
1714 : : }
1715 : :
1716 [ # # ]: 0 : if (arg_obj)
1717 : 0 : mlx5dr_cmd_destroy_obj(arg_obj);
1718 : :
1719 : 0 : return rte_errno;
1720 : : }
1721 : :
1722 : : static struct mlx5dr_action *
1723 : 0 : mlx5dr_action_create_modify_header_reparse(struct mlx5dr_context *ctx,
1724 : : uint8_t num_of_patterns,
1725 : : struct mlx5dr_action_mh_pattern *patterns,
1726 : : uint32_t log_bulk_size,
1727 : : uint32_t flags, uint32_t reparse)
1728 : : {
1729 : : struct mlx5dr_action *action;
1730 : : int ret;
1731 : :
1732 [ # # ]: 0 : if (!num_of_patterns) {
1733 : 0 : DR_LOG(ERR, "Invalid number of patterns");
1734 : 0 : rte_errno = ENOTSUP;
1735 : 0 : return NULL;
1736 : : }
1737 : :
1738 : 0 : action = mlx5dr_action_create_generic_bulk(ctx, flags,
1739 : : MLX5DR_ACTION_TYP_MODIFY_HDR,
1740 : : num_of_patterns);
1741 [ # # ]: 0 : if (!action)
1742 : : return NULL;
1743 : :
1744 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1745 [ # # ]: 0 : if (log_bulk_size) {
1746 : 0 : DR_LOG(ERR, "Bulk modify-header not supported over root");
1747 : 0 : rte_errno = ENOTSUP;
1748 : 0 : goto free_action;
1749 : : }
1750 : :
1751 [ # # ]: 0 : if (num_of_patterns != 1) {
1752 : 0 : DR_LOG(ERR, "Only a single pattern supported over root");
1753 : 0 : rte_errno = ENOTSUP;
1754 : 0 : goto free_action;
1755 : : }
1756 : :
1757 : 0 : ret = mlx5dr_action_create_modify_header_root(action,
1758 : : patterns->sz,
1759 : : patterns->data);
1760 [ # # ]: 0 : if (ret)
1761 : 0 : goto free_action;
1762 : :
1763 : : return action;
1764 : : }
1765 : :
1766 [ # # # # ]: 0 : if ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_patterns > 1)) {
1767 : 0 : DR_LOG(ERR, "Action cannot be shared with requested pattern or size");
1768 : 0 : rte_errno = EINVAL;
1769 : 0 : goto free_action;
1770 : : }
1771 : :
1772 : 0 : ret = mlx5dr_action_create_modify_header_hws(action,
1773 : : num_of_patterns,
1774 : : patterns,
1775 : : log_bulk_size,
1776 : : reparse);
1777 [ # # ]: 0 : if (ret)
1778 : 0 : goto free_action;
1779 : :
1780 : : return action;
1781 : :
1782 : 0 : free_action:
1783 : : simple_free(action);
1784 : 0 : return NULL;
1785 : : }
1786 : :
1787 : : struct mlx5dr_action *
1788 : 0 : mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
1789 : : uint8_t num_of_patterns,
1790 : : struct mlx5dr_action_mh_pattern *patterns,
1791 : : uint32_t log_bulk_size,
1792 : : uint32_t flags)
1793 : : {
1794 : 0 : return mlx5dr_action_create_modify_header_reparse(ctx, num_of_patterns, patterns,
1795 : : log_bulk_size, flags,
1796 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
1797 : : }
1798 : : static struct mlx5dr_devx_obj *
1799 : 0 : mlx5dr_action_dest_array_process_reformat(struct mlx5dr_context *ctx,
1800 : : enum mlx5dr_action_type type,
1801 : : void *reformat_data,
1802 : : size_t reformat_data_sz)
1803 : : {
1804 : 0 : struct mlx5dr_cmd_packet_reformat_create_attr pr_attr = {0};
1805 : : struct mlx5dr_devx_obj *reformat_devx_obj;
1806 : :
1807 [ # # ]: 0 : if (!reformat_data || !reformat_data_sz) {
1808 : 0 : DR_LOG(ERR, "Empty reformat action or data");
1809 : 0 : rte_errno = EINVAL;
1810 : 0 : return NULL;
1811 : : }
1812 : :
1813 [ # # # ]: 0 : switch (type) {
1814 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
1815 : 0 : pr_attr.type = MLX5_PACKET_REFORMAT_CONTEXT_REFORMAT_TYPE_L2_TO_L2_TUNNEL;
1816 : 0 : break;
1817 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
1818 : 0 : pr_attr.type = MLX5_PACKET_REFORMAT_CONTEXT_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
1819 : 0 : break;
1820 : 0 : default:
1821 : 0 : DR_LOG(ERR, "Invalid value for reformat type");
1822 : 0 : rte_errno = EINVAL;
1823 : 0 : return NULL;
1824 : : }
1825 : : pr_attr.reformat_param_0 = 0;
1826 : 0 : pr_attr.data_sz = reformat_data_sz;
1827 : 0 : pr_attr.data = reformat_data;
1828 : :
1829 : 0 : reformat_devx_obj = mlx5dr_cmd_packet_reformat_create(ctx->ibv_ctx, &pr_attr);
1830 [ # # ]: 0 : if (!reformat_devx_obj)
1831 : 0 : return NULL;
1832 : :
1833 : : return reformat_devx_obj;
1834 : : }
1835 : :
1836 : : struct mlx5dr_action *
1837 : 0 : mlx5dr_action_create_dest_array(struct mlx5dr_context *ctx,
1838 : : size_t num_dest,
1839 : : struct mlx5dr_action_dest_attr *dests,
1840 : : uint32_t flags)
1841 : : {
1842 : : struct mlx5dr_cmd_set_fte_dest *dest_list = NULL;
1843 : : struct mlx5dr_devx_obj *packet_reformat = NULL;
1844 : 0 : struct mlx5dr_cmd_ft_create_attr ft_attr = {0};
1845 : 0 : struct mlx5dr_cmd_set_fte_attr fte_attr = {0};
1846 : : struct mlx5dr_cmd_forward_tbl *fw_island;
1847 : : enum mlx5dr_table_type table_type;
1848 : : struct mlx5dr_action *action;
1849 : : uint32_t i;
1850 : : int ret;
1851 : :
1852 [ # # ]: 0 : if (num_dest <= 1) {
1853 : 0 : rte_errno = EINVAL;
1854 : 0 : DR_LOG(ERR, "Action must have multiple dests");
1855 : 0 : return NULL;
1856 : : }
1857 : :
1858 [ # # ]: 0 : if (flags == (MLX5DR_ACTION_FLAG_HWS_RX | MLX5DR_ACTION_FLAG_SHARED)) {
1859 : : ft_attr.type = FS_FT_NIC_RX;
1860 : 0 : ft_attr.level = MLX5_IFC_MULTI_PATH_FT_MAX_LEVEL - 1;
1861 : : table_type = MLX5DR_TABLE_TYPE_NIC_RX;
1862 [ # # ]: 0 : } else if (flags == (MLX5DR_ACTION_FLAG_HWS_FDB | MLX5DR_ACTION_FLAG_SHARED)) {
1863 : 0 : ft_attr.type = FS_FT_FDB;
1864 : 0 : ft_attr.level = ctx->caps->fdb_ft.max_level - 1;
1865 : : table_type = MLX5DR_TABLE_TYPE_FDB;
1866 : : } else {
1867 : 0 : DR_LOG(ERR, "Action flags not supported");
1868 : 0 : rte_errno = ENOTSUP;
1869 : 0 : return NULL;
1870 : : }
1871 : :
1872 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx)) {
1873 : 0 : DR_LOG(ERR, "Cannot use this action in shared GVMI context");
1874 : 0 : rte_errno = ENOTSUP;
1875 : 0 : return NULL;
1876 : : }
1877 : :
1878 : : dest_list = simple_calloc(num_dest, sizeof(*dest_list));
1879 [ # # ]: 0 : if (!dest_list) {
1880 : 0 : DR_LOG(ERR, "Failed to allocate memory for destinations");
1881 : 0 : rte_errno = ENOMEM;
1882 : 0 : return NULL;
1883 : : }
1884 : :
1885 [ # # ]: 0 : for (i = 0; i < num_dest; i++) {
1886 : 0 : enum mlx5dr_action_type *action_type = dests[i].action_type;
1887 : :
1888 [ # # ]: 0 : if (!mlx5dr_action_check_combo(dests[i].action_type, table_type)) {
1889 : 0 : DR_LOG(ERR, "Invalid combination of actions");
1890 : 0 : rte_errno = EINVAL;
1891 : 0 : goto free_dest_list;
1892 : : }
1893 : :
1894 [ # # ]: 0 : for (; *action_type != MLX5DR_ACTION_TYP_LAST; action_type++) {
1895 [ # # # # : 0 : switch (*action_type) {
# # ]
1896 : 0 : case MLX5DR_ACTION_TYP_TBL:
1897 : 0 : dest_list[i].destination_type =
1898 : : MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
1899 : 0 : dest_list[i].destination_id = dests[i].dest->devx_dest.devx_obj->id;
1900 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1901 : 0 : fte_attr.ignore_flow_level = 1;
1902 : 0 : break;
1903 : 0 : case MLX5DR_ACTION_TYP_MISS:
1904 [ # # ]: 0 : if (table_type != MLX5DR_TABLE_TYPE_FDB) {
1905 : 0 : DR_LOG(ERR, "Miss action supported for FDB only");
1906 : 0 : rte_errno = ENOTSUP;
1907 : 0 : goto free_dest_list;
1908 : : }
1909 : 0 : dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
1910 : 0 : dest_list[i].destination_id =
1911 : 0 : ctx->caps->eswitch_manager_vport_number;
1912 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1913 : 0 : break;
1914 : 0 : case MLX5DR_ACTION_TYP_VPORT:
1915 : 0 : dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
1916 : 0 : dest_list[i].destination_id = dests[i].dest->vport.vport_num;
1917 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1918 [ # # ]: 0 : if (ctx->caps->merged_eswitch) {
1919 : 0 : dest_list[i].ext_flags |=
1920 : : MLX5DR_CMD_EXT_DEST_ESW_OWNER_VHCA_ID;
1921 : 0 : dest_list[i].esw_owner_vhca_id =
1922 : 0 : dests[i].dest->vport.esw_owner_vhca_id;
1923 : : }
1924 : : break;
1925 : 0 : case MLX5DR_ACTION_TYP_TIR:
1926 : 0 : dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_TIR;
1927 : 0 : dest_list[i].destination_id = dests[i].dest->devx_dest.devx_obj->id;
1928 : 0 : fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1929 : 0 : break;
1930 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
1931 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
1932 : 0 : packet_reformat = mlx5dr_action_dest_array_process_reformat
1933 : : (ctx,
1934 : : *action_type,
1935 : : dests[i].reformat.reformat_data,
1936 : : dests[i].reformat.reformat_data_sz);
1937 [ # # ]: 0 : if (!packet_reformat)
1938 : 0 : goto free_dest_list;
1939 : :
1940 : 0 : dest_list[i].ext_flags |= MLX5DR_CMD_EXT_DEST_REFORMAT;
1941 : 0 : dest_list[i].ext_reformat = packet_reformat;
1942 : 0 : ft_attr.reformat_en = true;
1943 : 0 : fte_attr.extended_dest = 1;
1944 : 0 : break;
1945 : 0 : default:
1946 : 0 : DR_LOG(ERR, "Unsupported action in dest_array");
1947 : 0 : rte_errno = ENOTSUP;
1948 : 0 : goto free_dest_list;
1949 : : }
1950 : : }
1951 : : }
1952 : 0 : fte_attr.dests_num = num_dest;
1953 : 0 : fte_attr.dests = dest_list;
1954 : :
1955 : 0 : fw_island = mlx5dr_cmd_forward_tbl_create(ctx->ibv_ctx, &ft_attr, &fte_attr);
1956 [ # # ]: 0 : if (!fw_island)
1957 : 0 : goto free_dest_list;
1958 : :
1959 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DEST_ARRAY);
1960 [ # # ]: 0 : if (!action)
1961 : 0 : goto destroy_fw_island;
1962 : :
1963 : 0 : ret = mlx5dr_action_create_stcs(action, fw_island->ft);
1964 [ # # ]: 0 : if (ret)
1965 : 0 : goto free_action;
1966 : :
1967 : 0 : action->dest_array.fw_island = fw_island;
1968 : 0 : action->dest_array.num_dest = num_dest;
1969 : 0 : action->dest_array.dest_list = dest_list;
1970 : :
1971 : 0 : return action;
1972 : :
1973 : : free_action:
1974 : : simple_free(action);
1975 : 0 : destroy_fw_island:
1976 : 0 : mlx5dr_cmd_forward_tbl_destroy(fw_island);
1977 : : free_dest_list:
1978 [ # # ]: 0 : for (i = 0; i < num_dest; i++) {
1979 [ # # ]: 0 : if (dest_list[i].ext_reformat)
1980 : 0 : mlx5dr_cmd_destroy_obj(dest_list[i].ext_reformat);
1981 : : }
1982 : : simple_free(dest_list);
1983 : 0 : return NULL;
1984 : : }
1985 : :
1986 : : struct mlx5dr_action *
1987 : 0 : mlx5dr_action_create_dest_root(struct mlx5dr_context *ctx,
1988 : : uint16_t priority,
1989 : : uint32_t flags)
1990 : : {
1991 : 0 : struct mlx5dv_steering_anchor_attr attr = {0};
1992 : : struct mlx5dv_steering_anchor *sa;
1993 : : struct mlx5dr_action *action;
1994 : : int ret;
1995 : :
1996 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
1997 : 0 : DR_LOG(ERR, "Action flags must be only non root (HWS)");
1998 : 0 : rte_errno = ENOTSUP;
1999 : 0 : return NULL;
2000 : : }
2001 : :
2002 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(ctx)) {
2003 : 0 : DR_LOG(ERR, "Cannot use this action in shared GVMI context");
2004 : 0 : rte_errno = ENOTSUP;
2005 : 0 : return NULL;
2006 : : }
2007 : :
2008 : : if (mlx5dr_action_conv_flags_to_ft_type(flags, &attr.ft_type))
2009 : 0 : return NULL;
2010 : :
2011 : 0 : attr.priority = priority;
2012 : :
2013 : 0 : sa = mlx5_glue->create_steering_anchor(ctx->ibv_ctx, &attr);
2014 [ # # ]: 0 : if (!sa) {
2015 : 0 : DR_LOG(ERR, "Creation of steering anchor failed");
2016 : 0 : return NULL;
2017 : : }
2018 : :
2019 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DEST_ROOT);
2020 [ # # ]: 0 : if (!action)
2021 : 0 : goto free_steering_anchor;
2022 : :
2023 : 0 : action->root_tbl.sa = sa;
2024 : :
2025 : 0 : ret = mlx5dr_action_create_stcs(action, NULL);
2026 [ # # ]: 0 : if (ret)
2027 : 0 : goto free_action;
2028 : :
2029 : : return action;
2030 : :
2031 : : free_action:
2032 : : simple_free(action);
2033 : 0 : free_steering_anchor:
2034 : 0 : mlx5_glue->destroy_steering_anchor(sa);
2035 : 0 : return NULL;
2036 : : }
2037 : :
2038 : : static struct mlx5dr_action *
2039 : 0 : mlx5dr_action_create_insert_header_reparse(struct mlx5dr_context *ctx,
2040 : : uint8_t num_of_hdrs,
2041 : : struct mlx5dr_action_insert_header *hdrs,
2042 : : uint32_t log_bulk_size,
2043 : : uint32_t flags, uint32_t reparse)
2044 : : {
2045 : : struct mlx5dr_action_reformat_header *reformat_hdrs;
2046 : : struct mlx5dr_action *action;
2047 : : int i, ret;
2048 : :
2049 [ # # ]: 0 : if (!num_of_hdrs) {
2050 : 0 : DR_LOG(ERR, "Reformat num_of_hdrs cannot be zero");
2051 : 0 : rte_errno = EINVAL;
2052 : 0 : return NULL;
2053 : : }
2054 : :
2055 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
2056 : 0 : DR_LOG(ERR, "Dynamic reformat action not supported over root");
2057 : 0 : rte_errno = ENOTSUP;
2058 : 0 : return NULL;
2059 : : }
2060 : :
2061 [ # # ]: 0 : if (!mlx5dr_action_is_hws_flags(flags) ||
2062 [ # # # # ]: 0 : ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_hdrs > 1))) {
2063 : 0 : DR_LOG(ERR, "Reformat flags don't fit HWS (flags: 0x%x)", flags);
2064 : 0 : rte_errno = EINVAL;
2065 : 0 : return NULL;
2066 : : }
2067 : :
2068 : 0 : action = mlx5dr_action_create_generic_bulk(ctx, flags,
2069 : : MLX5DR_ACTION_TYP_INSERT_HEADER,
2070 : : num_of_hdrs);
2071 [ # # ]: 0 : if (!action)
2072 : : return NULL;
2073 : :
2074 : 0 : reformat_hdrs = simple_calloc(num_of_hdrs, sizeof(*reformat_hdrs));
2075 [ # # ]: 0 : if (!reformat_hdrs) {
2076 : 0 : DR_LOG(ERR, "Failed to allocate memory for reformat_hdrs");
2077 : 0 : rte_errno = ENOMEM;
2078 : 0 : goto free_action;
2079 : : }
2080 : :
2081 [ # # ]: 0 : for (i = 0; i < num_of_hdrs; i++) {
2082 [ # # ]: 0 : if (hdrs[i].offset % W_SIZE != 0) {
2083 : 0 : DR_LOG(ERR, "Header offset should be in WORD granularity");
2084 : 0 : rte_errno = EINVAL;
2085 : 0 : goto free_reformat_hdrs;
2086 : : }
2087 : :
2088 : 0 : action[i].reformat.anchor = hdrs[i].anchor;
2089 : 0 : action[i].reformat.encap = hdrs[i].encap;
2090 : 0 : action[i].reformat.offset = hdrs[i].offset;
2091 : 0 : reformat_hdrs[i].sz = hdrs[i].hdr.sz;
2092 : 0 : reformat_hdrs[i].data = hdrs[i].hdr.data;
2093 : : }
2094 : :
2095 : 0 : ret = mlx5dr_action_handle_insert_with_ptr(action, num_of_hdrs,
2096 : : reformat_hdrs, log_bulk_size,
2097 : : reparse);
2098 [ # # ]: 0 : if (ret) {
2099 : 0 : DR_LOG(ERR, "Failed to create HWS reformat action");
2100 : 0 : goto free_reformat_hdrs;
2101 : : }
2102 : :
2103 : : simple_free(reformat_hdrs);
2104 : :
2105 : 0 : return action;
2106 : :
2107 : 0 : free_reformat_hdrs:
2108 : : simple_free(reformat_hdrs);
2109 : 0 : free_action:
2110 : : simple_free(action);
2111 : 0 : return NULL;
2112 : : }
2113 : :
2114 : : struct mlx5dr_action *
2115 : 0 : mlx5dr_action_create_insert_header(struct mlx5dr_context *ctx,
2116 : : uint8_t num_of_hdrs,
2117 : : struct mlx5dr_action_insert_header *hdrs,
2118 : : uint32_t log_bulk_size,
2119 : : uint32_t flags)
2120 : : {
2121 : 0 : return mlx5dr_action_create_insert_header_reparse(ctx, num_of_hdrs, hdrs,
2122 : : log_bulk_size, flags,
2123 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT);
2124 : : }
2125 : :
2126 : : struct mlx5dr_action *
2127 : 0 : mlx5dr_action_create_remove_header(struct mlx5dr_context *ctx,
2128 : : struct mlx5dr_action_remove_header_attr *attr,
2129 : : uint32_t flags)
2130 : : {
2131 : : struct mlx5dr_action *action;
2132 : :
2133 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(flags)) {
2134 : 0 : DR_LOG(ERR, "Remove header action not supported over root");
2135 : 0 : rte_errno = ENOTSUP;
2136 : 0 : return NULL;
2137 : : }
2138 : :
2139 : : action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_REMOVE_HEADER);
2140 [ # # ]: 0 : if (!action)
2141 : : return NULL;
2142 : :
2143 [ # # # ]: 0 : switch (attr->type) {
2144 : 0 : case MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER:
2145 : 0 : action->remove_header.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER;
2146 : 0 : action->remove_header.start_anchor = attr->by_anchor.start_anchor;
2147 : 0 : action->remove_header.end_anchor = attr->by_anchor.end_anchor;
2148 : 0 : action->remove_header.decap = attr->by_anchor.decap;
2149 : 0 : break;
2150 : 0 : case MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET:
2151 [ # # ]: 0 : if (attr->by_offset.size % W_SIZE != 0) {
2152 : 0 : DR_LOG(ERR, "Invalid size, HW supports header remove in WORD granularity");
2153 : 0 : rte_errno = EINVAL;
2154 : 0 : goto free_action;
2155 : : }
2156 : :
2157 [ # # ]: 0 : if (attr->by_offset.size > MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE) {
2158 : 0 : DR_LOG(ERR, "Header removal size limited to %u bytes",
2159 : : MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE);
2160 : 0 : rte_errno = EINVAL;
2161 : 0 : goto free_action;
2162 : : }
2163 : :
2164 : 0 : action->remove_header.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET;
2165 : 0 : action->remove_header.start_anchor = attr->by_offset.start_anchor;
2166 : 0 : action->remove_header.num_of_words = attr->by_offset.size / W_SIZE;
2167 : 0 : break;
2168 : 0 : default:
2169 : 0 : DR_LOG(ERR, "Unsupported remove header type %u", attr->type);
2170 : 0 : rte_errno = ENOTSUP;
2171 : 0 : goto free_action;
2172 : : }
2173 : :
2174 [ # # ]: 0 : if (mlx5dr_action_create_stcs(action, NULL))
2175 : 0 : goto free_action;
2176 : :
2177 : : return action;
2178 : :
2179 : 0 : free_action:
2180 : : simple_free(action);
2181 : 0 : return NULL;
2182 : : }
2183 : :
2184 : : static void *
2185 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
2186 : : {
2187 : : struct mlx5dr_action_mh_pattern pattern;
2188 : 0 : __be64 cmd[3] = {0};
2189 : : uint16_t mod_id;
2190 : :
2191 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
2192 [ # # ]: 0 : if (!mod_id) {
2193 : 0 : rte_errno = EINVAL;
2194 : 0 : return NULL;
2195 : : }
2196 : :
2197 : : /*
2198 : : * Backup ipv6_route_ext.next_hdr to ipv6_route_ext.seg_left.
2199 : : * Next_hdr will be copied to ipv6.protocol after pop done.
2200 : : */
2201 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], action_type, MLX5_MODIFICATION_TYPE_COPY);
2202 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], length, 8);
2203 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], src_offset, 24);
2204 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], src_field, mod_id);
2205 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[0], dst_field, mod_id);
2206 : :
2207 : : /* Add nop between the continuous same modify field id */
2208 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[1], action_type, MLX5_MODIFICATION_TYPE_NOP);
2209 : :
2210 : : /* Clear next_hdr for right checksum */
2211 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], action_type, MLX5_MODIFICATION_TYPE_SET);
2212 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], length, 8);
2213 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], offset, 24);
2214 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[2], field, mod_id);
2215 : :
2216 : 0 : pattern.data = cmd;
2217 : 0 : pattern.sz = sizeof(cmd);
2218 : :
2219 : 0 : return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
2220 : 0 : action->flags,
2221 : : MLX5DR_ACTION_STC_REPARSE_ON);
2222 : : }
2223 : :
2224 : : static void *
2225 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(struct mlx5dr_action *action)
2226 : : {
2227 : 0 : enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = {
2228 : : MLX5_MODI_OUT_DIPV6_127_96,
2229 : : MLX5_MODI_OUT_DIPV6_95_64,
2230 : : MLX5_MODI_OUT_DIPV6_63_32,
2231 : : MLX5_MODI_OUT_DIPV6_31_0
2232 : : };
2233 : : struct mlx5dr_action_mh_pattern pattern;
2234 : 0 : __be64 cmd[5] = {0};
2235 : : uint16_t mod_id;
2236 : : uint32_t i;
2237 : :
2238 : : /* Copy ipv6_route_ext[first_segment].dst_addr by flex parser to ipv6.dst_addr */
2239 [ # # ]: 0 : for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
2240 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, i + 1);
2241 [ # # ]: 0 : if (!mod_id) {
2242 : 0 : rte_errno = EINVAL;
2243 : 0 : return NULL;
2244 : : }
2245 : :
2246 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_COPY);
2247 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[i], dst_field, field[i]);
2248 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[i], src_field, mod_id);
2249 : : }
2250 : :
2251 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
2252 [ # # ]: 0 : if (!mod_id) {
2253 : 0 : rte_errno = EINVAL;
2254 : 0 : return NULL;
2255 : : }
2256 : :
2257 : : /* Restore next_hdr from seg_left for flex parser identifying */
2258 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_COPY);
2259 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], length, 8);
2260 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], dst_offset, 24);
2261 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], src_field, mod_id);
2262 [ # # ]: 0 : MLX5_SET(copy_action_in, &cmd[4], dst_field, mod_id);
2263 : :
2264 : 0 : pattern.data = cmd;
2265 : 0 : pattern.sz = sizeof(cmd);
2266 : :
2267 : 0 : return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
2268 : 0 : action->flags,
2269 : : MLX5DR_ACTION_STC_REPARSE_ON);
2270 : : }
2271 : :
2272 : : static void *
2273 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(struct mlx5dr_action *action)
2274 : : {
2275 : 0 : uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0};
2276 : : struct mlx5dr_action_mh_pattern pattern;
2277 : : uint16_t mod_id;
2278 : :
2279 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
2280 [ # # ]: 0 : if (!mod_id) {
2281 : 0 : rte_errno = EINVAL;
2282 : 0 : return NULL;
2283 : : }
2284 : :
2285 : : /* Copy ipv6_route_ext.next_hdr to ipv6.protocol */
2286 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_COPY);
2287 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, length, 8);
2288 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, src_offset, 24);
2289 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, src_field, mod_id);
2290 [ # # ]: 0 : MLX5_SET(copy_action_in, cmd, dst_field, MLX5_MODI_OUT_IPV6_NEXT_HDR);
2291 : :
2292 : 0 : pattern.data = (__be64 *)cmd;
2293 : 0 : pattern.sz = sizeof(cmd);
2294 : :
2295 : 0 : return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
2296 : 0 : action->flags,
2297 : : MLX5DR_ACTION_STC_REPARSE_OFF);
2298 : : }
2299 : :
2300 : : static int
2301 : 0 : mlx5dr_action_create_pop_ipv6_route_ext(struct mlx5dr_action *action)
2302 : : {
2303 : 0 : uint8_t anchor_id = flow_hw_get_ipv6_route_ext_anchor_from_ctx(action->ctx);
2304 : : struct mlx5dr_action_remove_header_attr hdr_attr;
2305 : : uint32_t i;
2306 : :
2307 [ # # ]: 0 : if (!anchor_id) {
2308 : 0 : rte_errno = EINVAL;
2309 : 0 : return rte_errno;
2310 : : }
2311 : :
2312 : 0 : action->ipv6_route_ext.action[0] =
2313 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(action);
2314 : 0 : action->ipv6_route_ext.action[1] =
2315 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(action);
2316 : 0 : action->ipv6_route_ext.action[2] =
2317 : 0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(action);
2318 : :
2319 : 0 : hdr_attr.by_anchor.decap = 1;
2320 : 0 : hdr_attr.by_anchor.start_anchor = anchor_id;
2321 : 0 : hdr_attr.by_anchor.end_anchor = MLX5_HEADER_ANCHOR_TCP_UDP;
2322 : 0 : hdr_attr.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER;
2323 : 0 : action->ipv6_route_ext.action[3] =
2324 : 0 : mlx5dr_action_create_remove_header(action->ctx, &hdr_attr, action->flags);
2325 : :
2326 [ # # # # ]: 0 : if (!action->ipv6_route_ext.action[0] || !action->ipv6_route_ext.action[1] ||
2327 [ # # # # ]: 0 : !action->ipv6_route_ext.action[2] || !action->ipv6_route_ext.action[3]) {
2328 : 0 : DR_LOG(ERR, "Failed to create ipv6_route_ext pop subaction");
2329 : 0 : goto err;
2330 : : }
2331 : :
2332 : : return 0;
2333 : :
2334 : : err:
2335 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
2336 [ # # ]: 0 : if (action->ipv6_route_ext.action[i])
2337 : 0 : mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
2338 : :
2339 : 0 : return rte_errno;
2340 : : }
2341 : :
2342 : : static void *
2343 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
2344 : : {
2345 : : uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0};
2346 : : struct mlx5dr_action_mh_pattern pattern;
2347 : :
2348 : : /* Set ipv6.protocol to IPPROTO_ROUTING */
2349 : : MLX5_SET(set_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_SET);
2350 [ # # ]: 0 : MLX5_SET(set_action_in, cmd, length, 8);
2351 [ # # ]: 0 : MLX5_SET(set_action_in, cmd, field, MLX5_MODI_OUT_IPV6_NEXT_HDR);
2352 : 0 : MLX5_SET(set_action_in, cmd, data, IPPROTO_ROUTING);
2353 : :
2354 : 0 : pattern.data = (__be64 *)cmd;
2355 : 0 : pattern.sz = sizeof(cmd);
2356 : :
2357 : 0 : return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, 0,
2358 : 0 : action->flags | MLX5DR_ACTION_FLAG_SHARED);
2359 : : }
2360 : :
2361 : : static void *
2362 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr2(struct mlx5dr_action *action,
2363 : : uint32_t bulk_size,
2364 : : uint8_t *data)
2365 : : {
2366 : 0 : enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = {
2367 : : MLX5_MODI_OUT_DIPV6_127_96,
2368 : : MLX5_MODI_OUT_DIPV6_95_64,
2369 : : MLX5_MODI_OUT_DIPV6_63_32,
2370 : : MLX5_MODI_OUT_DIPV6_31_0
2371 : : };
2372 : : struct mlx5dr_action_mh_pattern pattern;
2373 : : uint32_t *ipv6_dst_addr = NULL;
2374 : : uint8_t seg_left, next_hdr;
2375 : 0 : __be64 cmd[5] = {0};
2376 : : uint16_t mod_id;
2377 : : uint32_t i;
2378 : :
2379 : : /* Fetch the last IPv6 address in the segment list */
2380 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
2381 [ # # ]: 0 : seg_left = MLX5_GET(header_ipv6_routing_ext, data, segments_left) - 1;
2382 : 0 : ipv6_dst_addr = (uint32_t *)data + MLX5_ST_SZ_DW(header_ipv6_routing_ext) +
2383 : : seg_left * MLX5_ST_SZ_DW(definer_hl_ipv6_addr);
2384 : : }
2385 : :
2386 : : /* Copy IPv6 destination address from ipv6_route_ext.last_segment */
2387 [ # # ]: 0 : for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
2388 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_SET);
2389 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[i], field, field[i]);
2390 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
2391 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[i], data, be32toh(*ipv6_dst_addr++));
2392 : : }
2393 : :
2394 : 0 : mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
2395 [ # # ]: 0 : if (!mod_id) {
2396 : 0 : rte_errno = EINVAL;
2397 : 0 : return NULL;
2398 : : }
2399 : :
2400 : : /* Set ipv6_route_ext.next_hdr since initially pushed as 0 for right checksum */
2401 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_SET);
2402 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], length, 8);
2403 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], offset, 24);
2404 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], field, mod_id);
2405 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
2406 [ # # ]: 0 : next_hdr = MLX5_GET(header_ipv6_routing_ext, data, next_hdr);
2407 [ # # ]: 0 : MLX5_SET(set_action_in, &cmd[4], data, next_hdr);
2408 : : }
2409 : :
2410 : 0 : pattern.data = cmd;
2411 : 0 : pattern.sz = sizeof(cmd);
2412 : :
2413 : 0 : return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern,
2414 : : bulk_size, action->flags);
2415 : : }
2416 : :
2417 : : static int
2418 : 0 : mlx5dr_action_create_push_ipv6_route_ext(struct mlx5dr_action *action,
2419 : : struct mlx5dr_action_reformat_header *hdr,
2420 : : uint32_t bulk_size)
2421 : : {
2422 : 0 : struct mlx5dr_action_insert_header insert_hdr = { {0} };
2423 : : uint8_t header[MLX5_PUSH_MAX_LEN];
2424 : : uint32_t i;
2425 : :
2426 [ # # # # : 0 : if (!hdr || !hdr->sz || hdr->sz > MLX5_PUSH_MAX_LEN ||
# # ]
2427 [ # # # # ]: 0 : ((action->flags & MLX5DR_ACTION_FLAG_SHARED) && !hdr->data)) {
2428 : 0 : DR_LOG(ERR, "Invalid ipv6_route_ext header");
2429 : 0 : rte_errno = EINVAL;
2430 : 0 : return rte_errno;
2431 : : }
2432 : :
2433 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
2434 [ # # ]: 0 : memcpy(header, hdr->data, hdr->sz);
2435 : : /* Clear ipv6_route_ext.next_hdr for right checksum */
2436 [ # # ]: 0 : MLX5_SET(header_ipv6_routing_ext, header, next_hdr, 0);
2437 : : }
2438 : :
2439 : 0 : insert_hdr.anchor = MLX5_HEADER_ANCHOR_TCP_UDP;
2440 : 0 : insert_hdr.encap = 1;
2441 : 0 : insert_hdr.hdr.sz = hdr->sz;
2442 : 0 : insert_hdr.hdr.data = header;
2443 : 0 : action->ipv6_route_ext.action[0] =
2444 : 0 : mlx5dr_action_create_insert_header_reparse(action->ctx, 1, &insert_hdr,
2445 : : bulk_size, action->flags,
2446 : : MLX5DR_ACTION_STC_REPARSE_OFF);
2447 : 0 : action->ipv6_route_ext.action[1] =
2448 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr1(action);
2449 : 0 : action->ipv6_route_ext.action[2] =
2450 : 0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr2(action, bulk_size, hdr->data);
2451 : :
2452 [ # # ]: 0 : if (!action->ipv6_route_ext.action[0] ||
2453 [ # # # # ]: 0 : !action->ipv6_route_ext.action[1] ||
2454 : : !action->ipv6_route_ext.action[2]) {
2455 : 0 : DR_LOG(ERR, "Failed to create ipv6_route_ext push subaction");
2456 : 0 : goto err;
2457 : : }
2458 : :
2459 : : return 0;
2460 : :
2461 : : err:
2462 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
2463 [ # # ]: 0 : if (action->ipv6_route_ext.action[i])
2464 : 0 : mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
2465 : :
2466 : 0 : return rte_errno;
2467 : : }
2468 : :
2469 : : struct mlx5dr_action *
2470 : 0 : mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
2471 : : enum mlx5dr_action_type action_type,
2472 : : struct mlx5dr_action_reformat_header *hdr,
2473 : : uint32_t log_bulk_size,
2474 : : uint32_t flags)
2475 : : {
2476 : : struct mlx5dr_action *action;
2477 : : int ret;
2478 : :
2479 [ # # ]: 0 : if (!mlx5dr_action_is_hws_flags(flags) ||
2480 [ # # # # ]: 0 : ((flags & MLX5DR_ACTION_FLAG_SHARED) && log_bulk_size)) {
2481 : 0 : DR_LOG(ERR, "IPv6 extension flags don't fit HWS (flags: 0x%x)", flags);
2482 : 0 : rte_errno = EINVAL;
2483 : 0 : return NULL;
2484 : : }
2485 : :
2486 : : action = mlx5dr_action_create_generic(ctx, flags, action_type);
2487 [ # # ]: 0 : if (!action) {
2488 : 0 : rte_errno = ENOMEM;
2489 : 0 : return NULL;
2490 : : }
2491 : :
2492 [ # # # ]: 0 : switch (action_type) {
2493 : 0 : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
2494 [ # # ]: 0 : if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) {
2495 : 0 : DR_LOG(ERR, "Pop ipv6_route_ext must be shared");
2496 : 0 : rte_errno = EINVAL;
2497 : 0 : goto free_action;
2498 : : }
2499 : :
2500 : 0 : ret = mlx5dr_action_create_pop_ipv6_route_ext(action);
2501 : 0 : break;
2502 : 0 : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
2503 [ # # ]: 0 : if (!mlx5dr_context_cap_dynamic_reparse(ctx)) {
2504 : 0 : DR_LOG(ERR, "IPv6 routing extension push actions is not supported");
2505 : 0 : rte_errno = ENOTSUP;
2506 : 0 : goto free_action;
2507 : : }
2508 : :
2509 : 0 : ret = mlx5dr_action_create_push_ipv6_route_ext(action, hdr, log_bulk_size);
2510 : 0 : break;
2511 : 0 : default:
2512 : 0 : DR_LOG(ERR, "Unsupported action type %d\n", action_type);
2513 : 0 : rte_errno = ENOTSUP;
2514 : 0 : goto free_action;
2515 : : }
2516 : :
2517 [ # # ]: 0 : if (ret) {
2518 : 0 : DR_LOG(ERR, "Failed to create IPv6 extension reformat action");
2519 : 0 : goto free_action;
2520 : : }
2521 : :
2522 : : return action;
2523 : :
2524 : 0 : free_action:
2525 : : simple_free(action);
2526 : 0 : return NULL;
2527 : : }
2528 : :
2529 : 0 : static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action)
2530 : : {
2531 : : struct mlx5dr_devx_obj *obj = NULL;
2532 : : uint32_t i;
2533 : :
2534 [ # # # # : 0 : switch (action->type) {
# # # # #
# ]
2535 : 0 : case MLX5DR_ACTION_TYP_TIR:
2536 : 0 : mlx5dr_action_destroy_stcs(action);
2537 [ # # ]: 0 : if (mlx5dr_context_shared_gvmi_used(action->ctx))
2538 : 0 : mlx5dr_cmd_destroy_obj(action->alias.devx_obj);
2539 : : break;
2540 : 0 : case MLX5DR_ACTION_TYP_MISS:
2541 : : case MLX5DR_ACTION_TYP_TAG:
2542 : : case MLX5DR_ACTION_TYP_DROP:
2543 : : case MLX5DR_ACTION_TYP_CTR:
2544 : : case MLX5DR_ACTION_TYP_TBL:
2545 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
2546 : : case MLX5DR_ACTION_TYP_ASO_METER:
2547 : : case MLX5DR_ACTION_TYP_ASO_CT:
2548 : : case MLX5DR_ACTION_TYP_PUSH_VLAN:
2549 : : case MLX5DR_ACTION_TYP_REMOVE_HEADER:
2550 : 0 : mlx5dr_action_destroy_stcs(action);
2551 : 0 : break;
2552 : 0 : case MLX5DR_ACTION_TYP_DEST_ROOT:
2553 : 0 : mlx5dr_action_destroy_stcs(action);
2554 : 0 : mlx5_glue->destroy_steering_anchor(action->root_tbl.sa);
2555 : 0 : break;
2556 : 0 : case MLX5DR_ACTION_TYP_POP_VLAN:
2557 : 0 : mlx5dr_action_destroy_stcs(action);
2558 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
2559 : 0 : break;
2560 : 0 : case MLX5DR_ACTION_TYP_DEST_ARRAY:
2561 : 0 : mlx5dr_action_destroy_stcs(action);
2562 : 0 : mlx5dr_cmd_forward_tbl_destroy(action->dest_array.fw_island);
2563 [ # # ]: 0 : for (i = 0; i < action->dest_array.num_dest; i++) {
2564 [ # # ]: 0 : if (action->dest_array.dest_list[i].ext_reformat)
2565 : 0 : mlx5dr_cmd_destroy_obj
2566 : : (action->dest_array.dest_list[i].ext_reformat);
2567 : : }
2568 : 0 : simple_free(action->dest_array.dest_list);
2569 : : break;
2570 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
2571 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
2572 [ # # ]: 0 : for (i = 0; i < action->modify_header.num_of_patterns; i++) {
2573 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
2574 [ # # ]: 0 : if (action[i].modify_header.num_of_actions > 1) {
2575 : 0 : mlx5dr_pat_put_pattern(action[i].ctx,
2576 : : action[i].modify_header.pat_obj);
2577 : : /* Save shared arg object if was used to free */
2578 [ # # ]: 0 : if (action[i].modify_header.arg_obj)
2579 : : obj = action[i].modify_header.arg_obj;
2580 : : }
2581 : : }
2582 [ # # ]: 0 : if (obj)
2583 : 0 : mlx5dr_cmd_destroy_obj(obj);
2584 : : break;
2585 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
2586 : 0 : mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
2587 [ # # ]: 0 : for (i = 0; i < action->reformat.num_of_hdrs; i++)
2588 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
2589 : 0 : mlx5dr_cmd_destroy_obj(action->reformat.arg_obj);
2590 : 0 : break;
2591 : : case MLX5DR_ACTION_TYP_INSERT_HEADER:
2592 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
2593 [ # # ]: 0 : for (i = 0; i < action->reformat.num_of_hdrs; i++)
2594 : 0 : mlx5dr_action_destroy_stcs(&action[i]);
2595 : 0 : mlx5dr_cmd_destroy_obj(action->reformat.arg_obj);
2596 : 0 : break;
2597 : : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
2598 : : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
2599 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
2600 [ # # ]: 0 : if (action->ipv6_route_ext.action[i])
2601 : 0 : mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
2602 : : break;
2603 : : }
2604 : 0 : }
2605 : :
2606 : 0 : static void mlx5dr_action_destroy_root(struct mlx5dr_action *action)
2607 : : {
2608 [ # # ]: 0 : switch (action->type) {
2609 : 0 : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
2610 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
2611 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
2612 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
2613 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
2614 [ # # ]: 0 : ibv_destroy_flow_action(action->flow_action);
2615 : : break;
2616 : : }
2617 : 0 : }
2618 : :
2619 : 0 : int mlx5dr_action_destroy(struct mlx5dr_action *action)
2620 : : {
2621 [ # # ]: 0 : if (mlx5dr_action_is_root_flags(action->flags))
2622 : 0 : mlx5dr_action_destroy_root(action);
2623 : : else
2624 : 0 : mlx5dr_action_destroy_hws(action);
2625 : :
2626 : : simple_free(action);
2627 : 0 : return 0;
2628 : : }
2629 : :
2630 : : /* Called under pthread_spin_lock(&ctx->ctrl_lock) */
2631 : 0 : int mlx5dr_action_get_default_stc(struct mlx5dr_context *ctx,
2632 : : uint8_t tbl_type)
2633 : : {
2634 : 0 : struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
2635 : : struct mlx5dr_action_default_stc *default_stc;
2636 : : int ret;
2637 : :
2638 [ # # ]: 0 : if (ctx->common_res[tbl_type].default_stc) {
2639 : 0 : ctx->common_res[tbl_type].default_stc->refcount++;
2640 : 0 : return 0;
2641 : : }
2642 : :
2643 : : default_stc = simple_calloc(1, sizeof(*default_stc));
2644 [ # # ]: 0 : if (!default_stc) {
2645 : 0 : DR_LOG(ERR, "Failed to allocate memory for default STCs");
2646 : 0 : rte_errno = ENOMEM;
2647 : 0 : return rte_errno;
2648 : : }
2649 : :
2650 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_NOP;
2651 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW0;
2652 : 0 : stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
2653 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
2654 : : &default_stc->nop_ctr);
2655 [ # # ]: 0 : if (ret) {
2656 : 0 : DR_LOG(ERR, "Failed to allocate default counter STC");
2657 : 0 : goto free_default_stc;
2658 : : }
2659 : :
2660 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
2661 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
2662 : : &default_stc->nop_dw5);
2663 [ # # ]: 0 : if (ret) {
2664 : 0 : DR_LOG(ERR, "Failed to allocate default NOP DW5 STC");
2665 : 0 : goto free_nop_ctr;
2666 : : }
2667 : :
2668 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW6;
2669 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
2670 : : &default_stc->nop_dw6);
2671 [ # # ]: 0 : if (ret) {
2672 : 0 : DR_LOG(ERR, "Failed to allocate default NOP DW6 STC");
2673 : 0 : goto free_nop_dw5;
2674 : : }
2675 : :
2676 : 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW7;
2677 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
2678 : : &default_stc->nop_dw7);
2679 [ # # ]: 0 : if (ret) {
2680 : 0 : DR_LOG(ERR, "Failed to allocate default NOP DW7 STC");
2681 : 0 : goto free_nop_dw6;
2682 : : }
2683 : :
2684 [ # # ]: 0 : stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
2685 [ # # ]: 0 : if (!mlx5dr_context_shared_gvmi_used(ctx)) {
2686 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
2687 : : } else {
2688 : : /* On shared gvmi the default hit behavior is jump to alias end ft */
2689 : 0 : stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
2690 : 0 : stc_attr.dest_table_id = ctx->gvmi_res[tbl_type].aliased_end_ft->id;
2691 : : }
2692 : :
2693 : 0 : ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
2694 : : &default_stc->default_hit);
2695 [ # # ]: 0 : if (ret) {
2696 : 0 : DR_LOG(ERR, "Failed to allocate default allow STC");
2697 : 0 : goto free_nop_dw7;
2698 : : }
2699 : :
2700 : 0 : ctx->common_res[tbl_type].default_stc = default_stc;
2701 : 0 : ctx->common_res[tbl_type].default_stc->refcount++;
2702 : :
2703 : 0 : return 0;
2704 : :
2705 : : free_nop_dw7:
2706 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw7);
2707 : 0 : free_nop_dw6:
2708 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw6);
2709 : 0 : free_nop_dw5:
2710 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw5);
2711 : 0 : free_nop_ctr:
2712 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_ctr);
2713 : 0 : free_default_stc:
2714 : : simple_free(default_stc);
2715 : 0 : return rte_errno;
2716 : : }
2717 : :
2718 : 0 : void mlx5dr_action_put_default_stc(struct mlx5dr_context *ctx,
2719 : : uint8_t tbl_type)
2720 : : {
2721 : : struct mlx5dr_action_default_stc *default_stc;
2722 : :
2723 : 0 : default_stc = ctx->common_res[tbl_type].default_stc;
2724 : :
2725 : : default_stc = ctx->common_res[tbl_type].default_stc;
2726 [ # # ]: 0 : if (--default_stc->refcount)
2727 : : return;
2728 : :
2729 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->default_hit);
2730 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw7);
2731 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw6);
2732 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw5);
2733 : 0 : mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_ctr);
2734 : : simple_free(default_stc);
2735 : 0 : ctx->common_res[tbl_type].default_stc = NULL;
2736 : : }
2737 : :
2738 : : static void mlx5dr_action_modify_write(struct mlx5dr_send_engine *queue,
2739 : : uint32_t arg_idx,
2740 : : uint8_t *arg_data,
2741 : : uint16_t num_of_actions)
2742 : : {
2743 : 0 : mlx5dr_arg_write(queue, NULL, arg_idx, arg_data,
2744 : 0 : num_of_actions * MLX5DR_MODIFY_ACTION_SIZE);
2745 : 0 : }
2746 : :
2747 : : void
2748 : 0 : mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,
2749 : : uint16_t num_of_actions)
2750 : : {
2751 : : uint8_t *e_src;
2752 : : int i;
2753 : :
2754 : : /* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes
2755 : : * copy from end of src to the start of dst.
2756 : : * move to the end, 2 is the leftover from 14B or 18B
2757 : : */
2758 [ # # ]: 0 : if (num_of_actions == DECAP_L3_NUM_ACTIONS_W_NO_VLAN)
2759 : 0 : e_src = src + MLX5DR_ACTION_HDR_LEN_L2;
2760 : : else
2761 : 0 : e_src = src + MLX5DR_ACTION_HDR_LEN_L2_W_VLAN;
2762 : :
2763 : : /* Move dst over the first remove action + zero data */
2764 : : dst += MLX5DR_ACTION_DOUBLE_SIZE;
2765 : : /* Move dst over the first insert ctrl action */
2766 : 0 : dst += MLX5DR_ACTION_DOUBLE_SIZE / 2;
2767 : : /* Actions:
2768 : : * no vlan: r_h-insert_4b-insert_4b-insert_4b-insert_4b-remove_2b.
2769 : : * with vlan: r_h-insert_4b-insert_4b-insert_4b-insert_4b-insert_4b-remove_2b.
2770 : : * the loop is without the last insertion.
2771 : : */
2772 [ # # ]: 0 : for (i = 0; i < num_of_actions - 3; i++) {
2773 : 0 : e_src -= MLX5DR_ACTION_INLINE_DATA_SIZE;
2774 : : memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE); /* data */
2775 : 0 : dst += MLX5DR_ACTION_DOUBLE_SIZE;
2776 : : }
2777 : : /* Copy the last 2 bytes after a gap of 2 bytes which will be removed */
2778 : 0 : e_src -= MLX5DR_ACTION_INLINE_DATA_SIZE / 2;
2779 : 0 : dst += MLX5DR_ACTION_INLINE_DATA_SIZE / 2;
2780 : : memcpy(dst, e_src, 2);
2781 : 0 : }
2782 : :
2783 : : static int mlx5dr_action_get_shared_stc_offset(struct mlx5dr_context_common_res *common_res,
2784 : : enum mlx5dr_context_shared_stc_type stc_type)
2785 : : {
2786 : 0 : return common_res->shared_stc[stc_type]->remove_header.offset;
2787 : : }
2788 : :
2789 : : static struct mlx5dr_actions_wqe_setter *
2790 : : mlx5dr_action_setter_find_first(struct mlx5dr_actions_wqe_setter *setter,
2791 : : uint8_t req_flags)
2792 : : {
2793 : : /* Use a new setter if requested flags are taken */
2794 [ # # # # : 0 : while (setter->flags & req_flags)
# # # # #
# # # # #
# # # # #
# # # #
# ]
2795 : 0 : setter++;
2796 : :
2797 : : /* Use current setter in required flags are not used */
2798 : : return setter;
2799 : : }
2800 : :
2801 : : static void
2802 : : mlx5dr_action_apply_stc(struct mlx5dr_actions_apply_data *apply,
2803 : : enum mlx5dr_action_stc_idx stc_idx,
2804 : : uint8_t action_idx)
2805 : : {
2806 : 0 : struct mlx5dr_action *action = apply->rule_action[action_idx].action;
2807 : :
2808 : 0 : apply->wqe_ctrl->stc_ix[stc_idx] =
2809 : 0 : htobe32(action->stc[apply->tbl_type].offset);
2810 : : }
2811 : :
2812 : : static void
2813 : 0 : mlx5dr_action_setter_push_vlan(struct mlx5dr_actions_apply_data *apply,
2814 : : struct mlx5dr_actions_wqe_setter *setter)
2815 : : {
2816 : : struct mlx5dr_rule_action *rule_action;
2817 : :
2818 : 0 : rule_action = &apply->rule_action[setter->idx_double];
2819 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
2820 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = rule_action->push_vlan.vlan_hdr;
2821 : :
2822 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW6, setter->idx_double);
2823 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
2824 : 0 : }
2825 : :
2826 : : static void
2827 : 0 : mlx5dr_action_setter_modify_header(struct mlx5dr_actions_apply_data *apply,
2828 : : struct mlx5dr_actions_wqe_setter *setter)
2829 : : {
2830 : : struct mlx5dr_rule_action *rule_action;
2831 : : uint32_t stc_idx, arg_sz, arg_idx;
2832 : : struct mlx5dr_action *action;
2833 : : uint8_t *single_action;
2834 : :
2835 : 0 : rule_action = &apply->rule_action[setter->idx_double];
2836 : 0 : action = rule_action->action + rule_action->modify_header.pattern_idx;
2837 : :
2838 [ # # ]: 0 : stc_idx = htobe32(action->stc[apply->tbl_type].offset);
2839 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
2840 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
2841 : :
2842 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
2843 : :
2844 [ # # ]: 0 : if (action->modify_header.num_of_actions == 1) {
2845 : 0 : if (action->modify_header.single_action_type ==
2846 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_COPY ||
2847 : : action->modify_header.single_action_type ==
2848 : : MLX5_MODIFICATION_TYPE_ADD_FIELD) {
2849 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = 0;
2850 : 0 : return;
2851 : : }
2852 : :
2853 [ # # ]: 0 : if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
2854 : 0 : single_action = (uint8_t *)&action->modify_header.single_action;
2855 : : else
2856 : 0 : single_action = rule_action->modify_header.data;
2857 : :
2858 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] =
2859 : : *(__be32 *)MLX5_ADDR_OF(set_action_in, single_action, data);
2860 : : } else {
2861 : : /* Argument offset multiple with number of args per these actions */
2862 : 0 : arg_sz = mlx5dr_arg_get_arg_size(action->modify_header.max_num_of_actions);
2863 : 0 : arg_idx = rule_action->modify_header.offset * arg_sz;
2864 : :
2865 [ # # ]: 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
2866 : :
2867 [ # # ]: 0 : if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
2868 : 0 : apply->require_dep = 1;
2869 : 0 : mlx5dr_action_modify_write(apply->queue,
2870 : 0 : action->modify_header.arg_obj->id + arg_idx,
2871 : : rule_action->modify_header.data,
2872 : 0 : action->modify_header.num_of_actions);
2873 : : }
2874 : : }
2875 : : }
2876 : :
2877 : : static void
2878 : 0 : mlx5dr_action_setter_insert_ptr(struct mlx5dr_actions_apply_data *apply,
2879 : : struct mlx5dr_actions_wqe_setter *setter)
2880 : : {
2881 : : struct mlx5dr_rule_action *rule_action;
2882 : : uint32_t stc_idx, arg_idx, arg_sz;
2883 : : struct mlx5dr_action *action;
2884 : :
2885 : 0 : rule_action = &apply->rule_action[setter->idx_double];
2886 : 0 : action = rule_action->action + rule_action->reformat.hdr_idx;
2887 : :
2888 : : /* Argument offset multiple on args required for header size */
2889 : 0 : arg_sz = mlx5dr_arg_data_size_to_arg_size(action->reformat.max_hdr_sz);
2890 : 0 : arg_idx = rule_action->reformat.offset * arg_sz;
2891 : :
2892 [ # # ]: 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
2893 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
2894 : :
2895 : 0 : stc_idx = htobe32(action->stc[apply->tbl_type].offset);
2896 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
2897 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
2898 : :
2899 [ # # ]: 0 : if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
2900 : 0 : apply->require_dep = 1;
2901 : 0 : mlx5dr_arg_write(apply->queue, NULL,
2902 : 0 : action->reformat.arg_obj->id + arg_idx,
2903 : : rule_action->reformat.data,
2904 : 0 : action->reformat.header_size);
2905 : : }
2906 : 0 : }
2907 : :
2908 : : static void
2909 : 0 : mlx5dr_action_setter_tnl_l3_to_l2(struct mlx5dr_actions_apply_data *apply,
2910 : : struct mlx5dr_actions_wqe_setter *setter)
2911 : : {
2912 : : struct mlx5dr_rule_action *rule_action;
2913 : : uint32_t stc_idx, arg_sz, arg_idx;
2914 : : struct mlx5dr_action *action;
2915 : :
2916 : 0 : rule_action = &apply->rule_action[setter->idx_double];
2917 : 0 : action = rule_action->action + rule_action->reformat.hdr_idx;
2918 : :
2919 : : /* Argument offset multiple on args required for num of actions */
2920 : 0 : arg_sz = mlx5dr_arg_get_arg_size(action->modify_header.max_num_of_actions);
2921 : 0 : arg_idx = rule_action->reformat.offset * arg_sz;
2922 : :
2923 [ # # ]: 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
2924 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
2925 : :
2926 : 0 : stc_idx = htobe32(action->stc[apply->tbl_type].offset);
2927 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
2928 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
2929 : :
2930 [ # # ]: 0 : if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
2931 : 0 : apply->require_dep = 1;
2932 : 0 : mlx5dr_arg_decapl3_write(apply->queue,
2933 : 0 : action->modify_header.arg_obj->id + arg_idx,
2934 : : rule_action->reformat.data,
2935 : 0 : action->modify_header.num_of_actions);
2936 : : }
2937 : 0 : }
2938 : :
2939 : : static void
2940 : 0 : mlx5dr_action_setter_aso(struct mlx5dr_actions_apply_data *apply,
2941 : : struct mlx5dr_actions_wqe_setter *setter)
2942 : : {
2943 : : struct mlx5dr_rule_action *rule_action;
2944 : : uint32_t exe_aso_ctrl;
2945 : : uint32_t offset;
2946 : :
2947 : 0 : rule_action = &apply->rule_action[setter->idx_double];
2948 : :
2949 [ # # # ]: 0 : switch (rule_action->action->type) {
2950 : 0 : case MLX5DR_ACTION_TYP_ASO_METER:
2951 : : /* exe_aso_ctrl format:
2952 : : * [STC only and reserved bits 29b][init_color 2b][meter_id 1b]
2953 : : */
2954 : 0 : offset = rule_action->aso_meter.offset / MLX5_ASO_METER_NUM_PER_OBJ;
2955 : 0 : exe_aso_ctrl = rule_action->aso_meter.offset % MLX5_ASO_METER_NUM_PER_OBJ;
2956 : 0 : exe_aso_ctrl |= rule_action->aso_meter.init_color <<
2957 : : MLX5DR_ACTION_METER_INIT_COLOR_OFFSET;
2958 : 0 : break;
2959 : 0 : case MLX5DR_ACTION_TYP_ASO_CT:
2960 : : /* exe_aso_ctrl CT format:
2961 : : * [STC only and reserved bits 31b][direction 1b]
2962 : : */
2963 : 0 : offset = rule_action->aso_ct.offset / MLX5_ASO_CT_NUM_PER_OBJ;
2964 : 0 : exe_aso_ctrl = rule_action->aso_ct.direction;
2965 : 0 : break;
2966 : 0 : default:
2967 : 0 : DR_LOG(ERR, "Unsupported ASO action type: %d", rule_action->action->type);
2968 : 0 : rte_errno = ENOTSUP;
2969 : 0 : return;
2970 : : }
2971 : :
2972 : : /* aso_object_offset format: [24B] */
2973 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = htobe32(offset);
2974 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(exe_aso_ctrl);
2975 : :
2976 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW6, setter->idx_double);
2977 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
2978 : : }
2979 : :
2980 : : static void
2981 : 0 : mlx5dr_action_setter_tag(struct mlx5dr_actions_apply_data *apply,
2982 : : struct mlx5dr_actions_wqe_setter *setter)
2983 : : {
2984 : : struct mlx5dr_rule_action *rule_action;
2985 : :
2986 : 0 : rule_action = &apply->rule_action[setter->idx_single];
2987 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = htobe32(rule_action->tag.value);
2988 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW5, setter->idx_single);
2989 : 0 : }
2990 : :
2991 : : static void
2992 : 0 : mlx5dr_action_setter_ctrl_ctr(struct mlx5dr_actions_apply_data *apply,
2993 : : struct mlx5dr_actions_wqe_setter *setter)
2994 : : {
2995 : : struct mlx5dr_rule_action *rule_action;
2996 : :
2997 : 0 : rule_action = &apply->rule_action[setter->idx_ctr];
2998 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW0] = htobe32(rule_action->counter.offset);
2999 : : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_CTRL, setter->idx_ctr);
3000 : 0 : }
3001 : :
3002 : : static void
3003 : 0 : mlx5dr_action_setter_single(struct mlx5dr_actions_apply_data *apply,
3004 : : struct mlx5dr_actions_wqe_setter *setter)
3005 : : {
3006 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
3007 : 0 : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW5, setter->idx_single);
3008 : 0 : }
3009 : :
3010 : : static void
3011 : 0 : mlx5dr_action_setter_single_double_pop(struct mlx5dr_actions_apply_data *apply,
3012 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3013 : : {
3014 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
3015 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
3016 : 0 : htobe32(mlx5dr_action_get_shared_stc_offset(apply->common_res,
3017 : : MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP));
3018 : 0 : }
3019 : :
3020 : : static void
3021 : 0 : mlx5dr_action_setter_hit(struct mlx5dr_actions_apply_data *apply,
3022 : : struct mlx5dr_actions_wqe_setter *setter)
3023 : : {
3024 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = 0;
3025 : 0 : mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_HIT, setter->idx_hit);
3026 : 0 : }
3027 : :
3028 : : static void
3029 : 0 : mlx5dr_action_setter_default_hit(struct mlx5dr_actions_apply_data *apply,
3030 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3031 : : {
3032 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = 0;
3033 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_HIT] =
3034 : 0 : htobe32(apply->common_res->default_stc->default_hit.offset);
3035 : 0 : }
3036 : :
3037 : : static void
3038 : 0 : mlx5dr_action_setter_hit_next_action(struct mlx5dr_actions_apply_data *apply,
3039 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3040 : : {
3041 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = htobe32(apply->next_direct_idx << 6);
3042 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_HIT] = htobe32(apply->jump_to_action_stc);
3043 : 0 : }
3044 : :
3045 : : static void
3046 : 0 : mlx5dr_action_setter_common_decap(struct mlx5dr_actions_apply_data *apply,
3047 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
3048 : : {
3049 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
3050 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
3051 : 0 : htobe32(mlx5dr_action_get_shared_stc_offset(apply->common_res,
3052 : : MLX5DR_CONTEXT_SHARED_STC_DECAP_L3));
3053 : 0 : }
3054 : :
3055 : : static void
3056 : 0 : mlx5dr_action_setter_ipv6_route_ext_gen_push_mhdr(uint8_t *data, void *mh_data)
3057 : : {
3058 : : uint8_t *action_ptr = mh_data;
3059 : : uint32_t *ipv6_dst_addr;
3060 : : uint8_t seg_left;
3061 : : uint32_t i;
3062 : :
3063 : : /* Fetch the last IPv6 address in the segment list which is the next hop */
3064 [ # # ]: 0 : seg_left = MLX5_GET(header_ipv6_routing_ext, data, segments_left) - 1;
3065 : 0 : ipv6_dst_addr = (uint32_t *)data + MLX5_ST_SZ_DW(header_ipv6_routing_ext)
3066 : 0 : + seg_left * MLX5_ST_SZ_DW(definer_hl_ipv6_addr);
3067 : :
3068 : : /* Load next hop IPv6 address in reverse order to ipv6.dst_address */
3069 [ # # ]: 0 : for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
3070 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, data, be32toh(*ipv6_dst_addr++));
3071 : 0 : action_ptr += MLX5DR_MODIFY_ACTION_SIZE;
3072 : : }
3073 : :
3074 : : /* Set ipv6_route_ext.next_hdr per user input */
3075 [ # # ]: 0 : MLX5_SET(set_action_in, action_ptr, data, *data);
3076 : 0 : }
3077 : :
3078 : : static void
3079 : 0 : mlx5dr_action_setter_ipv6_route_ext_mhdr(struct mlx5dr_actions_apply_data *apply,
3080 : : struct mlx5dr_actions_wqe_setter *setter)
3081 : : {
3082 : 0 : struct mlx5dr_rule_action *rule_action = apply->rule_action;
3083 : 0 : struct mlx5dr_actions_wqe_setter tmp_setter = {0};
3084 : : struct mlx5dr_rule_action tmp_rule_action;
3085 : 0 : __be64 cmd[MLX5_SRV6_SAMPLE_NUM] = {0};
3086 : : struct mlx5dr_action *ipv6_ext_action;
3087 : : uint8_t *header;
3088 : :
3089 : 0 : header = rule_action[setter->idx_double].ipv6_ext.header;
3090 : 0 : ipv6_ext_action = rule_action[setter->idx_double].action;
3091 : 0 : tmp_rule_action.action = ipv6_ext_action->ipv6_route_ext.action[setter->extra_data];
3092 : :
3093 [ # # ]: 0 : if (tmp_rule_action.action->flags & MLX5DR_ACTION_FLAG_SHARED) {
3094 : 0 : tmp_rule_action.modify_header.offset = 0;
3095 : 0 : tmp_rule_action.modify_header.pattern_idx = 0;
3096 : 0 : tmp_rule_action.modify_header.data = NULL;
3097 : : } else {
3098 : : /*
3099 : : * Copy ipv6_dst from ipv6_route_ext.last_seg.
3100 : : * Set ipv6_route_ext.next_hdr.
3101 : : */
3102 : 0 : mlx5dr_action_setter_ipv6_route_ext_gen_push_mhdr(header, cmd);
3103 : 0 : tmp_rule_action.modify_header.data = (uint8_t *)cmd;
3104 : 0 : tmp_rule_action.modify_header.pattern_idx = 0;
3105 : 0 : tmp_rule_action.modify_header.offset =
3106 : 0 : rule_action[setter->idx_double].ipv6_ext.offset;
3107 : : }
3108 : :
3109 : 0 : apply->rule_action = &tmp_rule_action;
3110 : :
3111 : : /* Reuse regular */
3112 : 0 : mlx5dr_action_setter_modify_header(apply, &tmp_setter);
3113 : :
3114 : : /* Swap rule actions from backup */
3115 : 0 : apply->rule_action = rule_action;
3116 : 0 : }
3117 : :
3118 : : static void
3119 : 0 : mlx5dr_action_setter_ipv6_route_ext_insert_ptr(struct mlx5dr_actions_apply_data *apply,
3120 : : struct mlx5dr_actions_wqe_setter *setter)
3121 : : {
3122 : 0 : struct mlx5dr_rule_action *rule_action = apply->rule_action;
3123 : 0 : struct mlx5dr_actions_wqe_setter tmp_setter = {0};
3124 : : struct mlx5dr_rule_action tmp_rule_action;
3125 : : struct mlx5dr_action *ipv6_ext_action;
3126 : : uint8_t header[MLX5_PUSH_MAX_LEN];
3127 : :
3128 : 0 : ipv6_ext_action = rule_action[setter->idx_double].action;
3129 : 0 : tmp_rule_action.action = ipv6_ext_action->ipv6_route_ext.action[setter->extra_data];
3130 : :
3131 [ # # ]: 0 : if (tmp_rule_action.action->flags & MLX5DR_ACTION_FLAG_SHARED) {
3132 : 0 : tmp_rule_action.reformat.offset = 0;
3133 : 0 : tmp_rule_action.reformat.hdr_idx = 0;
3134 : 0 : tmp_rule_action.reformat.data = NULL;
3135 : : } else {
3136 : 0 : memcpy(header, rule_action[setter->idx_double].ipv6_ext.header,
3137 [ # # ]: 0 : tmp_rule_action.action->reformat.header_size);
3138 : : /* Clear ipv6_route_ext.next_hdr for right checksum */
3139 [ # # ]: 0 : MLX5_SET(header_ipv6_routing_ext, header, next_hdr, 0);
3140 : 0 : tmp_rule_action.reformat.data = header;
3141 : 0 : tmp_rule_action.reformat.hdr_idx = 0;
3142 : 0 : tmp_rule_action.reformat.offset =
3143 : 0 : rule_action[setter->idx_double].ipv6_ext.offset;
3144 : : }
3145 : :
3146 : 0 : apply->rule_action = &tmp_rule_action;
3147 : :
3148 : : /* Reuse regular */
3149 : 0 : mlx5dr_action_setter_insert_ptr(apply, &tmp_setter);
3150 : :
3151 : : /* Swap rule actions from backup */
3152 : 0 : apply->rule_action = rule_action;
3153 : 0 : }
3154 : :
3155 : : static void
3156 : 0 : mlx5dr_action_setter_ipv6_route_ext_pop(struct mlx5dr_actions_apply_data *apply,
3157 : : struct mlx5dr_actions_wqe_setter *setter)
3158 : : {
3159 : 0 : struct mlx5dr_rule_action *rule_action = &apply->rule_action[setter->idx_single];
3160 : : uint8_t idx = MLX5DR_ACTION_IPV6_EXT_MAX_SA - 1;
3161 : : struct mlx5dr_action *action;
3162 : :
3163 : : /* Pop the ipv6_route_ext as set_single logic */
3164 : 0 : action = rule_action->action->ipv6_route_ext.action[idx];
3165 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
3166 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
3167 : 0 : htobe32(action->stc[apply->tbl_type].offset);
3168 : 0 : }
3169 : :
3170 : 0 : int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
3171 : : {
3172 : 0 : struct mlx5dr_actions_wqe_setter *start_setter = at->setters + 1;
3173 : 0 : enum mlx5dr_action_type *action_type = at->action_type_arr;
3174 : 0 : struct mlx5dr_actions_wqe_setter *setter = at->setters;
3175 : : struct mlx5dr_actions_wqe_setter *pop_setter = NULL;
3176 : : struct mlx5dr_actions_wqe_setter *last_setter;
3177 : : int i;
3178 : :
3179 : : /* Note: Given action combination must be valid */
3180 : :
3181 : : /* Check if action were already processed */
3182 [ # # ]: 0 : if (at->num_of_action_stes)
3183 : : return 0;
3184 : :
3185 [ # # ]: 0 : for (i = 0; i < MLX5DR_ACTION_MAX_STE; i++)
3186 : 0 : setter[i].set_hit = &mlx5dr_action_setter_hit_next_action;
3187 : :
3188 : : /* The same action template setters can be used with jumbo or match
3189 : : * STE, to support both cases we reseve the first setter for cases
3190 : : * with jumbo STE to allow jump to the first action STE.
3191 : : * This extra setter can be reduced in some cases on rule creation.
3192 : : */
3193 : : setter = start_setter;
3194 : : last_setter = start_setter;
3195 : :
3196 [ # # ]: 0 : for (i = 0; i < at->num_actions; i++) {
3197 [ # # # # : 0 : switch (action_type[i]) {
# # # # #
# # # #
# ]
3198 : 0 : case MLX5DR_ACTION_TYP_DROP:
3199 : : case MLX5DR_ACTION_TYP_TIR:
3200 : : case MLX5DR_ACTION_TYP_TBL:
3201 : : case MLX5DR_ACTION_TYP_DEST_ROOT:
3202 : : case MLX5DR_ACTION_TYP_DEST_ARRAY:
3203 : : case MLX5DR_ACTION_TYP_VPORT:
3204 : : case MLX5DR_ACTION_TYP_MISS:
3205 : : /* Hit action */
3206 : 0 : last_setter->flags |= ASF_HIT;
3207 : 0 : last_setter->set_hit = &mlx5dr_action_setter_hit;
3208 : 0 : last_setter->idx_hit = i;
3209 : 0 : break;
3210 : :
3211 : 0 : case MLX5DR_ACTION_TYP_POP_VLAN:
3212 : : /* Single remove header to header */
3213 [ # # ]: 0 : if (pop_setter) {
3214 : : /* We have 2 pops, use the shared */
3215 : 0 : pop_setter->set_single = &mlx5dr_action_setter_single_double_pop;
3216 : 0 : break;
3217 : : }
3218 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_SINGLE1 | ASF_MODIFY | ASF_INSERT);
3219 : 0 : setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
3220 : 0 : setter->set_single = &mlx5dr_action_setter_single;
3221 : 0 : setter->idx_single = i;
3222 : : pop_setter = setter;
3223 : 0 : break;
3224 : :
3225 : : case MLX5DR_ACTION_TYP_PUSH_VLAN:
3226 : : /* Double insert inline */
3227 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
3228 : 0 : setter->flags |= ASF_DOUBLE | ASF_INSERT;
3229 : 0 : setter->set_double = &mlx5dr_action_setter_push_vlan;
3230 : 0 : setter->idx_double = i;
3231 : 0 : break;
3232 : :
3233 : : case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
3234 : : /*
3235 : : * Backup ipv6_route_ext.next_hdr to ipv6_route_ext.seg_left.
3236 : : * Set ipv6_route_ext.next_hdr to 0 for checksum bug.
3237 : : */
3238 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
3239 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
3240 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
3241 : 0 : setter->idx_double = i;
3242 : 0 : setter->extra_data = 0;
3243 : : setter++;
3244 : :
3245 : : /*
3246 : : * Restore ipv6_route_ext.next_hdr from ipv6_route_ext.seg_left.
3247 : : * Load the final destination address from flex parser sample 1->4.
3248 : : */
3249 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
3250 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
3251 : 0 : setter->idx_double = i;
3252 : 0 : setter->extra_data = 1;
3253 : 0 : setter++;
3254 : :
3255 : : /* Set the ipv6.protocol per ipv6_route_ext.next_hdr */
3256 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
3257 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
3258 : 0 : setter->idx_double = i;
3259 : 0 : setter->extra_data = 2;
3260 : : /* Pop ipv6_route_ext */
3261 : 0 : setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
3262 : 0 : setter->set_single = &mlx5dr_action_setter_ipv6_route_ext_pop;
3263 : 0 : setter->idx_single = i;
3264 : 0 : break;
3265 : :
3266 : : case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
3267 : : /* Insert ipv6_route_ext with next_hdr as 0 due to checksum bug */
3268 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
3269 : 0 : setter->flags |= ASF_DOUBLE | ASF_INSERT;
3270 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_insert_ptr;
3271 : 0 : setter->idx_double = i;
3272 : 0 : setter->extra_data = 0;
3273 : : setter++;
3274 : :
3275 : : /* Set ipv6.protocol as IPPROTO_ROUTING: 0x2b */
3276 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
3277 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
3278 : 0 : setter->idx_double = i;
3279 : 0 : setter->extra_data = 1;
3280 : 0 : setter++;
3281 : :
3282 : : /*
3283 : : * Load the right ipv6_route_ext.next_hdr per user input buffer.
3284 : : * Load the next dest_addr from the ipv6_route_ext.seg_list[last].
3285 : : */
3286 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
3287 : 0 : setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
3288 : 0 : setter->idx_double = i;
3289 : 0 : setter->extra_data = 2;
3290 : 0 : break;
3291 : :
3292 : : case MLX5DR_ACTION_TYP_MODIFY_HDR:
3293 : : /* Double modify header list */
3294 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
3295 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY;
3296 : 0 : setter->set_double = &mlx5dr_action_setter_modify_header;
3297 : 0 : setter->idx_double = i;
3298 : 0 : break;
3299 : :
3300 : : case MLX5DR_ACTION_TYP_ASO_METER:
3301 : : case MLX5DR_ACTION_TYP_ASO_CT:
3302 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE);
3303 : 0 : setter->flags |= ASF_DOUBLE;
3304 : 0 : setter->set_double = &mlx5dr_action_setter_aso;
3305 : 0 : setter->idx_double = i;
3306 : 0 : break;
3307 : :
3308 : : case MLX5DR_ACTION_TYP_REMOVE_HEADER:
3309 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
3310 : : /* Single remove header to header */
3311 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_SINGLE1 | ASF_MODIFY);
3312 : 0 : setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
3313 : 0 : setter->set_single = &mlx5dr_action_setter_single;
3314 : 0 : setter->idx_single = i;
3315 : 0 : break;
3316 : :
3317 : : case MLX5DR_ACTION_TYP_INSERT_HEADER:
3318 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
3319 : : /* Double insert header with pointer */
3320 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
3321 : 0 : setter->flags |= ASF_DOUBLE | ASF_INSERT;
3322 : 0 : setter->set_double = &mlx5dr_action_setter_insert_ptr;
3323 : 0 : setter->idx_double = i;
3324 : 0 : break;
3325 : :
3326 : : case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
3327 : : /* Single remove + Double insert header with pointer */
3328 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_SINGLE1 | ASF_DOUBLE);
3329 : 0 : setter->flags |= ASF_SINGLE1 | ASF_DOUBLE;
3330 : 0 : setter->set_double = &mlx5dr_action_setter_insert_ptr;
3331 : 0 : setter->idx_double = i;
3332 : 0 : setter->set_single = &mlx5dr_action_setter_common_decap;
3333 : 0 : setter->idx_single = i;
3334 : 0 : break;
3335 : :
3336 : : case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
3337 : : /* Double modify header list with remove and push inline */
3338 : : setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
3339 : 0 : setter->flags |= ASF_DOUBLE | ASF_MODIFY | ASF_INSERT;
3340 : 0 : setter->set_double = &mlx5dr_action_setter_tnl_l3_to_l2;
3341 : 0 : setter->idx_double = i;
3342 : 0 : break;
3343 : :
3344 : : case MLX5DR_ACTION_TYP_TAG:
3345 : : /* Single TAG action, search for any room from the start */
3346 : : setter = mlx5dr_action_setter_find_first(start_setter, ASF_SINGLE1);
3347 : 0 : setter->flags |= ASF_SINGLE1;
3348 : 0 : setter->set_single = &mlx5dr_action_setter_tag;
3349 : 0 : setter->idx_single = i;
3350 : 0 : break;
3351 : :
3352 : : case MLX5DR_ACTION_TYP_CTR:
3353 : : /* Control counter action
3354 : : * TODO: Current counter executed first. Support is needed
3355 : : * for single ation counter action which is done last.
3356 : : * Example: Decap + CTR
3357 : : */
3358 : : setter = mlx5dr_action_setter_find_first(start_setter, ASF_CTR);
3359 : 0 : setter->flags |= ASF_CTR;
3360 : 0 : setter->set_ctr = &mlx5dr_action_setter_ctrl_ctr;
3361 : 0 : setter->idx_ctr = i;
3362 : 0 : break;
3363 : :
3364 : 0 : default:
3365 : 0 : DR_LOG(ERR, "Unsupported action type: %d", action_type[i]);
3366 : 0 : rte_errno = ENOTSUP;
3367 : 0 : assert(false);
3368 : : return rte_errno;
3369 : : }
3370 : :
3371 : 0 : last_setter = RTE_MAX(setter, last_setter);
3372 : : }
3373 : :
3374 : : /* Set default hit on the last STE if no hit action provided */
3375 [ # # ]: 0 : if (!(last_setter->flags & ASF_HIT))
3376 : 0 : last_setter->set_hit = &mlx5dr_action_setter_default_hit;
3377 : :
3378 : 0 : at->num_of_action_stes = last_setter - start_setter + 1;
3379 : :
3380 : : /* Check if action template doesn't require any action DWs */
3381 [ # # ]: 0 : at->only_term = (at->num_of_action_stes == 1) &&
3382 [ # # ]: 0 : !(last_setter->flags & ~(ASF_CTR | ASF_HIT));
3383 : :
3384 : 0 : return 0;
3385 : : }
3386 : :
3387 : : struct mlx5dr_action_template *
3388 : 0 : mlx5dr_action_template_create(const enum mlx5dr_action_type action_type[])
3389 : : {
3390 : : struct mlx5dr_action_template *at;
3391 : : uint8_t num_actions = 0;
3392 : : int i;
3393 : :
3394 : : at = simple_calloc(1, sizeof(*at));
3395 [ # # ]: 0 : if (!at) {
3396 : 0 : DR_LOG(ERR, "Failed to allocate action template");
3397 : 0 : rte_errno = ENOMEM;
3398 : 0 : return NULL;
3399 : : }
3400 : :
3401 [ # # ]: 0 : while (action_type[num_actions++] != MLX5DR_ACTION_TYP_LAST)
3402 : : ;
3403 : :
3404 : 0 : at->num_actions = num_actions - 1;
3405 : 0 : at->action_type_arr = simple_calloc(num_actions, sizeof(*action_type));
3406 [ # # ]: 0 : if (!at->action_type_arr) {
3407 : 0 : DR_LOG(ERR, "Failed to allocate action type array");
3408 : 0 : rte_errno = ENOMEM;
3409 : 0 : goto free_at;
3410 : : }
3411 : :
3412 [ # # ]: 0 : for (i = 0; i < num_actions; i++)
3413 : 0 : at->action_type_arr[i] = action_type[i];
3414 : :
3415 : : return at;
3416 : :
3417 : : free_at:
3418 : : simple_free(at);
3419 : 0 : return NULL;
3420 : : }
3421 : :
3422 : 0 : int mlx5dr_action_template_destroy(struct mlx5dr_action_template *at)
3423 : : {
3424 : 0 : simple_free(at->action_type_arr);
3425 : : simple_free(at);
3426 : 0 : return 0;
3427 : : }
|