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" | |
4a98544d | 39 | #include "fs_ft_pool.h" |
26a81453 | 40 | #include "mlx5_core.h" |
c9f1b073 | 41 | #include "eswitch.h" |
26a81453 | 42 | |
ae288a48 | 43 | static int mlx5_cmd_stub_update_root_ft(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
44 | struct mlx5_flow_table *ft, |
45 | u32 underlay_qpn, | |
46 | bool disconnect) | |
47 | { | |
48 | return 0; | |
49 | } | |
50 | ||
ae288a48 MG |
51 | static int mlx5_cmd_stub_create_flow_table(struct mlx5_flow_root_namespace *ns, |
52 | struct mlx5_flow_table *ft, | |
b0bb369e | 53 | struct mlx5_flow_table_attr *ft_attr, |
ae288a48 | 54 | struct mlx5_flow_table *next_ft) |
af76c501 | 55 | { |
b0bb369e MB |
56 | int max_fte = ft_attr->max_fte; |
57 | ||
58 | ft->max_fte = max_fte ? roundup_pow_of_two(max_fte) : 1; | |
04745afb | 59 | |
af76c501 MB |
60 | return 0; |
61 | } | |
62 | ||
ae288a48 | 63 | static int mlx5_cmd_stub_destroy_flow_table(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
64 | struct mlx5_flow_table *ft) |
65 | { | |
66 | return 0; | |
67 | } | |
68 | ||
ae288a48 | 69 | static int mlx5_cmd_stub_modify_flow_table(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
70 | struct mlx5_flow_table *ft, |
71 | struct mlx5_flow_table *next_ft) | |
72 | { | |
73 | return 0; | |
74 | } | |
75 | ||
ae288a48 | 76 | static int mlx5_cmd_stub_create_flow_group(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
77 | struct mlx5_flow_table *ft, |
78 | u32 *in, | |
ae288a48 | 79 | struct mlx5_flow_group *fg) |
af76c501 MB |
80 | { |
81 | return 0; | |
82 | } | |
83 | ||
ae288a48 | 84 | static int mlx5_cmd_stub_destroy_flow_group(struct mlx5_flow_root_namespace *ns, |
af76c501 | 85 | struct mlx5_flow_table *ft, |
ae288a48 | 86 | struct mlx5_flow_group *fg) |
af76c501 MB |
87 | { |
88 | return 0; | |
89 | } | |
90 | ||
ae288a48 | 91 | static int mlx5_cmd_stub_create_fte(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
92 | struct mlx5_flow_table *ft, |
93 | struct mlx5_flow_group *group, | |
94 | struct fs_fte *fte) | |
95 | { | |
96 | return 0; | |
97 | } | |
98 | ||
ae288a48 | 99 | static int mlx5_cmd_stub_update_fte(struct mlx5_flow_root_namespace *ns, |
af76c501 | 100 | struct mlx5_flow_table *ft, |
ae288a48 | 101 | struct mlx5_flow_group *group, |
af76c501 MB |
102 | int modify_mask, |
103 | struct fs_fte *fte) | |
104 | { | |
105 | return -EOPNOTSUPP; | |
106 | } | |
107 | ||
ae288a48 | 108 | static int mlx5_cmd_stub_delete_fte(struct mlx5_flow_root_namespace *ns, |
af76c501 | 109 | struct mlx5_flow_table *ft, |
e810bf5e | 110 | struct fs_fte *fte) |
af76c501 MB |
111 | { |
112 | return 0; | |
113 | } | |
114 | ||
2b688ea5 | 115 | static int mlx5_cmd_stub_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns, |
3f3f05ab | 116 | struct mlx5_pkt_reformat_params *params, |
2b688ea5 MG |
117 | enum mlx5_flow_namespace_type namespace, |
118 | struct mlx5_pkt_reformat *pkt_reformat) | |
119 | { | |
120 | return 0; | |
121 | } | |
122 | ||
123 | static void mlx5_cmd_stub_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns, | |
124 | struct mlx5_pkt_reformat *pkt_reformat) | |
125 | { | |
126 | } | |
127 | ||
128 | static int mlx5_cmd_stub_modify_header_alloc(struct mlx5_flow_root_namespace *ns, | |
129 | u8 namespace, u8 num_actions, | |
130 | void *modify_actions, | |
131 | struct mlx5_modify_hdr *modify_hdr) | |
132 | { | |
133 | return 0; | |
134 | } | |
135 | ||
136 | static void mlx5_cmd_stub_modify_header_dealloc(struct mlx5_flow_root_namespace *ns, | |
137 | struct mlx5_modify_hdr *modify_hdr) | |
138 | { | |
139 | } | |
140 | ||
6a48faee | 141 | static int mlx5_cmd_stub_set_peer(struct mlx5_flow_root_namespace *ns, |
6d5b7321 | 142 | struct mlx5_flow_root_namespace *peer_ns, |
62752c0b | 143 | u16 peer_vhca_id) |
6a48faee MG |
144 | { |
145 | return 0; | |
146 | } | |
147 | ||
148 | static int mlx5_cmd_stub_create_ns(struct mlx5_flow_root_namespace *ns) | |
149 | { | |
150 | return 0; | |
151 | } | |
152 | ||
153 | static int mlx5_cmd_stub_destroy_ns(struct mlx5_flow_root_namespace *ns) | |
154 | { | |
155 | return 0; | |
156 | } | |
157 | ||
8348b71c DC |
158 | static u32 mlx5_cmd_stub_get_capabilities(struct mlx5_flow_root_namespace *ns, |
159 | enum fs_flow_table_type ft_type) | |
160 | { | |
161 | return 0; | |
162 | } | |
163 | ||
db202995 MB |
164 | static int mlx5_cmd_set_slave_root_fdb(struct mlx5_core_dev *master, |
165 | struct mlx5_core_dev *slave, | |
166 | bool ft_id_valid, | |
167 | u32 ft_id) | |
168 | { | |
169 | u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {}; | |
170 | u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {}; | |
171 | struct mlx5_flow_root_namespace *root; | |
172 | struct mlx5_flow_namespace *ns; | |
173 | ||
174 | MLX5_SET(set_flow_table_root_in, in, opcode, | |
175 | MLX5_CMD_OP_SET_FLOW_TABLE_ROOT); | |
176 | MLX5_SET(set_flow_table_root_in, in, table_type, | |
177 | FS_FT_FDB); | |
178 | if (ft_id_valid) { | |
179 | MLX5_SET(set_flow_table_root_in, in, | |
180 | table_eswitch_owner_vhca_id_valid, 1); | |
181 | MLX5_SET(set_flow_table_root_in, in, | |
182 | table_eswitch_owner_vhca_id, | |
183 | MLX5_CAP_GEN(master, vhca_id)); | |
184 | MLX5_SET(set_flow_table_root_in, in, table_id, | |
185 | ft_id); | |
186 | } else { | |
187 | ns = mlx5_get_flow_namespace(slave, | |
188 | MLX5_FLOW_NAMESPACE_FDB); | |
189 | root = find_root(&ns->node); | |
190 | MLX5_SET(set_flow_table_root_in, in, table_id, | |
191 | root->root_ft->id); | |
192 | } | |
193 | ||
194 | return mlx5_cmd_exec(slave, in, sizeof(in), out, sizeof(out)); | |
195 | } | |
196 | ||
e7e2519e MG |
197 | static int |
198 | mlx5_cmd_stub_destroy_match_definer(struct mlx5_flow_root_namespace *ns, | |
199 | int definer_id) | |
200 | { | |
201 | return 0; | |
202 | } | |
203 | ||
204 | static int | |
205 | mlx5_cmd_stub_create_match_definer(struct mlx5_flow_root_namespace *ns, | |
206 | u16 format_id, u32 *match_mask) | |
207 | { | |
208 | return 0; | |
209 | } | |
210 | ||
ae288a48 | 211 | static int mlx5_cmd_update_root_ft(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
212 | struct mlx5_flow_table *ft, u32 underlay_qpn, |
213 | bool disconnect) | |
2cc43b49 | 214 | { |
31a0956e | 215 | u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {}; |
ae288a48 | 216 | struct mlx5_core_dev *dev = ns->dev; |
db202995 | 217 | int err; |
2cc43b49 | 218 | |
b3ba5149 | 219 | if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) && |
50854114 | 220 | underlay_qpn == 0) |
b3ba5149 ES |
221 | return 0; |
222 | ||
db202995 MB |
223 | if (ft->type == FS_FT_FDB && |
224 | mlx5_lag_is_shared_fdb(dev) && | |
225 | !mlx5_lag_is_master(dev)) | |
226 | return 0; | |
227 | ||
2cc43b49 MG |
228 | MLX5_SET(set_flow_table_root_in, in, opcode, |
229 | MLX5_CMD_OP_SET_FLOW_TABLE_ROOT); | |
230 | MLX5_SET(set_flow_table_root_in, in, table_type, ft->type); | |
dae37456 | 231 | |
31a0956e | 232 | if (disconnect) |
dae37456 | 233 | MLX5_SET(set_flow_table_root_in, in, op_mod, 1); |
31a0956e | 234 | else |
dae37456 | 235 | MLX5_SET(set_flow_table_root_in, in, table_id, ft->id); |
dae37456 | 236 | |
50854114 | 237 | MLX5_SET(set_flow_table_root_in, in, underlay_qpn, underlay_qpn); |
617b860c PP |
238 | MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport); |
239 | MLX5_SET(set_flow_table_root_in, in, other_vport, | |
240 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
2cc43b49 | 241 | |
db202995 MB |
242 | err = mlx5_cmd_exec_in(dev, set_flow_table_root, in); |
243 | if (!err && | |
244 | ft->type == FS_FT_FDB && | |
245 | mlx5_lag_is_shared_fdb(dev) && | |
246 | mlx5_lag_is_master(dev)) { | |
222dd185 | 247 | struct mlx5_core_dev *peer_dev; |
0fd23db0 | 248 | int i, j; |
222dd185 SD |
249 | |
250 | mlx5_lag_for_each_peer_mdev(dev, peer_dev, i) { | |
251 | err = mlx5_cmd_set_slave_root_fdb(dev, peer_dev, !disconnect, | |
252 | (!disconnect) ? ft->id : 0); | |
253 | if (err && !disconnect) { | |
0fd23db0 SD |
254 | mlx5_lag_for_each_peer_mdev(dev, peer_dev, j) { |
255 | if (j < i) | |
256 | mlx5_cmd_set_slave_root_fdb(dev, peer_dev, 1, | |
257 | ns->root_ft->id); | |
258 | else | |
259 | break; | |
260 | } | |
261 | ||
222dd185 SD |
262 | MLX5_SET(set_flow_table_root_in, in, op_mod, 0); |
263 | MLX5_SET(set_flow_table_root_in, in, table_id, | |
264 | ns->root_ft->id); | |
265 | mlx5_cmd_exec_in(dev, set_flow_table_root, in); | |
266 | } | |
267 | if (err) | |
268 | break; | |
db202995 | 269 | } |
222dd185 | 270 | |
db202995 MB |
271 | } |
272 | ||
273 | return err; | |
2cc43b49 MG |
274 | } |
275 | ||
ae288a48 MG |
276 | static int mlx5_cmd_create_flow_table(struct mlx5_flow_root_namespace *ns, |
277 | struct mlx5_flow_table *ft, | |
b0bb369e | 278 | struct mlx5_flow_table_attr *ft_attr, |
ae288a48 | 279 | struct mlx5_flow_table *next_ft) |
26a81453 | 280 | { |
ae288a48 MG |
281 | int en_encap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT); |
282 | int en_decap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_DECAP); | |
c6d4e45d | 283 | int term = !!(ft->flags & MLX5_FLOW_TABLE_TERMINATION); |
31a0956e LR |
284 | u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {}; |
285 | u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {}; | |
ae288a48 | 286 | struct mlx5_core_dev *dev = ns->dev; |
b0bb369e | 287 | unsigned int size; |
26a81453 MG |
288 | int err; |
289 | ||
b0bb369e | 290 | size = mlx5_ft_pool_get_avail_sz(dev, ft->type, ft_attr->max_fte); |
4a98544d PB |
291 | if (!size) |
292 | return -ENOSPC; | |
04745afb | 293 | |
26a81453 MG |
294 | MLX5_SET(create_flow_table_in, in, opcode, |
295 | MLX5_CMD_OP_CREATE_FLOW_TABLE); | |
296 | ||
b0bb369e | 297 | MLX5_SET(create_flow_table_in, in, uid, ft_attr->uid); |
ae288a48 MG |
298 | MLX5_SET(create_flow_table_in, in, table_type, ft->type); |
299 | MLX5_SET(create_flow_table_in, in, flow_table_context.level, ft->level); | |
4a98544d | 300 | MLX5_SET(create_flow_table_in, in, flow_table_context.log_size, size ? ilog2(size) : 0); |
617b860c PP |
301 | MLX5_SET(create_flow_table_in, in, vport_number, ft->vport); |
302 | MLX5_SET(create_flow_table_in, in, other_vport, | |
303 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
26a81453 | 304 | |
0c90e9c6 | 305 | MLX5_SET(create_flow_table_in, in, flow_table_context.decap_en, |
61444b45 | 306 | en_decap); |
60786f09 | 307 | MLX5_SET(create_flow_table_in, in, flow_table_context.reformat_en, |
61444b45 | 308 | en_encap); |
c6d4e45d EB |
309 | MLX5_SET(create_flow_table_in, in, flow_table_context.termination_table, |
310 | term); | |
c9f1b073 | 311 | |
ae288a48 | 312 | switch (ft->op_mod) { |
aaff1bea AH |
313 | case FS_FT_OP_MOD_NORMAL: |
314 | if (next_ft) { | |
0c90e9c6 | 315 | MLX5_SET(create_flow_table_in, in, |
f6f7d6b5 MG |
316 | flow_table_context.table_miss_action, |
317 | MLX5_FLOW_TABLE_MISS_ACTION_FWD); | |
0c90e9c6 MG |
318 | MLX5_SET(create_flow_table_in, in, |
319 | flow_table_context.table_miss_id, next_ft->id); | |
f6f7d6b5 MG |
320 | } else { |
321 | MLX5_SET(create_flow_table_in, in, | |
322 | flow_table_context.table_miss_action, | |
f66ad830 | 323 | ft->def_miss_action); |
aaff1bea AH |
324 | } |
325 | break; | |
326 | ||
327 | case FS_FT_OP_MOD_LAG_DEMUX: | |
328 | MLX5_SET(create_flow_table_in, in, op_mod, 0x1); | |
329 | if (next_ft) | |
0c90e9c6 MG |
330 | MLX5_SET(create_flow_table_in, in, |
331 | flow_table_context.lag_master_next_table_id, | |
aaff1bea AH |
332 | next_ft->id); |
333 | break; | |
334 | } | |
335 | ||
31a0956e | 336 | err = mlx5_cmd_exec_inout(dev, create_flow_table, in, out); |
4a98544d | 337 | if (!err) { |
ae288a48 MG |
338 | ft->id = MLX5_GET(create_flow_table_out, out, |
339 | table_id); | |
4a98544d PB |
340 | ft->max_fte = size; |
341 | } else { | |
342 | mlx5_ft_pool_put_sz(ns->dev, size); | |
343 | } | |
344 | ||
26a81453 MG |
345 | return err; |
346 | } | |
347 | ||
ae288a48 | 348 | static int mlx5_cmd_destroy_flow_table(struct mlx5_flow_root_namespace *ns, |
af76c501 | 349 | struct mlx5_flow_table *ft) |
26a81453 | 350 | { |
31a0956e | 351 | u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {}; |
ae288a48 | 352 | struct mlx5_core_dev *dev = ns->dev; |
4a98544d | 353 | int err; |
26a81453 MG |
354 | |
355 | MLX5_SET(destroy_flow_table_in, in, opcode, | |
356 | MLX5_CMD_OP_DESTROY_FLOW_TABLE); | |
357 | MLX5_SET(destroy_flow_table_in, in, table_type, ft->type); | |
358 | MLX5_SET(destroy_flow_table_in, in, table_id, ft->id); | |
617b860c PP |
359 | MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport); |
360 | MLX5_SET(destroy_flow_table_in, in, other_vport, | |
361 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
26a81453 | 362 | |
4a98544d PB |
363 | err = mlx5_cmd_exec_in(dev, destroy_flow_table, in); |
364 | if (!err) | |
365 | mlx5_ft_pool_put_sz(ns->dev, ft->max_fte); | |
366 | ||
367 | return err; | |
26a81453 MG |
368 | } |
369 | ||
ae288a48 | 370 | static int mlx5_cmd_modify_flow_table(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
371 | struct mlx5_flow_table *ft, |
372 | struct mlx5_flow_table *next_ft) | |
34a40e68 | 373 | { |
31a0956e | 374 | u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {}; |
ae288a48 | 375 | struct mlx5_core_dev *dev = ns->dev; |
34a40e68 MG |
376 | |
377 | MLX5_SET(modify_flow_table_in, in, opcode, | |
378 | MLX5_CMD_OP_MODIFY_FLOW_TABLE); | |
379 | MLX5_SET(modify_flow_table_in, in, table_type, ft->type); | |
380 | MLX5_SET(modify_flow_table_in, in, table_id, ft->id); | |
aaff1bea AH |
381 | |
382 | if (ft->op_mod == FS_FT_OP_MOD_LAG_DEMUX) { | |
383 | MLX5_SET(modify_flow_table_in, in, modify_field_select, | |
384 | MLX5_MODIFY_FLOW_TABLE_LAG_NEXT_TABLE_ID); | |
385 | if (next_ft) { | |
386 | MLX5_SET(modify_flow_table_in, in, | |
0c90e9c6 | 387 | flow_table_context.lag_master_next_table_id, next_ft->id); |
aaff1bea AH |
388 | } else { |
389 | MLX5_SET(modify_flow_table_in, in, | |
0c90e9c6 | 390 | flow_table_context.lag_master_next_table_id, 0); |
aaff1bea | 391 | } |
34a40e68 | 392 | } else { |
617b860c PP |
393 | MLX5_SET(modify_flow_table_in, in, vport_number, ft->vport); |
394 | MLX5_SET(modify_flow_table_in, in, other_vport, | |
395 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
aaff1bea AH |
396 | MLX5_SET(modify_flow_table_in, in, modify_field_select, |
397 | MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID); | |
398 | if (next_ft) { | |
0c90e9c6 | 399 | MLX5_SET(modify_flow_table_in, in, |
f6f7d6b5 MG |
400 | flow_table_context.table_miss_action, |
401 | MLX5_FLOW_TABLE_MISS_ACTION_FWD); | |
0c90e9c6 MG |
402 | MLX5_SET(modify_flow_table_in, in, |
403 | flow_table_context.table_miss_id, | |
aaff1bea AH |
404 | next_ft->id); |
405 | } else { | |
0c90e9c6 | 406 | MLX5_SET(modify_flow_table_in, in, |
f6f7d6b5 | 407 | flow_table_context.table_miss_action, |
f66ad830 | 408 | ft->def_miss_action); |
aaff1bea | 409 | } |
34a40e68 MG |
410 | } |
411 | ||
31a0956e | 412 | return mlx5_cmd_exec_in(dev, modify_flow_table, in); |
34a40e68 MG |
413 | } |
414 | ||
ae288a48 | 415 | static int mlx5_cmd_create_flow_group(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
416 | struct mlx5_flow_table *ft, |
417 | u32 *in, | |
ae288a48 | 418 | struct mlx5_flow_group *fg) |
26a81453 | 419 | { |
31a0956e | 420 | u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {}; |
ae288a48 | 421 | struct mlx5_core_dev *dev = ns->dev; |
26a81453 MG |
422 | int err; |
423 | ||
26a81453 MG |
424 | MLX5_SET(create_flow_group_in, in, opcode, |
425 | MLX5_CMD_OP_CREATE_FLOW_GROUP); | |
426 | MLX5_SET(create_flow_group_in, in, table_type, ft->type); | |
427 | MLX5_SET(create_flow_group_in, in, table_id, ft->id); | |
617b860c PP |
428 | MLX5_SET(create_flow_group_in, in, vport_number, ft->vport); |
429 | MLX5_SET(create_flow_group_in, in, other_vport, | |
430 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
31a0956e | 431 | err = mlx5_cmd_exec_inout(dev, create_flow_group, in, out); |
26a81453 | 432 | if (!err) |
ae288a48 MG |
433 | fg->id = MLX5_GET(create_flow_group_out, out, |
434 | group_id); | |
26a81453 MG |
435 | return err; |
436 | } | |
437 | ||
ae288a48 | 438 | static int mlx5_cmd_destroy_flow_group(struct mlx5_flow_root_namespace *ns, |
af76c501 | 439 | struct mlx5_flow_table *ft, |
ae288a48 | 440 | struct mlx5_flow_group *fg) |
26a81453 | 441 | { |
31a0956e | 442 | u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {}; |
ae288a48 | 443 | struct mlx5_core_dev *dev = ns->dev; |
26a81453 MG |
444 | |
445 | MLX5_SET(destroy_flow_group_in, in, opcode, | |
446 | MLX5_CMD_OP_DESTROY_FLOW_GROUP); | |
447 | MLX5_SET(destroy_flow_group_in, in, table_type, ft->type); | |
448 | MLX5_SET(destroy_flow_group_in, in, table_id, ft->id); | |
ae288a48 | 449 | MLX5_SET(destroy_flow_group_in, in, group_id, fg->id); |
617b860c PP |
450 | MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport); |
451 | MLX5_SET(destroy_flow_group_in, in, other_vport, | |
452 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
31a0956e | 453 | return mlx5_cmd_exec_in(dev, destroy_flow_group, in); |
26a81453 MG |
454 | } |
455 | ||
a2c6162b EB |
456 | static int mlx5_set_extended_dest(struct mlx5_core_dev *dev, |
457 | struct fs_fte *fte, bool *extended_dest) | |
458 | { | |
459 | int fw_log_max_fdb_encap_uplink = | |
460 | MLX5_CAP_ESW(dev, log_max_fdb_encap_uplink); | |
461 | int num_fwd_destinations = 0; | |
462 | struct mlx5_flow_rule *dst; | |
463 | int num_encap = 0; | |
464 | ||
465 | *extended_dest = false; | |
466 | if (!(fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST)) | |
467 | return 0; | |
468 | ||
469 | list_for_each_entry(dst, &fte->node.children, node.list) { | |
6510bc0d MB |
470 | if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER || |
471 | dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_NONE) | |
a2c6162b | 472 | continue; |
e3a0f40b YK |
473 | if ((dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_VPORT || |
474 | dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_UPLINK) && | |
a2c6162b EB |
475 | dst->dest_attr.vport.flags & MLX5_FLOW_DEST_VPORT_REFORMAT_ID) |
476 | num_encap++; | |
477 | num_fwd_destinations++; | |
478 | } | |
479 | if (num_fwd_destinations > 1 && num_encap > 0) | |
480 | *extended_dest = true; | |
481 | ||
482 | if (*extended_dest && !fw_log_max_fdb_encap_uplink) { | |
483 | mlx5_core_warn(dev, "FW does not support extended destination"); | |
484 | return -EOPNOTSUPP; | |
485 | } | |
486 | if (num_encap > (1 << fw_log_max_fdb_encap_uplink)) { | |
487 | mlx5_core_warn(dev, "FW does not support more than %d encaps", | |
488 | 1 << fw_log_max_fdb_encap_uplink); | |
489 | return -EOPNOTSUPP; | |
490 | } | |
491 | ||
492 | return 0; | |
493 | } | |
91707779 JL |
494 | |
495 | static void | |
496 | mlx5_cmd_set_fte_flow_meter(struct fs_fte *fte, void *in_flow_context) | |
497 | { | |
498 | void *exe_aso_ctrl; | |
499 | void *execute_aso; | |
500 | ||
501 | execute_aso = MLX5_ADDR_OF(flow_context, in_flow_context, | |
502 | execute_aso[0]); | |
503 | MLX5_SET(execute_aso, execute_aso, valid, 1); | |
504 | MLX5_SET(execute_aso, execute_aso, aso_object_id, | |
505 | fte->action.exe_aso.object_id); | |
506 | ||
507 | exe_aso_ctrl = MLX5_ADDR_OF(execute_aso, execute_aso, exe_aso_ctrl); | |
508 | MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, return_reg_id, | |
509 | fte->action.exe_aso.return_reg_id); | |
510 | MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, aso_type, | |
511 | fte->action.exe_aso.type); | |
512 | MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, init_color, | |
513 | fte->action.exe_aso.flow_meter.init_color); | |
514 | MLX5_SET(exe_aso_ctrl_flow_meter, exe_aso_ctrl, meter_id, | |
515 | fte->action.exe_aso.flow_meter.meter_idx); | |
516 | } | |
517 | ||
26a81453 MG |
518 | static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev, |
519 | int opmod, int modify_mask, | |
520 | struct mlx5_flow_table *ft, | |
521 | unsigned group_id, | |
522 | struct fs_fte *fte) | |
523 | { | |
c4f287c4 | 524 | u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0}; |
a2c6162b | 525 | bool extended_dest = false; |
26a81453 | 526 | struct mlx5_flow_rule *dst; |
0c06897a | 527 | void *in_flow_context, *vlan; |
26a81453 | 528 | void *in_match_value; |
87cd0649 | 529 | int reformat_id = 0; |
a2c6162b EB |
530 | unsigned int inlen; |
531 | int dst_cnt_size; | |
87cd0649 | 532 | u32 *in, action; |
26a81453 | 533 | void *in_dests; |
26a81453 MG |
534 | int err; |
535 | ||
a2c6162b EB |
536 | if (mlx5_set_extended_dest(dev, fte, &extended_dest)) |
537 | return -EOPNOTSUPP; | |
538 | ||
539 | if (!extended_dest) | |
540 | dst_cnt_size = MLX5_ST_SZ_BYTES(dest_format_struct); | |
541 | else | |
542 | dst_cnt_size = MLX5_ST_SZ_BYTES(extended_dest_format); | |
543 | ||
544 | inlen = MLX5_ST_SZ_BYTES(set_fte_in) + fte->dests_size * dst_cnt_size; | |
1b9a07ee LR |
545 | in = kvzalloc(inlen, GFP_KERNEL); |
546 | if (!in) | |
26a81453 | 547 | return -ENOMEM; |
26a81453 MG |
548 | |
549 | MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY); | |
550 | MLX5_SET(set_fte_in, in, op_mod, opmod); | |
551 | MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask); | |
552 | MLX5_SET(set_fte_in, in, table_type, ft->type); | |
553 | MLX5_SET(set_fte_in, in, table_id, ft->id); | |
554 | MLX5_SET(set_fte_in, in, flow_index, fte->index); | |
ff189b43 PB |
555 | MLX5_SET(set_fte_in, in, ignore_flow_level, |
556 | !!(fte->action.flags & FLOW_ACT_IGNORE_FLOW_LEVEL)); | |
557 | ||
617b860c PP |
558 | MLX5_SET(set_fte_in, in, vport_number, ft->vport); |
559 | MLX5_SET(set_fte_in, in, other_vport, | |
560 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
26a81453 MG |
561 | |
562 | in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context); | |
563 | MLX5_SET(flow_context, in_flow_context, group_id, group_id); | |
0c06897a | 564 | |
bb0ee7dc JL |
565 | MLX5_SET(flow_context, in_flow_context, flow_tag, |
566 | fte->flow_context.flow_tag); | |
8d212ff0 JL |
567 | MLX5_SET(flow_context, in_flow_context, flow_source, |
568 | fte->flow_context.flow_source); | |
ec7cc38e MS |
569 | MLX5_SET(flow_context, in_flow_context, uplink_hairpin_en, |
570 | !!(fte->flow_context.flags & FLOW_CONTEXT_UPLINK_HAIRPIN_EN)); | |
8d212ff0 | 571 | |
a2c6162b EB |
572 | MLX5_SET(flow_context, in_flow_context, extended_destination, |
573 | extended_dest); | |
a2c6162b | 574 | |
87cd0649 YK |
575 | action = fte->action.action; |
576 | if (extended_dest) | |
577 | action &= ~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT; | |
578 | ||
579 | MLX5_SET(flow_context, in_flow_context, action, action); | |
580 | ||
581 | if (!extended_dest && fte->action.pkt_reformat) { | |
582 | struct mlx5_pkt_reformat *pkt_reformat = fte->action.pkt_reformat; | |
583 | ||
584 | if (pkt_reformat->owner == MLX5_FLOW_RESOURCE_OWNER_SW) { | |
585 | reformat_id = mlx5_fs_dr_action_get_pkt_reformat_id(pkt_reformat); | |
586 | if (reformat_id < 0) { | |
587 | mlx5_core_err(dev, | |
588 | "Unsupported SW-owned pkt_reformat type (%d) in FW-owned table\n", | |
589 | pkt_reformat->reformat_type); | |
590 | err = reformat_id; | |
591 | goto err_out; | |
592 | } | |
593 | } else { | |
594 | reformat_id = fte->action.pkt_reformat->id; | |
595 | } | |
a2c6162b | 596 | } |
87cd0649 YK |
597 | |
598 | MLX5_SET(flow_context, in_flow_context, packet_reformat_id, (u32)reformat_id); | |
599 | ||
600 | if (fte->action.modify_hdr) { | |
601 | if (fte->action.modify_hdr->owner == MLX5_FLOW_RESOURCE_OWNER_SW) { | |
602 | mlx5_core_err(dev, "Can't use SW-owned modify_hdr in FW-owned table\n"); | |
603 | err = -EOPNOTSUPP; | |
604 | goto err_out; | |
605 | } | |
606 | ||
2b688ea5 MG |
607 | MLX5_SET(flow_context, in_flow_context, modify_header_id, |
608 | fte->action.modify_hdr->id); | |
87cd0649 | 609 | } |
0c06897a | 610 | |
e227ee99 LN |
611 | MLX5_SET(flow_context, in_flow_context, encrypt_decrypt_type, |
612 | fte->action.crypto.type); | |
613 | MLX5_SET(flow_context, in_flow_context, encrypt_decrypt_obj_id, | |
614 | fte->action.crypto.obj_id); | |
5e466345 | 615 | |
0c06897a OG |
616 | vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan); |
617 | ||
8da6fe2a JL |
618 | MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[0].ethtype); |
619 | MLX5_SET(vlan, vlan, vid, fte->action.vlan[0].vid); | |
620 | MLX5_SET(vlan, vlan, prio, fte->action.vlan[0].prio); | |
621 | ||
622 | vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan_2); | |
623 | ||
624 | MLX5_SET(vlan, vlan, ethtype, fte->action.vlan[1].ethtype); | |
625 | MLX5_SET(vlan, vlan, vid, fte->action.vlan[1].vid); | |
626 | MLX5_SET(vlan, vlan, prio, fte->action.vlan[1].prio); | |
0c06897a | 627 | |
26a81453 MG |
628 | in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context, |
629 | match_value); | |
667cb65a | 630 | memcpy(in_match_value, &fte->val, sizeof(fte->val)); |
26a81453 | 631 | |
bd5251db | 632 | in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination); |
d2ec6a35 | 633 | if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) { |
bd5251db AV |
634 | int list_size = 0; |
635 | ||
60ab4584 | 636 | list_for_each_entry(dst, &fte->node.children, node.list) { |
d639af62 MB |
637 | enum mlx5_flow_destination_type type = dst->dest_attr.type; |
638 | enum mlx5_ifc_flow_destination_type ifc_type; | |
639 | unsigned int id; | |
60ab4584 | 640 | |
664000b6 | 641 | if (type == MLX5_FLOW_DESTINATION_TYPE_COUNTER) |
bd5251db AV |
642 | continue; |
643 | ||
664000b6 | 644 | switch (type) { |
6510bc0d MB |
645 | case MLX5_FLOW_DESTINATION_TYPE_NONE: |
646 | continue; | |
664000b6 YH |
647 | case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM: |
648 | id = dst->dest_attr.ft_num; | |
d639af62 | 649 | ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_FLOW_TABLE; |
664000b6 YH |
650 | break; |
651 | case MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE: | |
60ab4584 | 652 | id = dst->dest_attr.ft->id; |
d639af62 | 653 | ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_FLOW_TABLE; |
664000b6 | 654 | break; |
58a606db | 655 | case MLX5_FLOW_DESTINATION_TYPE_UPLINK: |
664000b6 | 656 | case MLX5_FLOW_DESTINATION_TYPE_VPORT: |
b17f7fc1 SK |
657 | MLX5_SET(dest_format_struct, in_dests, |
658 | destination_eswitch_owner_vhca_id_valid, | |
aa39c2c0 EB |
659 | !!(dst->dest_attr.vport.flags & |
660 | MLX5_FLOW_DEST_VPORT_VHCA_ID)); | |
b17f7fc1 SK |
661 | MLX5_SET(dest_format_struct, in_dests, |
662 | destination_eswitch_owner_vhca_id, | |
663 | dst->dest_attr.vport.vhca_id); | |
58a606db MG |
664 | if (type == MLX5_FLOW_DESTINATION_TYPE_UPLINK) { |
665 | /* destination_id is reserved */ | |
666 | id = 0; | |
d639af62 | 667 | ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_UPLINK; |
58a606db MG |
668 | break; |
669 | } | |
d639af62 | 670 | ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_VPORT; |
58a606db | 671 | id = dst->dest_attr.vport.num; |
0fd79b1e EB |
672 | if (extended_dest && |
673 | dst->dest_attr.vport.pkt_reformat) { | |
a2c6162b EB |
674 | MLX5_SET(dest_format_struct, in_dests, |
675 | packet_reformat, | |
676 | !!(dst->dest_attr.vport.flags & | |
677 | MLX5_FLOW_DEST_VPORT_REFORMAT_ID)); | |
678 | MLX5_SET(extended_dest_format, in_dests, | |
679 | packet_reformat_id, | |
2b688ea5 | 680 | dst->dest_attr.vport.pkt_reformat->id); |
a2c6162b | 681 | } |
664000b6 | 682 | break; |
38730630 CM |
683 | case MLX5_FLOW_DESTINATION_TYPE_FLOW_SAMPLER: |
684 | id = dst->dest_attr.sampler_id; | |
d639af62 | 685 | ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_FLOW_SAMPLER; |
38730630 | 686 | break; |
4f226b71 MZ |
687 | case MLX5_FLOW_DESTINATION_TYPE_TABLE_TYPE: |
688 | MLX5_SET(dest_format_struct, in_dests, | |
689 | destination_table_type, dst->dest_attr.ft->type); | |
690 | id = dst->dest_attr.ft->id; | |
691 | ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_TABLE_TYPE; | |
692 | break; | |
664000b6 | 693 | default: |
60ab4584 | 694 | id = dst->dest_attr.tir_num; |
d639af62 | 695 | ifc_type = MLX5_IFC_FLOW_DESTINATION_TYPE_TIR; |
60ab4584 | 696 | } |
664000b6 YH |
697 | |
698 | MLX5_SET(dest_format_struct, in_dests, destination_type, | |
d639af62 | 699 | ifc_type); |
60ab4584 | 700 | MLX5_SET(dest_format_struct, in_dests, destination_id, id); |
a2c6162b | 701 | in_dests += dst_cnt_size; |
bd5251db AV |
702 | list_size++; |
703 | } | |
704 | ||
705 | MLX5_SET(flow_context, in_flow_context, destination_list_size, | |
706 | list_size); | |
707 | } | |
708 | ||
d2ec6a35 | 709 | if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
16f1c5bb RS |
710 | int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev, |
711 | log_max_flow_counter, | |
712 | ft->type)); | |
bd5251db AV |
713 | int list_size = 0; |
714 | ||
715 | list_for_each_entry(dst, &fte->node.children, node.list) { | |
716 | if (dst->dest_attr.type != | |
717 | MLX5_FLOW_DESTINATION_TYPE_COUNTER) | |
718 | continue; | |
719 | ||
720 | MLX5_SET(flow_counter_list, in_dests, flow_counter_id, | |
171c7625 | 721 | dst->dest_attr.counter_id); |
a2c6162b | 722 | in_dests += dst_cnt_size; |
bd5251db | 723 | list_size++; |
60ab4584 | 724 | } |
16f1c5bb RS |
725 | if (list_size > max_list_size) { |
726 | err = -EINVAL; | |
727 | goto err_out; | |
728 | } | |
bd5251db AV |
729 | |
730 | MLX5_SET(flow_context, in_flow_context, flow_counter_list_size, | |
731 | list_size); | |
26a81453 | 732 | } |
bd5251db | 733 | |
91707779 JL |
734 | if (fte->action.action & MLX5_FLOW_CONTEXT_ACTION_EXECUTE_ASO) { |
735 | if (fte->action.exe_aso.type == MLX5_EXE_ASO_FLOW_METER) { | |
736 | mlx5_cmd_set_fte_flow_meter(fte, in_flow_context); | |
737 | } else { | |
738 | err = -EOPNOTSUPP; | |
739 | goto err_out; | |
740 | } | |
741 | } | |
742 | ||
c4f287c4 | 743 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); |
16f1c5bb | 744 | err_out: |
26a81453 | 745 | kvfree(in); |
26a81453 MG |
746 | return err; |
747 | } | |
748 | ||
ae288a48 | 749 | static int mlx5_cmd_create_fte(struct mlx5_flow_root_namespace *ns, |
af76c501 MB |
750 | struct mlx5_flow_table *ft, |
751 | struct mlx5_flow_group *group, | |
752 | struct fs_fte *fte) | |
26a81453 | 753 | { |
ae288a48 | 754 | struct mlx5_core_dev *dev = ns->dev; |
af76c501 MB |
755 | unsigned int group_id = group->id; |
756 | ||
c4f287c4 | 757 | return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte); |
26a81453 MG |
758 | } |
759 | ||
ae288a48 | 760 | static int mlx5_cmd_update_fte(struct mlx5_flow_root_namespace *ns, |
af76c501 | 761 | struct mlx5_flow_table *ft, |
ae288a48 | 762 | struct mlx5_flow_group *fg, |
af76c501 MB |
763 | int modify_mask, |
764 | struct fs_fte *fte) | |
26a81453 MG |
765 | { |
766 | int opmod; | |
ae288a48 | 767 | struct mlx5_core_dev *dev = ns->dev; |
26a81453 MG |
768 | int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev, |
769 | flow_table_properties_nic_receive. | |
770 | flow_modify_en); | |
771 | if (!atomic_mod_cap) | |
9eb78923 | 772 | return -EOPNOTSUPP; |
26a81453 | 773 | opmod = 1; |
26a81453 | 774 | |
ae288a48 | 775 | return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, fg->id, fte); |
26a81453 MG |
776 | } |
777 | ||
ae288a48 | 778 | static int mlx5_cmd_delete_fte(struct mlx5_flow_root_namespace *ns, |
af76c501 | 779 | struct mlx5_flow_table *ft, |
e810bf5e | 780 | struct fs_fte *fte) |
26a81453 | 781 | { |
31a0956e | 782 | u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {}; |
ae288a48 | 783 | struct mlx5_core_dev *dev = ns->dev; |
26a81453 MG |
784 | |
785 | MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY); | |
786 | MLX5_SET(delete_fte_in, in, table_type, ft->type); | |
787 | MLX5_SET(delete_fte_in, in, table_id, ft->id); | |
e810bf5e | 788 | MLX5_SET(delete_fte_in, in, flow_index, fte->index); |
617b860c PP |
789 | MLX5_SET(delete_fte_in, in, vport_number, ft->vport); |
790 | MLX5_SET(delete_fte_in, in, other_vport, | |
791 | !!(ft->flags & MLX5_FLOW_TABLE_OTHER_VPORT)); | |
26a81453 | 792 | |
31a0956e | 793 | return mlx5_cmd_exec_in(dev, delete_fte, in); |
26a81453 | 794 | } |
9dc0b289 | 795 | |
8536a6bf GT |
796 | int mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, |
797 | enum mlx5_fc_bulk_alloc_bitmask alloc_bitmask, | |
798 | u32 *id) | |
9dc0b289 | 799 | { |
31a0956e LR |
800 | u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {}; |
801 | u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {}; | |
9dc0b289 AV |
802 | int err; |
803 | ||
9dc0b289 AV |
804 | MLX5_SET(alloc_flow_counter_in, in, opcode, |
805 | MLX5_CMD_OP_ALLOC_FLOW_COUNTER); | |
8536a6bf | 806 | MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk, alloc_bitmask); |
9dc0b289 | 807 | |
31a0956e | 808 | err = mlx5_cmd_exec_inout(dev, alloc_flow_counter, in, out); |
c4f287c4 SM |
809 | if (!err) |
810 | *id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id); | |
811 | return err; | |
9dc0b289 AV |
812 | } |
813 | ||
8536a6bf GT |
814 | int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id) |
815 | { | |
816 | return mlx5_cmd_fc_bulk_alloc(dev, 0, id); | |
817 | } | |
818 | ||
a8ffcc74 | 819 | int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id) |
9dc0b289 | 820 | { |
31a0956e | 821 | u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {}; |
9dc0b289 AV |
822 | |
823 | MLX5_SET(dealloc_flow_counter_in, in, opcode, | |
824 | MLX5_CMD_OP_DEALLOC_FLOW_COUNTER); | |
825 | MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id); | |
31a0956e | 826 | return mlx5_cmd_exec_in(dev, dealloc_flow_counter, in); |
9dc0b289 AV |
827 | } |
828 | ||
a8ffcc74 | 829 | int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id, |
9dc0b289 AV |
830 | u64 *packets, u64 *bytes) |
831 | { | |
832 | u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) + | |
31a0956e LR |
833 | MLX5_ST_SZ_BYTES(traffic_counter)] = {}; |
834 | u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {}; | |
9dc0b289 AV |
835 | void *stats; |
836 | int err = 0; | |
837 | ||
9dc0b289 AV |
838 | MLX5_SET(query_flow_counter_in, in, opcode, |
839 | MLX5_CMD_OP_QUERY_FLOW_COUNTER); | |
840 | MLX5_SET(query_flow_counter_in, in, op_mod, 0); | |
841 | MLX5_SET(query_flow_counter_in, in, flow_counter_id, id); | |
c4f287c4 | 842 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
9dc0b289 AV |
843 | if (err) |
844 | return err; | |
845 | ||
846 | stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics); | |
847 | *packets = MLX5_GET64(traffic_counter, stats, packets); | |
848 | *bytes = MLX5_GET64(traffic_counter, stats, octets); | |
9dc0b289 AV |
849 | return 0; |
850 | } | |
a351a1b0 | 851 | |
6f06e04b | 852 | int mlx5_cmd_fc_get_bulk_query_out_len(int bulk_len) |
a351a1b0 | 853 | { |
6f06e04b GT |
854 | return MLX5_ST_SZ_BYTES(query_flow_counter_out) + |
855 | MLX5_ST_SZ_BYTES(traffic_counter) * bulk_len; | |
a351a1b0 AV |
856 | } |
857 | ||
6f06e04b GT |
858 | int mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, u32 base_id, int bulk_len, |
859 | u32 *out) | |
a351a1b0 | 860 | { |
6f06e04b | 861 | int outlen = mlx5_cmd_fc_get_bulk_query_out_len(bulk_len); |
31a0956e | 862 | u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {}; |
a351a1b0 AV |
863 | |
864 | MLX5_SET(query_flow_counter_in, in, opcode, | |
865 | MLX5_CMD_OP_QUERY_FLOW_COUNTER); | |
6f06e04b GT |
866 | MLX5_SET(query_flow_counter_in, in, flow_counter_id, base_id); |
867 | MLX5_SET(query_flow_counter_in, in, num_of_counters, bulk_len); | |
868 | return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen); | |
a351a1b0 | 869 | } |
575ddf58 | 870 | |
2b688ea5 | 871 | static int mlx5_cmd_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns, |
3f3f05ab | 872 | struct mlx5_pkt_reformat_params *params, |
2b688ea5 MG |
873 | enum mlx5_flow_namespace_type namespace, |
874 | struct mlx5_pkt_reformat *pkt_reformat) | |
575ddf58 | 875 | { |
31a0956e | 876 | u32 out[MLX5_ST_SZ_DW(alloc_packet_reformat_context_out)] = {}; |
2b688ea5 | 877 | struct mlx5_core_dev *dev = ns->dev; |
60786f09 | 878 | void *packet_reformat_context_in; |
31ca3648 | 879 | int max_encap_size; |
60786f09 | 880 | void *reformat; |
43f93839 | 881 | int inlen; |
575ddf58 | 882 | int err; |
43f93839 | 883 | u32 *in; |
575ddf58 | 884 | |
22c3f2f5 MG |
885 | if (namespace == MLX5_FLOW_NAMESPACE_FDB || |
886 | namespace == MLX5_FLOW_NAMESPACE_FDB_BYPASS) | |
31ca3648 MB |
887 | max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size); |
888 | else | |
889 | max_encap_size = MLX5_CAP_FLOWTABLE(dev, max_encap_header_size); | |
890 | ||
3f3f05ab | 891 | if (params->size > max_encap_size) { |
073ff3c8 | 892 | mlx5_core_warn(dev, "encap size %zd too big, max supported is %d\n", |
3f3f05ab | 893 | params->size, max_encap_size); |
575ddf58 | 894 | return -EINVAL; |
073ff3c8 | 895 | } |
575ddf58 | 896 | |
3f3f05ab YK |
897 | in = kzalloc(MLX5_ST_SZ_BYTES(alloc_packet_reformat_context_in) + |
898 | params->size, GFP_KERNEL); | |
43f93839 HHZ |
899 | if (!in) |
900 | return -ENOMEM; | |
901 | ||
60786f09 MB |
902 | packet_reformat_context_in = MLX5_ADDR_OF(alloc_packet_reformat_context_in, |
903 | in, packet_reformat_context); | |
904 | reformat = MLX5_ADDR_OF(packet_reformat_context_in, | |
905 | packet_reformat_context_in, | |
906 | reformat_data); | |
3f3f05ab | 907 | inlen = reformat - (void *)in + params->size; |
43f93839 | 908 | |
60786f09 MB |
909 | MLX5_SET(alloc_packet_reformat_context_in, in, opcode, |
910 | MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT); | |
911 | MLX5_SET(packet_reformat_context_in, packet_reformat_context_in, | |
3f3f05ab | 912 | reformat_data_size, params->size); |
60786f09 | 913 | MLX5_SET(packet_reformat_context_in, packet_reformat_context_in, |
3f3f05ab YK |
914 | reformat_type, params->type); |
915 | MLX5_SET(packet_reformat_context_in, packet_reformat_context_in, | |
916 | reformat_param_0, params->param_0); | |
917 | MLX5_SET(packet_reformat_context_in, packet_reformat_context_in, | |
918 | reformat_param_1, params->param_1); | |
919 | if (params->data && params->size) | |
920 | memcpy(reformat, params->data, params->size); | |
575ddf58 | 921 | |
575ddf58 IL |
922 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); |
923 | ||
2b688ea5 MG |
924 | pkt_reformat->id = MLX5_GET(alloc_packet_reformat_context_out, |
925 | out, packet_reformat_id); | |
87cd0649 YK |
926 | pkt_reformat->owner = MLX5_FLOW_RESOURCE_OWNER_FW; |
927 | ||
43f93839 | 928 | kfree(in); |
575ddf58 IL |
929 | return err; |
930 | } | |
931 | ||
2b688ea5 MG |
932 | static void mlx5_cmd_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns, |
933 | struct mlx5_pkt_reformat *pkt_reformat) | |
575ddf58 | 934 | { |
31a0956e | 935 | u32 in[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_in)] = {}; |
2b688ea5 | 936 | struct mlx5_core_dev *dev = ns->dev; |
575ddf58 | 937 | |
60786f09 MB |
938 | MLX5_SET(dealloc_packet_reformat_context_in, in, opcode, |
939 | MLX5_CMD_OP_DEALLOC_PACKET_REFORMAT_CONTEXT); | |
940 | MLX5_SET(dealloc_packet_reformat_context_in, in, packet_reformat_id, | |
2b688ea5 | 941 | pkt_reformat->id); |
575ddf58 | 942 | |
31a0956e | 943 | mlx5_cmd_exec_in(dev, dealloc_packet_reformat_context, in); |
575ddf58 | 944 | } |
2de24fed | 945 | |
2b688ea5 MG |
946 | static int mlx5_cmd_modify_header_alloc(struct mlx5_flow_root_namespace *ns, |
947 | u8 namespace, u8 num_actions, | |
948 | void *modify_actions, | |
949 | struct mlx5_modify_hdr *modify_hdr) | |
2de24fed | 950 | { |
31a0956e | 951 | u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)] = {}; |
2de24fed | 952 | int max_actions, actions_size, inlen, err; |
2b688ea5 | 953 | struct mlx5_core_dev *dev = ns->dev; |
2de24fed OG |
954 | void *actions_in; |
955 | u8 table_type; | |
956 | u32 *in; | |
957 | ||
958 | switch (namespace) { | |
959 | case MLX5_FLOW_NAMESPACE_FDB: | |
22c3f2f5 | 960 | case MLX5_FLOW_NAMESPACE_FDB_BYPASS: |
2de24fed OG |
961 | max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, max_modify_header_actions); |
962 | table_type = FS_FT_FDB; | |
963 | break; | |
15d187e2 | 964 | case MLX5_FLOW_NAMESPACE_KERNEL_RX_MACSEC: |
2de24fed | 965 | case MLX5_FLOW_NAMESPACE_KERNEL: |
c3c062f8 | 966 | case MLX5_FLOW_NAMESPACE_BYPASS: |
2de24fed OG |
967 | max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions); |
968 | table_type = FS_FT_NIC_RX; | |
969 | break; | |
c3c062f8 | 970 | case MLX5_FLOW_NAMESPACE_EGRESS: |
ee534d7f LN |
971 | case MLX5_FLOW_NAMESPACE_EGRESS_IPSEC: |
972 | case MLX5_FLOW_NAMESPACE_EGRESS_MACSEC: | |
c3c062f8 MB |
973 | max_actions = MLX5_CAP_FLOWTABLE_NIC_TX(dev, max_modify_header_actions); |
974 | table_type = FS_FT_NIC_TX; | |
975 | break; | |
84b0d6a7 JL |
976 | case MLX5_FLOW_NAMESPACE_ESW_INGRESS: |
977 | max_actions = MLX5_CAP_ESW_INGRESS_ACL(dev, max_modify_header_actions); | |
978 | table_type = FS_FT_ESW_INGRESS_ACL; | |
979 | break; | |
ac7ea1c7 | 980 | case MLX5_FLOW_NAMESPACE_RDMA_TX_MACSEC: |
ecf814e0 MG |
981 | case MLX5_FLOW_NAMESPACE_RDMA_TX: |
982 | max_actions = MLX5_CAP_FLOWTABLE_RDMA_TX(dev, max_modify_header_actions); | |
983 | table_type = FS_FT_RDMA_TX; | |
984 | break; | |
2de24fed OG |
985 | default: |
986 | return -EOPNOTSUPP; | |
987 | } | |
988 | ||
989 | if (num_actions > max_actions) { | |
990 | mlx5_core_warn(dev, "too many modify header actions %d, max supported %d\n", | |
991 | num_actions, max_actions); | |
992 | return -EOPNOTSUPP; | |
993 | } | |
994 | ||
d65dbedf | 995 | actions_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) * num_actions; |
2de24fed OG |
996 | inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size; |
997 | ||
998 | in = kzalloc(inlen, GFP_KERNEL); | |
999 | if (!in) | |
1000 | return -ENOMEM; | |
1001 | ||
1002 | MLX5_SET(alloc_modify_header_context_in, in, opcode, | |
1003 | MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT); | |
1004 | MLX5_SET(alloc_modify_header_context_in, in, table_type, table_type); | |
1005 | MLX5_SET(alloc_modify_header_context_in, in, num_of_actions, num_actions); | |
1006 | ||
1007 | actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions); | |
1008 | memcpy(actions_in, modify_actions, actions_size); | |
1009 | ||
2de24fed OG |
1010 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); |
1011 | ||
2b688ea5 | 1012 | modify_hdr->id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id); |
87cd0649 | 1013 | modify_hdr->owner = MLX5_FLOW_RESOURCE_OWNER_FW; |
2de24fed OG |
1014 | kfree(in); |
1015 | return err; | |
1016 | } | |
1017 | ||
2b688ea5 MG |
1018 | static void mlx5_cmd_modify_header_dealloc(struct mlx5_flow_root_namespace *ns, |
1019 | struct mlx5_modify_hdr *modify_hdr) | |
2de24fed | 1020 | { |
31a0956e | 1021 | u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)] = {}; |
2b688ea5 | 1022 | struct mlx5_core_dev *dev = ns->dev; |
2de24fed | 1023 | |
2de24fed OG |
1024 | MLX5_SET(dealloc_modify_header_context_in, in, opcode, |
1025 | MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT); | |
1026 | MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id, | |
2b688ea5 | 1027 | modify_hdr->id); |
2de24fed | 1028 | |
31a0956e | 1029 | mlx5_cmd_exec_in(dev, dealloc_modify_header_context, in); |
2de24fed | 1030 | } |
af76c501 | 1031 | |
e7e2519e MG |
1032 | static int mlx5_cmd_destroy_match_definer(struct mlx5_flow_root_namespace *ns, |
1033 | int definer_id) | |
1034 | { | |
1035 | u32 in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {}; | |
1036 | u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)]; | |
1037 | ||
1038 | MLX5_SET(general_obj_in_cmd_hdr, in, opcode, | |
1039 | MLX5_CMD_OP_DESTROY_GENERAL_OBJECT); | |
1040 | MLX5_SET(general_obj_in_cmd_hdr, in, obj_type, | |
1041 | MLX5_OBJ_TYPE_MATCH_DEFINER); | |
1042 | MLX5_SET(general_obj_in_cmd_hdr, in, obj_id, definer_id); | |
1043 | ||
1044 | return mlx5_cmd_exec(ns->dev, in, sizeof(in), out, sizeof(out)); | |
1045 | } | |
1046 | ||
1047 | static int mlx5_cmd_create_match_definer(struct mlx5_flow_root_namespace *ns, | |
1048 | u16 format_id, u32 *match_mask) | |
1049 | { | |
1050 | u32 out[MLX5_ST_SZ_DW(create_match_definer_out)] = {}; | |
1051 | u32 in[MLX5_ST_SZ_DW(create_match_definer_in)] = {}; | |
1052 | struct mlx5_core_dev *dev = ns->dev; | |
1053 | void *ptr; | |
1054 | int err; | |
1055 | ||
1056 | MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.opcode, | |
1057 | MLX5_CMD_OP_CREATE_GENERAL_OBJECT); | |
1058 | MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.obj_type, | |
1059 | MLX5_OBJ_TYPE_MATCH_DEFINER); | |
1060 | ||
1061 | ptr = MLX5_ADDR_OF(create_match_definer_in, in, obj_context); | |
1062 | MLX5_SET(match_definer, ptr, format_id, format_id); | |
1063 | ||
1064 | ptr = MLX5_ADDR_OF(match_definer, ptr, match_mask); | |
1065 | memcpy(ptr, match_mask, MLX5_FLD_SZ_BYTES(match_definer, match_mask)); | |
1066 | ||
1067 | err = mlx5_cmd_exec_inout(dev, create_match_definer, in, out); | |
1068 | return err ? err : MLX5_GET(general_obj_out_cmd_hdr, out, obj_id); | |
1069 | } | |
1070 | ||
8348b71c DC |
1071 | static u32 mlx5_cmd_get_capabilities(struct mlx5_flow_root_namespace *ns, |
1072 | enum fs_flow_table_type ft_type) | |
1073 | { | |
1074 | return 0; | |
1075 | } | |
1076 | ||
af76c501 MB |
1077 | static const struct mlx5_flow_cmds mlx5_flow_cmds = { |
1078 | .create_flow_table = mlx5_cmd_create_flow_table, | |
1079 | .destroy_flow_table = mlx5_cmd_destroy_flow_table, | |
1080 | .modify_flow_table = mlx5_cmd_modify_flow_table, | |
1081 | .create_flow_group = mlx5_cmd_create_flow_group, | |
1082 | .destroy_flow_group = mlx5_cmd_destroy_flow_group, | |
1083 | .create_fte = mlx5_cmd_create_fte, | |
1084 | .update_fte = mlx5_cmd_update_fte, | |
1085 | .delete_fte = mlx5_cmd_delete_fte, | |
1086 | .update_root_ft = mlx5_cmd_update_root_ft, | |
2b688ea5 MG |
1087 | .packet_reformat_alloc = mlx5_cmd_packet_reformat_alloc, |
1088 | .packet_reformat_dealloc = mlx5_cmd_packet_reformat_dealloc, | |
1089 | .modify_header_alloc = mlx5_cmd_modify_header_alloc, | |
6a48faee | 1090 | .modify_header_dealloc = mlx5_cmd_modify_header_dealloc, |
e7e2519e MG |
1091 | .create_match_definer = mlx5_cmd_create_match_definer, |
1092 | .destroy_match_definer = mlx5_cmd_destroy_match_definer, | |
6a48faee MG |
1093 | .set_peer = mlx5_cmd_stub_set_peer, |
1094 | .create_ns = mlx5_cmd_stub_create_ns, | |
1095 | .destroy_ns = mlx5_cmd_stub_destroy_ns, | |
8348b71c | 1096 | .get_capabilities = mlx5_cmd_get_capabilities, |
af76c501 MB |
1097 | }; |
1098 | ||
1099 | static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = { | |
1100 | .create_flow_table = mlx5_cmd_stub_create_flow_table, | |
1101 | .destroy_flow_table = mlx5_cmd_stub_destroy_flow_table, | |
1102 | .modify_flow_table = mlx5_cmd_stub_modify_flow_table, | |
1103 | .create_flow_group = mlx5_cmd_stub_create_flow_group, | |
1104 | .destroy_flow_group = mlx5_cmd_stub_destroy_flow_group, | |
1105 | .create_fte = mlx5_cmd_stub_create_fte, | |
1106 | .update_fte = mlx5_cmd_stub_update_fte, | |
1107 | .delete_fte = mlx5_cmd_stub_delete_fte, | |
1108 | .update_root_ft = mlx5_cmd_stub_update_root_ft, | |
2b688ea5 MG |
1109 | .packet_reformat_alloc = mlx5_cmd_stub_packet_reformat_alloc, |
1110 | .packet_reformat_dealloc = mlx5_cmd_stub_packet_reformat_dealloc, | |
1111 | .modify_header_alloc = mlx5_cmd_stub_modify_header_alloc, | |
6a48faee | 1112 | .modify_header_dealloc = mlx5_cmd_stub_modify_header_dealloc, |
e7e2519e MG |
1113 | .create_match_definer = mlx5_cmd_stub_create_match_definer, |
1114 | .destroy_match_definer = mlx5_cmd_stub_destroy_match_definer, | |
6a48faee MG |
1115 | .set_peer = mlx5_cmd_stub_set_peer, |
1116 | .create_ns = mlx5_cmd_stub_create_ns, | |
1117 | .destroy_ns = mlx5_cmd_stub_destroy_ns, | |
8348b71c | 1118 | .get_capabilities = mlx5_cmd_stub_get_capabilities, |
af76c501 MB |
1119 | }; |
1120 | ||
6a48faee | 1121 | const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void) |
af76c501 MB |
1122 | { |
1123 | return &mlx5_flow_cmds; | |
1124 | } | |
1125 | ||
1126 | static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_stub_cmds(void) | |
1127 | { | |
1128 | return &mlx5_flow_cmd_stubs; | |
1129 | } | |
1130 | ||
1131 | const struct mlx5_flow_cmds *mlx5_fs_cmd_get_default(enum fs_flow_table_type type) | |
1132 | { | |
1133 | switch (type) { | |
1134 | case FS_FT_NIC_RX: | |
1135 | case FS_FT_ESW_EGRESS_ACL: | |
1136 | case FS_FT_ESW_INGRESS_ACL: | |
1137 | case FS_FT_FDB: | |
1138 | case FS_FT_SNIFFER_RX: | |
1139 | case FS_FT_SNIFFER_TX: | |
5f418378 | 1140 | case FS_FT_NIC_TX: |
d83eb50e | 1141 | case FS_FT_RDMA_RX: |
24670b1a | 1142 | case FS_FT_RDMA_TX: |
425a563a | 1143 | case FS_FT_PORT_SEL: |
8ce78257 | 1144 | return mlx5_fs_cmd_get_fw_cmds(); |
af76c501 MB |
1145 | default: |
1146 | return mlx5_fs_cmd_get_stub_cmds(); | |
1147 | } | |
1148 | } | |
dc6981eb TT |
1149 | |
1150 | int mlx5_fs_cmd_set_l2table_entry_silent(struct mlx5_core_dev *dev, u8 silent_mode) | |
1151 | { | |
1152 | u32 in[MLX5_ST_SZ_DW(set_l2_table_entry_in)] = {}; | |
1153 | ||
1154 | if (silent_mode && !MLX5_CAP_GEN(dev, silent_mode)) | |
1155 | return -EOPNOTSUPP; | |
1156 | ||
1157 | MLX5_SET(set_l2_table_entry_in, in, opcode, MLX5_CMD_OP_SET_L2_TABLE_ENTRY); | |
1158 | MLX5_SET(set_l2_table_entry_in, in, silent_mode_valid, 1); | |
1159 | MLX5_SET(set_l2_table_entry_in, in, silent_mode, silent_mode); | |
1160 | ||
1161 | return mlx5_cmd_exec_in(dev, set_l2_table_entry, in); | |
1162 | } | |
3c9c34c3 TT |
1163 | |
1164 | int mlx5_fs_cmd_set_tx_flow_table_root(struct mlx5_core_dev *dev, u32 ft_id, bool disconnect) | |
1165 | { | |
1166 | u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {}; | |
1167 | u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {}; | |
1168 | ||
1169 | if (disconnect && MLX5_CAP_FLOWTABLE_NIC_TX(dev, reset_root_to_default)) | |
1170 | return -EOPNOTSUPP; | |
1171 | ||
1172 | MLX5_SET(set_flow_table_root_in, in, opcode, | |
1173 | MLX5_CMD_OP_SET_FLOW_TABLE_ROOT); | |
1174 | MLX5_SET(set_flow_table_root_in, in, table_type, | |
1175 | FS_FT_NIC_TX); | |
1176 | if (disconnect) | |
1177 | MLX5_SET(set_flow_table_root_in, in, op_mod, 1); | |
1178 | else | |
1179 | MLX5_SET(set_flow_table_root_in, in, table_id, ft_id); | |
1180 | ||
1181 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); | |
1182 | } |