33 #include <linux/errno.h>
34 #include <linux/if_ether.h>
35 #include <linux/export.h>
41 #define MLX4_MAC_VALID (1ull << 63)
43 #define MLX4_VLAN_VALID (1u << 31)
44 #define MLX4_VLAN_MASK 0xfff
46 #define MLX4_STATS_TRAFFIC_COUNTERS_MASK 0xfULL
47 #define MLX4_STATS_TRAFFIC_DROPS_MASK 0xc0ULL
48 #define MLX4_STATS_ERROR_COUNTERS_MASK 0x1ffc30ULL
49 #define MLX4_STATS_PORT_COUNTERS_MASK 0x1fe00000ULL
60 table->
max = 1 << dev->
caps.log_num_macs;
86 switch (dev->
caps.steering_mode) {
112 INIT_LIST_HEAD(&rule.
list);
126 mlx4_warn(dev,
"Failed Attaching Unicast\n");
131 static void mlx4_uc_steer_release(
struct mlx4_dev *dev,
u8 port,
132 u64 mac,
int qpn,
u64 reg_id)
134 switch (dev->
caps.steering_mode) {
154 mlx4_err(dev,
"Invalid steering mode.\n");
158 static int validate_index(
struct mlx4_dev *dev,
163 if (index < 0 || index >= table->
max || !table->
entries[index]) {
164 mlx4_warn(dev,
"No valid Mac entry for the given index\n");
170 static int find_index(
struct mlx4_dev *dev,
192 mlx4_dbg(dev,
"Registering MAC: 0x%llx for adding\n",
193 (
unsigned long long) mac);
197 mlx4_err(dev,
"Failed adding MAC: 0x%llx\n",
198 (
unsigned long long) mac);
208 mlx4_dbg(dev,
"Reserved qp %d\n", *qpn);
210 mlx4_err(dev,
"Failed to reserve qp for mac registration\n");
214 err = mlx4_uc_steer_add(dev, port, mac, qpn, ®_id);
234 mlx4_uc_steer_release(dev, port, mac, *qpn, reg_id);
250 mlx4_dbg(dev,
"Registering MAC: 0x%llx for deleting\n",
251 (
unsigned long long) mac);
257 mlx4_dbg(dev,
"Releasing qp: port %d, mac 0x%llx,"
259 (
unsigned long long) mac, qpn);
260 mlx4_uc_steer_release(dev, port, entry->
mac,
270 static int mlx4_set_port_mac_table(
struct mlx4_dev *dev,
u8 port,
279 return PTR_ERR(mailbox);
299 mlx4_dbg(dev,
"Registering MAC: 0x%llx for port %d\n",
300 (
unsigned long long) mac, port);
304 if (free < 0 && !table->entries[i]) {
316 mlx4_dbg(dev,
"Free MAC index is %d\n", free);
327 err = mlx4_set_port_mac_table(dev, port, table->
entries);
329 mlx4_err(dev,
"Failed adding MAC: 0x%llx\n",
330 (
unsigned long long) mac);
348 if (mlx4_is_mfunc(dev)) {
349 set_param_l(&out_param, port);
350 err = mlx4_cmd_imm(dev, mac, &out_param,
RES_MAC,
356 return get_param_l(&out_param);
369 index = find_index(dev, table, mac);
373 if (validate_index(dev, table, index))
377 mlx4_set_port_mac_table(dev, port, table->
entries);
388 if (mlx4_is_mfunc(dev)) {
389 set_param_l(&out_param, port);
412 mlx4_uc_steer_release(dev, port, entry->
mac,
415 entry->
mac = new_mac;
418 err = mlx4_uc_steer_add(dev, port, entry->
mac,
426 err = validate_index(dev, table, index);
432 err = mlx4_set_port_mac_table(dev, port, table->
entries);
434 mlx4_err(dev,
"Failed adding MAC: 0x%llx\n",
435 (
unsigned long long) new_mac);
444 static int mlx4_set_port_vlan_table(
struct mlx4_dev *dev,
u8 port,
453 return PTR_ERR(mailbox);
471 if (table->
refs[i] &&
500 if (free < 0 && (table->
refs[i] == 0)) {
505 if (table->
refs[i] &&
524 err = mlx4_set_port_vlan_table(dev, port, table->
entries);
526 mlx4_warn(dev,
"Failed adding vlan: %u\n", vlan);
544 if (mlx4_is_mfunc(dev)) {
545 set_param_l(&out_param, port);
546 err = mlx4_cmd_imm(dev, vlan, &out_param,
RES_VLAN,
550 *index = get_param_l(&out_param);
554 return __mlx4_register_vlan(dev, port, vlan, index);
558 static void __mlx4_unregister_vlan(
struct mlx4_dev *dev,
u8 port,
int index)
563 mlx4_warn(dev,
"Trying to free special vlan index %d\n", index);
568 if (!table->
refs[index]) {
569 mlx4_warn(dev,
"No vlan entry for index %d\n", index);
572 if (--table->
refs[index]) {
573 mlx4_dbg(dev,
"Have more references for index %d,"
574 "no need to modify vlan table\n", index);
578 mlx4_set_port_vlan_table(dev, port, table->
entries);
589 if (mlx4_is_mfunc(dev)) {
590 set_param_l(&in_param, port);
595 mlx4_warn(dev,
"Failed freeing vlan at index:%d\n",
600 __mlx4_unregister_vlan(dev, port, index);
611 if (IS_ERR(inmailbox))
612 return PTR_ERR(inmailbox);
615 if (IS_ERR(outmailbox)) {
617 return PTR_ERR(outmailbox);
620 inbuf = inmailbox->
buf;
621 outbuf = outmailbox->
buf;
631 err = mlx4_cmd_box(dev, inmailbox->
dma, outmailbox->
dma, port, 3,
635 *caps = *(
__be32 *) (outbuf + 84);
641 static int mlx4_common_set_port(
struct mlx4_dev *dev,
int slave,
u32 in_mod,
650 int reset_qkey_viols;
662 port = in_mod & 0xff;
663 in_modifier = in_mod >> 8;
669 if (slave != dev->
caps.function &&
671 mlx4_warn(dev,
"denying SET_PORT for slave:%d\n",
675 switch (in_modifier) {
677 qpn_context = inbox->
buf;
680 qpn_context->
n_mac = 0x7;
693 gen_context = inbox->
buf;
697 mtu =
min_t(
int, mtu, dev->
caps.eth_mtu_cap[port]);
698 prev_mtu = slave_st->
mtu[
port];
700 if (mtu > master->
max_mtu[port])
702 if (mtu < prev_mtu && prev_mtu ==
728 reset_qkey_viols = (*(
u8 *) inbox->
buf) & 0x40;
729 new_cap_mask = ((
__be32 *) inbox->
buf)[2];
731 reset_qkey_viols = ((
u8 *) inbox->
buf)[3] & 0x1;
732 new_cap_mask = ((
__be32 *) inbox->
buf)[1];
736 if (slave != mlx4_master_func_num(dev) &&
741 if (mlx4_is_mfunc(dev) &&
747 priv->
mfunc.master.slave_state[slave].ib_cap_mask[
port];
751 priv->
mfunc.master.slave_state[i].ib_cap_mask[port];
756 if (slave != dev->
caps.function)
759 *(
u8 *) inbox->
buf |= !!reset_qkey_viols << 6;
760 ((
__be32 *) inbox->
buf)[2] = agg_cap_mask;
762 ((
u8 *) inbox->
buf)[3] |= !!reset_qkey_viols;
763 ((
__be32 *) inbox->
buf)[1] = agg_cap_mask;
769 priv->
mfunc.master.slave_state[slave].ib_cap_mask[
port] =
780 return mlx4_common_set_port(dev, slave, vhcr->
in_modifier,
803 return PTR_ERR(mailbox);
809 if (pkey_tbl_sz >= 0 && mlx4_is_master(dev)) {
815 for (vl_cap = 8; vl_cap >= 1; vl_cap >>= 1) {
833 u8 pptx,
u8 pfctx,
u8 pprx,
u8 pfcrx)
842 return PTR_ERR(mailbox);
843 context = mailbox->
buf;
844 memset(context, 0,
sizeof *context);
877 return PTR_ERR(mailbox);
878 context = mailbox->
buf;
879 memset(context, 0,
sizeof *context);
911 return PTR_ERR(mailbox);
912 context = mailbox->
buf;
913 memset(context, 0,
sizeof *context);
916 context->
prio2tc[i >> 1] = prio2tc[i] << 4 | prio2tc[i + 1];
938 return PTR_ERR(mailbox);
939 context = mailbox->
buf;
940 memset(context, 0,
sizeof *context);
944 u16 r = ratelimit && ratelimit[
i] ? ratelimit[
i] :
977 return mlx4_cmd(dev, (mac | (clear << 63)), port, mode,
997 return mlx4_cmd_box(dev, 0, outbox->
dma, in_mod, 0,
1008 if (slave != dev->
caps.function)
1016 if (!mlx4_is_mfunc(dev)) {
1025 if (mlx4_is_master(dev))