blob: 4b6aad39e72cd97d09d8deff9f35390684a700bf [file] [log] [blame]
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001/*
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>
Eugenia Emantayevc59fec22013-04-11 01:56:42 +000035#include <linux/if_vlan.h>
Paul Gortmakeree40fa02011-05-27 16:14:23 -040036#include <linux/export.h>
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -070037
38#include <linux/mlx4/cmd.h>
39
40#include "mlx4.h"
41
42#define MLX4_MAC_VALID (1ull << 63)
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -070043
44#define MLX4_VLAN_VALID (1u << 31)
45#define MLX4_VLAN_MASK 0xfff
46
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +000047#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
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -070052void 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
65void 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 }
Yevgeny Petriline72ebf52011-10-18 01:50:29 +000074 table->max = (1 << dev->caps.log_num_vlans) - MLX4_VLAN_REGULAR;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -070075 table->total = 0;
76}
77
Yevgeny Petrilin16792002011-03-22 22:38:31 +000078static int validate_index(struct mlx4_dev *dev,
79 struct mlx4_mac_table *table, int index)
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -070080{
Yevgeny Petrilin16792002011-03-22 22:38:31 +000081 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
90static int find_index(struct mlx4_dev *dev,
91 struct mlx4_mac_table *table, u64 mac)
92{
93 int i;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +000094
Yevgeny Petrilin16792002011-03-22 22:38:31 +000095 for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +000096 if ((mac & MLX4_MAC_MASK) ==
97 (MLX4_MAC_MASK & be64_to_cpu(table->entries[i])))
Yevgeny Petrilin16792002011-03-22 22:38:31 +000098 return i;
99 }
100 /* Mac not found */
101 return -EINVAL;
102}
103
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000104static 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;
118
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
126int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
127{
128 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
129 struct mlx4_mac_table *table = &info->mac_table;
130 int i, err = 0;
131 int free = -1;
132
133 mlx4_dbg(dev, "Registering MAC: 0x%llx for port %d\n",
134 (unsigned long long) mac, port);
135
136 mutex_lock(&table->mutex);
137 for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
138 if (free < 0 && !table->entries[i]) {
139 free = i;
140 continue;
141 }
142
143 if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) {
144 /* MAC already registered, Must not have duplicates */
145 err = -EEXIST;
146 goto out;
147 }
148 }
149
150 mlx4_dbg(dev, "Free MAC index is %d\n", free);
151
152 if (table->total == table->max) {
153 /* No free mac entries */
154 err = -ENOSPC;
155 goto out;
156 }
157
158 /* Register new MAC */
159 table->entries[free] = cpu_to_be64(mac | MLX4_MAC_VALID);
160
161 err = mlx4_set_port_mac_table(dev, port, table->entries);
162 if (unlikely(err)) {
163 mlx4_err(dev, "Failed adding MAC: 0x%llx\n",
164 (unsigned long long) mac);
165 table->entries[free] = 0;
166 goto out;
167 }
168
169 err = free;
170 ++table->total;
171out:
172 mutex_unlock(&table->mutex);
173 return err;
174}
175EXPORT_SYMBOL_GPL(__mlx4_register_mac);
176
177int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
178{
Jack Morgensteine7dbeba2013-03-07 03:46:54 +0000179 u64 out_param = 0;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000180 int err;
181
182 if (mlx4_is_mfunc(dev)) {
183 set_param_l(&out_param, port);
184 err = mlx4_cmd_imm(dev, mac, &out_param, RES_MAC,
185 RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES,
186 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
187 if (err)
188 return err;
189
190 return get_param_l(&out_param);
191 }
192 return __mlx4_register_mac(dev, port, mac);
193}
194EXPORT_SYMBOL_GPL(mlx4_register_mac);
195
Yan Burman16a10ff2013-02-07 02:25:22 +0000196int mlx4_get_base_qpn(struct mlx4_dev *dev, u8 port)
197{
198 return dev->caps.reserved_qps_base[MLX4_QP_REGION_ETH_ADDR] +
199 (port - 1) * (1 << dev->caps.log_num_macs);
200}
201EXPORT_SYMBOL_GPL(mlx4_get_base_qpn);
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000202
203void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
204{
205 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
206 struct mlx4_mac_table *table = &info->mac_table;
207 int index;
208
209 index = find_index(dev, table, mac);
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700210
211 mutex_lock(&table->mutex);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000212
213 if (validate_index(dev, table, index))
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700214 goto out;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000215
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000216 table->entries[index] = 0;
217 mlx4_set_port_mac_table(dev, port, table->entries);
218 --table->total;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700219out:
220 mutex_unlock(&table->mutex);
221}
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000222EXPORT_SYMBOL_GPL(__mlx4_unregister_mac);
223
224void mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
225{
Jack Morgensteine7dbeba2013-03-07 03:46:54 +0000226 u64 out_param = 0;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000227
228 if (mlx4_is_mfunc(dev)) {
229 set_param_l(&out_param, port);
Or Gerlitz162344e2012-05-15 10:34:57 +0000230 (void) mlx4_cmd_imm(dev, mac, &out_param, RES_MAC,
231 RES_OP_RESERVE_AND_MAP, MLX4_CMD_FREE_RES,
232 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000233 return;
234 }
235 __mlx4_unregister_mac(dev, port, mac);
236 return;
237}
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700238EXPORT_SYMBOL_GPL(mlx4_unregister_mac);
239
Yan Burman16a10ff2013-02-07 02:25:22 +0000240int __mlx4_replace_mac(struct mlx4_dev *dev, u8 port, int qpn, u64 new_mac)
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000241{
242 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
243 struct mlx4_mac_table *table = &info->mac_table;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000244 int index = qpn - info->base_qpn;
245 int err = 0;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000246
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000247 /* CX1 doesn't support multi-functions */
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000248 mutex_lock(&table->mutex);
249
250 err = validate_index(dev, table, index);
251 if (err)
252 goto out;
253
254 table->entries[index] = cpu_to_be64(new_mac | MLX4_MAC_VALID);
255
256 err = mlx4_set_port_mac_table(dev, port, table->entries);
257 if (unlikely(err)) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000258 mlx4_err(dev, "Failed adding MAC: 0x%llx\n",
259 (unsigned long long) new_mac);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000260 table->entries[index] = 0;
261 }
262out:
263 mutex_unlock(&table->mutex);
264 return err;
265}
Yan Burman16a10ff2013-02-07 02:25:22 +0000266EXPORT_SYMBOL_GPL(__mlx4_replace_mac);
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000267
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700268static int mlx4_set_port_vlan_table(struct mlx4_dev *dev, u8 port,
269 __be32 *entries)
270{
271 struct mlx4_cmd_mailbox *mailbox;
272 u32 in_mod;
273 int err;
274
275 mailbox = mlx4_alloc_cmd_mailbox(dev);
276 if (IS_ERR(mailbox))
277 return PTR_ERR(mailbox);
278
279 memcpy(mailbox->buf, entries, MLX4_VLAN_TABLE_SIZE);
280 in_mod = MLX4_SET_PORT_VLAN_TABLE << 8 | port;
281 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
Jack Morgensteinf9baff52011-12-13 04:10:51 +0000282 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700283
284 mlx4_free_cmd_mailbox(dev, mailbox);
285
286 return err;
287}
288
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300289int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx)
290{
291 struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
292 int i;
293
294 for (i = 0; i < MLX4_MAX_VLAN_NUM; ++i) {
295 if (table->refs[i] &&
296 (vid == (MLX4_VLAN_MASK &
297 be32_to_cpu(table->entries[i])))) {
298 /* VLAN already registered, increase reference count */
299 *idx = i;
300 return 0;
301 }
302 }
303
304 return -ENOENT;
305}
306EXPORT_SYMBOL_GPL(mlx4_find_cached_vlan);
307
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000308static int __mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan,
309 int *index)
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700310{
311 struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
312 int i, err = 0;
313 int free = -1;
314
315 mutex_lock(&table->mutex);
Yevgeny Petriline72ebf52011-10-18 01:50:29 +0000316
317 if (table->total == table->max) {
318 /* No free vlan entries */
319 err = -ENOSPC;
320 goto out;
321 }
322
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700323 for (i = MLX4_VLAN_REGULAR; i < MLX4_MAX_VLAN_NUM; i++) {
324 if (free < 0 && (table->refs[i] == 0)) {
325 free = i;
326 continue;
327 }
328
329 if (table->refs[i] &&
330 (vlan == (MLX4_VLAN_MASK &
331 be32_to_cpu(table->entries[i])))) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300332 /* Vlan already registered, increase references count */
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700333 *index = i;
334 ++table->refs[i];
335 goto out;
336 }
337 }
338
Eli Cohen0926f912010-10-25 02:56:47 +0000339 if (free < 0) {
340 err = -ENOMEM;
341 goto out;
342 }
343
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000344 /* Register new VLAN */
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700345 table->refs[free] = 1;
346 table->entries[free] = cpu_to_be32(vlan | MLX4_VLAN_VALID);
347
348 err = mlx4_set_port_vlan_table(dev, port, table->entries);
349 if (unlikely(err)) {
350 mlx4_warn(dev, "Failed adding vlan: %u\n", vlan);
351 table->refs[free] = 0;
352 table->entries[free] = 0;
353 goto out;
354 }
355
356 *index = free;
357 ++table->total;
358out:
359 mutex_unlock(&table->mutex);
360 return err;
361}
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000362
363int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index)
364{
Jack Morgensteine7dbeba2013-03-07 03:46:54 +0000365 u64 out_param = 0;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000366 int err;
367
368 if (mlx4_is_mfunc(dev)) {
369 set_param_l(&out_param, port);
370 err = mlx4_cmd_imm(dev, vlan, &out_param, RES_VLAN,
371 RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES,
372 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
373 if (!err)
374 *index = get_param_l(&out_param);
375
376 return err;
377 }
378 return __mlx4_register_vlan(dev, port, vlan, index);
379}
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700380EXPORT_SYMBOL_GPL(mlx4_register_vlan);
381
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000382static void __mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index)
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700383{
384 struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
385
386 if (index < MLX4_VLAN_REGULAR) {
387 mlx4_warn(dev, "Trying to free special vlan index %d\n", index);
388 return;
389 }
390
391 mutex_lock(&table->mutex);
392 if (!table->refs[index]) {
393 mlx4_warn(dev, "No vlan entry for index %d\n", index);
394 goto out;
395 }
396 if (--table->refs[index]) {
397 mlx4_dbg(dev, "Have more references for index %d,"
398 "no need to modify vlan table\n", index);
399 goto out;
400 }
401 table->entries[index] = 0;
402 mlx4_set_port_vlan_table(dev, port, table->entries);
403 --table->total;
404out:
405 mutex_unlock(&table->mutex);
406}
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000407
408void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index)
409{
Jack Morgensteine7dbeba2013-03-07 03:46:54 +0000410 u64 in_param = 0;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000411 int err;
412
413 if (mlx4_is_mfunc(dev)) {
414 set_param_l(&in_param, port);
415 err = mlx4_cmd(dev, in_param, RES_VLAN, RES_OP_RESERVE_AND_MAP,
416 MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A,
417 MLX4_CMD_WRAPPED);
418 if (!err)
419 mlx4_warn(dev, "Failed freeing vlan at index:%d\n",
420 index);
421
422 return;
423 }
424 __mlx4_unregister_vlan(dev, port, index);
425}
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700426EXPORT_SYMBOL_GPL(mlx4_unregister_vlan);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700427
Jack Morgenstein9a5aa622008-11-28 21:29:46 -0800428int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps)
429{
430 struct mlx4_cmd_mailbox *inmailbox, *outmailbox;
431 u8 *inbuf, *outbuf;
432 int err;
433
434 inmailbox = mlx4_alloc_cmd_mailbox(dev);
435 if (IS_ERR(inmailbox))
436 return PTR_ERR(inmailbox);
437
438 outmailbox = mlx4_alloc_cmd_mailbox(dev);
439 if (IS_ERR(outmailbox)) {
440 mlx4_free_cmd_mailbox(dev, inmailbox);
441 return PTR_ERR(outmailbox);
442 }
443
444 inbuf = inmailbox->buf;
445 outbuf = outmailbox->buf;
446 memset(inbuf, 0, 256);
447 memset(outbuf, 0, 256);
448 inbuf[0] = 1;
449 inbuf[1] = 1;
450 inbuf[2] = 1;
451 inbuf[3] = 1;
452 *(__be16 *) (&inbuf[16]) = cpu_to_be16(0x0015);
453 *(__be32 *) (&inbuf[20]) = cpu_to_be32(port);
454
455 err = mlx4_cmd_box(dev, inmailbox->dma, outmailbox->dma, port, 3,
Jack Morgensteinf9baff52011-12-13 04:10:51 +0000456 MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C,
457 MLX4_CMD_NATIVE);
Jack Morgenstein9a5aa622008-11-28 21:29:46 -0800458 if (!err)
459 *caps = *(__be32 *) (outbuf + 84);
460 mlx4_free_cmd_mailbox(dev, inmailbox);
461 mlx4_free_cmd_mailbox(dev, outmailbox);
462 return err;
463}
464
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000465static int mlx4_common_set_port(struct mlx4_dev *dev, int slave, u32 in_mod,
466 u8 op_mod, struct mlx4_cmd_mailbox *inbox)
467{
468 struct mlx4_priv *priv = mlx4_priv(dev);
469 struct mlx4_port_info *port_info;
470 struct mlx4_mfunc_master_ctx *master = &priv->mfunc.master;
471 struct mlx4_slave_state *slave_st = &master->slave_state[slave];
472 struct mlx4_set_port_rqp_calc_context *qpn_context;
473 struct mlx4_set_port_general_context *gen_context;
474 int reset_qkey_viols;
475 int port;
476 int is_eth;
477 u32 in_modifier;
478 u32 promisc;
479 u16 mtu, prev_mtu;
480 int err;
481 int i;
482 __be32 agg_cap_mask;
483 __be32 slave_cap_mask;
484 __be32 new_cap_mask;
485
486 port = in_mod & 0xff;
487 in_modifier = in_mod >> 8;
488 is_eth = op_mod;
489 port_info = &priv->port[port];
490
491 /* Slaves cannot perform SET_PORT operations except changing MTU */
492 if (is_eth) {
493 if (slave != dev->caps.function &&
494 in_modifier != MLX4_SET_PORT_GENERAL) {
495 mlx4_warn(dev, "denying SET_PORT for slave:%d\n",
496 slave);
497 return -EINVAL;
498 }
499 switch (in_modifier) {
500 case MLX4_SET_PORT_RQP_CALC:
501 qpn_context = inbox->buf;
502 qpn_context->base_qpn =
503 cpu_to_be32(port_info->base_qpn);
504 qpn_context->n_mac = 0x7;
505 promisc = be32_to_cpu(qpn_context->promisc) >>
506 SET_PORT_PROMISC_SHIFT;
507 qpn_context->promisc = cpu_to_be32(
508 promisc << SET_PORT_PROMISC_SHIFT |
509 port_info->base_qpn);
510 promisc = be32_to_cpu(qpn_context->mcast) >>
511 SET_PORT_MC_PROMISC_SHIFT;
512 qpn_context->mcast = cpu_to_be32(
513 promisc << SET_PORT_MC_PROMISC_SHIFT |
514 port_info->base_qpn);
515 break;
516 case MLX4_SET_PORT_GENERAL:
517 gen_context = inbox->buf;
518 /* Mtu is configured as the max MTU among all the
519 * the functions on the port. */
520 mtu = be16_to_cpu(gen_context->mtu);
Eugenia Emantayevc59fec22013-04-11 01:56:42 +0000521 mtu = min_t(int, mtu, dev->caps.eth_mtu_cap[port] +
522 ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000523 prev_mtu = slave_st->mtu[port];
524 slave_st->mtu[port] = mtu;
525 if (mtu > master->max_mtu[port])
526 master->max_mtu[port] = mtu;
527 if (mtu < prev_mtu && prev_mtu ==
528 master->max_mtu[port]) {
529 slave_st->mtu[port] = mtu;
530 master->max_mtu[port] = mtu;
531 for (i = 0; i < dev->num_slaves; i++) {
532 master->max_mtu[port] =
533 max(master->max_mtu[port],
534 master->slave_state[i].mtu[port]);
535 }
536 }
537
538 gen_context->mtu = cpu_to_be16(master->max_mtu[port]);
539 break;
540 }
541 return mlx4_cmd(dev, inbox->dma, in_mod, op_mod,
542 MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B,
543 MLX4_CMD_NATIVE);
544 }
545
546 /* For IB, we only consider:
547 * - The capability mask, which is set to the aggregate of all
548 * slave function capabilities
549 * - The QKey violatin counter - reset according to each request.
550 */
551
552 if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
553 reset_qkey_viols = (*(u8 *) inbox->buf) & 0x40;
554 new_cap_mask = ((__be32 *) inbox->buf)[2];
555 } else {
556 reset_qkey_viols = ((u8 *) inbox->buf)[3] & 0x1;
557 new_cap_mask = ((__be32 *) inbox->buf)[1];
558 }
559
Jack Morgensteinefcd2352012-08-03 08:40:52 +0000560 /* slave may not set the IS_SM capability for the port */
561 if (slave != mlx4_master_func_num(dev) &&
562 (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_IS_SM))
563 return -EINVAL;
564
565 /* No DEV_MGMT in multifunc mode */
566 if (mlx4_is_mfunc(dev) &&
567 (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_DEV_MGMT_SUP))
568 return -EINVAL;
569
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000570 agg_cap_mask = 0;
571 slave_cap_mask =
572 priv->mfunc.master.slave_state[slave].ib_cap_mask[port];
573 priv->mfunc.master.slave_state[slave].ib_cap_mask[port] = new_cap_mask;
574 for (i = 0; i < dev->num_slaves; i++)
575 agg_cap_mask |=
576 priv->mfunc.master.slave_state[i].ib_cap_mask[port];
577
578 /* only clear mailbox for guests. Master may be setting
579 * MTU or PKEY table size
580 */
581 if (slave != dev->caps.function)
582 memset(inbox->buf, 0, 256);
583 if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
Jack Morgensteinedc4a672012-05-24 16:08:09 +0300584 *(u8 *) inbox->buf |= !!reset_qkey_viols << 6;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000585 ((__be32 *) inbox->buf)[2] = agg_cap_mask;
586 } else {
Jack Morgensteinedc4a672012-05-24 16:08:09 +0300587 ((u8 *) inbox->buf)[3] |= !!reset_qkey_viols;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000588 ((__be32 *) inbox->buf)[1] = agg_cap_mask;
589 }
590
591 err = mlx4_cmd(dev, inbox->dma, port, is_eth, MLX4_CMD_SET_PORT,
592 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
593 if (err)
594 priv->mfunc.master.slave_state[slave].ib_cap_mask[port] =
595 slave_cap_mask;
596 return err;
597}
598
599int mlx4_SET_PORT_wrapper(struct mlx4_dev *dev, int slave,
600 struct mlx4_vhcr *vhcr,
601 struct mlx4_cmd_mailbox *inbox,
602 struct mlx4_cmd_mailbox *outbox,
603 struct mlx4_cmd_info *cmd)
604{
605 return mlx4_common_set_port(dev, slave, vhcr->in_modifier,
606 vhcr->op_modifier, inbox);
607}
608
Or Gerlitz096335b2012-01-11 19:02:17 +0200609/* bit locations for set port command with zero op modifier */
610enum {
611 MLX4_SET_PORT_VL_CAP = 4, /* bits 7:4 */
612 MLX4_SET_PORT_MTU_CAP = 12, /* bits 15:12 */
Jack Morgenstein66349612012-06-19 11:21:44 +0300613 MLX4_CHANGE_PORT_PKEY_TBL_SZ = 20,
Or Gerlitz096335b2012-01-11 19:02:17 +0200614 MLX4_CHANGE_PORT_VL_CAP = 21,
615 MLX4_CHANGE_PORT_MTU_CAP = 22,
616};
617
Jack Morgenstein66349612012-06-19 11:21:44 +0300618int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port, int pkey_tbl_sz)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700619{
620 struct mlx4_cmd_mailbox *mailbox;
Jack Morgenstein66349612012-06-19 11:21:44 +0300621 int err, vl_cap, pkey_tbl_flag = 0;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700622
Roland Dreier352b09e2009-03-31 09:54:15 -0700623 if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH)
624 return 0;
625
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700626 mailbox = mlx4_alloc_cmd_mailbox(dev);
627 if (IS_ERR(mailbox))
628 return PTR_ERR(mailbox);
629
630 memset(mailbox->buf, 0, 256);
Yevgeny Petrilin793730b2009-03-11 15:47:18 -0700631
632 ((__be32 *) mailbox->buf)[1] = dev->caps.ib_port_def_cap[port];
Or Gerlitz096335b2012-01-11 19:02:17 +0200633
Jack Morgenstein66349612012-06-19 11:21:44 +0300634 if (pkey_tbl_sz >= 0 && mlx4_is_master(dev)) {
635 pkey_tbl_flag = 1;
636 ((__be16 *) mailbox->buf)[20] = cpu_to_be16(pkey_tbl_sz);
637 }
638
Or Gerlitz096335b2012-01-11 19:02:17 +0200639 /* IB VL CAP enum isn't used by the firmware, just numerical values */
640 for (vl_cap = 8; vl_cap >= 1; vl_cap >>= 1) {
641 ((__be32 *) mailbox->buf)[0] = cpu_to_be32(
642 (1 << MLX4_CHANGE_PORT_MTU_CAP) |
643 (1 << MLX4_CHANGE_PORT_VL_CAP) |
Jack Morgenstein66349612012-06-19 11:21:44 +0300644 (pkey_tbl_flag << MLX4_CHANGE_PORT_PKEY_TBL_SZ) |
Or Gerlitz096335b2012-01-11 19:02:17 +0200645 (dev->caps.port_ib_mtu[port] << MLX4_SET_PORT_MTU_CAP) |
646 (vl_cap << MLX4_SET_PORT_VL_CAP));
647 err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT,
648 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
649 if (err != -ENOMEM)
650 break;
651 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700652
653 mlx4_free_cmd_mailbox(dev, mailbox);
654 return err;
655}
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000656
Joerg Roedelcb9ffb72011-12-15 06:48:37 +0000657int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000658 u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx)
659{
660 struct mlx4_cmd_mailbox *mailbox;
661 struct mlx4_set_port_general_context *context;
662 int err;
663 u32 in_mod;
664
665 mailbox = mlx4_alloc_cmd_mailbox(dev);
666 if (IS_ERR(mailbox))
667 return PTR_ERR(mailbox);
668 context = mailbox->buf;
669 memset(context, 0, sizeof *context);
670
671 context->flags = SET_PORT_GEN_ALL_VALID;
672 context->mtu = cpu_to_be16(mtu);
673 context->pptx = (pptx * (!pfctx)) << 7;
674 context->pfctx = pfctx;
675 context->pprx = (pprx * (!pfcrx)) << 7;
676 context->pfcrx = pfcrx;
677
678 in_mod = MLX4_SET_PORT_GENERAL << 8 | port;
679 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
680 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
681
682 mlx4_free_cmd_mailbox(dev, mailbox);
683 return err;
684}
685EXPORT_SYMBOL(mlx4_SET_PORT_general);
686
Joerg Roedelcb9ffb72011-12-15 06:48:37 +0000687int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000688 u8 promisc)
689{
690 struct mlx4_cmd_mailbox *mailbox;
691 struct mlx4_set_port_rqp_calc_context *context;
692 int err;
693 u32 in_mod;
694 u32 m_promisc = (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) ?
695 MCAST_DIRECT : MCAST_DEFAULT;
696
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000697 if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000698 return 0;
699
700 mailbox = mlx4_alloc_cmd_mailbox(dev);
701 if (IS_ERR(mailbox))
702 return PTR_ERR(mailbox);
703 context = mailbox->buf;
704 memset(context, 0, sizeof *context);
705
706 context->base_qpn = cpu_to_be32(base_qpn);
707 context->n_mac = dev->caps.log_num_macs;
708 context->promisc = cpu_to_be32(promisc << SET_PORT_PROMISC_SHIFT |
709 base_qpn);
710 context->mcast = cpu_to_be32(m_promisc << SET_PORT_MC_PROMISC_SHIFT |
711 base_qpn);
712 context->intra_no_vlan = 0;
713 context->no_vlan = MLX4_NO_VLAN_IDX;
714 context->intra_vlan_miss = 0;
715 context->vlan_miss = MLX4_VLAN_MISS_IDX;
716
717 in_mod = MLX4_SET_PORT_RQP_CALC << 8 | port;
718 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
719 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
720
721 mlx4_free_cmd_mailbox(dev, mailbox);
722 return err;
723}
724EXPORT_SYMBOL(mlx4_SET_PORT_qpn_calc);
725
Amir Vadaie5395e92012-04-04 21:33:25 +0000726int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc)
727{
728 struct mlx4_cmd_mailbox *mailbox;
729 struct mlx4_set_port_prio2tc_context *context;
730 int err;
731 u32 in_mod;
732 int i;
733
734 mailbox = mlx4_alloc_cmd_mailbox(dev);
735 if (IS_ERR(mailbox))
736 return PTR_ERR(mailbox);
737 context = mailbox->buf;
738 memset(context, 0, sizeof *context);
739
740 for (i = 0; i < MLX4_NUM_UP; i += 2)
741 context->prio2tc[i >> 1] = prio2tc[i] << 4 | prio2tc[i + 1];
742
743 in_mod = MLX4_SET_PORT_PRIO2TC << 8 | port;
744 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
745 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
746
747 mlx4_free_cmd_mailbox(dev, mailbox);
748 return err;
749}
750EXPORT_SYMBOL(mlx4_SET_PORT_PRIO2TC);
751
752int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw,
753 u8 *pg, u16 *ratelimit)
754{
755 struct mlx4_cmd_mailbox *mailbox;
756 struct mlx4_set_port_scheduler_context *context;
757 int err;
758 u32 in_mod;
759 int i;
760
761 mailbox = mlx4_alloc_cmd_mailbox(dev);
762 if (IS_ERR(mailbox))
763 return PTR_ERR(mailbox);
764 context = mailbox->buf;
765 memset(context, 0, sizeof *context);
766
767 for (i = 0; i < MLX4_NUM_TC; i++) {
768 struct mlx4_port_scheduler_tc_cfg_be *tc = &context->tc[i];
769 u16 r = ratelimit && ratelimit[i] ? ratelimit[i] :
770 MLX4_RATELIMIT_DEFAULT;
771
772 tc->pg = htons(pg[i]);
773 tc->bw_precentage = htons(tc_tx_bw[i]);
774
775 tc->max_bw_units = htons(MLX4_RATELIMIT_UNITS);
776 tc->max_bw_value = htons(r);
777 }
778
779 in_mod = MLX4_SET_PORT_SCHEDULER << 8 | port;
780 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
781 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
782
783 mlx4_free_cmd_mailbox(dev, mailbox);
784 return err;
785}
786EXPORT_SYMBOL(mlx4_SET_PORT_SCHEDULER);
787
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000788int mlx4_SET_MCAST_FLTR_wrapper(struct mlx4_dev *dev, int slave,
789 struct mlx4_vhcr *vhcr,
790 struct mlx4_cmd_mailbox *inbox,
791 struct mlx4_cmd_mailbox *outbox,
792 struct mlx4_cmd_info *cmd)
793{
794 int err = 0;
795
796 return err;
797}
798
799int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port,
800 u64 mac, u64 clear, u8 mode)
801{
802 return mlx4_cmd(dev, (mac | (clear << 63)), port, mode,
803 MLX4_CMD_SET_MCAST_FLTR, MLX4_CMD_TIME_CLASS_B,
804 MLX4_CMD_WRAPPED);
805}
806EXPORT_SYMBOL(mlx4_SET_MCAST_FLTR);
807
808int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave,
809 struct mlx4_vhcr *vhcr,
810 struct mlx4_cmd_mailbox *inbox,
811 struct mlx4_cmd_mailbox *outbox,
812 struct mlx4_cmd_info *cmd)
813{
814 int err = 0;
815
816 return err;
817}
818
819int mlx4_common_dump_eth_stats(struct mlx4_dev *dev, int slave,
820 u32 in_mod, struct mlx4_cmd_mailbox *outbox)
821{
822 return mlx4_cmd_box(dev, 0, outbox->dma, in_mod, 0,
823 MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
824 MLX4_CMD_NATIVE);
825}
826
827int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
828 struct mlx4_vhcr *vhcr,
829 struct mlx4_cmd_mailbox *inbox,
830 struct mlx4_cmd_mailbox *outbox,
831 struct mlx4_cmd_info *cmd)
832{
Eugenia Emantayev35fb9af2012-01-19 09:44:37 +0000833 if (slave != dev->caps.function)
834 return 0;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000835 return mlx4_common_dump_eth_stats(dev, slave,
836 vhcr->in_modifier, outbox);
837}
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000838
839void mlx4_set_stats_bitmap(struct mlx4_dev *dev, u64 *stats_bitmap)
840{
841 if (!mlx4_is_mfunc(dev)) {
842 *stats_bitmap = 0;
843 return;
844 }
845
846 *stats_bitmap = (MLX4_STATS_TRAFFIC_COUNTERS_MASK |
847 MLX4_STATS_TRAFFIC_DROPS_MASK |
848 MLX4_STATS_PORT_COUNTERS_MASK);
849
850 if (mlx4_is_master(dev))
851 *stats_bitmap |= MLX4_STATS_ERROR_COUNTERS_MASK;
852}
853EXPORT_SYMBOL(mlx4_set_stats_bitmap);