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