blob: d8b1195fba3dda53e9029e771828f523ee7b8a87 [file] [log] [blame]
Maor Gottlieb26a81452015-12-10 17:12:39 +02001/*
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"
39#include "mlx5_core.h"
40
Maor Gottlieb2cc43b42016-01-11 10:25:59 +020041int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev,
42 struct mlx5_flow_table *ft)
43{
44 u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)];
45 u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)];
46
47 memset(in, 0, sizeof(in));
48
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);
53
54 memset(out, 0, sizeof(out));
55 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
56 sizeof(out));
57}
58
Maor Gottlieb26a81452015-12-10 17:12:39 +020059int 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)
62{
63 u32 out[MLX5_ST_SZ_DW(create_flow_table_out)];
64 u32 in[MLX5_ST_SZ_DW(create_flow_table_in)];
65 int err;
66
67 memset(in, 0, sizeof(in));
68
69 MLX5_SET(create_flow_table_in, in, opcode,
70 MLX5_CMD_OP_CREATE_FLOW_TABLE);
71
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);
75
76 memset(out, 0, sizeof(out));
77 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
78 sizeof(out));
79
80 if (!err)
81 *table_id = MLX5_GET(create_flow_table_out, out,
82 table_id);
83 return err;
84}
85
86int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev,
87 struct mlx5_flow_table *ft)
88{
89 u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)];
90 u32 out[MLX5_ST_SZ_DW(destroy_flow_table_out)];
91
92 memset(in, 0, sizeof(in));
93 memset(out, 0, sizeof(out));
94
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);
99
100 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
101 sizeof(out));
102}
103
104int mlx5_cmd_create_flow_group(struct mlx5_core_dev *dev,
105 struct mlx5_flow_table *ft,
106 u32 *in,
107 unsigned int *group_id)
108{
109 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
110 u32 out[MLX5_ST_SZ_DW(create_flow_group_out)];
111 int err;
112
113 memset(out, 0, sizeof(out));
114
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);
119
120 err = mlx5_cmd_exec_check_status(dev, in,
121 inlen, out,
122 sizeof(out));
123 if (!err)
124 *group_id = MLX5_GET(create_flow_group_out, out,
125 group_id);
126
127 return err;
128}
129
130int mlx5_cmd_destroy_flow_group(struct mlx5_core_dev *dev,
131 struct mlx5_flow_table *ft,
132 unsigned int group_id)
133{
134 u32 out[MLX5_ST_SZ_DW(destroy_flow_group_out)];
135 u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)];
136
137 memset(in, 0, sizeof(in));
138 memset(out, 0, sizeof(out));
139
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);
145
146 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
147 sizeof(out));
148}
149
150static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
151 int opmod, int modify_mask,
152 struct mlx5_flow_table *ft,
153 unsigned group_id,
154 struct fs_fte *fte)
155{
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;
162 void *in_dests;
163 u32 *in;
164 int err;
165
166 in = mlx5_vzalloc(inlen);
167 if (!in) {
168 mlx5_core_warn(dev, "failed to allocate inbox\n");
169 return -ENOMEM;
170 }
171
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);
178
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,
184 fte->dests_size);
185 in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
186 match_value);
187 memcpy(in_match_value, &fte->val, MLX5_ST_SZ_BYTES(fte_match_param));
188
189 in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
190 list_for_each_entry(dst, &fte->node.children, node.list) {
191 unsigned int id;
192
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;
198 else
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);
202 }
203 memset(out, 0, sizeof(out));
204 err = mlx5_cmd_exec_check_status(dev, in, inlen, out,
205 sizeof(out));
206 kvfree(in);
207
208 return err;
209}
210
211int mlx5_cmd_create_fte(struct mlx5_core_dev *dev,
212 struct mlx5_flow_table *ft,
213 unsigned group_id,
214 struct fs_fte *fte)
215{
216 return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
217}
218
219int mlx5_cmd_update_fte(struct mlx5_core_dev *dev,
220 struct mlx5_flow_table *ft,
221 unsigned group_id,
222 struct fs_fte *fte)
223{
224 int opmod;
225 int modify_mask;
226 int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
227 flow_table_properties_nic_receive.
228 flow_modify_en);
229 if (!atomic_mod_cap)
230 return -ENOTSUPP;
231 opmod = 1;
232 modify_mask = 1 <<
233 MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST;
234
235 return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, group_id, fte);
236}
237
238int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
239 struct mlx5_flow_table *ft,
240 unsigned int index)
241{
242 u32 out[MLX5_ST_SZ_DW(delete_fte_out)];
243 u32 in[MLX5_ST_SZ_DW(delete_fte_in)];
244 int err;
245
246 memset(in, 0, sizeof(in));
247 memset(out, 0, sizeof(out));
248
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);
253
254 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
255
256 return err;
257}