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 | * |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 14 | #include <linux/debugfs.h> |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 15 | #include <linux/delay.h> |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 16 | #include <linux/etherdevice.h> |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 17 | #include <linux/ethtool.h> |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 18 | #include <linux/if_bridge.h> |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 19 | #include <linux/jiffies.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 20 | #include <linux/list.h> |
Paul Gortmaker | 2bbba27 | 2012-01-24 10:41:40 +0000 | [diff] [blame] | 21 | #include <linux/module.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/phy.h> |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 24 | #include <linux/seq_file.h> |
Ben Hutchings | c8f0b86 | 2011-11-27 17:06:08 +0000 | [diff] [blame] | 25 | #include <net/dsa.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 26 | #include "mv88e6xxx.h" |
| 27 | |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 28 | /* MDIO bus access can be nested in the case of PHYs connected to the |
| 29 | * internal MDIO bus of the switch, which is accessed via MDIO bus of |
| 30 | * the Ethernet interface. Avoid lockdep false positives by using |
| 31 | * mutex_lock_nested(). |
| 32 | */ |
| 33 | static int mv88e6xxx_mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) |
| 34 | { |
| 35 | int ret; |
| 36 | |
| 37 | mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING); |
| 38 | ret = bus->read(bus, addr, regnum); |
| 39 | mutex_unlock(&bus->mdio_lock); |
| 40 | |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static int mv88e6xxx_mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, |
| 45 | u16 val) |
| 46 | { |
| 47 | int ret; |
| 48 | |
| 49 | mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING); |
| 50 | ret = bus->write(bus, addr, regnum, val); |
| 51 | mutex_unlock(&bus->mdio_lock); |
| 52 | |
| 53 | return ret; |
| 54 | } |
| 55 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 56 | /* 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] | 57 | * use all 32 SMI bus addresses on its SMI bus, and all switch registers |
| 58 | * will be directly accessible on some {device address,register address} |
| 59 | * pair. If the ADDR[4:0] pins are not strapped to zero, the switch |
| 60 | * will only respond to SMI transactions to that specific address, and |
| 61 | * an indirect addressing mechanism needs to be used to access its |
| 62 | * registers. |
| 63 | */ |
| 64 | static int mv88e6xxx_reg_wait_ready(struct mii_bus *bus, int sw_addr) |
| 65 | { |
| 66 | int ret; |
| 67 | int i; |
| 68 | |
| 69 | for (i = 0; i < 16; i++) { |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 70 | ret = mv88e6xxx_mdiobus_read(bus, sw_addr, SMI_CMD); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 71 | if (ret < 0) |
| 72 | return ret; |
| 73 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 74 | if ((ret & SMI_CMD_BUSY) == 0) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | return -ETIMEDOUT; |
| 79 | } |
| 80 | |
| 81 | int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg) |
| 82 | { |
| 83 | int ret; |
| 84 | |
| 85 | if (sw_addr == 0) |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 86 | return mv88e6xxx_mdiobus_read(bus, addr, reg); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 87 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 88 | /* Wait for the bus to become free. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 89 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 90 | if (ret < 0) |
| 91 | return ret; |
| 92 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 93 | /* Transmit the read command. */ |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 94 | ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_CMD, |
| 95 | SMI_CMD_OP_22_READ | (addr << 5) | reg); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 96 | if (ret < 0) |
| 97 | return ret; |
| 98 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 99 | /* Wait for the read command to complete. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 100 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 101 | if (ret < 0) |
| 102 | return ret; |
| 103 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 104 | /* Read the data. */ |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 105 | ret = mv88e6xxx_mdiobus_read(bus, sw_addr, SMI_DATA); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 106 | if (ret < 0) |
| 107 | return ret; |
| 108 | |
| 109 | return ret & 0xffff; |
| 110 | } |
| 111 | |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 112 | /* Must be called with SMI mutex held */ |
| 113 | static int _mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 114 | { |
Guenter Roeck | b184e49 | 2014-10-17 12:30:58 -0700 | [diff] [blame] | 115 | struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 116 | int ret; |
| 117 | |
Guenter Roeck | b184e49 | 2014-10-17 12:30:58 -0700 | [diff] [blame] | 118 | if (bus == NULL) |
| 119 | return -EINVAL; |
| 120 | |
Guenter Roeck | b184e49 | 2014-10-17 12:30:58 -0700 | [diff] [blame] | 121 | ret = __mv88e6xxx_reg_read(bus, ds->pd->sw_addr, addr, reg); |
Vivien Didelot | bb92ea5 | 2015-01-23 16:10:36 -0500 | [diff] [blame] | 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | |
| 125 | dev_dbg(ds->master_dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n", |
| 126 | addr, reg, ret); |
| 127 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 128 | return ret; |
| 129 | } |
| 130 | |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 131 | int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg) |
| 132 | { |
| 133 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 134 | int ret; |
| 135 | |
| 136 | mutex_lock(&ps->smi_mutex); |
| 137 | ret = _mv88e6xxx_reg_read(ds, addr, reg); |
| 138 | mutex_unlock(&ps->smi_mutex); |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 143 | int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr, |
| 144 | int reg, u16 val) |
| 145 | { |
| 146 | int ret; |
| 147 | |
| 148 | if (sw_addr == 0) |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 149 | return mv88e6xxx_mdiobus_write(bus, addr, reg, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 150 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 151 | /* Wait for the bus to become free. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 152 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 153 | if (ret < 0) |
| 154 | return ret; |
| 155 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 156 | /* Transmit the data to write. */ |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 157 | ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_DATA, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 158 | if (ret < 0) |
| 159 | return ret; |
| 160 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 161 | /* Transmit the write command. */ |
Andrew Lunn | 16fe24f | 2015-05-06 01:09:55 +0200 | [diff] [blame] | 162 | ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_CMD, |
| 163 | SMI_CMD_OP_22_WRITE | (addr << 5) | reg); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 164 | if (ret < 0) |
| 165 | return ret; |
| 166 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 167 | /* Wait for the write command to complete. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 168 | ret = mv88e6xxx_reg_wait_ready(bus, sw_addr); |
| 169 | if (ret < 0) |
| 170 | return ret; |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 175 | /* Must be called with SMI mutex held */ |
| 176 | static int _mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, |
| 177 | u16 val) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 178 | { |
Guenter Roeck | b184e49 | 2014-10-17 12:30:58 -0700 | [diff] [blame] | 179 | struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 180 | |
Guenter Roeck | b184e49 | 2014-10-17 12:30:58 -0700 | [diff] [blame] | 181 | if (bus == NULL) |
| 182 | return -EINVAL; |
| 183 | |
Vivien Didelot | bb92ea5 | 2015-01-23 16:10:36 -0500 | [diff] [blame] | 184 | dev_dbg(ds->master_dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n", |
| 185 | addr, reg, val); |
| 186 | |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 187 | return __mv88e6xxx_reg_write(bus, ds->pd->sw_addr, addr, reg, val); |
| 188 | } |
| 189 | |
| 190 | int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val) |
| 191 | { |
| 192 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 193 | int ret; |
| 194 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 195 | mutex_lock(&ps->smi_mutex); |
Guenter Roeck | 8d6d09e | 2015-03-26 18:36:31 -0700 | [diff] [blame] | 196 | ret = _mv88e6xxx_reg_write(ds, addr, reg, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 197 | mutex_unlock(&ps->smi_mutex); |
| 198 | |
| 199 | return ret; |
| 200 | } |
| 201 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 202 | int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr) |
| 203 | { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 204 | REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]); |
| 205 | REG_WRITE(REG_GLOBAL, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]); |
| 206 | REG_WRITE(REG_GLOBAL, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 211 | int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr) |
| 212 | { |
| 213 | int i; |
| 214 | int ret; |
| 215 | |
| 216 | for (i = 0; i < 6; i++) { |
| 217 | int j; |
| 218 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 219 | /* Write the MAC address byte. */ |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 220 | REG_WRITE(REG_GLOBAL2, GLOBAL2_SWITCH_MAC, |
| 221 | GLOBAL2_SWITCH_MAC_BUSY | (i << 8) | addr[i]); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 222 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 223 | /* Wait for the write to complete. */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 224 | for (j = 0; j < 16; j++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 225 | ret = REG_READ(REG_GLOBAL2, GLOBAL2_SWITCH_MAC); |
| 226 | if ((ret & GLOBAL2_SWITCH_MAC_BUSY) == 0) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 227 | break; |
| 228 | } |
| 229 | if (j == 16) |
| 230 | return -ETIMEDOUT; |
| 231 | } |
| 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 236 | /* Must be called with SMI mutex held */ |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 237 | static int _mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 238 | { |
| 239 | if (addr >= 0) |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 240 | return _mv88e6xxx_reg_read(ds, addr, regnum); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 241 | return 0xffff; |
| 242 | } |
| 243 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 244 | /* Must be called with SMI mutex held */ |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 245 | static int _mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum, |
| 246 | u16 val) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 247 | { |
| 248 | if (addr >= 0) |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 249 | return _mv88e6xxx_reg_write(ds, addr, regnum, val); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 253 | #ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU |
| 254 | static int mv88e6xxx_ppu_disable(struct dsa_switch *ds) |
| 255 | { |
| 256 | int ret; |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 257 | unsigned long timeout; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 258 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 259 | ret = REG_READ(REG_GLOBAL, GLOBAL_CONTROL); |
| 260 | REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, |
| 261 | ret & ~GLOBAL_CONTROL_PPU_ENABLE); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 262 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 263 | timeout = jiffies + 1 * HZ; |
| 264 | while (time_before(jiffies, timeout)) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 265 | ret = REG_READ(REG_GLOBAL, GLOBAL_STATUS); |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 266 | usleep_range(1000, 2000); |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 267 | if ((ret & GLOBAL_STATUS_PPU_MASK) != |
| 268 | GLOBAL_STATUS_PPU_POLLING) |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 269 | return 0; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | return -ETIMEDOUT; |
| 273 | } |
| 274 | |
| 275 | static int mv88e6xxx_ppu_enable(struct dsa_switch *ds) |
| 276 | { |
| 277 | int ret; |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 278 | unsigned long timeout; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 279 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 280 | ret = REG_READ(REG_GLOBAL, GLOBAL_CONTROL); |
| 281 | REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, ret | GLOBAL_CONTROL_PPU_ENABLE); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 282 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 283 | timeout = jiffies + 1 * HZ; |
| 284 | while (time_before(jiffies, timeout)) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 285 | ret = REG_READ(REG_GLOBAL, GLOBAL_STATUS); |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 286 | usleep_range(1000, 2000); |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 287 | if ((ret & GLOBAL_STATUS_PPU_MASK) == |
| 288 | GLOBAL_STATUS_PPU_POLLING) |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 289 | return 0; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | return -ETIMEDOUT; |
| 293 | } |
| 294 | |
| 295 | static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly) |
| 296 | { |
| 297 | struct mv88e6xxx_priv_state *ps; |
| 298 | |
| 299 | ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work); |
| 300 | if (mutex_trylock(&ps->ppu_mutex)) { |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 301 | struct dsa_switch *ds = ((struct dsa_switch *)ps) - 1; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 302 | |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 303 | if (mv88e6xxx_ppu_enable(ds) == 0) |
| 304 | ps->ppu_disabled = 0; |
| 305 | mutex_unlock(&ps->ppu_mutex); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
| 309 | static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps) |
| 310 | { |
| 311 | struct mv88e6xxx_priv_state *ps = (void *)_ps; |
| 312 | |
| 313 | schedule_work(&ps->ppu_work); |
| 314 | } |
| 315 | |
| 316 | static int mv88e6xxx_ppu_access_get(struct dsa_switch *ds) |
| 317 | { |
Florian Fainelli | a22adce | 2014-04-28 11:14:28 -0700 | [diff] [blame] | 318 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 319 | int ret; |
| 320 | |
| 321 | mutex_lock(&ps->ppu_mutex); |
| 322 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 323 | /* If the PHY polling unit is enabled, disable it so that |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 324 | * we can access the PHY registers. If it was already |
| 325 | * disabled, cancel the timer that is going to re-enable |
| 326 | * it. |
| 327 | */ |
| 328 | if (!ps->ppu_disabled) { |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 329 | ret = mv88e6xxx_ppu_disable(ds); |
| 330 | if (ret < 0) { |
| 331 | mutex_unlock(&ps->ppu_mutex); |
| 332 | return ret; |
| 333 | } |
| 334 | ps->ppu_disabled = 1; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 335 | } else { |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 336 | del_timer(&ps->ppu_timer); |
| 337 | ret = 0; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | return ret; |
| 341 | } |
| 342 | |
| 343 | static void mv88e6xxx_ppu_access_put(struct dsa_switch *ds) |
| 344 | { |
Florian Fainelli | a22adce | 2014-04-28 11:14:28 -0700 | [diff] [blame] | 345 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 346 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 347 | /* Schedule a timer to re-enable the PHY polling unit. */ |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 348 | mod_timer(&ps->ppu_timer, jiffies + msecs_to_jiffies(10)); |
| 349 | mutex_unlock(&ps->ppu_mutex); |
| 350 | } |
| 351 | |
| 352 | void mv88e6xxx_ppu_state_init(struct dsa_switch *ds) |
| 353 | { |
Florian Fainelli | a22adce | 2014-04-28 11:14:28 -0700 | [diff] [blame] | 354 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 355 | |
| 356 | mutex_init(&ps->ppu_mutex); |
| 357 | INIT_WORK(&ps->ppu_work, mv88e6xxx_ppu_reenable_work); |
| 358 | init_timer(&ps->ppu_timer); |
| 359 | ps->ppu_timer.data = (unsigned long)ps; |
| 360 | ps->ppu_timer.function = mv88e6xxx_ppu_reenable_timer; |
| 361 | } |
| 362 | |
| 363 | int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum) |
| 364 | { |
| 365 | int ret; |
| 366 | |
| 367 | ret = mv88e6xxx_ppu_access_get(ds); |
| 368 | if (ret >= 0) { |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 369 | ret = mv88e6xxx_reg_read(ds, addr, regnum); |
| 370 | mv88e6xxx_ppu_access_put(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | return ret; |
| 374 | } |
| 375 | |
| 376 | int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr, |
| 377 | int regnum, u16 val) |
| 378 | { |
| 379 | int ret; |
| 380 | |
| 381 | ret = mv88e6xxx_ppu_access_get(ds); |
| 382 | if (ret >= 0) { |
Barry Grussling | 8568658 | 2013-01-08 16:05:56 +0000 | [diff] [blame] | 383 | ret = mv88e6xxx_reg_write(ds, addr, regnum, val); |
| 384 | mv88e6xxx_ppu_access_put(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | return ret; |
| 388 | } |
| 389 | #endif |
| 390 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 391 | void mv88e6xxx_poll_link(struct dsa_switch *ds) |
| 392 | { |
| 393 | int i; |
| 394 | |
| 395 | for (i = 0; i < DSA_MAX_PORTS; i++) { |
| 396 | struct net_device *dev; |
Ingo Molnar | 2a9e797 | 2008-11-25 16:50:49 -0800 | [diff] [blame] | 397 | int uninitialized_var(port_status); |
Andrew Lunn | 8b59d19 | 2015-08-31 15:56:52 +0200 | [diff] [blame] | 398 | int pcs_ctrl; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 399 | int link; |
| 400 | int speed; |
| 401 | int duplex; |
| 402 | int fc; |
| 403 | |
| 404 | dev = ds->ports[i]; |
| 405 | if (dev == NULL) |
| 406 | continue; |
| 407 | |
Andrew Lunn | 8b59d19 | 2015-08-31 15:56:52 +0200 | [diff] [blame] | 408 | pcs_ctrl = mv88e6xxx_reg_read(ds, REG_PORT(i), PORT_PCS_CTRL); |
| 409 | if (pcs_ctrl < 0 || pcs_ctrl & PORT_PCS_CTRL_FORCE_LINK) |
| 410 | continue; |
| 411 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 412 | link = 0; |
| 413 | if (dev->flags & IFF_UP) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 414 | port_status = mv88e6xxx_reg_read(ds, REG_PORT(i), |
| 415 | PORT_STATUS); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 416 | if (port_status < 0) |
| 417 | continue; |
| 418 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 419 | link = !!(port_status & PORT_STATUS_LINK); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | if (!link) { |
| 423 | if (netif_carrier_ok(dev)) { |
Barry Grussling | ab381a9 | 2013-01-08 16:05:55 +0000 | [diff] [blame] | 424 | netdev_info(dev, "link down\n"); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 425 | netif_carrier_off(dev); |
| 426 | } |
| 427 | continue; |
| 428 | } |
| 429 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 430 | switch (port_status & PORT_STATUS_SPEED_MASK) { |
| 431 | case PORT_STATUS_SPEED_10: |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 432 | speed = 10; |
| 433 | break; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 434 | case PORT_STATUS_SPEED_100: |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 435 | speed = 100; |
| 436 | break; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 437 | case PORT_STATUS_SPEED_1000: |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 438 | speed = 1000; |
| 439 | break; |
| 440 | default: |
| 441 | speed = -1; |
| 442 | break; |
| 443 | } |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 444 | duplex = (port_status & PORT_STATUS_DUPLEX) ? 1 : 0; |
| 445 | fc = (port_status & PORT_STATUS_PAUSE_EN) ? 1 : 0; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 446 | |
| 447 | if (!netif_carrier_ok(dev)) { |
Barry Grussling | ab381a9 | 2013-01-08 16:05:55 +0000 | [diff] [blame] | 448 | netdev_info(dev, |
| 449 | "link up, %d Mb/s, %s duplex, flow control %sabled\n", |
| 450 | speed, |
| 451 | duplex ? "full" : "half", |
| 452 | fc ? "en" : "dis"); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 453 | netif_carrier_on(dev); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 458 | static bool mv88e6xxx_6065_family(struct dsa_switch *ds) |
| 459 | { |
| 460 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 461 | |
| 462 | switch (ps->id) { |
| 463 | case PORT_SWITCH_ID_6031: |
| 464 | case PORT_SWITCH_ID_6061: |
| 465 | case PORT_SWITCH_ID_6035: |
| 466 | case PORT_SWITCH_ID_6065: |
| 467 | return true; |
| 468 | } |
| 469 | return false; |
| 470 | } |
| 471 | |
| 472 | static bool mv88e6xxx_6095_family(struct dsa_switch *ds) |
| 473 | { |
| 474 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 475 | |
| 476 | switch (ps->id) { |
| 477 | case PORT_SWITCH_ID_6092: |
| 478 | case PORT_SWITCH_ID_6095: |
| 479 | return true; |
| 480 | } |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | static bool mv88e6xxx_6097_family(struct dsa_switch *ds) |
| 485 | { |
| 486 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 487 | |
| 488 | switch (ps->id) { |
| 489 | case PORT_SWITCH_ID_6046: |
| 490 | case PORT_SWITCH_ID_6085: |
| 491 | case PORT_SWITCH_ID_6096: |
| 492 | case PORT_SWITCH_ID_6097: |
| 493 | return true; |
| 494 | } |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | static bool mv88e6xxx_6165_family(struct dsa_switch *ds) |
| 499 | { |
| 500 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 501 | |
| 502 | switch (ps->id) { |
| 503 | case PORT_SWITCH_ID_6123: |
| 504 | case PORT_SWITCH_ID_6161: |
| 505 | case PORT_SWITCH_ID_6165: |
| 506 | return true; |
| 507 | } |
| 508 | return false; |
| 509 | } |
| 510 | |
| 511 | static bool mv88e6xxx_6185_family(struct dsa_switch *ds) |
| 512 | { |
| 513 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 514 | |
| 515 | switch (ps->id) { |
| 516 | case PORT_SWITCH_ID_6121: |
| 517 | case PORT_SWITCH_ID_6122: |
| 518 | case PORT_SWITCH_ID_6152: |
| 519 | case PORT_SWITCH_ID_6155: |
| 520 | case PORT_SWITCH_ID_6182: |
| 521 | case PORT_SWITCH_ID_6185: |
| 522 | case PORT_SWITCH_ID_6108: |
| 523 | case PORT_SWITCH_ID_6131: |
| 524 | return true; |
| 525 | } |
| 526 | return false; |
| 527 | } |
| 528 | |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 529 | static bool mv88e6xxx_6320_family(struct dsa_switch *ds) |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 530 | { |
| 531 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 532 | |
| 533 | switch (ps->id) { |
| 534 | case PORT_SWITCH_ID_6320: |
| 535 | case PORT_SWITCH_ID_6321: |
| 536 | return true; |
| 537 | } |
| 538 | return false; |
| 539 | } |
| 540 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 541 | static bool mv88e6xxx_6351_family(struct dsa_switch *ds) |
| 542 | { |
| 543 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 544 | |
| 545 | switch (ps->id) { |
| 546 | case PORT_SWITCH_ID_6171: |
| 547 | case PORT_SWITCH_ID_6175: |
| 548 | case PORT_SWITCH_ID_6350: |
| 549 | case PORT_SWITCH_ID_6351: |
| 550 | return true; |
| 551 | } |
| 552 | return false; |
| 553 | } |
| 554 | |
Andrew Lunn | f3a8b6b | 2015-04-02 04:06:40 +0200 | [diff] [blame] | 555 | static bool mv88e6xxx_6352_family(struct dsa_switch *ds) |
| 556 | { |
| 557 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 558 | |
| 559 | switch (ps->id) { |
Andrew Lunn | f3a8b6b | 2015-04-02 04:06:40 +0200 | [diff] [blame] | 560 | case PORT_SWITCH_ID_6172: |
| 561 | case PORT_SWITCH_ID_6176: |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 562 | case PORT_SWITCH_ID_6240: |
| 563 | case PORT_SWITCH_ID_6352: |
Andrew Lunn | f3a8b6b | 2015-04-02 04:06:40 +0200 | [diff] [blame] | 564 | return true; |
| 565 | } |
| 566 | return false; |
| 567 | } |
| 568 | |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 569 | /* We expect the switch to perform auto negotiation if there is a real |
| 570 | * phy. However, in the case of a fixed link phy, we force the port |
| 571 | * settings from the fixed link settings. |
| 572 | */ |
| 573 | void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port, |
| 574 | struct phy_device *phydev) |
| 575 | { |
| 576 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 577 | u32 ret, reg; |
| 578 | |
| 579 | if (!phy_is_pseudo_fixed_link(phydev)) |
| 580 | return; |
| 581 | |
| 582 | mutex_lock(&ps->smi_mutex); |
| 583 | |
| 584 | ret = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_PCS_CTRL); |
| 585 | if (ret < 0) |
| 586 | goto out; |
| 587 | |
| 588 | reg = ret & ~(PORT_PCS_CTRL_LINK_UP | |
| 589 | PORT_PCS_CTRL_FORCE_LINK | |
| 590 | PORT_PCS_CTRL_DUPLEX_FULL | |
| 591 | PORT_PCS_CTRL_FORCE_DUPLEX | |
| 592 | PORT_PCS_CTRL_UNFORCED); |
| 593 | |
| 594 | reg |= PORT_PCS_CTRL_FORCE_LINK; |
| 595 | if (phydev->link) |
| 596 | reg |= PORT_PCS_CTRL_LINK_UP; |
| 597 | |
| 598 | if (mv88e6xxx_6065_family(ds) && phydev->speed > SPEED_100) |
| 599 | goto out; |
| 600 | |
| 601 | switch (phydev->speed) { |
| 602 | case SPEED_1000: |
| 603 | reg |= PORT_PCS_CTRL_1000; |
| 604 | break; |
| 605 | case SPEED_100: |
| 606 | reg |= PORT_PCS_CTRL_100; |
| 607 | break; |
| 608 | case SPEED_10: |
| 609 | reg |= PORT_PCS_CTRL_10; |
| 610 | break; |
| 611 | default: |
| 612 | pr_info("Unknown speed"); |
| 613 | goto out; |
| 614 | } |
| 615 | |
| 616 | reg |= PORT_PCS_CTRL_FORCE_DUPLEX; |
| 617 | if (phydev->duplex == DUPLEX_FULL) |
| 618 | reg |= PORT_PCS_CTRL_DUPLEX_FULL; |
| 619 | |
Andrew Lunn | e7e72ac | 2015-08-31 15:56:51 +0200 | [diff] [blame] | 620 | if ((mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds)) && |
| 621 | (port >= ps->num_ports - 2)) { |
| 622 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 623 | reg |= PORT_PCS_CTRL_RGMII_DELAY_RXCLK; |
| 624 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 625 | reg |= PORT_PCS_CTRL_RGMII_DELAY_TXCLK; |
| 626 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 627 | reg |= (PORT_PCS_CTRL_RGMII_DELAY_RXCLK | |
| 628 | PORT_PCS_CTRL_RGMII_DELAY_TXCLK); |
| 629 | } |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 630 | _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_PCS_CTRL, reg); |
| 631 | |
| 632 | out: |
| 633 | mutex_unlock(&ps->smi_mutex); |
| 634 | } |
| 635 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 636 | /* Must be called with SMI mutex held */ |
| 637 | static int _mv88e6xxx_stats_wait(struct dsa_switch *ds) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 638 | { |
| 639 | int ret; |
| 640 | int i; |
| 641 | |
| 642 | for (i = 0; i < 10; i++) { |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 643 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_OP); |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 644 | if ((ret & GLOBAL_STATS_OP_BUSY) == 0) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | return -ETIMEDOUT; |
| 649 | } |
| 650 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 651 | /* Must be called with SMI mutex held */ |
| 652 | static int _mv88e6xxx_stats_snapshot(struct dsa_switch *ds, int port) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 653 | { |
| 654 | int ret; |
| 655 | |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 656 | if (mv88e6xxx_6320_family(ds) || mv88e6xxx_6352_family(ds)) |
Andrew Lunn | f3a8b6b | 2015-04-02 04:06:40 +0200 | [diff] [blame] | 657 | port = (port + 1) << 5; |
| 658 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 659 | /* Snapshot the hardware statistics counters for this port. */ |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 660 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_STATS_OP, |
| 661 | GLOBAL_STATS_OP_CAPTURE_PORT | |
| 662 | GLOBAL_STATS_OP_HIST_RX_TX | port); |
| 663 | if (ret < 0) |
| 664 | return ret; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 665 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 666 | /* Wait for the snapshotting to complete. */ |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 667 | ret = _mv88e6xxx_stats_wait(ds); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 668 | if (ret < 0) |
| 669 | return ret; |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 674 | /* Must be called with SMI mutex held */ |
| 675 | static void _mv88e6xxx_stats_read(struct dsa_switch *ds, int stat, u32 *val) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 676 | { |
| 677 | u32 _val; |
| 678 | int ret; |
| 679 | |
| 680 | *val = 0; |
| 681 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 682 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_STATS_OP, |
| 683 | GLOBAL_STATS_OP_READ_CAPTURED | |
| 684 | GLOBAL_STATS_OP_HIST_RX_TX | stat); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 685 | if (ret < 0) |
| 686 | return; |
| 687 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 688 | ret = _mv88e6xxx_stats_wait(ds); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 689 | if (ret < 0) |
| 690 | return; |
| 691 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 692 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_COUNTER_32); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 693 | if (ret < 0) |
| 694 | return; |
| 695 | |
| 696 | _val = ret << 16; |
| 697 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 698 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_COUNTER_01); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 699 | if (ret < 0) |
| 700 | return; |
| 701 | |
| 702 | *val = _val | ret; |
| 703 | } |
| 704 | |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 705 | static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = { |
| 706 | { "in_good_octets", 8, 0x00, }, |
| 707 | { "in_bad_octets", 4, 0x02, }, |
| 708 | { "in_unicast", 4, 0x04, }, |
| 709 | { "in_broadcasts", 4, 0x06, }, |
| 710 | { "in_multicasts", 4, 0x07, }, |
| 711 | { "in_pause", 4, 0x16, }, |
| 712 | { "in_undersize", 4, 0x18, }, |
| 713 | { "in_fragments", 4, 0x19, }, |
| 714 | { "in_oversize", 4, 0x1a, }, |
| 715 | { "in_jabber", 4, 0x1b, }, |
| 716 | { "in_rx_error", 4, 0x1c, }, |
| 717 | { "in_fcs_error", 4, 0x1d, }, |
| 718 | { "out_octets", 8, 0x0e, }, |
| 719 | { "out_unicast", 4, 0x10, }, |
| 720 | { "out_broadcasts", 4, 0x13, }, |
| 721 | { "out_multicasts", 4, 0x12, }, |
| 722 | { "out_pause", 4, 0x15, }, |
| 723 | { "excessive", 4, 0x11, }, |
| 724 | { "collisions", 4, 0x1e, }, |
| 725 | { "deferred", 4, 0x05, }, |
| 726 | { "single", 4, 0x14, }, |
| 727 | { "multiple", 4, 0x17, }, |
| 728 | { "out_fcs_error", 4, 0x03, }, |
| 729 | { "late", 4, 0x1f, }, |
| 730 | { "hist_64bytes", 4, 0x08, }, |
| 731 | { "hist_65_127bytes", 4, 0x09, }, |
| 732 | { "hist_128_255bytes", 4, 0x0a, }, |
| 733 | { "hist_256_511bytes", 4, 0x0b, }, |
| 734 | { "hist_512_1023bytes", 4, 0x0c, }, |
| 735 | { "hist_1024_max_bytes", 4, 0x0d, }, |
| 736 | /* Not all devices have the following counters */ |
| 737 | { "sw_in_discards", 4, 0x110, }, |
| 738 | { "sw_in_filtered", 2, 0x112, }, |
| 739 | { "sw_out_filtered", 2, 0x113, }, |
| 740 | |
| 741 | }; |
| 742 | |
| 743 | static bool have_sw_in_discards(struct dsa_switch *ds) |
| 744 | { |
| 745 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 746 | |
| 747 | switch (ps->id) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 748 | case PORT_SWITCH_ID_6095: case PORT_SWITCH_ID_6161: |
| 749 | case PORT_SWITCH_ID_6165: case PORT_SWITCH_ID_6171: |
| 750 | case PORT_SWITCH_ID_6172: case PORT_SWITCH_ID_6176: |
| 751 | case PORT_SWITCH_ID_6182: case PORT_SWITCH_ID_6185: |
| 752 | case PORT_SWITCH_ID_6352: |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 753 | return true; |
| 754 | default: |
| 755 | return false; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | static void _mv88e6xxx_get_strings(struct dsa_switch *ds, |
| 760 | int nr_stats, |
| 761 | struct mv88e6xxx_hw_stat *stats, |
| 762 | int port, uint8_t *data) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 763 | { |
| 764 | int i; |
| 765 | |
| 766 | for (i = 0; i < nr_stats; i++) { |
| 767 | memcpy(data + i * ETH_GSTRING_LEN, |
| 768 | stats[i].string, ETH_GSTRING_LEN); |
| 769 | } |
| 770 | } |
| 771 | |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 772 | static uint64_t _mv88e6xxx_get_ethtool_stat(struct dsa_switch *ds, |
| 773 | int stat, |
| 774 | struct mv88e6xxx_hw_stat *stats, |
| 775 | int port) |
| 776 | { |
| 777 | struct mv88e6xxx_hw_stat *s = stats + stat; |
| 778 | u32 low; |
| 779 | u32 high = 0; |
| 780 | int ret; |
| 781 | u64 value; |
| 782 | |
| 783 | if (s->reg >= 0x100) { |
| 784 | ret = _mv88e6xxx_reg_read(ds, REG_PORT(port), |
| 785 | s->reg - 0x100); |
| 786 | if (ret < 0) |
| 787 | return UINT64_MAX; |
| 788 | |
| 789 | low = ret; |
| 790 | if (s->sizeof_stat == 4) { |
| 791 | ret = _mv88e6xxx_reg_read(ds, REG_PORT(port), |
| 792 | s->reg - 0x100 + 1); |
| 793 | if (ret < 0) |
| 794 | return UINT64_MAX; |
| 795 | high = ret; |
| 796 | } |
| 797 | } else { |
| 798 | _mv88e6xxx_stats_read(ds, s->reg, &low); |
| 799 | if (s->sizeof_stat == 8) |
| 800 | _mv88e6xxx_stats_read(ds, s->reg + 1, &high); |
| 801 | } |
| 802 | value = (((u64)high) << 16) | low; |
| 803 | return value; |
| 804 | } |
| 805 | |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 806 | static void _mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, |
| 807 | int nr_stats, |
| 808 | struct mv88e6xxx_hw_stat *stats, |
| 809 | int port, uint64_t *data) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 810 | { |
Florian Fainelli | a22adce | 2014-04-28 11:14:28 -0700 | [diff] [blame] | 811 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 812 | int ret; |
| 813 | int i; |
| 814 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 815 | mutex_lock(&ps->smi_mutex); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 816 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 817 | ret = _mv88e6xxx_stats_snapshot(ds, port); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 818 | if (ret < 0) { |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 819 | mutex_unlock(&ps->smi_mutex); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 820 | return; |
| 821 | } |
| 822 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 823 | /* Read each of the counters. */ |
Andrew Lunn | 80c4627 | 2015-06-20 18:42:30 +0200 | [diff] [blame] | 824 | for (i = 0; i < nr_stats; i++) |
| 825 | data[i] = _mv88e6xxx_get_ethtool_stat(ds, i, stats, port); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 826 | |
Andrew Lunn | 3188823 | 2015-05-06 01:09:54 +0200 | [diff] [blame] | 827 | mutex_unlock(&ps->smi_mutex); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 828 | } |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 829 | |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 830 | /* All the statistics in the table */ |
| 831 | void |
| 832 | mv88e6xxx_get_strings(struct dsa_switch *ds, int port, uint8_t *data) |
| 833 | { |
| 834 | if (have_sw_in_discards(ds)) |
| 835 | _mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6xxx_hw_stats), |
| 836 | mv88e6xxx_hw_stats, port, data); |
| 837 | else |
| 838 | _mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6xxx_hw_stats) - 3, |
| 839 | mv88e6xxx_hw_stats, port, data); |
| 840 | } |
| 841 | |
| 842 | int mv88e6xxx_get_sset_count(struct dsa_switch *ds) |
| 843 | { |
| 844 | if (have_sw_in_discards(ds)) |
| 845 | return ARRAY_SIZE(mv88e6xxx_hw_stats); |
| 846 | return ARRAY_SIZE(mv88e6xxx_hw_stats) - 3; |
| 847 | } |
| 848 | |
| 849 | void |
| 850 | mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, |
| 851 | int port, uint64_t *data) |
| 852 | { |
| 853 | if (have_sw_in_discards(ds)) |
| 854 | _mv88e6xxx_get_ethtool_stats( |
| 855 | ds, ARRAY_SIZE(mv88e6xxx_hw_stats), |
| 856 | mv88e6xxx_hw_stats, port, data); |
| 857 | else |
| 858 | _mv88e6xxx_get_ethtool_stats( |
| 859 | ds, ARRAY_SIZE(mv88e6xxx_hw_stats) - 3, |
| 860 | mv88e6xxx_hw_stats, port, data); |
| 861 | } |
| 862 | |
Guenter Roeck | a1ab91f | 2014-10-29 10:45:05 -0700 | [diff] [blame] | 863 | int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port) |
| 864 | { |
| 865 | return 32 * sizeof(u16); |
| 866 | } |
| 867 | |
| 868 | void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, |
| 869 | struct ethtool_regs *regs, void *_p) |
| 870 | { |
| 871 | u16 *p = _p; |
| 872 | int i; |
| 873 | |
| 874 | regs->version = 0; |
| 875 | |
| 876 | memset(p, 0xff, 32 * sizeof(u16)); |
| 877 | |
| 878 | for (i = 0; i < 32; i++) { |
| 879 | int ret; |
| 880 | |
| 881 | ret = mv88e6xxx_reg_read(ds, REG_PORT(port), i); |
| 882 | if (ret >= 0) |
| 883 | p[i] = ret; |
| 884 | } |
| 885 | } |
| 886 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 887 | /* Must be called with SMI lock held */ |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 888 | static int _mv88e6xxx_wait(struct dsa_switch *ds, int reg, int offset, |
| 889 | u16 mask) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 890 | { |
| 891 | unsigned long timeout = jiffies + HZ / 10; |
| 892 | |
| 893 | while (time_before(jiffies, timeout)) { |
| 894 | int ret; |
| 895 | |
| 896 | ret = _mv88e6xxx_reg_read(ds, reg, offset); |
| 897 | if (ret < 0) |
| 898 | return ret; |
| 899 | if (!(ret & mask)) |
| 900 | return 0; |
| 901 | |
| 902 | usleep_range(1000, 2000); |
| 903 | } |
| 904 | return -ETIMEDOUT; |
| 905 | } |
| 906 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 907 | static int mv88e6xxx_wait(struct dsa_switch *ds, int reg, int offset, u16 mask) |
| 908 | { |
| 909 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 910 | int ret; |
| 911 | |
| 912 | mutex_lock(&ps->smi_mutex); |
| 913 | ret = _mv88e6xxx_wait(ds, reg, offset, mask); |
| 914 | mutex_unlock(&ps->smi_mutex); |
| 915 | |
| 916 | return ret; |
| 917 | } |
| 918 | |
| 919 | static int _mv88e6xxx_phy_wait(struct dsa_switch *ds) |
| 920 | { |
| 921 | return _mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_SMI_OP, |
| 922 | GLOBAL2_SMI_OP_BUSY); |
| 923 | } |
| 924 | |
| 925 | int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds) |
| 926 | { |
| 927 | return mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
| 928 | GLOBAL2_EEPROM_OP_LOAD); |
| 929 | } |
| 930 | |
| 931 | int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds) |
| 932 | { |
| 933 | return mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
| 934 | GLOBAL2_EEPROM_OP_BUSY); |
| 935 | } |
| 936 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 937 | /* Must be called with SMI lock held */ |
| 938 | static int _mv88e6xxx_atu_wait(struct dsa_switch *ds) |
| 939 | { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 940 | return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_ATU_OP, |
| 941 | GLOBAL_ATU_OP_BUSY); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Andrew Lunn | 56d95e2 | 2015-06-20 18:42:33 +0200 | [diff] [blame] | 944 | /* Must be called with SMI lock held */ |
| 945 | static int _mv88e6xxx_scratch_wait(struct dsa_switch *ds) |
| 946 | { |
| 947 | return _mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_SCRATCH_MISC, |
| 948 | GLOBAL2_SCRATCH_BUSY); |
| 949 | } |
| 950 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 951 | /* Must be called with SMI mutex held */ |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 952 | static int _mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, |
| 953 | int regnum) |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 954 | { |
| 955 | int ret; |
| 956 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 957 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_SMI_OP, |
| 958 | GLOBAL2_SMI_OP_22_READ | (addr << 5) | |
| 959 | regnum); |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 960 | if (ret < 0) |
| 961 | return ret; |
| 962 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 963 | ret = _mv88e6xxx_phy_wait(ds); |
| 964 | if (ret < 0) |
| 965 | return ret; |
| 966 | |
| 967 | return _mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_SMI_DATA); |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 970 | /* Must be called with SMI mutex held */ |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 971 | static int _mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, |
| 972 | int regnum, u16 val) |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 973 | { |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 974 | int ret; |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 975 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 976 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_SMI_DATA, val); |
| 977 | if (ret < 0) |
| 978 | return ret; |
| 979 | |
| 980 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_SMI_OP, |
| 981 | GLOBAL2_SMI_OP_22_WRITE | (addr << 5) | |
| 982 | regnum); |
| 983 | |
| 984 | return _mv88e6xxx_phy_wait(ds); |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 985 | } |
| 986 | |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 987 | int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) |
| 988 | { |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 989 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 990 | int reg; |
| 991 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 992 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 993 | |
| 994 | reg = _mv88e6xxx_phy_read_indirect(ds, port, 16); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 995 | if (reg < 0) |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 996 | goto out; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 997 | |
| 998 | e->eee_enabled = !!(reg & 0x0200); |
| 999 | e->tx_lpi_enabled = !!(reg & 0x0100); |
| 1000 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1001 | reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_STATUS); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1002 | if (reg < 0) |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1003 | goto out; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1004 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1005 | e->eee_active = !!(reg & PORT_STATUS_EEE); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1006 | reg = 0; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1007 | |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1008 | out: |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1009 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1010 | return reg; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | int mv88e6xxx_set_eee(struct dsa_switch *ds, int port, |
| 1014 | struct phy_device *phydev, struct ethtool_eee *e) |
| 1015 | { |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1016 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1017 | int reg; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1018 | int ret; |
| 1019 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1020 | mutex_lock(&ps->smi_mutex); |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1021 | |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1022 | ret = _mv88e6xxx_phy_read_indirect(ds, port, 16); |
| 1023 | if (ret < 0) |
| 1024 | goto out; |
| 1025 | |
| 1026 | reg = ret & ~0x0300; |
| 1027 | if (e->eee_enabled) |
| 1028 | reg |= 0x0200; |
| 1029 | if (e->tx_lpi_enabled) |
| 1030 | reg |= 0x0100; |
| 1031 | |
| 1032 | ret = _mv88e6xxx_phy_write_indirect(ds, port, 16, reg); |
| 1033 | out: |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 1034 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 2f40c69 | 2015-04-02 04:06:37 +0200 | [diff] [blame] | 1035 | |
| 1036 | return ret; |
Guenter Roeck | 11b3b45 | 2015-03-06 22:23:51 -0800 | [diff] [blame] | 1037 | } |
| 1038 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1039 | static int _mv88e6xxx_atu_cmd(struct dsa_switch *ds, int fid, u16 cmd) |
| 1040 | { |
| 1041 | int ret; |
| 1042 | |
Vivien Didelot | a08df0f | 2015-08-10 09:09:46 -0400 | [diff] [blame] | 1043 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_FID, fid); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1044 | if (ret < 0) |
| 1045 | return ret; |
| 1046 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1047 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_OP, cmd); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1048 | if (ret < 0) |
| 1049 | return ret; |
| 1050 | |
| 1051 | return _mv88e6xxx_atu_wait(ds); |
| 1052 | } |
| 1053 | |
| 1054 | static int _mv88e6xxx_flush_fid(struct dsa_switch *ds, int fid) |
| 1055 | { |
| 1056 | int ret; |
| 1057 | |
| 1058 | ret = _mv88e6xxx_atu_wait(ds); |
| 1059 | if (ret < 0) |
| 1060 | return ret; |
| 1061 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1062 | return _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_FLUSH_NON_STATIC_DB); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | static int mv88e6xxx_set_port_state(struct dsa_switch *ds, int port, u8 state) |
| 1066 | { |
| 1067 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Geert Uytterhoeven | c3ffe6d | 2015-04-16 20:49:14 +0200 | [diff] [blame] | 1068 | int reg, ret = 0; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1069 | u8 oldstate; |
| 1070 | |
| 1071 | mutex_lock(&ps->smi_mutex); |
| 1072 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1073 | reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_CONTROL); |
Guenter Roeck | 538cc28 | 2015-04-15 22:12:42 -0700 | [diff] [blame] | 1074 | if (reg < 0) { |
| 1075 | ret = reg; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1076 | goto abort; |
Guenter Roeck | 538cc28 | 2015-04-15 22:12:42 -0700 | [diff] [blame] | 1077 | } |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1078 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1079 | oldstate = reg & PORT_CONTROL_STATE_MASK; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1080 | if (oldstate != state) { |
| 1081 | /* Flush forwarding database if we're moving a port |
| 1082 | * from Learning or Forwarding state to Disabled or |
| 1083 | * Blocking or Listening state. |
| 1084 | */ |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1085 | if (oldstate >= PORT_CONTROL_STATE_LEARNING && |
| 1086 | state <= PORT_CONTROL_STATE_BLOCKING) { |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1087 | ret = _mv88e6xxx_flush_fid(ds, ps->fid[port]); |
| 1088 | if (ret) |
| 1089 | goto abort; |
| 1090 | } |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1091 | reg = (reg & ~PORT_CONTROL_STATE_MASK) | state; |
| 1092 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL, |
| 1093 | reg); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | abort: |
| 1097 | mutex_unlock(&ps->smi_mutex); |
| 1098 | return ret; |
| 1099 | } |
| 1100 | |
| 1101 | /* Must be called with smi lock held */ |
| 1102 | static int _mv88e6xxx_update_port_config(struct dsa_switch *ds, int port) |
| 1103 | { |
| 1104 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1105 | u8 fid = ps->fid[port]; |
| 1106 | u16 reg = fid << 12; |
| 1107 | |
| 1108 | if (dsa_is_cpu_port(ds, port)) |
| 1109 | reg |= ds->phys_port_mask; |
| 1110 | else |
| 1111 | reg |= (ps->bridge_mask[fid] | |
| 1112 | (1 << dsa_upstream_port(ds))) & ~(1 << port); |
| 1113 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1114 | return _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_BASE_VLAN, reg); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | /* Must be called with smi lock held */ |
| 1118 | static int _mv88e6xxx_update_bridge_config(struct dsa_switch *ds, int fid) |
| 1119 | { |
| 1120 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1121 | int port; |
| 1122 | u32 mask; |
| 1123 | int ret; |
| 1124 | |
| 1125 | mask = ds->phys_port_mask; |
| 1126 | while (mask) { |
| 1127 | port = __ffs(mask); |
| 1128 | mask &= ~(1 << port); |
| 1129 | if (ps->fid[port] != fid) |
| 1130 | continue; |
| 1131 | |
| 1132 | ret = _mv88e6xxx_update_port_config(ds, port); |
| 1133 | if (ret) |
| 1134 | return ret; |
| 1135 | } |
| 1136 | |
| 1137 | return _mv88e6xxx_flush_fid(ds, fid); |
| 1138 | } |
| 1139 | |
| 1140 | /* Bridge handling functions */ |
| 1141 | |
| 1142 | int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask) |
| 1143 | { |
| 1144 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1145 | int ret = 0; |
| 1146 | u32 nmask; |
| 1147 | int fid; |
| 1148 | |
| 1149 | /* If the bridge group is not empty, join that group. |
| 1150 | * Otherwise create a new group. |
| 1151 | */ |
| 1152 | fid = ps->fid[port]; |
| 1153 | nmask = br_port_mask & ~(1 << port); |
| 1154 | if (nmask) |
| 1155 | fid = ps->fid[__ffs(nmask)]; |
| 1156 | |
| 1157 | nmask = ps->bridge_mask[fid] | (1 << port); |
| 1158 | if (nmask != br_port_mask) { |
| 1159 | netdev_err(ds->ports[port], |
| 1160 | "join: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n", |
| 1161 | fid, br_port_mask, nmask); |
| 1162 | return -EINVAL; |
| 1163 | } |
| 1164 | |
| 1165 | mutex_lock(&ps->smi_mutex); |
| 1166 | |
| 1167 | ps->bridge_mask[fid] = br_port_mask; |
| 1168 | |
| 1169 | if (fid != ps->fid[port]) { |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1170 | clear_bit(ps->fid[port], ps->fid_bitmap); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1171 | ps->fid[port] = fid; |
| 1172 | ret = _mv88e6xxx_update_bridge_config(ds, fid); |
| 1173 | } |
| 1174 | |
| 1175 | mutex_unlock(&ps->smi_mutex); |
| 1176 | |
| 1177 | return ret; |
| 1178 | } |
| 1179 | |
| 1180 | int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask) |
| 1181 | { |
| 1182 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1183 | u8 fid, newfid; |
| 1184 | int ret; |
| 1185 | |
| 1186 | fid = ps->fid[port]; |
| 1187 | |
| 1188 | if (ps->bridge_mask[fid] != br_port_mask) { |
| 1189 | netdev_err(ds->ports[port], |
| 1190 | "leave: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n", |
| 1191 | fid, br_port_mask, ps->bridge_mask[fid]); |
| 1192 | return -EINVAL; |
| 1193 | } |
| 1194 | |
| 1195 | /* If the port was the last port of a bridge, we are done. |
| 1196 | * Otherwise assign a new fid to the port, and fix up |
| 1197 | * the bridge configuration. |
| 1198 | */ |
| 1199 | if (br_port_mask == (1 << port)) |
| 1200 | return 0; |
| 1201 | |
| 1202 | mutex_lock(&ps->smi_mutex); |
| 1203 | |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1204 | newfid = find_next_zero_bit(ps->fid_bitmap, VLAN_N_VID, 1); |
| 1205 | if (unlikely(newfid > ps->num_ports)) { |
| 1206 | netdev_err(ds->ports[port], "all first %d FIDs are used\n", |
| 1207 | ps->num_ports); |
| 1208 | ret = -ENOSPC; |
| 1209 | goto unlock; |
| 1210 | } |
| 1211 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1212 | ps->fid[port] = newfid; |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1213 | set_bit(newfid, ps->fid_bitmap); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1214 | ps->bridge_mask[fid] &= ~(1 << port); |
| 1215 | ps->bridge_mask[newfid] = 1 << port; |
| 1216 | |
| 1217 | ret = _mv88e6xxx_update_bridge_config(ds, fid); |
| 1218 | if (!ret) |
| 1219 | ret = _mv88e6xxx_update_bridge_config(ds, newfid); |
| 1220 | |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1221 | unlock: |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1222 | mutex_unlock(&ps->smi_mutex); |
| 1223 | |
| 1224 | return ret; |
| 1225 | } |
| 1226 | |
| 1227 | int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state) |
| 1228 | { |
| 1229 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1230 | int stp_state; |
| 1231 | |
| 1232 | switch (state) { |
| 1233 | case BR_STATE_DISABLED: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1234 | stp_state = PORT_CONTROL_STATE_DISABLED; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1235 | break; |
| 1236 | case BR_STATE_BLOCKING: |
| 1237 | case BR_STATE_LISTENING: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1238 | stp_state = PORT_CONTROL_STATE_BLOCKING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | case BR_STATE_LEARNING: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1241 | stp_state = PORT_CONTROL_STATE_LEARNING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1242 | break; |
| 1243 | case BR_STATE_FORWARDING: |
| 1244 | default: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1245 | stp_state = PORT_CONTROL_STATE_FORWARDING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1246 | break; |
| 1247 | } |
| 1248 | |
| 1249 | netdev_dbg(ds->ports[port], "port state %d [%d]\n", state, stp_state); |
| 1250 | |
| 1251 | /* mv88e6xxx_port_stp_update may be called with softirqs disabled, |
| 1252 | * so we can not update the port state directly but need to schedule it. |
| 1253 | */ |
| 1254 | ps->port_state[port] = stp_state; |
| 1255 | set_bit(port, &ps->port_state_update_mask); |
| 1256 | schedule_work(&ps->bridge_work); |
| 1257 | |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1261 | int mv88e6xxx_port_pvid_get(struct dsa_switch *ds, int port, u16 *pvid) |
| 1262 | { |
| 1263 | int ret; |
| 1264 | |
| 1265 | ret = mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_DEFAULT_VLAN); |
| 1266 | if (ret < 0) |
| 1267 | return ret; |
| 1268 | |
| 1269 | *pvid = ret & PORT_DEFAULT_VLAN_MASK; |
| 1270 | |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1274 | int mv88e6xxx_port_pvid_set(struct dsa_switch *ds, int port, u16 pvid) |
| 1275 | { |
| 1276 | return mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_DEFAULT_VLAN, |
| 1277 | pvid & PORT_DEFAULT_VLAN_MASK); |
| 1278 | } |
| 1279 | |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1280 | static int _mv88e6xxx_vtu_wait(struct dsa_switch *ds) |
| 1281 | { |
| 1282 | return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_VTU_OP, |
| 1283 | GLOBAL_VTU_OP_BUSY); |
| 1284 | } |
| 1285 | |
| 1286 | static int _mv88e6xxx_vtu_cmd(struct dsa_switch *ds, u16 op) |
| 1287 | { |
| 1288 | int ret; |
| 1289 | |
| 1290 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_OP, op); |
| 1291 | if (ret < 0) |
| 1292 | return ret; |
| 1293 | |
| 1294 | return _mv88e6xxx_vtu_wait(ds); |
| 1295 | } |
| 1296 | |
| 1297 | static int _mv88e6xxx_vtu_stu_flush(struct dsa_switch *ds) |
| 1298 | { |
| 1299 | int ret; |
| 1300 | |
| 1301 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1302 | if (ret < 0) |
| 1303 | return ret; |
| 1304 | |
| 1305 | return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_FLUSH_ALL); |
| 1306 | } |
| 1307 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1308 | static int _mv88e6xxx_vtu_stu_data_read(struct dsa_switch *ds, |
| 1309 | struct mv88e6xxx_vtu_stu_entry *entry, |
| 1310 | unsigned int nibble_offset) |
| 1311 | { |
| 1312 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1313 | u16 regs[3]; |
| 1314 | int i; |
| 1315 | int ret; |
| 1316 | |
| 1317 | for (i = 0; i < 3; ++i) { |
| 1318 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1319 | GLOBAL_VTU_DATA_0_3 + i); |
| 1320 | if (ret < 0) |
| 1321 | return ret; |
| 1322 | |
| 1323 | regs[i] = ret; |
| 1324 | } |
| 1325 | |
| 1326 | for (i = 0; i < ps->num_ports; ++i) { |
| 1327 | unsigned int shift = (i % 4) * 4 + nibble_offset; |
| 1328 | u16 reg = regs[i / 4]; |
| 1329 | |
| 1330 | entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK; |
| 1331 | } |
| 1332 | |
| 1333 | return 0; |
| 1334 | } |
| 1335 | |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1336 | static int _mv88e6xxx_vtu_stu_data_write(struct dsa_switch *ds, |
| 1337 | struct mv88e6xxx_vtu_stu_entry *entry, |
| 1338 | unsigned int nibble_offset) |
| 1339 | { |
| 1340 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1341 | u16 regs[3] = { 0 }; |
| 1342 | int i; |
| 1343 | int ret; |
| 1344 | |
| 1345 | for (i = 0; i < ps->num_ports; ++i) { |
| 1346 | unsigned int shift = (i % 4) * 4 + nibble_offset; |
| 1347 | u8 data = entry->data[i]; |
| 1348 | |
| 1349 | regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift; |
| 1350 | } |
| 1351 | |
| 1352 | for (i = 0; i < 3; ++i) { |
| 1353 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, |
| 1354 | GLOBAL_VTU_DATA_0_3 + i, regs[i]); |
| 1355 | if (ret < 0) |
| 1356 | return ret; |
| 1357 | } |
| 1358 | |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1362 | static int _mv88e6xxx_vtu_getnext(struct dsa_switch *ds, u16 vid, |
| 1363 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1364 | { |
| 1365 | struct mv88e6xxx_vtu_stu_entry next = { 0 }; |
| 1366 | int ret; |
| 1367 | |
| 1368 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1369 | if (ret < 0) |
| 1370 | return ret; |
| 1371 | |
| 1372 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_VID, |
| 1373 | vid & GLOBAL_VTU_VID_MASK); |
| 1374 | if (ret < 0) |
| 1375 | return ret; |
| 1376 | |
| 1377 | ret = _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_VTU_GET_NEXT); |
| 1378 | if (ret < 0) |
| 1379 | return ret; |
| 1380 | |
| 1381 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_VTU_VID); |
| 1382 | if (ret < 0) |
| 1383 | return ret; |
| 1384 | |
| 1385 | next.vid = ret & GLOBAL_VTU_VID_MASK; |
| 1386 | next.valid = !!(ret & GLOBAL_VTU_VID_VALID); |
| 1387 | |
| 1388 | if (next.valid) { |
| 1389 | ret = _mv88e6xxx_vtu_stu_data_read(ds, &next, 0); |
| 1390 | if (ret < 0) |
| 1391 | return ret; |
| 1392 | |
| 1393 | if (mv88e6xxx_6097_family(ds) || mv88e6xxx_6165_family(ds) || |
| 1394 | mv88e6xxx_6351_family(ds) || mv88e6xxx_6352_family(ds)) { |
| 1395 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1396 | GLOBAL_VTU_FID); |
| 1397 | if (ret < 0) |
| 1398 | return ret; |
| 1399 | |
| 1400 | next.fid = ret & GLOBAL_VTU_FID_MASK; |
| 1401 | |
| 1402 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1403 | GLOBAL_VTU_SID); |
| 1404 | if (ret < 0) |
| 1405 | return ret; |
| 1406 | |
| 1407 | next.sid = ret & GLOBAL_VTU_SID_MASK; |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | *entry = next; |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1415 | static int _mv88e6xxx_vtu_loadpurge(struct dsa_switch *ds, |
| 1416 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1417 | { |
| 1418 | u16 reg = 0; |
| 1419 | int ret; |
| 1420 | |
| 1421 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1422 | if (ret < 0) |
| 1423 | return ret; |
| 1424 | |
| 1425 | if (!entry->valid) |
| 1426 | goto loadpurge; |
| 1427 | |
| 1428 | /* Write port member tags */ |
| 1429 | ret = _mv88e6xxx_vtu_stu_data_write(ds, entry, 0); |
| 1430 | if (ret < 0) |
| 1431 | return ret; |
| 1432 | |
| 1433 | if (mv88e6xxx_6097_family(ds) || mv88e6xxx_6165_family(ds) || |
| 1434 | mv88e6xxx_6351_family(ds) || mv88e6xxx_6352_family(ds)) { |
| 1435 | reg = entry->sid & GLOBAL_VTU_SID_MASK; |
| 1436 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_SID, reg); |
| 1437 | if (ret < 0) |
| 1438 | return ret; |
| 1439 | |
| 1440 | reg = entry->fid & GLOBAL_VTU_FID_MASK; |
| 1441 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_FID, reg); |
| 1442 | if (ret < 0) |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
| 1446 | reg = GLOBAL_VTU_VID_VALID; |
| 1447 | loadpurge: |
| 1448 | reg |= entry->vid & GLOBAL_VTU_VID_MASK; |
| 1449 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_VID, reg); |
| 1450 | if (ret < 0) |
| 1451 | return ret; |
| 1452 | |
| 1453 | return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_VTU_LOAD_PURGE); |
| 1454 | } |
| 1455 | |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1456 | static int _mv88e6xxx_stu_getnext(struct dsa_switch *ds, u8 sid, |
| 1457 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1458 | { |
| 1459 | struct mv88e6xxx_vtu_stu_entry next = { 0 }; |
| 1460 | int ret; |
| 1461 | |
| 1462 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1463 | if (ret < 0) |
| 1464 | return ret; |
| 1465 | |
| 1466 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_SID, |
| 1467 | sid & GLOBAL_VTU_SID_MASK); |
| 1468 | if (ret < 0) |
| 1469 | return ret; |
| 1470 | |
| 1471 | ret = _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_STU_GET_NEXT); |
| 1472 | if (ret < 0) |
| 1473 | return ret; |
| 1474 | |
| 1475 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_VTU_SID); |
| 1476 | if (ret < 0) |
| 1477 | return ret; |
| 1478 | |
| 1479 | next.sid = ret & GLOBAL_VTU_SID_MASK; |
| 1480 | |
| 1481 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_VTU_VID); |
| 1482 | if (ret < 0) |
| 1483 | return ret; |
| 1484 | |
| 1485 | next.valid = !!(ret & GLOBAL_VTU_VID_VALID); |
| 1486 | |
| 1487 | if (next.valid) { |
| 1488 | ret = _mv88e6xxx_vtu_stu_data_read(ds, &next, 2); |
| 1489 | if (ret < 0) |
| 1490 | return ret; |
| 1491 | } |
| 1492 | |
| 1493 | *entry = next; |
| 1494 | return 0; |
| 1495 | } |
| 1496 | |
| 1497 | static int _mv88e6xxx_stu_loadpurge(struct dsa_switch *ds, |
| 1498 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1499 | { |
| 1500 | u16 reg = 0; |
| 1501 | int ret; |
| 1502 | |
| 1503 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1504 | if (ret < 0) |
| 1505 | return ret; |
| 1506 | |
| 1507 | if (!entry->valid) |
| 1508 | goto loadpurge; |
| 1509 | |
| 1510 | /* Write port states */ |
| 1511 | ret = _mv88e6xxx_vtu_stu_data_write(ds, entry, 2); |
| 1512 | if (ret < 0) |
| 1513 | return ret; |
| 1514 | |
| 1515 | reg = GLOBAL_VTU_VID_VALID; |
| 1516 | loadpurge: |
| 1517 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_VID, reg); |
| 1518 | if (ret < 0) |
| 1519 | return ret; |
| 1520 | |
| 1521 | reg = entry->sid & GLOBAL_VTU_SID_MASK; |
| 1522 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_SID, reg); |
| 1523 | if (ret < 0) |
| 1524 | return ret; |
| 1525 | |
| 1526 | return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_STU_LOAD_PURGE); |
| 1527 | } |
| 1528 | |
| 1529 | static int _mv88e6xxx_vlan_init(struct dsa_switch *ds, u16 vid, |
| 1530 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1531 | { |
| 1532 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1533 | struct mv88e6xxx_vtu_stu_entry vlan = { |
| 1534 | .valid = true, |
| 1535 | .vid = vid, |
| 1536 | }; |
| 1537 | int i; |
| 1538 | |
| 1539 | /* exclude all ports except the CPU */ |
| 1540 | for (i = 0; i < ps->num_ports; ++i) |
| 1541 | vlan.data[i] = dsa_is_cpu_port(ds, i) ? |
| 1542 | GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED : |
| 1543 | GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; |
| 1544 | |
| 1545 | if (mv88e6xxx_6097_family(ds) || mv88e6xxx_6165_family(ds) || |
| 1546 | mv88e6xxx_6351_family(ds) || mv88e6xxx_6352_family(ds)) { |
| 1547 | struct mv88e6xxx_vtu_stu_entry vstp; |
| 1548 | int err; |
| 1549 | |
| 1550 | /* Adding a VTU entry requires a valid STU entry. As VSTP is not |
| 1551 | * implemented, only one STU entry is needed to cover all VTU |
| 1552 | * entries. Thus, validate the SID 0. |
| 1553 | */ |
| 1554 | vlan.sid = 0; |
| 1555 | err = _mv88e6xxx_stu_getnext(ds, GLOBAL_VTU_SID_MASK, &vstp); |
| 1556 | if (err) |
| 1557 | return err; |
| 1558 | |
| 1559 | if (vstp.sid != vlan.sid || !vstp.valid) { |
| 1560 | memset(&vstp, 0, sizeof(vstp)); |
| 1561 | vstp.valid = true; |
| 1562 | vstp.sid = vlan.sid; |
| 1563 | |
| 1564 | err = _mv88e6xxx_stu_loadpurge(ds, &vstp); |
| 1565 | if (err) |
| 1566 | return err; |
| 1567 | } |
| 1568 | |
| 1569 | /* Non-bridged ports and bridge groups use FIDs from 1 to |
| 1570 | * num_ports; VLANs use FIDs from num_ports+1 to 4095. |
| 1571 | */ |
| 1572 | vlan.fid = find_next_zero_bit(ps->fid_bitmap, VLAN_N_VID, |
| 1573 | ps->num_ports + 1); |
| 1574 | if (unlikely(vlan.fid == VLAN_N_VID)) { |
| 1575 | pr_err("no more FID available for VLAN %d\n", vid); |
| 1576 | return -ENOSPC; |
| 1577 | } |
| 1578 | |
| 1579 | err = _mv88e6xxx_flush_fid(ds, vlan.fid); |
| 1580 | if (err) |
| 1581 | return err; |
| 1582 | |
| 1583 | set_bit(vlan.fid, ps->fid_bitmap); |
| 1584 | } |
| 1585 | |
| 1586 | *entry = vlan; |
| 1587 | return 0; |
| 1588 | } |
| 1589 | |
| 1590 | int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port, u16 vid, |
| 1591 | bool untagged) |
| 1592 | { |
| 1593 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1594 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 1595 | int err; |
| 1596 | |
| 1597 | mutex_lock(&ps->smi_mutex); |
| 1598 | err = _mv88e6xxx_vtu_getnext(ds, vid - 1, &vlan); |
| 1599 | if (err) |
| 1600 | goto unlock; |
| 1601 | |
| 1602 | if (vlan.vid != vid || !vlan.valid) { |
| 1603 | err = _mv88e6xxx_vlan_init(ds, vid, &vlan); |
| 1604 | if (err) |
| 1605 | goto unlock; |
| 1606 | } |
| 1607 | |
| 1608 | vlan.data[port] = untagged ? |
| 1609 | GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED : |
| 1610 | GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED; |
| 1611 | |
| 1612 | err = _mv88e6xxx_vtu_loadpurge(ds, &vlan); |
| 1613 | unlock: |
| 1614 | mutex_unlock(&ps->smi_mutex); |
| 1615 | |
| 1616 | return err; |
| 1617 | } |
| 1618 | |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1619 | int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, u16 vid) |
| 1620 | { |
| 1621 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1622 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 1623 | bool keep = false; |
| 1624 | int i, err; |
| 1625 | |
| 1626 | mutex_lock(&ps->smi_mutex); |
| 1627 | |
| 1628 | err = _mv88e6xxx_vtu_getnext(ds, vid - 1, &vlan); |
| 1629 | if (err) |
| 1630 | goto unlock; |
| 1631 | |
| 1632 | if (vlan.vid != vid || !vlan.valid || |
| 1633 | vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) { |
| 1634 | err = -ENOENT; |
| 1635 | goto unlock; |
| 1636 | } |
| 1637 | |
| 1638 | vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; |
| 1639 | |
| 1640 | /* keep the VLAN unless all ports are excluded */ |
| 1641 | for (i = 0; i < ps->num_ports; ++i) { |
| 1642 | if (dsa_is_cpu_port(ds, i)) |
| 1643 | continue; |
| 1644 | |
| 1645 | if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) { |
| 1646 | keep = true; |
| 1647 | break; |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | vlan.valid = keep; |
| 1652 | err = _mv88e6xxx_vtu_loadpurge(ds, &vlan); |
| 1653 | if (err) |
| 1654 | goto unlock; |
| 1655 | |
| 1656 | if (!keep) |
| 1657 | clear_bit(vlan.fid, ps->fid_bitmap); |
| 1658 | |
| 1659 | unlock: |
| 1660 | mutex_unlock(&ps->smi_mutex); |
| 1661 | |
| 1662 | return err; |
| 1663 | } |
| 1664 | |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1665 | static int _mv88e6xxx_port_vtu_getnext(struct dsa_switch *ds, int port, u16 vid, |
| 1666 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1667 | { |
| 1668 | int err; |
| 1669 | |
| 1670 | do { |
| 1671 | if (vid == 4095) |
| 1672 | return -ENOENT; |
| 1673 | |
| 1674 | err = _mv88e6xxx_vtu_getnext(ds, vid, entry); |
| 1675 | if (err) |
| 1676 | return err; |
| 1677 | |
| 1678 | if (!entry->valid) |
| 1679 | return -ENOENT; |
| 1680 | |
| 1681 | vid = entry->vid; |
| 1682 | } while (entry->data[port] != GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED && |
| 1683 | entry->data[port] != GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED); |
| 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1688 | int mv88e6xxx_vlan_getnext(struct dsa_switch *ds, u16 *vid, |
| 1689 | unsigned long *ports, unsigned long *untagged) |
| 1690 | { |
| 1691 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1692 | struct mv88e6xxx_vtu_stu_entry next; |
| 1693 | int port; |
| 1694 | int err; |
| 1695 | |
| 1696 | if (*vid == 4095) |
| 1697 | return -ENOENT; |
| 1698 | |
| 1699 | mutex_lock(&ps->smi_mutex); |
| 1700 | err = _mv88e6xxx_vtu_getnext(ds, *vid, &next); |
| 1701 | mutex_unlock(&ps->smi_mutex); |
| 1702 | |
| 1703 | if (err) |
| 1704 | return err; |
| 1705 | |
| 1706 | if (!next.valid) |
| 1707 | return -ENOENT; |
| 1708 | |
| 1709 | *vid = next.vid; |
| 1710 | |
| 1711 | for (port = 0; port < ps->num_ports; ++port) { |
| 1712 | clear_bit(port, ports); |
| 1713 | clear_bit(port, untagged); |
| 1714 | |
| 1715 | if (dsa_is_cpu_port(ds, port)) |
| 1716 | continue; |
| 1717 | |
| 1718 | if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED || |
| 1719 | next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED) |
| 1720 | set_bit(port, ports); |
| 1721 | |
| 1722 | if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED) |
| 1723 | set_bit(port, untagged); |
| 1724 | } |
| 1725 | |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 1729 | static int _mv88e6xxx_atu_mac_write(struct dsa_switch *ds, |
| 1730 | const unsigned char *addr) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1731 | { |
| 1732 | int i, ret; |
| 1733 | |
| 1734 | for (i = 0; i < 3; i++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1735 | ret = _mv88e6xxx_reg_write( |
| 1736 | ds, REG_GLOBAL, GLOBAL_ATU_MAC_01 + i, |
| 1737 | (addr[i * 2] << 8) | addr[i * 2 + 1]); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1738 | if (ret < 0) |
| 1739 | return ret; |
| 1740 | } |
| 1741 | |
| 1742 | return 0; |
| 1743 | } |
| 1744 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 1745 | static int _mv88e6xxx_atu_mac_read(struct dsa_switch *ds, unsigned char *addr) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1746 | { |
| 1747 | int i, ret; |
| 1748 | |
| 1749 | for (i = 0; i < 3; i++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1750 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1751 | GLOBAL_ATU_MAC_01 + i); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1752 | if (ret < 0) |
| 1753 | return ret; |
| 1754 | addr[i * 2] = ret >> 8; |
| 1755 | addr[i * 2 + 1] = ret & 0xff; |
| 1756 | } |
| 1757 | |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1761 | static int _mv88e6xxx_atu_load(struct dsa_switch *ds, |
| 1762 | struct mv88e6xxx_atu_entry *entry) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1763 | { |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1764 | u16 reg = 0; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1765 | int ret; |
| 1766 | |
| 1767 | ret = _mv88e6xxx_atu_wait(ds); |
| 1768 | if (ret < 0) |
| 1769 | return ret; |
| 1770 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1771 | ret = _mv88e6xxx_atu_mac_write(ds, entry->mac); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1772 | if (ret < 0) |
| 1773 | return ret; |
| 1774 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1775 | if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 1776 | unsigned int mask, shift; |
| 1777 | |
| 1778 | if (entry->trunk) { |
| 1779 | reg |= GLOBAL_ATU_DATA_TRUNK; |
| 1780 | mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK; |
| 1781 | shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT; |
| 1782 | } else { |
| 1783 | mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK; |
| 1784 | shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT; |
| 1785 | } |
| 1786 | |
| 1787 | reg |= (entry->portv_trunkid << shift) & mask; |
| 1788 | } |
| 1789 | |
| 1790 | reg |= entry->state & GLOBAL_ATU_DATA_STATE_MASK; |
| 1791 | |
| 1792 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_DATA, reg); |
| 1793 | if (ret < 0) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1794 | return ret; |
| 1795 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1796 | return _mv88e6xxx_atu_cmd(ds, entry->fid, GLOBAL_ATU_OP_LOAD_DB); |
| 1797 | } |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1798 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1799 | static int _mv88e6xxx_port_vid_to_fid(struct dsa_switch *ds, int port, u16 vid) |
| 1800 | { |
| 1801 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1802 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 1803 | int err; |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1804 | |
| 1805 | if (vid == 0) |
| 1806 | return ps->fid[port]; |
| 1807 | |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1808 | err = _mv88e6xxx_port_vtu_getnext(ds, port, vid - 1, &vlan); |
| 1809 | if (err) |
| 1810 | return err; |
| 1811 | |
| 1812 | if (vlan.vid == vid) |
| 1813 | return vlan.fid; |
| 1814 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1815 | return -ENOENT; |
| 1816 | } |
| 1817 | |
| 1818 | static int _mv88e6xxx_port_fdb_load(struct dsa_switch *ds, int port, |
| 1819 | const unsigned char *addr, u16 vid, |
| 1820 | u8 state) |
| 1821 | { |
| 1822 | struct mv88e6xxx_atu_entry entry = { 0 }; |
| 1823 | int ret; |
| 1824 | |
| 1825 | ret = _mv88e6xxx_port_vid_to_fid(ds, port, vid); |
| 1826 | if (ret < 0) |
| 1827 | return ret; |
| 1828 | |
| 1829 | entry.fid = ret; |
| 1830 | entry.state = state; |
| 1831 | ether_addr_copy(entry.mac, addr); |
| 1832 | if (state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 1833 | entry.trunk = false; |
| 1834 | entry.portv_trunkid = BIT(port); |
| 1835 | } |
| 1836 | |
| 1837 | return _mv88e6xxx_atu_load(ds, &entry); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1840 | int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port, |
| 1841 | const unsigned char *addr, u16 vid) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1842 | { |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1843 | int state = is_multicast_ether_addr(addr) ? |
| 1844 | GLOBAL_ATU_DATA_STATE_MC_STATIC : |
| 1845 | GLOBAL_ATU_DATA_STATE_UC_STATIC; |
| 1846 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 6630e23 | 2015-08-06 01:44:07 -0400 | [diff] [blame] | 1847 | int ret; |
| 1848 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1849 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1850 | ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid, state); |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1851 | mutex_unlock(&ps->smi_mutex); |
| 1852 | |
| 1853 | return ret; |
| 1854 | } |
| 1855 | |
| 1856 | int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, |
| 1857 | const unsigned char *addr, u16 vid) |
| 1858 | { |
| 1859 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1860 | int ret; |
| 1861 | |
| 1862 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1863 | ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid, |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1864 | GLOBAL_ATU_DATA_STATE_UNUSED); |
| 1865 | mutex_unlock(&ps->smi_mutex); |
| 1866 | |
| 1867 | return ret; |
| 1868 | } |
| 1869 | |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1870 | static int _mv88e6xxx_atu_getnext(struct dsa_switch *ds, u16 fid, |
| 1871 | const unsigned char *addr, |
| 1872 | struct mv88e6xxx_atu_entry *entry) |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1873 | { |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1874 | struct mv88e6xxx_atu_entry next = { 0 }; |
| 1875 | int ret; |
| 1876 | |
| 1877 | next.fid = fid; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1878 | |
| 1879 | ret = _mv88e6xxx_atu_wait(ds); |
| 1880 | if (ret < 0) |
| 1881 | return ret; |
| 1882 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 1883 | ret = _mv88e6xxx_atu_mac_write(ds, addr); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1884 | if (ret < 0) |
| 1885 | return ret; |
| 1886 | |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1887 | ret = _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_GET_NEXT_DB); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1888 | if (ret < 0) |
| 1889 | return ret; |
| 1890 | |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1891 | ret = _mv88e6xxx_atu_mac_read(ds, next.mac); |
| 1892 | if (ret < 0) |
| 1893 | return ret; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1894 | |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1895 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA); |
| 1896 | if (ret < 0) |
| 1897 | return ret; |
| 1898 | |
| 1899 | next.state = ret & GLOBAL_ATU_DATA_STATE_MASK; |
| 1900 | if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 1901 | unsigned int mask, shift; |
| 1902 | |
| 1903 | if (ret & GLOBAL_ATU_DATA_TRUNK) { |
| 1904 | next.trunk = true; |
| 1905 | mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK; |
| 1906 | shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT; |
| 1907 | } else { |
| 1908 | next.trunk = false; |
| 1909 | mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK; |
| 1910 | shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT; |
| 1911 | } |
| 1912 | |
| 1913 | next.portv_trunkid = (ret & mask) >> shift; |
| 1914 | } |
| 1915 | |
| 1916 | *entry = next; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1917 | return 0; |
| 1918 | } |
| 1919 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1920 | /* get next entry for port */ |
| 1921 | int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port, |
Vivien Didelot | 2a778e1 | 2015-08-10 09:09:49 -0400 | [diff] [blame] | 1922 | unsigned char *addr, u16 *vid, bool *is_static) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1923 | { |
| 1924 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1925 | struct mv88e6xxx_atu_entry next; |
| 1926 | u16 fid; |
Vivien Didelot | 8782051 | 2015-08-06 01:44:08 -0400 | [diff] [blame] | 1927 | int ret; |
| 1928 | |
| 1929 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1930 | |
| 1931 | ret = _mv88e6xxx_port_vid_to_fid(ds, port, *vid); |
| 1932 | if (ret < 0) |
| 1933 | goto unlock; |
| 1934 | fid = ret; |
| 1935 | |
| 1936 | do { |
| 1937 | if (is_broadcast_ether_addr(addr)) { |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1938 | struct mv88e6xxx_vtu_stu_entry vtu; |
| 1939 | |
| 1940 | ret = _mv88e6xxx_port_vtu_getnext(ds, port, *vid, &vtu); |
| 1941 | if (ret < 0) |
| 1942 | goto unlock; |
| 1943 | |
| 1944 | *vid = vtu.vid; |
| 1945 | fid = vtu.fid; |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | ret = _mv88e6xxx_atu_getnext(ds, fid, addr, &next); |
| 1949 | if (ret < 0) |
| 1950 | goto unlock; |
| 1951 | |
| 1952 | ether_addr_copy(addr, next.mac); |
| 1953 | |
| 1954 | if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED) |
| 1955 | continue; |
| 1956 | } while (next.trunk || (next.portv_trunkid & BIT(port)) == 0); |
| 1957 | |
| 1958 | *is_static = next.state == (is_multicast_ether_addr(addr) ? |
| 1959 | GLOBAL_ATU_DATA_STATE_MC_STATIC : |
| 1960 | GLOBAL_ATU_DATA_STATE_UC_STATIC); |
| 1961 | unlock: |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1962 | mutex_unlock(&ps->smi_mutex); |
| 1963 | |
| 1964 | return ret; |
| 1965 | } |
| 1966 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1967 | static void mv88e6xxx_bridge_work(struct work_struct *work) |
| 1968 | { |
| 1969 | struct mv88e6xxx_priv_state *ps; |
| 1970 | struct dsa_switch *ds; |
| 1971 | int port; |
| 1972 | |
| 1973 | ps = container_of(work, struct mv88e6xxx_priv_state, bridge_work); |
| 1974 | ds = ((struct dsa_switch *)ps) - 1; |
| 1975 | |
| 1976 | while (ps->port_state_update_mask) { |
| 1977 | port = __ffs(ps->port_state_update_mask); |
| 1978 | clear_bit(port, &ps->port_state_update_mask); |
| 1979 | mv88e6xxx_set_port_state(ds, port, ps->port_state[port]); |
| 1980 | } |
| 1981 | } |
| 1982 | |
Andrew Lunn | dbde9e6 | 2015-05-06 01:09:48 +0200 | [diff] [blame] | 1983 | static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 1984 | { |
| 1985 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1986 | int ret, fid; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 1987 | u16 reg; |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 1988 | |
| 1989 | mutex_lock(&ps->smi_mutex); |
| 1990 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 1991 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 1992 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 1993 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 1994 | mv88e6xxx_6065_family(ds) || mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 1995 | /* MAC Forcing register: don't force link, speed, |
| 1996 | * duplex or flow control state to any particular |
| 1997 | * values on physical ports, but force the CPU port |
| 1998 | * and all DSA ports to their maximum bandwidth and |
| 1999 | * full duplex. |
| 2000 | */ |
| 2001 | reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_PCS_CTRL); |
Andrew Lunn | 60045cb | 2015-08-17 23:52:51 +0200 | [diff] [blame] | 2002 | 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] | 2003 | reg &= ~PORT_PCS_CTRL_UNFORCED; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2004 | reg |= PORT_PCS_CTRL_FORCE_LINK | |
| 2005 | PORT_PCS_CTRL_LINK_UP | |
| 2006 | PORT_PCS_CTRL_DUPLEX_FULL | |
| 2007 | PORT_PCS_CTRL_FORCE_DUPLEX; |
| 2008 | if (mv88e6xxx_6065_family(ds)) |
| 2009 | reg |= PORT_PCS_CTRL_100; |
| 2010 | else |
| 2011 | reg |= PORT_PCS_CTRL_1000; |
| 2012 | } else { |
| 2013 | reg |= PORT_PCS_CTRL_UNFORCED; |
| 2014 | } |
| 2015 | |
| 2016 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2017 | PORT_PCS_CTRL, reg); |
| 2018 | if (ret) |
| 2019 | goto abort; |
| 2020 | } |
| 2021 | |
| 2022 | /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock, |
| 2023 | * disable Header mode, enable IGMP/MLD snooping, disable VLAN |
| 2024 | * tunneling, determine priority by looking at 802.1p and IP |
| 2025 | * priority fields (IP prio has precedence), and set STP state |
| 2026 | * to Forwarding. |
| 2027 | * |
| 2028 | * If this is the CPU link, use DSA or EDSA tagging depending |
| 2029 | * on which tagging mode was configured. |
| 2030 | * |
| 2031 | * If this is a link to another switch, use DSA tagging mode. |
| 2032 | * |
| 2033 | * If this is the upstream port for this switch, enable |
| 2034 | * forwarding of unknown unicasts and multicasts. |
| 2035 | */ |
| 2036 | reg = 0; |
| 2037 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2038 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2039 | mv88e6xxx_6095_family(ds) || mv88e6xxx_6065_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2040 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6320_family(ds)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2041 | reg = PORT_CONTROL_IGMP_MLD_SNOOP | |
| 2042 | PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP | |
| 2043 | PORT_CONTROL_STATE_FORWARDING; |
| 2044 | if (dsa_is_cpu_port(ds, port)) { |
| 2045 | if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds)) |
| 2046 | reg |= PORT_CONTROL_DSA_TAG; |
| 2047 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2048 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2049 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2050 | if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA) |
| 2051 | reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA; |
| 2052 | else |
| 2053 | reg |= PORT_CONTROL_FRAME_MODE_DSA; |
Andrew Lunn | c047a1f | 2015-09-29 01:50:56 +0200 | [diff] [blame^] | 2054 | reg |= PORT_CONTROL_FORWARD_UNKNOWN | |
| 2055 | PORT_CONTROL_FORWARD_UNKNOWN_MC; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2059 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2060 | mv88e6xxx_6095_family(ds) || mv88e6xxx_6065_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2061 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2062 | if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA) |
| 2063 | reg |= PORT_CONTROL_EGRESS_ADD_TAG; |
| 2064 | } |
| 2065 | } |
Andrew Lunn | 6083ce7 | 2015-08-17 23:52:52 +0200 | [diff] [blame] | 2066 | if (dsa_is_dsa_port(ds, port)) { |
| 2067 | if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds)) |
| 2068 | reg |= PORT_CONTROL_DSA_TAG; |
| 2069 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2070 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2071 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2072 | reg |= PORT_CONTROL_FRAME_MODE_DSA; |
Andrew Lunn | 6083ce7 | 2015-08-17 23:52:52 +0200 | [diff] [blame] | 2073 | } |
| 2074 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2075 | if (port == dsa_upstream_port(ds)) |
| 2076 | reg |= PORT_CONTROL_FORWARD_UNKNOWN | |
| 2077 | PORT_CONTROL_FORWARD_UNKNOWN_MC; |
| 2078 | } |
| 2079 | if (reg) { |
| 2080 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2081 | PORT_CONTROL, reg); |
| 2082 | if (ret) |
| 2083 | goto abort; |
| 2084 | } |
| 2085 | |
Vivien Didelot | 8efdda4 | 2015-08-13 12:52:23 -0400 | [diff] [blame] | 2086 | /* Port Control 2: don't force a good FCS, set the maximum frame size to |
| 2087 | * 10240 bytes, enable secure 802.1q tags, don't discard tagged or |
| 2088 | * untagged frames on this port, do a destination address lookup on all |
| 2089 | * received packets as usual, disable ARP mirroring and don't send a |
| 2090 | * copy of all transmitted/received frames on this port to the CPU. |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2091 | */ |
| 2092 | reg = 0; |
| 2093 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2094 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2095 | mv88e6xxx_6095_family(ds) || mv88e6xxx_6320_family(ds)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2096 | reg = PORT_CONTROL_2_MAP_DA; |
| 2097 | |
| 2098 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2099 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6320_family(ds)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2100 | reg |= PORT_CONTROL_2_JUMBO_10240; |
| 2101 | |
| 2102 | if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds)) { |
| 2103 | /* Set the upstream port this port should use */ |
| 2104 | reg |= dsa_upstream_port(ds); |
| 2105 | /* enable forwarding of unknown multicast addresses to |
| 2106 | * the upstream port |
| 2107 | */ |
| 2108 | if (port == dsa_upstream_port(ds)) |
| 2109 | reg |= PORT_CONTROL_2_FORWARD_UNKNOWN; |
| 2110 | } |
| 2111 | |
Vivien Didelot | f5117ce | 2015-08-19 18:54:55 -0400 | [diff] [blame] | 2112 | reg |= PORT_CONTROL_2_8021Q_FALLBACK; |
Vivien Didelot | 8efdda4 | 2015-08-13 12:52:23 -0400 | [diff] [blame] | 2113 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2114 | if (reg) { |
| 2115 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2116 | PORT_CONTROL_2, reg); |
| 2117 | if (ret) |
| 2118 | goto abort; |
| 2119 | } |
| 2120 | |
| 2121 | /* Port Association Vector: when learning source addresses |
| 2122 | * of packets, add the address to the address database using |
| 2123 | * a port bitmap that has only the bit for this port set and |
| 2124 | * the other bits clear. |
| 2125 | */ |
| 2126 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_ASSOC_VECTOR, |
| 2127 | 1 << port); |
| 2128 | if (ret) |
| 2129 | goto abort; |
| 2130 | |
| 2131 | /* Egress rate control 2: disable egress rate control. */ |
| 2132 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_RATE_CONTROL_2, |
| 2133 | 0x0000); |
| 2134 | if (ret) |
| 2135 | goto abort; |
| 2136 | |
| 2137 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2138 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2139 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2140 | /* Do not limit the period of time that this port can |
| 2141 | * be paused for by the remote end or the period of |
| 2142 | * time that this port can pause the remote end. |
| 2143 | */ |
| 2144 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2145 | PORT_PAUSE_CTRL, 0x0000); |
| 2146 | if (ret) |
| 2147 | goto abort; |
| 2148 | |
| 2149 | /* Port ATU control: disable limiting the number of |
| 2150 | * address database entries that this port is allowed |
| 2151 | * to use. |
| 2152 | */ |
| 2153 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2154 | PORT_ATU_CONTROL, 0x0000); |
| 2155 | /* Priority Override: disable DA, SA and VTU priority |
| 2156 | * override. |
| 2157 | */ |
| 2158 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2159 | PORT_PRI_OVERRIDE, 0x0000); |
| 2160 | if (ret) |
| 2161 | goto abort; |
| 2162 | |
| 2163 | /* Port Ethertype: use the Ethertype DSA Ethertype |
| 2164 | * value. |
| 2165 | */ |
| 2166 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2167 | PORT_ETH_TYPE, ETH_P_EDSA); |
| 2168 | if (ret) |
| 2169 | goto abort; |
| 2170 | /* Tag Remap: use an identity 802.1p prio -> switch |
| 2171 | * prio mapping. |
| 2172 | */ |
| 2173 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2174 | PORT_TAG_REGMAP_0123, 0x3210); |
| 2175 | if (ret) |
| 2176 | goto abort; |
| 2177 | |
| 2178 | /* Tag Remap 2: use an identity 802.1p prio -> switch |
| 2179 | * prio mapping. |
| 2180 | */ |
| 2181 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2182 | PORT_TAG_REGMAP_4567, 0x7654); |
| 2183 | if (ret) |
| 2184 | goto abort; |
| 2185 | } |
| 2186 | |
| 2187 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2188 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2189 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) || |
| 2190 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2191 | /* Rate Control: disable ingress rate limiting. */ |
| 2192 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2193 | PORT_RATE_CONTROL, 0x0001); |
| 2194 | if (ret) |
| 2195 | goto abort; |
| 2196 | } |
| 2197 | |
Guenter Roeck | 366f0a0 | 2015-03-26 18:36:30 -0700 | [diff] [blame] | 2198 | /* Port Control 1: disable trunking, disable sending |
| 2199 | * learning messages to this port. |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2200 | */ |
Vivien Didelot | 614f03f | 2015-04-20 17:19:23 -0400 | [diff] [blame] | 2201 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL_1, 0x0000); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2202 | if (ret) |
| 2203 | goto abort; |
| 2204 | |
| 2205 | /* Port based VLAN map: give each port its own address |
| 2206 | * database, allow the CPU port to talk to each of the 'real' |
| 2207 | * ports, and allow each of the 'real' ports to only talk to |
| 2208 | * the upstream port. |
| 2209 | */ |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 2210 | fid = port + 1; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2211 | ps->fid[port] = fid; |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 2212 | set_bit(fid, ps->fid_bitmap); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2213 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2214 | if (!dsa_is_cpu_port(ds, port)) |
| 2215 | ps->bridge_mask[fid] = 1 << port; |
| 2216 | |
| 2217 | ret = _mv88e6xxx_update_port_config(ds, port); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2218 | if (ret) |
| 2219 | goto abort; |
| 2220 | |
| 2221 | /* Default VLAN ID and priority: don't set a default VLAN |
| 2222 | * ID, and set the default packet priority to zero. |
| 2223 | */ |
Vivien Didelot | 47cf1e65 | 2015-04-20 17:43:26 -0400 | [diff] [blame] | 2224 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_DEFAULT_VLAN, |
| 2225 | 0x0000); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2226 | abort: |
| 2227 | mutex_unlock(&ps->smi_mutex); |
| 2228 | return ret; |
| 2229 | } |
| 2230 | |
Andrew Lunn | dbde9e6 | 2015-05-06 01:09:48 +0200 | [diff] [blame] | 2231 | int mv88e6xxx_setup_ports(struct dsa_switch *ds) |
| 2232 | { |
| 2233 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2234 | int ret; |
| 2235 | int i; |
| 2236 | |
| 2237 | for (i = 0; i < ps->num_ports; i++) { |
| 2238 | ret = mv88e6xxx_setup_port(ds, i); |
| 2239 | if (ret < 0) |
| 2240 | return ret; |
| 2241 | } |
| 2242 | return 0; |
| 2243 | } |
| 2244 | |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 2245 | static int mv88e6xxx_regs_show(struct seq_file *s, void *p) |
| 2246 | { |
| 2247 | struct dsa_switch *ds = s->private; |
| 2248 | |
| 2249 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2250 | int reg, port; |
| 2251 | |
| 2252 | seq_puts(s, " GLOBAL GLOBAL2 "); |
| 2253 | for (port = 0 ; port < ps->num_ports; port++) |
| 2254 | seq_printf(s, " %2d ", port); |
| 2255 | seq_puts(s, "\n"); |
| 2256 | |
| 2257 | for (reg = 0; reg < 32; reg++) { |
| 2258 | seq_printf(s, "%2x: ", reg); |
| 2259 | seq_printf(s, " %4x %4x ", |
| 2260 | mv88e6xxx_reg_read(ds, REG_GLOBAL, reg), |
| 2261 | mv88e6xxx_reg_read(ds, REG_GLOBAL2, reg)); |
| 2262 | |
| 2263 | for (port = 0 ; port < ps->num_ports; port++) |
| 2264 | seq_printf(s, "%4x ", |
| 2265 | mv88e6xxx_reg_read(ds, REG_PORT(port), reg)); |
| 2266 | seq_puts(s, "\n"); |
| 2267 | } |
| 2268 | |
| 2269 | return 0; |
| 2270 | } |
| 2271 | |
| 2272 | static int mv88e6xxx_regs_open(struct inode *inode, struct file *file) |
| 2273 | { |
| 2274 | return single_open(file, mv88e6xxx_regs_show, inode->i_private); |
| 2275 | } |
| 2276 | |
| 2277 | static const struct file_operations mv88e6xxx_regs_fops = { |
| 2278 | .open = mv88e6xxx_regs_open, |
| 2279 | .read = seq_read, |
| 2280 | .llseek = no_llseek, |
| 2281 | .release = single_release, |
| 2282 | .owner = THIS_MODULE, |
| 2283 | }; |
| 2284 | |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2285 | static void mv88e6xxx_atu_show_header(struct seq_file *s) |
| 2286 | { |
| 2287 | seq_puts(s, "DB T/P Vec State Addr\n"); |
| 2288 | } |
| 2289 | |
| 2290 | static void mv88e6xxx_atu_show_entry(struct seq_file *s, int dbnum, |
| 2291 | unsigned char *addr, int data) |
| 2292 | { |
| 2293 | bool trunk = !!(data & GLOBAL_ATU_DATA_TRUNK); |
| 2294 | int portvec = ((data & GLOBAL_ATU_DATA_PORT_VECTOR_MASK) >> |
| 2295 | GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT); |
| 2296 | int state = data & GLOBAL_ATU_DATA_STATE_MASK; |
| 2297 | |
| 2298 | seq_printf(s, "%03x %5s %10pb %x %pM\n", |
| 2299 | dbnum, (trunk ? "Trunk" : "Port"), &portvec, state, addr); |
| 2300 | } |
| 2301 | |
| 2302 | static int mv88e6xxx_atu_show_db(struct seq_file *s, struct dsa_switch *ds, |
| 2303 | int dbnum) |
| 2304 | { |
| 2305 | unsigned char bcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 2306 | unsigned char addr[6]; |
| 2307 | int ret, data, state; |
| 2308 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 2309 | ret = _mv88e6xxx_atu_mac_write(ds, bcast); |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2310 | if (ret < 0) |
| 2311 | return ret; |
| 2312 | |
| 2313 | do { |
| 2314 | ret = _mv88e6xxx_atu_cmd(ds, dbnum, GLOBAL_ATU_OP_GET_NEXT_DB); |
| 2315 | if (ret < 0) |
| 2316 | return ret; |
| 2317 | data = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA); |
| 2318 | if (data < 0) |
| 2319 | return data; |
| 2320 | |
| 2321 | state = data & GLOBAL_ATU_DATA_STATE_MASK; |
| 2322 | if (state == GLOBAL_ATU_DATA_STATE_UNUSED) |
| 2323 | break; |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 2324 | ret = _mv88e6xxx_atu_mac_read(ds, addr); |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2325 | if (ret < 0) |
| 2326 | return ret; |
| 2327 | mv88e6xxx_atu_show_entry(s, dbnum, addr, data); |
| 2328 | } while (state != GLOBAL_ATU_DATA_STATE_UNUSED); |
| 2329 | |
| 2330 | return 0; |
| 2331 | } |
| 2332 | |
| 2333 | static int mv88e6xxx_atu_show(struct seq_file *s, void *p) |
| 2334 | { |
| 2335 | struct dsa_switch *ds = s->private; |
| 2336 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2337 | int dbnum; |
| 2338 | |
| 2339 | mv88e6xxx_atu_show_header(s); |
| 2340 | |
| 2341 | for (dbnum = 0; dbnum < 255; dbnum++) { |
| 2342 | mutex_lock(&ps->smi_mutex); |
| 2343 | mv88e6xxx_atu_show_db(s, ds, dbnum); |
| 2344 | mutex_unlock(&ps->smi_mutex); |
| 2345 | } |
| 2346 | |
| 2347 | return 0; |
| 2348 | } |
| 2349 | |
| 2350 | static int mv88e6xxx_atu_open(struct inode *inode, struct file *file) |
| 2351 | { |
| 2352 | return single_open(file, mv88e6xxx_atu_show, inode->i_private); |
| 2353 | } |
| 2354 | |
| 2355 | static const struct file_operations mv88e6xxx_atu_fops = { |
| 2356 | .open = mv88e6xxx_atu_open, |
| 2357 | .read = seq_read, |
| 2358 | .llseek = no_llseek, |
| 2359 | .release = single_release, |
| 2360 | .owner = THIS_MODULE, |
| 2361 | }; |
| 2362 | |
Andrew Lunn | 532c7a3 | 2015-06-20 18:42:31 +0200 | [diff] [blame] | 2363 | static void mv88e6xxx_stats_show_header(struct seq_file *s, |
| 2364 | struct mv88e6xxx_priv_state *ps) |
| 2365 | { |
| 2366 | int port; |
| 2367 | |
| 2368 | seq_puts(s, " Statistic "); |
| 2369 | for (port = 0 ; port < ps->num_ports; port++) |
| 2370 | seq_printf(s, "Port %2d ", port); |
| 2371 | seq_puts(s, "\n"); |
| 2372 | } |
| 2373 | |
| 2374 | static int mv88e6xxx_stats_show(struct seq_file *s, void *p) |
| 2375 | { |
| 2376 | struct dsa_switch *ds = s->private; |
| 2377 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2378 | struct mv88e6xxx_hw_stat *stats = mv88e6xxx_hw_stats; |
| 2379 | int port, stat, max_stats; |
| 2380 | uint64_t value; |
| 2381 | |
| 2382 | if (have_sw_in_discards(ds)) |
| 2383 | max_stats = ARRAY_SIZE(mv88e6xxx_hw_stats); |
| 2384 | else |
| 2385 | max_stats = ARRAY_SIZE(mv88e6xxx_hw_stats) - 3; |
| 2386 | |
| 2387 | mv88e6xxx_stats_show_header(s, ps); |
| 2388 | |
| 2389 | mutex_lock(&ps->smi_mutex); |
| 2390 | |
| 2391 | for (stat = 0; stat < max_stats; stat++) { |
| 2392 | seq_printf(s, "%19s: ", stats[stat].string); |
| 2393 | for (port = 0 ; port < ps->num_ports; port++) { |
| 2394 | _mv88e6xxx_stats_snapshot(ds, port); |
| 2395 | value = _mv88e6xxx_get_ethtool_stat(ds, stat, stats, |
| 2396 | port); |
| 2397 | seq_printf(s, "%8llu ", value); |
| 2398 | } |
| 2399 | seq_puts(s, "\n"); |
| 2400 | } |
| 2401 | mutex_unlock(&ps->smi_mutex); |
| 2402 | |
| 2403 | return 0; |
| 2404 | } |
| 2405 | |
| 2406 | static int mv88e6xxx_stats_open(struct inode *inode, struct file *file) |
| 2407 | { |
| 2408 | return single_open(file, mv88e6xxx_stats_show, inode->i_private); |
| 2409 | } |
| 2410 | |
| 2411 | static const struct file_operations mv88e6xxx_stats_fops = { |
| 2412 | .open = mv88e6xxx_stats_open, |
| 2413 | .read = seq_read, |
| 2414 | .llseek = no_llseek, |
| 2415 | .release = single_release, |
| 2416 | .owner = THIS_MODULE, |
| 2417 | }; |
| 2418 | |
Andrew Lunn | d35bd87 | 2015-06-20 18:42:32 +0200 | [diff] [blame] | 2419 | static int mv88e6xxx_device_map_show(struct seq_file *s, void *p) |
| 2420 | { |
| 2421 | struct dsa_switch *ds = s->private; |
| 2422 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2423 | int target, ret; |
| 2424 | |
| 2425 | seq_puts(s, "Target Port\n"); |
| 2426 | |
| 2427 | mutex_lock(&ps->smi_mutex); |
| 2428 | for (target = 0; target < 32; target++) { |
| 2429 | ret = _mv88e6xxx_reg_write( |
| 2430 | ds, REG_GLOBAL2, GLOBAL2_DEVICE_MAPPING, |
| 2431 | target << GLOBAL2_DEVICE_MAPPING_TARGET_SHIFT); |
| 2432 | if (ret < 0) |
| 2433 | goto out; |
| 2434 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL2, |
| 2435 | GLOBAL2_DEVICE_MAPPING); |
| 2436 | seq_printf(s, " %2d %2d\n", target, |
| 2437 | ret & GLOBAL2_DEVICE_MAPPING_PORT_MASK); |
| 2438 | } |
| 2439 | out: |
| 2440 | mutex_unlock(&ps->smi_mutex); |
| 2441 | |
| 2442 | return 0; |
| 2443 | } |
| 2444 | |
| 2445 | static int mv88e6xxx_device_map_open(struct inode *inode, struct file *file) |
| 2446 | { |
| 2447 | return single_open(file, mv88e6xxx_device_map_show, inode->i_private); |
| 2448 | } |
| 2449 | |
| 2450 | static const struct file_operations mv88e6xxx_device_map_fops = { |
| 2451 | .open = mv88e6xxx_device_map_open, |
| 2452 | .read = seq_read, |
| 2453 | .llseek = no_llseek, |
| 2454 | .release = single_release, |
| 2455 | .owner = THIS_MODULE, |
| 2456 | }; |
| 2457 | |
Andrew Lunn | 56d95e2 | 2015-06-20 18:42:33 +0200 | [diff] [blame] | 2458 | static int mv88e6xxx_scratch_show(struct seq_file *s, void *p) |
| 2459 | { |
| 2460 | struct dsa_switch *ds = s->private; |
| 2461 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2462 | int reg, ret; |
| 2463 | |
| 2464 | seq_puts(s, "Register Value\n"); |
| 2465 | |
| 2466 | mutex_lock(&ps->smi_mutex); |
| 2467 | for (reg = 0; reg < 0x80; reg++) { |
| 2468 | ret = _mv88e6xxx_reg_write( |
| 2469 | ds, REG_GLOBAL2, GLOBAL2_SCRATCH_MISC, |
| 2470 | reg << GLOBAL2_SCRATCH_REGISTER_SHIFT); |
| 2471 | if (ret < 0) |
| 2472 | goto out; |
| 2473 | |
| 2474 | ret = _mv88e6xxx_scratch_wait(ds); |
| 2475 | if (ret < 0) |
| 2476 | goto out; |
| 2477 | |
| 2478 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL2, |
| 2479 | GLOBAL2_SCRATCH_MISC); |
| 2480 | seq_printf(s, " %2x %2x\n", reg, |
| 2481 | ret & GLOBAL2_SCRATCH_VALUE_MASK); |
| 2482 | } |
| 2483 | out: |
| 2484 | mutex_unlock(&ps->smi_mutex); |
| 2485 | |
| 2486 | return 0; |
| 2487 | } |
| 2488 | |
| 2489 | static int mv88e6xxx_scratch_open(struct inode *inode, struct file *file) |
| 2490 | { |
| 2491 | return single_open(file, mv88e6xxx_scratch_show, inode->i_private); |
| 2492 | } |
| 2493 | |
| 2494 | static const struct file_operations mv88e6xxx_scratch_fops = { |
| 2495 | .open = mv88e6xxx_scratch_open, |
| 2496 | .read = seq_read, |
| 2497 | .llseek = no_llseek, |
| 2498 | .release = single_release, |
| 2499 | .owner = THIS_MODULE, |
| 2500 | }; |
| 2501 | |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2502 | int mv88e6xxx_setup_common(struct dsa_switch *ds) |
| 2503 | { |
| 2504 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 2505 | char *name; |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2506 | |
| 2507 | mutex_init(&ps->smi_mutex); |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2508 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 2509 | ps->id = REG_READ(REG_PORT(0), PORT_SWITCH_ID) & 0xfff0; |
Andrew Lunn | a8f064c | 2015-03-26 18:36:40 -0700 | [diff] [blame] | 2510 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2511 | INIT_WORK(&ps->bridge_work, mv88e6xxx_bridge_work); |
| 2512 | |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 2513 | name = kasprintf(GFP_KERNEL, "dsa%d", ds->index); |
| 2514 | ps->dbgfs = debugfs_create_dir(name, NULL); |
| 2515 | kfree(name); |
| 2516 | |
| 2517 | debugfs_create_file("regs", S_IRUGO, ps->dbgfs, ds, |
| 2518 | &mv88e6xxx_regs_fops); |
| 2519 | |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2520 | debugfs_create_file("atu", S_IRUGO, ps->dbgfs, ds, |
| 2521 | &mv88e6xxx_atu_fops); |
| 2522 | |
Andrew Lunn | 532c7a3 | 2015-06-20 18:42:31 +0200 | [diff] [blame] | 2523 | debugfs_create_file("stats", S_IRUGO, ps->dbgfs, ds, |
| 2524 | &mv88e6xxx_stats_fops); |
| 2525 | |
Andrew Lunn | d35bd87 | 2015-06-20 18:42:32 +0200 | [diff] [blame] | 2526 | debugfs_create_file("device_map", S_IRUGO, ps->dbgfs, ds, |
| 2527 | &mv88e6xxx_device_map_fops); |
Andrew Lunn | 56d95e2 | 2015-06-20 18:42:33 +0200 | [diff] [blame] | 2528 | |
| 2529 | debugfs_create_file("scratch", S_IRUGO, ps->dbgfs, ds, |
| 2530 | &mv88e6xxx_scratch_fops); |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2531 | return 0; |
| 2532 | } |
| 2533 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2534 | int mv88e6xxx_setup_global(struct dsa_switch *ds) |
| 2535 | { |
| 2536 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2537 | int ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2538 | int i; |
| 2539 | |
| 2540 | /* Set the default address aging time to 5 minutes, and |
| 2541 | * enable address learn messages to be sent to all message |
| 2542 | * ports. |
| 2543 | */ |
| 2544 | REG_WRITE(REG_GLOBAL, GLOBAL_ATU_CONTROL, |
| 2545 | 0x0140 | GLOBAL_ATU_CONTROL_LEARN2ALL); |
| 2546 | |
| 2547 | /* Configure the IP ToS mapping registers. */ |
| 2548 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_0, 0x0000); |
| 2549 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_1, 0x0000); |
| 2550 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_2, 0x5555); |
| 2551 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_3, 0x5555); |
| 2552 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_4, 0xaaaa); |
| 2553 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_5, 0xaaaa); |
| 2554 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_6, 0xffff); |
| 2555 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_7, 0xffff); |
| 2556 | |
| 2557 | /* Configure the IEEE 802.1p priority mapping register. */ |
| 2558 | REG_WRITE(REG_GLOBAL, GLOBAL_IEEE_PRI, 0xfa41); |
| 2559 | |
| 2560 | /* Send all frames with destination addresses matching |
| 2561 | * 01:80:c2:00:00:0x to the CPU port. |
| 2562 | */ |
| 2563 | REG_WRITE(REG_GLOBAL2, GLOBAL2_MGMT_EN_0X, 0xffff); |
| 2564 | |
| 2565 | /* Ignore removed tag data on doubly tagged packets, disable |
| 2566 | * flow control messages, force flow control priority to the |
| 2567 | * highest, and send all special multicast frames to the CPU |
| 2568 | * port at the highest priority. |
| 2569 | */ |
| 2570 | REG_WRITE(REG_GLOBAL2, GLOBAL2_SWITCH_MGMT, |
| 2571 | 0x7 | GLOBAL2_SWITCH_MGMT_RSVD2CPU | 0x70 | |
| 2572 | GLOBAL2_SWITCH_MGMT_FORCE_FLOW_CTRL_PRI); |
| 2573 | |
| 2574 | /* Program the DSA routing table. */ |
| 2575 | for (i = 0; i < 32; i++) { |
| 2576 | int nexthop = 0x1f; |
| 2577 | |
| 2578 | if (ds->pd->rtable && |
| 2579 | i != ds->index && i < ds->dst->pd->nr_chips) |
| 2580 | nexthop = ds->pd->rtable[i] & 0x1f; |
| 2581 | |
| 2582 | REG_WRITE(REG_GLOBAL2, GLOBAL2_DEVICE_MAPPING, |
| 2583 | GLOBAL2_DEVICE_MAPPING_UPDATE | |
| 2584 | (i << GLOBAL2_DEVICE_MAPPING_TARGET_SHIFT) | |
| 2585 | nexthop); |
| 2586 | } |
| 2587 | |
| 2588 | /* Clear all trunk masks. */ |
| 2589 | for (i = 0; i < 8; i++) |
| 2590 | REG_WRITE(REG_GLOBAL2, GLOBAL2_TRUNK_MASK, |
| 2591 | 0x8000 | (i << GLOBAL2_TRUNK_MASK_NUM_SHIFT) | |
| 2592 | ((1 << ps->num_ports) - 1)); |
| 2593 | |
| 2594 | /* Clear all trunk mappings. */ |
| 2595 | for (i = 0; i < 16; i++) |
| 2596 | REG_WRITE(REG_GLOBAL2, GLOBAL2_TRUNK_MAPPING, |
| 2597 | GLOBAL2_TRUNK_MAPPING_UPDATE | |
| 2598 | (i << GLOBAL2_TRUNK_MAPPING_ID_SHIFT)); |
| 2599 | |
| 2600 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2601 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2602 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2603 | /* Send all frames with destination addresses matching |
| 2604 | * 01:80:c2:00:00:2x to the CPU port. |
| 2605 | */ |
| 2606 | REG_WRITE(REG_GLOBAL2, GLOBAL2_MGMT_EN_2X, 0xffff); |
| 2607 | |
| 2608 | /* Initialise cross-chip port VLAN table to reset |
| 2609 | * defaults. |
| 2610 | */ |
| 2611 | REG_WRITE(REG_GLOBAL2, GLOBAL2_PVT_ADDR, 0x9000); |
| 2612 | |
| 2613 | /* Clear the priority override table. */ |
| 2614 | for (i = 0; i < 16; i++) |
| 2615 | REG_WRITE(REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE, |
| 2616 | 0x8000 | (i << 8)); |
| 2617 | } |
| 2618 | |
| 2619 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2620 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2621 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) || |
| 2622 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2623 | /* Disable ingress rate limiting by resetting all |
| 2624 | * ingress rate limit registers to their initial |
| 2625 | * state. |
| 2626 | */ |
| 2627 | for (i = 0; i < ps->num_ports; i++) |
| 2628 | REG_WRITE(REG_GLOBAL2, GLOBAL2_INGRESS_OP, |
| 2629 | 0x9000 | (i << 8)); |
| 2630 | } |
| 2631 | |
Andrew Lunn | db687a5 | 2015-06-20 21:31:29 +0200 | [diff] [blame] | 2632 | /* Clear the statistics counters for all ports */ |
| 2633 | REG_WRITE(REG_GLOBAL, GLOBAL_STATS_OP, GLOBAL_STATS_OP_FLUSH_ALL); |
| 2634 | |
| 2635 | /* Wait for the flush to complete. */ |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2636 | mutex_lock(&ps->smi_mutex); |
| 2637 | ret = _mv88e6xxx_stats_wait(ds); |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 2638 | if (ret < 0) |
| 2639 | goto unlock; |
| 2640 | |
| 2641 | /* Clear all the VTU and STU entries */ |
| 2642 | ret = _mv88e6xxx_vtu_stu_flush(ds); |
| 2643 | unlock: |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2644 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | db687a5 | 2015-06-20 21:31:29 +0200 | [diff] [blame] | 2645 | |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2646 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2647 | } |
| 2648 | |
Andrew Lunn | 143a830 | 2015-04-02 04:06:34 +0200 | [diff] [blame] | 2649 | int mv88e6xxx_switch_reset(struct dsa_switch *ds, bool ppu_active) |
| 2650 | { |
| 2651 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2652 | u16 is_reset = (ppu_active ? 0x8800 : 0xc800); |
| 2653 | unsigned long timeout; |
| 2654 | int ret; |
| 2655 | int i; |
| 2656 | |
| 2657 | /* Set all ports to the disabled state. */ |
| 2658 | for (i = 0; i < ps->num_ports; i++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 2659 | ret = REG_READ(REG_PORT(i), PORT_CONTROL); |
| 2660 | REG_WRITE(REG_PORT(i), PORT_CONTROL, ret & 0xfffc); |
Andrew Lunn | 143a830 | 2015-04-02 04:06:34 +0200 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | /* Wait for transmit queues to drain. */ |
| 2664 | usleep_range(2000, 4000); |
| 2665 | |
| 2666 | /* Reset the switch. Keep the PPU active if requested. The PPU |
| 2667 | * needs to be active to support indirect phy register access |
| 2668 | * through global registers 0x18 and 0x19. |
| 2669 | */ |
| 2670 | if (ppu_active) |
| 2671 | REG_WRITE(REG_GLOBAL, 0x04, 0xc000); |
| 2672 | else |
| 2673 | REG_WRITE(REG_GLOBAL, 0x04, 0xc400); |
| 2674 | |
| 2675 | /* Wait up to one second for reset to complete. */ |
| 2676 | timeout = jiffies + 1 * HZ; |
| 2677 | while (time_before(jiffies, timeout)) { |
| 2678 | ret = REG_READ(REG_GLOBAL, 0x00); |
| 2679 | if ((ret & is_reset) == is_reset) |
| 2680 | break; |
| 2681 | usleep_range(1000, 2000); |
| 2682 | } |
| 2683 | if (time_after(jiffies, timeout)) |
| 2684 | return -ETIMEDOUT; |
| 2685 | |
| 2686 | return 0; |
| 2687 | } |
| 2688 | |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2689 | int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg) |
| 2690 | { |
| 2691 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2692 | int ret; |
| 2693 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2694 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2695 | ret = _mv88e6xxx_phy_write_indirect(ds, port, 0x16, page); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2696 | if (ret < 0) |
| 2697 | goto error; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2698 | ret = _mv88e6xxx_phy_read_indirect(ds, port, reg); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2699 | error: |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2700 | _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2701 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2702 | return ret; |
| 2703 | } |
| 2704 | |
| 2705 | int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page, |
| 2706 | int reg, int val) |
| 2707 | { |
| 2708 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2709 | int ret; |
| 2710 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2711 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2712 | ret = _mv88e6xxx_phy_write_indirect(ds, port, 0x16, page); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2713 | if (ret < 0) |
| 2714 | goto error; |
| 2715 | |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2716 | ret = _mv88e6xxx_phy_write_indirect(ds, port, reg, val); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2717 | error: |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2718 | _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2719 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2720 | return ret; |
| 2721 | } |
| 2722 | |
| 2723 | static int mv88e6xxx_port_to_phy_addr(struct dsa_switch *ds, int port) |
| 2724 | { |
| 2725 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2726 | |
| 2727 | if (port >= 0 && port < ps->num_ports) |
| 2728 | return port; |
| 2729 | return -EINVAL; |
| 2730 | } |
| 2731 | |
| 2732 | int |
| 2733 | mv88e6xxx_phy_read(struct dsa_switch *ds, int port, int regnum) |
| 2734 | { |
| 2735 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2736 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2737 | int ret; |
| 2738 | |
| 2739 | if (addr < 0) |
| 2740 | return addr; |
| 2741 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2742 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2743 | ret = _mv88e6xxx_phy_read(ds, addr, regnum); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2744 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2745 | return ret; |
| 2746 | } |
| 2747 | |
| 2748 | int |
| 2749 | mv88e6xxx_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val) |
| 2750 | { |
| 2751 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2752 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2753 | int ret; |
| 2754 | |
| 2755 | if (addr < 0) |
| 2756 | return addr; |
| 2757 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2758 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2759 | ret = _mv88e6xxx_phy_write(ds, addr, regnum, val); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2760 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2761 | return ret; |
| 2762 | } |
| 2763 | |
| 2764 | int |
| 2765 | mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int port, int regnum) |
| 2766 | { |
| 2767 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2768 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2769 | int ret; |
| 2770 | |
| 2771 | if (addr < 0) |
| 2772 | return addr; |
| 2773 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2774 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2775 | ret = _mv88e6xxx_phy_read_indirect(ds, addr, regnum); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2776 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2777 | return ret; |
| 2778 | } |
| 2779 | |
| 2780 | int |
| 2781 | mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int port, int regnum, |
| 2782 | u16 val) |
| 2783 | { |
| 2784 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2785 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2786 | int ret; |
| 2787 | |
| 2788 | if (addr < 0) |
| 2789 | return addr; |
| 2790 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2791 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2792 | ret = _mv88e6xxx_phy_write_indirect(ds, addr, regnum, val); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2793 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2794 | return ret; |
| 2795 | } |
| 2796 | |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 2797 | #ifdef CONFIG_NET_DSA_HWMON |
| 2798 | |
| 2799 | static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp) |
| 2800 | { |
| 2801 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2802 | int ret; |
| 2803 | int val; |
| 2804 | |
| 2805 | *temp = 0; |
| 2806 | |
| 2807 | mutex_lock(&ps->smi_mutex); |
| 2808 | |
| 2809 | ret = _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x6); |
| 2810 | if (ret < 0) |
| 2811 | goto error; |
| 2812 | |
| 2813 | /* Enable temperature sensor */ |
| 2814 | ret = _mv88e6xxx_phy_read(ds, 0x0, 0x1a); |
| 2815 | if (ret < 0) |
| 2816 | goto error; |
| 2817 | |
| 2818 | ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret | (1 << 5)); |
| 2819 | if (ret < 0) |
| 2820 | goto error; |
| 2821 | |
| 2822 | /* Wait for temperature to stabilize */ |
| 2823 | usleep_range(10000, 12000); |
| 2824 | |
| 2825 | val = _mv88e6xxx_phy_read(ds, 0x0, 0x1a); |
| 2826 | if (val < 0) { |
| 2827 | ret = val; |
| 2828 | goto error; |
| 2829 | } |
| 2830 | |
| 2831 | /* Disable temperature sensor */ |
| 2832 | ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret & ~(1 << 5)); |
| 2833 | if (ret < 0) |
| 2834 | goto error; |
| 2835 | |
| 2836 | *temp = ((val & 0x1f) - 5) * 5; |
| 2837 | |
| 2838 | error: |
| 2839 | _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x0); |
| 2840 | mutex_unlock(&ps->smi_mutex); |
| 2841 | return ret; |
| 2842 | } |
| 2843 | |
| 2844 | static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp) |
| 2845 | { |
| 2846 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2847 | int ret; |
| 2848 | |
| 2849 | *temp = 0; |
| 2850 | |
| 2851 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 27); |
| 2852 | if (ret < 0) |
| 2853 | return ret; |
| 2854 | |
| 2855 | *temp = (ret & 0xff) - 25; |
| 2856 | |
| 2857 | return 0; |
| 2858 | } |
| 2859 | |
| 2860 | int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp) |
| 2861 | { |
| 2862 | if (mv88e6xxx_6320_family(ds) || mv88e6xxx_6352_family(ds)) |
| 2863 | return mv88e63xx_get_temp(ds, temp); |
| 2864 | |
| 2865 | return mv88e61xx_get_temp(ds, temp); |
| 2866 | } |
| 2867 | |
| 2868 | int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp) |
| 2869 | { |
| 2870 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2871 | int ret; |
| 2872 | |
| 2873 | if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds)) |
| 2874 | return -EOPNOTSUPP; |
| 2875 | |
| 2876 | *temp = 0; |
| 2877 | |
| 2878 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26); |
| 2879 | if (ret < 0) |
| 2880 | return ret; |
| 2881 | |
| 2882 | *temp = (((ret >> 8) & 0x1f) * 5) - 25; |
| 2883 | |
| 2884 | return 0; |
| 2885 | } |
| 2886 | |
| 2887 | int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp) |
| 2888 | { |
| 2889 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2890 | int ret; |
| 2891 | |
| 2892 | if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds)) |
| 2893 | return -EOPNOTSUPP; |
| 2894 | |
| 2895 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26); |
| 2896 | if (ret < 0) |
| 2897 | return ret; |
| 2898 | temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); |
| 2899 | return mv88e6xxx_phy_page_write(ds, phy, 6, 26, |
| 2900 | (ret & 0xe0ff) | (temp << 8)); |
| 2901 | } |
| 2902 | |
| 2903 | int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm) |
| 2904 | { |
| 2905 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2906 | int ret; |
| 2907 | |
| 2908 | if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds)) |
| 2909 | return -EOPNOTSUPP; |
| 2910 | |
| 2911 | *alarm = false; |
| 2912 | |
| 2913 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26); |
| 2914 | if (ret < 0) |
| 2915 | return ret; |
| 2916 | |
| 2917 | *alarm = !!(ret & 0x40); |
| 2918 | |
| 2919 | return 0; |
| 2920 | } |
| 2921 | #endif /* CONFIG_NET_DSA_HWMON */ |
| 2922 | |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 2923 | static int __init mv88e6xxx_init(void) |
| 2924 | { |
| 2925 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) |
| 2926 | register_switch_driver(&mv88e6131_switch_driver); |
| 2927 | #endif |
| 2928 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65) |
| 2929 | register_switch_driver(&mv88e6123_61_65_switch_driver); |
| 2930 | #endif |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 2931 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6352) |
| 2932 | register_switch_driver(&mv88e6352_switch_driver); |
| 2933 | #endif |
Andrew Lunn | 42f2725 | 2014-09-12 23:58:44 +0200 | [diff] [blame] | 2934 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6171) |
| 2935 | register_switch_driver(&mv88e6171_switch_driver); |
| 2936 | #endif |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 2937 | return 0; |
| 2938 | } |
| 2939 | module_init(mv88e6xxx_init); |
| 2940 | |
| 2941 | static void __exit mv88e6xxx_cleanup(void) |
| 2942 | { |
Andrew Lunn | 42f2725 | 2014-09-12 23:58:44 +0200 | [diff] [blame] | 2943 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6171) |
| 2944 | unregister_switch_driver(&mv88e6171_switch_driver); |
| 2945 | #endif |
Vivien Didelot | 4212b54 | 2015-05-01 10:43:52 -0400 | [diff] [blame] | 2946 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6352) |
| 2947 | unregister_switch_driver(&mv88e6352_switch_driver); |
| 2948 | #endif |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 2949 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65) |
| 2950 | unregister_switch_driver(&mv88e6123_61_65_switch_driver); |
| 2951 | #endif |
| 2952 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) |
| 2953 | unregister_switch_driver(&mv88e6131_switch_driver); |
| 2954 | #endif |
| 2955 | } |
| 2956 | module_exit(mv88e6xxx_cleanup); |
Ben Hutchings | 3d825ed | 2011-11-25 14:37:16 +0000 | [diff] [blame] | 2957 | |
| 2958 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>"); |
| 2959 | MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips"); |
| 2960 | MODULE_LICENSE("GPL"); |