]>
Commit | Line | Data |
---|---|---|
26a81453 MG |
1 | /* |
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" | |
c9f1b073 | 40 | #include "eswitch.h" |
26a81453 | 41 | |
2cc43b49 MG |
42 | int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev, |
43 | struct mlx5_flow_table *ft) | |
44 | { | |
c4f287c4 SM |
45 | u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {0}; |
46 | u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {0}; | |
2cc43b49 | 47 | |
b3ba5149 ES |
48 | if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) && |
49 | ft->underlay_qpn == 0) | |
50 | return 0; | |
51 | ||
2cc43b49 MG |
52 | MLX5_SET(set_flow_table_root_in, in, opcode, |
53 | MLX5_CMD_OP_SET_FLOW_TABLE_ROOT); | |
54 | MLX5_SET(set_flow_table_root_in, in, table_type, ft->type); | |
55 | MLX5_SET(set_flow_table_root_in, in, table_id, ft->id); | |
efdc810b MHY |
56 | if (ft->vport) { |
57 | MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport); | |
58 | MLX5_SET(set_flow_table_root_in, in, other_vport, 1); | |
59 | } | |
2cc43b49 | 60 | |
b3ba5149 ES |
61 | if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) && |
62 | ft->underlay_qpn != 0) | |
63 | MLX5_SET(set_flow_table_root_in, in, underlay_qpn, ft->underlay_qpn); | |
64 | ||
c4f287c4 | 65 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
2cc43b49 MG |
66 | } |
67 | ||
26a81453 | 68 | int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev, |
efdc810b | 69 | u16 vport, |
aaff1bea | 70 | enum fs_flow_table_op_mod op_mod, |
26a81453 | 71 | enum fs_flow_table_type type, unsigned int level, |
f90edfd2 | 72 | unsigned int log_size, struct mlx5_flow_table |
c9f1b073 | 73 | *next_ft, unsigned int *table_id, u32 flags) |
26a81453 | 74 | { |
c9f1b073 | 75 | int en_encap_decap = !!(flags & MLX5_FLOW_TABLE_TUNNEL_EN); |
c4f287c4 SM |
76 | u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {0}; |
77 | u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {0}; | |
26a81453 MG |
78 | int err; |
79 | ||
26a81453 MG |
80 | MLX5_SET(create_flow_table_in, in, opcode, |
81 | MLX5_CMD_OP_CREATE_FLOW_TABLE); | |
82 | ||
83 | MLX5_SET(create_flow_table_in, in, table_type, type); | |
84 | MLX5_SET(create_flow_table_in, in, level, level); | |
85 | MLX5_SET(create_flow_table_in, in, log_size, log_size); | |
efdc810b MHY |
86 | if (vport) { |
87 | MLX5_SET(create_flow_table_in, in, vport_number, vport); | |
88 | MLX5_SET(create_flow_table_in, in, other_vport, 1); | |
89 | } | |
26a81453 | 90 | |
c9f1b073 HHZ |
91 | MLX5_SET(create_flow_table_in, in, decap_en, en_encap_decap); |
92 | MLX5_SET(create_flow_table_in, in, encap_en, en_encap_decap); | |
93 | ||
aaff1bea AH |
94 | switch (op_mod) { |
95 | case FS_FT_OP_MOD_NORMAL: | |
96 | if (next_ft) { | |
97 | MLX5_SET(create_flow_table_in, in, table_miss_mode, 1); | |
98 | MLX5_SET(create_flow_table_in, in, table_miss_id, next_ft->id); | |
99 | } | |
100 | break; | |
101 | ||
102 | case FS_FT_OP_MOD_LAG_DEMUX: | |
103 | MLX5_SET(create_flow_table_in, in, op_mod, 0x1); | |
104 | if (next_ft) | |
105 | MLX5_SET(create_flow_table_in, in, lag_master_next_table_id, | |
106 | next_ft->id); | |
107 | break; | |
108 | } | |
109 | ||
c4f287c4 | 110 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
26a81453 MG |
111 | if (!err) |
112 | *table_id = MLX5_GET(create_flow_table_out, out, | |
113 | table_id); | |
114 | return err; | |
115 | } | |
116 | ||
117 | int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev, | |
118 | struct mlx5_flow_table *ft) | |
119 | { | |
c4f287c4 SM |
120 | u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {0}; |
121 | u32 out[MLX5_ST_SZ_DW(destroy_flow_table_out)] = {0}; | |
26a81453 MG |
122 | |
123 | MLX5_SET(destroy_flow_table_in, in, opcode, | |
124 | MLX5_CMD_OP_DESTROY_FLOW_TABLE); | |
125 | MLX5_SET(destroy_flow_table_in, in, table_type, ft->type); | |
126 | MLX5_SET(destroy_flow_table_in, in, table_id, ft->id); | |
efdc810b MHY |
127 | if (ft->vport) { |
128 | MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport); | |
129 | MLX5_SET(destroy_flow_table_in, in, other_vport, 1); | |
130 | } | |
26a81453 | 131 | |
c4f287c4 | 132 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
26a81453 MG |
133 | } |
134 | ||
34a40e68 MG |
135 | int mlx5_cmd_modify_flow_table(struct mlx5_core_dev *dev, |
136 | struct mlx5_flow_table *ft, | |
137 | struct mlx5_flow_table *next_ft) | |
138 | { | |
c4f287c4 SM |
139 | u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {0}; |
140 | u32 out[MLX5_ST_SZ_DW(modify_flow_table_out)] = {0}; | |
34a40e68 MG |
141 | |
142 | MLX5_SET(modify_flow_table_in, in, opcode, | |
143 | MLX5_CMD_OP_MODIFY_FLOW_TABLE); | |
144 | MLX5_SET(modify_flow_table_in, in, table_type, ft->type); | |
145 | MLX5_SET(modify_flow_table_in, in, table_id, ft->id); | |
aaff1bea AH |
146 | |
147 | if (ft->op_mod == FS_FT_OP_MOD_LAG_DEMUX) { | |
148 | MLX5_SET(modify_flow_table_in, in, modify_field_select, | |
149 | MLX5_MODIFY_FLOW_TABLE_LAG_NEXT_TABLE_ID); | |
150 | if (next_ft) { | |
151 | MLX5_SET(modify_flow_table_in, in, | |
152 | lag_master_next_table_id, next_ft->id); | |
153 | } else { | |
154 | MLX5_SET(modify_flow_table_in, in, | |
155 | lag_master_next_table_id, 0); | |
156 | } | |
34a40e68 | 157 | } else { |
aaff1bea AH |
158 | if (ft->vport) { |
159 | MLX5_SET(modify_flow_table_in, in, vport_number, | |
160 | ft->vport); | |
161 | MLX5_SET(modify_flow_table_in, in, other_vport, 1); | |
162 | } | |
163 | MLX5_SET(modify_flow_table_in, in, modify_field_select, | |
164 | MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID); | |
165 | if (next_ft) { | |
166 | MLX5_SET(modify_flow_table_in, in, table_miss_mode, 1); | |
167 | MLX5_SET(modify_flow_table_in, in, table_miss_id, | |
168 | next_ft->id); | |
169 | } else { | |
170 | MLX5_SET(modify_flow_table_in, in, table_miss_mode, 0); | |
171 | } | |
34a40e68 MG |
172 | } |
173 | ||
c4f287c4 | 174 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
34a40e68 MG |
175 | } |
176 | ||
26a81453 MG |
177 | int mlx5_cmd_create_flow_group(struct mlx5_core_dev *dev, |
178 | struct mlx5_flow_table *ft, | |
179 | u32 *in, | |
180 | unsigned int *group_id) | |
181 | { | |
c4f287c4 | 182 | u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {0}; |
26a81453 | 183 | int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); |
26a81453 MG |
184 | int err; |
185 | ||
26a81453 MG |
186 | MLX5_SET(create_flow_group_in, in, opcode, |
187 | MLX5_CMD_OP_CREATE_FLOW_GROUP); | |
188 | MLX5_SET(create_flow_group_in, in, table_type, ft->type); | |
189 | MLX5_SET(create_flow_group_in, in, table_id, ft->id); | |
efdc810b MHY |
190 | if (ft->vport) { |
191 | MLX5_SET(create_flow_group_in, in, vport_number, ft->vport); | |
192 | MLX5_SET(create_flow_group_in, in, other_vport, 1); | |
193 | } | |
26a81453 | 194 | |
c4f287c4 | 195 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); |
26a81453 MG |
196 | if (!err) |
197 | *group_id = MLX5_GET(create_flow_group_out, out, | |
198 | group_id); | |
26a81453 MG |
199 | return err; |
200 | } | |
201 | ||
202 | int mlx5_cmd_destroy_flow_group(struct mlx5_core_dev *dev, | |
203 | struct mlx5_flow_table *ft, | |
204 | unsigned int group_id) | |
205 | { | |
c4f287c4 SM |
206 | u32 out[MLX5_ST_SZ_DW(destroy_flow_group_out)] = {0}; |
207 | u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {0}; | |
26a81453 MG |
208 | |
209 | MLX5_SET(destroy_flow_group_in, in, opcode, | |
210 | MLX5_CMD_OP_DESTROY_FLOW_GROUP); | |
211 | MLX5_SET(destroy_flow_group_in, in, table_type, ft->type); | |
212 | MLX5_SET(destroy_flow_group_in, in, table_id, ft->id); | |
213 | MLX5_SET(destroy_flow_group_in, in, group_id, group_id); | |
efdc810b MHY |
214 | if (ft->vport) { |
215 | MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport); | |
216 | MLX5_SET(destroy_flow_group_in, in, other_vport, 1); | |
217 | } | |
26a81453 | 218 | |
c4f287c4 | 219 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
26a81453 MG |
220 | } |
221 | ||
222 | static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev, | |
223 | int opmod, int modify_mask, | |
224 | struct mlx5_flow_table *ft, | |
225 | unsigned group_id, | |
226 | struct fs_fte *fte) | |
227 | { | |
228 | unsigned int inlen = MLX5_ST_SZ_BYTES(set_fte_in) + | |
229 | fte->dests_size * MLX5_ST_SZ_BYTES(dest_format_struct); | |
c4f287c4 | 230 | u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0}; |
26a81453 MG |
231 | struct mlx5_flow_rule *dst; |
232 | void *in_flow_context; | |
233 | void *in_match_value; | |
234 | void *in_dests; | |
235 | u32 *in; | |
236 | int err; | |
237 | ||
1b9a07ee LR |
238 | in = kvzalloc(inlen, GFP_KERNEL); |
239 | if (!in) | |
26a81453 | 240 | return -ENOMEM; |
26a81453 MG |
241 | |
242 | MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY); | |
243 | MLX5_SET(set_fte_in, in, op_mod, opmod); | |
244 | MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask); | |
245 | MLX5_SET(set_fte_in, in, table_type, ft->type); | |
246 | MLX5_SET(set_fte_in, in, table_id, ft->id); | |
247 | MLX5_SET(set_fte_in, in, flow_index, fte->index); | |
efdc810b MHY |
248 | if (ft->vport) { |
249 | MLX5_SET(set_fte_in, in, vport_number, ft->vport); | |
250 | MLX5_SET(set_fte_in, in, other_vport, 1); | |
251 | } | |
26a81453 MG |
252 | |
253 | in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context); | |
254 | MLX5_SET(flow_context, in_flow_context, group_id, group_id); | |
255 | MLX5_SET(flow_context, in_flow_context, flow_tag, fte->flow_tag); | |
256 | MLX5_SET(flow_context, in_flow_context, action, fte->action); | |
66958ed9 | 257 | MLX5_SET(flow_context, in_flow_context, encap_id, fte->encap_id); |
2a69cb9f | 258 | MLX5_SET(flow_context, in_flow_context, modify_header_id, fte->modify_id); |
26a81453 MG |
259 | in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context, |
260 | match_value); | |
261 | memcpy(in_match_value, &fte->val, MLX5_ST_SZ_BYTES(fte_match_param)); | |
262 | ||
bd5251db | 263 | in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination); |
60ab4584 | 264 | if (fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) { |
bd5251db AV |
265 | int list_size = 0; |
266 | ||
60ab4584 AV |
267 | list_for_each_entry(dst, &fte->node.children, node.list) { |
268 | unsigned int id; | |
269 | ||
bd5251db AV |
270 | if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER) |
271 | continue; | |
272 | ||
60ab4584 AV |
273 | MLX5_SET(dest_format_struct, in_dests, destination_type, |
274 | dst->dest_attr.type); | |
275 | if (dst->dest_attr.type == | |
276 | MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) { | |
277 | id = dst->dest_attr.ft->id; | |
278 | } else { | |
279 | id = dst->dest_attr.tir_num; | |
280 | } | |
281 | MLX5_SET(dest_format_struct, in_dests, destination_id, id); | |
282 | in_dests += MLX5_ST_SZ_BYTES(dest_format_struct); | |
bd5251db AV |
283 | list_size++; |
284 | } | |
285 | ||
286 | MLX5_SET(flow_context, in_flow_context, destination_list_size, | |
287 | list_size); | |
288 | } | |
289 | ||
290 | if (fte->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { | |
291 | int list_size = 0; | |
292 | ||
293 | list_for_each_entry(dst, &fte->node.children, node.list) { | |
294 | if (dst->dest_attr.type != | |
295 | MLX5_FLOW_DESTINATION_TYPE_COUNTER) | |
296 | continue; | |
297 | ||
298 | MLX5_SET(flow_counter_list, in_dests, flow_counter_id, | |
299 | dst->dest_attr.counter->id); | |
300 | in_dests += MLX5_ST_SZ_BYTES(dest_format_struct); | |
301 | list_size++; | |
60ab4584 | 302 | } |
bd5251db AV |
303 | |
304 | MLX5_SET(flow_context, in_flow_context, flow_counter_list_size, | |
305 | list_size); | |
26a81453 | 306 | } |
bd5251db | 307 | |
c4f287c4 | 308 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); |
26a81453 | 309 | kvfree(in); |
26a81453 MG |
310 | return err; |
311 | } | |
312 | ||
313 | int mlx5_cmd_create_fte(struct mlx5_core_dev *dev, | |
314 | struct mlx5_flow_table *ft, | |
315 | unsigned group_id, | |
316 | struct fs_fte *fte) | |
317 | { | |
c4f287c4 | 318 | return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte); |
26a81453 MG |
319 | } |
320 | ||
321 | int mlx5_cmd_update_fte(struct mlx5_core_dev *dev, | |
322 | struct mlx5_flow_table *ft, | |
323 | unsigned group_id, | |
bd5251db | 324 | int modify_mask, |
26a81453 MG |
325 | struct fs_fte *fte) |
326 | { | |
327 | int opmod; | |
26a81453 MG |
328 | int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev, |
329 | flow_table_properties_nic_receive. | |
330 | flow_modify_en); | |
331 | if (!atomic_mod_cap) | |
9eb78923 | 332 | return -EOPNOTSUPP; |
26a81453 | 333 | opmod = 1; |
26a81453 MG |
334 | |
335 | return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, group_id, fte); | |
336 | } | |
337 | ||
338 | int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev, | |
339 | struct mlx5_flow_table *ft, | |
340 | unsigned int index) | |
341 | { | |
c4f287c4 SM |
342 | u32 out[MLX5_ST_SZ_DW(delete_fte_out)] = {0}; |
343 | u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {0}; | |
26a81453 MG |
344 | |
345 | MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY); | |
346 | MLX5_SET(delete_fte_in, in, table_type, ft->type); | |
347 | MLX5_SET(delete_fte_in, in, table_id, ft->id); | |
348 | MLX5_SET(delete_fte_in, in, flow_index, index); | |
efdc810b MHY |
349 | if (ft->vport) { |
350 | MLX5_SET(delete_fte_in, in, vport_number, ft->vport); | |
351 | MLX5_SET(delete_fte_in, in, other_vport, 1); | |
352 | } | |
26a81453 | 353 | |
c4f287c4 | 354 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
26a81453 | 355 | } |
9dc0b289 AV |
356 | |
357 | int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u16 *id) | |
358 | { | |
c4f287c4 SM |
359 | u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0}; |
360 | u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0}; | |
9dc0b289 AV |
361 | int err; |
362 | ||
9dc0b289 AV |
363 | MLX5_SET(alloc_flow_counter_in, in, opcode, |
364 | MLX5_CMD_OP_ALLOC_FLOW_COUNTER); | |
365 | ||
c4f287c4 SM |
366 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
367 | if (!err) | |
368 | *id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id); | |
369 | return err; | |
9dc0b289 AV |
370 | } |
371 | ||
372 | int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u16 id) | |
373 | { | |
c4f287c4 SM |
374 | u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {0}; |
375 | u32 out[MLX5_ST_SZ_DW(dealloc_flow_counter_out)] = {0}; | |
9dc0b289 AV |
376 | |
377 | MLX5_SET(dealloc_flow_counter_in, in, opcode, | |
378 | MLX5_CMD_OP_DEALLOC_FLOW_COUNTER); | |
379 | MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id); | |
c4f287c4 | 380 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
9dc0b289 AV |
381 | } |
382 | ||
383 | int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u16 id, | |
384 | u64 *packets, u64 *bytes) | |
385 | { | |
386 | u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) + | |
c4f287c4 SM |
387 | MLX5_ST_SZ_BYTES(traffic_counter)] = {0}; |
388 | u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0}; | |
9dc0b289 AV |
389 | void *stats; |
390 | int err = 0; | |
391 | ||
9dc0b289 AV |
392 | MLX5_SET(query_flow_counter_in, in, opcode, |
393 | MLX5_CMD_OP_QUERY_FLOW_COUNTER); | |
394 | MLX5_SET(query_flow_counter_in, in, op_mod, 0); | |
395 | MLX5_SET(query_flow_counter_in, in, flow_counter_id, id); | |
c4f287c4 | 396 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
9dc0b289 AV |
397 | if (err) |
398 | return err; | |
399 | ||
400 | stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics); | |
401 | *packets = MLX5_GET64(traffic_counter, stats, packets); | |
402 | *bytes = MLX5_GET64(traffic_counter, stats, octets); | |
9dc0b289 AV |
403 | return 0; |
404 | } | |
a351a1b0 AV |
405 | |
406 | struct mlx5_cmd_fc_bulk { | |
407 | u16 id; | |
408 | int num; | |
409 | int outlen; | |
410 | u32 out[0]; | |
411 | }; | |
412 | ||
413 | struct mlx5_cmd_fc_bulk * | |
414 | mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u16 id, int num) | |
415 | { | |
416 | struct mlx5_cmd_fc_bulk *b; | |
babd6134 | 417 | int outlen = |
a351a1b0 AV |
418 | MLX5_ST_SZ_BYTES(query_flow_counter_out) + |
419 | MLX5_ST_SZ_BYTES(traffic_counter) * num; | |
420 | ||
babd6134 | 421 | b = kzalloc(sizeof(*b) + outlen, GFP_KERNEL); |
a351a1b0 AV |
422 | if (!b) |
423 | return NULL; | |
424 | ||
425 | b->id = id; | |
426 | b->num = num; | |
427 | b->outlen = outlen; | |
428 | ||
429 | return b; | |
430 | } | |
431 | ||
432 | void mlx5_cmd_fc_bulk_free(struct mlx5_cmd_fc_bulk *b) | |
433 | { | |
434 | kfree(b); | |
435 | } | |
436 | ||
437 | int | |
438 | mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, struct mlx5_cmd_fc_bulk *b) | |
439 | { | |
c4f287c4 | 440 | u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0}; |
a351a1b0 AV |
441 | |
442 | MLX5_SET(query_flow_counter_in, in, opcode, | |
443 | MLX5_CMD_OP_QUERY_FLOW_COUNTER); | |
444 | MLX5_SET(query_flow_counter_in, in, op_mod, 0); | |
445 | MLX5_SET(query_flow_counter_in, in, flow_counter_id, b->id); | |
446 | MLX5_SET(query_flow_counter_in, in, num_of_counters, b->num); | |
c4f287c4 | 447 | return mlx5_cmd_exec(dev, in, sizeof(in), b->out, b->outlen); |
a351a1b0 AV |
448 | } |
449 | ||
450 | void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev, | |
451 | struct mlx5_cmd_fc_bulk *b, u16 id, | |
452 | u64 *packets, u64 *bytes) | |
453 | { | |
454 | int index = id - b->id; | |
455 | void *stats; | |
456 | ||
457 | if (index < 0 || index >= b->num) { | |
458 | mlx5_core_warn(dev, "Flow counter id (0x%x) out of range (0x%x..0x%x). Counter ignored.\n", | |
459 | id, b->id, b->id + b->num - 1); | |
460 | return; | |
461 | } | |
462 | ||
463 | stats = MLX5_ADDR_OF(query_flow_counter_out, b->out, | |
464 | flow_statistics[index]); | |
465 | *packets = MLX5_GET64(traffic_counter, stats, packets); | |
466 | *bytes = MLX5_GET64(traffic_counter, stats, octets); | |
467 | } | |
575ddf58 | 468 | |
ae9f83ac HHZ |
469 | int mlx5_encap_alloc(struct mlx5_core_dev *dev, |
470 | int header_type, | |
471 | size_t size, | |
472 | void *encap_header, | |
473 | u32 *encap_id) | |
575ddf58 | 474 | { |
43f93839 | 475 | int max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size); |
575ddf58 | 476 | u32 out[MLX5_ST_SZ_DW(alloc_encap_header_out)]; |
43f93839 HHZ |
477 | void *encap_header_in; |
478 | void *header; | |
479 | int inlen; | |
575ddf58 | 480 | int err; |
43f93839 | 481 | u32 *in; |
575ddf58 | 482 | |
073ff3c8 OG |
483 | if (size > max_encap_size) { |
484 | mlx5_core_warn(dev, "encap size %zd too big, max supported is %d\n", | |
485 | size, max_encap_size); | |
575ddf58 | 486 | return -EINVAL; |
073ff3c8 | 487 | } |
575ddf58 | 488 | |
073ff3c8 | 489 | in = kzalloc(MLX5_ST_SZ_BYTES(alloc_encap_header_in) + size, |
43f93839 HHZ |
490 | GFP_KERNEL); |
491 | if (!in) | |
492 | return -ENOMEM; | |
493 | ||
494 | encap_header_in = MLX5_ADDR_OF(alloc_encap_header_in, in, encap_header); | |
495 | header = MLX5_ADDR_OF(encap_header_in, encap_header_in, encap_header); | |
496 | inlen = header - (void *)in + size; | |
497 | ||
575ddf58 IL |
498 | memset(in, 0, inlen); |
499 | MLX5_SET(alloc_encap_header_in, in, opcode, | |
500 | MLX5_CMD_OP_ALLOC_ENCAP_HEADER); | |
501 | MLX5_SET(encap_header_in, encap_header_in, encap_header_size, size); | |
502 | MLX5_SET(encap_header_in, encap_header_in, header_type, header_type); | |
503 | memcpy(header, encap_header, size); | |
504 | ||
505 | memset(out, 0, sizeof(out)); | |
506 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); | |
507 | ||
508 | *encap_id = MLX5_GET(alloc_encap_header_out, out, encap_id); | |
43f93839 | 509 | kfree(in); |
575ddf58 IL |
510 | return err; |
511 | } | |
512 | ||
ae9f83ac | 513 | void mlx5_encap_dealloc(struct mlx5_core_dev *dev, u32 encap_id) |
575ddf58 IL |
514 | { |
515 | u32 in[MLX5_ST_SZ_DW(dealloc_encap_header_in)]; | |
516 | u32 out[MLX5_ST_SZ_DW(dealloc_encap_header_out)]; | |
517 | ||
518 | memset(in, 0, sizeof(in)); | |
519 | MLX5_SET(dealloc_encap_header_in, in, opcode, | |
520 | MLX5_CMD_OP_DEALLOC_ENCAP_HEADER); | |
521 | MLX5_SET(dealloc_encap_header_in, in, encap_id, encap_id); | |
522 | ||
523 | mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); | |
524 | } | |
2de24fed OG |
525 | |
526 | int mlx5_modify_header_alloc(struct mlx5_core_dev *dev, | |
527 | u8 namespace, u8 num_actions, | |
528 | void *modify_actions, u32 *modify_header_id) | |
529 | { | |
530 | u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)]; | |
531 | int max_actions, actions_size, inlen, err; | |
532 | void *actions_in; | |
533 | u8 table_type; | |
534 | u32 *in; | |
535 | ||
536 | switch (namespace) { | |
537 | case MLX5_FLOW_NAMESPACE_FDB: | |
538 | max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, max_modify_header_actions); | |
539 | table_type = FS_FT_FDB; | |
540 | break; | |
541 | case MLX5_FLOW_NAMESPACE_KERNEL: | |
542 | max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions); | |
543 | table_type = FS_FT_NIC_RX; | |
544 | break; | |
545 | default: | |
546 | return -EOPNOTSUPP; | |
547 | } | |
548 | ||
549 | if (num_actions > max_actions) { | |
550 | mlx5_core_warn(dev, "too many modify header actions %d, max supported %d\n", | |
551 | num_actions, max_actions); | |
552 | return -EOPNOTSUPP; | |
553 | } | |
554 | ||
555 | actions_size = MLX5_UN_SZ_BYTES(set_action_in_add_action_in_auto) * num_actions; | |
556 | inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size; | |
557 | ||
558 | in = kzalloc(inlen, GFP_KERNEL); | |
559 | if (!in) | |
560 | return -ENOMEM; | |
561 | ||
562 | MLX5_SET(alloc_modify_header_context_in, in, opcode, | |
563 | MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT); | |
564 | MLX5_SET(alloc_modify_header_context_in, in, table_type, table_type); | |
565 | MLX5_SET(alloc_modify_header_context_in, in, num_of_actions, num_actions); | |
566 | ||
567 | actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions); | |
568 | memcpy(actions_in, modify_actions, actions_size); | |
569 | ||
570 | memset(out, 0, sizeof(out)); | |
571 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); | |
572 | ||
573 | *modify_header_id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id); | |
574 | kfree(in); | |
575 | return err; | |
576 | } | |
577 | ||
578 | void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev, u32 modify_header_id) | |
579 | { | |
580 | u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)]; | |
581 | u32 out[MLX5_ST_SZ_DW(dealloc_modify_header_context_out)]; | |
582 | ||
583 | memset(in, 0, sizeof(in)); | |
584 | MLX5_SET(dealloc_modify_header_context_in, in, opcode, | |
585 | MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT); | |
586 | MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id, | |
587 | modify_header_id); | |
588 | ||
589 | mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); | |
590 | } |