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