1 /*
2  * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 
33 #include <linux/mlx5/driver.h>
34 #include <linux/mlx5/device.h>
35 #include <linux/mlx5/mlx5_ifc.h>
36 
37 #include "fs_core.h"
38 #include "fs_cmd.h"
39 #include "fs_ft_pool.h"
40 #include "mlx5_core.h"
41 #include "eswitch.h"
42 
43 static int mlx5_cmd_stub_update_root_ft(struct mlx5_flow_root_namespace *ns,
44 					struct mlx5_flow_table *ft,
45 					u32 underlay_qpn,
46 					bool disconnect)
47 {
48 	return 0;
49 }
50 
51 static int mlx5_cmd_stub_create_flow_table(struct mlx5_flow_root_namespace *ns,
52 					   struct mlx5_flow_table *ft,
53 					   unsigned int size,
54 					   struct mlx5_flow_table *next_ft)
55 {
56 	ft->max_fte = size ? roundup_pow_of_two(size) : 1;
57 
58 	return 0;
59 }
60 
61 static int mlx5_cmd_stub_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
62 					    struct mlx5_flow_table *ft)
63 {
64 	return 0;
65 }
66 
67 static int mlx5_cmd_stub_modify_flow_table(struct mlx5_flow_root_namespace *ns,
68 					   struct mlx5_flow_table *ft,
69 					   struct mlx5_flow_table *next_ft)
70 {
71 	return 0;
72 }
73 
74 static int mlx5_cmd_stub_create_flow_group(struct mlx5_flow_root_namespace *ns,
75 					   struct mlx5_flow_table *ft,
76 					   u32 *in,
77 					   struct mlx5_flow_group *fg)
78 {
79 	return 0;
80 }
81 
82 static int mlx5_cmd_stub_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
83 					    struct mlx5_flow_table *ft,
84 					    struct mlx5_flow_group *fg)
85 {
86 	return 0;
87 }
88 
89 static int mlx5_cmd_stub_create_fte(struct mlx5_flow_root_namespace *ns,
90 				    struct mlx5_flow_table *ft,
91 				    struct mlx5_flow_group *group,
92 				    struct fs_fte *fte)
93 {
94 	return 0;
95 }
96 
97 static int mlx5_cmd_stub_update_fte(struct mlx5_flow_root_namespace *ns,
98 				    struct mlx5_flow_table *ft,
99 				    struct mlx5_flow_group *group,
100 				    int modify_mask,
101 				    struct fs_fte *fte)
102 {
103 	return -EOPNOTSUPP;
104 }
105 
106 static int mlx5_cmd_stub_delete_fte(struct mlx5_flow_root_namespace *ns,
107 				    struct mlx5_flow_table *ft,
108 				    struct fs_fte *fte)
109 {
110 	return 0;
111 }
112 
113 static int mlx5_cmd_stub_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
114 					       struct mlx5_pkt_reformat_params *params,
115 					       enum mlx5_flow_namespace_type namespace,
116 					       struct mlx5_pkt_reformat *pkt_reformat)
117 {
118 	return 0;
119 }
120 
121 static void mlx5_cmd_stub_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
122 						  struct mlx5_pkt_reformat *pkt_reformat)
123 {
124 }
125 
126 static int mlx5_cmd_stub_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
127 					     u8 namespace, u8 num_actions,
128 					     void *modify_actions,
129 					     struct mlx5_modify_hdr *modify_hdr)
130 {
131 	return 0;
132 }
133 
134 static void mlx5_cmd_stub_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
135 						struct mlx5_modify_hdr *modify_hdr)
136 {
137 }
138 
139 static int mlx5_cmd_stub_set_peer(struct mlx5_flow_root_namespace *ns,
140 				  struct mlx5_flow_root_namespace *peer_ns)
141 {
142 	return 0;
143 }
144 
145 static int mlx5_cmd_stub_create_ns(struct mlx5_flow_root_namespace *ns)
146 {
147 	return 0;
148 }
149 
150 static int mlx5_cmd_stub_destroy_ns(struct mlx5_flow_root_namespace *ns)
151 {
152 	return 0;
153 }
154 
155 static int mlx5_cmd_set_slave_root_fdb(struct mlx5_core_dev *master,
156 				       struct mlx5_core_dev *slave,
157 				       bool ft_id_valid,
158 				       u32 ft_id)
159 {
160 	u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {};
161 	u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {};
162 	struct mlx5_flow_root_namespace *root;
163 	struct mlx5_flow_namespace *ns;
164 
165 	MLX5_SET(set_flow_table_root_in, in, opcode,
166 		 MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
167 	MLX5_SET(set_flow_table_root_in, in, table_type,
168 		 FS_FT_FDB);
169 	if (ft_id_valid) {
170 		MLX5_SET(set_flow_table_root_in, in,
171 			 table_eswitch_owner_vhca_id_valid, 1);
172 		MLX5_SET(set_flow_table_root_in, in,
173 			 table_eswitch_owner_vhca_id,
174 			 MLX5_CAP_GEN(master, vhca_id));
175 		MLX5_SET(set_flow_table_root_in, in, table_id,
176 			 ft_id);
177 	} else {
178 		ns = mlx5_get_flow_namespace(slave,
179 					     MLX5_FLOW_NAMESPACE_FDB);
180 		root = find_root(&ns->node);
181 		MLX5_SET(set_flow_table_root_in, in, table_id,
182 			 root->root_ft->id);
183 	}
184 
185 	return mlx5_cmd_exec(slave, in, sizeof(in), out, sizeof(out));
186 }
187 
188 static int
189 mlx5_cmd_stub_destroy_match_definer(struct mlx5_flow_root_namespace *ns,
190 				    int definer_id)
191 {
192 	return 0;
193 }
194 
195 static int
196 mlx5_cmd_stub_create_match_definer(struct mlx5_flow_root_namespace *ns,
197 				   u16 format_id, u32 *match_mask)
198 {
199 	return 0;
200 }
201 
202 static int mlx5_cmd_update_root_ft(struct mlx5_flow_root_namespace *ns,
203 				   struct mlx5_flow_table *ft, u32 underlay_qpn,
204 				   bool disconnect)
205 {
206 	u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {};
207 	struct mlx5_core_dev *dev = ns->dev;
208 	int err;
209 
210 	if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) &&
211 	    underlay_qpn == 0)
212 		return 0;
213 
214 	if (ft->type == FS_FT_FDB &&
215 	    mlx5_lag_is_shared_fdb(dev) &&
216 	    !mlx5_lag_is_master(dev))
217 		return 0;
218 
219 	MLX5_SET(set_flow_table_root_in, in, opcode,
220 		 MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
221 	MLX5_SET(set_flow_table_root_in, in, table_type, ft->type);
222 
223 	if (disconnect)
224 		MLX5_SET(set_flow_table_root_in, in, op_mod, 1);
225 	else
226 		MLX5_SET(set_flow_table_root_in, in, table_id, ft->id);
227 
228 	MLX5_SET(set_flow_table_root_in, in, underlay_qpn, underlay_qpn);
229 	MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport);
230 	MLX5_SET(set_flow_table_root_in, in, other_vport,
231 		 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
232 
233 	err = mlx5_cmd_exec_in(dev, set_flow_table_root, in);
234 	if (!err &&
235 	    ft->type == FS_FT_FDB &&
236 	    mlx5_lag_is_shared_fdb(dev) &&
237 	    mlx5_lag_is_master(dev)) {
238 		err = mlx5_cmd_set_slave_root_fdb(dev,
239 						  mlx5_lag_get_peer_mdev(dev),
240 						  !disconnect, (!disconnect) ?
241 						  ft->id : 0);
242 		if (err && !disconnect) {
243 			MLX5_SET(set_flow_table_root_in, in, op_mod, 0);
244 			MLX5_SET(set_flow_table_root_in, in, table_id,
245 				 ns->root_ft->id);
246 			mlx5_cmd_exec_in(dev, set_flow_table_root, in);
247 		}
248 	}
249 
250 	return err;
251 }
252 
253 static int mlx5_cmd_create_flow_table(struct mlx5_flow_root_namespace *ns,
254 				      struct mlx5_flow_table *ft,
255 				      unsigned int size,
256 				      struct mlx5_flow_table *next_ft)
257 {
258 	int en_encap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT);
259 	int en_decap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_DECAP);
260 	int term = !!(ft->flags & MLX5_FLOW_TABLE_TERMINATION);
261 	u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {};
262 	u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {};
263 	struct mlx5_core_dev *dev = ns->dev;
264 	int err;
265 
266 	if (size != POOL_NEXT_SIZE)
267 		size = roundup_pow_of_two(size);
268 	size = mlx5_ft_pool_get_avail_sz(dev, ft->type, size);
269 	if (!size)
270 		return -ENOSPC;
271 
272 	MLX5_SET(create_flow_table_in, in, opcode,
273 		 MLX5_CMD_OP_CREATE_FLOW_TABLE);
274 
275 	MLX5_SET(create_flow_table_in, in, table_type, ft->type);
276 	MLX5_SET(create_flow_table_in, in, flow_table_context.level, ft->level);
277 	MLX5_SET(create_flow_table_in, in, flow_table_context.log_size, size ? ilog2(size) : 0);
278 	MLX5_SET(create_flow_table_in, in, vport_number, ft->vport);
279 	MLX5_SET(create_flow_table_in, in, other_vport,
280 		 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
281 
282 	MLX5_SET(create_flow_table_in, in, flow_table_context.decap_en,
283 		 en_decap);
284 	MLX5_SET(create_flow_table_in, in, flow_table_context.reformat_en,
285 		 en_encap);
286 	MLX5_SET(create_flow_table_in, in, flow_table_context.termination_table,
287 		 term);
288 
289 	switch (ft->op_mod) {
290 	case FS_FT_OP_MOD_NORMAL:
291 		if (next_ft) {
292 			MLX5_SET(create_flow_table_in, in,
293 				 flow_table_context.table_miss_action,
294 				 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
295 			MLX5_SET(create_flow_table_in, in,
296 				 flow_table_context.table_miss_id, next_ft->id);
297 		} else {
298 			MLX5_SET(create_flow_table_in, in,
299 				 flow_table_context.table_miss_action,
300 				 ft->def_miss_action);
301 		}
302 		break;
303 
304 	case FS_FT_OP_MOD_LAG_DEMUX:
305 		MLX5_SET(create_flow_table_in, in, op_mod, 0x1);
306 		if (next_ft)
307 			MLX5_SET(create_flow_table_in, in,
308 				 flow_table_context.lag_master_next_table_id,
309 				 next_ft->id);
310 		break;
311 	}
312 
313 	err = mlx5_cmd_exec_inout(dev, create_flow_table, in, out);
314 	if (!err) {
315 		ft->id = MLX5_GET(create_flow_table_out, out,
316 				  table_id);
317 		ft->max_fte = size;
318 	} else {
319 		mlx5_ft_pool_put_sz(ns->dev, size);
320 	}
321 
322 	return err;
323 }
324 
325 static int mlx5_cmd_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
326 				       struct mlx5_flow_table *ft)
327 {
328 	u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {};
329 	struct mlx5_core_dev *dev = ns->dev;
330 	int err;
331 
332 	MLX5_SET(destroy_flow_table_in, in, opcode,
333 		 MLX5_CMD_OP_DESTROY_FLOW_TABLE);
334 	MLX5_SET(destroy_flow_table_in, in, table_type, ft->type);
335 	MLX5_SET(destroy_flow_table_in, in, table_id, ft->id);
336 	MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport);
337 	MLX5_SET(destroy_flow_table_in, in, other_vport,
338 		 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
339 
340 	err = mlx5_cmd_exec_in(dev, destroy_flow_table, in);
341 	if (!err)
342 		mlx5_ft_pool_put_sz(ns->dev, ft->max_fte);
343 
344 	return err;
345 }
346 
347 static int mlx5_cmd_modify_flow_table(struct mlx5_flow_root_namespace *ns,
348 				      struct mlx5_flow_table *ft,
349 				      struct mlx5_flow_table *next_ft)
350 {
351 	u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {};
352 	struct mlx5_core_dev *dev = ns->dev;
353 
354 	MLX5_SET(modify_flow_table_in, in, opcode,
355 		 MLX5_CMD_OP_MODIFY_FLOW_TABLE);
356 	MLX5_SET(modify_flow_table_in, in, table_type, ft->type);
357 	MLX5_SET(modify_flow_table_in, in, table_id, ft->id);
358 
359 	if (ft->op_mod == FS_FT_OP_MOD_LAG_DEMUX) {
360 		MLX5_SET(modify_flow_table_in, in, modify_field_select,
361 			 MLX5_MODIFY_FLOW_TABLE_LAG_NEXT_TABLE_ID);
362 		if (next_ft) {
363 			MLX5_SET(modify_flow_table_in, in,
364 				 flow_table_context.lag_master_next_table_id, next_ft->id);
365 		} else {
366 			MLX5_SET(modify_flow_table_in, in,
367 				 flow_table_context.lag_master_next_table_id, 0);
368 		}
369 	} else {
370 		MLX5_SET(modify_flow_table_in, in, vport_number, ft->vport);
371 		MLX5_SET(modify_flow_table_in, in, other_vport,
372 			 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
373 		MLX5_SET(modify_flow_table_in, in, modify_field_select,
374 			 MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID);
375 		if (next_ft) {
376 			MLX5_SET(modify_flow_table_in, in,
377 				 flow_table_context.table_miss_action,
378 				 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
379 			MLX5_SET(modify_flow_table_in, in,
380 				 flow_table_context.table_miss_id,
381 				 next_ft->id);
382 		} else {
383 			MLX5_SET(modify_flow_table_in, in,
384 				 flow_table_context.table_miss_action,
385 				 ft->def_miss_action);
386 		}
387 	}
388 
389 	return mlx5_cmd_exec_in(dev, modify_flow_table, in);
390 }
391 
392 static int mlx5_cmd_create_flow_group(struct mlx5_flow_root_namespace *ns,
393 				      struct mlx5_flow_table *ft,
394 				      u32 *in,
395 				      struct mlx5_flow_group *fg)
396 {
397 	u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {};
398 	struct mlx5_core_dev *dev = ns->dev;
399 	int err;
400 
401 	MLX5_SET(create_flow_group_in, in, opcode,
402 		 MLX5_CMD_OP_CREATE_FLOW_GROUP);
403 	MLX5_SET(create_flow_group_in, in, table_type, ft->type);
404 	MLX5_SET(create_flow_group_in, in, table_id, ft->id);
405 	if (ft->vport) {
406 		MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
407 		MLX5_SET(create_flow_group_in, in, other_vport, 1);
408 	}
409 
410 	MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
411 	MLX5_SET(create_flow_group_in, in, other_vport,
412 		 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
413 	err = mlx5_cmd_exec_inout(dev, create_flow_group, in, out);
414 	if (!err)
415 		fg->id = MLX5_GET(create_flow_group_out, out,
416 				  group_id);
417 	return err;
418 }
419 
420 static int mlx5_cmd_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
421 				       struct mlx5_flow_table *ft,
422 				       struct mlx5_flow_group *fg)
423 {
424 	u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {};
425 	struct mlx5_core_dev *dev = ns->dev;
426 
427 	MLX5_SET(destroy_flow_group_in, in, opcode,
428 		 MLX5_CMD_OP_DESTROY_FLOW_GROUP);
429 	MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
430 	MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
431 	MLX5_SET(destroy_flow_group_in, in, group_id, fg->id);
432 	MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport);
433 	MLX5_SET(destroy_flow_group_in, in, other_vport,
434 		 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
435 	return mlx5_cmd_exec_in(dev, destroy_flow_group, in);
436 }
437 
438 static int mlx5_set_extended_dest(struct mlx5_core_dev *dev,
439 				  struct fs_fte *fte, bool *extended_dest)
440 {
441 	int fw_log_max_fdb_encap_uplink =
442 		MLX5_CAP_ESW(dev, log_max_fdb_encap_uplink);
443 	int num_fwd_destinations = 0;
444 	struct mlx5_flow_rule *dst;
445 	int num_encap = 0;
446 
447 	*extended_dest = false;
448 	if (!(fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
449 		return 0;
450 
451 	list_for_each_entry(dst, &fte->node.children, node.list) {
452 		if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
453 			continue;
454 		if ((dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_VPORT ||
455 		     dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_UPLINK) &&
456 		    dst->dest_attr.vport.flags & MLX5_FLOW_DEST_VPORT_REFORMAT_ID)
457 			num_encap++;
458 		num_fwd_destinations++;
459 	}
460 	if (num_fwd_destinations > 1 && num_encap > 0)
461 		*extended_dest = true;
462 
463 	if (*extended_dest && !fw_log_max_fdb_encap_uplink) {
464 		mlx5_core_warn(dev, "FW does not support extended destination");
465 		return -EOPNOTSUPP;
466 	}
467 	if (num_encap > (1 << fw_log_max_fdb_encap_uplink)) {
468 		mlx5_core_warn(dev, "FW does not support more than %d encaps",
469 			       1 << fw_log_max_fdb_encap_uplink);
470 		return -EOPNOTSUPP;
471 	}
472 
473 	return 0;
474 }
475 static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
476 			    int opmod, int modify_mask,
477 			    struct mlx5_flow_table *ft,
478 			    unsigned group_id,
479 			    struct fs_fte *fte)
480 {
481 	u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0};
482 	bool extended_dest = false;
483 	struct mlx5_flow_rule *dst;
484 	void *in_flow_context, *vlan;
485 	void *in_match_value;
486 	unsigned int inlen;
487 	int dst_cnt_size;
488 	void *in_dests;
489 	u32 *in;
490 	int err;
491 
492 	if (mlx5_set_extended_dest(dev, fte, &extended_dest))
493 		return -EOPNOTSUPP;
494 
495 	if (!extended_dest)
496 		dst_cnt_size = MLX5_ST_SZ_BYTES(dest_format_struct);
497 	else
498 		dst_cnt_size = MLX5_ST_SZ_BYTES(extended_dest_format);
499 
500 	inlen = MLX5_ST_SZ_BYTES(set_fte_in) + fte->dests_size * dst_cnt_size;
501 	in = kvzalloc(inlen, GFP_KERNEL);
502 	if (!in)
503 		return -ENOMEM;
504 
505 	MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY);
506 	MLX5_SET(set_fte_in, in, op_mod, opmod);
507 	MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask);
508 	MLX5_SET(set_fte_in, in, table_type, ft->type);
509 	MLX5_SET(set_fte_in, in, table_id,   ft->id);
510 	MLX5_SET(set_fte_in, in, flow_index, fte->index);
511 	MLX5_SET(set_fte_in, in, ignore_flow_level,
512 		 !!(fte->action.flags & FLOW_ACT_IGNORE_FLOW_LEVEL));
513 
514 	MLX5_SET(set_fte_in, in, vport_number, ft->vport);
515 	MLX5_SET(set_fte_in, in, other_vport,
516 		 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
517 
518 	in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
519 	MLX5_SET(flow_context, in_flow_context, group_id, group_id);
520 
521 	MLX5_SET(flow_context, in_flow_context, flow_tag,
522 		 fte->flow_context.flow_tag);
523 	MLX5_SET(flow_context, in_flow_context, flow_source,
524 		 fte->flow_context.flow_source);
525 
526 	MLX5_SET(flow_context, in_flow_context, extended_destination,
527 		 extended_dest);
528 	if (extended_dest) {
529 		u32 action;
530 
531 		action = fte->action.action &
532 			~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
533 		MLX5_SET(flow_context, in_flow_context, action, action);
534 	} else {
535 		MLX5_SET(flow_context, in_flow_context, action,
536 			 fte->action.action);
537 		if (fte->action.pkt_reformat)
538 			MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
539 				 fte->action.pkt_reformat->id);
540 	}
541 	if (fte->action.modify_hdr)
542 		MLX5_SET(flow_context, in_flow_context, modify_header_id,
543 			 fte->action.modify_hdr->id);
544 
545 	MLX5_SET(flow_context, in_flow_context, ipsec_obj_id, fte->action.ipsec_obj_id);
546 
547 	vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan);
548 
549 	MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[0].ethtype);
550 	MLX5_SET(vlan, vlan, vid, fte->action.vlan[0].vid);
551 	MLX5_SET(vlan, vlan, prio, fte->action.vlan[0].prio);
552 
553 	vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan_2);
554 
555 	MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[1].ethtype);
556 	MLX5_SET(vlan, vlan, vid, fte->action.vlan[1].vid);
557 	MLX5_SET(vlan, vlan, prio, fte->action.vlan[1].prio);
558 
559 	in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
560 				      match_value);
561 	memcpy(in_match_value, &fte->val, sizeof(fte->val));
562 
563 	in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
564 	if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
565 		int list_size = 0;
566 
567 		list_for_each_entry(dst, &fte->node.children, node.list) {
568 			unsigned int id, type = dst->dest_attr.type;
569 
570 			if (type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
571 				continue;
572 
573 			switch (type) {
574 			case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM:
575 				id = dst->dest_attr.ft_num;
576 				type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
577 				break;
578 			case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE:
579 				id = dst->dest_attr.ft->id;
580 				break;
581 			case MLX5_FLOW_DESTINATION_TYPE_UPLINK:
582 			case MLX5_FLOW_DESTINATION_TYPE_VPORT:
583 				MLX5_SET(dest_format_struct, in_dests,
584 					 destination_eswitch_owner_vhca_id_valid,
585 					 !!(dst->dest_attr.vport.flags &
586 					    MLX5_FLOW_DEST_VPORT_VHCA_ID));
587 				MLX5_SET(dest_format_struct, in_dests,
588 					 destination_eswitch_owner_vhca_id,
589 					 dst->dest_attr.vport.vhca_id);
590 				if (type == MLX5_FLOW_DESTINATION_TYPE_UPLINK) {
591 					/* destination_id is reserved */
592 					id = 0;
593 					break;
594 				}
595 				id = dst->dest_attr.vport.num;
596 				if (extended_dest &&
597 				    dst->dest_attr.vport.pkt_reformat) {
598 					MLX5_SET(dest_format_struct, in_dests,
599 						 packet_reformat,
600 						 !!(dst->dest_attr.vport.flags &
601 						    MLX5_FLOW_DEST_VPORT_REFORMAT_ID));
602 					MLX5_SET(extended_dest_format, in_dests,
603 						 packet_reformat_id,
604 						 dst->dest_attr.vport.pkt_reformat->id);
605 				}
606 				break;
607 			case MLX5_FLOW_DESTINATION_TYPE_FLOW_SAMPLER:
608 				id = dst->dest_attr.sampler_id;
609 				break;
610 			default:
611 				id = dst->dest_attr.tir_num;
612 			}
613 
614 			MLX5_SET(dest_format_struct, in_dests, destination_type,
615 				 type);
616 			MLX5_SET(dest_format_struct, in_dests, destination_id, id);
617 			in_dests += dst_cnt_size;
618 			list_size++;
619 		}
620 
621 		MLX5_SET(flow_context, in_flow_context, destination_list_size,
622 			 list_size);
623 	}
624 
625 	if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
626 		int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
627 					log_max_flow_counter,
628 					ft->type));
629 		int list_size = 0;
630 
631 		list_for_each_entry(dst, &fte->node.children, node.list) {
632 			if (dst->dest_attr.type !=
633 			    MLX5_FLOW_DESTINATION_TYPE_COUNTER)
634 				continue;
635 
636 			MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
637 				 dst->dest_attr.counter_id);
638 			in_dests += dst_cnt_size;
639 			list_size++;
640 		}
641 		if (list_size > max_list_size) {
642 			err = -EINVAL;
643 			goto err_out;
644 		}
645 
646 		MLX5_SET(flow_context, in_flow_context, flow_counter_list_size,
647 			 list_size);
648 	}
649 
650 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
651 err_out:
652 	kvfree(in);
653 	return err;
654 }
655 
656 static int mlx5_cmd_create_fte(struct mlx5_flow_root_namespace *ns,
657 			       struct mlx5_flow_table *ft,
658 			       struct mlx5_flow_group *group,
659 			       struct fs_fte *fte)
660 {
661 	struct mlx5_core_dev *dev = ns->dev;
662 	unsigned int group_id = group->id;
663 
664 	return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
665 }
666 
667 static int mlx5_cmd_update_fte(struct mlx5_flow_root_namespace *ns,
668 			       struct mlx5_flow_table *ft,
669 			       struct mlx5_flow_group *fg,
670 			       int modify_mask,
671 			       struct fs_fte *fte)
672 {
673 	int opmod;
674 	struct mlx5_core_dev *dev = ns->dev;
675 	int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
676 						flow_table_properties_nic_receive.
677 						flow_modify_en);
678 	if (!atomic_mod_cap)
679 		return -EOPNOTSUPP;
680 	opmod = 1;
681 
682 	return	mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, fg->id, fte);
683 }
684 
685 static int mlx5_cmd_delete_fte(struct mlx5_flow_root_namespace *ns,
686 			       struct mlx5_flow_table *ft,
687 			       struct fs_fte *fte)
688 {
689 	u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {};
690 	struct mlx5_core_dev *dev = ns->dev;
691 
692 	MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY);
693 	MLX5_SET(delete_fte_in, in, table_type, ft->type);
694 	MLX5_SET(delete_fte_in, in, table_id, ft->id);
695 	MLX5_SET(delete_fte_in, in, flow_index, fte->index);
696 	MLX5_SET(delete_fte_in, in, vport_number, ft->vport);
697 	MLX5_SET(delete_fte_in, in, other_vport,
698 		 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
699 
700 	return mlx5_cmd_exec_in(dev, delete_fte, in);
701 }
702 
703 int mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev,
704 			   enum mlx5_fc_bulk_alloc_bitmask alloc_bitmask,
705 			   u32 *id)
706 {
707 	u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {};
708 	u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {};
709 	int err;
710 
711 	MLX5_SET(alloc_flow_counter_in, in, opcode,
712 		 MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
713 	MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk, alloc_bitmask);
714 
715 	err = mlx5_cmd_exec_inout(dev, alloc_flow_counter, in, out);
716 	if (!err)
717 		*id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
718 	return err;
719 }
720 
721 int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id)
722 {
723 	return mlx5_cmd_fc_bulk_alloc(dev, 0, id);
724 }
725 
726 int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id)
727 {
728 	u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {};
729 
730 	MLX5_SET(dealloc_flow_counter_in, in, opcode,
731 		 MLX5_CMD_OP_DEALLOC_FLOW_COUNTER);
732 	MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id);
733 	return mlx5_cmd_exec_in(dev, dealloc_flow_counter, in);
734 }
735 
736 int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id,
737 		      u64 *packets, u64 *bytes)
738 {
739 	u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
740 		MLX5_ST_SZ_BYTES(traffic_counter)] = {};
741 	u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
742 	void *stats;
743 	int err = 0;
744 
745 	MLX5_SET(query_flow_counter_in, in, opcode,
746 		 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
747 	MLX5_SET(query_flow_counter_in, in, op_mod, 0);
748 	MLX5_SET(query_flow_counter_in, in, flow_counter_id, id);
749 	err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
750 	if (err)
751 		return err;
752 
753 	stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics);
754 	*packets = MLX5_GET64(traffic_counter, stats, packets);
755 	*bytes = MLX5_GET64(traffic_counter, stats, octets);
756 	return 0;
757 }
758 
759 int mlx5_cmd_fc_get_bulk_query_out_len(int bulk_len)
760 {
761 	return MLX5_ST_SZ_BYTES(query_flow_counter_out) +
762 		MLX5_ST_SZ_BYTES(traffic_counter) * bulk_len;
763 }
764 
765 int mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, u32 base_id, int bulk_len,
766 			   u32 *out)
767 {
768 	int outlen = mlx5_cmd_fc_get_bulk_query_out_len(bulk_len);
769 	u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
770 
771 	MLX5_SET(query_flow_counter_in, in, opcode,
772 		 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
773 	MLX5_SET(query_flow_counter_in, in, flow_counter_id, base_id);
774 	MLX5_SET(query_flow_counter_in, in, num_of_counters, bulk_len);
775 	return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
776 }
777 
778 static int mlx5_cmd_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
779 					  struct mlx5_pkt_reformat_params *params,
780 					  enum mlx5_flow_namespace_type namespace,
781 					  struct mlx5_pkt_reformat *pkt_reformat)
782 {
783 	u32 out[MLX5_ST_SZ_DW(alloc_packet_reformat_context_out)] = {};
784 	struct mlx5_core_dev *dev = ns->dev;
785 	void *packet_reformat_context_in;
786 	int max_encap_size;
787 	void *reformat;
788 	int inlen;
789 	int err;
790 	u32 *in;
791 
792 	if (namespace == MLX5_FLOW_NAMESPACE_FDB ||
793 	    namespace == MLX5_FLOW_NAMESPACE_FDB_BYPASS)
794 		max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
795 	else
796 		max_encap_size = MLX5_CAP_FLOWTABLE(dev, max_encap_header_size);
797 
798 	if (params->size > max_encap_size) {
799 		mlx5_core_warn(dev, "encap size %zd too big, max supported is %d\n",
800 			       params->size, max_encap_size);
801 		return -EINVAL;
802 	}
803 
804 	in = kzalloc(MLX5_ST_SZ_BYTES(alloc_packet_reformat_context_in) +
805 		     params->size, GFP_KERNEL);
806 	if (!in)
807 		return -ENOMEM;
808 
809 	packet_reformat_context_in = MLX5_ADDR_OF(alloc_packet_reformat_context_in,
810 						  in, packet_reformat_context);
811 	reformat = MLX5_ADDR_OF(packet_reformat_context_in,
812 				packet_reformat_context_in,
813 				reformat_data);
814 	inlen = reformat - (void *)in + params->size;
815 
816 	MLX5_SET(alloc_packet_reformat_context_in, in, opcode,
817 		 MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT);
818 	MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
819 		 reformat_data_size, params->size);
820 	MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
821 		 reformat_type, params->type);
822 	MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
823 		 reformat_param_0, params->param_0);
824 	MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
825 		 reformat_param_1, params->param_1);
826 	if (params->data && params->size)
827 		memcpy(reformat, params->data, params->size);
828 
829 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
830 
831 	pkt_reformat->id = MLX5_GET(alloc_packet_reformat_context_out,
832 				    out, packet_reformat_id);
833 	kfree(in);
834 	return err;
835 }
836 
837 static void mlx5_cmd_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
838 					     struct mlx5_pkt_reformat *pkt_reformat)
839 {
840 	u32 in[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_in)] = {};
841 	struct mlx5_core_dev *dev = ns->dev;
842 
843 	MLX5_SET(dealloc_packet_reformat_context_in, in, opcode,
844 		 MLX5_CMD_OP_DEALLOC_PACKET_REFORMAT_CONTEXT);
845 	MLX5_SET(dealloc_packet_reformat_context_in, in, packet_reformat_id,
846 		 pkt_reformat->id);
847 
848 	mlx5_cmd_exec_in(dev, dealloc_packet_reformat_context, in);
849 }
850 
851 static int mlx5_cmd_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
852 					u8 namespace, u8 num_actions,
853 					void *modify_actions,
854 					struct mlx5_modify_hdr *modify_hdr)
855 {
856 	u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)] = {};
857 	int max_actions, actions_size, inlen, err;
858 	struct mlx5_core_dev *dev = ns->dev;
859 	void *actions_in;
860 	u8 table_type;
861 	u32 *in;
862 
863 	switch (namespace) {
864 	case MLX5_FLOW_NAMESPACE_FDB:
865 	case MLX5_FLOW_NAMESPACE_FDB_BYPASS:
866 		max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, max_modify_header_actions);
867 		table_type = FS_FT_FDB;
868 		break;
869 	case MLX5_FLOW_NAMESPACE_KERNEL:
870 	case MLX5_FLOW_NAMESPACE_BYPASS:
871 		max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions);
872 		table_type = FS_FT_NIC_RX;
873 		break;
874 	case MLX5_FLOW_NAMESPACE_EGRESS:
875 #ifdef CONFIG_MLX5_IPSEC
876 	case MLX5_FLOW_NAMESPACE_EGRESS_KERNEL:
877 #endif
878 		max_actions = MLX5_CAP_FLOWTABLE_NIC_TX(dev, max_modify_header_actions);
879 		table_type = FS_FT_NIC_TX;
880 		break;
881 	case MLX5_FLOW_NAMESPACE_ESW_INGRESS:
882 		max_actions = MLX5_CAP_ESW_INGRESS_ACL(dev, max_modify_header_actions);
883 		table_type = FS_FT_ESW_INGRESS_ACL;
884 		break;
885 	case MLX5_FLOW_NAMESPACE_RDMA_TX:
886 		max_actions = MLX5_CAP_FLOWTABLE_RDMA_TX(dev, max_modify_header_actions);
887 		table_type = FS_FT_RDMA_TX;
888 		break;
889 	default:
890 		return -EOPNOTSUPP;
891 	}
892 
893 	if (num_actions > max_actions) {
894 		mlx5_core_warn(dev, "too many modify header actions %d, max supported %d\n",
895 			       num_actions, max_actions);
896 		return -EOPNOTSUPP;
897 	}
898 
899 	actions_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) * num_actions;
900 	inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size;
901 
902 	in = kzalloc(inlen, GFP_KERNEL);
903 	if (!in)
904 		return -ENOMEM;
905 
906 	MLX5_SET(alloc_modify_header_context_in, in, opcode,
907 		 MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT);
908 	MLX5_SET(alloc_modify_header_context_in, in, table_type, table_type);
909 	MLX5_SET(alloc_modify_header_context_in, in, num_of_actions, num_actions);
910 
911 	actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions);
912 	memcpy(actions_in, modify_actions, actions_size);
913 
914 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
915 
916 	modify_hdr->id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
917 	kfree(in);
918 	return err;
919 }
920 
921 static void mlx5_cmd_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
922 					   struct mlx5_modify_hdr *modify_hdr)
923 {
924 	u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)] = {};
925 	struct mlx5_core_dev *dev = ns->dev;
926 
927 	MLX5_SET(dealloc_modify_header_context_in, in, opcode,
928 		 MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT);
929 	MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id,
930 		 modify_hdr->id);
931 
932 	mlx5_cmd_exec_in(dev, dealloc_modify_header_context, in);
933 }
934 
935 static int mlx5_cmd_destroy_match_definer(struct mlx5_flow_root_namespace *ns,
936 					  int definer_id)
937 {
938 	u32 in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {};
939 	u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)];
940 
941 	MLX5_SET(general_obj_in_cmd_hdr, in, opcode,
942 		 MLX5_CMD_OP_DESTROY_GENERAL_OBJECT);
943 	MLX5_SET(general_obj_in_cmd_hdr, in, obj_type,
944 		 MLX5_OBJ_TYPE_MATCH_DEFINER);
945 	MLX5_SET(general_obj_in_cmd_hdr, in, obj_id, definer_id);
946 
947 	return mlx5_cmd_exec(ns->dev, in, sizeof(in), out, sizeof(out));
948 }
949 
950 static int mlx5_cmd_create_match_definer(struct mlx5_flow_root_namespace *ns,
951 					 u16 format_id, u32 *match_mask)
952 {
953 	u32 out[MLX5_ST_SZ_DW(create_match_definer_out)] = {};
954 	u32 in[MLX5_ST_SZ_DW(create_match_definer_in)] = {};
955 	struct mlx5_core_dev *dev = ns->dev;
956 	void *ptr;
957 	int err;
958 
959 	MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.opcode,
960 		 MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
961 	MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.obj_type,
962 		 MLX5_OBJ_TYPE_MATCH_DEFINER);
963 
964 	ptr = MLX5_ADDR_OF(create_match_definer_in, in, obj_context);
965 	MLX5_SET(match_definer, ptr, format_id, format_id);
966 
967 	ptr = MLX5_ADDR_OF(match_definer, ptr, match_mask);
968 	memcpy(ptr, match_mask, MLX5_FLD_SZ_BYTES(match_definer, match_mask));
969 
970 	err = mlx5_cmd_exec_inout(dev, create_match_definer, in, out);
971 	return err ? err : MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
972 }
973 
974 static const struct mlx5_flow_cmds mlx5_flow_cmds = {
975 	.create_flow_table = mlx5_cmd_create_flow_table,
976 	.destroy_flow_table = mlx5_cmd_destroy_flow_table,
977 	.modify_flow_table = mlx5_cmd_modify_flow_table,
978 	.create_flow_group = mlx5_cmd_create_flow_group,
979 	.destroy_flow_group = mlx5_cmd_destroy_flow_group,
980 	.create_fte = mlx5_cmd_create_fte,
981 	.update_fte = mlx5_cmd_update_fte,
982 	.delete_fte = mlx5_cmd_delete_fte,
983 	.update_root_ft = mlx5_cmd_update_root_ft,
984 	.packet_reformat_alloc = mlx5_cmd_packet_reformat_alloc,
985 	.packet_reformat_dealloc = mlx5_cmd_packet_reformat_dealloc,
986 	.modify_header_alloc = mlx5_cmd_modify_header_alloc,
987 	.modify_header_dealloc = mlx5_cmd_modify_header_dealloc,
988 	.create_match_definer = mlx5_cmd_create_match_definer,
989 	.destroy_match_definer = mlx5_cmd_destroy_match_definer,
990 	.set_peer = mlx5_cmd_stub_set_peer,
991 	.create_ns = mlx5_cmd_stub_create_ns,
992 	.destroy_ns = mlx5_cmd_stub_destroy_ns,
993 };
994 
995 static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = {
996 	.create_flow_table = mlx5_cmd_stub_create_flow_table,
997 	.destroy_flow_table = mlx5_cmd_stub_destroy_flow_table,
998 	.modify_flow_table = mlx5_cmd_stub_modify_flow_table,
999 	.create_flow_group = mlx5_cmd_stub_create_flow_group,
1000 	.destroy_flow_group = mlx5_cmd_stub_destroy_flow_group,
1001 	.create_fte = mlx5_cmd_stub_create_fte,
1002 	.update_fte = mlx5_cmd_stub_update_fte,
1003 	.delete_fte = mlx5_cmd_stub_delete_fte,
1004 	.update_root_ft = mlx5_cmd_stub_update_root_ft,
1005 	.packet_reformat_alloc = mlx5_cmd_stub_packet_reformat_alloc,
1006 	.packet_reformat_dealloc = mlx5_cmd_stub_packet_reformat_dealloc,
1007 	.modify_header_alloc = mlx5_cmd_stub_modify_header_alloc,
1008 	.modify_header_dealloc = mlx5_cmd_stub_modify_header_dealloc,
1009 	.create_match_definer = mlx5_cmd_stub_create_match_definer,
1010 	.destroy_match_definer = mlx5_cmd_stub_destroy_match_definer,
1011 	.set_peer = mlx5_cmd_stub_set_peer,
1012 	.create_ns = mlx5_cmd_stub_create_ns,
1013 	.destroy_ns = mlx5_cmd_stub_destroy_ns,
1014 };
1015 
1016 const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void)
1017 {
1018 	return &mlx5_flow_cmds;
1019 }
1020 
1021 static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_stub_cmds(void)
1022 {
1023 	return &mlx5_flow_cmd_stubs;
1024 }
1025 
1026 const struct mlx5_flow_cmds *mlx5_fs_cmd_get_default(enum fs_flow_table_type type)
1027 {
1028 	switch (type) {
1029 	case FS_FT_NIC_RX:
1030 	case FS_FT_ESW_EGRESS_ACL:
1031 	case FS_FT_ESW_INGRESS_ACL:
1032 	case FS_FT_FDB:
1033 	case FS_FT_SNIFFER_RX:
1034 	case FS_FT_SNIFFER_TX:
1035 	case FS_FT_NIC_TX:
1036 	case FS_FT_RDMA_RX:
1037 	case FS_FT_RDMA_TX:
1038 	case FS_FT_PORT_SEL:
1039 		return mlx5_fs_cmd_get_fw_cmds();
1040 	default:
1041 		return mlx5_fs_cmd_get_stub_cmds();
1042 	}
1043 }
1044