net/mlx5: Add MACsec offload Tx command support
[linux-block.git] / drivers / net / ethernet / mellanox / mlx5 / core / fs_cmd.c
CommitLineData
26a81453
MG
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"
4a98544d 39#include "fs_ft_pool.h"
26a81453 40#include "mlx5_core.h"
c9f1b073 41#include "eswitch.h"
26a81453 42
ae288a48 43static int mlx5_cmd_stub_update_root_ft(struct mlx5_flow_root_namespace *ns,
af76c501
MB
44 struct mlx5_flow_table *ft,
45 u32 underlay_qpn,
46 bool disconnect)
47{
48 return 0;
49}
50
ae288a48
MG
51static int mlx5_cmd_stub_create_flow_table(struct mlx5_flow_root_namespace *ns,
52 struct mlx5_flow_table *ft,
b0bb369e 53 struct mlx5_flow_table_attr *ft_attr,
ae288a48 54 struct mlx5_flow_table *next_ft)
af76c501 55{
b0bb369e
MB
56 int max_fte = ft_attr->max_fte;
57
58 ft->max_fte = max_fte ? roundup_pow_of_two(max_fte) : 1;
04745afb 59
af76c501
MB
60 return 0;
61}
62
ae288a48 63static int mlx5_cmd_stub_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
af76c501
MB
64 struct mlx5_flow_table *ft)
65{
66 return 0;
67}
68
ae288a48 69static int mlx5_cmd_stub_modify_flow_table(struct mlx5_flow_root_namespace *ns,
af76c501
MB
70 struct mlx5_flow_table *ft,
71 struct mlx5_flow_table *next_ft)
72{
73 return 0;
74}
75
ae288a48 76static int mlx5_cmd_stub_create_flow_group(struct mlx5_flow_root_namespace *ns,
af76c501
MB
77 struct mlx5_flow_table *ft,
78 u32 *in,
ae288a48 79 struct mlx5_flow_group *fg)
af76c501
MB
80{
81 return 0;
82}
83
ae288a48 84static int mlx5_cmd_stub_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
af76c501 85 struct mlx5_flow_table *ft,
ae288a48 86 struct mlx5_flow_group *fg)
af76c501
MB
87{
88 return 0;
89}
90
ae288a48 91static int mlx5_cmd_stub_create_fte(struct mlx5_flow_root_namespace *ns,
af76c501
MB
92 struct mlx5_flow_table *ft,
93 struct mlx5_flow_group *group,
94 struct fs_fte *fte)
95{
96 return 0;
97}
98
ae288a48 99static int mlx5_cmd_stub_update_fte(struct mlx5_flow_root_namespace *ns,
af76c501 100 struct mlx5_flow_table *ft,
ae288a48 101 struct mlx5_flow_group *group,
af76c501
MB
102 int modify_mask,
103 struct fs_fte *fte)
104{
105 return -EOPNOTSUPP;
106}
107
ae288a48 108static int mlx5_cmd_stub_delete_fte(struct mlx5_flow_root_namespace *ns,
af76c501 109 struct mlx5_flow_table *ft,
e810bf5e 110 struct fs_fte *fte)
af76c501
MB
111{
112 return 0;
113}
114
2b688ea5 115static int mlx5_cmd_stub_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
3f3f05ab 116 struct mlx5_pkt_reformat_params *params,
2b688ea5
MG
117 enum mlx5_flow_namespace_type namespace,
118 struct mlx5_pkt_reformat *pkt_reformat)
119{
120 return 0;
121}
122
123static void mlx5_cmd_stub_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
124 struct mlx5_pkt_reformat *pkt_reformat)
125{
126}
127
128static int mlx5_cmd_stub_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
129 u8 namespace, u8 num_actions,
130 void *modify_actions,
131 struct mlx5_modify_hdr *modify_hdr)
132{
133 return 0;
134}
135
136static void mlx5_cmd_stub_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
137 struct mlx5_modify_hdr *modify_hdr)
138{
139}
140
6a48faee
MG
141static int mlx5_cmd_stub_set_peer(struct mlx5_flow_root_namespace *ns,
142 struct mlx5_flow_root_namespace *peer_ns)
143{
144 return 0;
145}
146
147static int mlx5_cmd_stub_create_ns(struct mlx5_flow_root_namespace *ns)
148{
149 return 0;
150}
151
152static int mlx5_cmd_stub_destroy_ns(struct mlx5_flow_root_namespace *ns)
153{
154 return 0;
155}
156
8348b71c
DC
157static u32 mlx5_cmd_stub_get_capabilities(struct mlx5_flow_root_namespace *ns,
158 enum fs_flow_table_type ft_type)
159{
160 return 0;
161}
162
db202995
MB
163static int mlx5_cmd_set_slave_root_fdb(struct mlx5_core_dev *master,
164 struct mlx5_core_dev *slave,
165 bool ft_id_valid,
166 u32 ft_id)
167{
168 u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {};
169 u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {};
170 struct mlx5_flow_root_namespace *root;
171 struct mlx5_flow_namespace *ns;
172
173 MLX5_SET(set_flow_table_root_in, in, opcode,
174 MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
175 MLX5_SET(set_flow_table_root_in, in, table_type,
176 FS_FT_FDB);
177 if (ft_id_valid) {
178 MLX5_SET(set_flow_table_root_in, in,
179 table_eswitch_owner_vhca_id_valid, 1);
180 MLX5_SET(set_flow_table_root_in, in,
181 table_eswitch_owner_vhca_id,
182 MLX5_CAP_GEN(master, vhca_id));
183 MLX5_SET(set_flow_table_root_in, in, table_id,
184 ft_id);
185 } else {
186 ns = mlx5_get_flow_namespace(slave,
187 MLX5_FLOW_NAMESPACE_FDB);
188 root = find_root(&ns->node);
189 MLX5_SET(set_flow_table_root_in, in, table_id,
190 root->root_ft->id);
191 }
192
193 return mlx5_cmd_exec(slave, in, sizeof(in), out, sizeof(out));
194}
195
e7e2519e
MG
196static int
197mlx5_cmd_stub_destroy_match_definer(struct mlx5_flow_root_namespace *ns,
198 int definer_id)
199{
200 return 0;
201}
202
203static int
204mlx5_cmd_stub_create_match_definer(struct mlx5_flow_root_namespace *ns,
205 u16 format_id, u32 *match_mask)
206{
207 return 0;
208}
209
ae288a48 210static int mlx5_cmd_update_root_ft(struct mlx5_flow_root_namespace *ns,
af76c501
MB
211 struct mlx5_flow_table *ft, u32 underlay_qpn,
212 bool disconnect)
2cc43b49 213{
31a0956e 214 u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {};
ae288a48 215 struct mlx5_core_dev *dev = ns->dev;
db202995 216 int err;
2cc43b49 217
b3ba5149 218 if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) &&
50854114 219 underlay_qpn == 0)
b3ba5149
ES
220 return 0;
221
db202995
MB
222 if (ft->type == FS_FT_FDB &&
223 mlx5_lag_is_shared_fdb(dev) &&
224 !mlx5_lag_is_master(dev))
225 return 0;
226
2cc43b49
MG
227 MLX5_SET(set_flow_table_root_in, in, opcode,
228 MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
229 MLX5_SET(set_flow_table_root_in, in, table_type, ft->type);
dae37456 230
31a0956e 231 if (disconnect)
dae37456 232 MLX5_SET(set_flow_table_root_in, in, op_mod, 1);
31a0956e 233 else
dae37456 234 MLX5_SET(set_flow_table_root_in, in, table_id, ft->id);
dae37456 235
50854114 236 MLX5_SET(set_flow_table_root_in, in, underlay_qpn, underlay_qpn);
617b860c
PP
237 MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport);
238 MLX5_SET(set_flow_table_root_in, in, other_vport,
239 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
2cc43b49 240
db202995
MB
241 err = mlx5_cmd_exec_in(dev, set_flow_table_root, in);
242 if (!err &&
243 ft->type == FS_FT_FDB &&
244 mlx5_lag_is_shared_fdb(dev) &&
245 mlx5_lag_is_master(dev)) {
246 err = mlx5_cmd_set_slave_root_fdb(dev,
247 mlx5_lag_get_peer_mdev(dev),
248 !disconnect, (!disconnect) ?
249 ft->id : 0);
250 if (err && !disconnect) {
251 MLX5_SET(set_flow_table_root_in, in, op_mod, 0);
252 MLX5_SET(set_flow_table_root_in, in, table_id,
253 ns->root_ft->id);
254 mlx5_cmd_exec_in(dev, set_flow_table_root, in);
255 }
256 }
257
258 return err;
2cc43b49
MG
259}
260
ae288a48
MG
261static int mlx5_cmd_create_flow_table(struct mlx5_flow_root_namespace *ns,
262 struct mlx5_flow_table *ft,
b0bb369e 263 struct mlx5_flow_table_attr *ft_attr,
ae288a48 264 struct mlx5_flow_table *next_ft)
26a81453 265{
ae288a48
MG
266 int en_encap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT);
267 int en_decap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_DECAP);
c6d4e45d 268 int term = !!(ft->flags & MLX5_FLOW_TABLE_TERMINATION);
31a0956e
LR
269 u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {};
270 u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {};
ae288a48 271 struct mlx5_core_dev *dev = ns->dev;
b0bb369e 272 unsigned int size;
26a81453
MG
273 int err;
274
b0bb369e
MB
275 if (ft_attr->max_fte != POOL_NEXT_SIZE)
276 size = roundup_pow_of_two(ft_attr->max_fte);
277 size = mlx5_ft_pool_get_avail_sz(dev, ft->type, ft_attr->max_fte);
4a98544d
PB
278 if (!size)
279 return -ENOSPC;
04745afb 280
26a81453
MG
281 MLX5_SET(create_flow_table_in, in, opcode,
282 MLX5_CMD_OP_CREATE_FLOW_TABLE);
283
b0bb369e 284 MLX5_SET(create_flow_table_in, in, uid, ft_attr->uid);
ae288a48
MG
285 MLX5_SET(create_flow_table_in, in, table_type, ft->type);
286 MLX5_SET(create_flow_table_in, in, flow_table_context.level, ft->level);
4a98544d 287 MLX5_SET(create_flow_table_in, in, flow_table_context.log_size, size ? ilog2(size) : 0);
617b860c
PP
288 MLX5_SET(create_flow_table_in, in, vport_number, ft->vport);
289 MLX5_SET(create_flow_table_in, in, other_vport,
290 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
26a81453 291
0c90e9c6 292 MLX5_SET(create_flow_table_in, in, flow_table_context.decap_en,
61444b45 293 en_decap);
60786f09 294 MLX5_SET(create_flow_table_in, in, flow_table_context.reformat_en,
61444b45 295 en_encap);
c6d4e45d
EB
296 MLX5_SET(create_flow_table_in, in, flow_table_context.termination_table,
297 term);
c9f1b073 298
ae288a48 299 switch (ft->op_mod) {
aaff1bea
AH
300 case FS_FT_OP_MOD_NORMAL:
301 if (next_ft) {
0c90e9c6 302 MLX5_SET(create_flow_table_in, in,
f6f7d6b5
MG
303 flow_table_context.table_miss_action,
304 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
0c90e9c6
MG
305 MLX5_SET(create_flow_table_in, in,
306 flow_table_context.table_miss_id, next_ft->id);
f6f7d6b5
MG
307 } else {
308 MLX5_SET(create_flow_table_in, in,
309 flow_table_context.table_miss_action,
f66ad830 310 ft->def_miss_action);
aaff1bea
AH
311 }
312 break;
313
314 case FS_FT_OP_MOD_LAG_DEMUX:
315 MLX5_SET(create_flow_table_in, in, op_mod, 0x1);
316 if (next_ft)
0c90e9c6
MG
317 MLX5_SET(create_flow_table_in, in,
318 flow_table_context.lag_master_next_table_id,
aaff1bea
AH
319 next_ft->id);
320 break;
321 }
322
31a0956e 323 err = mlx5_cmd_exec_inout(dev, create_flow_table, in, out);
4a98544d 324 if (!err) {
ae288a48
MG
325 ft->id = MLX5_GET(create_flow_table_out, out,
326 table_id);
4a98544d
PB
327 ft->max_fte = size;
328 } else {
329 mlx5_ft_pool_put_sz(ns->dev, size);
330 }
331
26a81453
MG
332 return err;
333}
334
ae288a48 335static int mlx5_cmd_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
af76c501 336 struct mlx5_flow_table *ft)
26a81453 337{
31a0956e 338 u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {};
ae288a48 339 struct mlx5_core_dev *dev = ns->dev;
4a98544d 340 int err;
26a81453
MG
341
342 MLX5_SET(destroy_flow_table_in, in, opcode,
343 MLX5_CMD_OP_DESTROY_FLOW_TABLE);
344 MLX5_SET(destroy_flow_table_in, in, table_type, ft->type);
345 MLX5_SET(destroy_flow_table_in, in, table_id, ft->id);
617b860c
PP
346 MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport);
347 MLX5_SET(destroy_flow_table_in, in, other_vport,
348 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
26a81453 349
4a98544d
PB
350 err = mlx5_cmd_exec_in(dev, destroy_flow_table, in);
351 if (!err)
352 mlx5_ft_pool_put_sz(ns->dev, ft->max_fte);
353
354 return err;
26a81453
MG
355}
356
ae288a48 357static int mlx5_cmd_modify_flow_table(struct mlx5_flow_root_namespace *ns,
af76c501
MB
358 struct mlx5_flow_table *ft,
359 struct mlx5_flow_table *next_ft)
34a40e68 360{
31a0956e 361 u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {};
ae288a48 362 struct mlx5_core_dev *dev = ns->dev;
34a40e68
MG
363
364 MLX5_SET(modify_flow_table_in, in, opcode,
365 MLX5_CMD_OP_MODIFY_FLOW_TABLE);
366 MLX5_SET(modify_flow_table_in, in, table_type, ft->type);
367 MLX5_SET(modify_flow_table_in, in, table_id, ft->id);
aaff1bea
AH
368
369 if (ft->op_mod == FS_FT_OP_MOD_LAG_DEMUX) {
370 MLX5_SET(modify_flow_table_in, in, modify_field_select,
371 MLX5_MODIFY_FLOW_TABLE_LAG_NEXT_TABLE_ID);
372 if (next_ft) {
373 MLX5_SET(modify_flow_table_in, in,
0c90e9c6 374 flow_table_context.lag_master_next_table_id, next_ft->id);
aaff1bea
AH
375 } else {
376 MLX5_SET(modify_flow_table_in, in,
0c90e9c6 377 flow_table_context.lag_master_next_table_id, 0);
aaff1bea 378 }
34a40e68 379 } else {
617b860c
PP
380 MLX5_SET(modify_flow_table_in, in, vport_number, ft->vport);
381 MLX5_SET(modify_flow_table_in, in, other_vport,
382 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
aaff1bea
AH
383 MLX5_SET(modify_flow_table_in, in, modify_field_select,
384 MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID);
385 if (next_ft) {
0c90e9c6 386 MLX5_SET(modify_flow_table_in, in,
f6f7d6b5
MG
387 flow_table_context.table_miss_action,
388 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
0c90e9c6
MG
389 MLX5_SET(modify_flow_table_in, in,
390 flow_table_context.table_miss_id,
aaff1bea
AH
391 next_ft->id);
392 } else {
0c90e9c6 393 MLX5_SET(modify_flow_table_in, in,
f6f7d6b5 394 flow_table_context.table_miss_action,
f66ad830 395 ft->def_miss_action);
aaff1bea 396 }
34a40e68
MG
397 }
398
31a0956e 399 return mlx5_cmd_exec_in(dev, modify_flow_table, in);
34a40e68
MG
400}
401
ae288a48 402static int mlx5_cmd_create_flow_group(struct mlx5_flow_root_namespace *ns,
af76c501
MB
403 struct mlx5_flow_table *ft,
404 u32 *in,
ae288a48 405 struct mlx5_flow_group *fg)
26a81453 406{
31a0956e 407 u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {};
ae288a48 408 struct mlx5_core_dev *dev = ns->dev;
26a81453
MG
409 int err;
410
26a81453
MG
411 MLX5_SET(create_flow_group_in, in, opcode,
412 MLX5_CMD_OP_CREATE_FLOW_GROUP);
413 MLX5_SET(create_flow_group_in, in, table_type, ft->type);
414 MLX5_SET(create_flow_group_in, in, table_id, ft->id);
efdc810b
MHY
415 if (ft->vport) {
416 MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
417 MLX5_SET(create_flow_group_in, in, other_vport, 1);
418 }
26a81453 419
617b860c
PP
420 MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
421 MLX5_SET(create_flow_group_in, in, other_vport,
422 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
31a0956e 423 err = mlx5_cmd_exec_inout(dev, create_flow_group, in, out);
26a81453 424 if (!err)
ae288a48
MG
425 fg->id = MLX5_GET(create_flow_group_out, out,
426 group_id);
26a81453
MG
427 return err;
428}
429
ae288a48 430static int mlx5_cmd_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
af76c501 431 struct mlx5_flow_table *ft,
ae288a48 432 struct mlx5_flow_group *fg)
26a81453 433{
31a0956e 434 u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {};
ae288a48 435 struct mlx5_core_dev *dev = ns->dev;
26a81453
MG
436
437 MLX5_SET(destroy_flow_group_in, in, opcode,
438 MLX5_CMD_OP_DESTROY_FLOW_GROUP);
439 MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
440 MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
ae288a48 441 MLX5_SET(destroy_flow_group_in, in, group_id, fg->id);
617b860c
PP
442 MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport);
443 MLX5_SET(destroy_flow_group_in, in, other_vport,
444 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
31a0956e 445 return mlx5_cmd_exec_in(dev, destroy_flow_group, in);
26a81453
MG
446}
447
a2c6162b
EB
448static int mlx5_set_extended_dest(struct mlx5_core_dev *dev,
449 struct fs_fte *fte, bool *extended_dest)
450{
451 int fw_log_max_fdb_encap_uplink =
452 MLX5_CAP_ESW(dev, log_max_fdb_encap_uplink);
453 int num_fwd_destinations = 0;
454 struct mlx5_flow_rule *dst;
455 int num_encap = 0;
456
457 *extended_dest = false;
458 if (!(fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
459 return 0;
460
461 list_for_each_entry(dst, &fte->node.children, node.list) {
6510bc0d
MB
462 if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER ||
463 dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_NONE)
a2c6162b 464 continue;
e3a0f40b
YK
465 if ((dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_VPORT ||
466 dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_UPLINK) &&
a2c6162b
EB
467 dst->dest_attr.vport.flags & MLX5_FLOW_DEST_VPORT_REFORMAT_ID)
468 num_encap++;
469 num_fwd_destinations++;
470 }
471 if (num_fwd_destinations > 1 && num_encap > 0)
472 *extended_dest = true;
473
474 if (*extended_dest && !fw_log_max_fdb_encap_uplink) {
475 mlx5_core_warn(dev, "FW does not support extended destination");
476 return -EOPNOTSUPP;
477 }
478 if (num_encap > (1 << fw_log_max_fdb_encap_uplink)) {
479 mlx5_core_warn(dev, "FW does not support more than %d encaps",
480 1 << fw_log_max_fdb_encap_uplink);
481 return -EOPNOTSUPP;
482 }
483
484 return 0;
485}
91707779
JL
486
487static void
488mlx5_cmd_set_fte_flow_meter(struct fs_fte *fte, void *in_flow_context)
489{
490 void *exe_aso_ctrl;
491 void *execute_aso;
492
493 execute_aso = MLX5_ADDR_OF(flow_context, in_flow_context,
494 execute_aso[0]);
495 MLX5_SET(execute_aso, execute_aso, valid, 1);
496 MLX5_SET(execute_aso, execute_aso, aso_object_id,
497 fte->action.exe_aso.object_id);
498
499 exe_aso_ctrl = MLX5_ADDR_OF(execute_aso, execute_aso, exe_aso_ctrl);
500 MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, return_reg_id,
501 fte->action.exe_aso.return_reg_id);
502 MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, aso_type,
503 fte->action.exe_aso.type);
504 MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, init_color,
505 fte->action.exe_aso.flow_meter.init_color);
506 MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, meter_id,
507 fte->action.exe_aso.flow_meter.meter_idx);
508}
509
26a81453
MG
510static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
511 int opmod, int modify_mask,
512 struct mlx5_flow_table *ft,
513 unsigned group_id,
514 struct fs_fte *fte)
515{
c4f287c4 516 u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0};
a2c6162b 517 bool extended_dest = false;
26a81453 518 struct mlx5_flow_rule *dst;
0c06897a 519 void *in_flow_context, *vlan;
26a81453 520 void *in_match_value;
a2c6162b
EB
521 unsigned int inlen;
522 int dst_cnt_size;
26a81453
MG
523 void *in_dests;
524 u32 *in;
525 int err;
526
a2c6162b
EB
527 if (mlx5_set_extended_dest(dev, fte, &extended_dest))
528 return -EOPNOTSUPP;
529
530 if (!extended_dest)
531 dst_cnt_size = MLX5_ST_SZ_BYTES(dest_format_struct);
532 else
533 dst_cnt_size = MLX5_ST_SZ_BYTES(extended_dest_format);
534
535 inlen = MLX5_ST_SZ_BYTES(set_fte_in) + fte->dests_size * dst_cnt_size;
1b9a07ee
LR
536 in = kvzalloc(inlen, GFP_KERNEL);
537 if (!in)
26a81453 538 return -ENOMEM;
26a81453
MG
539
540 MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY);
541 MLX5_SET(set_fte_in, in, op_mod, opmod);
542 MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask);
543 MLX5_SET(set_fte_in, in, table_type, ft->type);
544 MLX5_SET(set_fte_in, in, table_id, ft->id);
545 MLX5_SET(set_fte_in, in, flow_index, fte->index);
ff189b43
PB
546 MLX5_SET(set_fte_in, in, ignore_flow_level,
547 !!(fte->action.flags & FLOW_ACT_IGNORE_FLOW_LEVEL));
548
617b860c
PP
549 MLX5_SET(set_fte_in, in, vport_number, ft->vport);
550 MLX5_SET(set_fte_in, in, other_vport,
551 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
26a81453
MG
552
553 in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
554 MLX5_SET(flow_context, in_flow_context, group_id, group_id);
0c06897a 555
bb0ee7dc
JL
556 MLX5_SET(flow_context, in_flow_context, flow_tag,
557 fte->flow_context.flow_tag);
8d212ff0
JL
558 MLX5_SET(flow_context, in_flow_context, flow_source,
559 fte->flow_context.flow_source);
560
a2c6162b
EB
561 MLX5_SET(flow_context, in_flow_context, extended_destination,
562 extended_dest);
563 if (extended_dest) {
564 u32 action;
565
566 action = fte->action.action &
567 ~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
568 MLX5_SET(flow_context, in_flow_context, action, action);
569 } else {
570 MLX5_SET(flow_context, in_flow_context, action,
571 fte->action.action);
2b688ea5
MG
572 if (fte->action.pkt_reformat)
573 MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
574 fte->action.pkt_reformat->id);
a2c6162b 575 }
2b688ea5
MG
576 if (fte->action.modify_hdr)
577 MLX5_SET(flow_context, in_flow_context, modify_header_id,
578 fte->action.modify_hdr->id);
0c06897a 579
e227ee99
LN
580 MLX5_SET(flow_context, in_flow_context, encrypt_decrypt_type,
581 fte->action.crypto.type);
582 MLX5_SET(flow_context, in_flow_context, encrypt_decrypt_obj_id,
583 fte->action.crypto.obj_id);
5e466345 584
0c06897a
OG
585 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan);
586
8da6fe2a
JL
587 MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[0].ethtype);
588 MLX5_SET(vlan, vlan, vid, fte->action.vlan[0].vid);
589 MLX5_SET(vlan, vlan, prio, fte->action.vlan[0].prio);
590
591 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan_2);
592
593 MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[1].ethtype);
594 MLX5_SET(vlan, vlan, vid, fte->action.vlan[1].vid);
595 MLX5_SET(vlan, vlan, prio, fte->action.vlan[1].prio);
0c06897a 596
26a81453
MG
597 in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
598 match_value);
667cb65a 599 memcpy(in_match_value, &fte->val, sizeof(fte->val));
26a81453 600
bd5251db 601 in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
d2ec6a35 602 if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
bd5251db
AV
603 int list_size = 0;
604
60ab4584 605 list_for_each_entry(dst, &fte->node.children, node.list) {
d639af62
MB
606 enum mlx5_flow_destination_type type = dst->dest_attr.type;
607 enum mlx5_ifc_flow_destination_type ifc_type;
608 unsigned int id;
60ab4584 609
664000b6 610 if (type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
bd5251db
AV
611 continue;
612
664000b6 613 switch (type) {
6510bc0d
MB
614 case MLX5_FLOW_DESTINATION_TYPE_NONE:
615 continue;
664000b6
YH
616 case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM:
617 id = dst->dest_attr.ft_num;
d639af62 618 ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_FLOW_TABLE;
664000b6
YH
619 break;
620 case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE:
60ab4584 621 id = dst->dest_attr.ft->id;
d639af62 622 ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_FLOW_TABLE;
664000b6 623 break;
58a606db 624 case MLX5_FLOW_DESTINATION_TYPE_UPLINK:
664000b6 625 case MLX5_FLOW_DESTINATION_TYPE_VPORT:
b17f7fc1
SK
626 MLX5_SET(dest_format_struct, in_dests,
627 destination_eswitch_owner_vhca_id_valid,
aa39c2c0
EB
628 !!(dst->dest_attr.vport.flags &
629 MLX5_FLOW_DEST_VPORT_VHCA_ID));
b17f7fc1
SK
630 MLX5_SET(dest_format_struct, in_dests,
631 destination_eswitch_owner_vhca_id,
632 dst->dest_attr.vport.vhca_id);
58a606db
MG
633 if (type == MLX5_FLOW_DESTINATION_TYPE_UPLINK) {
634 /* destination_id is reserved */
635 id = 0;
d639af62 636 ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_UPLINK;
58a606db
MG
637 break;
638 }
d639af62 639 ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_VPORT;
58a606db 640 id = dst->dest_attr.vport.num;
0fd79b1e
EB
641 if (extended_dest &&
642 dst->dest_attr.vport.pkt_reformat) {
a2c6162b
EB
643 MLX5_SET(dest_format_struct, in_dests,
644 packet_reformat,
645 !!(dst->dest_attr.vport.flags &
646 MLX5_FLOW_DEST_VPORT_REFORMAT_ID));
647 MLX5_SET(extended_dest_format, in_dests,
648 packet_reformat_id,
2b688ea5 649 dst->dest_attr.vport.pkt_reformat->id);
a2c6162b 650 }
664000b6 651 break;
38730630
CM
652 case MLX5_FLOW_DESTINATION_TYPE_FLOW_SAMPLER:
653 id = dst->dest_attr.sampler_id;
d639af62 654 ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_FLOW_SAMPLER;
38730630 655 break;
664000b6 656 default:
60ab4584 657 id = dst->dest_attr.tir_num;
d639af62 658 ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_TIR;
60ab4584 659 }
664000b6
YH
660
661 MLX5_SET(dest_format_struct, in_dests, destination_type,
d639af62 662 ifc_type);
60ab4584 663 MLX5_SET(dest_format_struct, in_dests, destination_id, id);
a2c6162b 664 in_dests += dst_cnt_size;
bd5251db
AV
665 list_size++;
666 }
667
668 MLX5_SET(flow_context, in_flow_context, destination_list_size,
669 list_size);
670 }
671
d2ec6a35 672 if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
16f1c5bb
RS
673 int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
674 log_max_flow_counter,
675 ft->type));
bd5251db
AV
676 int list_size = 0;
677
678 list_for_each_entry(dst, &fte->node.children, node.list) {
679 if (dst->dest_attr.type !=
680 MLX5_FLOW_DESTINATION_TYPE_COUNTER)
681 continue;
682
683 MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
171c7625 684 dst->dest_attr.counter_id);
a2c6162b 685 in_dests += dst_cnt_size;
bd5251db 686 list_size++;
60ab4584 687 }
16f1c5bb
RS
688 if (list_size > max_list_size) {
689 err = -EINVAL;
690 goto err_out;
691 }
bd5251db
AV
692
693 MLX5_SET(flow_context, in_flow_context, flow_counter_list_size,
694 list_size);
26a81453 695 }
bd5251db 696
91707779
JL
697 if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_EXECUTE_ASO) {
698 if (fte->action.exe_aso.type == MLX5_EXE_ASO_FLOW_METER) {
699 mlx5_cmd_set_fte_flow_meter(fte, in_flow_context);
700 } else {
701 err = -EOPNOTSUPP;
702 goto err_out;
703 }
704 }
705
c4f287c4 706 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
16f1c5bb 707err_out:
26a81453 708 kvfree(in);
26a81453
MG
709 return err;
710}
711
ae288a48 712static int mlx5_cmd_create_fte(struct mlx5_flow_root_namespace *ns,
af76c501
MB
713 struct mlx5_flow_table *ft,
714 struct mlx5_flow_group *group,
715 struct fs_fte *fte)
26a81453 716{
ae288a48 717 struct mlx5_core_dev *dev = ns->dev;
af76c501
MB
718 unsigned int group_id = group->id;
719
c4f287c4 720 return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
26a81453
MG
721}
722
ae288a48 723static int mlx5_cmd_update_fte(struct mlx5_flow_root_namespace *ns,
af76c501 724 struct mlx5_flow_table *ft,
ae288a48 725 struct mlx5_flow_group *fg,
af76c501
MB
726 int modify_mask,
727 struct fs_fte *fte)
26a81453
MG
728{
729 int opmod;
ae288a48 730 struct mlx5_core_dev *dev = ns->dev;
26a81453
MG
731 int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
732 flow_table_properties_nic_receive.
733 flow_modify_en);
734 if (!atomic_mod_cap)
9eb78923 735 return -EOPNOTSUPP;
26a81453 736 opmod = 1;
26a81453 737
ae288a48 738 return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, fg->id, fte);
26a81453
MG
739}
740
ae288a48 741static int mlx5_cmd_delete_fte(struct mlx5_flow_root_namespace *ns,
af76c501 742 struct mlx5_flow_table *ft,
e810bf5e 743 struct fs_fte *fte)
26a81453 744{
31a0956e 745 u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {};
ae288a48 746 struct mlx5_core_dev *dev = ns->dev;
26a81453
MG
747
748 MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY);
749 MLX5_SET(delete_fte_in, in, table_type, ft->type);
750 MLX5_SET(delete_fte_in, in, table_id, ft->id);
e810bf5e 751 MLX5_SET(delete_fte_in, in, flow_index, fte->index);
617b860c
PP
752 MLX5_SET(delete_fte_in, in, vport_number, ft->vport);
753 MLX5_SET(delete_fte_in, in, other_vport,
754 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
26a81453 755
31a0956e 756 return mlx5_cmd_exec_in(dev, delete_fte, in);
26a81453 757}
9dc0b289 758
8536a6bf
GT
759int mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev,
760 enum mlx5_fc_bulk_alloc_bitmask alloc_bitmask,
761 u32 *id)
9dc0b289 762{
31a0956e
LR
763 u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {};
764 u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {};
9dc0b289
AV
765 int err;
766
9dc0b289
AV
767 MLX5_SET(alloc_flow_counter_in, in, opcode,
768 MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
8536a6bf 769 MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk, alloc_bitmask);
9dc0b289 770
31a0956e 771 err = mlx5_cmd_exec_inout(dev, alloc_flow_counter, in, out);
c4f287c4
SM
772 if (!err)
773 *id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
774 return err;
9dc0b289
AV
775}
776
8536a6bf
GT
777int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id)
778{
779 return mlx5_cmd_fc_bulk_alloc(dev, 0, id);
780}
781
a8ffcc74 782int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id)
9dc0b289 783{
31a0956e 784 u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {};
9dc0b289
AV
785
786 MLX5_SET(dealloc_flow_counter_in, in, opcode,
787 MLX5_CMD_OP_DEALLOC_FLOW_COUNTER);
788 MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id);
31a0956e 789 return mlx5_cmd_exec_in(dev, dealloc_flow_counter, in);
9dc0b289
AV
790}
791
a8ffcc74 792int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id,
9dc0b289
AV
793 u64 *packets, u64 *bytes)
794{
795 u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
31a0956e
LR
796 MLX5_ST_SZ_BYTES(traffic_counter)] = {};
797 u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
9dc0b289
AV
798 void *stats;
799 int err = 0;
800
9dc0b289
AV
801 MLX5_SET(query_flow_counter_in, in, opcode,
802 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
803 MLX5_SET(query_flow_counter_in, in, op_mod, 0);
804 MLX5_SET(query_flow_counter_in, in, flow_counter_id, id);
c4f287c4 805 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
9dc0b289
AV
806 if (err)
807 return err;
808
809 stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics);
810 *packets = MLX5_GET64(traffic_counter, stats, packets);
811 *bytes = MLX5_GET64(traffic_counter, stats, octets);
9dc0b289
AV
812 return 0;
813}
a351a1b0 814
6f06e04b 815int mlx5_cmd_fc_get_bulk_query_out_len(int bulk_len)
a351a1b0 816{
6f06e04b
GT
817 return MLX5_ST_SZ_BYTES(query_flow_counter_out) +
818 MLX5_ST_SZ_BYTES(traffic_counter) * bulk_len;
a351a1b0
AV
819}
820
6f06e04b
GT
821int mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, u32 base_id, int bulk_len,
822 u32 *out)
a351a1b0 823{
6f06e04b 824 int outlen = mlx5_cmd_fc_get_bulk_query_out_len(bulk_len);
31a0956e 825 u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
a351a1b0
AV
826
827 MLX5_SET(query_flow_counter_in, in, opcode,
828 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
6f06e04b
GT
829 MLX5_SET(query_flow_counter_in, in, flow_counter_id, base_id);
830 MLX5_SET(query_flow_counter_in, in, num_of_counters, bulk_len);
831 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
a351a1b0 832}
575ddf58 833
2b688ea5 834static int mlx5_cmd_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
3f3f05ab 835 struct mlx5_pkt_reformat_params *params,
2b688ea5
MG
836 enum mlx5_flow_namespace_type namespace,
837 struct mlx5_pkt_reformat *pkt_reformat)
575ddf58 838{
31a0956e 839 u32 out[MLX5_ST_SZ_DW(alloc_packet_reformat_context_out)] = {};
2b688ea5 840 struct mlx5_core_dev *dev = ns->dev;
60786f09 841 void *packet_reformat_context_in;
31ca3648 842 int max_encap_size;
60786f09 843 void *reformat;
43f93839 844 int inlen;
575ddf58 845 int err;
43f93839 846 u32 *in;
575ddf58 847
22c3f2f5
MG
848 if (namespace == MLX5_FLOW_NAMESPACE_FDB ||
849 namespace == MLX5_FLOW_NAMESPACE_FDB_BYPASS)
31ca3648
MB
850 max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
851 else
852 max_encap_size = MLX5_CAP_FLOWTABLE(dev, max_encap_header_size);
853
3f3f05ab 854 if (params->size > max_encap_size) {
073ff3c8 855 mlx5_core_warn(dev, "encap size %zd too big, max supported is %d\n",
3f3f05ab 856 params->size, max_encap_size);
575ddf58 857 return -EINVAL;
073ff3c8 858 }
575ddf58 859
3f3f05ab
YK
860 in = kzalloc(MLX5_ST_SZ_BYTES(alloc_packet_reformat_context_in) +
861 params->size, GFP_KERNEL);
43f93839
HHZ
862 if (!in)
863 return -ENOMEM;
864
60786f09
MB
865 packet_reformat_context_in = MLX5_ADDR_OF(alloc_packet_reformat_context_in,
866 in, packet_reformat_context);
867 reformat = MLX5_ADDR_OF(packet_reformat_context_in,
868 packet_reformat_context_in,
869 reformat_data);
3f3f05ab 870 inlen = reformat - (void *)in + params->size;
43f93839 871
60786f09
MB
872 MLX5_SET(alloc_packet_reformat_context_in, in, opcode,
873 MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT);
874 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
3f3f05ab 875 reformat_data_size, params->size);
60786f09 876 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
3f3f05ab
YK
877 reformat_type, params->type);
878 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
879 reformat_param_0, params->param_0);
880 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
881 reformat_param_1, params->param_1);
882 if (params->data && params->size)
883 memcpy(reformat, params->data, params->size);
575ddf58 884
575ddf58
IL
885 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
886
2b688ea5
MG
887 pkt_reformat->id = MLX5_GET(alloc_packet_reformat_context_out,
888 out, packet_reformat_id);
43f93839 889 kfree(in);
575ddf58
IL
890 return err;
891}
892
2b688ea5
MG
893static void mlx5_cmd_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
894 struct mlx5_pkt_reformat *pkt_reformat)
575ddf58 895{
31a0956e 896 u32 in[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_in)] = {};
2b688ea5 897 struct mlx5_core_dev *dev = ns->dev;
575ddf58 898
60786f09
MB
899 MLX5_SET(dealloc_packet_reformat_context_in, in, opcode,
900 MLX5_CMD_OP_DEALLOC_PACKET_REFORMAT_CONTEXT);
901 MLX5_SET(dealloc_packet_reformat_context_in, in, packet_reformat_id,
2b688ea5 902 pkt_reformat->id);
575ddf58 903
31a0956e 904 mlx5_cmd_exec_in(dev, dealloc_packet_reformat_context, in);
575ddf58 905}
2de24fed 906
2b688ea5
MG
907static int mlx5_cmd_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
908 u8 namespace, u8 num_actions,
909 void *modify_actions,
910 struct mlx5_modify_hdr *modify_hdr)
2de24fed 911{
31a0956e 912 u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)] = {};
2de24fed 913 int max_actions, actions_size, inlen, err;
2b688ea5 914 struct mlx5_core_dev *dev = ns->dev;
2de24fed
OG
915 void *actions_in;
916 u8 table_type;
917 u32 *in;
918
919 switch (namespace) {
920 case MLX5_FLOW_NAMESPACE_FDB:
22c3f2f5 921 case MLX5_FLOW_NAMESPACE_FDB_BYPASS:
2de24fed
OG
922 max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, max_modify_header_actions);
923 table_type = FS_FT_FDB;
924 break;
925 case MLX5_FLOW_NAMESPACE_KERNEL:
c3c062f8 926 case MLX5_FLOW_NAMESPACE_BYPASS:
2de24fed
OG
927 max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions);
928 table_type = FS_FT_NIC_RX;
929 break;
c3c062f8 930 case MLX5_FLOW_NAMESPACE_EGRESS:
ee92e4f1 931 case MLX5_FLOW_NAMESPACE_EGRESS_KERNEL:
c3c062f8
MB
932 max_actions = MLX5_CAP_FLOWTABLE_NIC_TX(dev, max_modify_header_actions);
933 table_type = FS_FT_NIC_TX;
934 break;
84b0d6a7
JL
935 case MLX5_FLOW_NAMESPACE_ESW_INGRESS:
936 max_actions = MLX5_CAP_ESW_INGRESS_ACL(dev, max_modify_header_actions);
937 table_type = FS_FT_ESW_INGRESS_ACL;
938 break;
ecf814e0
MG
939 case MLX5_FLOW_NAMESPACE_RDMA_TX:
940 max_actions = MLX5_CAP_FLOWTABLE_RDMA_TX(dev, max_modify_header_actions);
941 table_type = FS_FT_RDMA_TX;
942 break;
2de24fed
OG
943 default:
944 return -EOPNOTSUPP;
945 }
946
947 if (num_actions > max_actions) {
948 mlx5_core_warn(dev, "too many modify header actions %d, max supported %d\n",
949 num_actions, max_actions);
950 return -EOPNOTSUPP;
951 }
952
d65dbedf 953 actions_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) * num_actions;
2de24fed
OG
954 inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size;
955
956 in = kzalloc(inlen, GFP_KERNEL);
957 if (!in)
958 return -ENOMEM;
959
960 MLX5_SET(alloc_modify_header_context_in, in, opcode,
961 MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT);
962 MLX5_SET(alloc_modify_header_context_in, in, table_type, table_type);
963 MLX5_SET(alloc_modify_header_context_in, in, num_of_actions, num_actions);
964
965 actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions);
966 memcpy(actions_in, modify_actions, actions_size);
967
2de24fed
OG
968 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
969
2b688ea5 970 modify_hdr->id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
2de24fed
OG
971 kfree(in);
972 return err;
973}
974
2b688ea5
MG
975static void mlx5_cmd_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
976 struct mlx5_modify_hdr *modify_hdr)
2de24fed 977{
31a0956e 978 u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)] = {};
2b688ea5 979 struct mlx5_core_dev *dev = ns->dev;
2de24fed 980
2de24fed
OG
981 MLX5_SET(dealloc_modify_header_context_in, in, opcode,
982 MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT);
983 MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id,
2b688ea5 984 modify_hdr->id);
2de24fed 985
31a0956e 986 mlx5_cmd_exec_in(dev, dealloc_modify_header_context, in);
2de24fed 987}
af76c501 988
e7e2519e
MG
989static int mlx5_cmd_destroy_match_definer(struct mlx5_flow_root_namespace *ns,
990 int definer_id)
991{
992 u32 in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {};
993 u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)];
994
995 MLX5_SET(general_obj_in_cmd_hdr, in, opcode,
996 MLX5_CMD_OP_DESTROY_GENERAL_OBJECT);
997 MLX5_SET(general_obj_in_cmd_hdr, in, obj_type,
998 MLX5_OBJ_TYPE_MATCH_DEFINER);
999 MLX5_SET(general_obj_in_cmd_hdr, in, obj_id, definer_id);
1000
1001 return mlx5_cmd_exec(ns->dev, in, sizeof(in), out, sizeof(out));
1002}
1003
1004static int mlx5_cmd_create_match_definer(struct mlx5_flow_root_namespace *ns,
1005 u16 format_id, u32 *match_mask)
1006{
1007 u32 out[MLX5_ST_SZ_DW(create_match_definer_out)] = {};
1008 u32 in[MLX5_ST_SZ_DW(create_match_definer_in)] = {};
1009 struct mlx5_core_dev *dev = ns->dev;
1010 void *ptr;
1011 int err;
1012
1013 MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.opcode,
1014 MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
1015 MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.obj_type,
1016 MLX5_OBJ_TYPE_MATCH_DEFINER);
1017
1018 ptr = MLX5_ADDR_OF(create_match_definer_in, in, obj_context);
1019 MLX5_SET(match_definer, ptr, format_id, format_id);
1020
1021 ptr = MLX5_ADDR_OF(match_definer, ptr, match_mask);
1022 memcpy(ptr, match_mask, MLX5_FLD_SZ_BYTES(match_definer, match_mask));
1023
1024 err = mlx5_cmd_exec_inout(dev, create_match_definer, in, out);
1025 return err ? err : MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
1026}
1027
8348b71c
DC
1028static u32 mlx5_cmd_get_capabilities(struct mlx5_flow_root_namespace *ns,
1029 enum fs_flow_table_type ft_type)
1030{
1031 return 0;
1032}
1033
af76c501
MB
1034static const struct mlx5_flow_cmds mlx5_flow_cmds = {
1035 .create_flow_table = mlx5_cmd_create_flow_table,
1036 .destroy_flow_table = mlx5_cmd_destroy_flow_table,
1037 .modify_flow_table = mlx5_cmd_modify_flow_table,
1038 .create_flow_group = mlx5_cmd_create_flow_group,
1039 .destroy_flow_group = mlx5_cmd_destroy_flow_group,
1040 .create_fte = mlx5_cmd_create_fte,
1041 .update_fte = mlx5_cmd_update_fte,
1042 .delete_fte = mlx5_cmd_delete_fte,
1043 .update_root_ft = mlx5_cmd_update_root_ft,
2b688ea5
MG
1044 .packet_reformat_alloc = mlx5_cmd_packet_reformat_alloc,
1045 .packet_reformat_dealloc = mlx5_cmd_packet_reformat_dealloc,
1046 .modify_header_alloc = mlx5_cmd_modify_header_alloc,
6a48faee 1047 .modify_header_dealloc = mlx5_cmd_modify_header_dealloc,
e7e2519e
MG
1048 .create_match_definer = mlx5_cmd_create_match_definer,
1049 .destroy_match_definer = mlx5_cmd_destroy_match_definer,
6a48faee
MG
1050 .set_peer = mlx5_cmd_stub_set_peer,
1051 .create_ns = mlx5_cmd_stub_create_ns,
1052 .destroy_ns = mlx5_cmd_stub_destroy_ns,
8348b71c 1053 .get_capabilities = mlx5_cmd_get_capabilities,
af76c501
MB
1054};
1055
1056static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = {
1057 .create_flow_table = mlx5_cmd_stub_create_flow_table,
1058 .destroy_flow_table = mlx5_cmd_stub_destroy_flow_table,
1059 .modify_flow_table = mlx5_cmd_stub_modify_flow_table,
1060 .create_flow_group = mlx5_cmd_stub_create_flow_group,
1061 .destroy_flow_group = mlx5_cmd_stub_destroy_flow_group,
1062 .create_fte = mlx5_cmd_stub_create_fte,
1063 .update_fte = mlx5_cmd_stub_update_fte,
1064 .delete_fte = mlx5_cmd_stub_delete_fte,
1065 .update_root_ft = mlx5_cmd_stub_update_root_ft,
2b688ea5
MG
1066 .packet_reformat_alloc = mlx5_cmd_stub_packet_reformat_alloc,
1067 .packet_reformat_dealloc = mlx5_cmd_stub_packet_reformat_dealloc,
1068 .modify_header_alloc = mlx5_cmd_stub_modify_header_alloc,
6a48faee 1069 .modify_header_dealloc = mlx5_cmd_stub_modify_header_dealloc,
e7e2519e
MG
1070 .create_match_definer = mlx5_cmd_stub_create_match_definer,
1071 .destroy_match_definer = mlx5_cmd_stub_destroy_match_definer,
6a48faee
MG
1072 .set_peer = mlx5_cmd_stub_set_peer,
1073 .create_ns = mlx5_cmd_stub_create_ns,
1074 .destroy_ns = mlx5_cmd_stub_destroy_ns,
8348b71c 1075 .get_capabilities = mlx5_cmd_stub_get_capabilities,
af76c501
MB
1076};
1077
6a48faee 1078const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void)
af76c501
MB
1079{
1080 return &mlx5_flow_cmds;
1081}
1082
1083static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_stub_cmds(void)
1084{
1085 return &mlx5_flow_cmd_stubs;
1086}
1087
1088const struct mlx5_flow_cmds *mlx5_fs_cmd_get_default(enum fs_flow_table_type type)
1089{
1090 switch (type) {
1091 case FS_FT_NIC_RX:
1092 case FS_FT_ESW_EGRESS_ACL:
1093 case FS_FT_ESW_INGRESS_ACL:
1094 case FS_FT_FDB:
1095 case FS_FT_SNIFFER_RX:
1096 case FS_FT_SNIFFER_TX:
5f418378 1097 case FS_FT_NIC_TX:
d83eb50e 1098 case FS_FT_RDMA_RX:
24670b1a 1099 case FS_FT_RDMA_TX:
425a563a 1100 case FS_FT_PORT_SEL:
8ce78257 1101 return mlx5_fs_cmd_get_fw_cmds();
af76c501
MB
1102 default:
1103 return mlx5_fs_cmd_get_stub_cmds();
1104 }
1105}