1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2019 Mellanox Technologies. */
7 enum dr_action_domain {
8 DR_ACTION_DOMAIN_NIC_INGRESS,
9 DR_ACTION_DOMAIN_NIC_EGRESS,
10 DR_ACTION_DOMAIN_FDB_INGRESS,
11 DR_ACTION_DOMAIN_FDB_EGRESS,
15 enum dr_action_valid_state {
17 DR_ACTION_STATE_NO_ACTION,
18 DR_ACTION_STATE_ENCAP,
19 DR_ACTION_STATE_DECAP,
20 DR_ACTION_STATE_MODIFY_HDR,
21 DR_ACTION_STATE_POP_VLAN,
22 DR_ACTION_STATE_PUSH_VLAN,
23 DR_ACTION_STATE_NON_TERM,
29 static const char * const action_type_to_str[] = {
30 [DR_ACTION_TYP_TNL_L2_TO_L2] = "DR_ACTION_TYP_TNL_L2_TO_L2",
31 [DR_ACTION_TYP_L2_TO_TNL_L2] = "DR_ACTION_TYP_L2_TO_TNL_L2",
32 [DR_ACTION_TYP_TNL_L3_TO_L2] = "DR_ACTION_TYP_TNL_L3_TO_L2",
33 [DR_ACTION_TYP_L2_TO_TNL_L3] = "DR_ACTION_TYP_L2_TO_TNL_L3",
34 [DR_ACTION_TYP_DROP] = "DR_ACTION_TYP_DROP",
35 [DR_ACTION_TYP_QP] = "DR_ACTION_TYP_QP",
36 [DR_ACTION_TYP_FT] = "DR_ACTION_TYP_FT",
37 [DR_ACTION_TYP_CTR] = "DR_ACTION_TYP_CTR",
38 [DR_ACTION_TYP_TAG] = "DR_ACTION_TYP_TAG",
39 [DR_ACTION_TYP_MODIFY_HDR] = "DR_ACTION_TYP_MODIFY_HDR",
40 [DR_ACTION_TYP_VPORT] = "DR_ACTION_TYP_VPORT",
41 [DR_ACTION_TYP_POP_VLAN] = "DR_ACTION_TYP_POP_VLAN",
42 [DR_ACTION_TYP_PUSH_VLAN] = "DR_ACTION_TYP_PUSH_VLAN",
43 [DR_ACTION_TYP_SAMPLER] = "DR_ACTION_TYP_SAMPLER",
44 [DR_ACTION_TYP_INSERT_HDR] = "DR_ACTION_TYP_INSERT_HDR",
45 [DR_ACTION_TYP_REMOVE_HDR] = "DR_ACTION_TYP_REMOVE_HDR",
46 [DR_ACTION_TYP_ASO_FLOW_METER] = "DR_ACTION_TYP_ASO_FLOW_METER",
47 [DR_ACTION_TYP_RANGE] = "DR_ACTION_TYP_RANGE",
48 [DR_ACTION_TYP_MAX] = "DR_ACTION_UNKNOWN",
51 static const char *dr_action_id_to_str(enum mlx5dr_action_type action_id)
53 if (action_id > DR_ACTION_TYP_MAX)
54 action_id = DR_ACTION_TYP_MAX;
55 return action_type_to_str[action_id];
58 static bool mlx5dr_action_supp_fwd_fdb_multi_ft(struct mlx5_core_dev *dev)
60 return (MLX5_CAP_GEN(dev, steering_format_version) < MLX5_STEERING_FORMAT_CONNECTX_6DX ||
61 MLX5_CAP_ESW_FLOWTABLE(dev, fdb_multi_path_any_table_limit_regc) ||
62 MLX5_CAP_ESW_FLOWTABLE(dev, fdb_multi_path_any_table));
65 static const enum dr_action_valid_state
66 next_action_state[DR_ACTION_DOMAIN_MAX][DR_ACTION_STATE_MAX][DR_ACTION_TYP_MAX] = {
67 [DR_ACTION_DOMAIN_NIC_INGRESS] = {
68 [DR_ACTION_STATE_NO_ACTION] = {
69 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
70 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
71 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
72 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
73 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
74 [DR_ACTION_TYP_TAG] = DR_ACTION_STATE_NON_TERM,
75 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
76 [DR_ACTION_TYP_TNL_L2_TO_L2] = DR_ACTION_STATE_DECAP,
77 [DR_ACTION_TYP_TNL_L3_TO_L2] = DR_ACTION_STATE_DECAP,
78 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
79 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
80 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
81 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
82 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
83 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
84 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
85 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
87 [DR_ACTION_STATE_DECAP] = {
88 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
89 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
90 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
91 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
92 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
93 [DR_ACTION_TYP_TAG] = DR_ACTION_STATE_DECAP,
94 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_DECAP,
95 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
96 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
97 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
98 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
99 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
100 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
101 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
103 [DR_ACTION_STATE_ENCAP] = {
104 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
105 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
106 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
107 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
108 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
109 [DR_ACTION_TYP_TAG] = DR_ACTION_STATE_ENCAP,
110 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ENCAP,
111 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
113 [DR_ACTION_STATE_MODIFY_HDR] = {
114 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
115 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
116 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
117 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
118 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
119 [DR_ACTION_TYP_TAG] = DR_ACTION_STATE_MODIFY_HDR,
120 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_MODIFY_HDR,
121 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
122 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
123 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
124 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
125 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
127 [DR_ACTION_STATE_POP_VLAN] = {
128 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
129 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
130 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
131 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
132 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
133 [DR_ACTION_TYP_TAG] = DR_ACTION_STATE_POP_VLAN,
134 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_POP_VLAN,
135 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
136 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
137 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
138 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
139 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
140 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
142 [DR_ACTION_STATE_PUSH_VLAN] = {
143 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
144 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
145 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
146 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
147 [DR_ACTION_TYP_TAG] = DR_ACTION_STATE_PUSH_VLAN,
148 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_PUSH_VLAN,
149 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
150 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
151 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
152 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
154 [DR_ACTION_STATE_NON_TERM] = {
155 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
156 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
157 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
158 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
159 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
160 [DR_ACTION_TYP_TAG] = DR_ACTION_STATE_NON_TERM,
161 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
162 [DR_ACTION_TYP_TNL_L2_TO_L2] = DR_ACTION_STATE_DECAP,
163 [DR_ACTION_TYP_TNL_L3_TO_L2] = DR_ACTION_STATE_DECAP,
164 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
165 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
166 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
167 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
168 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
169 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
170 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
171 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
173 [DR_ACTION_STATE_ASO] = {
174 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
175 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
176 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
177 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
178 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ASO,
180 [DR_ACTION_STATE_TERM] = {
181 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_TERM,
184 [DR_ACTION_DOMAIN_NIC_EGRESS] = {
185 [DR_ACTION_STATE_NO_ACTION] = {
186 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
187 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
188 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
189 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
190 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
191 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
192 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
193 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
194 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
195 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
196 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
197 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
198 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
200 [DR_ACTION_STATE_DECAP] = {
201 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
202 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
203 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
204 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
205 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_DECAP,
206 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
208 [DR_ACTION_STATE_ENCAP] = {
209 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
210 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
211 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
212 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
213 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ENCAP,
214 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
216 [DR_ACTION_STATE_MODIFY_HDR] = {
217 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
218 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
219 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
220 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
221 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_MODIFY_HDR,
222 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
223 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
224 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
225 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
226 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
228 [DR_ACTION_STATE_POP_VLAN] = {
229 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
230 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
231 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
232 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_POP_VLAN,
233 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
234 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
235 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
236 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
237 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
238 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
239 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
241 [DR_ACTION_STATE_PUSH_VLAN] = {
242 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
243 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
244 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
245 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
246 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_PUSH_VLAN,
247 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
248 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
249 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
250 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
251 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
253 [DR_ACTION_STATE_NON_TERM] = {
254 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
255 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
256 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
257 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
258 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
259 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
260 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
261 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
262 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
263 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
264 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
265 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
266 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
268 [DR_ACTION_STATE_ASO] = {
269 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
270 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
271 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
272 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
273 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ASO,
274 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
275 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
276 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
278 [DR_ACTION_STATE_TERM] = {
279 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_TERM,
282 [DR_ACTION_DOMAIN_FDB_INGRESS] = {
283 [DR_ACTION_STATE_NO_ACTION] = {
284 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
285 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
286 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
287 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
288 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
289 [DR_ACTION_TYP_TNL_L2_TO_L2] = DR_ACTION_STATE_DECAP,
290 [DR_ACTION_TYP_TNL_L3_TO_L2] = DR_ACTION_STATE_DECAP,
291 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
292 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
293 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
294 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
295 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
296 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
297 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
298 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
299 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
301 [DR_ACTION_STATE_DECAP] = {
302 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
303 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
304 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
305 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_DECAP,
306 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
307 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
308 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
309 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
310 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
311 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
312 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
313 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
314 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
316 [DR_ACTION_STATE_ENCAP] = {
317 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
318 [DR_ACTION_TYP_QP] = DR_ACTION_STATE_TERM,
319 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
320 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
321 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
322 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
323 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ENCAP,
324 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
326 [DR_ACTION_STATE_MODIFY_HDR] = {
327 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
328 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
329 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
330 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
331 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_MODIFY_HDR,
332 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
333 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
334 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
335 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
336 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
337 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
339 [DR_ACTION_STATE_POP_VLAN] = {
340 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
341 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
342 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
343 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
344 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
345 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_POP_VLAN,
346 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
347 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
348 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
349 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
350 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
351 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
353 [DR_ACTION_STATE_PUSH_VLAN] = {
354 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
355 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
356 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
357 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
358 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
359 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_PUSH_VLAN,
360 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
361 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
362 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
363 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
364 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
365 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
367 [DR_ACTION_STATE_NON_TERM] = {
368 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
369 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
370 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
371 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
372 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
373 [DR_ACTION_TYP_TNL_L2_TO_L2] = DR_ACTION_STATE_DECAP,
374 [DR_ACTION_TYP_TNL_L3_TO_L2] = DR_ACTION_STATE_DECAP,
375 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
376 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
377 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
378 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
379 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
380 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
381 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
382 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
383 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
385 [DR_ACTION_STATE_ASO] = {
386 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
387 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
388 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
389 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
390 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ASO,
392 [DR_ACTION_STATE_TERM] = {
393 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_TERM,
396 [DR_ACTION_DOMAIN_FDB_EGRESS] = {
397 [DR_ACTION_STATE_NO_ACTION] = {
398 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
399 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
400 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
401 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
402 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
403 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
404 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
405 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
406 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
407 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
408 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
409 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
410 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
411 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
413 [DR_ACTION_STATE_DECAP] = {
414 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
415 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
416 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
417 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_DECAP,
418 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
419 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
420 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
422 [DR_ACTION_STATE_ENCAP] = {
423 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
424 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
425 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
426 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ENCAP,
427 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
428 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
429 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
431 [DR_ACTION_STATE_MODIFY_HDR] = {
432 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
433 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
434 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
435 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
436 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_MODIFY_HDR,
437 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
438 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
439 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
440 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
441 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
442 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
444 [DR_ACTION_STATE_POP_VLAN] = {
445 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
446 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
447 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
448 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_POP_VLAN,
449 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
450 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
451 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
452 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
453 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
454 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
455 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
456 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
458 [DR_ACTION_STATE_PUSH_VLAN] = {
459 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
460 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
461 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
462 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
463 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
464 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_PUSH_VLAN,
465 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
466 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
467 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
468 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
469 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
471 [DR_ACTION_STATE_NON_TERM] = {
472 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
473 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
474 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
475 [DR_ACTION_TYP_SAMPLER] = DR_ACTION_STATE_TERM,
476 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_NON_TERM,
477 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
478 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
479 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
480 [DR_ACTION_TYP_INSERT_HDR] = DR_ACTION_STATE_ENCAP,
481 [DR_ACTION_TYP_REMOVE_HDR] = DR_ACTION_STATE_DECAP,
482 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
483 [DR_ACTION_TYP_POP_VLAN] = DR_ACTION_STATE_POP_VLAN,
484 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
485 [DR_ACTION_TYP_ASO_FLOW_METER] = DR_ACTION_STATE_ASO,
487 [DR_ACTION_STATE_ASO] = {
488 [DR_ACTION_TYP_L2_TO_TNL_L2] = DR_ACTION_STATE_ENCAP,
489 [DR_ACTION_TYP_L2_TO_TNL_L3] = DR_ACTION_STATE_ENCAP,
490 [DR_ACTION_TYP_MODIFY_HDR] = DR_ACTION_STATE_MODIFY_HDR,
491 [DR_ACTION_TYP_PUSH_VLAN] = DR_ACTION_STATE_PUSH_VLAN,
492 [DR_ACTION_TYP_DROP] = DR_ACTION_STATE_TERM,
493 [DR_ACTION_TYP_FT] = DR_ACTION_STATE_TERM,
494 [DR_ACTION_TYP_RANGE] = DR_ACTION_STATE_TERM,
495 [DR_ACTION_TYP_VPORT] = DR_ACTION_STATE_TERM,
496 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_ASO,
498 [DR_ACTION_STATE_TERM] = {
499 [DR_ACTION_TYP_CTR] = DR_ACTION_STATE_TERM,
505 dr_action_reformat_to_action_type(enum mlx5dr_action_reformat_type reformat_type,
506 enum mlx5dr_action_type *action_type)
508 switch (reformat_type) {
509 case DR_ACTION_REFORMAT_TYP_TNL_L2_TO_L2:
510 *action_type = DR_ACTION_TYP_TNL_L2_TO_L2;
512 case DR_ACTION_REFORMAT_TYP_L2_TO_TNL_L2:
513 *action_type = DR_ACTION_TYP_L2_TO_TNL_L2;
515 case DR_ACTION_REFORMAT_TYP_TNL_L3_TO_L2:
516 *action_type = DR_ACTION_TYP_TNL_L3_TO_L2;
518 case DR_ACTION_REFORMAT_TYP_L2_TO_TNL_L3:
519 *action_type = DR_ACTION_TYP_L2_TO_TNL_L3;
521 case DR_ACTION_REFORMAT_TYP_INSERT_HDR:
522 *action_type = DR_ACTION_TYP_INSERT_HDR;
524 case DR_ACTION_REFORMAT_TYP_REMOVE_HDR:
525 *action_type = DR_ACTION_TYP_REMOVE_HDR;
534 /* Apply the actions on the rule STE array starting from the last_ste.
535 * Actions might require more than one STE, new_num_stes will return
536 * the new size of the STEs array, rule with actions.
538 static void dr_actions_apply(struct mlx5dr_domain *dmn,
539 enum mlx5dr_domain_nic_type nic_type,
542 struct mlx5dr_ste_actions_attr *attr,
545 struct mlx5dr_ste_ctx *ste_ctx = dmn->ste_ctx;
548 if (nic_type == DR_DOMAIN_NIC_TYPE_RX)
549 mlx5dr_ste_set_actions_rx(ste_ctx, dmn, action_type_set,
550 last_ste, attr, &added_stes);
552 mlx5dr_ste_set_actions_tx(ste_ctx, dmn, action_type_set,
553 last_ste, attr, &added_stes);
555 *new_num_stes += added_stes;
558 static enum dr_action_domain
559 dr_action_get_action_domain(enum mlx5dr_domain_type domain,
560 enum mlx5dr_domain_nic_type nic_type)
563 case MLX5DR_DOMAIN_TYPE_NIC_RX:
564 return DR_ACTION_DOMAIN_NIC_INGRESS;
565 case MLX5DR_DOMAIN_TYPE_NIC_TX:
566 return DR_ACTION_DOMAIN_NIC_EGRESS;
567 case MLX5DR_DOMAIN_TYPE_FDB:
568 if (nic_type == DR_DOMAIN_NIC_TYPE_RX)
569 return DR_ACTION_DOMAIN_FDB_INGRESS;
570 return DR_ACTION_DOMAIN_FDB_EGRESS;
573 return DR_ACTION_DOMAIN_MAX;
578 int dr_action_validate_and_get_next_state(enum dr_action_domain action_domain,
582 u32 cur_state = *state;
584 /* Check action state machine is valid */
585 *state = next_action_state[action_domain][cur_state][action_type];
587 if (*state == DR_ACTION_STATE_ERR)
593 static int dr_action_handle_cs_recalc(struct mlx5dr_domain *dmn,
594 struct mlx5dr_action *dest_action,
599 switch (dest_action->action_type) {
600 case DR_ACTION_TYP_FT:
601 /* Allow destination flow table only if table is a terminating
602 * table, since there is an *assumption* that in such case FW
603 * will recalculate the CS.
605 if (dest_action->dest_tbl->is_fw_tbl) {
606 *final_icm_addr = dest_action->dest_tbl->fw_tbl.rx_icm_addr;
609 "Destination FT should be terminating when modify TTL is used\n");
614 case DR_ACTION_TYP_VPORT:
615 /* If destination is vport we will get the FW flow table
616 * that recalculates the CS and forwards to the vport.
618 ret = mlx5dr_domain_get_recalc_cs_ft_addr(dest_action->vport->dmn,
619 dest_action->vport->caps->num,
622 mlx5dr_err(dmn, "Failed to get FW cs recalc flow table\n");
634 static void dr_action_modify_ttl_adjust(struct mlx5dr_domain *dmn,
635 struct mlx5dr_ste_actions_attr *attr,
637 bool *recalc_cs_required)
639 *recalc_cs_required = false;
641 /* if device supports csum recalculation - no adjustment needed */
642 if (mlx5dr_ste_supp_ttl_cs_recalc(&dmn->info.caps))
645 /* no adjustment needed on TX rules */
649 if (!MLX5_CAP_ESW_FLOWTABLE(dmn->mdev, fdb_ipv4_ttl_modify)) {
650 /* Ignore the modify TTL action.
651 * It is always kept as last HW action.
653 attr->modify_actions--;
657 if (dmn->type == MLX5DR_DOMAIN_TYPE_FDB)
658 /* Due to a HW bug on some devices, modifying TTL on RX flows
659 * will cause an incorrect checksum calculation. In such cases
660 * we will use a FW table to recalculate the checksum.
662 *recalc_cs_required = true;
665 static void dr_action_print_sequence(struct mlx5dr_domain *dmn,
666 struct mlx5dr_action *actions[],
671 for (i = 0; i <= last_idx; i++)
672 mlx5dr_err(dmn, "< %s (%d) > ",
673 dr_action_id_to_str(actions[i]->action_type),
674 actions[i]->action_type);
677 static int dr_action_get_dest_fw_tbl_addr(struct mlx5dr_matcher *matcher,
678 struct mlx5dr_action_dest_tbl *dest_tbl,
682 struct mlx5dr_cmd_query_flow_table_details output;
683 struct mlx5dr_domain *dmn = matcher->tbl->dmn;
686 if (!dest_tbl->fw_tbl.rx_icm_addr) {
687 ret = mlx5dr_cmd_query_flow_table(dmn->mdev,
688 dest_tbl->fw_tbl.type,
693 "Failed mlx5_cmd_query_flow_table ret: %d\n",
698 dest_tbl->fw_tbl.tx_icm_addr = output.sw_owner_icm_root_1;
699 dest_tbl->fw_tbl.rx_icm_addr = output.sw_owner_icm_root_0;
702 *final_icm_addr = is_rx_rule ? dest_tbl->fw_tbl.rx_icm_addr :
703 dest_tbl->fw_tbl.tx_icm_addr;
707 static int dr_action_get_dest_sw_tbl_addr(struct mlx5dr_matcher *matcher,
708 struct mlx5dr_action_dest_tbl *dest_tbl,
712 struct mlx5dr_domain *dmn = matcher->tbl->dmn;
713 struct mlx5dr_icm_chunk *chunk;
715 if (dest_tbl->tbl->dmn != dmn) {
717 "Destination table belongs to a different domain\n");
721 if (dest_tbl->tbl->level <= matcher->tbl->level) {
722 mlx5_core_dbg_once(dmn->mdev,
723 "Connecting table to a lower/same level destination table\n");
725 "Connecting table at level %d to a destination table at level %d\n",
727 dest_tbl->tbl->level);
730 chunk = is_rx_rule ? dest_tbl->tbl->rx.s_anchor->chunk :
731 dest_tbl->tbl->tx.s_anchor->chunk;
733 *final_icm_addr = mlx5dr_icm_pool_get_chunk_icm_addr(chunk);
737 static int dr_action_get_dest_tbl_addr(struct mlx5dr_matcher *matcher,
738 struct mlx5dr_action_dest_tbl *dest_tbl,
742 if (dest_tbl->is_fw_tbl)
743 return dr_action_get_dest_fw_tbl_addr(matcher,
748 return dr_action_get_dest_sw_tbl_addr(matcher,
754 #define WITH_VLAN_NUM_HW_ACTIONS 6
756 int mlx5dr_actions_build_ste_arr(struct mlx5dr_matcher *matcher,
757 struct mlx5dr_matcher_rx_tx *nic_matcher,
758 struct mlx5dr_action *actions[],
761 u32 *new_hw_ste_arr_sz)
763 struct mlx5dr_domain_rx_tx *nic_dmn = nic_matcher->nic_tbl->nic_dmn;
764 bool rx_rule = nic_dmn->type == DR_DOMAIN_NIC_TYPE_RX;
765 struct mlx5dr_domain *dmn = matcher->tbl->dmn;
766 u8 action_type_set[DR_ACTION_TYP_MAX] = {};
767 struct mlx5dr_ste_actions_attr attr = {};
768 struct mlx5dr_action *dest_action = NULL;
769 u32 state = DR_ACTION_STATE_NO_ACTION;
770 enum dr_action_domain action_domain;
771 bool recalc_cs_required = false;
775 attr.gvmi = dmn->info.caps.gvmi;
776 attr.hit_gvmi = dmn->info.caps.gvmi;
777 attr.final_icm_addr = nic_dmn->default_icm_addr;
778 action_domain = dr_action_get_action_domain(dmn->type, nic_dmn->type);
780 for (i = 0; i < num_actions; i++) {
781 struct mlx5dr_action *action;
782 int max_actions_type = 1;
786 action_type = action->action_type;
788 switch (action_type) {
789 case DR_ACTION_TYP_DROP:
790 attr.final_icm_addr = nic_dmn->drop_icm_addr;
791 attr.hit_gvmi = nic_dmn->drop_icm_addr >> 48;
793 case DR_ACTION_TYP_FT:
794 dest_action = action;
795 ret = dr_action_get_dest_tbl_addr(matcher, action->dest_tbl,
796 rx_rule, &attr.final_icm_addr);
800 case DR_ACTION_TYP_RANGE:
801 ret = dr_action_get_dest_tbl_addr(matcher,
802 action->range->hit_tbl_action->dest_tbl,
803 rx_rule, &attr.final_icm_addr);
807 ret = dr_action_get_dest_tbl_addr(matcher,
808 action->range->miss_tbl_action->dest_tbl,
809 rx_rule, &attr.range.miss_icm_addr);
813 attr.range.definer_id = action->range->definer_id;
814 attr.range.min = action->range->min;
815 attr.range.max = action->range->max;
817 case DR_ACTION_TYP_QP:
818 mlx5dr_info(dmn, "Domain doesn't support QP\n");
820 case DR_ACTION_TYP_CTR:
821 attr.ctr_id = action->ctr->ctr_id +
824 case DR_ACTION_TYP_TAG:
825 attr.flow_tag = action->flow_tag->flow_tag;
827 case DR_ACTION_TYP_TNL_L2_TO_L2:
829 case DR_ACTION_TYP_TNL_L3_TO_L2:
830 if (action->rewrite->ptrn && action->rewrite->arg) {
831 attr.decap_index = mlx5dr_arg_get_obj_id(action->rewrite->arg);
832 attr.decap_actions = action->rewrite->ptrn->num_of_actions;
833 attr.decap_pat_idx = action->rewrite->ptrn->index;
835 attr.decap_index = action->rewrite->index;
836 attr.decap_actions = action->rewrite->num_of_actions;
837 attr.decap_with_vlan =
838 attr.decap_actions == WITH_VLAN_NUM_HW_ACTIONS;
839 attr.decap_pat_idx = MLX5DR_INVALID_PATTERN_INDEX;
842 case DR_ACTION_TYP_MODIFY_HDR:
843 if (action->rewrite->single_action_opt) {
844 attr.modify_actions = action->rewrite->num_of_actions;
845 attr.single_modify_action = action->rewrite->data;
847 if (action->rewrite->ptrn && action->rewrite->arg) {
849 mlx5dr_arg_get_obj_id(action->rewrite->arg);
850 attr.modify_actions = action->rewrite->ptrn->num_of_actions;
851 attr.modify_pat_idx = action->rewrite->ptrn->index;
853 attr.modify_index = action->rewrite->index;
854 attr.modify_actions = action->rewrite->num_of_actions;
855 attr.modify_pat_idx = MLX5DR_INVALID_PATTERN_INDEX;
858 if (action->rewrite->modify_ttl)
859 dr_action_modify_ttl_adjust(dmn, &attr, rx_rule,
860 &recalc_cs_required);
862 case DR_ACTION_TYP_L2_TO_TNL_L2:
863 case DR_ACTION_TYP_L2_TO_TNL_L3:
865 !(dmn->ste_ctx->actions_caps & DR_STE_CTX_ACTION_CAP_RX_ENCAP)) {
866 mlx5dr_info(dmn, "Device doesn't support Encap on RX\n");
869 attr.reformat.size = action->reformat->size;
870 attr.reformat.id = action->reformat->id;
872 case DR_ACTION_TYP_SAMPLER:
873 attr.final_icm_addr = rx_rule ? action->sampler->rx_icm_addr :
874 action->sampler->tx_icm_addr;
876 case DR_ACTION_TYP_VPORT:
877 if (unlikely(rx_rule && action->vport->caps->num == MLX5_VPORT_UPLINK)) {
878 /* can't go to uplink on RX rule - dropping instead */
879 attr.final_icm_addr = nic_dmn->drop_icm_addr;
880 attr.hit_gvmi = nic_dmn->drop_icm_addr >> 48;
882 attr.hit_gvmi = action->vport->caps->vhca_gvmi;
883 dest_action = action;
884 attr.final_icm_addr = rx_rule ?
885 action->vport->caps->icm_address_rx :
886 action->vport->caps->icm_address_tx;
889 case DR_ACTION_TYP_POP_VLAN:
890 if (!rx_rule && !(dmn->ste_ctx->actions_caps &
891 DR_STE_CTX_ACTION_CAP_TX_POP)) {
892 mlx5dr_dbg(dmn, "Device doesn't support POP VLAN action on TX\n");
896 max_actions_type = MLX5DR_MAX_VLANS;
899 case DR_ACTION_TYP_PUSH_VLAN:
900 if (rx_rule && !(dmn->ste_ctx->actions_caps &
901 DR_STE_CTX_ACTION_CAP_RX_PUSH)) {
902 mlx5dr_dbg(dmn, "Device doesn't support PUSH VLAN action on RX\n");
906 max_actions_type = MLX5DR_MAX_VLANS;
907 if (attr.vlans.count == MLX5DR_MAX_VLANS) {
908 mlx5dr_dbg(dmn, "Max VLAN push/pop count exceeded\n");
912 attr.vlans.headers[attr.vlans.count++] = action->push_vlan->vlan_hdr;
914 case DR_ACTION_TYP_INSERT_HDR:
915 case DR_ACTION_TYP_REMOVE_HDR:
916 attr.reformat.size = action->reformat->size;
917 attr.reformat.id = action->reformat->id;
918 attr.reformat.param_0 = action->reformat->param_0;
919 attr.reformat.param_1 = action->reformat->param_1;
921 case DR_ACTION_TYP_ASO_FLOW_METER:
922 attr.aso_flow_meter.obj_id = action->aso->obj_id;
923 attr.aso_flow_meter.offset = action->aso->offset;
924 attr.aso_flow_meter.dest_reg_id = action->aso->dest_reg_id;
925 attr.aso_flow_meter.init_color = action->aso->init_color;
928 mlx5dr_err(dmn, "Unsupported action type %d\n", action_type);
932 /* Check action duplication */
933 if (++action_type_set[action_type] > max_actions_type) {
934 mlx5dr_err(dmn, "Action type %d supports only max %d time(s)\n",
935 action_type, max_actions_type);
939 /* Check action state machine is valid */
940 if (dr_action_validate_and_get_next_state(action_domain,
943 mlx5dr_err(dmn, "Invalid action (gvmi: %d, is_rx: %d) sequence provided:",
945 dr_action_print_sequence(dmn, actions, i);
950 *new_hw_ste_arr_sz = nic_matcher->num_of_builders;
951 last_ste = ste_arr + DR_STE_SIZE * (nic_matcher->num_of_builders - 1);
953 if (recalc_cs_required && dest_action) {
954 ret = dr_action_handle_cs_recalc(dmn, dest_action, &attr.final_icm_addr);
957 "Failed to handle checksum recalculation err %d\n",
963 dr_actions_apply(dmn,
973 static unsigned int action_size[DR_ACTION_TYP_MAX] = {
974 [DR_ACTION_TYP_TNL_L2_TO_L2] = sizeof(struct mlx5dr_action_reformat),
975 [DR_ACTION_TYP_L2_TO_TNL_L2] = sizeof(struct mlx5dr_action_reformat),
976 [DR_ACTION_TYP_TNL_L3_TO_L2] = sizeof(struct mlx5dr_action_rewrite),
977 [DR_ACTION_TYP_L2_TO_TNL_L3] = sizeof(struct mlx5dr_action_reformat),
978 [DR_ACTION_TYP_FT] = sizeof(struct mlx5dr_action_dest_tbl),
979 [DR_ACTION_TYP_CTR] = sizeof(struct mlx5dr_action_ctr),
980 [DR_ACTION_TYP_TAG] = sizeof(struct mlx5dr_action_flow_tag),
981 [DR_ACTION_TYP_MODIFY_HDR] = sizeof(struct mlx5dr_action_rewrite),
982 [DR_ACTION_TYP_VPORT] = sizeof(struct mlx5dr_action_vport),
983 [DR_ACTION_TYP_PUSH_VLAN] = sizeof(struct mlx5dr_action_push_vlan),
984 [DR_ACTION_TYP_INSERT_HDR] = sizeof(struct mlx5dr_action_reformat),
985 [DR_ACTION_TYP_REMOVE_HDR] = sizeof(struct mlx5dr_action_reformat),
986 [DR_ACTION_TYP_SAMPLER] = sizeof(struct mlx5dr_action_sampler),
987 [DR_ACTION_TYP_ASO_FLOW_METER] = sizeof(struct mlx5dr_action_aso_flow_meter),
988 [DR_ACTION_TYP_RANGE] = sizeof(struct mlx5dr_action_range),
991 static struct mlx5dr_action *
992 dr_action_create_generic(enum mlx5dr_action_type action_type)
994 struct mlx5dr_action *action;
997 if (action_type < DR_ACTION_TYP_MAX)
998 extra_size = action_size[action_type];
1002 action = kzalloc(sizeof(*action) + extra_size, GFP_KERNEL);
1006 action->action_type = action_type;
1007 refcount_set(&action->refcount, 1);
1008 action->data = action + 1;
1013 struct mlx5dr_action *mlx5dr_action_create_drop(void)
1015 return dr_action_create_generic(DR_ACTION_TYP_DROP);
1018 struct mlx5dr_action *
1019 mlx5dr_action_create_dest_table_num(struct mlx5dr_domain *dmn, u32 table_num)
1021 struct mlx5dr_action *action;
1023 action = dr_action_create_generic(DR_ACTION_TYP_FT);
1027 action->dest_tbl->is_fw_tbl = true;
1028 action->dest_tbl->fw_tbl.dmn = dmn;
1029 action->dest_tbl->fw_tbl.id = table_num;
1030 action->dest_tbl->fw_tbl.type = FS_FT_FDB;
1031 refcount_inc(&dmn->refcount);
1036 struct mlx5dr_action *
1037 mlx5dr_action_create_dest_table(struct mlx5dr_table *tbl)
1039 struct mlx5dr_action *action;
1041 refcount_inc(&tbl->refcount);
1043 action = dr_action_create_generic(DR_ACTION_TYP_FT);
1047 action->dest_tbl->tbl = tbl;
1052 refcount_dec(&tbl->refcount);
1056 static void dr_action_range_definer_fill(u16 *format_id,
1063 *format_id = MLX5_IFC_DEFINER_FORMAT_ID_SELECT;
1065 dw_selectors[0] = MLX5_IFC_DEFINER_FORMAT_OFFSET_OUTER_ETH_PKT_LEN / 4;
1067 for (i = 1; i < MLX5_IFC_DEFINER_DW_SELECTORS_NUM; i++)
1068 dw_selectors[i] = MLX5_IFC_DEFINER_FORMAT_OFFSET_UNUSED;
1070 for (i = 0; i < MLX5_IFC_DEFINER_BYTE_SELECTORS_NUM; i++)
1071 byte_selectors[i] = MLX5_IFC_DEFINER_FORMAT_OFFSET_UNUSED;
1073 MLX5_SET(match_definer_match_mask, match_mask,
1074 match_dw_0, 0xffffUL << 16);
1077 static int dr_action_create_range_definer(struct mlx5dr_action *action)
1079 u8 match_mask[MLX5_FLD_SZ_BYTES(match_definer, match_mask)] = {};
1080 u8 byte_selectors[MLX5_IFC_DEFINER_BYTE_SELECTORS_NUM] = {};
1081 u8 dw_selectors[MLX5_IFC_DEFINER_DW_SELECTORS_NUM] = {};
1082 struct mlx5dr_domain *dmn = action->range->dmn;
1087 dr_action_range_definer_fill(&format_id,
1092 ret = mlx5dr_definer_get(dmn, format_id,
1093 dw_selectors, byte_selectors,
1094 match_mask, &definer_id);
1098 action->range->definer_id = definer_id;
1102 static void dr_action_destroy_range_definer(struct mlx5dr_action *action)
1104 mlx5dr_definer_put(action->range->dmn, action->range->definer_id);
1107 struct mlx5dr_action *
1108 mlx5dr_action_create_dest_match_range(struct mlx5dr_domain *dmn,
1110 struct mlx5_flow_table *hit_ft,
1111 struct mlx5_flow_table *miss_ft,
1115 struct mlx5dr_action *action;
1118 if (!mlx5dr_supp_match_ranges(dmn->mdev)) {
1119 mlx5dr_dbg(dmn, "SELECT definer support is needed for match range\n");
1123 if (field != MLX5_FLOW_DEST_RANGE_FIELD_PKT_LEN ||
1124 min > 0xffff || max > 0xffff) {
1125 mlx5dr_err(dmn, "Invalid match range parameters\n");
1129 action = dr_action_create_generic(DR_ACTION_TYP_RANGE);
1133 action->range->hit_tbl_action =
1134 mlx5dr_is_fw_table(hit_ft) ?
1135 mlx5dr_action_create_dest_flow_fw_table(dmn, hit_ft) :
1136 mlx5dr_action_create_dest_table(hit_ft->fs_dr_table.dr_table);
1138 if (!action->range->hit_tbl_action)
1141 action->range->miss_tbl_action =
1142 mlx5dr_is_fw_table(miss_ft) ?
1143 mlx5dr_action_create_dest_flow_fw_table(dmn, miss_ft) :
1144 mlx5dr_action_create_dest_table(miss_ft->fs_dr_table.dr_table);
1146 if (!action->range->miss_tbl_action)
1147 goto free_hit_tbl_action;
1149 action->range->min = min;
1150 action->range->max = max;
1151 action->range->dmn = dmn;
1153 ret = dr_action_create_range_definer(action);
1155 goto free_miss_tbl_action;
1157 /* No need to increase refcount on domain for this action,
1158 * the hit/miss table actions will do it internally.
1163 free_miss_tbl_action:
1164 mlx5dr_action_destroy(action->range->miss_tbl_action);
1165 free_hit_tbl_action:
1166 mlx5dr_action_destroy(action->range->hit_tbl_action);
1173 struct mlx5dr_action *
1174 mlx5dr_action_create_mult_dest_tbl(struct mlx5dr_domain *dmn,
1175 struct mlx5dr_action_dest *dests,
1177 bool ignore_flow_level,
1180 struct mlx5dr_cmd_flow_destination_hw_info *hw_dests;
1181 struct mlx5dr_action **ref_actions;
1182 struct mlx5dr_action *action;
1183 bool reformat_req = false;
1184 bool is_ft_wire = false;
1192 if (dmn->type != MLX5DR_DOMAIN_TYPE_FDB) {
1193 mlx5dr_err(dmn, "Multiple destination support is for FDB only\n");
1197 hw_dests = kcalloc(num_of_dests, sizeof(*hw_dests), GFP_KERNEL);
1201 if (unlikely(check_mul_overflow(num_of_dests, 2u, &ref_act_cnt)))
1204 ref_actions = kcalloc(ref_act_cnt, sizeof(*ref_actions), GFP_KERNEL);
1208 for (i = 0; i < num_of_dests; i++) {
1209 struct mlx5dr_action *reformat_action = dests[i].reformat;
1210 struct mlx5dr_action *dest_action = dests[i].dest;
1212 ref_actions[num_of_ref++] = dest_action;
1214 switch (dest_action->action_type) {
1215 case DR_ACTION_TYP_VPORT:
1216 hw_dests[i].vport.flags = MLX5_FLOW_DEST_VPORT_VHCA_ID;
1217 hw_dests[i].type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
1218 hw_dests[i].vport.num = dest_action->vport->caps->num;
1219 hw_dests[i].vport.vhca_id = dest_action->vport->caps->vhca_gvmi;
1220 if (reformat_action) {
1221 reformat_req = true;
1222 hw_dests[i].vport.reformat_id =
1223 reformat_action->reformat->id;
1224 ref_actions[num_of_ref++] = reformat_action;
1225 hw_dests[i].vport.flags |= MLX5_FLOW_DEST_VPORT_REFORMAT_ID;
1229 case DR_ACTION_TYP_FT:
1231 !mlx5dr_action_supp_fwd_fdb_multi_ft(dmn->mdev)) {
1232 mlx5dr_dbg(dmn, "multiple FT destinations not supported\n");
1233 goto free_ref_actions;
1236 hw_dests[i].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
1237 if (dest_action->dest_tbl->is_fw_tbl) {
1238 hw_dests[i].ft_id = dest_action->dest_tbl->fw_tbl.id;
1240 hw_dests[i].ft_id = dest_action->dest_tbl->tbl->table_id;
1241 if (dest_action->dest_tbl->is_wire_ft) {
1249 mlx5dr_dbg(dmn, "Invalid multiple destinations action\n");
1250 goto free_ref_actions;
1254 /* In multidest, the FW does the iterator in the RX except of the last
1255 * one that done in the TX.
1256 * So, if one of the ft target is wire, put it at the end of the dest list.
1258 if (is_ft_wire && num_dst_ft > 1)
1259 swap(hw_dests[last_dest], hw_dests[num_of_dests - 1]);
1261 action = dr_action_create_generic(DR_ACTION_TYP_FT);
1263 goto free_ref_actions;
1265 ret = mlx5dr_fw_create_md_tbl(dmn,
1269 &action->dest_tbl->fw_tbl.id,
1270 &action->dest_tbl->fw_tbl.group_id,
1276 refcount_inc(&dmn->refcount);
1278 for (i = 0; i < num_of_ref; i++)
1279 refcount_inc(&ref_actions[i]->refcount);
1281 action->dest_tbl->is_fw_tbl = true;
1282 action->dest_tbl->fw_tbl.dmn = dmn;
1283 action->dest_tbl->fw_tbl.type = FS_FT_FDB;
1284 action->dest_tbl->fw_tbl.ref_actions = ref_actions;
1285 action->dest_tbl->fw_tbl.num_of_ref_actions = num_of_ref;
1300 struct mlx5dr_action *
1301 mlx5dr_action_create_dest_flow_fw_table(struct mlx5dr_domain *dmn,
1302 struct mlx5_flow_table *ft)
1304 struct mlx5dr_action *action;
1306 action = dr_action_create_generic(DR_ACTION_TYP_FT);
1310 action->dest_tbl->is_fw_tbl = 1;
1311 action->dest_tbl->fw_tbl.type = ft->type;
1312 action->dest_tbl->fw_tbl.id = ft->id;
1313 action->dest_tbl->fw_tbl.dmn = dmn;
1315 refcount_inc(&dmn->refcount);
1320 struct mlx5dr_action *
1321 mlx5dr_action_create_flow_counter(u32 counter_id)
1323 struct mlx5dr_action *action;
1325 action = dr_action_create_generic(DR_ACTION_TYP_CTR);
1329 action->ctr->ctr_id = counter_id;
1334 struct mlx5dr_action *mlx5dr_action_create_tag(u32 tag_value)
1336 struct mlx5dr_action *action;
1338 action = dr_action_create_generic(DR_ACTION_TYP_TAG);
1342 action->flow_tag->flow_tag = tag_value & 0xffffff;
1347 struct mlx5dr_action *
1348 mlx5dr_action_create_flow_sampler(struct mlx5dr_domain *dmn, u32 sampler_id)
1350 struct mlx5dr_action *action;
1354 ret = mlx5dr_cmd_query_flow_sampler(dmn->mdev, sampler_id,
1359 action = dr_action_create_generic(DR_ACTION_TYP_SAMPLER);
1363 action->sampler->dmn = dmn;
1364 action->sampler->sampler_id = sampler_id;
1365 action->sampler->rx_icm_addr = icm_rx;
1366 action->sampler->tx_icm_addr = icm_tx;
1368 refcount_inc(&dmn->refcount);
1373 dr_action_verify_reformat_params(enum mlx5dr_action_type reformat_type,
1374 struct mlx5dr_domain *dmn,
1375 u8 reformat_param_0,
1376 u8 reformat_param_1,
1380 if (reformat_type == DR_ACTION_TYP_INSERT_HDR) {
1381 if ((!data && data_sz) || (data && !data_sz) ||
1382 MLX5_CAP_GEN_2(dmn->mdev, max_reformat_insert_size) < data_sz ||
1383 MLX5_CAP_GEN_2(dmn->mdev, max_reformat_insert_offset) < reformat_param_1) {
1384 mlx5dr_dbg(dmn, "Invalid reformat parameters for INSERT_HDR\n");
1387 } else if (reformat_type == DR_ACTION_TYP_REMOVE_HDR) {
1389 MLX5_CAP_GEN_2(dmn->mdev, max_reformat_remove_size) < data_sz ||
1390 MLX5_CAP_GEN_2(dmn->mdev, max_reformat_remove_offset) < reformat_param_1) {
1391 mlx5dr_dbg(dmn, "Invalid reformat parameters for REMOVE_HDR\n");
1394 } else if (reformat_param_0 || reformat_param_1 ||
1395 reformat_type > DR_ACTION_TYP_REMOVE_HDR) {
1396 mlx5dr_dbg(dmn, "Invalid reformat parameters\n");
1400 if (dmn->type == MLX5DR_DOMAIN_TYPE_FDB)
1403 if (dmn->type == MLX5DR_DOMAIN_TYPE_NIC_RX) {
1404 if (reformat_type != DR_ACTION_TYP_TNL_L2_TO_L2 &&
1405 reformat_type != DR_ACTION_TYP_TNL_L3_TO_L2) {
1406 mlx5dr_dbg(dmn, "Action reformat type not support on RX domain\n");
1409 } else if (dmn->type == MLX5DR_DOMAIN_TYPE_NIC_TX) {
1410 if (reformat_type != DR_ACTION_TYP_L2_TO_TNL_L2 &&
1411 reformat_type != DR_ACTION_TYP_L2_TO_TNL_L3) {
1412 mlx5dr_dbg(dmn, "Action reformat type not support on TX domain\n");
1424 dr_action_create_reformat_action(struct mlx5dr_domain *dmn,
1425 u8 reformat_param_0, u8 reformat_param_1,
1426 size_t data_sz, void *data,
1427 struct mlx5dr_action *action)
1432 switch (action->action_type) {
1433 case DR_ACTION_TYP_L2_TO_TNL_L2:
1434 case DR_ACTION_TYP_L2_TO_TNL_L3:
1436 enum mlx5_reformat_ctx_type rt;
1438 if (action->action_type == DR_ACTION_TYP_L2_TO_TNL_L2)
1439 rt = MLX5_REFORMAT_TYPE_L2_TO_L2_TUNNEL;
1441 rt = MLX5_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
1443 ret = mlx5dr_cmd_create_reformat_ctx(dmn->mdev, rt, 0, 0,
1449 action->reformat->id = reformat_id;
1450 action->reformat->size = data_sz;
1453 case DR_ACTION_TYP_TNL_L2_TO_L2:
1457 case DR_ACTION_TYP_TNL_L3_TO_L2:
1461 hw_actions = kzalloc(DR_ACTION_CACHE_LINE_SIZE, GFP_KERNEL);
1465 ret = mlx5dr_ste_set_action_decap_l3_list(dmn->ste_ctx,
1468 DR_ACTION_CACHE_LINE_SIZE,
1469 &action->rewrite->num_of_actions);
1471 mlx5dr_dbg(dmn, "Failed creating decap l3 action list\n");
1476 action->rewrite->data = hw_actions;
1477 action->rewrite->dmn = dmn;
1479 ret = mlx5dr_ste_alloc_modify_hdr(action);
1481 mlx5dr_dbg(dmn, "Failed preparing reformat data\n");
1487 case DR_ACTION_TYP_INSERT_HDR:
1488 ret = mlx5dr_cmd_create_reformat_ctx(dmn->mdev,
1489 MLX5_REFORMAT_TYPE_INSERT_HDR,
1497 action->reformat->id = reformat_id;
1498 action->reformat->size = data_sz;
1499 action->reformat->param_0 = reformat_param_0;
1500 action->reformat->param_1 = reformat_param_1;
1502 case DR_ACTION_TYP_REMOVE_HDR:
1503 action->reformat->id = 0;
1504 action->reformat->size = data_sz;
1505 action->reformat->param_0 = reformat_param_0;
1506 action->reformat->param_1 = reformat_param_1;
1509 mlx5dr_info(dmn, "Reformat type is not supported %d\n", action->action_type);
1514 #define CVLAN_ETHERTYPE 0x8100
1515 #define SVLAN_ETHERTYPE 0x88a8
1517 struct mlx5dr_action *mlx5dr_action_create_pop_vlan(void)
1519 return dr_action_create_generic(DR_ACTION_TYP_POP_VLAN);
1522 struct mlx5dr_action *mlx5dr_action_create_push_vlan(struct mlx5dr_domain *dmn,
1525 u32 vlan_hdr_h = ntohl(vlan_hdr);
1526 u16 ethertype = vlan_hdr_h >> 16;
1527 struct mlx5dr_action *action;
1529 if (ethertype != SVLAN_ETHERTYPE && ethertype != CVLAN_ETHERTYPE) {
1530 mlx5dr_dbg(dmn, "Invalid vlan ethertype\n");
1534 action = dr_action_create_generic(DR_ACTION_TYP_PUSH_VLAN);
1538 action->push_vlan->vlan_hdr = vlan_hdr_h;
1542 struct mlx5dr_action *
1543 mlx5dr_action_create_packet_reformat(struct mlx5dr_domain *dmn,
1544 enum mlx5dr_action_reformat_type reformat_type,
1545 u8 reformat_param_0,
1546 u8 reformat_param_1,
1550 enum mlx5dr_action_type action_type;
1551 struct mlx5dr_action *action;
1554 refcount_inc(&dmn->refcount);
1556 /* General checks */
1557 ret = dr_action_reformat_to_action_type(reformat_type, &action_type);
1559 mlx5dr_dbg(dmn, "Invalid reformat_type provided\n");
1563 ret = dr_action_verify_reformat_params(action_type, dmn,
1564 reformat_param_0, reformat_param_1,
1569 action = dr_action_create_generic(action_type);
1573 action->reformat->dmn = dmn;
1575 ret = dr_action_create_reformat_action(dmn,
1582 mlx5dr_dbg(dmn, "Failed creating reformat action %d\n", ret);
1591 refcount_dec(&dmn->refcount);
1596 dr_action_modify_sw_to_hw_add(struct mlx5dr_domain *dmn,
1599 const struct mlx5dr_ste_action_modify_field **ret_hw_info)
1601 const struct mlx5dr_ste_action_modify_field *hw_action_info;
1606 /* Get SW modify action data */
1607 sw_field = MLX5_GET(set_action_in, sw_action, field);
1608 data = MLX5_GET(set_action_in, sw_action, data);
1610 /* Convert SW data to HW modify action format */
1611 hw_action_info = mlx5dr_ste_conv_modify_hdr_sw_field(dmn->ste_ctx, sw_field);
1612 if (!hw_action_info) {
1613 mlx5dr_dbg(dmn, "Modify add action invalid field given\n");
1617 max_length = hw_action_info->end - hw_action_info->start + 1;
1619 mlx5dr_ste_set_action_add(dmn->ste_ctx,
1621 hw_action_info->hw_field,
1622 hw_action_info->start,
1626 *ret_hw_info = hw_action_info;
1632 dr_action_modify_sw_to_hw_set(struct mlx5dr_domain *dmn,
1635 const struct mlx5dr_ste_action_modify_field **ret_hw_info)
1637 const struct mlx5dr_ste_action_modify_field *hw_action_info;
1638 u8 offset, length, max_length;
1642 /* Get SW modify action data */
1643 length = MLX5_GET(set_action_in, sw_action, length);
1644 offset = MLX5_GET(set_action_in, sw_action, offset);
1645 sw_field = MLX5_GET(set_action_in, sw_action, field);
1646 data = MLX5_GET(set_action_in, sw_action, data);
1648 /* Convert SW data to HW modify action format */
1649 hw_action_info = mlx5dr_ste_conv_modify_hdr_sw_field(dmn->ste_ctx, sw_field);
1650 if (!hw_action_info) {
1651 mlx5dr_dbg(dmn, "Modify set action invalid field given\n");
1655 /* PRM defines that length zero specific length of 32bits */
1656 length = length ? length : 32;
1658 max_length = hw_action_info->end - hw_action_info->start + 1;
1660 if (length + offset > max_length) {
1661 mlx5dr_dbg(dmn, "Modify action length + offset exceeds limit\n");
1665 mlx5dr_ste_set_action_set(dmn->ste_ctx,
1667 hw_action_info->hw_field,
1668 hw_action_info->start + offset,
1672 *ret_hw_info = hw_action_info;
1678 dr_action_modify_sw_to_hw_copy(struct mlx5dr_domain *dmn,
1681 const struct mlx5dr_ste_action_modify_field **ret_dst_hw_info,
1682 const struct mlx5dr_ste_action_modify_field **ret_src_hw_info)
1684 u8 src_offset, dst_offset, src_max_length, dst_max_length, length;
1685 const struct mlx5dr_ste_action_modify_field *hw_dst_action_info;
1686 const struct mlx5dr_ste_action_modify_field *hw_src_action_info;
1687 u16 src_field, dst_field;
1689 /* Get SW modify action data */
1690 src_field = MLX5_GET(copy_action_in, sw_action, src_field);
1691 dst_field = MLX5_GET(copy_action_in, sw_action, dst_field);
1692 src_offset = MLX5_GET(copy_action_in, sw_action, src_offset);
1693 dst_offset = MLX5_GET(copy_action_in, sw_action, dst_offset);
1694 length = MLX5_GET(copy_action_in, sw_action, length);
1696 /* Convert SW data to HW modify action format */
1697 hw_src_action_info = mlx5dr_ste_conv_modify_hdr_sw_field(dmn->ste_ctx, src_field);
1698 hw_dst_action_info = mlx5dr_ste_conv_modify_hdr_sw_field(dmn->ste_ctx, dst_field);
1699 if (!hw_src_action_info || !hw_dst_action_info) {
1700 mlx5dr_dbg(dmn, "Modify copy action invalid field given\n");
1704 /* PRM defines that length zero specific length of 32bits */
1705 length = length ? length : 32;
1707 src_max_length = hw_src_action_info->end -
1708 hw_src_action_info->start + 1;
1709 dst_max_length = hw_dst_action_info->end -
1710 hw_dst_action_info->start + 1;
1712 if (length + src_offset > src_max_length ||
1713 length + dst_offset > dst_max_length) {
1714 mlx5dr_dbg(dmn, "Modify action length + offset exceeds limit\n");
1718 mlx5dr_ste_set_action_copy(dmn->ste_ctx,
1720 hw_dst_action_info->hw_field,
1721 hw_dst_action_info->start + dst_offset,
1723 hw_src_action_info->hw_field,
1724 hw_src_action_info->start + src_offset);
1726 *ret_dst_hw_info = hw_dst_action_info;
1727 *ret_src_hw_info = hw_src_action_info;
1733 dr_action_modify_sw_to_hw(struct mlx5dr_domain *dmn,
1736 const struct mlx5dr_ste_action_modify_field **ret_dst_hw_info,
1737 const struct mlx5dr_ste_action_modify_field **ret_src_hw_info)
1743 *ret_src_hw_info = NULL;
1745 /* Get SW modify action type */
1746 action = MLX5_GET(set_action_in, sw_action, action_type);
1749 case MLX5_ACTION_TYPE_SET:
1750 ret = dr_action_modify_sw_to_hw_set(dmn, sw_action,
1755 case MLX5_ACTION_TYPE_ADD:
1756 ret = dr_action_modify_sw_to_hw_add(dmn, sw_action,
1761 case MLX5_ACTION_TYPE_COPY:
1762 ret = dr_action_modify_sw_to_hw_copy(dmn, sw_action,
1769 mlx5dr_info(dmn, "Unsupported action_type for modify action\n");
1777 dr_action_modify_check_set_field_limitation(struct mlx5dr_action *action,
1778 const __be64 *sw_action)
1780 u16 sw_field = MLX5_GET(set_action_in, sw_action, field);
1781 struct mlx5dr_domain *dmn = action->rewrite->dmn;
1783 if (sw_field == MLX5_ACTION_IN_FIELD_METADATA_REG_A) {
1784 action->rewrite->allow_rx = 0;
1785 if (dmn->type != MLX5DR_DOMAIN_TYPE_NIC_TX) {
1786 mlx5dr_dbg(dmn, "Unsupported field %d for RX/FDB set action\n",
1790 } else if (sw_field == MLX5_ACTION_IN_FIELD_METADATA_REG_B) {
1791 action->rewrite->allow_tx = 0;
1792 if (dmn->type != MLX5DR_DOMAIN_TYPE_NIC_RX) {
1793 mlx5dr_dbg(dmn, "Unsupported field %d for TX/FDB set action\n",
1799 if (!action->rewrite->allow_rx && !action->rewrite->allow_tx) {
1800 mlx5dr_dbg(dmn, "Modify SET actions not supported on both RX and TX\n");
1808 dr_action_modify_check_add_field_limitation(struct mlx5dr_action *action,
1809 const __be64 *sw_action)
1811 u16 sw_field = MLX5_GET(set_action_in, sw_action, field);
1812 struct mlx5dr_domain *dmn = action->rewrite->dmn;
1814 if (sw_field != MLX5_ACTION_IN_FIELD_OUT_IP_TTL &&
1815 sw_field != MLX5_ACTION_IN_FIELD_OUT_IPV6_HOPLIMIT &&
1816 sw_field != MLX5_ACTION_IN_FIELD_OUT_TCP_SEQ_NUM &&
1817 sw_field != MLX5_ACTION_IN_FIELD_OUT_TCP_ACK_NUM) {
1818 mlx5dr_dbg(dmn, "Unsupported field %d for add action\n",
1827 dr_action_modify_check_copy_field_limitation(struct mlx5dr_action *action,
1828 const __be64 *sw_action)
1830 struct mlx5dr_domain *dmn = action->rewrite->dmn;
1834 sw_fields[0] = MLX5_GET(copy_action_in, sw_action, src_field);
1835 sw_fields[1] = MLX5_GET(copy_action_in, sw_action, dst_field);
1837 for (i = 0; i < 2; i++) {
1838 if (sw_fields[i] == MLX5_ACTION_IN_FIELD_METADATA_REG_A) {
1839 action->rewrite->allow_rx = 0;
1840 if (dmn->type != MLX5DR_DOMAIN_TYPE_NIC_TX) {
1841 mlx5dr_dbg(dmn, "Unsupported field %d for RX/FDB set action\n",
1845 } else if (sw_fields[i] == MLX5_ACTION_IN_FIELD_METADATA_REG_B) {
1846 action->rewrite->allow_tx = 0;
1847 if (dmn->type != MLX5DR_DOMAIN_TYPE_NIC_RX) {
1848 mlx5dr_dbg(dmn, "Unsupported field %d for TX/FDB set action\n",
1855 if (!action->rewrite->allow_rx && !action->rewrite->allow_tx) {
1856 mlx5dr_dbg(dmn, "Modify copy actions not supported on both RX and TX\n");
1864 dr_action_modify_check_field_limitation(struct mlx5dr_action *action,
1865 const __be64 *sw_action)
1867 struct mlx5dr_domain *dmn = action->rewrite->dmn;
1871 action_type = MLX5_GET(set_action_in, sw_action, action_type);
1873 switch (action_type) {
1874 case MLX5_ACTION_TYPE_SET:
1875 ret = dr_action_modify_check_set_field_limitation(action,
1879 case MLX5_ACTION_TYPE_ADD:
1880 ret = dr_action_modify_check_add_field_limitation(action,
1884 case MLX5_ACTION_TYPE_COPY:
1885 ret = dr_action_modify_check_copy_field_limitation(action,
1890 mlx5dr_info(dmn, "Unsupported action %d modify action\n",
1899 dr_action_modify_check_is_ttl_modify(const void *sw_action)
1901 u16 sw_field = MLX5_GET(set_action_in, sw_action, field);
1903 return sw_field == MLX5_ACTION_IN_FIELD_OUT_IP_TTL;
1906 static int dr_actions_convert_modify_header(struct mlx5dr_action *action,
1909 __be64 sw_actions[],
1910 __be64 hw_actions[],
1911 u32 *num_hw_actions,
1914 const struct mlx5dr_ste_action_modify_field *hw_dst_action_info;
1915 const struct mlx5dr_ste_action_modify_field *hw_src_action_info;
1916 struct mlx5dr_domain *dmn = action->rewrite->dmn;
1917 __be64 *modify_ttl_sw_action = NULL;
1918 int ret, i, hw_idx = 0;
1925 *modify_ttl = false;
1927 action->rewrite->allow_rx = 1;
1928 action->rewrite->allow_tx = 1;
1930 for (i = 0; i < num_sw_actions || modify_ttl_sw_action; i++) {
1931 /* modify TTL is handled separately, as a last action */
1932 if (i == num_sw_actions) {
1933 sw_action = modify_ttl_sw_action;
1934 modify_ttl_sw_action = NULL;
1936 sw_action = &sw_actions[i];
1939 ret = dr_action_modify_check_field_limitation(action,
1944 if (!(*modify_ttl) &&
1945 dr_action_modify_check_is_ttl_modify(sw_action)) {
1946 modify_ttl_sw_action = sw_action;
1951 /* Convert SW action to HW action */
1952 ret = dr_action_modify_sw_to_hw(dmn,
1955 &hw_dst_action_info,
1956 &hw_src_action_info);
1960 /* Due to a HW limitation we cannot modify 2 different L3 types */
1961 if (l3_type && hw_dst_action_info->l3_type &&
1962 hw_dst_action_info->l3_type != l3_type) {
1963 mlx5dr_dbg(dmn, "Action list can't support two different L3 types\n");
1966 if (hw_dst_action_info->l3_type)
1967 l3_type = hw_dst_action_info->l3_type;
1969 /* Due to a HW limitation we cannot modify two different L4 types */
1970 if (l4_type && hw_dst_action_info->l4_type &&
1971 hw_dst_action_info->l4_type != l4_type) {
1972 mlx5dr_dbg(dmn, "Action list can't support two different L4 types\n");
1975 if (hw_dst_action_info->l4_type)
1976 l4_type = hw_dst_action_info->l4_type;
1978 /* HW reads and executes two actions at once this means we
1979 * need to create a gap if two actions access the same field
1981 if ((hw_idx % 2) && (hw_field == hw_dst_action_info->hw_field ||
1982 (hw_src_action_info &&
1983 hw_field == hw_src_action_info->hw_field))) {
1984 /* Check if after gap insertion the total number of HW
1985 * modify actions doesn't exceeds the limit
1988 if (hw_idx >= max_hw_actions) {
1989 mlx5dr_dbg(dmn, "Modify header action number exceeds HW limit\n");
1993 hw_field = hw_dst_action_info->hw_field;
1995 hw_actions[hw_idx] = hw_action;
1999 /* if the resulting HW actions list is empty, add NOP action */
2003 *num_hw_actions = hw_idx;
2008 static int dr_action_create_modify_action(struct mlx5dr_domain *dmn,
2011 struct mlx5dr_action *action)
2020 num_sw_actions = actions_sz / DR_MODIFY_ACTION_SIZE;
2021 max_hw_actions = mlx5dr_icm_pool_chunk_size_to_entries(DR_CHUNK_SIZE_16);
2023 if (num_sw_actions > max_hw_actions) {
2024 mlx5dr_dbg(dmn, "Max number of actions %d exceeds limit %d\n",
2025 num_sw_actions, max_hw_actions);
2029 hw_actions = kcalloc(1, max_hw_actions * DR_MODIFY_ACTION_SIZE, GFP_KERNEL);
2033 ret = dr_actions_convert_modify_header(action,
2041 goto free_hw_actions;
2043 action->rewrite->modify_ttl = modify_ttl;
2044 action->rewrite->data = (u8 *)hw_actions;
2045 action->rewrite->num_of_actions = num_hw_actions;
2047 if (num_hw_actions == 1 &&
2048 dmn->info.caps.sw_format_ver >= MLX5_STEERING_FORMAT_CONNECTX_6DX) {
2049 action->rewrite->single_action_opt = true;
2051 action->rewrite->single_action_opt = false;
2052 ret = mlx5dr_ste_alloc_modify_hdr(action);
2054 goto free_hw_actions;
2064 struct mlx5dr_action *
2065 mlx5dr_action_create_modify_header(struct mlx5dr_domain *dmn,
2070 struct mlx5dr_action *action;
2073 refcount_inc(&dmn->refcount);
2075 if (actions_sz % DR_MODIFY_ACTION_SIZE) {
2076 mlx5dr_dbg(dmn, "Invalid modify actions size provided\n");
2080 action = dr_action_create_generic(DR_ACTION_TYP_MODIFY_HDR);
2084 action->rewrite->dmn = dmn;
2086 ret = dr_action_create_modify_action(dmn,
2091 mlx5dr_dbg(dmn, "Failed creating modify header action %d\n", ret);
2100 refcount_dec(&dmn->refcount);
2104 struct mlx5dr_action *
2105 mlx5dr_action_create_dest_vport(struct mlx5dr_domain *dmn,
2106 u16 vport, u8 vhca_id_valid,
2109 struct mlx5dr_cmd_vport_cap *vport_cap;
2110 struct mlx5dr_domain *vport_dmn;
2111 struct mlx5dr_action *action;
2114 peer_vport = vhca_id_valid && mlx5_core_is_pf(dmn->mdev) &&
2115 (vhca_id != dmn->info.caps.gvmi);
2116 vport_dmn = peer_vport ? xa_load(&dmn->peer_dmn_xa, vhca_id) : dmn;
2118 mlx5dr_dbg(dmn, "No peer vport domain for given vhca_id\n");
2122 if (vport_dmn->type != MLX5DR_DOMAIN_TYPE_FDB) {
2123 mlx5dr_dbg(dmn, "Domain doesn't support vport actions\n");
2127 vport_cap = mlx5dr_domain_get_vport_cap(vport_dmn, vport);
2130 "Failed to get vport 0x%x caps - vport is disabled or invalid\n",
2135 action = dr_action_create_generic(DR_ACTION_TYP_VPORT);
2139 action->vport->dmn = vport_dmn;
2140 action->vport->caps = vport_cap;
2145 struct mlx5dr_action *
2146 mlx5dr_action_create_aso(struct mlx5dr_domain *dmn, u32 obj_id,
2147 u8 dest_reg_id, u8 aso_type,
2148 u8 init_color, u8 meter_id)
2150 struct mlx5dr_action *action;
2152 if (aso_type != MLX5_EXE_ASO_FLOW_METER)
2155 if (init_color > MLX5_FLOW_METER_COLOR_UNDEFINED)
2158 action = dr_action_create_generic(DR_ACTION_TYP_ASO_FLOW_METER);
2162 action->aso->obj_id = obj_id;
2163 action->aso->offset = meter_id;
2164 action->aso->dest_reg_id = dest_reg_id;
2165 action->aso->init_color = init_color;
2166 action->aso->dmn = dmn;
2168 refcount_inc(&dmn->refcount);
2173 u32 mlx5dr_action_get_pkt_reformat_id(struct mlx5dr_action *action)
2175 return action->reformat->id;
2178 int mlx5dr_action_destroy(struct mlx5dr_action *action)
2180 if (WARN_ON_ONCE(refcount_read(&action->refcount) > 1))
2183 switch (action->action_type) {
2184 case DR_ACTION_TYP_FT:
2185 if (action->dest_tbl->is_fw_tbl)
2186 refcount_dec(&action->dest_tbl->fw_tbl.dmn->refcount);
2188 refcount_dec(&action->dest_tbl->tbl->refcount);
2190 if (action->dest_tbl->is_fw_tbl &&
2191 action->dest_tbl->fw_tbl.num_of_ref_actions) {
2192 struct mlx5dr_action **ref_actions;
2195 ref_actions = action->dest_tbl->fw_tbl.ref_actions;
2196 for (i = 0; i < action->dest_tbl->fw_tbl.num_of_ref_actions; i++)
2197 refcount_dec(&ref_actions[i]->refcount);
2201 mlx5dr_fw_destroy_md_tbl(action->dest_tbl->fw_tbl.dmn,
2202 action->dest_tbl->fw_tbl.id,
2203 action->dest_tbl->fw_tbl.group_id);
2206 case DR_ACTION_TYP_TNL_L2_TO_L2:
2207 case DR_ACTION_TYP_REMOVE_HDR:
2208 refcount_dec(&action->reformat->dmn->refcount);
2210 case DR_ACTION_TYP_TNL_L3_TO_L2:
2211 mlx5dr_ste_free_modify_hdr(action);
2212 kfree(action->rewrite->data);
2213 refcount_dec(&action->rewrite->dmn->refcount);
2215 case DR_ACTION_TYP_L2_TO_TNL_L2:
2216 case DR_ACTION_TYP_L2_TO_TNL_L3:
2217 case DR_ACTION_TYP_INSERT_HDR:
2218 mlx5dr_cmd_destroy_reformat_ctx((action->reformat->dmn)->mdev,
2219 action->reformat->id);
2220 refcount_dec(&action->reformat->dmn->refcount);
2222 case DR_ACTION_TYP_MODIFY_HDR:
2223 if (!action->rewrite->single_action_opt)
2224 mlx5dr_ste_free_modify_hdr(action);
2225 kfree(action->rewrite->data);
2226 refcount_dec(&action->rewrite->dmn->refcount);
2228 case DR_ACTION_TYP_SAMPLER:
2229 refcount_dec(&action->sampler->dmn->refcount);
2231 case DR_ACTION_TYP_ASO_FLOW_METER:
2232 refcount_dec(&action->aso->dmn->refcount);
2234 case DR_ACTION_TYP_RANGE:
2235 dr_action_destroy_range_definer(action);
2236 mlx5dr_action_destroy(action->range->miss_tbl_action);
2237 mlx5dr_action_destroy(action->range->hit_tbl_action);