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_update_root_ft(struct mlx5_flow_root_namespace *ns,
111 struct mlx5_flow_table *ft, u32 underlay_qpn,
114 u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {0};
115 u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {0};
116 struct mlx5_core_dev *dev = ns->dev;
118 if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) &&
122 MLX5_SET(set_flow_table_root_in, in, opcode,
123 MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
124 MLX5_SET(set_flow_table_root_in, in, table_type, ft->type);
127 MLX5_SET(set_flow_table_root_in, in, op_mod, 1);
128 MLX5_SET(set_flow_table_root_in, in, table_id, 0);
130 MLX5_SET(set_flow_table_root_in, in, op_mod, 0);
131 MLX5_SET(set_flow_table_root_in, in, table_id, ft->id);
134 MLX5_SET(set_flow_table_root_in, in, underlay_qpn, underlay_qpn);
136 MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport);
137 MLX5_SET(set_flow_table_root_in, in, other_vport, 1);
140 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
143 static int mlx5_cmd_create_flow_table(struct mlx5_flow_root_namespace *ns,
144 struct mlx5_flow_table *ft,
145 unsigned int log_size,
146 struct mlx5_flow_table *next_ft)
148 int en_encap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT);
149 int en_decap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_DECAP);
150 int term = !!(ft->flags & MLX5_FLOW_TABLE_TERMINATION);
151 u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {0};
152 u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {0};
153 struct mlx5_core_dev *dev = ns->dev;
156 MLX5_SET(create_flow_table_in, in, opcode,
157 MLX5_CMD_OP_CREATE_FLOW_TABLE);
159 MLX5_SET(create_flow_table_in, in, table_type, ft->type);
160 MLX5_SET(create_flow_table_in, in, flow_table_context.level, ft->level);
161 MLX5_SET(create_flow_table_in, in, flow_table_context.log_size, log_size);
163 MLX5_SET(create_flow_table_in, in, vport_number, ft->vport);
164 MLX5_SET(create_flow_table_in, in, other_vport, 1);
167 MLX5_SET(create_flow_table_in, in, flow_table_context.decap_en,
169 MLX5_SET(create_flow_table_in, in, flow_table_context.reformat_en,
171 MLX5_SET(create_flow_table_in, in, flow_table_context.termination_table,
174 switch (ft->op_mod) {
175 case FS_FT_OP_MOD_NORMAL:
177 MLX5_SET(create_flow_table_in, in,
178 flow_table_context.table_miss_action,
179 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
180 MLX5_SET(create_flow_table_in, in,
181 flow_table_context.table_miss_id, next_ft->id);
183 MLX5_SET(create_flow_table_in, in,
184 flow_table_context.table_miss_action,
185 ns->def_miss_action);
189 case FS_FT_OP_MOD_LAG_DEMUX:
190 MLX5_SET(create_flow_table_in, in, op_mod, 0x1);
192 MLX5_SET(create_flow_table_in, in,
193 flow_table_context.lag_master_next_table_id,
198 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
200 ft->id = MLX5_GET(create_flow_table_out, out,
205 static int mlx5_cmd_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
206 struct mlx5_flow_table *ft)
208 u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {0};
209 u32 out[MLX5_ST_SZ_DW(destroy_flow_table_out)] = {0};
210 struct mlx5_core_dev *dev = ns->dev;
212 MLX5_SET(destroy_flow_table_in, in, opcode,
213 MLX5_CMD_OP_DESTROY_FLOW_TABLE);
214 MLX5_SET(destroy_flow_table_in, in, table_type, ft->type);
215 MLX5_SET(destroy_flow_table_in, in, table_id, ft->id);
217 MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport);
218 MLX5_SET(destroy_flow_table_in, in, other_vport, 1);
221 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
224 static int mlx5_cmd_modify_flow_table(struct mlx5_flow_root_namespace *ns,
225 struct mlx5_flow_table *ft,
226 struct mlx5_flow_table *next_ft)
228 u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {0};
229 u32 out[MLX5_ST_SZ_DW(modify_flow_table_out)] = {0};
230 struct mlx5_core_dev *dev = ns->dev;
232 MLX5_SET(modify_flow_table_in, in, opcode,
233 MLX5_CMD_OP_MODIFY_FLOW_TABLE);
234 MLX5_SET(modify_flow_table_in, in, table_type, ft->type);
235 MLX5_SET(modify_flow_table_in, in, table_id, ft->id);
237 if (ft->op_mod == FS_FT_OP_MOD_LAG_DEMUX) {
238 MLX5_SET(modify_flow_table_in, in, modify_field_select,
239 MLX5_MODIFY_FLOW_TABLE_LAG_NEXT_TABLE_ID);
241 MLX5_SET(modify_flow_table_in, in,
242 flow_table_context.lag_master_next_table_id, next_ft->id);
244 MLX5_SET(modify_flow_table_in, in,
245 flow_table_context.lag_master_next_table_id, 0);
249 MLX5_SET(modify_flow_table_in, in, vport_number,
251 MLX5_SET(modify_flow_table_in, in, other_vport, 1);
253 MLX5_SET(modify_flow_table_in, in, modify_field_select,
254 MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID);
256 MLX5_SET(modify_flow_table_in, in,
257 flow_table_context.table_miss_action,
258 MLX5_FLOW_TABLE_MISS_ACTION_FWD);
259 MLX5_SET(modify_flow_table_in, in,
260 flow_table_context.table_miss_id,
263 MLX5_SET(modify_flow_table_in, in,
264 flow_table_context.table_miss_action,
265 ns->def_miss_action);
269 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
272 static int mlx5_cmd_create_flow_group(struct mlx5_flow_root_namespace *ns,
273 struct mlx5_flow_table *ft,
275 struct mlx5_flow_group *fg)
277 u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {0};
278 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
279 struct mlx5_core_dev *dev = ns->dev;
282 MLX5_SET(create_flow_group_in, in, opcode,
283 MLX5_CMD_OP_CREATE_FLOW_GROUP);
284 MLX5_SET(create_flow_group_in, in, table_type, ft->type);
285 MLX5_SET(create_flow_group_in, in, table_id, ft->id);
287 MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
288 MLX5_SET(create_flow_group_in, in, other_vport, 1);
291 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
293 fg->id = MLX5_GET(create_flow_group_out, out,
298 static int mlx5_cmd_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
299 struct mlx5_flow_table *ft,
300 struct mlx5_flow_group *fg)
302 u32 out[MLX5_ST_SZ_DW(destroy_flow_group_out)] = {0};
303 u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {0};
304 struct mlx5_core_dev *dev = ns->dev;
306 MLX5_SET(destroy_flow_group_in, in, opcode,
307 MLX5_CMD_OP_DESTROY_FLOW_GROUP);
308 MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
309 MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
310 MLX5_SET(destroy_flow_group_in, in, group_id, fg->id);
312 MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport);
313 MLX5_SET(destroy_flow_group_in, in, other_vport, 1);
316 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
319 static int mlx5_set_extended_dest(struct mlx5_core_dev *dev,
320 struct fs_fte *fte, bool *extended_dest)
322 int fw_log_max_fdb_encap_uplink =
323 MLX5_CAP_ESW(dev, log_max_fdb_encap_uplink);
324 int num_fwd_destinations = 0;
325 struct mlx5_flow_rule *dst;
328 *extended_dest = false;
329 if (!(fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
332 list_for_each_entry(dst, &fte->node.children, node.list) {
333 if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
335 if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_VPORT &&
336 dst->dest_attr.vport.flags & MLX5_FLOW_DEST_VPORT_REFORMAT_ID)
338 num_fwd_destinations++;
340 if (num_fwd_destinations > 1 && num_encap > 0)
341 *extended_dest = true;
343 if (*extended_dest && !fw_log_max_fdb_encap_uplink) {
344 mlx5_core_warn(dev, "FW does not support extended destination");
347 if (num_encap > (1 << fw_log_max_fdb_encap_uplink)) {
348 mlx5_core_warn(dev, "FW does not support more than %d encaps",
349 1 << fw_log_max_fdb_encap_uplink);
355 static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
356 int opmod, int modify_mask,
357 struct mlx5_flow_table *ft,
361 u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0};
362 bool extended_dest = false;
363 struct mlx5_flow_rule *dst;
364 void *in_flow_context, *vlan;
365 void *in_match_value;
372 if (mlx5_set_extended_dest(dev, fte, &extended_dest))
376 dst_cnt_size = MLX5_ST_SZ_BYTES(dest_format_struct);
378 dst_cnt_size = MLX5_ST_SZ_BYTES(extended_dest_format);
380 inlen = MLX5_ST_SZ_BYTES(set_fte_in) + fte->dests_size * dst_cnt_size;
381 in = kvzalloc(inlen, GFP_KERNEL);
385 MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY);
386 MLX5_SET(set_fte_in, in, op_mod, opmod);
387 MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask);
388 MLX5_SET(set_fte_in, in, table_type, ft->type);
389 MLX5_SET(set_fte_in, in, table_id, ft->id);
390 MLX5_SET(set_fte_in, in, flow_index, fte->index);
392 MLX5_SET(set_fte_in, in, vport_number, ft->vport);
393 MLX5_SET(set_fte_in, in, other_vport, 1);
396 in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
397 MLX5_SET(flow_context, in_flow_context, group_id, group_id);
399 MLX5_SET(flow_context, in_flow_context, flow_tag,
400 fte->flow_context.flow_tag);
401 MLX5_SET(flow_context, in_flow_context, flow_source,
402 fte->flow_context.flow_source);
404 MLX5_SET(flow_context, in_flow_context, extended_destination,
409 action = fte->action.action &
410 ~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
411 MLX5_SET(flow_context, in_flow_context, action, action);
413 MLX5_SET(flow_context, in_flow_context, action,
415 MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
416 fte->action.reformat_id);
418 MLX5_SET(flow_context, in_flow_context, modify_header_id,
419 fte->action.modify_id);
421 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan);
423 MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[0].ethtype);
424 MLX5_SET(vlan, vlan, vid, fte->action.vlan[0].vid);
425 MLX5_SET(vlan, vlan, prio, fte->action.vlan[0].prio);
427 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan_2);
429 MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[1].ethtype);
430 MLX5_SET(vlan, vlan, vid, fte->action.vlan[1].vid);
431 MLX5_SET(vlan, vlan, prio, fte->action.vlan[1].prio);
433 in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
435 memcpy(in_match_value, &fte->val, sizeof(fte->val));
437 in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
438 if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
441 list_for_each_entry(dst, &fte->node.children, node.list) {
442 unsigned int id, type = dst->dest_attr.type;
444 if (type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
448 case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM:
449 id = dst->dest_attr.ft_num;
450 type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
452 case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE:
453 id = dst->dest_attr.ft->id;
455 case MLX5_FLOW_DESTINATION_TYPE_VPORT:
456 id = dst->dest_attr.vport.num;
457 MLX5_SET(dest_format_struct, in_dests,
458 destination_eswitch_owner_vhca_id_valid,
459 !!(dst->dest_attr.vport.flags &
460 MLX5_FLOW_DEST_VPORT_VHCA_ID));
461 MLX5_SET(dest_format_struct, in_dests,
462 destination_eswitch_owner_vhca_id,
463 dst->dest_attr.vport.vhca_id);
465 MLX5_SET(dest_format_struct, in_dests,
467 !!(dst->dest_attr.vport.flags &
468 MLX5_FLOW_DEST_VPORT_REFORMAT_ID));
469 MLX5_SET(extended_dest_format, in_dests,
471 dst->dest_attr.vport.reformat_id);
475 id = dst->dest_attr.tir_num;
478 MLX5_SET(dest_format_struct, in_dests, destination_type,
480 MLX5_SET(dest_format_struct, in_dests, destination_id, id);
481 in_dests += dst_cnt_size;
485 MLX5_SET(flow_context, in_flow_context, destination_list_size,
489 if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
490 int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
491 log_max_flow_counter,
495 list_for_each_entry(dst, &fte->node.children, node.list) {
496 if (dst->dest_attr.type !=
497 MLX5_FLOW_DESTINATION_TYPE_COUNTER)
500 MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
501 dst->dest_attr.counter_id);
502 in_dests += dst_cnt_size;
505 if (list_size > max_list_size) {
510 MLX5_SET(flow_context, in_flow_context, flow_counter_list_size,
514 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
520 static int mlx5_cmd_create_fte(struct mlx5_flow_root_namespace *ns,
521 struct mlx5_flow_table *ft,
522 struct mlx5_flow_group *group,
525 struct mlx5_core_dev *dev = ns->dev;
526 unsigned int group_id = group->id;
528 return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
531 static int mlx5_cmd_update_fte(struct mlx5_flow_root_namespace *ns,
532 struct mlx5_flow_table *ft,
533 struct mlx5_flow_group *fg,
538 struct mlx5_core_dev *dev = ns->dev;
539 int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
540 flow_table_properties_nic_receive.
546 return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, fg->id, fte);
549 static int mlx5_cmd_delete_fte(struct mlx5_flow_root_namespace *ns,
550 struct mlx5_flow_table *ft,
553 u32 out[MLX5_ST_SZ_DW(delete_fte_out)] = {0};
554 u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {0};
555 struct mlx5_core_dev *dev = ns->dev;
557 MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY);
558 MLX5_SET(delete_fte_in, in, table_type, ft->type);
559 MLX5_SET(delete_fte_in, in, table_id, ft->id);
560 MLX5_SET(delete_fte_in, in, flow_index, fte->index);
562 MLX5_SET(delete_fte_in, in, vport_number, ft->vport);
563 MLX5_SET(delete_fte_in, in, other_vport, 1);
566 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
569 int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id)
571 u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0};
572 u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0};
575 MLX5_SET(alloc_flow_counter_in, in, opcode,
576 MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
578 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
580 *id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
584 int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id)
586 u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {0};
587 u32 out[MLX5_ST_SZ_DW(dealloc_flow_counter_out)] = {0};
589 MLX5_SET(dealloc_flow_counter_in, in, opcode,
590 MLX5_CMD_OP_DEALLOC_FLOW_COUNTER);
591 MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id);
592 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
595 int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id,
596 u64 *packets, u64 *bytes)
598 u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
599 MLX5_ST_SZ_BYTES(traffic_counter)] = {0};
600 u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0};
604 MLX5_SET(query_flow_counter_in, in, opcode,
605 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
606 MLX5_SET(query_flow_counter_in, in, op_mod, 0);
607 MLX5_SET(query_flow_counter_in, in, flow_counter_id, id);
608 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
612 stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics);
613 *packets = MLX5_GET64(traffic_counter, stats, packets);
614 *bytes = MLX5_GET64(traffic_counter, stats, octets);
618 struct mlx5_cmd_fc_bulk {
625 struct mlx5_cmd_fc_bulk *
626 mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u32 id, int num)
628 struct mlx5_cmd_fc_bulk *b;
630 MLX5_ST_SZ_BYTES(query_flow_counter_out) +
631 MLX5_ST_SZ_BYTES(traffic_counter) * num;
633 b = kzalloc(sizeof(*b) + outlen, GFP_KERNEL);
644 void mlx5_cmd_fc_bulk_free(struct mlx5_cmd_fc_bulk *b)
650 mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, struct mlx5_cmd_fc_bulk *b)
652 u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0};
654 MLX5_SET(query_flow_counter_in, in, opcode,
655 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
656 MLX5_SET(query_flow_counter_in, in, op_mod, 0);
657 MLX5_SET(query_flow_counter_in, in, flow_counter_id, b->id);
658 MLX5_SET(query_flow_counter_in, in, num_of_counters, b->num);
659 return mlx5_cmd_exec(dev, in, sizeof(in), b->out, b->outlen);
662 void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
663 struct mlx5_cmd_fc_bulk *b, u32 id,
664 u64 *packets, u64 *bytes)
666 int index = id - b->id;
669 if (index < 0 || index >= b->num) {
670 mlx5_core_warn(dev, "Flow counter id (0x%x) out of range (0x%x..0x%x). Counter ignored.\n",
671 id, b->id, b->id + b->num - 1);
675 stats = MLX5_ADDR_OF(query_flow_counter_out, b->out,
676 flow_statistics[index]);
677 *packets = MLX5_GET64(traffic_counter, stats, packets);
678 *bytes = MLX5_GET64(traffic_counter, stats, octets);
681 int mlx5_packet_reformat_alloc(struct mlx5_core_dev *dev,
685 enum mlx5_flow_namespace_type namespace,
686 u32 *packet_reformat_id)
688 u32 out[MLX5_ST_SZ_DW(alloc_packet_reformat_context_out)];
689 void *packet_reformat_context_in;
696 if (namespace == MLX5_FLOW_NAMESPACE_FDB)
697 max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
699 max_encap_size = MLX5_CAP_FLOWTABLE(dev, max_encap_header_size);
701 if (size > max_encap_size) {
702 mlx5_core_warn(dev, "encap size %zd too big, max supported is %d\n",
703 size, max_encap_size);
707 in = kzalloc(MLX5_ST_SZ_BYTES(alloc_packet_reformat_context_in) + size,
712 packet_reformat_context_in = MLX5_ADDR_OF(alloc_packet_reformat_context_in,
713 in, packet_reformat_context);
714 reformat = MLX5_ADDR_OF(packet_reformat_context_in,
715 packet_reformat_context_in,
717 inlen = reformat - (void *)in + size;
719 memset(in, 0, inlen);
720 MLX5_SET(alloc_packet_reformat_context_in, in, opcode,
721 MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT);
722 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
723 reformat_data_size, size);
724 MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
725 reformat_type, reformat_type);
726 memcpy(reformat, reformat_data, size);
728 memset(out, 0, sizeof(out));
729 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
731 *packet_reformat_id = MLX5_GET(alloc_packet_reformat_context_out,
732 out, packet_reformat_id);
736 EXPORT_SYMBOL(mlx5_packet_reformat_alloc);
738 void mlx5_packet_reformat_dealloc(struct mlx5_core_dev *dev,
739 u32 packet_reformat_id)
741 u32 in[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_in)];
742 u32 out[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_out)];
744 memset(in, 0, sizeof(in));
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(dev, in, sizeof(in), out, sizeof(out));
752 EXPORT_SYMBOL(mlx5_packet_reformat_dealloc);
754 int mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
755 u8 namespace, u8 num_actions,
756 void *modify_actions, u32 *modify_header_id)
758 u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)];
759 int max_actions, actions_size, inlen, err;
765 case MLX5_FLOW_NAMESPACE_FDB:
766 max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, max_modify_header_actions);
767 table_type = FS_FT_FDB;
769 case MLX5_FLOW_NAMESPACE_KERNEL:
770 case MLX5_FLOW_NAMESPACE_BYPASS:
771 max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions);
772 table_type = FS_FT_NIC_RX;
774 case MLX5_FLOW_NAMESPACE_EGRESS:
775 max_actions = MLX5_CAP_FLOWTABLE_NIC_TX(dev, max_modify_header_actions);
776 table_type = FS_FT_NIC_TX;
778 case MLX5_FLOW_NAMESPACE_ESW_INGRESS:
779 max_actions = MLX5_CAP_ESW_INGRESS_ACL(dev, max_modify_header_actions);
780 table_type = FS_FT_ESW_INGRESS_ACL;
786 if (num_actions > max_actions) {
787 mlx5_core_warn(dev, "too many modify header actions %d, max supported %d\n",
788 num_actions, max_actions);
792 actions_size = MLX5_UN_SZ_BYTES(set_action_in_add_action_in_auto) * num_actions;
793 inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size;
795 in = kzalloc(inlen, GFP_KERNEL);
799 MLX5_SET(alloc_modify_header_context_in, in, opcode,
800 MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT);
801 MLX5_SET(alloc_modify_header_context_in, in, table_type, table_type);
802 MLX5_SET(alloc_modify_header_context_in, in, num_of_actions, num_actions);
804 actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions);
805 memcpy(actions_in, modify_actions, actions_size);
807 memset(out, 0, sizeof(out));
808 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
810 *modify_header_id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
814 EXPORT_SYMBOL(mlx5_modify_header_alloc);
816 void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev, u32 modify_header_id)
818 u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)];
819 u32 out[MLX5_ST_SZ_DW(dealloc_modify_header_context_out)];
821 memset(in, 0, sizeof(in));
822 MLX5_SET(dealloc_modify_header_context_in, in, opcode,
823 MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT);
824 MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id,
827 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
829 EXPORT_SYMBOL(mlx5_modify_header_dealloc);
831 static const struct mlx5_flow_cmds mlx5_flow_cmds = {
832 .create_flow_table = mlx5_cmd_create_flow_table,
833 .destroy_flow_table = mlx5_cmd_destroy_flow_table,
834 .modify_flow_table = mlx5_cmd_modify_flow_table,
835 .create_flow_group = mlx5_cmd_create_flow_group,
836 .destroy_flow_group = mlx5_cmd_destroy_flow_group,
837 .create_fte = mlx5_cmd_create_fte,
838 .update_fte = mlx5_cmd_update_fte,
839 .delete_fte = mlx5_cmd_delete_fte,
840 .update_root_ft = mlx5_cmd_update_root_ft,
843 static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = {
844 .create_flow_table = mlx5_cmd_stub_create_flow_table,
845 .destroy_flow_table = mlx5_cmd_stub_destroy_flow_table,
846 .modify_flow_table = mlx5_cmd_stub_modify_flow_table,
847 .create_flow_group = mlx5_cmd_stub_create_flow_group,
848 .destroy_flow_group = mlx5_cmd_stub_destroy_flow_group,
849 .create_fte = mlx5_cmd_stub_create_fte,
850 .update_fte = mlx5_cmd_stub_update_fte,
851 .delete_fte = mlx5_cmd_stub_delete_fte,
852 .update_root_ft = mlx5_cmd_stub_update_root_ft,
855 static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void)
857 return &mlx5_flow_cmds;
860 static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_stub_cmds(void)
862 return &mlx5_flow_cmd_stubs;
865 const struct mlx5_flow_cmds *mlx5_fs_cmd_get_default(enum fs_flow_table_type type)
869 case FS_FT_ESW_EGRESS_ACL:
870 case FS_FT_ESW_INGRESS_ACL:
872 case FS_FT_SNIFFER_RX:
873 case FS_FT_SNIFFER_TX:
876 return mlx5_fs_cmd_get_fw_cmds();
878 return mlx5_fs_cmd_get_stub_cmds();