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"
41 int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev,
42 struct mlx5_flow_table *ft)
44 u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)];
45 u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)];
47 memset(in, 0, sizeof(in));
49 MLX5_SET(set_flow_table_root_in, in, opcode,
50 MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
51 MLX5_SET(set_flow_table_root_in, in, table_type, ft->type);
52 MLX5_SET(set_flow_table_root_in, in, table_id, ft->id);
54 memset(out, 0, sizeof(out));
55 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
59 int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
60 enum fs_flow_table_type type, unsigned int level,
61 unsigned int log_size, unsigned int *table_id)
63 u32 out[MLX5_ST_SZ_DW(create_flow_table_out)];
64 u32 in[MLX5_ST_SZ_DW(create_flow_table_in)];
67 memset(in, 0, sizeof(in));
69 MLX5_SET(create_flow_table_in, in, opcode,
70 MLX5_CMD_OP_CREATE_FLOW_TABLE);
72 MLX5_SET(create_flow_table_in, in, table_type, type);
73 MLX5_SET(create_flow_table_in, in, level, level);
74 MLX5_SET(create_flow_table_in, in, log_size, log_size);
76 memset(out, 0, sizeof(out));
77 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
81 *table_id = MLX5_GET(create_flow_table_out, out,
86 int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev,
87 struct mlx5_flow_table *ft)
89 u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)];
90 u32 out[MLX5_ST_SZ_DW(destroy_flow_table_out)];
92 memset(in, 0, sizeof(in));
93 memset(out, 0, sizeof(out));
95 MLX5_SET(destroy_flow_table_in, in, opcode,
96 MLX5_CMD_OP_DESTROY_FLOW_TABLE);
97 MLX5_SET(destroy_flow_table_in, in, table_type, ft->type);
98 MLX5_SET(destroy_flow_table_in, in, table_id, ft->id);
100 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
104 int mlx5_cmd_create_flow_group(struct mlx5_core_dev *dev,
105 struct mlx5_flow_table *ft,
107 unsigned int *group_id)
109 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
110 u32 out[MLX5_ST_SZ_DW(create_flow_group_out)];
113 memset(out, 0, sizeof(out));
115 MLX5_SET(create_flow_group_in, in, opcode,
116 MLX5_CMD_OP_CREATE_FLOW_GROUP);
117 MLX5_SET(create_flow_group_in, in, table_type, ft->type);
118 MLX5_SET(create_flow_group_in, in, table_id, ft->id);
120 err = mlx5_cmd_exec_check_status(dev, in,
124 *group_id = MLX5_GET(create_flow_group_out, out,
130 int mlx5_cmd_destroy_flow_group(struct mlx5_core_dev *dev,
131 struct mlx5_flow_table *ft,
132 unsigned int group_id)
134 u32 out[MLX5_ST_SZ_DW(destroy_flow_group_out)];
135 u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)];
137 memset(in, 0, sizeof(in));
138 memset(out, 0, sizeof(out));
140 MLX5_SET(destroy_flow_group_in, in, opcode,
141 MLX5_CMD_OP_DESTROY_FLOW_GROUP);
142 MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
143 MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
144 MLX5_SET(destroy_flow_group_in, in, group_id, group_id);
146 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
150 static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
151 int opmod, int modify_mask,
152 struct mlx5_flow_table *ft,
156 unsigned int inlen = MLX5_ST_SZ_BYTES(set_fte_in) +
157 fte->dests_size * MLX5_ST_SZ_BYTES(dest_format_struct);
158 u32 out[MLX5_ST_SZ_DW(set_fte_out)];
159 struct mlx5_flow_rule *dst;
160 void *in_flow_context;
161 void *in_match_value;
166 in = mlx5_vzalloc(inlen);
168 mlx5_core_warn(dev, "failed to allocate inbox\n");
172 MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY);
173 MLX5_SET(set_fte_in, in, op_mod, opmod);
174 MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask);
175 MLX5_SET(set_fte_in, in, table_type, ft->type);
176 MLX5_SET(set_fte_in, in, table_id, ft->id);
177 MLX5_SET(set_fte_in, in, flow_index, fte->index);
179 in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
180 MLX5_SET(flow_context, in_flow_context, group_id, group_id);
181 MLX5_SET(flow_context, in_flow_context, flow_tag, fte->flow_tag);
182 MLX5_SET(flow_context, in_flow_context, action, fte->action);
183 MLX5_SET(flow_context, in_flow_context, destination_list_size,
185 in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
187 memcpy(in_match_value, &fte->val, MLX5_ST_SZ_BYTES(fte_match_param));
189 in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
190 list_for_each_entry(dst, &fte->node.children, node.list) {
193 MLX5_SET(dest_format_struct, in_dests, destination_type,
194 dst->dest_attr.type);
195 if (dst->dest_attr.type ==
196 MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE)
197 id = dst->dest_attr.ft->id;
199 id = dst->dest_attr.tir_num;
200 MLX5_SET(dest_format_struct, in_dests, destination_id, id);
201 in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
203 memset(out, 0, sizeof(out));
204 err = mlx5_cmd_exec_check_status(dev, in, inlen, out,
211 int mlx5_cmd_create_fte(struct mlx5_core_dev *dev,
212 struct mlx5_flow_table *ft,
216 return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
219 int mlx5_cmd_update_fte(struct mlx5_core_dev *dev,
220 struct mlx5_flow_table *ft,
226 int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
227 flow_table_properties_nic_receive.
233 MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST;
235 return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, group_id, fte);
238 int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
239 struct mlx5_flow_table *ft,
242 u32 out[MLX5_ST_SZ_DW(delete_fte_out)];
243 u32 in[MLX5_ST_SZ_DW(delete_fte_in)];
246 memset(in, 0, sizeof(in));
247 memset(out, 0, sizeof(out));
249 MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY);
250 MLX5_SET(delete_fte_in, in, table_type, ft->type);
251 MLX5_SET(delete_fte_in, in, table_id, ft->id);
252 MLX5_SET(delete_fte_in, in, flow_index, index);
254 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));