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