]>
Commit | Line | Data |
---|---|---|
2a2336f8 YP |
1 | /* |
2 | * Copyright (c) 2007 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/errno.h> | |
34 | #include <linux/if_ether.h> | |
c59fec20 | 35 | #include <linux/if_vlan.h> |
ee40fa06 | 36 | #include <linux/export.h> |
2a2336f8 YP |
37 | |
38 | #include <linux/mlx4/cmd.h> | |
39 | ||
40 | #include "mlx4.h" | |
41 | ||
42 | #define MLX4_MAC_VALID (1ull << 63) | |
2a2336f8 YP |
43 | |
44 | #define MLX4_VLAN_VALID (1u << 31) | |
45 | #define MLX4_VLAN_MASK 0xfff | |
46 | ||
93ece0c1 EE |
47 | #define MLX4_STATS_TRAFFIC_COUNTERS_MASK 0xfULL |
48 | #define MLX4_STATS_TRAFFIC_DROPS_MASK 0xc0ULL | |
49 | #define MLX4_STATS_ERROR_COUNTERS_MASK 0x1ffc30ULL | |
50 | #define MLX4_STATS_PORT_COUNTERS_MASK 0x1fe00000ULL | |
51 | ||
2a2336f8 YP |
52 | void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table) |
53 | { | |
54 | int i; | |
55 | ||
56 | mutex_init(&table->mutex); | |
57 | for (i = 0; i < MLX4_MAX_MAC_NUM; i++) { | |
58 | table->entries[i] = 0; | |
59 | table->refs[i] = 0; | |
60 | } | |
61 | table->max = 1 << dev->caps.log_num_macs; | |
62 | table->total = 0; | |
63 | } | |
64 | ||
65 | void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table) | |
66 | { | |
67 | int i; | |
68 | ||
69 | mutex_init(&table->mutex); | |
70 | for (i = 0; i < MLX4_MAX_VLAN_NUM; i++) { | |
71 | table->entries[i] = 0; | |
72 | table->refs[i] = 0; | |
73 | } | |
e72ebf5a | 74 | table->max = (1 << dev->caps.log_num_vlans) - MLX4_VLAN_REGULAR; |
2a2336f8 YP |
75 | table->total = 0; |
76 | } | |
77 | ||
ffe455ad EE |
78 | static int validate_index(struct mlx4_dev *dev, |
79 | struct mlx4_mac_table *table, int index) | |
80 | { | |
81 | int err = 0; | |
82 | ||
83 | if (index < 0 || index >= table->max || !table->entries[index]) { | |
84 | mlx4_warn(dev, "No valid Mac entry for the given index\n"); | |
85 | err = -EINVAL; | |
86 | } | |
87 | return err; | |
88 | } | |
89 | ||
90 | static int find_index(struct mlx4_dev *dev, | |
91 | struct mlx4_mac_table *table, u64 mac) | |
92 | { | |
93 | int i; | |
94 | ||
95 | for (i = 0; i < MLX4_MAX_MAC_NUM; i++) { | |
96 | if ((mac & MLX4_MAC_MASK) == | |
97 | (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) | |
98 | return i; | |
99 | } | |
100 | /* Mac not found */ | |
101 | return -EINVAL; | |
1679200f YP |
102 | } |
103 | ||
ffe455ad EE |
104 | static int mlx4_set_port_mac_table(struct mlx4_dev *dev, u8 port, |
105 | __be64 *entries) | |
106 | { | |
107 | struct mlx4_cmd_mailbox *mailbox; | |
108 | u32 in_mod; | |
109 | int err; | |
110 | ||
111 | mailbox = mlx4_alloc_cmd_mailbox(dev); | |
112 | if (IS_ERR(mailbox)) | |
113 | return PTR_ERR(mailbox); | |
114 | ||
115 | memcpy(mailbox->buf, entries, MLX4_MAC_TABLE_SIZE); | |
116 | ||
117 | in_mod = MLX4_SET_PORT_MAC_TABLE << 8 | port; | |
0f6740c7 | 118 | |
ffe455ad EE |
119 | err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT, |
120 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); | |
121 | ||
122 | mlx4_free_cmd_mailbox(dev, mailbox); | |
123 | return err; | |
124 | } | |
125 | ||
297e0dad MS |
126 | int mlx4_find_cached_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *idx) |
127 | { | |
128 | struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; | |
129 | struct mlx4_mac_table *table = &info->mac_table; | |
130 | int i; | |
131 | ||
132 | for (i = 0; i < MLX4_MAX_MAC_NUM; i++) { | |
133 | if (!table->refs[i]) | |
134 | continue; | |
135 | ||
136 | if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) { | |
137 | *idx = i; | |
138 | return 0; | |
139 | } | |
140 | } | |
141 | ||
142 | return -ENOENT; | |
143 | } | |
144 | EXPORT_SYMBOL_GPL(mlx4_find_cached_mac); | |
145 | ||
ffe455ad EE |
146 | int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac) |
147 | { | |
148 | struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; | |
149 | struct mlx4_mac_table *table = &info->mac_table; | |
150 | int i, err = 0; | |
151 | int free = -1; | |
152 | ||
153 | mlx4_dbg(dev, "Registering MAC: 0x%llx for port %d\n", | |
154 | (unsigned long long) mac, port); | |
0f6740c7 | 155 | |
2a2336f8 | 156 | mutex_lock(&table->mutex); |
ffe455ad EE |
157 | for (i = 0; i < MLX4_MAX_MAC_NUM; i++) { |
158 | if (free < 0 && !table->entries[i]) { | |
2a2336f8 YP |
159 | free = i; |
160 | continue; | |
161 | } | |
162 | ||
163 | if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) { | |
6ce71acd RE |
164 | /* MAC already registered, increment ref count */ |
165 | err = i; | |
166 | ++table->refs[i]; | |
2a2336f8 YP |
167 | goto out; |
168 | } | |
169 | } | |
0926f910 | 170 | |
2a2336f8 YP |
171 | mlx4_dbg(dev, "Free MAC index is %d\n", free); |
172 | ||
173 | if (table->total == table->max) { | |
174 | /* No free mac entries */ | |
175 | err = -ENOSPC; | |
176 | goto out; | |
177 | } | |
178 | ||
179 | /* Register new MAC */ | |
2a2336f8 YP |
180 | table->entries[free] = cpu_to_be64(mac | MLX4_MAC_VALID); |
181 | ||
182 | err = mlx4_set_port_mac_table(dev, port, table->entries); | |
183 | if (unlikely(err)) { | |
ffe455ad EE |
184 | mlx4_err(dev, "Failed adding MAC: 0x%llx\n", |
185 | (unsigned long long) mac); | |
2a2336f8 YP |
186 | table->entries[free] = 0; |
187 | goto out; | |
188 | } | |
6ce71acd | 189 | table->refs[free] = 1; |
ffe455ad | 190 | err = free; |
2a2336f8 YP |
191 | ++table->total; |
192 | out: | |
193 | mutex_unlock(&table->mutex); | |
194 | return err; | |
195 | } | |
ffe455ad | 196 | EXPORT_SYMBOL_GPL(__mlx4_register_mac); |
2a2336f8 | 197 | |
ffe455ad | 198 | int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac) |
2a2336f8 | 199 | { |
e7dbeba8 | 200 | u64 out_param = 0; |
acddd5dd | 201 | int err = -EINVAL; |
2a2336f8 | 202 | |
ffe455ad | 203 | if (mlx4_is_mfunc(dev)) { |
acddd5dd JM |
204 | if (!(dev->flags & MLX4_FLAG_OLD_REG_MAC)) { |
205 | err = mlx4_cmd_imm(dev, mac, &out_param, | |
206 | ((u32) port) << 8 | (u32) RES_MAC, | |
207 | RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES, | |
208 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); | |
209 | } | |
210 | if (err && err == -EINVAL && mlx4_is_slave(dev)) { | |
211 | /* retry using old REG_MAC format */ | |
212 | set_param_l(&out_param, port); | |
213 | err = mlx4_cmd_imm(dev, mac, &out_param, RES_MAC, | |
214 | RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES, | |
215 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); | |
216 | if (!err) | |
217 | dev->flags |= MLX4_FLAG_OLD_REG_MAC; | |
218 | } | |
ffe455ad EE |
219 | if (err) |
220 | return err; | |
1679200f | 221 | |
ffe455ad | 222 | return get_param_l(&out_param); |
1679200f | 223 | } |
ffe455ad | 224 | return __mlx4_register_mac(dev, port, mac); |
1679200f | 225 | } |
ffe455ad EE |
226 | EXPORT_SYMBOL_GPL(mlx4_register_mac); |
227 | ||
16a10ffd YB |
228 | int mlx4_get_base_qpn(struct mlx4_dev *dev, u8 port) |
229 | { | |
230 | return dev->caps.reserved_qps_base[MLX4_QP_REGION_ETH_ADDR] + | |
231 | (port - 1) * (1 << dev->caps.log_num_macs); | |
232 | } | |
233 | EXPORT_SYMBOL_GPL(mlx4_get_base_qpn); | |
1679200f | 234 | |
ffe455ad | 235 | void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac) |
1679200f YP |
236 | { |
237 | struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; | |
238 | struct mlx4_mac_table *table = &info->mac_table; | |
ffe455ad | 239 | int index; |
1679200f | 240 | |
1679200f | 241 | mutex_lock(&table->mutex); |
6ce71acd | 242 | index = find_index(dev, table, mac); |
1679200f YP |
243 | |
244 | if (validate_index(dev, table, index)) | |
245 | goto out; | |
6ce71acd RE |
246 | if (--table->refs[index]) { |
247 | mlx4_dbg(dev, "Have more references for index %d," | |
248 | "no need to modify mac table\n", index); | |
249 | goto out; | |
250 | } | |
1679200f | 251 | |
ffe455ad EE |
252 | table->entries[index] = 0; |
253 | mlx4_set_port_mac_table(dev, port, table->entries); | |
254 | --table->total; | |
2a2336f8 YP |
255 | out: |
256 | mutex_unlock(&table->mutex); | |
257 | } | |
ffe455ad EE |
258 | EXPORT_SYMBOL_GPL(__mlx4_unregister_mac); |
259 | ||
260 | void mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac) | |
261 | { | |
e7dbeba8 | 262 | u64 out_param = 0; |
ffe455ad EE |
263 | |
264 | if (mlx4_is_mfunc(dev)) { | |
acddd5dd JM |
265 | if (!(dev->flags & MLX4_FLAG_OLD_REG_MAC)) { |
266 | (void) mlx4_cmd_imm(dev, mac, &out_param, | |
267 | ((u32) port) << 8 | (u32) RES_MAC, | |
268 | RES_OP_RESERVE_AND_MAP, MLX4_CMD_FREE_RES, | |
269 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); | |
270 | } else { | |
271 | /* use old unregister mac format */ | |
272 | set_param_l(&out_param, port); | |
273 | (void) mlx4_cmd_imm(dev, mac, &out_param, RES_MAC, | |
274 | RES_OP_RESERVE_AND_MAP, MLX4_CMD_FREE_RES, | |
275 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); | |
276 | } | |
ffe455ad EE |
277 | return; |
278 | } | |
279 | __mlx4_unregister_mac(dev, port, mac); | |
280 | return; | |
281 | } | |
2a2336f8 YP |
282 | EXPORT_SYMBOL_GPL(mlx4_unregister_mac); |
283 | ||
16a10ffd | 284 | int __mlx4_replace_mac(struct mlx4_dev *dev, u8 port, int qpn, u64 new_mac) |
1679200f YP |
285 | { |
286 | struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; | |
287 | struct mlx4_mac_table *table = &info->mac_table; | |
ffe455ad EE |
288 | int index = qpn - info->base_qpn; |
289 | int err = 0; | |
1679200f | 290 | |
ffe455ad | 291 | /* CX1 doesn't support multi-functions */ |
1679200f YP |
292 | mutex_lock(&table->mutex); |
293 | ||
294 | err = validate_index(dev, table, index); | |
295 | if (err) | |
296 | goto out; | |
297 | ||
298 | table->entries[index] = cpu_to_be64(new_mac | MLX4_MAC_VALID); | |
299 | ||
300 | err = mlx4_set_port_mac_table(dev, port, table->entries); | |
301 | if (unlikely(err)) { | |
ffe455ad EE |
302 | mlx4_err(dev, "Failed adding MAC: 0x%llx\n", |
303 | (unsigned long long) new_mac); | |
1679200f YP |
304 | table->entries[index] = 0; |
305 | } | |
306 | out: | |
307 | mutex_unlock(&table->mutex); | |
308 | return err; | |
309 | } | |
16a10ffd | 310 | EXPORT_SYMBOL_GPL(__mlx4_replace_mac); |
ffe455ad | 311 | |
2a2336f8 YP |
312 | static int mlx4_set_port_vlan_table(struct mlx4_dev *dev, u8 port, |
313 | __be32 *entries) | |
314 | { | |
315 | struct mlx4_cmd_mailbox *mailbox; | |
316 | u32 in_mod; | |
317 | int err; | |
318 | ||
319 | mailbox = mlx4_alloc_cmd_mailbox(dev); | |
320 | if (IS_ERR(mailbox)) | |
321 | return PTR_ERR(mailbox); | |
322 | ||
323 | memcpy(mailbox->buf, entries, MLX4_VLAN_TABLE_SIZE); | |
324 | in_mod = MLX4_SET_PORT_VLAN_TABLE << 8 | port; | |
325 | err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT, | |
162226a1 | 326 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); |
2a2336f8 YP |
327 | |
328 | mlx4_free_cmd_mailbox(dev, mailbox); | |
329 | ||
330 | return err; | |
331 | } | |
332 | ||
4c3eb3ca EC |
333 | int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx) |
334 | { | |
335 | struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table; | |
336 | int i; | |
337 | ||
338 | for (i = 0; i < MLX4_MAX_VLAN_NUM; ++i) { | |
339 | if (table->refs[i] && | |
340 | (vid == (MLX4_VLAN_MASK & | |
341 | be32_to_cpu(table->entries[i])))) { | |
342 | /* VLAN already registered, increase reference count */ | |
343 | *idx = i; | |
344 | return 0; | |
345 | } | |
346 | } | |
347 | ||
348 | return -ENOENT; | |
349 | } | |
350 | EXPORT_SYMBOL_GPL(mlx4_find_cached_vlan); | |
351 | ||
3f7fb021 | 352 | int __mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, |
ffe455ad | 353 | int *index) |
2a2336f8 YP |
354 | { |
355 | struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table; | |
356 | int i, err = 0; | |
357 | int free = -1; | |
358 | ||
359 | mutex_lock(&table->mutex); | |
e72ebf5a YP |
360 | |
361 | if (table->total == table->max) { | |
362 | /* No free vlan entries */ | |
363 | err = -ENOSPC; | |
364 | goto out; | |
365 | } | |
366 | ||
2a2336f8 YP |
367 | for (i = MLX4_VLAN_REGULAR; i < MLX4_MAX_VLAN_NUM; i++) { |
368 | if (free < 0 && (table->refs[i] == 0)) { | |
369 | free = i; | |
370 | continue; | |
371 | } | |
372 | ||
373 | if (table->refs[i] && | |
374 | (vlan == (MLX4_VLAN_MASK & | |
375 | be32_to_cpu(table->entries[i])))) { | |
25985edc | 376 | /* Vlan already registered, increase references count */ |
2a2336f8 YP |
377 | *index = i; |
378 | ++table->refs[i]; | |
379 | goto out; | |
380 | } | |
381 | } | |
382 | ||
0926f910 EC |
383 | if (free < 0) { |
384 | err = -ENOMEM; | |
385 | goto out; | |
386 | } | |
387 | ||
ffe455ad | 388 | /* Register new VLAN */ |
2a2336f8 YP |
389 | table->refs[free] = 1; |
390 | table->entries[free] = cpu_to_be32(vlan | MLX4_VLAN_VALID); | |
391 | ||
392 | err = mlx4_set_port_vlan_table(dev, port, table->entries); | |
393 | if (unlikely(err)) { | |
394 | mlx4_warn(dev, "Failed adding vlan: %u\n", vlan); | |
395 | table->refs[free] = 0; | |
396 | table->entries[free] = 0; | |
397 | goto out; | |
398 | } | |
399 | ||
400 | *index = free; | |
401 | ++table->total; | |
402 | out: | |
403 | mutex_unlock(&table->mutex); | |
404 | return err; | |
405 | } | |
ffe455ad EE |
406 | |
407 | int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index) | |
408 | { | |
e7dbeba8 | 409 | u64 out_param = 0; |
ffe455ad EE |
410 | int err; |
411 | ||
162226a1 JM |
412 | if (vlan > 4095) |
413 | return -EINVAL; | |
414 | ||
ffe455ad | 415 | if (mlx4_is_mfunc(dev)) { |
acddd5dd JM |
416 | err = mlx4_cmd_imm(dev, vlan, &out_param, |
417 | ((u32) port) << 8 | (u32) RES_VLAN, | |
ffe455ad EE |
418 | RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES, |
419 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); | |
420 | if (!err) | |
421 | *index = get_param_l(&out_param); | |
422 | ||
423 | return err; | |
424 | } | |
425 | return __mlx4_register_vlan(dev, port, vlan, index); | |
426 | } | |
2a2336f8 YP |
427 | EXPORT_SYMBOL_GPL(mlx4_register_vlan); |
428 | ||
2009d005 | 429 | void __mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, u16 vlan) |
2a2336f8 YP |
430 | { |
431 | struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table; | |
2009d005 | 432 | int index; |
2a2336f8 | 433 | |
2009d005 JM |
434 | mutex_lock(&table->mutex); |
435 | if (mlx4_find_cached_vlan(dev, port, vlan, &index)) { | |
436 | mlx4_warn(dev, "vlan 0x%x is not in the vlan table\n", vlan); | |
437 | goto out; | |
2a2336f8 YP |
438 | } |
439 | ||
2009d005 JM |
440 | if (index < MLX4_VLAN_REGULAR) { |
441 | mlx4_warn(dev, "Trying to free special vlan index %d\n", index); | |
2a2336f8 YP |
442 | goto out; |
443 | } | |
2009d005 | 444 | |
2a2336f8 | 445 | if (--table->refs[index]) { |
2009d005 JM |
446 | mlx4_dbg(dev, "Have %d more references for index %d," |
447 | "no need to modify vlan table\n", table->refs[index], | |
448 | index); | |
2a2336f8 YP |
449 | goto out; |
450 | } | |
451 | table->entries[index] = 0; | |
452 | mlx4_set_port_vlan_table(dev, port, table->entries); | |
453 | --table->total; | |
454 | out: | |
455 | mutex_unlock(&table->mutex); | |
456 | } | |
ffe455ad | 457 | |
2009d005 | 458 | void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, u16 vlan) |
ffe455ad | 459 | { |
162226a1 | 460 | u64 out_param = 0; |
ffe455ad EE |
461 | |
462 | if (mlx4_is_mfunc(dev)) { | |
2009d005 | 463 | (void) mlx4_cmd_imm(dev, vlan, &out_param, |
acddd5dd | 464 | ((u32) port) << 8 | (u32) RES_VLAN, |
162226a1 JM |
465 | RES_OP_RESERVE_AND_MAP, |
466 | MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A, | |
467 | MLX4_CMD_WRAPPED); | |
ffe455ad EE |
468 | return; |
469 | } | |
2009d005 | 470 | __mlx4_unregister_vlan(dev, port, vlan); |
ffe455ad | 471 | } |
2a2336f8 | 472 | EXPORT_SYMBOL_GPL(mlx4_unregister_vlan); |
7ff93f8b | 473 | |
9a5aa622 JM |
474 | int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps) |
475 | { | |
476 | struct mlx4_cmd_mailbox *inmailbox, *outmailbox; | |
477 | u8 *inbuf, *outbuf; | |
478 | int err; | |
479 | ||
480 | inmailbox = mlx4_alloc_cmd_mailbox(dev); | |
481 | if (IS_ERR(inmailbox)) | |
482 | return PTR_ERR(inmailbox); | |
483 | ||
484 | outmailbox = mlx4_alloc_cmd_mailbox(dev); | |
485 | if (IS_ERR(outmailbox)) { | |
486 | mlx4_free_cmd_mailbox(dev, inmailbox); | |
487 | return PTR_ERR(outmailbox); | |
488 | } | |
489 | ||
490 | inbuf = inmailbox->buf; | |
491 | outbuf = outmailbox->buf; | |
9a5aa622 JM |
492 | inbuf[0] = 1; |
493 | inbuf[1] = 1; | |
494 | inbuf[2] = 1; | |
495 | inbuf[3] = 1; | |
496 | *(__be16 *) (&inbuf[16]) = cpu_to_be16(0x0015); | |
497 | *(__be32 *) (&inbuf[20]) = cpu_to_be32(port); | |
498 | ||
499 | err = mlx4_cmd_box(dev, inmailbox->dma, outmailbox->dma, port, 3, | |
f9baff50 JM |
500 | MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C, |
501 | MLX4_CMD_NATIVE); | |
9a5aa622 JM |
502 | if (!err) |
503 | *caps = *(__be32 *) (outbuf + 84); | |
504 | mlx4_free_cmd_mailbox(dev, inmailbox); | |
505 | mlx4_free_cmd_mailbox(dev, outmailbox); | |
506 | return err; | |
507 | } | |
9cd59352 | 508 | static struct mlx4_roce_gid_entry zgid_entry; |
9a5aa622 | 509 | |
b6ffaeff JM |
510 | int mlx4_get_slave_num_gids(struct mlx4_dev *dev, int slave) |
511 | { | |
512 | if (slave == 0) | |
513 | return MLX4_ROCE_PF_GIDS; | |
514 | if (slave <= ((MLX4_ROCE_MAX_GIDS - MLX4_ROCE_PF_GIDS) % dev->num_vfs)) | |
515 | return ((MLX4_ROCE_MAX_GIDS - MLX4_ROCE_PF_GIDS) / dev->num_vfs) + 1; | |
516 | return (MLX4_ROCE_MAX_GIDS - MLX4_ROCE_PF_GIDS) / dev->num_vfs; | |
517 | } | |
518 | ||
519 | int mlx4_get_base_gid_ix(struct mlx4_dev *dev, int slave) | |
520 | { | |
521 | int gids; | |
522 | int vfs; | |
523 | ||
524 | gids = MLX4_ROCE_MAX_GIDS - MLX4_ROCE_PF_GIDS; | |
525 | vfs = dev->num_vfs; | |
526 | ||
527 | if (slave == 0) | |
528 | return 0; | |
529 | if (slave <= gids % vfs) | |
530 | return MLX4_ROCE_PF_GIDS + ((gids / vfs) + 1) * (slave - 1); | |
531 | ||
532 | return MLX4_ROCE_PF_GIDS + (gids % vfs) + ((gids / vfs) * (slave - 1)); | |
533 | } | |
534 | ||
ffe455ad EE |
535 | static int mlx4_common_set_port(struct mlx4_dev *dev, int slave, u32 in_mod, |
536 | u8 op_mod, struct mlx4_cmd_mailbox *inbox) | |
537 | { | |
538 | struct mlx4_priv *priv = mlx4_priv(dev); | |
539 | struct mlx4_port_info *port_info; | |
540 | struct mlx4_mfunc_master_ctx *master = &priv->mfunc.master; | |
541 | struct mlx4_slave_state *slave_st = &master->slave_state[slave]; | |
542 | struct mlx4_set_port_rqp_calc_context *qpn_context; | |
543 | struct mlx4_set_port_general_context *gen_context; | |
b6ffaeff | 544 | struct mlx4_roce_gid_entry *gid_entry_tbl, *gid_entry_mbox, *gid_entry_mb1; |
ffe455ad EE |
545 | int reset_qkey_viols; |
546 | int port; | |
547 | int is_eth; | |
b6ffaeff JM |
548 | int num_gids; |
549 | int base; | |
ffe455ad EE |
550 | u32 in_modifier; |
551 | u32 promisc; | |
552 | u16 mtu, prev_mtu; | |
553 | int err; | |
b6ffaeff JM |
554 | int i, j; |
555 | int offset; | |
ffe455ad EE |
556 | __be32 agg_cap_mask; |
557 | __be32 slave_cap_mask; | |
558 | __be32 new_cap_mask; | |
559 | ||
560 | port = in_mod & 0xff; | |
561 | in_modifier = in_mod >> 8; | |
562 | is_eth = op_mod; | |
563 | port_info = &priv->port[port]; | |
564 | ||
565 | /* Slaves cannot perform SET_PORT operations except changing MTU */ | |
566 | if (is_eth) { | |
567 | if (slave != dev->caps.function && | |
9cd59352 JM |
568 | in_modifier != MLX4_SET_PORT_GENERAL && |
569 | in_modifier != MLX4_SET_PORT_GID_TABLE) { | |
ffe455ad EE |
570 | mlx4_warn(dev, "denying SET_PORT for slave:%d\n", |
571 | slave); | |
572 | return -EINVAL; | |
573 | } | |
574 | switch (in_modifier) { | |
575 | case MLX4_SET_PORT_RQP_CALC: | |
576 | qpn_context = inbox->buf; | |
577 | qpn_context->base_qpn = | |
578 | cpu_to_be32(port_info->base_qpn); | |
579 | qpn_context->n_mac = 0x7; | |
580 | promisc = be32_to_cpu(qpn_context->promisc) >> | |
581 | SET_PORT_PROMISC_SHIFT; | |
582 | qpn_context->promisc = cpu_to_be32( | |
583 | promisc << SET_PORT_PROMISC_SHIFT | | |
584 | port_info->base_qpn); | |
585 | promisc = be32_to_cpu(qpn_context->mcast) >> | |
586 | SET_PORT_MC_PROMISC_SHIFT; | |
587 | qpn_context->mcast = cpu_to_be32( | |
588 | promisc << SET_PORT_MC_PROMISC_SHIFT | | |
589 | port_info->base_qpn); | |
590 | break; | |
591 | case MLX4_SET_PORT_GENERAL: | |
592 | gen_context = inbox->buf; | |
593 | /* Mtu is configured as the max MTU among all the | |
594 | * the functions on the port. */ | |
595 | mtu = be16_to_cpu(gen_context->mtu); | |
c59fec20 EE |
596 | mtu = min_t(int, mtu, dev->caps.eth_mtu_cap[port] + |
597 | ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN); | |
ffe455ad EE |
598 | prev_mtu = slave_st->mtu[port]; |
599 | slave_st->mtu[port] = mtu; | |
600 | if (mtu > master->max_mtu[port]) | |
601 | master->max_mtu[port] = mtu; | |
602 | if (mtu < prev_mtu && prev_mtu == | |
603 | master->max_mtu[port]) { | |
604 | slave_st->mtu[port] = mtu; | |
605 | master->max_mtu[port] = mtu; | |
606 | for (i = 0; i < dev->num_slaves; i++) { | |
607 | master->max_mtu[port] = | |
608 | max(master->max_mtu[port], | |
609 | master->slave_state[i].mtu[port]); | |
610 | } | |
611 | } | |
612 | ||
613 | gen_context->mtu = cpu_to_be16(master->max_mtu[port]); | |
614 | break; | |
9cd59352 | 615 | case MLX4_SET_PORT_GID_TABLE: |
b6ffaeff JM |
616 | /* change to MULTIPLE entries: number of guest's gids |
617 | * need a FOR-loop here over number of gids the guest has. | |
618 | * 1. Check no duplicates in gids passed by slave | |
619 | */ | |
620 | num_gids = mlx4_get_slave_num_gids(dev, slave); | |
621 | base = mlx4_get_base_gid_ix(dev, slave); | |
622 | gid_entry_mbox = (struct mlx4_roce_gid_entry *)(inbox->buf); | |
623 | for (i = 0; i < num_gids; gid_entry_mbox++, i++) { | |
624 | if (!memcmp(gid_entry_mbox->raw, zgid_entry.raw, | |
625 | sizeof(zgid_entry))) | |
626 | continue; | |
627 | gid_entry_mb1 = gid_entry_mbox + 1; | |
628 | for (j = i + 1; j < num_gids; gid_entry_mb1++, j++) { | |
629 | if (!memcmp(gid_entry_mb1->raw, | |
630 | zgid_entry.raw, sizeof(zgid_entry))) | |
631 | continue; | |
632 | if (!memcmp(gid_entry_mb1->raw, gid_entry_mbox->raw, | |
633 | sizeof(gid_entry_mbox->raw))) { | |
634 | /* found duplicate */ | |
635 | return -EINVAL; | |
9cd59352 JM |
636 | } |
637 | } | |
638 | } | |
b6ffaeff JM |
639 | |
640 | /* 2. Check that do not have duplicates in OTHER | |
641 | * entries in the port GID table | |
642 | */ | |
9cd59352 | 643 | for (i = 0; i < MLX4_ROCE_MAX_GIDS; i++) { |
b6ffaeff JM |
644 | if (i >= base && i < base + num_gids) |
645 | continue; /* don't compare to slave's current gids */ | |
646 | gid_entry_tbl = &priv->roce_gids[port - 1][i]; | |
647 | if (!memcmp(gid_entry_tbl->raw, zgid_entry.raw, sizeof(zgid_entry))) | |
648 | continue; | |
649 | gid_entry_mbox = (struct mlx4_roce_gid_entry *)(inbox->buf); | |
650 | for (j = 0; j < num_gids; gid_entry_mbox++, j++) { | |
651 | if (!memcmp(gid_entry_mbox->raw, zgid_entry.raw, | |
652 | sizeof(zgid_entry))) | |
653 | continue; | |
654 | if (!memcmp(gid_entry_mbox->raw, gid_entry_tbl->raw, | |
655 | sizeof(gid_entry_tbl->raw))) { | |
656 | /* found duplicate */ | |
657 | mlx4_warn(dev, "requested gid entry for slave:%d " | |
658 | "is a duplicate of gid at index %d\n", | |
659 | slave, i); | |
660 | return -EINVAL; | |
661 | } | |
662 | } | |
9cd59352 | 663 | } |
b6ffaeff JM |
664 | |
665 | /* insert slave GIDs with memcpy, starting at slave's base index */ | |
666 | gid_entry_mbox = (struct mlx4_roce_gid_entry *)(inbox->buf); | |
667 | for (i = 0, offset = base; i < num_gids; gid_entry_mbox++, offset++, i++) | |
668 | memcpy(priv->roce_gids[port - 1][offset].raw, gid_entry_mbox->raw, 16); | |
669 | ||
670 | /* Now, copy roce port gids table to current mailbox for passing to FW */ | |
671 | gid_entry_mbox = (struct mlx4_roce_gid_entry *)(inbox->buf); | |
672 | for (i = 0; i < MLX4_ROCE_MAX_GIDS; gid_entry_mbox++, i++) | |
673 | memcpy(gid_entry_mbox->raw, priv->roce_gids[port - 1][i].raw, 16); | |
674 | ||
9cd59352 | 675 | break; |
ffe455ad EE |
676 | } |
677 | return mlx4_cmd(dev, inbox->dma, in_mod, op_mod, | |
678 | MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B, | |
679 | MLX4_CMD_NATIVE); | |
680 | } | |
681 | ||
682 | /* For IB, we only consider: | |
683 | * - The capability mask, which is set to the aggregate of all | |
684 | * slave function capabilities | |
685 | * - The QKey violatin counter - reset according to each request. | |
686 | */ | |
687 | ||
688 | if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) { | |
689 | reset_qkey_viols = (*(u8 *) inbox->buf) & 0x40; | |
690 | new_cap_mask = ((__be32 *) inbox->buf)[2]; | |
691 | } else { | |
692 | reset_qkey_viols = ((u8 *) inbox->buf)[3] & 0x1; | |
693 | new_cap_mask = ((__be32 *) inbox->buf)[1]; | |
694 | } | |
695 | ||
efcd235d JM |
696 | /* slave may not set the IS_SM capability for the port */ |
697 | if (slave != mlx4_master_func_num(dev) && | |
698 | (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_IS_SM)) | |
699 | return -EINVAL; | |
700 | ||
701 | /* No DEV_MGMT in multifunc mode */ | |
702 | if (mlx4_is_mfunc(dev) && | |
703 | (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_DEV_MGMT_SUP)) | |
704 | return -EINVAL; | |
705 | ||
ffe455ad EE |
706 | agg_cap_mask = 0; |
707 | slave_cap_mask = | |
708 | priv->mfunc.master.slave_state[slave].ib_cap_mask[port]; | |
709 | priv->mfunc.master.slave_state[slave].ib_cap_mask[port] = new_cap_mask; | |
710 | for (i = 0; i < dev->num_slaves; i++) | |
711 | agg_cap_mask |= | |
712 | priv->mfunc.master.slave_state[i].ib_cap_mask[port]; | |
713 | ||
714 | /* only clear mailbox for guests. Master may be setting | |
715 | * MTU or PKEY table size | |
716 | */ | |
717 | if (slave != dev->caps.function) | |
718 | memset(inbox->buf, 0, 256); | |
719 | if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) { | |
edc4a67e | 720 | *(u8 *) inbox->buf |= !!reset_qkey_viols << 6; |
ffe455ad EE |
721 | ((__be32 *) inbox->buf)[2] = agg_cap_mask; |
722 | } else { | |
edc4a67e | 723 | ((u8 *) inbox->buf)[3] |= !!reset_qkey_viols; |
ffe455ad EE |
724 | ((__be32 *) inbox->buf)[1] = agg_cap_mask; |
725 | } | |
726 | ||
727 | err = mlx4_cmd(dev, inbox->dma, port, is_eth, MLX4_CMD_SET_PORT, | |
728 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); | |
729 | if (err) | |
730 | priv->mfunc.master.slave_state[slave].ib_cap_mask[port] = | |
731 | slave_cap_mask; | |
732 | return err; | |
733 | } | |
734 | ||
735 | int mlx4_SET_PORT_wrapper(struct mlx4_dev *dev, int slave, | |
736 | struct mlx4_vhcr *vhcr, | |
737 | struct mlx4_cmd_mailbox *inbox, | |
738 | struct mlx4_cmd_mailbox *outbox, | |
739 | struct mlx4_cmd_info *cmd) | |
740 | { | |
741 | return mlx4_common_set_port(dev, slave, vhcr->in_modifier, | |
742 | vhcr->op_modifier, inbox); | |
743 | } | |
744 | ||
096335b3 OG |
745 | /* bit locations for set port command with zero op modifier */ |
746 | enum { | |
747 | MLX4_SET_PORT_VL_CAP = 4, /* bits 7:4 */ | |
748 | MLX4_SET_PORT_MTU_CAP = 12, /* bits 15:12 */ | |
6634961c | 749 | MLX4_CHANGE_PORT_PKEY_TBL_SZ = 20, |
096335b3 OG |
750 | MLX4_CHANGE_PORT_VL_CAP = 21, |
751 | MLX4_CHANGE_PORT_MTU_CAP = 22, | |
752 | }; | |
753 | ||
6634961c | 754 | int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port, int pkey_tbl_sz) |
7ff93f8b YP |
755 | { |
756 | struct mlx4_cmd_mailbox *mailbox; | |
6634961c | 757 | int err, vl_cap, pkey_tbl_flag = 0; |
7ff93f8b | 758 | |
352b09ed RD |
759 | if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) |
760 | return 0; | |
761 | ||
7ff93f8b YP |
762 | mailbox = mlx4_alloc_cmd_mailbox(dev); |
763 | if (IS_ERR(mailbox)) | |
764 | return PTR_ERR(mailbox); | |
765 | ||
793730bf | 766 | ((__be32 *) mailbox->buf)[1] = dev->caps.ib_port_def_cap[port]; |
096335b3 | 767 | |
6634961c JM |
768 | if (pkey_tbl_sz >= 0 && mlx4_is_master(dev)) { |
769 | pkey_tbl_flag = 1; | |
770 | ((__be16 *) mailbox->buf)[20] = cpu_to_be16(pkey_tbl_sz); | |
771 | } | |
772 | ||
096335b3 OG |
773 | /* IB VL CAP enum isn't used by the firmware, just numerical values */ |
774 | for (vl_cap = 8; vl_cap >= 1; vl_cap >>= 1) { | |
775 | ((__be32 *) mailbox->buf)[0] = cpu_to_be32( | |
776 | (1 << MLX4_CHANGE_PORT_MTU_CAP) | | |
777 | (1 << MLX4_CHANGE_PORT_VL_CAP) | | |
6634961c | 778 | (pkey_tbl_flag << MLX4_CHANGE_PORT_PKEY_TBL_SZ) | |
096335b3 OG |
779 | (dev->caps.port_ib_mtu[port] << MLX4_SET_PORT_MTU_CAP) | |
780 | (vl_cap << MLX4_SET_PORT_VL_CAP)); | |
781 | err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT, | |
782 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED); | |
783 | if (err != -ENOMEM) | |
784 | break; | |
785 | } | |
7ff93f8b YP |
786 | |
787 | mlx4_free_cmd_mailbox(dev, mailbox); | |
788 | return err; | |
789 | } | |
ffe455ad | 790 | |
cb9ffb76 | 791 | int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu, |
ffe455ad EE |
792 | u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx) |
793 | { | |
794 | struct mlx4_cmd_mailbox *mailbox; | |
795 | struct mlx4_set_port_general_context *context; | |
796 | int err; | |
797 | u32 in_mod; | |
798 | ||
799 | mailbox = mlx4_alloc_cmd_mailbox(dev); | |
800 | if (IS_ERR(mailbox)) | |
801 | return PTR_ERR(mailbox); | |
802 | context = mailbox->buf; | |
ffe455ad EE |
803 | context->flags = SET_PORT_GEN_ALL_VALID; |
804 | context->mtu = cpu_to_be16(mtu); | |
805 | context->pptx = (pptx * (!pfctx)) << 7; | |
806 | context->pfctx = pfctx; | |
807 | context->pprx = (pprx * (!pfcrx)) << 7; | |
808 | context->pfcrx = pfcrx; | |
809 | ||
810 | in_mod = MLX4_SET_PORT_GENERAL << 8 | port; | |
811 | err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT, | |
812 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED); | |
813 | ||
814 | mlx4_free_cmd_mailbox(dev, mailbox); | |
815 | return err; | |
816 | } | |
817 | EXPORT_SYMBOL(mlx4_SET_PORT_general); | |
818 | ||
cb9ffb76 | 819 | int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn, |
ffe455ad EE |
820 | u8 promisc) |
821 | { | |
822 | struct mlx4_cmd_mailbox *mailbox; | |
823 | struct mlx4_set_port_rqp_calc_context *context; | |
824 | int err; | |
825 | u32 in_mod; | |
826 | u32 m_promisc = (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) ? | |
827 | MCAST_DIRECT : MCAST_DEFAULT; | |
828 | ||
c96d97f4 | 829 | if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0) |
ffe455ad EE |
830 | return 0; |
831 | ||
832 | mailbox = mlx4_alloc_cmd_mailbox(dev); | |
833 | if (IS_ERR(mailbox)) | |
834 | return PTR_ERR(mailbox); | |
835 | context = mailbox->buf; | |
ffe455ad EE |
836 | context->base_qpn = cpu_to_be32(base_qpn); |
837 | context->n_mac = dev->caps.log_num_macs; | |
838 | context->promisc = cpu_to_be32(promisc << SET_PORT_PROMISC_SHIFT | | |
839 | base_qpn); | |
840 | context->mcast = cpu_to_be32(m_promisc << SET_PORT_MC_PROMISC_SHIFT | | |
841 | base_qpn); | |
842 | context->intra_no_vlan = 0; | |
843 | context->no_vlan = MLX4_NO_VLAN_IDX; | |
844 | context->intra_vlan_miss = 0; | |
845 | context->vlan_miss = MLX4_VLAN_MISS_IDX; | |
846 | ||
847 | in_mod = MLX4_SET_PORT_RQP_CALC << 8 | port; | |
848 | err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT, | |
849 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED); | |
850 | ||
851 | mlx4_free_cmd_mailbox(dev, mailbox); | |
852 | return err; | |
853 | } | |
854 | EXPORT_SYMBOL(mlx4_SET_PORT_qpn_calc); | |
855 | ||
e5395e92 AV |
856 | int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc) |
857 | { | |
858 | struct mlx4_cmd_mailbox *mailbox; | |
859 | struct mlx4_set_port_prio2tc_context *context; | |
860 | int err; | |
861 | u32 in_mod; | |
862 | int i; | |
863 | ||
864 | mailbox = mlx4_alloc_cmd_mailbox(dev); | |
865 | if (IS_ERR(mailbox)) | |
866 | return PTR_ERR(mailbox); | |
867 | context = mailbox->buf; | |
e5395e92 AV |
868 | for (i = 0; i < MLX4_NUM_UP; i += 2) |
869 | context->prio2tc[i >> 1] = prio2tc[i] << 4 | prio2tc[i + 1]; | |
870 | ||
871 | in_mod = MLX4_SET_PORT_PRIO2TC << 8 | port; | |
872 | err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT, | |
873 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); | |
874 | ||
875 | mlx4_free_cmd_mailbox(dev, mailbox); | |
876 | return err; | |
877 | } | |
878 | EXPORT_SYMBOL(mlx4_SET_PORT_PRIO2TC); | |
879 | ||
880 | int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw, | |
881 | u8 *pg, u16 *ratelimit) | |
882 | { | |
883 | struct mlx4_cmd_mailbox *mailbox; | |
884 | struct mlx4_set_port_scheduler_context *context; | |
885 | int err; | |
886 | u32 in_mod; | |
887 | int i; | |
888 | ||
889 | mailbox = mlx4_alloc_cmd_mailbox(dev); | |
890 | if (IS_ERR(mailbox)) | |
891 | return PTR_ERR(mailbox); | |
892 | context = mailbox->buf; | |
e5395e92 AV |
893 | |
894 | for (i = 0; i < MLX4_NUM_TC; i++) { | |
895 | struct mlx4_port_scheduler_tc_cfg_be *tc = &context->tc[i]; | |
896 | u16 r = ratelimit && ratelimit[i] ? ratelimit[i] : | |
897 | MLX4_RATELIMIT_DEFAULT; | |
898 | ||
899 | tc->pg = htons(pg[i]); | |
900 | tc->bw_precentage = htons(tc_tx_bw[i]); | |
901 | ||
902 | tc->max_bw_units = htons(MLX4_RATELIMIT_UNITS); | |
903 | tc->max_bw_value = htons(r); | |
904 | } | |
905 | ||
906 | in_mod = MLX4_SET_PORT_SCHEDULER << 8 | port; | |
907 | err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT, | |
908 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); | |
909 | ||
910 | mlx4_free_cmd_mailbox(dev, mailbox); | |
911 | return err; | |
912 | } | |
913 | EXPORT_SYMBOL(mlx4_SET_PORT_SCHEDULER); | |
914 | ||
7ffdf726 OG |
915 | enum { |
916 | VXLAN_ENABLE_MODIFY = 1 << 7, | |
917 | VXLAN_STEERING_MODIFY = 1 << 6, | |
918 | ||
919 | VXLAN_ENABLE = 1 << 7, | |
920 | }; | |
921 | ||
922 | struct mlx4_set_port_vxlan_context { | |
923 | u32 reserved1; | |
924 | u8 modify_flags; | |
925 | u8 reserved2; | |
926 | u8 enable_flags; | |
927 | u8 steering; | |
928 | }; | |
929 | ||
930 | int mlx4_SET_PORT_VXLAN(struct mlx4_dev *dev, u8 port, u8 steering) | |
931 | { | |
932 | int err; | |
933 | u32 in_mod; | |
934 | struct mlx4_cmd_mailbox *mailbox; | |
935 | struct mlx4_set_port_vxlan_context *context; | |
936 | ||
937 | mailbox = mlx4_alloc_cmd_mailbox(dev); | |
938 | if (IS_ERR(mailbox)) | |
939 | return PTR_ERR(mailbox); | |
940 | context = mailbox->buf; | |
941 | memset(context, 0, sizeof(*context)); | |
942 | ||
943 | context->modify_flags = VXLAN_ENABLE_MODIFY | VXLAN_STEERING_MODIFY; | |
944 | context->enable_flags = VXLAN_ENABLE; | |
945 | context->steering = steering; | |
946 | ||
947 | in_mod = MLX4_SET_PORT_VXLAN << 8 | port; | |
948 | err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT, | |
949 | MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); | |
950 | ||
951 | mlx4_free_cmd_mailbox(dev, mailbox); | |
952 | return err; | |
953 | } | |
954 | EXPORT_SYMBOL(mlx4_SET_PORT_VXLAN); | |
955 | ||
ffe455ad EE |
956 | int mlx4_SET_MCAST_FLTR_wrapper(struct mlx4_dev *dev, int slave, |
957 | struct mlx4_vhcr *vhcr, | |
958 | struct mlx4_cmd_mailbox *inbox, | |
959 | struct mlx4_cmd_mailbox *outbox, | |
960 | struct mlx4_cmd_info *cmd) | |
961 | { | |
962 | int err = 0; | |
963 | ||
964 | return err; | |
965 | } | |
966 | ||
967 | int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, | |
968 | u64 mac, u64 clear, u8 mode) | |
969 | { | |
970 | return mlx4_cmd(dev, (mac | (clear << 63)), port, mode, | |
971 | MLX4_CMD_SET_MCAST_FLTR, MLX4_CMD_TIME_CLASS_B, | |
972 | MLX4_CMD_WRAPPED); | |
973 | } | |
974 | EXPORT_SYMBOL(mlx4_SET_MCAST_FLTR); | |
975 | ||
976 | int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave, | |
977 | struct mlx4_vhcr *vhcr, | |
978 | struct mlx4_cmd_mailbox *inbox, | |
979 | struct mlx4_cmd_mailbox *outbox, | |
980 | struct mlx4_cmd_info *cmd) | |
981 | { | |
982 | int err = 0; | |
983 | ||
984 | return err; | |
985 | } | |
986 | ||
987 | int mlx4_common_dump_eth_stats(struct mlx4_dev *dev, int slave, | |
988 | u32 in_mod, struct mlx4_cmd_mailbox *outbox) | |
989 | { | |
990 | return mlx4_cmd_box(dev, 0, outbox->dma, in_mod, 0, | |
991 | MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B, | |
992 | MLX4_CMD_NATIVE); | |
993 | } | |
994 | ||
995 | int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave, | |
996 | struct mlx4_vhcr *vhcr, | |
997 | struct mlx4_cmd_mailbox *inbox, | |
998 | struct mlx4_cmd_mailbox *outbox, | |
999 | struct mlx4_cmd_info *cmd) | |
1000 | { | |
35fb9afb EE |
1001 | if (slave != dev->caps.function) |
1002 | return 0; | |
ffe455ad EE |
1003 | return mlx4_common_dump_eth_stats(dev, slave, |
1004 | vhcr->in_modifier, outbox); | |
1005 | } | |
93ece0c1 EE |
1006 | |
1007 | void mlx4_set_stats_bitmap(struct mlx4_dev *dev, u64 *stats_bitmap) | |
1008 | { | |
1009 | if (!mlx4_is_mfunc(dev)) { | |
1010 | *stats_bitmap = 0; | |
1011 | return; | |
1012 | } | |
1013 | ||
1014 | *stats_bitmap = (MLX4_STATS_TRAFFIC_COUNTERS_MASK | | |
1015 | MLX4_STATS_TRAFFIC_DROPS_MASK | | |
1016 | MLX4_STATS_PORT_COUNTERS_MASK); | |
1017 | ||
1018 | if (mlx4_is_master(dev)) | |
1019 | *stats_bitmap |= MLX4_STATS_ERROR_COUNTERS_MASK; | |
1020 | } | |
1021 | EXPORT_SYMBOL(mlx4_set_stats_bitmap); | |
6ee51a4e | 1022 | |
9cd59352 JM |
1023 | int mlx4_get_slave_from_roce_gid(struct mlx4_dev *dev, int port, u8 *gid, |
1024 | int *slave_id) | |
6ee51a4e JM |
1025 | { |
1026 | struct mlx4_priv *priv = mlx4_priv(dev); | |
1027 | int i, found_ix = -1; | |
b6ffaeff | 1028 | int vf_gids = MLX4_ROCE_MAX_GIDS - MLX4_ROCE_PF_GIDS; |
6ee51a4e JM |
1029 | |
1030 | if (!mlx4_is_mfunc(dev)) | |
1031 | return -EINVAL; | |
1032 | ||
1033 | for (i = 0; i < MLX4_ROCE_MAX_GIDS; i++) { | |
1034 | if (!memcmp(priv->roce_gids[port - 1][i].raw, gid, 16)) { | |
1035 | found_ix = i; | |
1036 | break; | |
1037 | } | |
1038 | } | |
1039 | ||
b6ffaeff JM |
1040 | if (found_ix >= 0) { |
1041 | if (found_ix < MLX4_ROCE_PF_GIDS) | |
1042 | *slave_id = 0; | |
1043 | else if (found_ix < MLX4_ROCE_PF_GIDS + (vf_gids % dev->num_vfs) * | |
1044 | (vf_gids / dev->num_vfs + 1)) | |
1045 | *slave_id = ((found_ix - MLX4_ROCE_PF_GIDS) / | |
1046 | (vf_gids / dev->num_vfs + 1)) + 1; | |
1047 | else | |
1048 | *slave_id = | |
1049 | ((found_ix - MLX4_ROCE_PF_GIDS - | |
1050 | ((vf_gids % dev->num_vfs) * ((vf_gids / dev->num_vfs + 1)))) / | |
1051 | (vf_gids / dev->num_vfs)) + vf_gids % dev->num_vfs + 1; | |
1052 | } | |
6ee51a4e JM |
1053 | |
1054 | return (found_ix >= 0) ? 0 : -EINVAL; | |
1055 | } | |
1056 | EXPORT_SYMBOL(mlx4_get_slave_from_roce_gid); | |
1057 | ||
9cd59352 JM |
1058 | int mlx4_get_roce_gid_from_slave(struct mlx4_dev *dev, int port, int slave_id, |
1059 | u8 *gid) | |
6ee51a4e JM |
1060 | { |
1061 | struct mlx4_priv *priv = mlx4_priv(dev); | |
1062 | ||
1063 | if (!mlx4_is_master(dev)) | |
1064 | return -EINVAL; | |
1065 | ||
1066 | memcpy(gid, priv->roce_gids[port - 1][slave_id].raw, 16); | |
1067 | return 0; | |
1068 | } | |
1069 | EXPORT_SYMBOL(mlx4_get_roce_gid_from_slave); |