2 * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/mlx5/driver.h>
34 #include <linux/mlx5/device.h>
35 #include <linux/mlx5/mlx5_ifc.h>
39 #include "mlx5_core.h"
42 static int mlx5_cmd_stub_update_root_ft(struct mlx5_flow_root_namespace *ns,
43 struct mlx5_flow_table *ft,
50 static int mlx5_cmd_stub_create_flow_table(struct mlx5_flow_root_namespace *ns,
51 struct mlx5_flow_table *ft,
52 unsigned int log_size,
53 struct mlx5_flow_table *next_ft)
58 static int mlx5_cmd_stub_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
59 struct mlx5_flow_table *ft)
64 static int mlx5_cmd_stub_modify_flow_table(struct mlx5_flow_root_namespace *ns,
65 struct mlx5_flow_table *ft,
66 struct mlx5_flow_table *next_ft)
71 static int mlx5_cmd_stub_create_flow_group(struct mlx5_flow_root_namespace *ns,
72 struct mlx5_flow_table *ft,
74 struct mlx5_flow_group *fg)
79 static int mlx5_cmd_stub_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
80 struct mlx5_flow_table *ft,
81 struct mlx5_flow_group *fg)
86 static int mlx5_cmd_stub_create_fte(struct mlx5_flow_root_namespace *ns,
87 struct mlx5_flow_table *ft,
88 struct mlx5_flow_group *group,
94 static int mlx5_cmd_stub_update_fte(struct mlx5_flow_root_namespace *ns,
95 struct mlx5_flow_table *ft,
96 struct mlx5_flow_group *group,
103 static int mlx5_cmd_stub_delete_fte(struct mlx5_flow_root_namespace *ns,
104 struct mlx5_flow_table *ft,
110 static int mlx5_cmd_stub_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
114 enum mlx5_flow_namespace_type namespace,
115 struct mlx5_pkt_reformat *pkt_reformat)
120 static void mlx5_cmd_stub_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
121 struct mlx5_pkt_reformat *pkt_reformat)
125 static int mlx5_cmd_stub_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
126 u8 namespace, u8 num_actions,
127 void *modify_actions,
128 struct mlx5_modify_hdr *modify_hdr)
133 static void mlx5_cmd_stub_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
134 struct mlx5_modify_hdr *modify_hdr)
138 static int mlx5_cmd_stub_set_peer(struct mlx5_flow_root_namespace *ns,
139 struct mlx5_flow_root_namespace *peer_ns)
144 static int mlx5_cmd_stub_create_ns(struct mlx5_flow_root_namespace *ns)
149 static int mlx5_cmd_stub_destroy_ns(struct mlx5_flow_root_namespace *ns)
154 static int mlx5_cmd_update_root_ft(struct mlx5_flow_root_namespace *ns,
155 struct mlx5_flow_table *ft, u32 underlay_qpn,
158 u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {};
159 struct mlx5_core_dev *dev = ns->dev;
161 if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) &&
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, ft->type);
170 MLX5_SET(set_flow_table_root_in, in, op_mod, 1);
172 MLX5_SET(set_flow_table_root_in, in, table_id, ft->id);
174 MLX5_SET(set_flow_table_root_in, in, underlay_qpn, underlay_qpn);
175 MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport);
176 MLX5_SET(set_flow_table_root_in, in, other_vport,
177 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
179 return mlx5_cmd_exec_in(dev, set_flow_table_root, in);
182 static int mlx5_cmd_create_flow_table(struct mlx5_flow_root_namespace *ns,
183 struct mlx5_flow_table *ft,
184 unsigned int log_size,
185 struct mlx5_flow_table *next_ft)
187 int en_encap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT);
188 int en_decap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_DECAP);
189 int term = !!(ft->flags & MLX5_FLOW_TABLE_TERMINATION);
190 u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {};
191 u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {};
192 struct mlx5_core_dev *dev = ns->dev;
195 MLX5_SET(create_flow_table_in, in, opcode,
196 MLX5_CMD_OP_CREATE_FLOW_TABLE);
198 MLX5_SET(create_flow_table_in, in, table_type, ft->type);
199 MLX5_SET(create_flow_table_in, in, flow_table_context.level, ft->level);
200 MLX5_SET(create_flow_table_in, in, flow_table_context.log_size, log_size);
201 MLX5_SET(create_flow_table_in, in, vport_number, ft->vport);
202 MLX5_SET(create_flow_table_in, in, other_vport,
203 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
205 MLX5_SET(create_flow_table_in, in, flow_table_context.decap_en,
207 MLX5_SET(create_flow_table_in, in, flow_table_context.reformat_en,
209 MLX5_SET(create_flow_table_in, in, flow_table_context.termination_table,
212 switch (ft->op_mod) {
213 case FS_FT_OP_MOD_NORMAL:
215 MLX5_SET(create_flow_table_in, in,
216 flow_table_context.table_miss_action,
217 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
218 MLX5_SET(create_flow_table_in, in,
219 flow_table_context.table_miss_id, next_ft->id);
221 MLX5_SET(create_flow_table_in, in,
222 flow_table_context.table_miss_action,
223 ft->def_miss_action);
227 case FS_FT_OP_MOD_LAG_DEMUX:
228 MLX5_SET(create_flow_table_in, in, op_mod, 0x1);
230 MLX5_SET(create_flow_table_in, in,
231 flow_table_context.lag_master_next_table_id,
236 err = mlx5_cmd_exec_inout(dev, create_flow_table, in, out);
238 ft->id = MLX5_GET(create_flow_table_out, out,
243 static int mlx5_cmd_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
244 struct mlx5_flow_table *ft)
246 u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {};
247 struct mlx5_core_dev *dev = ns->dev;
249 MLX5_SET(destroy_flow_table_in, in, opcode,
250 MLX5_CMD_OP_DESTROY_FLOW_TABLE);
251 MLX5_SET(destroy_flow_table_in, in, table_type, ft->type);
252 MLX5_SET(destroy_flow_table_in, in, table_id, ft->id);
253 MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport);
254 MLX5_SET(destroy_flow_table_in, in, other_vport,
255 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
257 return mlx5_cmd_exec_in(dev, destroy_flow_table, in);
260 static int mlx5_cmd_modify_flow_table(struct mlx5_flow_root_namespace *ns,
261 struct mlx5_flow_table *ft,
262 struct mlx5_flow_table *next_ft)
264 u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {};
265 struct mlx5_core_dev *dev = ns->dev;
267 MLX5_SET(modify_flow_table_in, in, opcode,
268 MLX5_CMD_OP_MODIFY_FLOW_TABLE);
269 MLX5_SET(modify_flow_table_in, in, table_type, ft->type);
270 MLX5_SET(modify_flow_table_in, in, table_id, ft->id);
272 if (ft->op_mod == FS_FT_OP_MOD_LAG_DEMUX) {
273 MLX5_SET(modify_flow_table_in, in, modify_field_select,
274 MLX5_MODIFY_FLOW_TABLE_LAG_NEXT_TABLE_ID);
276 MLX5_SET(modify_flow_table_in, in,
277 flow_table_context.lag_master_next_table_id, next_ft->id);
279 MLX5_SET(modify_flow_table_in, in,
280 flow_table_context.lag_master_next_table_id, 0);
283 MLX5_SET(modify_flow_table_in, in, vport_number, ft->vport);
284 MLX5_SET(modify_flow_table_in, in, other_vport,
285 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
286 MLX5_SET(modify_flow_table_in, in, modify_field_select,
287 MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID);
289 MLX5_SET(modify_flow_table_in, in,
290 flow_table_context.table_miss_action,
291 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
292 MLX5_SET(modify_flow_table_in, in,
293 flow_table_context.table_miss_id,
296 MLX5_SET(modify_flow_table_in, in,
297 flow_table_context.table_miss_action,
298 ft->def_miss_action);
302 return mlx5_cmd_exec_in(dev, modify_flow_table, in);
305 static int mlx5_cmd_create_flow_group(struct mlx5_flow_root_namespace *ns,
306 struct mlx5_flow_table *ft,
308 struct mlx5_flow_group *fg)
310 u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {};
311 struct mlx5_core_dev *dev = ns->dev;
314 MLX5_SET(create_flow_group_in, in, opcode,
315 MLX5_CMD_OP_CREATE_FLOW_GROUP);
316 MLX5_SET(create_flow_group_in, in, table_type, ft->type);
317 MLX5_SET(create_flow_group_in, in, table_id, ft->id);
319 MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
320 MLX5_SET(create_flow_group_in, in, other_vport, 1);
323 MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
324 MLX5_SET(create_flow_group_in, in, other_vport,
325 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
326 err = mlx5_cmd_exec_inout(dev, create_flow_group, in, out);
328 fg->id = MLX5_GET(create_flow_group_out, out,
333 static int mlx5_cmd_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
334 struct mlx5_flow_table *ft,
335 struct mlx5_flow_group *fg)
337 u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {};
338 struct mlx5_core_dev *dev = ns->dev;
340 MLX5_SET(destroy_flow_group_in, in, opcode,
341 MLX5_CMD_OP_DESTROY_FLOW_GROUP);
342 MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
343 MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
344 MLX5_SET(destroy_flow_group_in, in, group_id, fg->id);
345 MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport);
346 MLX5_SET(destroy_flow_group_in, in, other_vport,
347 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
348 return mlx5_cmd_exec_in(dev, destroy_flow_group, in);
351 static int mlx5_set_extended_dest(struct mlx5_core_dev *dev,
352 struct fs_fte *fte, bool *extended_dest)
354 int fw_log_max_fdb_encap_uplink =
355 MLX5_CAP_ESW(dev, log_max_fdb_encap_uplink);
356 int num_fwd_destinations = 0;
357 struct mlx5_flow_rule *dst;
360 *extended_dest = false;
361 if (!(fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
364 list_for_each_entry(dst, &fte->node.children, node.list) {
365 if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
367 if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_VPORT &&
368 dst->dest_attr.vport.flags & MLX5_FLOW_DEST_VPORT_REFORMAT_ID)
370 num_fwd_destinations++;
372 if (num_fwd_destinations > 1 && num_encap > 0)
373 *extended_dest = true;
375 if (*extended_dest && !fw_log_max_fdb_encap_uplink) {
376 mlx5_core_warn(dev, "FW does not support extended destination");
379 if (num_encap > (1 << fw_log_max_fdb_encap_uplink)) {
380 mlx5_core_warn(dev, "FW does not support more than %d encaps",
381 1 << fw_log_max_fdb_encap_uplink);
387 static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
388 int opmod, int modify_mask,
389 struct mlx5_flow_table *ft,
393 u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0};
394 bool extended_dest = false;
395 struct mlx5_flow_rule *dst;
396 void *in_flow_context, *vlan;
397 void *in_match_value;
404 if (mlx5_set_extended_dest(dev, fte, &extended_dest))
408 dst_cnt_size = MLX5_ST_SZ_BYTES(dest_format_struct);
410 dst_cnt_size = MLX5_ST_SZ_BYTES(extended_dest_format);
412 inlen = MLX5_ST_SZ_BYTES(set_fte_in) + fte->dests_size * dst_cnt_size;
413 in = kvzalloc(inlen, GFP_KERNEL);
417 MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY);
418 MLX5_SET(set_fte_in, in, op_mod, opmod);
419 MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask);
420 MLX5_SET(set_fte_in, in, table_type, ft->type);
421 MLX5_SET(set_fte_in, in, table_id, ft->id);
422 MLX5_SET(set_fte_in, in, flow_index, fte->index);
423 MLX5_SET(set_fte_in, in, ignore_flow_level,
424 !!(fte->action.flags & FLOW_ACT_IGNORE_FLOW_LEVEL));
426 MLX5_SET(set_fte_in, in, vport_number, ft->vport);
427 MLX5_SET(set_fte_in, in, other_vport,
428 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
430 in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
431 MLX5_SET(flow_context, in_flow_context, group_id, group_id);
433 MLX5_SET(flow_context, in_flow_context, flow_tag,
434 fte->flow_context.flow_tag);
435 MLX5_SET(flow_context, in_flow_context, flow_source,
436 fte->flow_context.flow_source);
438 MLX5_SET(flow_context, in_flow_context, extended_destination,
443 action = fte->action.action &
444 ~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
445 MLX5_SET(flow_context, in_flow_context, action, action);
447 MLX5_SET(flow_context, in_flow_context, action,
449 if (fte->action.pkt_reformat)
450 MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
451 fte->action.pkt_reformat->id);
453 if (fte->action.modify_hdr)
454 MLX5_SET(flow_context, in_flow_context, modify_header_id,
455 fte->action.modify_hdr->id);
457 MLX5_SET(flow_context, in_flow_context, ipsec_obj_id, fte->action.ipsec_obj_id);
459 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan);
461 MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[0].ethtype);
462 MLX5_SET(vlan, vlan, vid, fte->action.vlan[0].vid);
463 MLX5_SET(vlan, vlan, prio, fte->action.vlan[0].prio);
465 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan_2);
467 MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[1].ethtype);
468 MLX5_SET(vlan, vlan, vid, fte->action.vlan[1].vid);
469 MLX5_SET(vlan, vlan, prio, fte->action.vlan[1].prio);
471 in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
473 memcpy(in_match_value, &fte->val, sizeof(fte->val));
475 in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
476 if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
479 list_for_each_entry(dst, &fte->node.children, node.list) {
480 unsigned int id, type = dst->dest_attr.type;
482 if (type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
486 case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM:
487 id = dst->dest_attr.ft_num;
488 type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
490 case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE:
491 id = dst->dest_attr.ft->id;
493 case MLX5_FLOW_DESTINATION_TYPE_VPORT:
494 id = dst->dest_attr.vport.num;
495 MLX5_SET(dest_format_struct, in_dests,
496 destination_eswitch_owner_vhca_id_valid,
497 !!(dst->dest_attr.vport.flags &
498 MLX5_FLOW_DEST_VPORT_VHCA_ID));
499 MLX5_SET(dest_format_struct, in_dests,
500 destination_eswitch_owner_vhca_id,
501 dst->dest_attr.vport.vhca_id);
503 dst->dest_attr.vport.pkt_reformat) {
504 MLX5_SET(dest_format_struct, in_dests,
506 !!(dst->dest_attr.vport.flags &
507 MLX5_FLOW_DEST_VPORT_REFORMAT_ID));
508 MLX5_SET(extended_dest_format, in_dests,
510 dst->dest_attr.vport.pkt_reformat->id);
513 case MLX5_FLOW_DESTINATION_TYPE_FLOW_SAMPLER:
514 id = dst->dest_attr.sampler_id;
517 id = dst->dest_attr.tir_num;
520 MLX5_SET(dest_format_struct, in_dests, destination_type,
522 MLX5_SET(dest_format_struct, in_dests, destination_id, id);
523 in_dests += dst_cnt_size;
527 MLX5_SET(flow_context, in_flow_context, destination_list_size,
531 if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
532 int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
533 log_max_flow_counter,
537 list_for_each_entry(dst, &fte->node.children, node.list) {
538 if (dst->dest_attr.type !=
539 MLX5_FLOW_DESTINATION_TYPE_COUNTER)
542 MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
543 dst->dest_attr.counter_id);
544 in_dests += dst_cnt_size;
547 if (list_size > max_list_size) {
552 MLX5_SET(flow_context, in_flow_context, flow_counter_list_size,
556 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
562 static int mlx5_cmd_create_fte(struct mlx5_flow_root_namespace *ns,
563 struct mlx5_flow_table *ft,
564 struct mlx5_flow_group *group,
567 struct mlx5_core_dev *dev = ns->dev;
568 unsigned int group_id = group->id;
570 return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
573 static int mlx5_cmd_update_fte(struct mlx5_flow_root_namespace *ns,
574 struct mlx5_flow_table *ft,
575 struct mlx5_flow_group *fg,
580 struct mlx5_core_dev *dev = ns->dev;
581 int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
582 flow_table_properties_nic_receive.
588 return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, fg->id, fte);
591 static int mlx5_cmd_delete_fte(struct mlx5_flow_root_namespace *ns,
592 struct mlx5_flow_table *ft,
595 u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {};
596 struct mlx5_core_dev *dev = ns->dev;
598 MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY);
599 MLX5_SET(delete_fte_in, in, table_type, ft->type);
600 MLX5_SET(delete_fte_in, in, table_id, ft->id);
601 MLX5_SET(delete_fte_in, in, flow_index, fte->index);
602 MLX5_SET(delete_fte_in, in, vport_number, ft->vport);
603 MLX5_SET(delete_fte_in, in, other_vport,
604 !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT));
606 return mlx5_cmd_exec_in(dev, delete_fte, in);
609 int mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev,
610 enum mlx5_fc_bulk_alloc_bitmask alloc_bitmask,
613 u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {};
614 u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {};
617 MLX5_SET(alloc_flow_counter_in, in, opcode,
618 MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
619 MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk, alloc_bitmask);
621 err = mlx5_cmd_exec_inout(dev, alloc_flow_counter, in, out);
623 *id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
627 int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id)
629 return mlx5_cmd_fc_bulk_alloc(dev, 0, id);
632 int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id)
634 u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {};
636 MLX5_SET(dealloc_flow_counter_in, in, opcode,
637 MLX5_CMD_OP_DEALLOC_FLOW_COUNTER);
638 MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id);
639 return mlx5_cmd_exec_in(dev, dealloc_flow_counter, in);
642 int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id,
643 u64 *packets, u64 *bytes)
645 u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
646 MLX5_ST_SZ_BYTES(traffic_counter)] = {};
647 u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
651 MLX5_SET(query_flow_counter_in, in, opcode,
652 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
653 MLX5_SET(query_flow_counter_in, in, op_mod, 0);
654 MLX5_SET(query_flow_counter_in, in, flow_counter_id, id);
655 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
659 stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics);
660 *packets = MLX5_GET64(traffic_counter, stats, packets);
661 *bytes = MLX5_GET64(traffic_counter, stats, octets);
665 int mlx5_cmd_fc_get_bulk_query_out_len(int bulk_len)
667 return MLX5_ST_SZ_BYTES(query_flow_counter_out) +
668 MLX5_ST_SZ_BYTES(traffic_counter) * bulk_len;
671 int mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, u32 base_id, int bulk_len,
674 int outlen = mlx5_cmd_fc_get_bulk_query_out_len(bulk_len);
675 u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
677 MLX5_SET(query_flow_counter_in, in, opcode,
678 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
679 MLX5_SET(query_flow_counter_in, in, flow_counter_id, base_id);
680 MLX5_SET(query_flow_counter_in, in, num_of_counters, bulk_len);
681 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
684 static int mlx5_cmd_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
688 enum mlx5_flow_namespace_type namespace,
689 struct mlx5_pkt_reformat *pkt_reformat)
691 u32 out[MLX5_ST_SZ_DW(alloc_packet_reformat_context_out)] = {};
692 struct mlx5_core_dev *dev = ns->dev;
693 void *packet_reformat_context_in;
700 if (namespace == MLX5_FLOW_NAMESPACE_FDB)
701 max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
703 max_encap_size = MLX5_CAP_FLOWTABLE(dev, max_encap_header_size);
705 if (size > max_encap_size) {
706 mlx5_core_warn(dev, "encap size %zd too big, max supported is %d\n",
707 size, max_encap_size);
711 in = kzalloc(MLX5_ST_SZ_BYTES(alloc_packet_reformat_context_in) + size,
716 packet_reformat_context_in = MLX5_ADDR_OF(alloc_packet_reformat_context_in,
717 in, packet_reformat_context);
718 reformat = MLX5_ADDR_OF(packet_reformat_context_in,
719 packet_reformat_context_in,
721 inlen = reformat - (void *)in + size;
723 MLX5_SET(alloc_packet_reformat_context_in, in, opcode,
724 MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT);
725 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
726 reformat_data_size, size);
727 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
728 reformat_type, reformat_type);
729 memcpy(reformat, reformat_data, size);
731 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
733 pkt_reformat->id = MLX5_GET(alloc_packet_reformat_context_out,
734 out, packet_reformat_id);
739 static void mlx5_cmd_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
740 struct mlx5_pkt_reformat *pkt_reformat)
742 u32 in[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_in)] = {};
743 struct mlx5_core_dev *dev = ns->dev;
745 MLX5_SET(dealloc_packet_reformat_context_in, in, opcode,
746 MLX5_CMD_OP_DEALLOC_PACKET_REFORMAT_CONTEXT);
747 MLX5_SET(dealloc_packet_reformat_context_in, in, packet_reformat_id,
750 mlx5_cmd_exec_in(dev, dealloc_packet_reformat_context, in);
753 static int mlx5_cmd_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
754 u8 namespace, u8 num_actions,
755 void *modify_actions,
756 struct mlx5_modify_hdr *modify_hdr)
758 u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)] = {};
759 int max_actions, actions_size, inlen, err;
760 struct mlx5_core_dev *dev = ns->dev;
766 case MLX5_FLOW_NAMESPACE_FDB:
767 max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, max_modify_header_actions);
768 table_type = FS_FT_FDB;
770 case MLX5_FLOW_NAMESPACE_KERNEL:
771 case MLX5_FLOW_NAMESPACE_BYPASS:
772 max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions);
773 table_type = FS_FT_NIC_RX;
775 case MLX5_FLOW_NAMESPACE_EGRESS:
776 #ifdef CONFIG_MLX5_IPSEC
777 case MLX5_FLOW_NAMESPACE_EGRESS_KERNEL:
779 max_actions = MLX5_CAP_FLOWTABLE_NIC_TX(dev, max_modify_header_actions);
780 table_type = FS_FT_NIC_TX;
782 case MLX5_FLOW_NAMESPACE_ESW_INGRESS:
783 max_actions = MLX5_CAP_ESW_INGRESS_ACL(dev, max_modify_header_actions);
784 table_type = FS_FT_ESW_INGRESS_ACL;
786 case MLX5_FLOW_NAMESPACE_RDMA_TX:
787 max_actions = MLX5_CAP_FLOWTABLE_RDMA_TX(dev, max_modify_header_actions);
788 table_type = FS_FT_RDMA_TX;
794 if (num_actions > max_actions) {
795 mlx5_core_warn(dev, "too many modify header actions %d, max supported %d\n",
796 num_actions, max_actions);
800 actions_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) * num_actions;
801 inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size;
803 in = kzalloc(inlen, GFP_KERNEL);
807 MLX5_SET(alloc_modify_header_context_in, in, opcode,
808 MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT);
809 MLX5_SET(alloc_modify_header_context_in, in, table_type, table_type);
810 MLX5_SET(alloc_modify_header_context_in, in, num_of_actions, num_actions);
812 actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions);
813 memcpy(actions_in, modify_actions, actions_size);
815 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
817 modify_hdr->id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
822 static void mlx5_cmd_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
823 struct mlx5_modify_hdr *modify_hdr)
825 u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)] = {};
826 struct mlx5_core_dev *dev = ns->dev;
828 MLX5_SET(dealloc_modify_header_context_in, in, opcode,
829 MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT);
830 MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id,
833 mlx5_cmd_exec_in(dev, dealloc_modify_header_context, in);
836 static const struct mlx5_flow_cmds mlx5_flow_cmds = {
837 .create_flow_table = mlx5_cmd_create_flow_table,
838 .destroy_flow_table = mlx5_cmd_destroy_flow_table,
839 .modify_flow_table = mlx5_cmd_modify_flow_table,
840 .create_flow_group = mlx5_cmd_create_flow_group,
841 .destroy_flow_group = mlx5_cmd_destroy_flow_group,
842 .create_fte = mlx5_cmd_create_fte,
843 .update_fte = mlx5_cmd_update_fte,
844 .delete_fte = mlx5_cmd_delete_fte,
845 .update_root_ft = mlx5_cmd_update_root_ft,
846 .packet_reformat_alloc = mlx5_cmd_packet_reformat_alloc,
847 .packet_reformat_dealloc = mlx5_cmd_packet_reformat_dealloc,
848 .modify_header_alloc = mlx5_cmd_modify_header_alloc,
849 .modify_header_dealloc = mlx5_cmd_modify_header_dealloc,
850 .set_peer = mlx5_cmd_stub_set_peer,
851 .create_ns = mlx5_cmd_stub_create_ns,
852 .destroy_ns = mlx5_cmd_stub_destroy_ns,
855 static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = {
856 .create_flow_table = mlx5_cmd_stub_create_flow_table,
857 .destroy_flow_table = mlx5_cmd_stub_destroy_flow_table,
858 .modify_flow_table = mlx5_cmd_stub_modify_flow_table,
859 .create_flow_group = mlx5_cmd_stub_create_flow_group,
860 .destroy_flow_group = mlx5_cmd_stub_destroy_flow_group,
861 .create_fte = mlx5_cmd_stub_create_fte,
862 .update_fte = mlx5_cmd_stub_update_fte,
863 .delete_fte = mlx5_cmd_stub_delete_fte,
864 .update_root_ft = mlx5_cmd_stub_update_root_ft,
865 .packet_reformat_alloc = mlx5_cmd_stub_packet_reformat_alloc,
866 .packet_reformat_dealloc = mlx5_cmd_stub_packet_reformat_dealloc,
867 .modify_header_alloc = mlx5_cmd_stub_modify_header_alloc,
868 .modify_header_dealloc = mlx5_cmd_stub_modify_header_dealloc,
869 .set_peer = mlx5_cmd_stub_set_peer,
870 .create_ns = mlx5_cmd_stub_create_ns,
871 .destroy_ns = mlx5_cmd_stub_destroy_ns,
874 const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void)
876 return &mlx5_flow_cmds;
879 static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_stub_cmds(void)
881 return &mlx5_flow_cmd_stubs;
884 const struct mlx5_flow_cmds *mlx5_fs_cmd_get_default(enum fs_flow_table_type type)
888 case FS_FT_ESW_EGRESS_ACL:
889 case FS_FT_ESW_INGRESS_ACL:
891 case FS_FT_SNIFFER_RX:
892 case FS_FT_SNIFFER_TX:
896 return mlx5_fs_cmd_get_fw_cmds();
898 return mlx5_fs_cmd_get_stub_cmds();