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, struct mlx5_flow_table
62 *next_ft, unsigned int *table_id)
64 u32 out[MLX5_ST_SZ_DW(create_flow_table_out)];
65 u32 in[MLX5_ST_SZ_DW(create_flow_table_in)];
68 memset(in, 0, sizeof(in));
70 MLX5_SET(create_flow_table_in, in, opcode,
71 MLX5_CMD_OP_CREATE_FLOW_TABLE);
74 MLX5_SET(create_flow_table_in, in, table_miss_mode, 1);
75 MLX5_SET(create_flow_table_in, in, table_miss_id, next_ft->id);
77 MLX5_SET(create_flow_table_in, in, table_type, type);
78 MLX5_SET(create_flow_table_in, in, level, level);
79 MLX5_SET(create_flow_table_in, in, log_size, log_size);
81 memset(out, 0, sizeof(out));
82 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
86 *table_id = MLX5_GET(create_flow_table_out, out,
91 int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev,
92 struct mlx5_flow_table *ft)
94 u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)];
95 u32 out[MLX5_ST_SZ_DW(destroy_flow_table_out)];
97 memset(in, 0, sizeof(in));
98 memset(out, 0, sizeof(out));
100 MLX5_SET(destroy_flow_table_in, in, opcode,
101 MLX5_CMD_OP_DESTROY_FLOW_TABLE);
102 MLX5_SET(destroy_flow_table_in, in, table_type, ft->type);
103 MLX5_SET(destroy_flow_table_in, in, table_id, ft->id);
105 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
109 int mlx5_cmd_modify_flow_table(struct mlx5_core_dev *dev,
110 struct mlx5_flow_table *ft,
111 struct mlx5_flow_table *next_ft)
113 u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)];
114 u32 out[MLX5_ST_SZ_DW(modify_flow_table_out)];
116 memset(in, 0, sizeof(in));
117 memset(out, 0, sizeof(out));
119 MLX5_SET(modify_flow_table_in, in, opcode,
120 MLX5_CMD_OP_MODIFY_FLOW_TABLE);
121 MLX5_SET(modify_flow_table_in, in, table_type, ft->type);
122 MLX5_SET(modify_flow_table_in, in, table_id, ft->id);
123 MLX5_SET(modify_flow_table_in, in, modify_field_select,
124 MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID);
126 MLX5_SET(modify_flow_table_in, in, table_miss_mode, 1);
127 MLX5_SET(modify_flow_table_in, in, table_miss_id, next_ft->id);
129 MLX5_SET(modify_flow_table_in, in, table_miss_mode, 0);
132 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
136 int mlx5_cmd_create_flow_group(struct mlx5_core_dev *dev,
137 struct mlx5_flow_table *ft,
139 unsigned int *group_id)
141 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
142 u32 out[MLX5_ST_SZ_DW(create_flow_group_out)];
145 memset(out, 0, sizeof(out));
147 MLX5_SET(create_flow_group_in, in, opcode,
148 MLX5_CMD_OP_CREATE_FLOW_GROUP);
149 MLX5_SET(create_flow_group_in, in, table_type, ft->type);
150 MLX5_SET(create_flow_group_in, in, table_id, ft->id);
152 err = mlx5_cmd_exec_check_status(dev, in,
156 *group_id = MLX5_GET(create_flow_group_out, out,
162 int mlx5_cmd_destroy_flow_group(struct mlx5_core_dev *dev,
163 struct mlx5_flow_table *ft,
164 unsigned int group_id)
166 u32 out[MLX5_ST_SZ_DW(destroy_flow_group_out)];
167 u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)];
169 memset(in, 0, sizeof(in));
170 memset(out, 0, sizeof(out));
172 MLX5_SET(destroy_flow_group_in, in, opcode,
173 MLX5_CMD_OP_DESTROY_FLOW_GROUP);
174 MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
175 MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
176 MLX5_SET(destroy_flow_group_in, in, group_id, group_id);
178 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
182 static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
183 int opmod, int modify_mask,
184 struct mlx5_flow_table *ft,
188 unsigned int inlen = MLX5_ST_SZ_BYTES(set_fte_in) +
189 fte->dests_size * MLX5_ST_SZ_BYTES(dest_format_struct);
190 u32 out[MLX5_ST_SZ_DW(set_fte_out)];
191 struct mlx5_flow_rule *dst;
192 void *in_flow_context;
193 void *in_match_value;
198 in = mlx5_vzalloc(inlen);
200 mlx5_core_warn(dev, "failed to allocate inbox\n");
204 MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY);
205 MLX5_SET(set_fte_in, in, op_mod, opmod);
206 MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask);
207 MLX5_SET(set_fte_in, in, table_type, ft->type);
208 MLX5_SET(set_fte_in, in, table_id, ft->id);
209 MLX5_SET(set_fte_in, in, flow_index, fte->index);
211 in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
212 MLX5_SET(flow_context, in_flow_context, group_id, group_id);
213 MLX5_SET(flow_context, in_flow_context, flow_tag, fte->flow_tag);
214 MLX5_SET(flow_context, in_flow_context, action, fte->action);
215 MLX5_SET(flow_context, in_flow_context, destination_list_size,
217 in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
219 memcpy(in_match_value, &fte->val, MLX5_ST_SZ_BYTES(fte_match_param));
221 if (fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
222 in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
223 list_for_each_entry(dst, &fte->node.children, node.list) {
226 MLX5_SET(dest_format_struct, in_dests, destination_type,
227 dst->dest_attr.type);
228 if (dst->dest_attr.type ==
229 MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) {
230 id = dst->dest_attr.ft->id;
232 id = dst->dest_attr.tir_num;
234 MLX5_SET(dest_format_struct, in_dests, destination_id, id);
235 in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
238 memset(out, 0, sizeof(out));
239 err = mlx5_cmd_exec_check_status(dev, in, inlen, out,
246 int mlx5_cmd_create_fte(struct mlx5_core_dev *dev,
247 struct mlx5_flow_table *ft,
251 return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
254 int mlx5_cmd_update_fte(struct mlx5_core_dev *dev,
255 struct mlx5_flow_table *ft,
261 int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
262 flow_table_properties_nic_receive.
268 MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST;
270 return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, group_id, fte);
273 int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
274 struct mlx5_flow_table *ft,
277 u32 out[MLX5_ST_SZ_DW(delete_fte_out)];
278 u32 in[MLX5_ST_SZ_DW(delete_fte_in)];
281 memset(in, 0, sizeof(in));
282 memset(out, 0, sizeof(out));
284 MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY);
285 MLX5_SET(delete_fte_in, in, table_type, ft->type);
286 MLX5_SET(delete_fte_in, in, table_id, ft->id);
287 MLX5_SET(delete_fte_in, in, flow_index, index);
289 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));