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