Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * net/dsa/mv88e6xxx.c - Marvell 88e6xxx switch chip support |
| 3 | * Copyright (c) 2008 Marvell Semiconductor |
| 4 | * |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 5 | * Copyright (c) 2015 CMC Electronics, Inc. |
| 6 | * Added support for VLAN Table Unit operations |
| 7 | * |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 8 | * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch> |
| 9 | * |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | */ |
| 15 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 16 | #include <linux/delay.h> |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 18 | #include <linux/ethtool.h> |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 19 | #include <linux/if_bridge.h> |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 20 | #include <linux/jiffies.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 21 | #include <linux/list.h> |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 22 | #include <linux/mdio.h> |
Paul Gortmaker | 2bbba27 | 2012-01-24 10:41:40 +0000 | [diff] [blame] | 23 | #include <linux/module.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 24 | #include <linux/netdevice.h> |
Andrew Lunn | c8c1b39a | 2015-11-20 03:56:24 +0100 | [diff] [blame] | 25 | #include <linux/gpio/consumer.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 26 | #include <linux/phy.h> |
Ben Hutchings | c8f0b86 | 2011-11-27 17:06:08 +0000 | [diff] [blame] | 27 | #include <net/dsa.h> |
Vivien Didelot | 1f36faf | 2015-10-08 11:35:13 -0400 | [diff] [blame] | 28 | #include <net/switchdev.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 29 | #include "mv88e6xxx.h" |
| 30 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 31 | static void assert_smi_lock(struct mv88e6xxx_priv_state *ps) |
Vivien Didelot | 3996a4f | 2015-10-30 18:56:45 -0400 | [diff] [blame] | 32 | { |
Vivien Didelot | 3996a4f | 2015-10-30 18:56:45 -0400 | [diff] [blame] | 33 | if (unlikely(!mutex_is_locked(&ps->smi_mutex))) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 34 | dev_err(ps->dev, "SMI lock not held!\n"); |
Vivien Didelot | 3996a4f | 2015-10-30 18:56:45 -0400 | [diff] [blame] | 35 | dump_stack(); |
| 36 | } |
| 37 | } |
| 38 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 39 | /* If the switch's ADDR[4:0] strap pins are strapped to zero, it will |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 40 | * use all 32 SMI bus addresses on its SMI bus, and all switch registers |
| 41 | * will be directly accessible on some {device address,register address} |
| 42 | * pair. If the ADDR[4:0] pins are not strapped to zero, the switch |
| 43 | * will only respond to SMI transactions to that specific address, and |
| 44 | * an indirect addressing mechanism needs to be used to access its |
| 45 | * registers. |
| 46 | */ |
| 47 | static int mv88e6xxx_reg_wait_ready(struct mii_bus *bus, int sw_addr) |
| 48 | { |
| 49 | int ret; |
| 50 | int i; |
| 51 | |
| 52 | for (i = 0; i < 16; i++) { |
Neil Armstrong | 6e899e6 | 2015-10-22 10:37:53 +0200 | [diff] [blame] | 53 | ret = mdiobus_read_nested(bus, sw_addr, SMI_CMD); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 54 | if (ret < 0) |
| 55 | return ret; |
| 56 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 57 | if ((ret & SMI_CMD_BUSY) == 0) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | return -ETIMEDOUT; |
| 62 | } |
| 63 | |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 64 | static int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, |
| 65 | int reg) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 66 | { |
| 67 | int ret; |
| 68 | |
| 69 | if (sw_addr == 0) |
Neil Armstrong | 6e899e6 | 2015-10-22 10:37:53 +0200 | [diff] [blame] | 70 | return mdiobus_read_nested(bus, addr, reg); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 71 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 72 | /* Wait for the bus to become free. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 73 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 74 | if (ret < 0) |
| 75 | return ret; |
| 76 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 77 | /* Transmit the read command. */ |
Neil Armstrong | 6e899e6 | 2015-10-22 10:37:53 +0200 | [diff] [blame] | 78 | ret = mdiobus_write_nested(bus, sw_addr, SMI_CMD, |
| 79 | SMI_CMD_OP_22_READ | (addr << 5) | reg); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 80 | if (ret < 0) |
| 81 | return ret; |
| 82 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 83 | /* Wait for the read command to complete. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 84 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 85 | if (ret < 0) |
| 86 | return ret; |
| 87 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 88 | /* Read the data. */ |
Neil Armstrong | 6e899e6 | 2015-10-22 10:37:53 +0200 | [diff] [blame] | 89 | ret = mdiobus_read_nested(bus, sw_addr, SMI_DATA); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 90 | if (ret < 0) |
| 91 | return ret; |
| 92 | |
| 93 | return ret & 0xffff; |
| 94 | } |
| 95 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 96 | static int _mv88e6xxx_reg_read(struct mv88e6xxx_priv_state *ps, |
| 97 | int addr, int reg) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 98 | { |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 99 | int ret; |
| 100 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 101 | assert_smi_lock(ps); |
Vivien Didelot | 3996a4f | 2015-10-30 18:56:45 -0400 | [diff] [blame] | 102 | |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 103 | ret = __mv88e6xxx_reg_read(ps->bus, ps->sw_addr, addr, reg); |
Vivien Didelot | bb92ea5 | 2015-01-23 16:10:36 -0500 | [diff] [blame] | 104 | if (ret < 0) |
| 105 | return ret; |
| 106 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 107 | dev_dbg(ps->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n", |
Vivien Didelot | bb92ea5 | 2015-01-23 16:10:36 -0500 | [diff] [blame] | 108 | addr, reg, ret); |
| 109 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 110 | return ret; |
| 111 | } |
| 112 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 113 | int mv88e6xxx_reg_read(struct mv88e6xxx_priv_state *ps, int addr, int reg) |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 114 | { |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 115 | int ret; |
| 116 | |
| 117 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 118 | ret = _mv88e6xxx_reg_read(ps, addr, reg); |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 119 | mutex_unlock(&ps->smi_mutex); |
| 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 124 | static int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr, |
| 125 | int reg, u16 val) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 126 | { |
| 127 | int ret; |
| 128 | |
| 129 | if (sw_addr == 0) |
Neil Armstrong | 6e899e6 | 2015-10-22 10:37:53 +0200 | [diff] [blame] | 130 | return mdiobus_write_nested(bus, addr, reg, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 131 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 132 | /* Wait for the bus to become free. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 133 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 134 | if (ret < 0) |
| 135 | return ret; |
| 136 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 137 | /* Transmit the data to write. */ |
Neil Armstrong | 6e899e6 | 2015-10-22 10:37:53 +0200 | [diff] [blame] | 138 | ret = mdiobus_write_nested(bus, sw_addr, SMI_DATA, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 139 | if (ret < 0) |
| 140 | return ret; |
| 141 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 142 | /* Transmit the write command. */ |
Neil Armstrong | 6e899e6 | 2015-10-22 10:37:53 +0200 | [diff] [blame] | 143 | ret = mdiobus_write_nested(bus, sw_addr, SMI_CMD, |
| 144 | SMI_CMD_OP_22_WRITE | (addr << 5) | reg); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 145 | if (ret < 0) |
| 146 | return ret; |
| 147 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 148 | /* Wait for the write command to complete. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 149 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 150 | if (ret < 0) |
| 151 | return ret; |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 156 | static int _mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr, |
| 157 | int reg, u16 val) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 158 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 159 | assert_smi_lock(ps); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 160 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 161 | dev_dbg(ps->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n", |
Vivien Didelot | bb92ea5 | 2015-01-23 16:10:36 -0500 | [diff] [blame] | 162 | addr, reg, val); |
| 163 | |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 164 | return __mv88e6xxx_reg_write(ps->bus, ps->sw_addr, addr, reg, val); |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 167 | int mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr, |
| 168 | int reg, u16 val) |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 169 | { |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 170 | int ret; |
| 171 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 172 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 173 | ret = _mv88e6xxx_reg_write(ps, addr, reg, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 174 | mutex_unlock(&ps->smi_mutex); |
| 175 | |
| 176 | return ret; |
| 177 | } |
| 178 | |
Vivien Didelot | 1d13a06 | 2016-05-09 13:22:43 -0400 | [diff] [blame] | 179 | static int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 180 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 181 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 182 | int err; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 183 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 184 | err = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MAC_01, |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 185 | (addr[0] << 8) | addr[1]); |
| 186 | if (err) |
| 187 | return err; |
| 188 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 189 | err = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MAC_23, |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 190 | (addr[2] << 8) | addr[3]); |
| 191 | if (err) |
| 192 | return err; |
| 193 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 194 | return mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MAC_45, |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 195 | (addr[4] << 8) | addr[5]); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Vivien Didelot | 1d13a06 | 2016-05-09 13:22:43 -0400 | [diff] [blame] | 198 | static int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 199 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 200 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 201 | int ret; |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 202 | int i; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 203 | |
| 204 | for (i = 0; i < 6; i++) { |
| 205 | int j; |
| 206 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 207 | /* Write the MAC address byte. */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 208 | ret = mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_SWITCH_MAC, |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 209 | GLOBAL2_SWITCH_MAC_BUSY | |
| 210 | (i << 8) | addr[i]); |
| 211 | if (ret) |
| 212 | return ret; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 213 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 214 | /* Wait for the write to complete. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 215 | for (j = 0; j < 16; j++) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 216 | ret = mv88e6xxx_reg_read(ps, REG_GLOBAL2, |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 217 | GLOBAL2_SWITCH_MAC); |
| 218 | if (ret < 0) |
| 219 | return ret; |
| 220 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 221 | if ((ret & GLOBAL2_SWITCH_MAC_BUSY) == 0) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | if (j == 16) |
| 225 | return -ETIMEDOUT; |
| 226 | } |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Vivien Didelot | 1d13a06 | 2016-05-09 13:22:43 -0400 | [diff] [blame] | 231 | int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr) |
| 232 | { |
| 233 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 234 | |
| 235 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_SWITCH_MAC)) |
| 236 | return mv88e6xxx_set_addr_indirect(ds, addr); |
| 237 | else |
| 238 | return mv88e6xxx_set_addr_direct(ds, addr); |
| 239 | } |
| 240 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 241 | static int mv88e6xxx_mdio_read_direct(struct mv88e6xxx_priv_state *ps, |
| 242 | int addr, int regnum) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 243 | { |
| 244 | if (addr >= 0) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 245 | return _mv88e6xxx_reg_read(ps, addr, regnum); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 246 | return 0xffff; |
| 247 | } |
| 248 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 249 | static int mv88e6xxx_mdio_write_direct(struct mv88e6xxx_priv_state *ps, |
| 250 | int addr, int regnum, u16 val) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 251 | { |
| 252 | if (addr >= 0) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 253 | return _mv88e6xxx_reg_write(ps, addr, regnum, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 257 | static int mv88e6xxx_ppu_disable(struct mv88e6xxx_priv_state *ps) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 258 | { |
| 259 | int ret; |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 260 | unsigned long timeout; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 261 | |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 262 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_CONTROL); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 263 | if (ret < 0) |
| 264 | return ret; |
| 265 | |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 266 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL, |
| 267 | ret & ~GLOBAL_CONTROL_PPU_ENABLE); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 268 | if (ret) |
| 269 | return ret; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 270 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 271 | timeout = jiffies + 1 * HZ; |
| 272 | while (time_before(jiffies, timeout)) { |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 273 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_STATUS); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 274 | if (ret < 0) |
| 275 | return ret; |
| 276 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 277 | usleep_range(1000, 2000); |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 278 | if ((ret & GLOBAL_STATUS_PPU_MASK) != |
| 279 | GLOBAL_STATUS_PPU_POLLING) |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 280 | return 0; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | return -ETIMEDOUT; |
| 284 | } |
| 285 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 286 | static int mv88e6xxx_ppu_enable(struct mv88e6xxx_priv_state *ps) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 287 | { |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 288 | int ret, err; |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 289 | unsigned long timeout; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 290 | |
Vivien Didelot | 762eb67 | 2016-06-04 21:16:54 +0200 | [diff] [blame] | 291 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_CONTROL); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 292 | if (ret < 0) |
| 293 | return ret; |
| 294 | |
Vivien Didelot | 762eb67 | 2016-06-04 21:16:54 +0200 | [diff] [blame] | 295 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL, |
| 296 | ret | GLOBAL_CONTROL_PPU_ENABLE); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 297 | if (err) |
| 298 | return err; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 299 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 300 | timeout = jiffies + 1 * HZ; |
| 301 | while (time_before(jiffies, timeout)) { |
Vivien Didelot | 762eb67 | 2016-06-04 21:16:54 +0200 | [diff] [blame] | 302 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_STATUS); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 303 | if (ret < 0) |
| 304 | return ret; |
| 305 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 306 | usleep_range(1000, 2000); |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 307 | if ((ret & GLOBAL_STATUS_PPU_MASK) == |
| 308 | GLOBAL_STATUS_PPU_POLLING) |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 309 | return 0; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | return -ETIMEDOUT; |
| 313 | } |
| 314 | |
| 315 | static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly) |
| 316 | { |
| 317 | struct mv88e6xxx_priv_state *ps; |
| 318 | |
| 319 | ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work); |
Vivien Didelot | 762eb67 | 2016-06-04 21:16:54 +0200 | [diff] [blame] | 320 | |
| 321 | mutex_lock(&ps->smi_mutex); |
| 322 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 323 | if (mutex_trylock(&ps->ppu_mutex)) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 324 | if (mv88e6xxx_ppu_enable(ps) == 0) |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 325 | ps->ppu_disabled = 0; |
| 326 | mutex_unlock(&ps->ppu_mutex); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 327 | } |
Vivien Didelot | 762eb67 | 2016-06-04 21:16:54 +0200 | [diff] [blame] | 328 | |
| 329 | mutex_unlock(&ps->smi_mutex); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps) |
| 333 | { |
| 334 | struct mv88e6xxx_priv_state *ps = (void *)_ps; |
| 335 | |
| 336 | schedule_work(&ps->ppu_work); |
| 337 | } |
| 338 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 339 | static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_priv_state *ps) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 340 | { |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 341 | int ret; |
| 342 | |
| 343 | mutex_lock(&ps->ppu_mutex); |
| 344 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 345 | /* If the PHY polling unit is enabled, disable it so that |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 346 | * we can access the PHY registers. If it was already |
| 347 | * disabled, cancel the timer that is going to re-enable |
| 348 | * it. |
| 349 | */ |
| 350 | if (!ps->ppu_disabled) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 351 | ret = mv88e6xxx_ppu_disable(ps); |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 352 | if (ret < 0) { |
| 353 | mutex_unlock(&ps->ppu_mutex); |
| 354 | return ret; |
| 355 | } |
| 356 | ps->ppu_disabled = 1; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 357 | } else { |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 358 | del_timer(&ps->ppu_timer); |
| 359 | ret = 0; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | return ret; |
| 363 | } |
| 364 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 365 | static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_priv_state *ps) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 366 | { |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 367 | /* Schedule a timer to re-enable the PHY polling unit. */ |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 368 | mod_timer(&ps->ppu_timer, jiffies + msecs_to_jiffies(10)); |
| 369 | mutex_unlock(&ps->ppu_mutex); |
| 370 | } |
| 371 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 372 | void mv88e6xxx_ppu_state_init(struct mv88e6xxx_priv_state *ps) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 373 | { |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 374 | mutex_init(&ps->ppu_mutex); |
| 375 | INIT_WORK(&ps->ppu_work, mv88e6xxx_ppu_reenable_work); |
| 376 | init_timer(&ps->ppu_timer); |
| 377 | ps->ppu_timer.data = (unsigned long)ps; |
| 378 | ps->ppu_timer.function = mv88e6xxx_ppu_reenable_timer; |
| 379 | } |
| 380 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 381 | static int mv88e6xxx_mdio_read_ppu(struct mv88e6xxx_priv_state *ps, int addr, |
| 382 | int regnum) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 383 | { |
| 384 | int ret; |
| 385 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 386 | ret = mv88e6xxx_ppu_access_get(ps); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 387 | if (ret >= 0) { |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 388 | ret = _mv88e6xxx_reg_read(ps, addr, regnum); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 389 | mv88e6xxx_ppu_access_put(ps); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | return ret; |
| 393 | } |
| 394 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 395 | static int mv88e6xxx_mdio_write_ppu(struct mv88e6xxx_priv_state *ps, int addr, |
| 396 | int regnum, u16 val) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 397 | { |
| 398 | int ret; |
| 399 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 400 | ret = mv88e6xxx_ppu_access_get(ps); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 401 | if (ret >= 0) { |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 402 | ret = _mv88e6xxx_reg_write(ps, addr, regnum, val); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 403 | mv88e6xxx_ppu_access_put(ps); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | return ret; |
| 407 | } |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 408 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 409 | static bool mv88e6xxx_6065_family(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 410 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 411 | return ps->info->family == MV88E6XXX_FAMILY_6065; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 412 | } |
| 413 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 414 | static bool mv88e6xxx_6095_family(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 415 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 416 | return ps->info->family == MV88E6XXX_FAMILY_6095; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 419 | static bool mv88e6xxx_6097_family(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 420 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 421 | return ps->info->family == MV88E6XXX_FAMILY_6097; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 424 | static bool mv88e6xxx_6165_family(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 425 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 426 | return ps->info->family == MV88E6XXX_FAMILY_6165; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 427 | } |
| 428 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 429 | static bool mv88e6xxx_6185_family(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 430 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 431 | return ps->info->family == MV88E6XXX_FAMILY_6185; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 432 | } |
| 433 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 434 | static bool mv88e6xxx_6320_family(struct mv88e6xxx_priv_state *ps) |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 435 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 436 | return ps->info->family == MV88E6XXX_FAMILY_6320; |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 439 | static bool mv88e6xxx_6351_family(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 440 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 441 | return ps->info->family == MV88E6XXX_FAMILY_6351; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 442 | } |
| 443 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 444 | static bool mv88e6xxx_6352_family(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | f3a8b6b | 2015-04-02 04:06:40 +0200 | [diff] [blame] | 445 | { |
Vivien Didelot | 2235647 | 2016-04-17 13:24:00 -0400 | [diff] [blame] | 446 | return ps->info->family == MV88E6XXX_FAMILY_6352; |
Andrew Lunn | f3a8b6b | 2015-04-02 04:06:40 +0200 | [diff] [blame] | 447 | } |
| 448 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 449 | static unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_priv_state *ps) |
Vivien Didelot | f74df0b | 2016-03-31 16:53:43 -0400 | [diff] [blame] | 450 | { |
Vivien Didelot | cd5a2c8 | 2016-04-17 13:24:02 -0400 | [diff] [blame] | 451 | return ps->info->num_databases; |
Vivien Didelot | f74df0b | 2016-03-31 16:53:43 -0400 | [diff] [blame] | 452 | } |
| 453 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 454 | static bool mv88e6xxx_has_fid_reg(struct mv88e6xxx_priv_state *ps) |
Vivien Didelot | b426e5f | 2016-03-31 16:53:42 -0400 | [diff] [blame] | 455 | { |
| 456 | /* Does the device have dedicated FID registers for ATU and VTU ops? */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 457 | if (mv88e6xxx_6097_family(ps) || mv88e6xxx_6165_family(ps) || |
| 458 | mv88e6xxx_6351_family(ps) || mv88e6xxx_6352_family(ps)) |
Vivien Didelot | b426e5f | 2016-03-31 16:53:42 -0400 | [diff] [blame] | 459 | return true; |
| 460 | |
| 461 | return false; |
| 462 | } |
| 463 | |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 464 | /* We expect the switch to perform auto negotiation if there is a real |
| 465 | * phy. However, in the case of a fixed link phy, we force the port |
| 466 | * settings from the fixed link settings. |
| 467 | */ |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 468 | static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port, |
| 469 | struct phy_device *phydev) |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 470 | { |
| 471 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | 4905287 | 2015-09-29 01:53:48 +0200 | [diff] [blame] | 472 | u32 reg; |
| 473 | int ret; |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 474 | |
| 475 | if (!phy_is_pseudo_fixed_link(phydev)) |
| 476 | return; |
| 477 | |
| 478 | mutex_lock(&ps->smi_mutex); |
| 479 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 480 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_PCS_CTRL); |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 481 | if (ret < 0) |
| 482 | goto out; |
| 483 | |
| 484 | reg = ret & ~(PORT_PCS_CTRL_LINK_UP | |
| 485 | PORT_PCS_CTRL_FORCE_LINK | |
| 486 | PORT_PCS_CTRL_DUPLEX_FULL | |
| 487 | PORT_PCS_CTRL_FORCE_DUPLEX | |
| 488 | PORT_PCS_CTRL_UNFORCED); |
| 489 | |
| 490 | reg |= PORT_PCS_CTRL_FORCE_LINK; |
| 491 | if (phydev->link) |
| 492 | reg |= PORT_PCS_CTRL_LINK_UP; |
| 493 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 494 | if (mv88e6xxx_6065_family(ps) && phydev->speed > SPEED_100) |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 495 | goto out; |
| 496 | |
| 497 | switch (phydev->speed) { |
| 498 | case SPEED_1000: |
| 499 | reg |= PORT_PCS_CTRL_1000; |
| 500 | break; |
| 501 | case SPEED_100: |
| 502 | reg |= PORT_PCS_CTRL_100; |
| 503 | break; |
| 504 | case SPEED_10: |
| 505 | reg |= PORT_PCS_CTRL_10; |
| 506 | break; |
| 507 | default: |
| 508 | pr_info("Unknown speed"); |
| 509 | goto out; |
| 510 | } |
| 511 | |
| 512 | reg |= PORT_PCS_CTRL_FORCE_DUPLEX; |
| 513 | if (phydev->duplex == DUPLEX_FULL) |
| 514 | reg |= PORT_PCS_CTRL_DUPLEX_FULL; |
| 515 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 516 | if ((mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps)) && |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 517 | (port >= ps->info->num_ports - 2)) { |
Andrew Lunn | e7e72ac | 2015-08-31 15:56:51 +0200 | [diff] [blame] | 518 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 519 | reg |= PORT_PCS_CTRL_RGMII_DELAY_RXCLK; |
| 520 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 521 | reg |= PORT_PCS_CTRL_RGMII_DELAY_TXCLK; |
| 522 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 523 | reg |= (PORT_PCS_CTRL_RGMII_DELAY_RXCLK | |
| 524 | PORT_PCS_CTRL_RGMII_DELAY_TXCLK); |
| 525 | } |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 526 | _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_PCS_CTRL, reg); |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 527 | |
| 528 | out: |
| 529 | mutex_unlock(&ps->smi_mutex); |
| 530 | } |
| 531 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 532 | static int _mv88e6xxx_stats_wait(struct mv88e6xxx_priv_state *ps) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 533 | { |
| 534 | int ret; |
| 535 | int i; |
| 536 | |
| 537 | for (i = 0; i < 10; i++) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 538 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_STATS_OP); |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 539 | if ((ret & GLOBAL_STATS_OP_BUSY) == 0) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | return -ETIMEDOUT; |
| 544 | } |
| 545 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 546 | static int _mv88e6xxx_stats_snapshot(struct mv88e6xxx_priv_state *ps, |
| 547 | int port) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 548 | { |
| 549 | int ret; |
| 550 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 551 | if (mv88e6xxx_6320_family(ps) || mv88e6xxx_6352_family(ps)) |
Andrew Lunn | f3a8b6b | 2015-04-02 04:06:40 +0200 | [diff] [blame] | 552 | port = (port + 1) << 5; |
| 553 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 554 | /* Snapshot the hardware statistics counters for this port. */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 555 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_STATS_OP, |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 556 | GLOBAL_STATS_OP_CAPTURE_PORT | |
| 557 | GLOBAL_STATS_OP_HIST_RX_TX | port); |
| 558 | if (ret < 0) |
| 559 | return ret; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 560 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 561 | /* Wait for the snapshotting to complete. */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 562 | ret = _mv88e6xxx_stats_wait(ps); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 563 | if (ret < 0) |
| 564 | return ret; |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 569 | static void _mv88e6xxx_stats_read(struct mv88e6xxx_priv_state *ps, |
| 570 | int stat, u32 *val) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 571 | { |
| 572 | u32 _val; |
| 573 | int ret; |
| 574 | |
| 575 | *val = 0; |
| 576 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 577 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_STATS_OP, |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 578 | GLOBAL_STATS_OP_READ_CAPTURED | |
| 579 | GLOBAL_STATS_OP_HIST_RX_TX | stat); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 580 | if (ret < 0) |
| 581 | return; |
| 582 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 583 | ret = _mv88e6xxx_stats_wait(ps); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 584 | if (ret < 0) |
| 585 | return; |
| 586 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 587 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_STATS_COUNTER_32); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 588 | if (ret < 0) |
| 589 | return; |
| 590 | |
| 591 | _val = ret << 16; |
| 592 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 593 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_STATS_COUNTER_01); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 594 | if (ret < 0) |
| 595 | return; |
| 596 | |
| 597 | *val = _val | ret; |
| 598 | } |
| 599 | |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 600 | static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = { |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 601 | { "in_good_octets", 8, 0x00, BANK0, }, |
| 602 | { "in_bad_octets", 4, 0x02, BANK0, }, |
| 603 | { "in_unicast", 4, 0x04, BANK0, }, |
| 604 | { "in_broadcasts", 4, 0x06, BANK0, }, |
| 605 | { "in_multicasts", 4, 0x07, BANK0, }, |
| 606 | { "in_pause", 4, 0x16, BANK0, }, |
| 607 | { "in_undersize", 4, 0x18, BANK0, }, |
| 608 | { "in_fragments", 4, 0x19, BANK0, }, |
| 609 | { "in_oversize", 4, 0x1a, BANK0, }, |
| 610 | { "in_jabber", 4, 0x1b, BANK0, }, |
| 611 | { "in_rx_error", 4, 0x1c, BANK0, }, |
| 612 | { "in_fcs_error", 4, 0x1d, BANK0, }, |
| 613 | { "out_octets", 8, 0x0e, BANK0, }, |
| 614 | { "out_unicast", 4, 0x10, BANK0, }, |
| 615 | { "out_broadcasts", 4, 0x13, BANK0, }, |
| 616 | { "out_multicasts", 4, 0x12, BANK0, }, |
| 617 | { "out_pause", 4, 0x15, BANK0, }, |
| 618 | { "excessive", 4, 0x11, BANK0, }, |
| 619 | { "collisions", 4, 0x1e, BANK0, }, |
| 620 | { "deferred", 4, 0x05, BANK0, }, |
| 621 | { "single", 4, 0x14, BANK0, }, |
| 622 | { "multiple", 4, 0x17, BANK0, }, |
| 623 | { "out_fcs_error", 4, 0x03, BANK0, }, |
| 624 | { "late", 4, 0x1f, BANK0, }, |
| 625 | { "hist_64bytes", 4, 0x08, BANK0, }, |
| 626 | { "hist_65_127bytes", 4, 0x09, BANK0, }, |
| 627 | { "hist_128_255bytes", 4, 0x0a, BANK0, }, |
| 628 | { "hist_256_511bytes", 4, 0x0b, BANK0, }, |
| 629 | { "hist_512_1023bytes", 4, 0x0c, BANK0, }, |
| 630 | { "hist_1024_max_bytes", 4, 0x0d, BANK0, }, |
| 631 | { "sw_in_discards", 4, 0x10, PORT, }, |
| 632 | { "sw_in_filtered", 2, 0x12, PORT, }, |
| 633 | { "sw_out_filtered", 2, 0x13, PORT, }, |
| 634 | { "in_discards", 4, 0x00 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 635 | { "in_filtered", 4, 0x01 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 636 | { "in_accepted", 4, 0x02 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 637 | { "in_bad_accepted", 4, 0x03 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 638 | { "in_good_avb_class_a", 4, 0x04 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 639 | { "in_good_avb_class_b", 4, 0x05 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 640 | { "in_bad_avb_class_a", 4, 0x06 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 641 | { "in_bad_avb_class_b", 4, 0x07 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 642 | { "tcam_counter_0", 4, 0x08 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 643 | { "tcam_counter_1", 4, 0x09 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 644 | { "tcam_counter_2", 4, 0x0a | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 645 | { "tcam_counter_3", 4, 0x0b | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 646 | { "in_da_unknown", 4, 0x0e | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 647 | { "in_management", 4, 0x0f | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 648 | { "out_queue_0", 4, 0x10 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 649 | { "out_queue_1", 4, 0x11 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 650 | { "out_queue_2", 4, 0x12 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 651 | { "out_queue_3", 4, 0x13 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 652 | { "out_queue_4", 4, 0x14 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 653 | { "out_queue_5", 4, 0x15 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 654 | { "out_queue_6", 4, 0x16 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 655 | { "out_queue_7", 4, 0x17 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 656 | { "out_cut_through", 4, 0x18 | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 657 | { "out_octets_a", 4, 0x1a | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 658 | { "out_octets_b", 4, 0x1b | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
| 659 | { "out_management", 4, 0x1f | GLOBAL_STATS_OP_BANK_1, BANK1, }, |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 660 | }; |
| 661 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 662 | static bool mv88e6xxx_has_stat(struct mv88e6xxx_priv_state *ps, |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 663 | struct mv88e6xxx_hw_stat *stat) |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 664 | { |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 665 | switch (stat->type) { |
| 666 | case BANK0: |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 667 | return true; |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 668 | case BANK1: |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 669 | return mv88e6xxx_6320_family(ps); |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 670 | case PORT: |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 671 | return mv88e6xxx_6095_family(ps) || |
| 672 | mv88e6xxx_6185_family(ps) || |
| 673 | mv88e6xxx_6097_family(ps) || |
| 674 | mv88e6xxx_6165_family(ps) || |
| 675 | mv88e6xxx_6351_family(ps) || |
| 676 | mv88e6xxx_6352_family(ps); |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 677 | } |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 678 | return false; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 681 | static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_priv_state *ps, |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 682 | struct mv88e6xxx_hw_stat *s, |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 683 | int port) |
| 684 | { |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 685 | u32 low; |
| 686 | u32 high = 0; |
| 687 | int ret; |
| 688 | u64 value; |
| 689 | |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 690 | switch (s->type) { |
| 691 | case PORT: |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 692 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), s->reg); |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 693 | if (ret < 0) |
| 694 | return UINT64_MAX; |
| 695 | |
| 696 | low = ret; |
| 697 | if (s->sizeof_stat == 4) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 698 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 699 | s->reg + 1); |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 700 | if (ret < 0) |
| 701 | return UINT64_MAX; |
| 702 | high = ret; |
| 703 | } |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 704 | break; |
| 705 | case BANK0: |
| 706 | case BANK1: |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 707 | _mv88e6xxx_stats_read(ps, s->reg, &low); |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 708 | if (s->sizeof_stat == 8) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 709 | _mv88e6xxx_stats_read(ps, s->reg + 1, &high); |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 710 | } |
| 711 | value = (((u64)high) << 16) | low; |
| 712 | return value; |
| 713 | } |
| 714 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 715 | static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port, |
| 716 | uint8_t *data) |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 717 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 718 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 719 | struct mv88e6xxx_hw_stat *stat; |
| 720 | int i, j; |
| 721 | |
| 722 | for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { |
| 723 | stat = &mv88e6xxx_hw_stats[i]; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 724 | if (mv88e6xxx_has_stat(ps, stat)) { |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 725 | memcpy(data + j * ETH_GSTRING_LEN, stat->string, |
| 726 | ETH_GSTRING_LEN); |
| 727 | j++; |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 732 | static int mv88e6xxx_get_sset_count(struct dsa_switch *ds) |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 733 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 734 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 735 | struct mv88e6xxx_hw_stat *stat; |
| 736 | int i, j; |
| 737 | |
| 738 | for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { |
| 739 | stat = &mv88e6xxx_hw_stats[i]; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 740 | if (mv88e6xxx_has_stat(ps, stat)) |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 741 | j++; |
| 742 | } |
| 743 | return j; |
| 744 | } |
| 745 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 746 | static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port, |
| 747 | uint64_t *data) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 748 | { |
Florian Fainelli | a22adce | 2014-04-28 11:14:28 -0700 | [diff] [blame] | 749 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 750 | struct mv88e6xxx_hw_stat *stat; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 751 | int ret; |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 752 | int i, j; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 753 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 754 | mutex_lock(&ps->smi_mutex); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 755 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 756 | ret = _mv88e6xxx_stats_snapshot(ps, port); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 757 | if (ret < 0) { |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 758 | mutex_unlock(&ps->smi_mutex); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 759 | return; |
| 760 | } |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 761 | for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { |
| 762 | stat = &mv88e6xxx_hw_stats[i]; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 763 | if (mv88e6xxx_has_stat(ps, stat)) { |
| 764 | data[j] = _mv88e6xxx_get_ethtool_stat(ps, stat, port); |
Andrew Lunn | f5e2ed0 | 2015-12-23 13:23:17 +0100 | [diff] [blame] | 765 | j++; |
| 766 | } |
| 767 | } |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 768 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 769 | mutex_unlock(&ps->smi_mutex); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 770 | } |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 771 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 772 | static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port) |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 773 | { |
| 774 | return 32 * sizeof(u16); |
| 775 | } |
| 776 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 777 | static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, |
| 778 | struct ethtool_regs *regs, void *_p) |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 779 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 780 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 781 | u16 *p = _p; |
| 782 | int i; |
| 783 | |
| 784 | regs->version = 0; |
| 785 | |
| 786 | memset(p, 0xff, 32 * sizeof(u16)); |
| 787 | |
Vivien Didelot | 2306251 | 2016-05-09 13:22:45 -0400 | [diff] [blame] | 788 | mutex_lock(&ps->smi_mutex); |
| 789 | |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 790 | for (i = 0; i < 32; i++) { |
| 791 | int ret; |
| 792 | |
Vivien Didelot | 2306251 | 2016-05-09 13:22:45 -0400 | [diff] [blame] | 793 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), i); |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 794 | if (ret >= 0) |
| 795 | p[i] = ret; |
| 796 | } |
Vivien Didelot | 2306251 | 2016-05-09 13:22:45 -0400 | [diff] [blame] | 797 | |
| 798 | mutex_unlock(&ps->smi_mutex); |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 801 | static int _mv88e6xxx_wait(struct mv88e6xxx_priv_state *ps, int reg, int offset, |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 802 | u16 mask) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 803 | { |
| 804 | unsigned long timeout = jiffies + HZ / 10; |
| 805 | |
| 806 | while (time_before(jiffies, timeout)) { |
| 807 | int ret; |
| 808 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 809 | ret = _mv88e6xxx_reg_read(ps, reg, offset); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 810 | if (ret < 0) |
| 811 | return ret; |
| 812 | if (!(ret & mask)) |
| 813 | return 0; |
| 814 | |
| 815 | usleep_range(1000, 2000); |
| 816 | } |
| 817 | return -ETIMEDOUT; |
| 818 | } |
| 819 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 820 | static int mv88e6xxx_wait(struct mv88e6xxx_priv_state *ps, int reg, |
| 821 | int offset, u16 mask) |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 822 | { |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 823 | int ret; |
| 824 | |
| 825 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 826 | ret = _mv88e6xxx_wait(ps, reg, offset, mask); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 827 | mutex_unlock(&ps->smi_mutex); |
| 828 | |
| 829 | return ret; |
| 830 | } |
| 831 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 832 | static int mv88e6xxx_mdio_wait(struct mv88e6xxx_priv_state *ps) |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 833 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 834 | return _mv88e6xxx_wait(ps, REG_GLOBAL2, GLOBAL2_SMI_OP, |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 835 | GLOBAL2_SMI_OP_BUSY); |
| 836 | } |
| 837 | |
Vivien Didelot | d24645b | 2016-05-09 13:22:41 -0400 | [diff] [blame] | 838 | static int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds) |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 839 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 840 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 841 | |
| 842 | return mv88e6xxx_wait(ps, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 843 | GLOBAL2_EEPROM_OP_LOAD); |
| 844 | } |
| 845 | |
Vivien Didelot | d24645b | 2016-05-09 13:22:41 -0400 | [diff] [blame] | 846 | static int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds) |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 847 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 848 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 849 | |
| 850 | return mv88e6xxx_wait(ps, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 851 | GLOBAL2_EEPROM_OP_BUSY); |
| 852 | } |
| 853 | |
Vivien Didelot | d24645b | 2016-05-09 13:22:41 -0400 | [diff] [blame] | 854 | static int mv88e6xxx_read_eeprom_word(struct dsa_switch *ds, int addr) |
| 855 | { |
| 856 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 857 | int ret; |
| 858 | |
| 859 | mutex_lock(&ps->eeprom_mutex); |
| 860 | |
| 861 | ret = mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
| 862 | GLOBAL2_EEPROM_OP_READ | |
| 863 | (addr & GLOBAL2_EEPROM_OP_ADDR_MASK)); |
| 864 | if (ret < 0) |
| 865 | goto error; |
| 866 | |
| 867 | ret = mv88e6xxx_eeprom_busy_wait(ds); |
| 868 | if (ret < 0) |
| 869 | goto error; |
| 870 | |
| 871 | ret = mv88e6xxx_reg_read(ps, REG_GLOBAL2, GLOBAL2_EEPROM_DATA); |
| 872 | error: |
| 873 | mutex_unlock(&ps->eeprom_mutex); |
| 874 | return ret; |
| 875 | } |
| 876 | |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 877 | static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds) |
| 878 | { |
| 879 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 880 | |
| 881 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM)) |
| 882 | return ps->eeprom_len; |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 887 | static int mv88e6xxx_get_eeprom(struct dsa_switch *ds, |
| 888 | struct ethtool_eeprom *eeprom, u8 *data) |
Vivien Didelot | d24645b | 2016-05-09 13:22:41 -0400 | [diff] [blame] | 889 | { |
| 890 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 891 | int offset; |
| 892 | int len; |
| 893 | int ret; |
| 894 | |
| 895 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM)) |
| 896 | return -EOPNOTSUPP; |
| 897 | |
| 898 | offset = eeprom->offset; |
| 899 | len = eeprom->len; |
| 900 | eeprom->len = 0; |
| 901 | |
| 902 | eeprom->magic = 0xc3ec4951; |
| 903 | |
| 904 | ret = mv88e6xxx_eeprom_load_wait(ds); |
| 905 | if (ret < 0) |
| 906 | return ret; |
| 907 | |
| 908 | if (offset & 1) { |
| 909 | int word; |
| 910 | |
| 911 | word = mv88e6xxx_read_eeprom_word(ds, offset >> 1); |
| 912 | if (word < 0) |
| 913 | return word; |
| 914 | |
| 915 | *data++ = (word >> 8) & 0xff; |
| 916 | |
| 917 | offset++; |
| 918 | len--; |
| 919 | eeprom->len++; |
| 920 | } |
| 921 | |
| 922 | while (len >= 2) { |
| 923 | int word; |
| 924 | |
| 925 | word = mv88e6xxx_read_eeprom_word(ds, offset >> 1); |
| 926 | if (word < 0) |
| 927 | return word; |
| 928 | |
| 929 | *data++ = word & 0xff; |
| 930 | *data++ = (word >> 8) & 0xff; |
| 931 | |
| 932 | offset += 2; |
| 933 | len -= 2; |
| 934 | eeprom->len += 2; |
| 935 | } |
| 936 | |
| 937 | if (len) { |
| 938 | int word; |
| 939 | |
| 940 | word = mv88e6xxx_read_eeprom_word(ds, offset >> 1); |
| 941 | if (word < 0) |
| 942 | return word; |
| 943 | |
| 944 | *data++ = word & 0xff; |
| 945 | |
| 946 | offset++; |
| 947 | len--; |
| 948 | eeprom->len++; |
| 949 | } |
| 950 | |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | static int mv88e6xxx_eeprom_is_readonly(struct dsa_switch *ds) |
| 955 | { |
| 956 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 957 | int ret; |
| 958 | |
| 959 | ret = mv88e6xxx_reg_read(ps, REG_GLOBAL2, GLOBAL2_EEPROM_OP); |
| 960 | if (ret < 0) |
| 961 | return ret; |
| 962 | |
| 963 | if (!(ret & GLOBAL2_EEPROM_OP_WRITE_EN)) |
| 964 | return -EROFS; |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | static int mv88e6xxx_write_eeprom_word(struct dsa_switch *ds, int addr, |
| 970 | u16 data) |
| 971 | { |
| 972 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 973 | int ret; |
| 974 | |
| 975 | mutex_lock(&ps->eeprom_mutex); |
| 976 | |
| 977 | ret = mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data); |
| 978 | if (ret < 0) |
| 979 | goto error; |
| 980 | |
| 981 | ret = mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
| 982 | GLOBAL2_EEPROM_OP_WRITE | |
| 983 | (addr & GLOBAL2_EEPROM_OP_ADDR_MASK)); |
| 984 | if (ret < 0) |
| 985 | goto error; |
| 986 | |
| 987 | ret = mv88e6xxx_eeprom_busy_wait(ds); |
| 988 | error: |
| 989 | mutex_unlock(&ps->eeprom_mutex); |
| 990 | return ret; |
| 991 | } |
| 992 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 993 | static int mv88e6xxx_set_eeprom(struct dsa_switch *ds, |
| 994 | struct ethtool_eeprom *eeprom, u8 *data) |
Vivien Didelot | d24645b | 2016-05-09 13:22:41 -0400 | [diff] [blame] | 995 | { |
| 996 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 997 | int offset; |
| 998 | int ret; |
| 999 | int len; |
| 1000 | |
| 1001 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM)) |
| 1002 | return -EOPNOTSUPP; |
| 1003 | |
| 1004 | if (eeprom->magic != 0xc3ec4951) |
| 1005 | return -EINVAL; |
| 1006 | |
| 1007 | ret = mv88e6xxx_eeprom_is_readonly(ds); |
| 1008 | if (ret) |
| 1009 | return ret; |
| 1010 | |
| 1011 | offset = eeprom->offset; |
| 1012 | len = eeprom->len; |
| 1013 | eeprom->len = 0; |
| 1014 | |
| 1015 | ret = mv88e6xxx_eeprom_load_wait(ds); |
| 1016 | if (ret < 0) |
| 1017 | return ret; |
| 1018 | |
| 1019 | if (offset & 1) { |
| 1020 | int word; |
| 1021 | |
| 1022 | word = mv88e6xxx_read_eeprom_word(ds, offset >> 1); |
| 1023 | if (word < 0) |
| 1024 | return word; |
| 1025 | |
| 1026 | word = (*data++ << 8) | (word & 0xff); |
| 1027 | |
| 1028 | ret = mv88e6xxx_write_eeprom_word(ds, offset >> 1, word); |
| 1029 | if (ret < 0) |
| 1030 | return ret; |
| 1031 | |
| 1032 | offset++; |
| 1033 | len--; |
| 1034 | eeprom->len++; |
| 1035 | } |
| 1036 | |
| 1037 | while (len >= 2) { |
| 1038 | int word; |
| 1039 | |
| 1040 | word = *data++; |
| 1041 | word |= *data++ << 8; |
| 1042 | |
| 1043 | ret = mv88e6xxx_write_eeprom_word(ds, offset >> 1, word); |
| 1044 | if (ret < 0) |
| 1045 | return ret; |
| 1046 | |
| 1047 | offset += 2; |
| 1048 | len -= 2; |
| 1049 | eeprom->len += 2; |
| 1050 | } |
| 1051 | |
| 1052 | if (len) { |
| 1053 | int word; |
| 1054 | |
| 1055 | word = mv88e6xxx_read_eeprom_word(ds, offset >> 1); |
| 1056 | if (word < 0) |
| 1057 | return word; |
| 1058 | |
| 1059 | word = (word & 0xff00) | *data++; |
| 1060 | |
| 1061 | ret = mv88e6xxx_write_eeprom_word(ds, offset >> 1, word); |
| 1062 | if (ret < 0) |
| 1063 | return ret; |
| 1064 | |
| 1065 | offset++; |
| 1066 | len--; |
| 1067 | eeprom->len++; |
| 1068 | } |
| 1069 | |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1073 | static int _mv88e6xxx_atu_wait(struct mv88e6xxx_priv_state *ps) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1074 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1075 | return _mv88e6xxx_wait(ps, REG_GLOBAL, GLOBAL_ATU_OP, |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1076 | GLOBAL_ATU_OP_BUSY); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 1079 | static int mv88e6xxx_mdio_read_indirect(struct mv88e6xxx_priv_state *ps, |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1080 | int addr, int regnum) |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 1081 | { |
| 1082 | int ret; |
| 1083 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1084 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_SMI_OP, |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1085 | GLOBAL2_SMI_OP_22_READ | (addr << 5) | |
| 1086 | regnum); |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 1087 | if (ret < 0) |
| 1088 | return ret; |
| 1089 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 1090 | ret = mv88e6xxx_mdio_wait(ps); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1091 | if (ret < 0) |
| 1092 | return ret; |
| 1093 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1094 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL2, GLOBAL2_SMI_DATA); |
| 1095 | |
| 1096 | return ret; |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 1097 | } |
| 1098 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 1099 | static int mv88e6xxx_mdio_write_indirect(struct mv88e6xxx_priv_state *ps, |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1100 | int addr, int regnum, u16 val) |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 1101 | { |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1102 | int ret; |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 1103 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1104 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_SMI_DATA, val); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1105 | if (ret < 0) |
| 1106 | return ret; |
| 1107 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1108 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_SMI_OP, |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1109 | GLOBAL2_SMI_OP_22_WRITE | (addr << 5) | |
| 1110 | regnum); |
| 1111 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 1112 | return mv88e6xxx_mdio_wait(ps); |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 1115 | static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, |
| 1116 | struct ethtool_eee *e) |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1117 | { |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1118 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1119 | int reg; |
| 1120 | |
Vivien Didelot | aadbdb8 | 2016-05-09 13:22:44 -0400 | [diff] [blame] | 1121 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEE)) |
| 1122 | return -EOPNOTSUPP; |
| 1123 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1124 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1125 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 1126 | reg = mv88e6xxx_mdio_read_indirect(ps, port, 16); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1127 | if (reg < 0) |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1128 | goto out; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1129 | |
| 1130 | e->eee_enabled = !!(reg & 0x0200); |
| 1131 | e->tx_lpi_enabled = !!(reg & 0x0100); |
| 1132 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1133 | reg = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_STATUS); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1134 | if (reg < 0) |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1135 | goto out; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1136 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1137 | e->eee_active = !!(reg & PORT_STATUS_EEE); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1138 | reg = 0; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1139 | |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1140 | out: |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1141 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1142 | return reg; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1143 | } |
| 1144 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 1145 | static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port, |
| 1146 | struct phy_device *phydev, struct ethtool_eee *e) |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1147 | { |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1148 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1149 | int reg; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1150 | int ret; |
| 1151 | |
Vivien Didelot | aadbdb8 | 2016-05-09 13:22:44 -0400 | [diff] [blame] | 1152 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEE)) |
| 1153 | return -EOPNOTSUPP; |
| 1154 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1155 | mutex_lock(&ps->smi_mutex); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1156 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 1157 | ret = mv88e6xxx_mdio_read_indirect(ps, port, 16); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1158 | if (ret < 0) |
| 1159 | goto out; |
| 1160 | |
| 1161 | reg = ret & ~0x0300; |
| 1162 | if (e->eee_enabled) |
| 1163 | reg |= 0x0200; |
| 1164 | if (e->tx_lpi_enabled) |
| 1165 | reg |= 0x0100; |
| 1166 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 1167 | ret = mv88e6xxx_mdio_write_indirect(ps, port, 16, reg); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1168 | out: |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1169 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1170 | |
| 1171 | return ret; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1172 | } |
| 1173 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1174 | static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_priv_state *ps, u16 fid, u16 cmd) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1175 | { |
| 1176 | int ret; |
| 1177 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1178 | if (mv88e6xxx_has_fid_reg(ps)) { |
| 1179 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_ATU_FID, fid); |
Vivien Didelot | b426e5f | 2016-03-31 16:53:42 -0400 | [diff] [blame] | 1180 | if (ret < 0) |
| 1181 | return ret; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1182 | } else if (mv88e6xxx_num_databases(ps) == 256) { |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1183 | /* ATU DBNum[7:4] are located in ATU Control 15:12 */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1184 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_ATU_CONTROL); |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1185 | if (ret < 0) |
| 1186 | return ret; |
| 1187 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1188 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_ATU_CONTROL, |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1189 | (ret & 0xfff) | |
| 1190 | ((fid << 8) & 0xf000)); |
| 1191 | if (ret < 0) |
| 1192 | return ret; |
| 1193 | |
| 1194 | /* ATU DBNum[3:0] are located in ATU Operation 3:0 */ |
| 1195 | cmd |= fid & 0xf; |
Vivien Didelot | b426e5f | 2016-03-31 16:53:42 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1198 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_ATU_OP, cmd); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1199 | if (ret < 0) |
| 1200 | return ret; |
| 1201 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1202 | return _mv88e6xxx_atu_wait(ps); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1205 | static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | 37705b7 | 2015-09-04 14:34:11 -0400 | [diff] [blame] | 1206 | struct mv88e6xxx_atu_entry *entry) |
| 1207 | { |
| 1208 | u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK; |
| 1209 | |
| 1210 | if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 1211 | unsigned int mask, shift; |
| 1212 | |
| 1213 | if (entry->trunk) { |
| 1214 | data |= GLOBAL_ATU_DATA_TRUNK; |
| 1215 | mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK; |
| 1216 | shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT; |
| 1217 | } else { |
| 1218 | mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK; |
| 1219 | shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT; |
| 1220 | } |
| 1221 | |
| 1222 | data |= (entry->portv_trunkid << shift) & mask; |
| 1223 | } |
| 1224 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1225 | return _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_ATU_DATA, data); |
Vivien Didelot | 37705b7 | 2015-09-04 14:34:11 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1228 | static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame] | 1229 | struct mv88e6xxx_atu_entry *entry, |
| 1230 | bool static_too) |
| 1231 | { |
| 1232 | int op; |
| 1233 | int err; |
| 1234 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1235 | err = _mv88e6xxx_atu_wait(ps); |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame] | 1236 | if (err) |
| 1237 | return err; |
| 1238 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1239 | err = _mv88e6xxx_atu_data_write(ps, entry); |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame] | 1240 | if (err) |
| 1241 | return err; |
| 1242 | |
| 1243 | if (entry->fid) { |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame] | 1244 | op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB : |
| 1245 | GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB; |
| 1246 | } else { |
| 1247 | op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL : |
| 1248 | GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC; |
| 1249 | } |
| 1250 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1251 | return _mv88e6xxx_atu_cmd(ps, entry->fid, op); |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame] | 1252 | } |
| 1253 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1254 | static int _mv88e6xxx_atu_flush(struct mv88e6xxx_priv_state *ps, |
| 1255 | u16 fid, bool static_too) |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame] | 1256 | { |
| 1257 | struct mv88e6xxx_atu_entry entry = { |
| 1258 | .fid = fid, |
| 1259 | .state = 0, /* EntryState bits must be 0 */ |
| 1260 | }; |
| 1261 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1262 | return _mv88e6xxx_atu_flush_move(ps, &entry, static_too); |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1265 | static int _mv88e6xxx_atu_move(struct mv88e6xxx_priv_state *ps, u16 fid, |
| 1266 | int from_port, int to_port, bool static_too) |
Vivien Didelot | 9f4d55d | 2015-09-04 14:34:15 -0400 | [diff] [blame] | 1267 | { |
| 1268 | struct mv88e6xxx_atu_entry entry = { |
| 1269 | .trunk = false, |
| 1270 | .fid = fid, |
| 1271 | }; |
| 1272 | |
| 1273 | /* EntryState bits must be 0xF */ |
| 1274 | entry.state = GLOBAL_ATU_DATA_STATE_MASK; |
| 1275 | |
| 1276 | /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */ |
| 1277 | entry.portv_trunkid = (to_port & 0x0f) << 4; |
| 1278 | entry.portv_trunkid |= from_port & 0x0f; |
| 1279 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1280 | return _mv88e6xxx_atu_flush_move(ps, &entry, static_too); |
Vivien Didelot | 9f4d55d | 2015-09-04 14:34:15 -0400 | [diff] [blame] | 1281 | } |
| 1282 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1283 | static int _mv88e6xxx_atu_remove(struct mv88e6xxx_priv_state *ps, u16 fid, |
| 1284 | int port, bool static_too) |
Vivien Didelot | 9f4d55d | 2015-09-04 14:34:15 -0400 | [diff] [blame] | 1285 | { |
| 1286 | /* Destination port 0xF means remove the entries */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1287 | return _mv88e6xxx_atu_move(ps, fid, port, 0x0f, static_too); |
Vivien Didelot | 9f4d55d | 2015-09-04 14:34:15 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1290 | static const char * const mv88e6xxx_port_state_names[] = { |
| 1291 | [PORT_CONTROL_STATE_DISABLED] = "Disabled", |
| 1292 | [PORT_CONTROL_STATE_BLOCKING] = "Blocking/Listening", |
| 1293 | [PORT_CONTROL_STATE_LEARNING] = "Learning", |
| 1294 | [PORT_CONTROL_STATE_FORWARDING] = "Forwarding", |
| 1295 | }; |
| 1296 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1297 | static int _mv88e6xxx_port_state(struct mv88e6xxx_priv_state *ps, int port, |
| 1298 | u8 state) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1299 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1300 | struct dsa_switch *ds = ps->ds; |
Geert Uytterhoeven | c3ffe6d | 2015-04-16 20:49:14 +0200 | [diff] [blame] | 1301 | int reg, ret = 0; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1302 | u8 oldstate; |
| 1303 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1304 | reg = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_CONTROL); |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1305 | if (reg < 0) |
| 1306 | return reg; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1307 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1308 | oldstate = reg & PORT_CONTROL_STATE_MASK; |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1309 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1310 | if (oldstate != state) { |
| 1311 | /* Flush forwarding database if we're moving a port |
| 1312 | * from Learning or Forwarding state to Disabled or |
| 1313 | * Blocking or Listening state. |
| 1314 | */ |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1315 | if ((oldstate == PORT_CONTROL_STATE_LEARNING || |
| 1316 | oldstate == PORT_CONTROL_STATE_FORWARDING) |
| 1317 | && (state == PORT_CONTROL_STATE_DISABLED || |
| 1318 | state == PORT_CONTROL_STATE_BLOCKING)) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1319 | ret = _mv88e6xxx_atu_remove(ps, 0, port, false); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1320 | if (ret) |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1321 | return ret; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1322 | } |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1323 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1324 | reg = (reg & ~PORT_CONTROL_STATE_MASK) | state; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1325 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL, |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1326 | reg); |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1327 | if (ret) |
| 1328 | return ret; |
| 1329 | |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 1330 | netdev_dbg(ds->ports[port].netdev, "PortState %s (was %s)\n", |
Vivien Didelot | 2d9deae | 2016-03-07 18:24:17 -0500 | [diff] [blame] | 1331 | mv88e6xxx_port_state_names[state], |
| 1332 | mv88e6xxx_port_state_names[oldstate]); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1335 | return ret; |
| 1336 | } |
| 1337 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1338 | static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_priv_state *ps, |
| 1339 | int port) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1340 | { |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 1341 | struct net_device *bridge = ps->ports[port].bridge_dev; |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 1342 | const u16 mask = (1 << ps->info->num_ports) - 1; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1343 | struct dsa_switch *ds = ps->ds; |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 1344 | u16 output_ports = 0; |
Vivien Didelot | ede8098 | 2015-10-11 18:08:35 -0400 | [diff] [blame] | 1345 | int reg; |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 1346 | int i; |
| 1347 | |
| 1348 | /* allow CPU port or DSA link(s) to send frames to every port */ |
| 1349 | if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) { |
| 1350 | output_ports = mask; |
| 1351 | } else { |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 1352 | for (i = 0; i < ps->info->num_ports; ++i) { |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 1353 | /* allow sending frames to every group member */ |
| 1354 | if (bridge && ps->ports[i].bridge_dev == bridge) |
| 1355 | output_ports |= BIT(i); |
| 1356 | |
| 1357 | /* allow sending frames to CPU port and DSA link(s) */ |
| 1358 | if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)) |
| 1359 | output_ports |= BIT(i); |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | /* prevent frames from going back out of the port they came in on */ |
| 1364 | output_ports &= ~BIT(port); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1365 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1366 | reg = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_BASE_VLAN); |
Vivien Didelot | ede8098 | 2015-10-11 18:08:35 -0400 | [diff] [blame] | 1367 | if (reg < 0) |
| 1368 | return reg; |
| 1369 | |
| 1370 | reg &= ~mask; |
| 1371 | reg |= output_ports & mask; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1372 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1373 | return _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_BASE_VLAN, reg); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 1376 | static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port, |
| 1377 | u8 state) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1378 | { |
| 1379 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1380 | int stp_state; |
Vivien Didelot | 553eb54 | 2016-05-13 20:38:23 -0400 | [diff] [blame] | 1381 | int err; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1382 | |
Vivien Didelot | 936f234 | 2016-05-09 13:22:46 -0400 | [diff] [blame] | 1383 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_PORTSTATE)) |
| 1384 | return; |
| 1385 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1386 | switch (state) { |
| 1387 | case BR_STATE_DISABLED: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1388 | stp_state = PORT_CONTROL_STATE_DISABLED; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1389 | break; |
| 1390 | case BR_STATE_BLOCKING: |
| 1391 | case BR_STATE_LISTENING: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1392 | stp_state = PORT_CONTROL_STATE_BLOCKING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | case BR_STATE_LEARNING: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1395 | stp_state = PORT_CONTROL_STATE_LEARNING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | case BR_STATE_FORWARDING: |
| 1398 | default: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1399 | stp_state = PORT_CONTROL_STATE_FORWARDING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1400 | break; |
| 1401 | } |
| 1402 | |
Vivien Didelot | 553eb54 | 2016-05-13 20:38:23 -0400 | [diff] [blame] | 1403 | mutex_lock(&ps->smi_mutex); |
| 1404 | err = _mv88e6xxx_port_state(ps, port, stp_state); |
| 1405 | mutex_unlock(&ps->smi_mutex); |
| 1406 | |
| 1407 | if (err) |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 1408 | netdev_err(ds->ports[port].netdev, |
| 1409 | "failed to update state to %s\n", |
Vivien Didelot | 553eb54 | 2016-05-13 20:38:23 -0400 | [diff] [blame] | 1410 | mv88e6xxx_port_state_names[stp_state]); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1413 | static int _mv88e6xxx_port_pvid(struct mv88e6xxx_priv_state *ps, int port, |
| 1414 | u16 *new, u16 *old) |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 1415 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1416 | struct dsa_switch *ds = ps->ds; |
Vivien Didelot | 5da9603 | 2016-03-07 18:24:39 -0500 | [diff] [blame] | 1417 | u16 pvid; |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 1418 | int ret; |
| 1419 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1420 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_DEFAULT_VLAN); |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 1421 | if (ret < 0) |
| 1422 | return ret; |
| 1423 | |
Vivien Didelot | 5da9603 | 2016-03-07 18:24:39 -0500 | [diff] [blame] | 1424 | pvid = ret & PORT_DEFAULT_VLAN_MASK; |
| 1425 | |
| 1426 | if (new) { |
| 1427 | ret &= ~PORT_DEFAULT_VLAN_MASK; |
| 1428 | ret |= *new & PORT_DEFAULT_VLAN_MASK; |
| 1429 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1430 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Vivien Didelot | 5da9603 | 2016-03-07 18:24:39 -0500 | [diff] [blame] | 1431 | PORT_DEFAULT_VLAN, ret); |
| 1432 | if (ret < 0) |
| 1433 | return ret; |
| 1434 | |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 1435 | netdev_dbg(ds->ports[port].netdev, |
| 1436 | "DefaultVID %d (was %d)\n", *new, pvid); |
Vivien Didelot | 5da9603 | 2016-03-07 18:24:39 -0500 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | if (old) |
| 1440 | *old = pvid; |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 1441 | |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1445 | static int _mv88e6xxx_port_pvid_get(struct mv88e6xxx_priv_state *ps, |
| 1446 | int port, u16 *pvid) |
Vivien Didelot | 5da9603 | 2016-03-07 18:24:39 -0500 | [diff] [blame] | 1447 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1448 | return _mv88e6xxx_port_pvid(ps, port, NULL, pvid); |
Vivien Didelot | 5da9603 | 2016-03-07 18:24:39 -0500 | [diff] [blame] | 1449 | } |
| 1450 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1451 | static int _mv88e6xxx_port_pvid_set(struct mv88e6xxx_priv_state *ps, |
| 1452 | int port, u16 pvid) |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1453 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1454 | return _mv88e6xxx_port_pvid(ps, port, &pvid, NULL); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1457 | static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_priv_state *ps) |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1458 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1459 | return _mv88e6xxx_wait(ps, REG_GLOBAL, GLOBAL_VTU_OP, |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1460 | GLOBAL_VTU_OP_BUSY); |
| 1461 | } |
| 1462 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1463 | static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_priv_state *ps, u16 op) |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1464 | { |
| 1465 | int ret; |
| 1466 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1467 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_OP, op); |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1468 | if (ret < 0) |
| 1469 | return ret; |
| 1470 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1471 | return _mv88e6xxx_vtu_wait(ps); |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1472 | } |
| 1473 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1474 | static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_priv_state *ps) |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1475 | { |
| 1476 | int ret; |
| 1477 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1478 | ret = _mv88e6xxx_vtu_wait(ps); |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1479 | if (ret < 0) |
| 1480 | return ret; |
| 1481 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1482 | return _mv88e6xxx_vtu_cmd(ps, GLOBAL_VTU_OP_FLUSH_ALL); |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1483 | } |
| 1484 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1485 | static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1486 | struct mv88e6xxx_vtu_stu_entry *entry, |
| 1487 | unsigned int nibble_offset) |
| 1488 | { |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1489 | u16 regs[3]; |
| 1490 | int i; |
| 1491 | int ret; |
| 1492 | |
| 1493 | for (i = 0; i < 3; ++i) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1494 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1495 | GLOBAL_VTU_DATA_0_3 + i); |
| 1496 | if (ret < 0) |
| 1497 | return ret; |
| 1498 | |
| 1499 | regs[i] = ret; |
| 1500 | } |
| 1501 | |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 1502 | for (i = 0; i < ps->info->num_ports; ++i) { |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1503 | unsigned int shift = (i % 4) * 4 + nibble_offset; |
| 1504 | u16 reg = regs[i / 4]; |
| 1505 | |
| 1506 | entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK; |
| 1507 | } |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
Vivien Didelot | 15d7d7d | 2016-05-10 15:44:28 -0400 | [diff] [blame] | 1512 | static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_priv_state *ps, |
| 1513 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1514 | { |
| 1515 | return _mv88e6xxx_vtu_stu_data_read(ps, entry, 0); |
| 1516 | } |
| 1517 | |
| 1518 | static int mv88e6xxx_stu_data_read(struct mv88e6xxx_priv_state *ps, |
| 1519 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1520 | { |
| 1521 | return _mv88e6xxx_vtu_stu_data_read(ps, entry, 2); |
| 1522 | } |
| 1523 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1524 | static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1525 | struct mv88e6xxx_vtu_stu_entry *entry, |
| 1526 | unsigned int nibble_offset) |
| 1527 | { |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1528 | u16 regs[3] = { 0 }; |
| 1529 | int i; |
| 1530 | int ret; |
| 1531 | |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 1532 | for (i = 0; i < ps->info->num_ports; ++i) { |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1533 | unsigned int shift = (i % 4) * 4 + nibble_offset; |
| 1534 | u8 data = entry->data[i]; |
| 1535 | |
| 1536 | regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift; |
| 1537 | } |
| 1538 | |
| 1539 | for (i = 0; i < 3; ++i) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1540 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1541 | GLOBAL_VTU_DATA_0_3 + i, regs[i]); |
| 1542 | if (ret < 0) |
| 1543 | return ret; |
| 1544 | } |
| 1545 | |
| 1546 | return 0; |
| 1547 | } |
| 1548 | |
Vivien Didelot | 15d7d7d | 2016-05-10 15:44:28 -0400 | [diff] [blame] | 1549 | static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_priv_state *ps, |
| 1550 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1551 | { |
| 1552 | return _mv88e6xxx_vtu_stu_data_write(ps, entry, 0); |
| 1553 | } |
| 1554 | |
| 1555 | static int mv88e6xxx_stu_data_write(struct mv88e6xxx_priv_state *ps, |
| 1556 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1557 | { |
| 1558 | return _mv88e6xxx_vtu_stu_data_write(ps, entry, 2); |
| 1559 | } |
| 1560 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1561 | static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_priv_state *ps, u16 vid) |
Vivien Didelot | 36d04ba | 2015-10-22 09:34:39 -0400 | [diff] [blame] | 1562 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1563 | return _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_VID, |
Vivien Didelot | 36d04ba | 2015-10-22 09:34:39 -0400 | [diff] [blame] | 1564 | vid & GLOBAL_VTU_VID_MASK); |
| 1565 | } |
| 1566 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1567 | static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1568 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1569 | { |
| 1570 | struct mv88e6xxx_vtu_stu_entry next = { 0 }; |
| 1571 | int ret; |
| 1572 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1573 | ret = _mv88e6xxx_vtu_wait(ps); |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1574 | if (ret < 0) |
| 1575 | return ret; |
| 1576 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1577 | ret = _mv88e6xxx_vtu_cmd(ps, GLOBAL_VTU_OP_VTU_GET_NEXT); |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1578 | if (ret < 0) |
| 1579 | return ret; |
| 1580 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1581 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_VTU_VID); |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1582 | if (ret < 0) |
| 1583 | return ret; |
| 1584 | |
| 1585 | next.vid = ret & GLOBAL_VTU_VID_MASK; |
| 1586 | next.valid = !!(ret & GLOBAL_VTU_VID_VALID); |
| 1587 | |
| 1588 | if (next.valid) { |
Vivien Didelot | 15d7d7d | 2016-05-10 15:44:28 -0400 | [diff] [blame] | 1589 | ret = mv88e6xxx_vtu_data_read(ps, &next); |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1590 | if (ret < 0) |
| 1591 | return ret; |
| 1592 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1593 | if (mv88e6xxx_has_fid_reg(ps)) { |
| 1594 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1595 | GLOBAL_VTU_FID); |
| 1596 | if (ret < 0) |
| 1597 | return ret; |
| 1598 | |
| 1599 | next.fid = ret & GLOBAL_VTU_FID_MASK; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1600 | } else if (mv88e6xxx_num_databases(ps) == 256) { |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1601 | /* VTU DBNum[7:4] are located in VTU Operation 11:8, and |
| 1602 | * VTU DBNum[3:0] are located in VTU Operation 3:0 |
| 1603 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1604 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1605 | GLOBAL_VTU_OP); |
| 1606 | if (ret < 0) |
| 1607 | return ret; |
| 1608 | |
| 1609 | next.fid = (ret & 0xf00) >> 4; |
| 1610 | next.fid |= ret & 0xf; |
Vivien Didelot | 2e7bd5e | 2016-03-31 16:53:41 -0400 | [diff] [blame] | 1611 | } |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1612 | |
Vivien Didelot | cb9b902 | 2016-05-10 15:44:29 -0400 | [diff] [blame] | 1613 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_STU)) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1614 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1615 | GLOBAL_VTU_SID); |
| 1616 | if (ret < 0) |
| 1617 | return ret; |
| 1618 | |
| 1619 | next.sid = ret & GLOBAL_VTU_SID_MASK; |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | *entry = next; |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 1627 | static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port, |
| 1628 | struct switchdev_obj_port_vlan *vlan, |
| 1629 | int (*cb)(struct switchdev_obj *obj)) |
Vivien Didelot | ceff5ef | 2016-02-23 12:13:55 -0500 | [diff] [blame] | 1630 | { |
| 1631 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1632 | struct mv88e6xxx_vtu_stu_entry next; |
| 1633 | u16 pvid; |
| 1634 | int err; |
| 1635 | |
Vivien Didelot | 54d77b5 | 2016-05-09 13:22:47 -0400 | [diff] [blame] | 1636 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_VTU)) |
| 1637 | return -EOPNOTSUPP; |
| 1638 | |
Vivien Didelot | ceff5ef | 2016-02-23 12:13:55 -0500 | [diff] [blame] | 1639 | mutex_lock(&ps->smi_mutex); |
| 1640 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1641 | err = _mv88e6xxx_port_pvid_get(ps, port, &pvid); |
Vivien Didelot | ceff5ef | 2016-02-23 12:13:55 -0500 | [diff] [blame] | 1642 | if (err) |
| 1643 | goto unlock; |
| 1644 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1645 | err = _mv88e6xxx_vtu_vid_write(ps, GLOBAL_VTU_VID_MASK); |
Vivien Didelot | ceff5ef | 2016-02-23 12:13:55 -0500 | [diff] [blame] | 1646 | if (err) |
| 1647 | goto unlock; |
| 1648 | |
| 1649 | do { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1650 | err = _mv88e6xxx_vtu_getnext(ps, &next); |
Vivien Didelot | ceff5ef | 2016-02-23 12:13:55 -0500 | [diff] [blame] | 1651 | if (err) |
| 1652 | break; |
| 1653 | |
| 1654 | if (!next.valid) |
| 1655 | break; |
| 1656 | |
| 1657 | if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) |
| 1658 | continue; |
| 1659 | |
| 1660 | /* reinit and dump this VLAN obj */ |
| 1661 | vlan->vid_begin = vlan->vid_end = next.vid; |
| 1662 | vlan->flags = 0; |
| 1663 | |
| 1664 | if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED) |
| 1665 | vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
| 1666 | |
| 1667 | if (next.vid == pvid) |
| 1668 | vlan->flags |= BRIDGE_VLAN_INFO_PVID; |
| 1669 | |
| 1670 | err = cb(&vlan->obj); |
| 1671 | if (err) |
| 1672 | break; |
| 1673 | } while (next.vid < GLOBAL_VTU_VID_MASK); |
| 1674 | |
| 1675 | unlock: |
| 1676 | mutex_unlock(&ps->smi_mutex); |
| 1677 | |
| 1678 | return err; |
| 1679 | } |
| 1680 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1681 | static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1682 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1683 | { |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1684 | u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE; |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1685 | u16 reg = 0; |
| 1686 | int ret; |
| 1687 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1688 | ret = _mv88e6xxx_vtu_wait(ps); |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1689 | if (ret < 0) |
| 1690 | return ret; |
| 1691 | |
| 1692 | if (!entry->valid) |
| 1693 | goto loadpurge; |
| 1694 | |
| 1695 | /* Write port member tags */ |
Vivien Didelot | 15d7d7d | 2016-05-10 15:44:28 -0400 | [diff] [blame] | 1696 | ret = mv88e6xxx_vtu_data_write(ps, entry); |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1697 | if (ret < 0) |
| 1698 | return ret; |
| 1699 | |
Vivien Didelot | cb9b902 | 2016-05-10 15:44:29 -0400 | [diff] [blame] | 1700 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_STU)) { |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1701 | reg = entry->sid & GLOBAL_VTU_SID_MASK; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1702 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_SID, reg); |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1703 | if (ret < 0) |
| 1704 | return ret; |
Vivien Didelot | b426e5f | 2016-03-31 16:53:42 -0400 | [diff] [blame] | 1705 | } |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1706 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1707 | if (mv88e6xxx_has_fid_reg(ps)) { |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1708 | reg = entry->fid & GLOBAL_VTU_FID_MASK; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1709 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_FID, reg); |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1710 | if (ret < 0) |
| 1711 | return ret; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1712 | } else if (mv88e6xxx_num_databases(ps) == 256) { |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1713 | /* VTU DBNum[7:4] are located in VTU Operation 11:8, and |
| 1714 | * VTU DBNum[3:0] are located in VTU Operation 3:0 |
| 1715 | */ |
| 1716 | op |= (entry->fid & 0xf0) << 8; |
| 1717 | op |= entry->fid & 0xf; |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | reg = GLOBAL_VTU_VID_VALID; |
| 1721 | loadpurge: |
| 1722 | reg |= entry->vid & GLOBAL_VTU_VID_MASK; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1723 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_VID, reg); |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1724 | if (ret < 0) |
| 1725 | return ret; |
| 1726 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1727 | return _mv88e6xxx_vtu_cmd(ps, op); |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1728 | } |
| 1729 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1730 | static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_priv_state *ps, u8 sid, |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1731 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1732 | { |
| 1733 | struct mv88e6xxx_vtu_stu_entry next = { 0 }; |
| 1734 | int ret; |
| 1735 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1736 | ret = _mv88e6xxx_vtu_wait(ps); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1737 | if (ret < 0) |
| 1738 | return ret; |
| 1739 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1740 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_SID, |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1741 | sid & GLOBAL_VTU_SID_MASK); |
| 1742 | if (ret < 0) |
| 1743 | return ret; |
| 1744 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1745 | ret = _mv88e6xxx_vtu_cmd(ps, GLOBAL_VTU_OP_STU_GET_NEXT); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1746 | if (ret < 0) |
| 1747 | return ret; |
| 1748 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1749 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_VTU_SID); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1750 | if (ret < 0) |
| 1751 | return ret; |
| 1752 | |
| 1753 | next.sid = ret & GLOBAL_VTU_SID_MASK; |
| 1754 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1755 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_VTU_VID); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1756 | if (ret < 0) |
| 1757 | return ret; |
| 1758 | |
| 1759 | next.valid = !!(ret & GLOBAL_VTU_VID_VALID); |
| 1760 | |
| 1761 | if (next.valid) { |
Vivien Didelot | 15d7d7d | 2016-05-10 15:44:28 -0400 | [diff] [blame] | 1762 | ret = mv88e6xxx_stu_data_read(ps, &next); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1763 | if (ret < 0) |
| 1764 | return ret; |
| 1765 | } |
| 1766 | |
| 1767 | *entry = next; |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1771 | static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1772 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1773 | { |
| 1774 | u16 reg = 0; |
| 1775 | int ret; |
| 1776 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1777 | ret = _mv88e6xxx_vtu_wait(ps); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1778 | if (ret < 0) |
| 1779 | return ret; |
| 1780 | |
| 1781 | if (!entry->valid) |
| 1782 | goto loadpurge; |
| 1783 | |
| 1784 | /* Write port states */ |
Vivien Didelot | 15d7d7d | 2016-05-10 15:44:28 -0400 | [diff] [blame] | 1785 | ret = mv88e6xxx_stu_data_write(ps, entry); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1786 | if (ret < 0) |
| 1787 | return ret; |
| 1788 | |
| 1789 | reg = GLOBAL_VTU_VID_VALID; |
| 1790 | loadpurge: |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1791 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_VID, reg); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1792 | if (ret < 0) |
| 1793 | return ret; |
| 1794 | |
| 1795 | reg = entry->sid & GLOBAL_VTU_SID_MASK; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1796 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_VTU_SID, reg); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1797 | if (ret < 0) |
| 1798 | return ret; |
| 1799 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1800 | return _mv88e6xxx_vtu_cmd(ps, GLOBAL_VTU_OP_STU_LOAD_PURGE); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1801 | } |
| 1802 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1803 | static int _mv88e6xxx_port_fid(struct mv88e6xxx_priv_state *ps, int port, |
| 1804 | u16 *new, u16 *old) |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1805 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1806 | struct dsa_switch *ds = ps->ds; |
Vivien Didelot | f74df0b | 2016-03-31 16:53:43 -0400 | [diff] [blame] | 1807 | u16 upper_mask; |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1808 | u16 fid; |
| 1809 | int ret; |
| 1810 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1811 | if (mv88e6xxx_num_databases(ps) == 4096) |
Vivien Didelot | f74df0b | 2016-03-31 16:53:43 -0400 | [diff] [blame] | 1812 | upper_mask = 0xff; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1813 | else if (mv88e6xxx_num_databases(ps) == 256) |
Vivien Didelot | 11ea809 | 2016-03-31 16:53:44 -0400 | [diff] [blame] | 1814 | upper_mask = 0xf; |
Vivien Didelot | f74df0b | 2016-03-31 16:53:43 -0400 | [diff] [blame] | 1815 | else |
| 1816 | return -EOPNOTSUPP; |
| 1817 | |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1818 | /* Port's default FID bits 3:0 are located in reg 0x06, offset 12 */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1819 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_BASE_VLAN); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1820 | if (ret < 0) |
| 1821 | return ret; |
| 1822 | |
| 1823 | fid = (ret & PORT_BASE_VLAN_FID_3_0_MASK) >> 12; |
| 1824 | |
| 1825 | if (new) { |
| 1826 | ret &= ~PORT_BASE_VLAN_FID_3_0_MASK; |
| 1827 | ret |= (*new << 12) & PORT_BASE_VLAN_FID_3_0_MASK; |
| 1828 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1829 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_BASE_VLAN, |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1830 | ret); |
| 1831 | if (ret < 0) |
| 1832 | return ret; |
| 1833 | } |
| 1834 | |
| 1835 | /* Port's default FID bits 11:4 are located in reg 0x05, offset 0 */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1836 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_CONTROL_1); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1837 | if (ret < 0) |
| 1838 | return ret; |
| 1839 | |
Vivien Didelot | f74df0b | 2016-03-31 16:53:43 -0400 | [diff] [blame] | 1840 | fid |= (ret & upper_mask) << 4; |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1841 | |
| 1842 | if (new) { |
Vivien Didelot | f74df0b | 2016-03-31 16:53:43 -0400 | [diff] [blame] | 1843 | ret &= ~upper_mask; |
| 1844 | ret |= (*new >> 4) & upper_mask; |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1845 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1846 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL_1, |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1847 | ret); |
| 1848 | if (ret < 0) |
| 1849 | return ret; |
| 1850 | |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 1851 | netdev_dbg(ds->ports[port].netdev, |
| 1852 | "FID %d (was %d)\n", *new, fid); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | if (old) |
| 1856 | *old = fid; |
| 1857 | |
| 1858 | return 0; |
| 1859 | } |
| 1860 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1861 | static int _mv88e6xxx_port_fid_get(struct mv88e6xxx_priv_state *ps, |
| 1862 | int port, u16 *fid) |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1863 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1864 | return _mv88e6xxx_port_fid(ps, port, NULL, fid); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1865 | } |
| 1866 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1867 | static int _mv88e6xxx_port_fid_set(struct mv88e6xxx_priv_state *ps, |
| 1868 | int port, u16 fid) |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1869 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1870 | return _mv88e6xxx_port_fid(ps, port, &fid, NULL); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1871 | } |
| 1872 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1873 | static int _mv88e6xxx_fid_new(struct mv88e6xxx_priv_state *ps, u16 *fid) |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1874 | { |
| 1875 | DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID); |
| 1876 | struct mv88e6xxx_vtu_stu_entry vlan; |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1877 | int i, err; |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1878 | |
| 1879 | bitmap_zero(fid_bitmap, MV88E6XXX_N_FID); |
| 1880 | |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1881 | /* Set every FID bit used by the (un)bridged ports */ |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 1882 | for (i = 0; i < ps->info->num_ports; ++i) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1883 | err = _mv88e6xxx_port_fid_get(ps, i, fid); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 1884 | if (err) |
| 1885 | return err; |
| 1886 | |
| 1887 | set_bit(*fid, fid_bitmap); |
| 1888 | } |
| 1889 | |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1890 | /* Set every FID bit used by the VLAN entries */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1891 | err = _mv88e6xxx_vtu_vid_write(ps, GLOBAL_VTU_VID_MASK); |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1892 | if (err) |
| 1893 | return err; |
| 1894 | |
| 1895 | do { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1896 | err = _mv88e6xxx_vtu_getnext(ps, &vlan); |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1897 | if (err) |
| 1898 | return err; |
| 1899 | |
| 1900 | if (!vlan.valid) |
| 1901 | break; |
| 1902 | |
| 1903 | set_bit(vlan.fid, fid_bitmap); |
| 1904 | } while (vlan.vid < GLOBAL_VTU_VID_MASK); |
| 1905 | |
| 1906 | /* The reset value 0x000 is used to indicate that multiple address |
| 1907 | * databases are not needed. Return the next positive available. |
| 1908 | */ |
| 1909 | *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1910 | if (unlikely(*fid >= mv88e6xxx_num_databases(ps))) |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1911 | return -ENOSPC; |
| 1912 | |
| 1913 | /* Clear the database */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1914 | return _mv88e6xxx_atu_flush(ps, *fid, true); |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1915 | } |
| 1916 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1917 | static int _mv88e6xxx_vtu_new(struct mv88e6xxx_priv_state *ps, u16 vid, |
Vivien Didelot | 2fb5ef0 | 2016-02-26 13:16:01 -0500 | [diff] [blame] | 1918 | struct mv88e6xxx_vtu_stu_entry *entry) |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1919 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1920 | struct dsa_switch *ds = ps->ds; |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1921 | struct mv88e6xxx_vtu_stu_entry vlan = { |
| 1922 | .valid = true, |
| 1923 | .vid = vid, |
| 1924 | }; |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1925 | int i, err; |
| 1926 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1927 | err = _mv88e6xxx_fid_new(ps, &vlan.fid); |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 1928 | if (err) |
| 1929 | return err; |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1930 | |
Vivien Didelot | 3d131f0 | 2015-11-03 10:52:52 -0500 | [diff] [blame] | 1931 | /* exclude all ports except the CPU and DSA ports */ |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 1932 | for (i = 0; i < ps->info->num_ports; ++i) |
Vivien Didelot | 3d131f0 | 2015-11-03 10:52:52 -0500 | [diff] [blame] | 1933 | vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i) |
| 1934 | ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED |
| 1935 | : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1936 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1937 | if (mv88e6xxx_6097_family(ps) || mv88e6xxx_6165_family(ps) || |
| 1938 | mv88e6xxx_6351_family(ps) || mv88e6xxx_6352_family(ps)) { |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1939 | struct mv88e6xxx_vtu_stu_entry vstp; |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1940 | |
| 1941 | /* Adding a VTU entry requires a valid STU entry. As VSTP is not |
| 1942 | * implemented, only one STU entry is needed to cover all VTU |
| 1943 | * entries. Thus, validate the SID 0. |
| 1944 | */ |
| 1945 | vlan.sid = 0; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1946 | err = _mv88e6xxx_stu_getnext(ps, GLOBAL_VTU_SID_MASK, &vstp); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1947 | if (err) |
| 1948 | return err; |
| 1949 | |
| 1950 | if (vstp.sid != vlan.sid || !vstp.valid) { |
| 1951 | memset(&vstp, 0, sizeof(vstp)); |
| 1952 | vstp.valid = true; |
| 1953 | vstp.sid = vlan.sid; |
| 1954 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1955 | err = _mv88e6xxx_stu_loadpurge(ps, &vstp); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1956 | if (err) |
| 1957 | return err; |
| 1958 | } |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | *entry = vlan; |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1965 | static int _mv88e6xxx_vtu_get(struct mv88e6xxx_priv_state *ps, u16 vid, |
Vivien Didelot | 2fb5ef0 | 2016-02-26 13:16:01 -0500 | [diff] [blame] | 1966 | struct mv88e6xxx_vtu_stu_entry *entry, bool creat) |
| 1967 | { |
| 1968 | int err; |
| 1969 | |
| 1970 | if (!vid) |
| 1971 | return -EINVAL; |
| 1972 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1973 | err = _mv88e6xxx_vtu_vid_write(ps, vid - 1); |
Vivien Didelot | 2fb5ef0 | 2016-02-26 13:16:01 -0500 | [diff] [blame] | 1974 | if (err) |
| 1975 | return err; |
| 1976 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1977 | err = _mv88e6xxx_vtu_getnext(ps, entry); |
Vivien Didelot | 2fb5ef0 | 2016-02-26 13:16:01 -0500 | [diff] [blame] | 1978 | if (err) |
| 1979 | return err; |
| 1980 | |
| 1981 | if (entry->vid != vid || !entry->valid) { |
| 1982 | if (!creat) |
| 1983 | return -EOPNOTSUPP; |
| 1984 | /* -ENOENT would've been more appropriate, but switchdev expects |
| 1985 | * -EOPNOTSUPP to inform bridge about an eventual software VLAN. |
| 1986 | */ |
| 1987 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 1988 | err = _mv88e6xxx_vtu_new(ps, vid, entry); |
Vivien Didelot | 2fb5ef0 | 2016-02-26 13:16:01 -0500 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | return err; |
| 1992 | } |
| 1993 | |
Vivien Didelot | da9c359 | 2016-02-12 12:09:40 -0500 | [diff] [blame] | 1994 | static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, |
| 1995 | u16 vid_begin, u16 vid_end) |
| 1996 | { |
| 1997 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1998 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 1999 | int i, err; |
| 2000 | |
| 2001 | if (!vid_begin) |
| 2002 | return -EOPNOTSUPP; |
| 2003 | |
| 2004 | mutex_lock(&ps->smi_mutex); |
| 2005 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2006 | err = _mv88e6xxx_vtu_vid_write(ps, vid_begin - 1); |
Vivien Didelot | da9c359 | 2016-02-12 12:09:40 -0500 | [diff] [blame] | 2007 | if (err) |
| 2008 | goto unlock; |
| 2009 | |
| 2010 | do { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2011 | err = _mv88e6xxx_vtu_getnext(ps, &vlan); |
Vivien Didelot | da9c359 | 2016-02-12 12:09:40 -0500 | [diff] [blame] | 2012 | if (err) |
| 2013 | goto unlock; |
| 2014 | |
| 2015 | if (!vlan.valid) |
| 2016 | break; |
| 2017 | |
| 2018 | if (vlan.vid > vid_end) |
| 2019 | break; |
| 2020 | |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 2021 | for (i = 0; i < ps->info->num_ports; ++i) { |
Vivien Didelot | da9c359 | 2016-02-12 12:09:40 -0500 | [diff] [blame] | 2022 | if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i)) |
| 2023 | continue; |
| 2024 | |
| 2025 | if (vlan.data[i] == |
| 2026 | GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) |
| 2027 | continue; |
| 2028 | |
| 2029 | if (ps->ports[i].bridge_dev == |
| 2030 | ps->ports[port].bridge_dev) |
| 2031 | break; /* same bridge, check next VLAN */ |
| 2032 | |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 2033 | netdev_warn(ds->ports[port].netdev, |
Vivien Didelot | da9c359 | 2016-02-12 12:09:40 -0500 | [diff] [blame] | 2034 | "hardware VLAN %d already used by %s\n", |
| 2035 | vlan.vid, |
| 2036 | netdev_name(ps->ports[i].bridge_dev)); |
| 2037 | err = -EOPNOTSUPP; |
| 2038 | goto unlock; |
| 2039 | } |
| 2040 | } while (vlan.vid < vid_end); |
| 2041 | |
| 2042 | unlock: |
| 2043 | mutex_unlock(&ps->smi_mutex); |
| 2044 | |
| 2045 | return err; |
| 2046 | } |
| 2047 | |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 2048 | static const char * const mv88e6xxx_port_8021q_mode_names[] = { |
| 2049 | [PORT_CONTROL_2_8021Q_DISABLED] = "Disabled", |
| 2050 | [PORT_CONTROL_2_8021Q_FALLBACK] = "Fallback", |
| 2051 | [PORT_CONTROL_2_8021Q_CHECK] = "Check", |
| 2052 | [PORT_CONTROL_2_8021Q_SECURE] = "Secure", |
| 2053 | }; |
| 2054 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2055 | static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port, |
| 2056 | bool vlan_filtering) |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 2057 | { |
| 2058 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2059 | u16 old, new = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE : |
| 2060 | PORT_CONTROL_2_8021Q_DISABLED; |
| 2061 | int ret; |
| 2062 | |
Vivien Didelot | 54d77b5 | 2016-05-09 13:22:47 -0400 | [diff] [blame] | 2063 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_VTU)) |
| 2064 | return -EOPNOTSUPP; |
| 2065 | |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 2066 | mutex_lock(&ps->smi_mutex); |
| 2067 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2068 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_CONTROL_2); |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 2069 | if (ret < 0) |
| 2070 | goto unlock; |
| 2071 | |
| 2072 | old = ret & PORT_CONTROL_2_8021Q_MASK; |
| 2073 | |
Vivien Didelot | 5220ef1 | 2016-03-07 18:24:52 -0500 | [diff] [blame] | 2074 | if (new != old) { |
| 2075 | ret &= ~PORT_CONTROL_2_8021Q_MASK; |
| 2076 | ret |= new & PORT_CONTROL_2_8021Q_MASK; |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 2077 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2078 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL_2, |
Vivien Didelot | 5220ef1 | 2016-03-07 18:24:52 -0500 | [diff] [blame] | 2079 | ret); |
| 2080 | if (ret < 0) |
| 2081 | goto unlock; |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 2082 | |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 2083 | netdev_dbg(ds->ports[port].netdev, "802.1Q Mode %s (was %s)\n", |
Vivien Didelot | 5220ef1 | 2016-03-07 18:24:52 -0500 | [diff] [blame] | 2084 | mv88e6xxx_port_8021q_mode_names[new], |
| 2085 | mv88e6xxx_port_8021q_mode_names[old]); |
| 2086 | } |
| 2087 | |
| 2088 | ret = 0; |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 2089 | unlock: |
| 2090 | mutex_unlock(&ps->smi_mutex); |
| 2091 | |
| 2092 | return ret; |
| 2093 | } |
| 2094 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2095 | static int mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port, |
| 2096 | const struct switchdev_obj_port_vlan *vlan, |
| 2097 | struct switchdev_trans *trans) |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 2098 | { |
Vivien Didelot | 54d77b5 | 2016-05-09 13:22:47 -0400 | [diff] [blame] | 2099 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | da9c359 | 2016-02-12 12:09:40 -0500 | [diff] [blame] | 2100 | int err; |
| 2101 | |
Vivien Didelot | 54d77b5 | 2016-05-09 13:22:47 -0400 | [diff] [blame] | 2102 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_VTU)) |
| 2103 | return -EOPNOTSUPP; |
| 2104 | |
Vivien Didelot | da9c359 | 2016-02-12 12:09:40 -0500 | [diff] [blame] | 2105 | /* If the requested port doesn't belong to the same bridge as the VLAN |
| 2106 | * members, do not support it (yet) and fallback to software VLAN. |
| 2107 | */ |
| 2108 | err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin, |
| 2109 | vlan->vid_end); |
| 2110 | if (err) |
| 2111 | return err; |
| 2112 | |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2113 | /* We don't need any dynamic resource from the kernel (yet), |
| 2114 | * so skip the prepare phase. |
| 2115 | */ |
| 2116 | return 0; |
| 2117 | } |
| 2118 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2119 | static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_priv_state *ps, int port, |
| 2120 | u16 vid, bool untagged) |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2121 | { |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 2122 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 2123 | int err; |
| 2124 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2125 | err = _mv88e6xxx_vtu_get(ps, vid, &vlan, true); |
Vivien Didelot | 36d04ba | 2015-10-22 09:34:39 -0400 | [diff] [blame] | 2126 | if (err) |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2127 | return err; |
Vivien Didelot | 36d04ba | 2015-10-22 09:34:39 -0400 | [diff] [blame] | 2128 | |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 2129 | vlan.data[port] = untagged ? |
| 2130 | GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED : |
| 2131 | GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED; |
| 2132 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2133 | return _mv88e6xxx_vtu_loadpurge(ps, &vlan); |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2134 | } |
| 2135 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2136 | static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port, |
| 2137 | const struct switchdev_obj_port_vlan *vlan, |
| 2138 | struct switchdev_trans *trans) |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2139 | { |
| 2140 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2141 | bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; |
| 2142 | bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; |
| 2143 | u16 vid; |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2144 | |
Vivien Didelot | 54d77b5 | 2016-05-09 13:22:47 -0400 | [diff] [blame] | 2145 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_VTU)) |
| 2146 | return; |
| 2147 | |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2148 | mutex_lock(&ps->smi_mutex); |
| 2149 | |
Vivien Didelot | 4d5770b | 2016-04-06 11:55:05 -0400 | [diff] [blame] | 2150 | for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2151 | if (_mv88e6xxx_port_vlan_add(ps, port, vid, untagged)) |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 2152 | netdev_err(ds->ports[port].netdev, |
| 2153 | "failed to add VLAN %d%c\n", |
Vivien Didelot | 4d5770b | 2016-04-06 11:55:05 -0400 | [diff] [blame] | 2154 | vid, untagged ? 'u' : 't'); |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2155 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2156 | if (pvid && _mv88e6xxx_port_pvid_set(ps, port, vlan->vid_end)) |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 2157 | netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n", |
Vivien Didelot | 4d5770b | 2016-04-06 11:55:05 -0400 | [diff] [blame] | 2158 | vlan->vid_end); |
| 2159 | |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 2160 | mutex_unlock(&ps->smi_mutex); |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 2161 | } |
| 2162 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2163 | static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_priv_state *ps, |
| 2164 | int port, u16 vid) |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2165 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2166 | struct dsa_switch *ds = ps->ds; |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2167 | struct mv88e6xxx_vtu_stu_entry vlan; |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2168 | int i, err; |
| 2169 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2170 | err = _mv88e6xxx_vtu_get(ps, vid, &vlan, false); |
Vivien Didelot | 36d04ba | 2015-10-22 09:34:39 -0400 | [diff] [blame] | 2171 | if (err) |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2172 | return err; |
Vivien Didelot | 36d04ba | 2015-10-22 09:34:39 -0400 | [diff] [blame] | 2173 | |
Vivien Didelot | 2fb5ef0 | 2016-02-26 13:16:01 -0500 | [diff] [blame] | 2174 | /* Tell switchdev if this VLAN is handled in software */ |
| 2175 | if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) |
Vivien Didelot | 3c06f08 | 2016-02-05 14:04:39 -0500 | [diff] [blame] | 2176 | return -EOPNOTSUPP; |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2177 | |
| 2178 | vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; |
| 2179 | |
| 2180 | /* keep the VLAN unless all ports are excluded */ |
Vivien Didelot | f02bdff | 2015-10-11 18:08:36 -0400 | [diff] [blame] | 2181 | vlan.valid = false; |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 2182 | for (i = 0; i < ps->info->num_ports; ++i) { |
Vivien Didelot | 3d131f0 | 2015-11-03 10:52:52 -0500 | [diff] [blame] | 2183 | if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)) |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2184 | continue; |
| 2185 | |
| 2186 | if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) { |
Vivien Didelot | f02bdff | 2015-10-11 18:08:36 -0400 | [diff] [blame] | 2187 | vlan.valid = true; |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2188 | break; |
| 2189 | } |
| 2190 | } |
| 2191 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2192 | err = _mv88e6xxx_vtu_loadpurge(ps, &vlan); |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2193 | if (err) |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2194 | return err; |
| 2195 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2196 | return _mv88e6xxx_atu_remove(ps, vlan.fid, port, false); |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2197 | } |
| 2198 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2199 | static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, |
| 2200 | const struct switchdev_obj_port_vlan *vlan) |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2201 | { |
| 2202 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2203 | u16 pvid, vid; |
| 2204 | int err = 0; |
| 2205 | |
Vivien Didelot | 54d77b5 | 2016-05-09 13:22:47 -0400 | [diff] [blame] | 2206 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_VTU)) |
| 2207 | return -EOPNOTSUPP; |
| 2208 | |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2209 | mutex_lock(&ps->smi_mutex); |
| 2210 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2211 | err = _mv88e6xxx_port_pvid_get(ps, port, &pvid); |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2212 | if (err) |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2213 | goto unlock; |
| 2214 | |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2215 | for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2216 | err = _mv88e6xxx_port_vlan_del(ps, port, vid); |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2217 | if (err) |
| 2218 | goto unlock; |
| 2219 | |
| 2220 | if (vid == pvid) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2221 | err = _mv88e6xxx_port_pvid_set(ps, port, 0); |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 2222 | if (err) |
| 2223 | goto unlock; |
| 2224 | } |
| 2225 | } |
| 2226 | |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 2227 | unlock: |
| 2228 | mutex_unlock(&ps->smi_mutex); |
| 2229 | |
| 2230 | return err; |
| 2231 | } |
| 2232 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2233 | static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 2234 | const unsigned char *addr) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2235 | { |
| 2236 | int i, ret; |
| 2237 | |
| 2238 | for (i = 0; i < 3; i++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 2239 | ret = _mv88e6xxx_reg_write( |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2240 | ps, REG_GLOBAL, GLOBAL_ATU_MAC_01 + i, |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 2241 | (addr[i * 2] << 8) | addr[i * 2 + 1]); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2242 | if (ret < 0) |
| 2243 | return ret; |
| 2244 | } |
| 2245 | |
| 2246 | return 0; |
| 2247 | } |
| 2248 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2249 | static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_priv_state *ps, |
| 2250 | unsigned char *addr) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2251 | { |
| 2252 | int i, ret; |
| 2253 | |
| 2254 | for (i = 0; i < 3; i++) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2255 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 2256 | GLOBAL_ATU_MAC_01 + i); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2257 | if (ret < 0) |
| 2258 | return ret; |
| 2259 | addr[i * 2] = ret >> 8; |
| 2260 | addr[i * 2 + 1] = ret & 0xff; |
| 2261 | } |
| 2262 | |
| 2263 | return 0; |
| 2264 | } |
| 2265 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2266 | static int _mv88e6xxx_atu_load(struct mv88e6xxx_priv_state *ps, |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 2267 | struct mv88e6xxx_atu_entry *entry) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2268 | { |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2269 | int ret; |
| 2270 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2271 | ret = _mv88e6xxx_atu_wait(ps); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2272 | if (ret < 0) |
| 2273 | return ret; |
| 2274 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2275 | ret = _mv88e6xxx_atu_mac_write(ps, entry->mac); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2276 | if (ret < 0) |
| 2277 | return ret; |
| 2278 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2279 | ret = _mv88e6xxx_atu_data_write(ps, entry); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 2280 | if (ret < 0) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2281 | return ret; |
| 2282 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2283 | return _mv88e6xxx_atu_cmd(ps, entry->fid, GLOBAL_ATU_OP_LOAD_DB); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 2284 | } |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2285 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2286 | static int _mv88e6xxx_port_fdb_load(struct mv88e6xxx_priv_state *ps, int port, |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 2287 | const unsigned char *addr, u16 vid, |
| 2288 | u8 state) |
| 2289 | { |
| 2290 | struct mv88e6xxx_atu_entry entry = { 0 }; |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 2291 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 2292 | int err; |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 2293 | |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2294 | /* Null VLAN ID corresponds to the port private database */ |
| 2295 | if (vid == 0) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2296 | err = _mv88e6xxx_port_fid_get(ps, port, &vlan.fid); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2297 | else |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2298 | err = _mv88e6xxx_vtu_get(ps, vid, &vlan, false); |
Vivien Didelot | 3285f9e | 2016-02-26 13:16:03 -0500 | [diff] [blame] | 2299 | if (err) |
| 2300 | return err; |
| 2301 | |
| 2302 | entry.fid = vlan.fid; |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 2303 | entry.state = state; |
| 2304 | ether_addr_copy(entry.mac, addr); |
| 2305 | if (state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 2306 | entry.trunk = false; |
| 2307 | entry.portv_trunkid = BIT(port); |
| 2308 | } |
| 2309 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2310 | return _mv88e6xxx_atu_load(ps, &entry); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2313 | static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port, |
| 2314 | const struct switchdev_obj_port_fdb *fdb, |
| 2315 | struct switchdev_trans *trans) |
Vivien Didelot | 146a320 | 2015-10-08 11:35:12 -0400 | [diff] [blame] | 2316 | { |
Vivien Didelot | 2672f82 | 2016-05-09 13:22:48 -0400 | [diff] [blame] | 2317 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2318 | |
| 2319 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_ATU)) |
| 2320 | return -EOPNOTSUPP; |
| 2321 | |
Vivien Didelot | 146a320 | 2015-10-08 11:35:12 -0400 | [diff] [blame] | 2322 | /* We don't need any dynamic resource from the kernel (yet), |
| 2323 | * so skip the prepare phase. |
| 2324 | */ |
| 2325 | return 0; |
| 2326 | } |
| 2327 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2328 | static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port, |
| 2329 | const struct switchdev_obj_port_fdb *fdb, |
| 2330 | struct switchdev_trans *trans) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2331 | { |
Vivien Didelot | 1f36faf | 2015-10-08 11:35:13 -0400 | [diff] [blame] | 2332 | int state = is_multicast_ether_addr(fdb->addr) ? |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2333 | GLOBAL_ATU_DATA_STATE_MC_STATIC : |
| 2334 | GLOBAL_ATU_DATA_STATE_UC_STATIC; |
| 2335 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 6630e23 | 2015-08-06 01:44:07 -0400 | [diff] [blame] | 2336 | |
Vivien Didelot | 2672f82 | 2016-05-09 13:22:48 -0400 | [diff] [blame] | 2337 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_ATU)) |
| 2338 | return; |
| 2339 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2340 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2341 | if (_mv88e6xxx_port_fdb_load(ps, port, fdb->addr, fdb->vid, state)) |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 2342 | netdev_err(ds->ports[port].netdev, |
| 2343 | "failed to load MAC address\n"); |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2344 | mutex_unlock(&ps->smi_mutex); |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2347 | static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, |
| 2348 | const struct switchdev_obj_port_fdb *fdb) |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2349 | { |
| 2350 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2351 | int ret; |
| 2352 | |
Vivien Didelot | 2672f82 | 2016-05-09 13:22:48 -0400 | [diff] [blame] | 2353 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_ATU)) |
| 2354 | return -EOPNOTSUPP; |
| 2355 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2356 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2357 | ret = _mv88e6xxx_port_fdb_load(ps, port, fdb->addr, fdb->vid, |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2358 | GLOBAL_ATU_DATA_STATE_UNUSED); |
| 2359 | mutex_unlock(&ps->smi_mutex); |
| 2360 | |
| 2361 | return ret; |
| 2362 | } |
| 2363 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2364 | static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_priv_state *ps, u16 fid, |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 2365 | struct mv88e6xxx_atu_entry *entry) |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 2366 | { |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 2367 | struct mv88e6xxx_atu_entry next = { 0 }; |
| 2368 | int ret; |
| 2369 | |
| 2370 | next.fid = fid; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2371 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2372 | ret = _mv88e6xxx_atu_wait(ps); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2373 | if (ret < 0) |
| 2374 | return ret; |
| 2375 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2376 | ret = _mv88e6xxx_atu_cmd(ps, fid, GLOBAL_ATU_OP_GET_NEXT_DB); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2377 | if (ret < 0) |
| 2378 | return ret; |
| 2379 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2380 | ret = _mv88e6xxx_atu_mac_read(ps, next.mac); |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 2381 | if (ret < 0) |
| 2382 | return ret; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2383 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2384 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, GLOBAL_ATU_DATA); |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 2385 | if (ret < 0) |
| 2386 | return ret; |
| 2387 | |
| 2388 | next.state = ret & GLOBAL_ATU_DATA_STATE_MASK; |
| 2389 | if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 2390 | unsigned int mask, shift; |
| 2391 | |
| 2392 | if (ret & GLOBAL_ATU_DATA_TRUNK) { |
| 2393 | next.trunk = true; |
| 2394 | mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK; |
| 2395 | shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT; |
| 2396 | } else { |
| 2397 | next.trunk = false; |
| 2398 | mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK; |
| 2399 | shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT; |
| 2400 | } |
| 2401 | |
| 2402 | next.portv_trunkid = (ret & mask) >> shift; |
| 2403 | } |
| 2404 | |
| 2405 | *entry = next; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2406 | return 0; |
| 2407 | } |
| 2408 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2409 | static int _mv88e6xxx_port_fdb_dump_one(struct mv88e6xxx_priv_state *ps, |
| 2410 | u16 fid, u16 vid, int port, |
Vivien Didelot | 74b6ba0 | 2016-02-26 13:16:02 -0500 | [diff] [blame] | 2411 | struct switchdev_obj_port_fdb *fdb, |
| 2412 | int (*cb)(struct switchdev_obj *obj)) |
| 2413 | { |
| 2414 | struct mv88e6xxx_atu_entry addr = { |
| 2415 | .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, |
| 2416 | }; |
| 2417 | int err; |
| 2418 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2419 | err = _mv88e6xxx_atu_mac_write(ps, addr.mac); |
Vivien Didelot | 74b6ba0 | 2016-02-26 13:16:02 -0500 | [diff] [blame] | 2420 | if (err) |
| 2421 | return err; |
| 2422 | |
| 2423 | do { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2424 | err = _mv88e6xxx_atu_getnext(ps, fid, &addr); |
Vivien Didelot | 74b6ba0 | 2016-02-26 13:16:02 -0500 | [diff] [blame] | 2425 | if (err) |
| 2426 | break; |
| 2427 | |
| 2428 | if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED) |
| 2429 | break; |
| 2430 | |
| 2431 | if (!addr.trunk && addr.portv_trunkid & BIT(port)) { |
| 2432 | bool is_static = addr.state == |
| 2433 | (is_multicast_ether_addr(addr.mac) ? |
| 2434 | GLOBAL_ATU_DATA_STATE_MC_STATIC : |
| 2435 | GLOBAL_ATU_DATA_STATE_UC_STATIC); |
| 2436 | |
| 2437 | fdb->vid = vid; |
| 2438 | ether_addr_copy(fdb->addr, addr.mac); |
| 2439 | fdb->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE; |
| 2440 | |
| 2441 | err = cb(&fdb->obj); |
| 2442 | if (err) |
| 2443 | break; |
| 2444 | } |
| 2445 | } while (!is_broadcast_ether_addr(addr.mac)); |
| 2446 | |
| 2447 | return err; |
| 2448 | } |
| 2449 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2450 | static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port, |
| 2451 | struct switchdev_obj_port_fdb *fdb, |
| 2452 | int (*cb)(struct switchdev_obj *obj)) |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2453 | { |
| 2454 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2455 | struct mv88e6xxx_vtu_stu_entry vlan = { |
| 2456 | .vid = GLOBAL_VTU_VID_MASK, /* all ones */ |
| 2457 | }; |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2458 | u16 fid; |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2459 | int err; |
| 2460 | |
Vivien Didelot | 2672f82 | 2016-05-09 13:22:48 -0400 | [diff] [blame] | 2461 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_ATU)) |
| 2462 | return -EOPNOTSUPP; |
| 2463 | |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2464 | mutex_lock(&ps->smi_mutex); |
| 2465 | |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2466 | /* Dump port's default Filtering Information Database (VLAN ID 0) */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2467 | err = _mv88e6xxx_port_fid_get(ps, port, &fid); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2468 | if (err) |
| 2469 | goto unlock; |
| 2470 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2471 | err = _mv88e6xxx_port_fdb_dump_one(ps, fid, 0, port, fdb, cb); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2472 | if (err) |
| 2473 | goto unlock; |
| 2474 | |
Vivien Didelot | 74b6ba0 | 2016-02-26 13:16:02 -0500 | [diff] [blame] | 2475 | /* Dump VLANs' Filtering Information Databases */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2476 | err = _mv88e6xxx_vtu_vid_write(ps, vlan.vid); |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2477 | if (err) |
| 2478 | goto unlock; |
| 2479 | |
| 2480 | do { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2481 | err = _mv88e6xxx_vtu_getnext(ps, &vlan); |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2482 | if (err) |
Vivien Didelot | 74b6ba0 | 2016-02-26 13:16:02 -0500 | [diff] [blame] | 2483 | break; |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2484 | |
| 2485 | if (!vlan.valid) |
| 2486 | break; |
| 2487 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2488 | err = _mv88e6xxx_port_fdb_dump_one(ps, vlan.fid, vlan.vid, port, |
Vivien Didelot | 74b6ba0 | 2016-02-26 13:16:02 -0500 | [diff] [blame] | 2489 | fdb, cb); |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2490 | if (err) |
Vivien Didelot | 74b6ba0 | 2016-02-26 13:16:02 -0500 | [diff] [blame] | 2491 | break; |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 2492 | } while (vlan.vid < GLOBAL_VTU_VID_MASK); |
| 2493 | |
| 2494 | unlock: |
| 2495 | mutex_unlock(&ps->smi_mutex); |
| 2496 | |
| 2497 | return err; |
| 2498 | } |
| 2499 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2500 | static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, |
| 2501 | struct net_device *bridge) |
Vivien Didelot | e79a8bc | 2015-11-04 17:23:40 -0500 | [diff] [blame] | 2502 | { |
Vivien Didelot | a669275 | 2016-02-12 12:09:39 -0500 | [diff] [blame] | 2503 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Colin Ian King | 1d9619d | 2016-04-25 23:11:22 +0100 | [diff] [blame] | 2504 | int i, err = 0; |
Vivien Didelot | 466dfa0 | 2016-02-26 13:16:05 -0500 | [diff] [blame] | 2505 | |
Vivien Didelot | 936f234 | 2016-05-09 13:22:46 -0400 | [diff] [blame] | 2506 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_VLANTABLE)) |
| 2507 | return -EOPNOTSUPP; |
| 2508 | |
Vivien Didelot | 466dfa0 | 2016-02-26 13:16:05 -0500 | [diff] [blame] | 2509 | mutex_lock(&ps->smi_mutex); |
| 2510 | |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2511 | /* Assign the bridge and remap each port's VLANTable */ |
Vivien Didelot | a669275 | 2016-02-12 12:09:39 -0500 | [diff] [blame] | 2512 | ps->ports[port].bridge_dev = bridge; |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2513 | |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 2514 | for (i = 0; i < ps->info->num_ports; ++i) { |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2515 | if (ps->ports[i].bridge_dev == bridge) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2516 | err = _mv88e6xxx_port_based_vlan_map(ps, i); |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2517 | if (err) |
| 2518 | break; |
| 2519 | } |
| 2520 | } |
| 2521 | |
Vivien Didelot | 466dfa0 | 2016-02-26 13:16:05 -0500 | [diff] [blame] | 2522 | mutex_unlock(&ps->smi_mutex); |
Vivien Didelot | a669275 | 2016-02-12 12:09:39 -0500 | [diff] [blame] | 2523 | |
Vivien Didelot | 466dfa0 | 2016-02-26 13:16:05 -0500 | [diff] [blame] | 2524 | return err; |
Vivien Didelot | e79a8bc | 2015-11-04 17:23:40 -0500 | [diff] [blame] | 2525 | } |
| 2526 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 2527 | static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port) |
Vivien Didelot | e79a8bc | 2015-11-04 17:23:40 -0500 | [diff] [blame] | 2528 | { |
Vivien Didelot | a669275 | 2016-02-12 12:09:39 -0500 | [diff] [blame] | 2529 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2530 | struct net_device *bridge = ps->ports[port].bridge_dev; |
Vivien Didelot | 16bfa70 | 2016-03-13 16:21:33 -0400 | [diff] [blame] | 2531 | int i; |
Vivien Didelot | 466dfa0 | 2016-02-26 13:16:05 -0500 | [diff] [blame] | 2532 | |
Vivien Didelot | 936f234 | 2016-05-09 13:22:46 -0400 | [diff] [blame] | 2533 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_VLANTABLE)) |
| 2534 | return; |
| 2535 | |
Vivien Didelot | 466dfa0 | 2016-02-26 13:16:05 -0500 | [diff] [blame] | 2536 | mutex_lock(&ps->smi_mutex); |
| 2537 | |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2538 | /* Unassign the bridge and remap each port's VLANTable */ |
Vivien Didelot | a669275 | 2016-02-12 12:09:39 -0500 | [diff] [blame] | 2539 | ps->ports[port].bridge_dev = NULL; |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2540 | |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 2541 | for (i = 0; i < ps->info->num_ports; ++i) |
Vivien Didelot | 16bfa70 | 2016-03-13 16:21:33 -0400 | [diff] [blame] | 2542 | if (i == port || ps->ports[i].bridge_dev == bridge) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2543 | if (_mv88e6xxx_port_based_vlan_map(ps, i)) |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 2544 | netdev_warn(ds->ports[i].netdev, |
| 2545 | "failed to remap\n"); |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2546 | |
Vivien Didelot | 466dfa0 | 2016-02-26 13:16:05 -0500 | [diff] [blame] | 2547 | mutex_unlock(&ps->smi_mutex); |
Vivien Didelot | 66d9cd0 | 2016-02-05 14:07:14 -0500 | [diff] [blame] | 2548 | } |
| 2549 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2550 | static int _mv88e6xxx_mdio_page_write(struct mv88e6xxx_priv_state *ps, |
| 2551 | int port, int page, int reg, int val) |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2552 | { |
| 2553 | int ret; |
| 2554 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2555 | ret = mv88e6xxx_mdio_write_indirect(ps, port, 0x16, page); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2556 | if (ret < 0) |
| 2557 | goto restore_page_0; |
| 2558 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2559 | ret = mv88e6xxx_mdio_write_indirect(ps, port, reg, val); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2560 | restore_page_0: |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2561 | mv88e6xxx_mdio_write_indirect(ps, port, 0x16, 0x0); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2562 | |
| 2563 | return ret; |
| 2564 | } |
| 2565 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2566 | static int _mv88e6xxx_mdio_page_read(struct mv88e6xxx_priv_state *ps, |
| 2567 | int port, int page, int reg) |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2568 | { |
| 2569 | int ret; |
| 2570 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2571 | ret = mv88e6xxx_mdio_write_indirect(ps, port, 0x16, page); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2572 | if (ret < 0) |
| 2573 | goto restore_page_0; |
| 2574 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2575 | ret = mv88e6xxx_mdio_read_indirect(ps, port, reg); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2576 | restore_page_0: |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2577 | mv88e6xxx_mdio_write_indirect(ps, port, 0x16, 0x0); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 2578 | |
| 2579 | return ret; |
| 2580 | } |
| 2581 | |
Vivien Didelot | 552238b | 2016-05-09 13:22:49 -0400 | [diff] [blame] | 2582 | static int mv88e6xxx_switch_reset(struct mv88e6xxx_priv_state *ps) |
| 2583 | { |
| 2584 | bool ppu_active = mv88e6xxx_has(ps, MV88E6XXX_FLAG_PPU_ACTIVE); |
| 2585 | u16 is_reset = (ppu_active ? 0x8800 : 0xc800); |
Andrew Lunn | 52638f7 | 2016-05-10 23:27:22 +0200 | [diff] [blame] | 2586 | struct gpio_desc *gpiod = ps->reset; |
Vivien Didelot | 552238b | 2016-05-09 13:22:49 -0400 | [diff] [blame] | 2587 | unsigned long timeout; |
| 2588 | int ret; |
| 2589 | int i; |
| 2590 | |
| 2591 | /* Set all ports to the disabled state. */ |
| 2592 | for (i = 0; i < ps->info->num_ports; i++) { |
| 2593 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(i), PORT_CONTROL); |
| 2594 | if (ret < 0) |
| 2595 | return ret; |
| 2596 | |
| 2597 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(i), PORT_CONTROL, |
| 2598 | ret & 0xfffc); |
| 2599 | if (ret) |
| 2600 | return ret; |
| 2601 | } |
| 2602 | |
| 2603 | /* Wait for transmit queues to drain. */ |
| 2604 | usleep_range(2000, 4000); |
| 2605 | |
| 2606 | /* If there is a gpio connected to the reset pin, toggle it */ |
| 2607 | if (gpiod) { |
| 2608 | gpiod_set_value_cansleep(gpiod, 1); |
| 2609 | usleep_range(10000, 20000); |
| 2610 | gpiod_set_value_cansleep(gpiod, 0); |
| 2611 | usleep_range(10000, 20000); |
| 2612 | } |
| 2613 | |
| 2614 | /* Reset the switch. Keep the PPU active if requested. The PPU |
| 2615 | * needs to be active to support indirect phy register access |
| 2616 | * through global registers 0x18 and 0x19. |
| 2617 | */ |
| 2618 | if (ppu_active) |
| 2619 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, 0x04, 0xc000); |
| 2620 | else |
| 2621 | ret = _mv88e6xxx_reg_write(ps, REG_GLOBAL, 0x04, 0xc400); |
| 2622 | if (ret) |
| 2623 | return ret; |
| 2624 | |
| 2625 | /* Wait up to one second for reset to complete. */ |
| 2626 | timeout = jiffies + 1 * HZ; |
| 2627 | while (time_before(jiffies, timeout)) { |
| 2628 | ret = _mv88e6xxx_reg_read(ps, REG_GLOBAL, 0x00); |
| 2629 | if (ret < 0) |
| 2630 | return ret; |
| 2631 | |
| 2632 | if ((ret & is_reset) == is_reset) |
| 2633 | break; |
| 2634 | usleep_range(1000, 2000); |
| 2635 | } |
| 2636 | if (time_after(jiffies, timeout)) |
| 2637 | ret = -ETIMEDOUT; |
| 2638 | else |
| 2639 | ret = 0; |
| 2640 | |
| 2641 | return ret; |
| 2642 | } |
| 2643 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2644 | static int mv88e6xxx_power_on_serdes(struct mv88e6xxx_priv_state *ps) |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2645 | { |
| 2646 | int ret; |
| 2647 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2648 | ret = _mv88e6xxx_mdio_page_read(ps, REG_FIBER_SERDES, |
| 2649 | PAGE_FIBER_SERDES, MII_BMCR); |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2650 | if (ret < 0) |
| 2651 | return ret; |
| 2652 | |
| 2653 | if (ret & BMCR_PDOWN) { |
| 2654 | ret &= ~BMCR_PDOWN; |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 2655 | ret = _mv88e6xxx_mdio_page_write(ps, REG_FIBER_SERDES, |
| 2656 | PAGE_FIBER_SERDES, MII_BMCR, |
| 2657 | ret); |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | return ret; |
| 2661 | } |
| 2662 | |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2663 | static int mv88e6xxx_setup_port(struct mv88e6xxx_priv_state *ps, int port) |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2664 | { |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2665 | struct dsa_switch *ds = ps->ds; |
Vivien Didelot | f02bdff | 2015-10-11 18:08:36 -0400 | [diff] [blame] | 2666 | int ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2667 | u16 reg; |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2668 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2669 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2670 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2671 | mv88e6xxx_6185_family(ps) || mv88e6xxx_6095_family(ps) || |
| 2672 | mv88e6xxx_6065_family(ps) || mv88e6xxx_6320_family(ps)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2673 | /* MAC Forcing register: don't force link, speed, |
| 2674 | * duplex or flow control state to any particular |
| 2675 | * values on physical ports, but force the CPU port |
| 2676 | * and all DSA ports to their maximum bandwidth and |
| 2677 | * full duplex. |
| 2678 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2679 | reg = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_PCS_CTRL); |
Andrew Lunn | 60045cb | 2015-08-17 23:52:51 +0200 | [diff] [blame] | 2680 | if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) { |
Russell King | 53adc9e | 2015-09-21 21:42:59 +0100 | [diff] [blame] | 2681 | reg &= ~PORT_PCS_CTRL_UNFORCED; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2682 | reg |= PORT_PCS_CTRL_FORCE_LINK | |
| 2683 | PORT_PCS_CTRL_LINK_UP | |
| 2684 | PORT_PCS_CTRL_DUPLEX_FULL | |
| 2685 | PORT_PCS_CTRL_FORCE_DUPLEX; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2686 | if (mv88e6xxx_6065_family(ps)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2687 | reg |= PORT_PCS_CTRL_100; |
| 2688 | else |
| 2689 | reg |= PORT_PCS_CTRL_1000; |
| 2690 | } else { |
| 2691 | reg |= PORT_PCS_CTRL_UNFORCED; |
| 2692 | } |
| 2693 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2694 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2695 | PORT_PCS_CTRL, reg); |
| 2696 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2697 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock, |
| 2701 | * disable Header mode, enable IGMP/MLD snooping, disable VLAN |
| 2702 | * tunneling, determine priority by looking at 802.1p and IP |
| 2703 | * priority fields (IP prio has precedence), and set STP state |
| 2704 | * to Forwarding. |
| 2705 | * |
| 2706 | * If this is the CPU link, use DSA or EDSA tagging depending |
| 2707 | * on which tagging mode was configured. |
| 2708 | * |
| 2709 | * If this is a link to another switch, use DSA tagging mode. |
| 2710 | * |
| 2711 | * If this is the upstream port for this switch, enable |
| 2712 | * forwarding of unknown unicasts and multicasts. |
| 2713 | */ |
| 2714 | reg = 0; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2715 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2716 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2717 | mv88e6xxx_6095_family(ps) || mv88e6xxx_6065_family(ps) || |
| 2718 | mv88e6xxx_6185_family(ps) || mv88e6xxx_6320_family(ps)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2719 | reg = PORT_CONTROL_IGMP_MLD_SNOOP | |
| 2720 | PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP | |
| 2721 | PORT_CONTROL_STATE_FORWARDING; |
| 2722 | if (dsa_is_cpu_port(ds, port)) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2723 | if (mv88e6xxx_6095_family(ps) || mv88e6xxx_6185_family(ps)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2724 | reg |= PORT_CONTROL_DSA_TAG; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2725 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2726 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2727 | mv88e6xxx_6320_family(ps)) { |
Andrew Lunn | 5377b80 | 2016-06-04 21:17:02 +0200 | [diff] [blame] | 2728 | reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA | |
| 2729 | PORT_CONTROL_FORWARD_UNKNOWN | |
Andrew Lunn | c047a1f | 2015-09-29 01:50:56 +0200 | [diff] [blame] | 2730 | PORT_CONTROL_FORWARD_UNKNOWN_MC; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2731 | } |
| 2732 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2733 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2734 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2735 | mv88e6xxx_6095_family(ps) || mv88e6xxx_6065_family(ps) || |
| 2736 | mv88e6xxx_6185_family(ps) || mv88e6xxx_6320_family(ps)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2737 | reg |= PORT_CONTROL_EGRESS_ADD_TAG; |
| 2738 | } |
| 2739 | } |
Andrew Lunn | 6083ce7 | 2015-08-17 23:52:52 +0200 | [diff] [blame] | 2740 | if (dsa_is_dsa_port(ds, port)) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2741 | if (mv88e6xxx_6095_family(ps) || mv88e6xxx_6185_family(ps)) |
Andrew Lunn | 6083ce7 | 2015-08-17 23:52:52 +0200 | [diff] [blame] | 2742 | reg |= PORT_CONTROL_DSA_TAG; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2743 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2744 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2745 | mv88e6xxx_6320_family(ps)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2746 | reg |= PORT_CONTROL_FRAME_MODE_DSA; |
Andrew Lunn | 6083ce7 | 2015-08-17 23:52:52 +0200 | [diff] [blame] | 2747 | } |
| 2748 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2749 | if (port == dsa_upstream_port(ds)) |
| 2750 | reg |= PORT_CONTROL_FORWARD_UNKNOWN | |
| 2751 | PORT_CONTROL_FORWARD_UNKNOWN_MC; |
| 2752 | } |
| 2753 | if (reg) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2754 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2755 | PORT_CONTROL, reg); |
| 2756 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2757 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2758 | } |
| 2759 | |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2760 | /* If this port is connected to a SerDes, make sure the SerDes is not |
| 2761 | * powered down. |
| 2762 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2763 | if (mv88e6xxx_6352_family(ps)) { |
| 2764 | ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_STATUS); |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2765 | if (ret < 0) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2766 | return ret; |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2767 | ret &= PORT_STATUS_CMODE_MASK; |
| 2768 | if ((ret == PORT_STATUS_CMODE_100BASE_X) || |
| 2769 | (ret == PORT_STATUS_CMODE_1000BASE_X) || |
| 2770 | (ret == PORT_STATUS_CMODE_SGMII)) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2771 | ret = mv88e6xxx_power_on_serdes(ps); |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2772 | if (ret < 0) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2773 | return ret; |
Patrick Uiterwijk | 13a7ebb | 2016-03-30 01:39:41 +0000 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | |
Vivien Didelot | 8efdda4 | 2015-08-13 12:52:23 -0400 | [diff] [blame] | 2777 | /* Port Control 2: don't force a good FCS, set the maximum frame size to |
Vivien Didelot | 46fbe5e | 2016-02-26 13:16:07 -0500 | [diff] [blame] | 2778 | * 10240 bytes, disable 802.1q tags checking, don't discard tagged or |
Vivien Didelot | 8efdda4 | 2015-08-13 12:52:23 -0400 | [diff] [blame] | 2779 | * untagged frames on this port, do a destination address lookup on all |
| 2780 | * received packets as usual, disable ARP mirroring and don't send a |
| 2781 | * copy of all transmitted/received frames on this port to the CPU. |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2782 | */ |
| 2783 | reg = 0; |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2784 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2785 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2786 | mv88e6xxx_6095_family(ps) || mv88e6xxx_6320_family(ps) || |
| 2787 | mv88e6xxx_6185_family(ps)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2788 | reg = PORT_CONTROL_2_MAP_DA; |
| 2789 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2790 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2791 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6320_family(ps)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2792 | reg |= PORT_CONTROL_2_JUMBO_10240; |
| 2793 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2794 | if (mv88e6xxx_6095_family(ps) || mv88e6xxx_6185_family(ps)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2795 | /* Set the upstream port this port should use */ |
| 2796 | reg |= dsa_upstream_port(ds); |
| 2797 | /* enable forwarding of unknown multicast addresses to |
| 2798 | * the upstream port |
| 2799 | */ |
| 2800 | if (port == dsa_upstream_port(ds)) |
| 2801 | reg |= PORT_CONTROL_2_FORWARD_UNKNOWN; |
| 2802 | } |
| 2803 | |
Vivien Didelot | 46fbe5e | 2016-02-26 13:16:07 -0500 | [diff] [blame] | 2804 | reg |= PORT_CONTROL_2_8021Q_DISABLED; |
Vivien Didelot | 8efdda4 | 2015-08-13 12:52:23 -0400 | [diff] [blame] | 2805 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2806 | if (reg) { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2807 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2808 | PORT_CONTROL_2, reg); |
| 2809 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2810 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | /* Port Association Vector: when learning source addresses |
| 2814 | * of packets, add the address to the address database using |
| 2815 | * a port bitmap that has only the bit for this port set and |
| 2816 | * the other bits clear. |
| 2817 | */ |
Andrew Lunn | 4c7ea3c | 2015-11-03 10:52:36 -0500 | [diff] [blame] | 2818 | reg = 1 << port; |
Vivien Didelot | 996ecb8 | 2016-04-14 14:42:08 -0400 | [diff] [blame] | 2819 | /* Disable learning for CPU port */ |
| 2820 | if (dsa_is_cpu_port(ds, port)) |
Vivien Didelot | 65fa402 | 2016-04-14 14:42:07 -0400 | [diff] [blame] | 2821 | reg = 0; |
Andrew Lunn | 4c7ea3c | 2015-11-03 10:52:36 -0500 | [diff] [blame] | 2822 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2823 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_ASSOC_VECTOR, reg); |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2824 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2825 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2826 | |
| 2827 | /* Egress rate control 2: disable egress rate control. */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2828 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_RATE_CONTROL_2, |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2829 | 0x0000); |
| 2830 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2831 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2832 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2833 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2834 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2835 | mv88e6xxx_6320_family(ps)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2836 | /* Do not limit the period of time that this port can |
| 2837 | * be paused for by the remote end or the period of |
| 2838 | * time that this port can pause the remote end. |
| 2839 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2840 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2841 | PORT_PAUSE_CTRL, 0x0000); |
| 2842 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2843 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2844 | |
| 2845 | /* Port ATU control: disable limiting the number of |
| 2846 | * address database entries that this port is allowed |
| 2847 | * to use. |
| 2848 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2849 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2850 | PORT_ATU_CONTROL, 0x0000); |
| 2851 | /* Priority Override: disable DA, SA and VTU priority |
| 2852 | * override. |
| 2853 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2854 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2855 | PORT_PRI_OVERRIDE, 0x0000); |
| 2856 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2857 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2858 | |
| 2859 | /* Port Ethertype: use the Ethertype DSA Ethertype |
| 2860 | * value. |
| 2861 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2862 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2863 | PORT_ETH_TYPE, ETH_P_EDSA); |
| 2864 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2865 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2866 | /* Tag Remap: use an identity 802.1p prio -> switch |
| 2867 | * prio mapping. |
| 2868 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2869 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2870 | PORT_TAG_REGMAP_0123, 0x3210); |
| 2871 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2872 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2873 | |
| 2874 | /* Tag Remap 2: use an identity 802.1p prio -> switch |
| 2875 | * prio mapping. |
| 2876 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2877 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2878 | PORT_TAG_REGMAP_4567, 0x7654); |
| 2879 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2880 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2881 | } |
| 2882 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2883 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 2884 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 2885 | mv88e6xxx_6185_family(ps) || mv88e6xxx_6095_family(ps) || |
| 2886 | mv88e6xxx_6320_family(ps)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2887 | /* Rate Control: disable ingress rate limiting. */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2888 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2889 | PORT_RATE_CONTROL, 0x0001); |
| 2890 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2891 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2892 | } |
| 2893 | |
Guenter Roeck | 366f0a0 | 2015-03-26 18:36:30 -0700 | [diff] [blame] | 2894 | /* Port Control 1: disable trunking, disable sending |
| 2895 | * learning messages to this port. |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2896 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2897 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL_1, 0x0000); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2898 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2899 | return ret; |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2900 | |
Vivien Didelot | 207afda | 2016-04-14 14:42:09 -0400 | [diff] [blame] | 2901 | /* Port based VLAN map: give each port the same default address |
Vivien Didelot | b7666ef | 2016-02-26 13:16:06 -0500 | [diff] [blame] | 2902 | * database, and allow bidirectional communication between the |
| 2903 | * CPU and DSA port(s), and the other ports. |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2904 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2905 | ret = _mv88e6xxx_port_fid_set(ps, port, 0); |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2906 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2907 | return ret; |
Vivien Didelot | 2db9ce1 | 2016-02-26 13:16:04 -0500 | [diff] [blame] | 2908 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2909 | ret = _mv88e6xxx_port_based_vlan_map(ps, port); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2910 | if (ret) |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2911 | return ret; |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2912 | |
| 2913 | /* Default VLAN ID and priority: don't set a default VLAN |
| 2914 | * ID, and set the default packet priority to zero. |
| 2915 | */ |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2916 | ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_DEFAULT_VLAN, |
Vivien Didelot | 47cf1e65 | 2015-04-20 17:43:26 -0400 | [diff] [blame] | 2917 | 0x0000); |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 2918 | if (ret) |
| 2919 | return ret; |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2920 | |
Andrew Lunn | dbde9e6 | 2015-05-06 01:09:48 +0200 | [diff] [blame] | 2921 | return 0; |
| 2922 | } |
| 2923 | |
Vivien Didelot | 08a0126 | 2016-05-09 13:22:50 -0400 | [diff] [blame] | 2924 | static int mv88e6xxx_setup_global(struct mv88e6xxx_priv_state *ps) |
| 2925 | { |
Vivien Didelot | b0745e87 | 2016-05-09 13:22:53 -0400 | [diff] [blame] | 2926 | struct dsa_switch *ds = ps->ds; |
| 2927 | u32 upstream_port = dsa_upstream_port(ds); |
Vivien Didelot | 119477b | 2016-05-09 13:22:51 -0400 | [diff] [blame] | 2928 | u16 reg; |
Vivien Didelot | 08a0126 | 2016-05-09 13:22:50 -0400 | [diff] [blame] | 2929 | int err; |
| 2930 | int i; |
| 2931 | |
Vivien Didelot | 119477b | 2016-05-09 13:22:51 -0400 | [diff] [blame] | 2932 | /* Enable the PHY Polling Unit if present, don't discard any packets, |
| 2933 | * and mask all interrupt sources. |
| 2934 | */ |
| 2935 | reg = 0; |
| 2936 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_PPU) || |
| 2937 | mv88e6xxx_has(ps, MV88E6XXX_FLAG_PPU_ACTIVE)) |
| 2938 | reg |= GLOBAL_CONTROL_PPU_ENABLE; |
| 2939 | |
| 2940 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL, reg); |
| 2941 | if (err) |
| 2942 | return err; |
| 2943 | |
Vivien Didelot | b0745e87 | 2016-05-09 13:22:53 -0400 | [diff] [blame] | 2944 | /* Configure the upstream port, and configure it as the port to which |
| 2945 | * ingress and egress and ARP monitor frames are to be sent. |
| 2946 | */ |
| 2947 | reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT | |
| 2948 | upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT | |
| 2949 | upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT; |
| 2950 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg); |
| 2951 | if (err) |
| 2952 | return err; |
| 2953 | |
Vivien Didelot | 50484ff | 2016-05-09 13:22:54 -0400 | [diff] [blame] | 2954 | /* Disable remote management, and set the switch's DSA device number. */ |
| 2955 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2, |
| 2956 | GLOBAL_CONTROL_2_MULTIPLE_CASCADE | |
| 2957 | (ds->index & 0x1f)); |
| 2958 | if (err) |
| 2959 | return err; |
| 2960 | |
Vivien Didelot | 08a0126 | 2016-05-09 13:22:50 -0400 | [diff] [blame] | 2961 | /* Set the default address aging time to 5 minutes, and |
| 2962 | * enable address learn messages to be sent to all message |
| 2963 | * ports. |
| 2964 | */ |
| 2965 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_ATU_CONTROL, |
| 2966 | 0x0140 | GLOBAL_ATU_CONTROL_LEARN2ALL); |
| 2967 | if (err) |
| 2968 | return err; |
| 2969 | |
| 2970 | /* Configure the IP ToS mapping registers. */ |
| 2971 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_0, 0x0000); |
| 2972 | if (err) |
| 2973 | return err; |
| 2974 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_1, 0x0000); |
| 2975 | if (err) |
| 2976 | return err; |
| 2977 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_2, 0x5555); |
| 2978 | if (err) |
| 2979 | return err; |
| 2980 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_3, 0x5555); |
| 2981 | if (err) |
| 2982 | return err; |
| 2983 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_4, 0xaaaa); |
| 2984 | if (err) |
| 2985 | return err; |
| 2986 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_5, 0xaaaa); |
| 2987 | if (err) |
| 2988 | return err; |
| 2989 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_6, 0xffff); |
| 2990 | if (err) |
| 2991 | return err; |
| 2992 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IP_PRI_7, 0xffff); |
| 2993 | if (err) |
| 2994 | return err; |
| 2995 | |
| 2996 | /* Configure the IEEE 802.1p priority mapping register. */ |
| 2997 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_IEEE_PRI, 0xfa41); |
| 2998 | if (err) |
| 2999 | return err; |
| 3000 | |
| 3001 | /* Send all frames with destination addresses matching |
| 3002 | * 01:80:c2:00:00:0x to the CPU port. |
| 3003 | */ |
| 3004 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_MGMT_EN_0X, 0xffff); |
| 3005 | if (err) |
| 3006 | return err; |
| 3007 | |
| 3008 | /* Ignore removed tag data on doubly tagged packets, disable |
| 3009 | * flow control messages, force flow control priority to the |
| 3010 | * highest, and send all special multicast frames to the CPU |
| 3011 | * port at the highest priority. |
| 3012 | */ |
| 3013 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_SWITCH_MGMT, |
| 3014 | 0x7 | GLOBAL2_SWITCH_MGMT_RSVD2CPU | 0x70 | |
| 3015 | GLOBAL2_SWITCH_MGMT_FORCE_FLOW_CTRL_PRI); |
| 3016 | if (err) |
| 3017 | return err; |
| 3018 | |
| 3019 | /* Program the DSA routing table. */ |
| 3020 | for (i = 0; i < 32; i++) { |
| 3021 | int nexthop = 0x1f; |
| 3022 | |
Andrew Lunn | 66472fc | 2016-06-04 21:17:00 +0200 | [diff] [blame] | 3023 | if (i != ds->index && i < DSA_MAX_SWITCHES) |
| 3024 | nexthop = ds->rtable[i] & 0x1f; |
Vivien Didelot | 08a0126 | 2016-05-09 13:22:50 -0400 | [diff] [blame] | 3025 | |
| 3026 | err = _mv88e6xxx_reg_write( |
| 3027 | ps, REG_GLOBAL2, |
| 3028 | GLOBAL2_DEVICE_MAPPING, |
| 3029 | GLOBAL2_DEVICE_MAPPING_UPDATE | |
| 3030 | (i << GLOBAL2_DEVICE_MAPPING_TARGET_SHIFT) | nexthop); |
| 3031 | if (err) |
| 3032 | return err; |
| 3033 | } |
| 3034 | |
| 3035 | /* Clear all trunk masks. */ |
| 3036 | for (i = 0; i < 8; i++) { |
| 3037 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_TRUNK_MASK, |
| 3038 | 0x8000 | |
| 3039 | (i << GLOBAL2_TRUNK_MASK_NUM_SHIFT) | |
| 3040 | ((1 << ps->info->num_ports) - 1)); |
| 3041 | if (err) |
| 3042 | return err; |
| 3043 | } |
| 3044 | |
| 3045 | /* Clear all trunk mappings. */ |
| 3046 | for (i = 0; i < 16; i++) { |
| 3047 | err = _mv88e6xxx_reg_write( |
| 3048 | ps, REG_GLOBAL2, |
| 3049 | GLOBAL2_TRUNK_MAPPING, |
| 3050 | GLOBAL2_TRUNK_MAPPING_UPDATE | |
| 3051 | (i << GLOBAL2_TRUNK_MAPPING_ID_SHIFT)); |
| 3052 | if (err) |
| 3053 | return err; |
| 3054 | } |
| 3055 | |
| 3056 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 3057 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 3058 | mv88e6xxx_6320_family(ps)) { |
| 3059 | /* Send all frames with destination addresses matching |
| 3060 | * 01:80:c2:00:00:2x to the CPU port. |
| 3061 | */ |
| 3062 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, |
| 3063 | GLOBAL2_MGMT_EN_2X, 0xffff); |
| 3064 | if (err) |
| 3065 | return err; |
| 3066 | |
| 3067 | /* Initialise cross-chip port VLAN table to reset |
| 3068 | * defaults. |
| 3069 | */ |
| 3070 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, |
| 3071 | GLOBAL2_PVT_ADDR, 0x9000); |
| 3072 | if (err) |
| 3073 | return err; |
| 3074 | |
| 3075 | /* Clear the priority override table. */ |
| 3076 | for (i = 0; i < 16; i++) { |
| 3077 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, |
| 3078 | GLOBAL2_PRIO_OVERRIDE, |
| 3079 | 0x8000 | (i << 8)); |
| 3080 | if (err) |
| 3081 | return err; |
| 3082 | } |
| 3083 | } |
| 3084 | |
| 3085 | if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || |
| 3086 | mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || |
| 3087 | mv88e6xxx_6185_family(ps) || mv88e6xxx_6095_family(ps) || |
| 3088 | mv88e6xxx_6320_family(ps)) { |
| 3089 | /* Disable ingress rate limiting by resetting all |
| 3090 | * ingress rate limit registers to their initial |
| 3091 | * state. |
| 3092 | */ |
| 3093 | for (i = 0; i < ps->info->num_ports; i++) { |
| 3094 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL2, |
| 3095 | GLOBAL2_INGRESS_OP, |
| 3096 | 0x9000 | (i << 8)); |
| 3097 | if (err) |
| 3098 | return err; |
| 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | /* Clear the statistics counters for all ports */ |
| 3103 | err = _mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_STATS_OP, |
| 3104 | GLOBAL_STATS_OP_FLUSH_ALL); |
| 3105 | if (err) |
| 3106 | return err; |
| 3107 | |
| 3108 | /* Wait for the flush to complete. */ |
| 3109 | err = _mv88e6xxx_stats_wait(ps); |
| 3110 | if (err) |
| 3111 | return err; |
| 3112 | |
| 3113 | /* Clear all ATU entries */ |
| 3114 | err = _mv88e6xxx_atu_flush(ps, 0, true); |
| 3115 | if (err) |
| 3116 | return err; |
| 3117 | |
| 3118 | /* Clear all the VTU and STU entries */ |
| 3119 | err = _mv88e6xxx_vtu_stu_flush(ps); |
| 3120 | if (err < 0) |
| 3121 | return err; |
| 3122 | |
| 3123 | return err; |
| 3124 | } |
| 3125 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3126 | static int mv88e6xxx_setup(struct dsa_switch *ds) |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 3127 | { |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 3128 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 552238b | 2016-05-09 13:22:49 -0400 | [diff] [blame] | 3129 | int err; |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 3130 | int i; |
| 3131 | |
| 3132 | ps->ds = ds; |
Vivien Didelot | 552238b | 2016-05-09 13:22:49 -0400 | [diff] [blame] | 3133 | |
Vivien Didelot | d24645b | 2016-05-09 13:22:41 -0400 | [diff] [blame] | 3134 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM)) |
| 3135 | mutex_init(&ps->eeprom_mutex); |
| 3136 | |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 3137 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_PPU)) |
| 3138 | mv88e6xxx_ppu_state_init(ps); |
| 3139 | |
Vivien Didelot | 552238b | 2016-05-09 13:22:49 -0400 | [diff] [blame] | 3140 | mutex_lock(&ps->smi_mutex); |
| 3141 | |
| 3142 | err = mv88e6xxx_switch_reset(ps); |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 3143 | if (err) |
| 3144 | goto unlock; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 3145 | |
Vivien Didelot | 08a0126 | 2016-05-09 13:22:50 -0400 | [diff] [blame] | 3146 | err = mv88e6xxx_setup_global(ps); |
Vivien Didelot | a1a6a4d | 2016-05-09 13:22:56 -0400 | [diff] [blame] | 3147 | if (err) |
| 3148 | goto unlock; |
| 3149 | |
| 3150 | for (i = 0; i < ps->info->num_ports; i++) { |
| 3151 | err = mv88e6xxx_setup_port(ps, i); |
| 3152 | if (err) |
| 3153 | goto unlock; |
| 3154 | } |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 3155 | |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 3156 | unlock: |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 3157 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | db687a5 | 2015-06-20 21:31:29 +0200 | [diff] [blame] | 3158 | |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 3159 | return err; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 3160 | } |
| 3161 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3162 | int mv88e6xxx_mdio_page_read(struct dsa_switch *ds, int port, int page, int reg) |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 3163 | { |
| 3164 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3165 | int ret; |
| 3166 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3167 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3168 | ret = _mv88e6xxx_mdio_page_read(ps, port, page, reg); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3169 | mutex_unlock(&ps->smi_mutex); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 3170 | |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 3171 | return ret; |
| 3172 | } |
| 3173 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3174 | int mv88e6xxx_mdio_page_write(struct dsa_switch *ds, int port, int page, |
| 3175 | int reg, int val) |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 3176 | { |
| 3177 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3178 | int ret; |
| 3179 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3180 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3181 | ret = _mv88e6xxx_mdio_page_write(ps, port, page, reg, val); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3182 | mutex_unlock(&ps->smi_mutex); |
Patrick Uiterwijk | 75baacf | 2016-03-30 01:39:40 +0000 | [diff] [blame] | 3183 | |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3184 | return ret; |
| 3185 | } |
| 3186 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3187 | static int mv88e6xxx_port_to_mdio_addr(struct mv88e6xxx_priv_state *ps, |
| 3188 | int port) |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3189 | { |
Vivien Didelot | 009a2b9 | 2016-04-17 13:24:01 -0400 | [diff] [blame] | 3190 | if (port >= 0 && port < ps->info->num_ports) |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3191 | return port; |
| 3192 | return -EINVAL; |
| 3193 | } |
| 3194 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3195 | static int mv88e6xxx_mdio_read(struct dsa_switch *ds, int port, int regnum) |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3196 | { |
| 3197 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3198 | int addr = mv88e6xxx_port_to_mdio_addr(ps, port); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3199 | int ret; |
| 3200 | |
| 3201 | if (addr < 0) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3202 | return 0xffff; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3203 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3204 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 3205 | |
| 3206 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_PPU)) |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3207 | ret = mv88e6xxx_mdio_read_ppu(ps, addr, regnum); |
Vivien Didelot | 6d5834a | 2016-05-09 13:22:40 -0400 | [diff] [blame] | 3208 | else if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_SMI_PHY)) |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3209 | ret = mv88e6xxx_mdio_read_indirect(ps, addr, regnum); |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 3210 | else |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3211 | ret = mv88e6xxx_mdio_read_direct(ps, addr, regnum); |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 3212 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3213 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3214 | return ret; |
| 3215 | } |
| 3216 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3217 | static int mv88e6xxx_mdio_write(struct dsa_switch *ds, int port, int regnum, |
| 3218 | u16 val) |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3219 | { |
| 3220 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3221 | int addr = mv88e6xxx_port_to_mdio_addr(ps, port); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3222 | int ret; |
| 3223 | |
| 3224 | if (addr < 0) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3225 | return 0xffff; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3226 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3227 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 3228 | |
| 3229 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_PPU)) |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3230 | ret = mv88e6xxx_mdio_write_ppu(ps, addr, regnum, val); |
Vivien Didelot | 6d5834a | 2016-05-09 13:22:40 -0400 | [diff] [blame] | 3231 | else if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_SMI_PHY)) |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3232 | ret = mv88e6xxx_mdio_write_indirect(ps, addr, regnum, val); |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 3233 | else |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3234 | ret = mv88e6xxx_mdio_write_direct(ps, addr, regnum, val); |
Vivien Didelot | 8c9983a | 2016-05-09 13:22:39 -0400 | [diff] [blame] | 3235 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 3236 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 3237 | return ret; |
| 3238 | } |
| 3239 | |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3240 | #ifdef CONFIG_NET_DSA_HWMON |
| 3241 | |
| 3242 | static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp) |
| 3243 | { |
| 3244 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3245 | int ret; |
| 3246 | int val; |
| 3247 | |
| 3248 | *temp = 0; |
| 3249 | |
| 3250 | mutex_lock(&ps->smi_mutex); |
| 3251 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3252 | ret = mv88e6xxx_mdio_write_direct(ps, 0x0, 0x16, 0x6); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3253 | if (ret < 0) |
| 3254 | goto error; |
| 3255 | |
| 3256 | /* Enable temperature sensor */ |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3257 | ret = mv88e6xxx_mdio_read_direct(ps, 0x0, 0x1a); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3258 | if (ret < 0) |
| 3259 | goto error; |
| 3260 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3261 | ret = mv88e6xxx_mdio_write_direct(ps, 0x0, 0x1a, ret | (1 << 5)); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3262 | if (ret < 0) |
| 3263 | goto error; |
| 3264 | |
| 3265 | /* Wait for temperature to stabilize */ |
| 3266 | usleep_range(10000, 12000); |
| 3267 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3268 | val = mv88e6xxx_mdio_read_direct(ps, 0x0, 0x1a); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3269 | if (val < 0) { |
| 3270 | ret = val; |
| 3271 | goto error; |
| 3272 | } |
| 3273 | |
| 3274 | /* Disable temperature sensor */ |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3275 | ret = mv88e6xxx_mdio_write_direct(ps, 0x0, 0x1a, ret & ~(1 << 5)); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3276 | if (ret < 0) |
| 3277 | goto error; |
| 3278 | |
| 3279 | *temp = ((val & 0x1f) - 5) * 5; |
| 3280 | |
| 3281 | error: |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3282 | mv88e6xxx_mdio_write_direct(ps, 0x0, 0x16, 0x0); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3283 | mutex_unlock(&ps->smi_mutex); |
| 3284 | return ret; |
| 3285 | } |
| 3286 | |
| 3287 | static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp) |
| 3288 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3289 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3290 | int phy = mv88e6xxx_6320_family(ps) ? 3 : 0; |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3291 | int ret; |
| 3292 | |
| 3293 | *temp = 0; |
| 3294 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3295 | ret = mv88e6xxx_mdio_page_read(ds, phy, 6, 27); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3296 | if (ret < 0) |
| 3297 | return ret; |
| 3298 | |
| 3299 | *temp = (ret & 0xff) - 25; |
| 3300 | |
| 3301 | return 0; |
| 3302 | } |
| 3303 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3304 | static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3305 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3306 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3307 | |
Vivien Didelot | 6594f61 | 2016-05-09 13:22:42 -0400 | [diff] [blame] | 3308 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_TEMP)) |
| 3309 | return -EOPNOTSUPP; |
| 3310 | |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3311 | if (mv88e6xxx_6320_family(ps) || mv88e6xxx_6352_family(ps)) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3312 | return mv88e63xx_get_temp(ds, temp); |
| 3313 | |
| 3314 | return mv88e61xx_get_temp(ds, temp); |
| 3315 | } |
| 3316 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3317 | static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3318 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3319 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3320 | int phy = mv88e6xxx_6320_family(ps) ? 3 : 0; |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3321 | int ret; |
| 3322 | |
Vivien Didelot | 6594f61 | 2016-05-09 13:22:42 -0400 | [diff] [blame] | 3323 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_TEMP_LIMIT)) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3324 | return -EOPNOTSUPP; |
| 3325 | |
| 3326 | *temp = 0; |
| 3327 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3328 | ret = mv88e6xxx_mdio_page_read(ds, phy, 6, 26); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3329 | if (ret < 0) |
| 3330 | return ret; |
| 3331 | |
| 3332 | *temp = (((ret >> 8) & 0x1f) * 5) - 25; |
| 3333 | |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3337 | static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3338 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3339 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3340 | int phy = mv88e6xxx_6320_family(ps) ? 3 : 0; |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3341 | int ret; |
| 3342 | |
Vivien Didelot | 6594f61 | 2016-05-09 13:22:42 -0400 | [diff] [blame] | 3343 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_TEMP_LIMIT)) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3344 | return -EOPNOTSUPP; |
| 3345 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3346 | ret = mv88e6xxx_mdio_page_read(ds, phy, 6, 26); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3347 | if (ret < 0) |
| 3348 | return ret; |
| 3349 | temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3350 | return mv88e6xxx_mdio_page_write(ds, phy, 6, 26, |
| 3351 | (ret & 0xe0ff) | (temp << 8)); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3354 | static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3355 | { |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 3356 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3357 | int phy = mv88e6xxx_6320_family(ps) ? 3 : 0; |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3358 | int ret; |
| 3359 | |
Vivien Didelot | 6594f61 | 2016-05-09 13:22:42 -0400 | [diff] [blame] | 3360 | if (!mv88e6xxx_has(ps, MV88E6XXX_FLAG_TEMP_LIMIT)) |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3361 | return -EOPNOTSUPP; |
| 3362 | |
| 3363 | *alarm = false; |
| 3364 | |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3365 | ret = mv88e6xxx_mdio_page_read(ds, phy, 6, 26); |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 3366 | if (ret < 0) |
| 3367 | return ret; |
| 3368 | |
| 3369 | *alarm = !!(ret & 0x40); |
| 3370 | |
| 3371 | return 0; |
| 3372 | } |
| 3373 | #endif /* CONFIG_NET_DSA_HWMON */ |
| 3374 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3375 | static const struct mv88e6xxx_info mv88e6xxx_table[] = { |
| 3376 | [MV88E6085] = { |
| 3377 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6085, |
| 3378 | .family = MV88E6XXX_FAMILY_6097, |
| 3379 | .name = "Marvell 88E6085", |
| 3380 | .num_databases = 4096, |
| 3381 | .num_ports = 10, |
| 3382 | .flags = MV88E6XXX_FLAGS_FAMILY_6097, |
| 3383 | }, |
| 3384 | |
| 3385 | [MV88E6095] = { |
| 3386 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6095, |
| 3387 | .family = MV88E6XXX_FAMILY_6095, |
| 3388 | .name = "Marvell 88E6095/88E6095F", |
| 3389 | .num_databases = 256, |
| 3390 | .num_ports = 11, |
| 3391 | .flags = MV88E6XXX_FLAGS_FAMILY_6095, |
| 3392 | }, |
| 3393 | |
| 3394 | [MV88E6123] = { |
| 3395 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6123, |
| 3396 | .family = MV88E6XXX_FAMILY_6165, |
| 3397 | .name = "Marvell 88E6123", |
| 3398 | .num_databases = 4096, |
| 3399 | .num_ports = 3, |
| 3400 | .flags = MV88E6XXX_FLAGS_FAMILY_6165, |
| 3401 | }, |
| 3402 | |
| 3403 | [MV88E6131] = { |
| 3404 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6131, |
| 3405 | .family = MV88E6XXX_FAMILY_6185, |
| 3406 | .name = "Marvell 88E6131", |
| 3407 | .num_databases = 256, |
| 3408 | .num_ports = 8, |
| 3409 | .flags = MV88E6XXX_FLAGS_FAMILY_6185, |
| 3410 | }, |
| 3411 | |
| 3412 | [MV88E6161] = { |
| 3413 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6161, |
| 3414 | .family = MV88E6XXX_FAMILY_6165, |
| 3415 | .name = "Marvell 88E6161", |
| 3416 | .num_databases = 4096, |
| 3417 | .num_ports = 6, |
| 3418 | .flags = MV88E6XXX_FLAGS_FAMILY_6165, |
| 3419 | }, |
| 3420 | |
| 3421 | [MV88E6165] = { |
| 3422 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6165, |
| 3423 | .family = MV88E6XXX_FAMILY_6165, |
| 3424 | .name = "Marvell 88E6165", |
| 3425 | .num_databases = 4096, |
| 3426 | .num_ports = 6, |
| 3427 | .flags = MV88E6XXX_FLAGS_FAMILY_6165, |
| 3428 | }, |
| 3429 | |
| 3430 | [MV88E6171] = { |
| 3431 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6171, |
| 3432 | .family = MV88E6XXX_FAMILY_6351, |
| 3433 | .name = "Marvell 88E6171", |
| 3434 | .num_databases = 4096, |
| 3435 | .num_ports = 7, |
| 3436 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
| 3437 | }, |
| 3438 | |
| 3439 | [MV88E6172] = { |
| 3440 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6172, |
| 3441 | .family = MV88E6XXX_FAMILY_6352, |
| 3442 | .name = "Marvell 88E6172", |
| 3443 | .num_databases = 4096, |
| 3444 | .num_ports = 7, |
| 3445 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
| 3446 | }, |
| 3447 | |
| 3448 | [MV88E6175] = { |
| 3449 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6175, |
| 3450 | .family = MV88E6XXX_FAMILY_6351, |
| 3451 | .name = "Marvell 88E6175", |
| 3452 | .num_databases = 4096, |
| 3453 | .num_ports = 7, |
| 3454 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
| 3455 | }, |
| 3456 | |
| 3457 | [MV88E6176] = { |
| 3458 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6176, |
| 3459 | .family = MV88E6XXX_FAMILY_6352, |
| 3460 | .name = "Marvell 88E6176", |
| 3461 | .num_databases = 4096, |
| 3462 | .num_ports = 7, |
| 3463 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
| 3464 | }, |
| 3465 | |
| 3466 | [MV88E6185] = { |
| 3467 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6185, |
| 3468 | .family = MV88E6XXX_FAMILY_6185, |
| 3469 | .name = "Marvell 88E6185", |
| 3470 | .num_databases = 256, |
| 3471 | .num_ports = 10, |
| 3472 | .flags = MV88E6XXX_FLAGS_FAMILY_6185, |
| 3473 | }, |
| 3474 | |
| 3475 | [MV88E6240] = { |
| 3476 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6240, |
| 3477 | .family = MV88E6XXX_FAMILY_6352, |
| 3478 | .name = "Marvell 88E6240", |
| 3479 | .num_databases = 4096, |
| 3480 | .num_ports = 7, |
| 3481 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
| 3482 | }, |
| 3483 | |
| 3484 | [MV88E6320] = { |
| 3485 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6320, |
| 3486 | .family = MV88E6XXX_FAMILY_6320, |
| 3487 | .name = "Marvell 88E6320", |
| 3488 | .num_databases = 4096, |
| 3489 | .num_ports = 7, |
| 3490 | .flags = MV88E6XXX_FLAGS_FAMILY_6320, |
| 3491 | }, |
| 3492 | |
| 3493 | [MV88E6321] = { |
| 3494 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6321, |
| 3495 | .family = MV88E6XXX_FAMILY_6320, |
| 3496 | .name = "Marvell 88E6321", |
| 3497 | .num_databases = 4096, |
| 3498 | .num_ports = 7, |
| 3499 | .flags = MV88E6XXX_FLAGS_FAMILY_6320, |
| 3500 | }, |
| 3501 | |
| 3502 | [MV88E6350] = { |
| 3503 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6350, |
| 3504 | .family = MV88E6XXX_FAMILY_6351, |
| 3505 | .name = "Marvell 88E6350", |
| 3506 | .num_databases = 4096, |
| 3507 | .num_ports = 7, |
| 3508 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
| 3509 | }, |
| 3510 | |
| 3511 | [MV88E6351] = { |
| 3512 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6351, |
| 3513 | .family = MV88E6XXX_FAMILY_6351, |
| 3514 | .name = "Marvell 88E6351", |
| 3515 | .num_databases = 4096, |
| 3516 | .num_ports = 7, |
| 3517 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
| 3518 | }, |
| 3519 | |
| 3520 | [MV88E6352] = { |
| 3521 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6352, |
| 3522 | .family = MV88E6XXX_FAMILY_6352, |
| 3523 | .name = "Marvell 88E6352", |
| 3524 | .num_databases = 4096, |
| 3525 | .num_ports = 7, |
| 3526 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
| 3527 | }, |
| 3528 | }; |
| 3529 | |
Vivien Didelot | f6271e6 | 2016-04-17 13:23:59 -0400 | [diff] [blame] | 3530 | static const struct mv88e6xxx_info * |
| 3531 | mv88e6xxx_lookup_info(unsigned int prod_num, const struct mv88e6xxx_info *table, |
Vivien Didelot | 0209d14 | 2016-04-17 13:23:55 -0400 | [diff] [blame] | 3532 | unsigned int num) |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 3533 | { |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3534 | int i; |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 3535 | |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 3536 | for (i = 0; i < num; ++i) |
Vivien Didelot | f6271e6 | 2016-04-17 13:23:59 -0400 | [diff] [blame] | 3537 | if (table[i].prod_num == prod_num) |
| 3538 | return &table[i]; |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 3539 | |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 3540 | return NULL; |
| 3541 | } |
| 3542 | |
Andrew Lunn | fcdce7d | 2016-05-10 23:27:20 +0200 | [diff] [blame] | 3543 | static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, |
| 3544 | struct device *host_dev, int sw_addr, |
| 3545 | void **priv) |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 3546 | { |
Vivien Didelot | f6271e6 | 2016-04-17 13:23:59 -0400 | [diff] [blame] | 3547 | const struct mv88e6xxx_info *info; |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 3548 | struct mv88e6xxx_priv_state *ps; |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3549 | struct mii_bus *bus; |
Vivien Didelot | 0209d14 | 2016-04-17 13:23:55 -0400 | [diff] [blame] | 3550 | const char *name; |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3551 | int id, prod_num, rev; |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 3552 | |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3553 | bus = dsa_host_dev_to_mii_bus(host_dev); |
Andrew Lunn | c156913 | 2016-04-13 02:40:45 +0200 | [diff] [blame] | 3554 | if (!bus) |
| 3555 | return NULL; |
| 3556 | |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3557 | id = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID); |
| 3558 | if (id < 0) |
| 3559 | return NULL; |
| 3560 | |
| 3561 | prod_num = (id & 0xfff0) >> 4; |
| 3562 | rev = id & 0x000f; |
| 3563 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3564 | info = mv88e6xxx_lookup_info(prod_num, mv88e6xxx_table, |
| 3565 | ARRAY_SIZE(mv88e6xxx_table)); |
Vivien Didelot | f6271e6 | 2016-04-17 13:23:59 -0400 | [diff] [blame] | 3566 | if (!info) |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3567 | return NULL; |
| 3568 | |
Vivien Didelot | f6271e6 | 2016-04-17 13:23:59 -0400 | [diff] [blame] | 3569 | name = info->name; |
| 3570 | |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3571 | ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL); |
| 3572 | if (!ps) |
| 3573 | return NULL; |
| 3574 | |
| 3575 | ps->bus = bus; |
| 3576 | ps->sw_addr = sw_addr; |
Vivien Didelot | f6271e6 | 2016-04-17 13:23:59 -0400 | [diff] [blame] | 3577 | ps->info = info; |
Andrew Lunn | b681957 | 2016-05-10 23:27:19 +0200 | [diff] [blame] | 3578 | mutex_init(&ps->smi_mutex); |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 3579 | |
| 3580 | *priv = ps; |
| 3581 | |
| 3582 | dev_info(&ps->bus->dev, "switch 0x%x probed: %s, revision %u\n", |
| 3583 | prod_num, name, rev); |
| 3584 | |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 3585 | return name; |
| 3586 | } |
| 3587 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3588 | struct dsa_switch_driver mv88e6xxx_switch_driver = { |
| 3589 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Andrew Lunn | fcdce7d | 2016-05-10 23:27:20 +0200 | [diff] [blame] | 3590 | .probe = mv88e6xxx_drv_probe, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3591 | .setup = mv88e6xxx_setup, |
| 3592 | .set_addr = mv88e6xxx_set_addr, |
Andrew Lunn | 03a4a54 | 2016-06-04 21:17:05 +0200 | [diff] [blame^] | 3593 | .phy_read = mv88e6xxx_mdio_read, |
| 3594 | .phy_write = mv88e6xxx_mdio_write, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3595 | .adjust_link = mv88e6xxx_adjust_link, |
| 3596 | .get_strings = mv88e6xxx_get_strings, |
| 3597 | .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, |
| 3598 | .get_sset_count = mv88e6xxx_get_sset_count, |
| 3599 | .set_eee = mv88e6xxx_set_eee, |
| 3600 | .get_eee = mv88e6xxx_get_eee, |
| 3601 | #ifdef CONFIG_NET_DSA_HWMON |
| 3602 | .get_temp = mv88e6xxx_get_temp, |
| 3603 | .get_temp_limit = mv88e6xxx_get_temp_limit, |
| 3604 | .set_temp_limit = mv88e6xxx_set_temp_limit, |
| 3605 | .get_temp_alarm = mv88e6xxx_get_temp_alarm, |
| 3606 | #endif |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 3607 | .get_eeprom_len = mv88e6xxx_get_eeprom_len, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3608 | .get_eeprom = mv88e6xxx_get_eeprom, |
| 3609 | .set_eeprom = mv88e6xxx_set_eeprom, |
| 3610 | .get_regs_len = mv88e6xxx_get_regs_len, |
| 3611 | .get_regs = mv88e6xxx_get_regs, |
| 3612 | .port_bridge_join = mv88e6xxx_port_bridge_join, |
| 3613 | .port_bridge_leave = mv88e6xxx_port_bridge_leave, |
| 3614 | .port_stp_state_set = mv88e6xxx_port_stp_state_set, |
| 3615 | .port_vlan_filtering = mv88e6xxx_port_vlan_filtering, |
| 3616 | .port_vlan_prepare = mv88e6xxx_port_vlan_prepare, |
| 3617 | .port_vlan_add = mv88e6xxx_port_vlan_add, |
| 3618 | .port_vlan_del = mv88e6xxx_port_vlan_del, |
| 3619 | .port_vlan_dump = mv88e6xxx_port_vlan_dump, |
| 3620 | .port_fdb_prepare = mv88e6xxx_port_fdb_prepare, |
| 3621 | .port_fdb_add = mv88e6xxx_port_fdb_add, |
| 3622 | .port_fdb_del = mv88e6xxx_port_fdb_del, |
| 3623 | .port_fdb_dump = mv88e6xxx_port_fdb_dump, |
| 3624 | }; |
| 3625 | |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 3626 | int mv88e6xxx_probe(struct mdio_device *mdiodev) |
| 3627 | { |
| 3628 | struct device *dev = &mdiodev->dev; |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 3629 | struct device_node *np = dev->of_node; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 3630 | struct mv88e6xxx_priv_state *ps; |
| 3631 | int id, prod_num, rev; |
| 3632 | struct dsa_switch *ds; |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 3633 | u32 eeprom_len; |
Andrew Lunn | 52638f7 | 2016-05-10 23:27:22 +0200 | [diff] [blame] | 3634 | int err; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 3635 | |
| 3636 | ds = devm_kzalloc(dev, sizeof(*ds) + sizeof(*ps), GFP_KERNEL); |
| 3637 | if (!ds) |
| 3638 | return -ENOMEM; |
| 3639 | |
| 3640 | ps = (struct mv88e6xxx_priv_state *)(ds + 1); |
| 3641 | ds->priv = ps; |
Andrew Lunn | c33063d | 2016-05-10 23:27:23 +0200 | [diff] [blame] | 3642 | ds->dev = dev; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 3643 | ps->dev = dev; |
| 3644 | ps->ds = ds; |
| 3645 | ps->bus = mdiodev->bus; |
| 3646 | ps->sw_addr = mdiodev->addr; |
| 3647 | mutex_init(&ps->smi_mutex); |
| 3648 | |
| 3649 | get_device(&ps->bus->dev); |
| 3650 | |
| 3651 | ds->drv = &mv88e6xxx_switch_driver; |
| 3652 | |
| 3653 | id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); |
| 3654 | if (id < 0) |
| 3655 | return id; |
| 3656 | |
| 3657 | prod_num = (id & 0xfff0) >> 4; |
| 3658 | rev = id & 0x000f; |
| 3659 | |
| 3660 | ps->info = mv88e6xxx_lookup_info(prod_num, mv88e6xxx_table, |
| 3661 | ARRAY_SIZE(mv88e6xxx_table)); |
| 3662 | if (!ps->info) |
| 3663 | return -ENODEV; |
| 3664 | |
Andrew Lunn | 52638f7 | 2016-05-10 23:27:22 +0200 | [diff] [blame] | 3665 | ps->reset = devm_gpiod_get(&mdiodev->dev, "reset", GPIOD_ASIS); |
| 3666 | if (IS_ERR(ps->reset)) { |
| 3667 | err = PTR_ERR(ps->reset); |
| 3668 | if (err == -ENOENT) { |
| 3669 | /* Optional, so not an error */ |
| 3670 | ps->reset = NULL; |
| 3671 | } else { |
| 3672 | return err; |
| 3673 | } |
| 3674 | } |
| 3675 | |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 3676 | if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_EEPROM) && |
| 3677 | !of_property_read_u32(np, "eeprom-length", &eeprom_len)) |
| 3678 | ps->eeprom_len = eeprom_len; |
| 3679 | |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 3680 | dev_set_drvdata(dev, ds); |
| 3681 | |
| 3682 | dev_info(dev, "switch 0x%x probed: %s, revision %u\n", |
| 3683 | prod_num, ps->info->name, rev); |
| 3684 | |
| 3685 | return 0; |
| 3686 | } |
| 3687 | |
| 3688 | static void mv88e6xxx_remove(struct mdio_device *mdiodev) |
| 3689 | { |
| 3690 | struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); |
| 3691 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 3692 | |
| 3693 | put_device(&ps->bus->dev); |
| 3694 | } |
| 3695 | |
| 3696 | static const struct of_device_id mv88e6xxx_of_match[] = { |
| 3697 | { .compatible = "marvell,mv88e6085" }, |
| 3698 | { /* sentinel */ }, |
| 3699 | }; |
| 3700 | |
| 3701 | MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match); |
| 3702 | |
| 3703 | static struct mdio_driver mv88e6xxx_driver = { |
| 3704 | .probe = mv88e6xxx_probe, |
| 3705 | .remove = mv88e6xxx_remove, |
| 3706 | .mdiodrv.driver = { |
| 3707 | .name = "mv88e6085", |
| 3708 | .of_match_table = mv88e6xxx_of_match, |
| 3709 | }, |
| 3710 | }; |
| 3711 | |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 3712 | static int __init mv88e6xxx_init(void) |
| 3713 | { |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3714 | register_switch_driver(&mv88e6xxx_switch_driver); |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 3715 | return mdio_driver_register(&mv88e6xxx_driver); |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 3716 | } |
| 3717 | module_init(mv88e6xxx_init); |
| 3718 | |
| 3719 | static void __exit mv88e6xxx_cleanup(void) |
| 3720 | { |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 3721 | mdio_driver_unregister(&mv88e6xxx_driver); |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3722 | unregister_switch_driver(&mv88e6xxx_switch_driver); |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 3723 | } |
| 3724 | module_exit(mv88e6xxx_cleanup); |
Ben Hutchings | 3d825ed | 2011-11-25 14:37:16 +0000 | [diff] [blame] | 3725 | |
| 3726 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>"); |
| 3727 | MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips"); |
| 3728 | MODULE_LICENSE("GPL"); |