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 | |
Vivien Didelot | 70cc99d | 2015-09-04 14:34:10 -0400 | [diff] [blame] | 1039 | static int _mv88e6xxx_atu_cmd(struct dsa_switch *ds, u16 cmd) |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1040 | { |
| 1041 | int ret; |
| 1042 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1043 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_OP, cmd); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1044 | if (ret < 0) |
| 1045 | return ret; |
| 1046 | |
| 1047 | return _mv88e6xxx_atu_wait(ds); |
| 1048 | } |
| 1049 | |
Vivien Didelot | 37705b7 | 2015-09-04 14:34:11 -0400 | [diff] [blame] | 1050 | static int _mv88e6xxx_atu_data_write(struct dsa_switch *ds, |
| 1051 | struct mv88e6xxx_atu_entry *entry) |
| 1052 | { |
| 1053 | u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK; |
| 1054 | |
| 1055 | if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 1056 | unsigned int mask, shift; |
| 1057 | |
| 1058 | if (entry->trunk) { |
| 1059 | data |= GLOBAL_ATU_DATA_TRUNK; |
| 1060 | mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK; |
| 1061 | shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT; |
| 1062 | } else { |
| 1063 | mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK; |
| 1064 | shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT; |
| 1065 | } |
| 1066 | |
| 1067 | data |= (entry->portv_trunkid << shift) & mask; |
| 1068 | } |
| 1069 | |
| 1070 | return _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_DATA, data); |
| 1071 | } |
| 1072 | |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame^] | 1073 | static int _mv88e6xxx_atu_flush_move(struct dsa_switch *ds, |
| 1074 | struct mv88e6xxx_atu_entry *entry, |
| 1075 | bool static_too) |
| 1076 | { |
| 1077 | int op; |
| 1078 | int err; |
| 1079 | |
| 1080 | err = _mv88e6xxx_atu_wait(ds); |
| 1081 | if (err) |
| 1082 | return err; |
| 1083 | |
| 1084 | err = _mv88e6xxx_atu_data_write(ds, entry); |
| 1085 | if (err) |
| 1086 | return err; |
| 1087 | |
| 1088 | if (entry->fid) { |
| 1089 | err = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_FID, |
| 1090 | entry->fid); |
| 1091 | if (err) |
| 1092 | return err; |
| 1093 | |
| 1094 | op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB : |
| 1095 | GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB; |
| 1096 | } else { |
| 1097 | op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL : |
| 1098 | GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC; |
| 1099 | } |
| 1100 | |
| 1101 | return _mv88e6xxx_atu_cmd(ds, op); |
| 1102 | } |
| 1103 | |
| 1104 | static int _mv88e6xxx_atu_flush(struct dsa_switch *ds, u16 fid, bool static_too) |
| 1105 | { |
| 1106 | struct mv88e6xxx_atu_entry entry = { |
| 1107 | .fid = fid, |
| 1108 | .state = 0, /* EntryState bits must be 0 */ |
| 1109 | }; |
| 1110 | |
| 1111 | return _mv88e6xxx_atu_flush_move(ds, &entry, static_too); |
| 1112 | } |
| 1113 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1114 | static int _mv88e6xxx_flush_fid(struct dsa_switch *ds, int fid) |
| 1115 | { |
Vivien Didelot | 7fb5e75 | 2015-09-04 14:34:12 -0400 | [diff] [blame^] | 1116 | return _mv88e6xxx_atu_flush(ds, fid, false); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | static int mv88e6xxx_set_port_state(struct dsa_switch *ds, int port, u8 state) |
| 1120 | { |
| 1121 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Geert Uytterhoeven | c3ffe6d | 2015-04-16 20:49:14 +0200 | [diff] [blame] | 1122 | int reg, ret = 0; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1123 | u8 oldstate; |
| 1124 | |
| 1125 | mutex_lock(&ps->smi_mutex); |
| 1126 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1127 | reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_CONTROL); |
Guenter Roeck | 538cc28 | 2015-04-15 22:12:42 -0700 | [diff] [blame] | 1128 | if (reg < 0) { |
| 1129 | ret = reg; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1130 | goto abort; |
Guenter Roeck | 538cc28 | 2015-04-15 22:12:42 -0700 | [diff] [blame] | 1131 | } |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1132 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1133 | oldstate = reg & PORT_CONTROL_STATE_MASK; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1134 | if (oldstate != state) { |
| 1135 | /* Flush forwarding database if we're moving a port |
| 1136 | * from Learning or Forwarding state to Disabled or |
| 1137 | * Blocking or Listening state. |
| 1138 | */ |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1139 | if (oldstate >= PORT_CONTROL_STATE_LEARNING && |
| 1140 | state <= PORT_CONTROL_STATE_BLOCKING) { |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1141 | ret = _mv88e6xxx_flush_fid(ds, ps->fid[port]); |
| 1142 | if (ret) |
| 1143 | goto abort; |
| 1144 | } |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1145 | reg = (reg & ~PORT_CONTROL_STATE_MASK) | state; |
| 1146 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL, |
| 1147 | reg); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | abort: |
| 1151 | mutex_unlock(&ps->smi_mutex); |
| 1152 | return ret; |
| 1153 | } |
| 1154 | |
| 1155 | /* Must be called with smi lock held */ |
| 1156 | static int _mv88e6xxx_update_port_config(struct dsa_switch *ds, int port) |
| 1157 | { |
| 1158 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1159 | u8 fid = ps->fid[port]; |
| 1160 | u16 reg = fid << 12; |
| 1161 | |
| 1162 | if (dsa_is_cpu_port(ds, port)) |
| 1163 | reg |= ds->phys_port_mask; |
| 1164 | else |
| 1165 | reg |= (ps->bridge_mask[fid] | |
| 1166 | (1 << dsa_upstream_port(ds))) & ~(1 << port); |
| 1167 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1168 | return _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_BASE_VLAN, reg); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | /* Must be called with smi lock held */ |
| 1172 | static int _mv88e6xxx_update_bridge_config(struct dsa_switch *ds, int fid) |
| 1173 | { |
| 1174 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1175 | int port; |
| 1176 | u32 mask; |
| 1177 | int ret; |
| 1178 | |
| 1179 | mask = ds->phys_port_mask; |
| 1180 | while (mask) { |
| 1181 | port = __ffs(mask); |
| 1182 | mask &= ~(1 << port); |
| 1183 | if (ps->fid[port] != fid) |
| 1184 | continue; |
| 1185 | |
| 1186 | ret = _mv88e6xxx_update_port_config(ds, port); |
| 1187 | if (ret) |
| 1188 | return ret; |
| 1189 | } |
| 1190 | |
| 1191 | return _mv88e6xxx_flush_fid(ds, fid); |
| 1192 | } |
| 1193 | |
| 1194 | /* Bridge handling functions */ |
| 1195 | |
| 1196 | int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask) |
| 1197 | { |
| 1198 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1199 | int ret = 0; |
| 1200 | u32 nmask; |
| 1201 | int fid; |
| 1202 | |
| 1203 | /* If the bridge group is not empty, join that group. |
| 1204 | * Otherwise create a new group. |
| 1205 | */ |
| 1206 | fid = ps->fid[port]; |
| 1207 | nmask = br_port_mask & ~(1 << port); |
| 1208 | if (nmask) |
| 1209 | fid = ps->fid[__ffs(nmask)]; |
| 1210 | |
| 1211 | nmask = ps->bridge_mask[fid] | (1 << port); |
| 1212 | if (nmask != br_port_mask) { |
| 1213 | netdev_err(ds->ports[port], |
| 1214 | "join: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n", |
| 1215 | fid, br_port_mask, nmask); |
| 1216 | return -EINVAL; |
| 1217 | } |
| 1218 | |
| 1219 | mutex_lock(&ps->smi_mutex); |
| 1220 | |
| 1221 | ps->bridge_mask[fid] = br_port_mask; |
| 1222 | |
| 1223 | if (fid != ps->fid[port]) { |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1224 | clear_bit(ps->fid[port], ps->fid_bitmap); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1225 | ps->fid[port] = fid; |
| 1226 | ret = _mv88e6xxx_update_bridge_config(ds, fid); |
| 1227 | } |
| 1228 | |
| 1229 | mutex_unlock(&ps->smi_mutex); |
| 1230 | |
| 1231 | return ret; |
| 1232 | } |
| 1233 | |
| 1234 | int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask) |
| 1235 | { |
| 1236 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1237 | u8 fid, newfid; |
| 1238 | int ret; |
| 1239 | |
| 1240 | fid = ps->fid[port]; |
| 1241 | |
| 1242 | if (ps->bridge_mask[fid] != br_port_mask) { |
| 1243 | netdev_err(ds->ports[port], |
| 1244 | "leave: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n", |
| 1245 | fid, br_port_mask, ps->bridge_mask[fid]); |
| 1246 | return -EINVAL; |
| 1247 | } |
| 1248 | |
| 1249 | /* If the port was the last port of a bridge, we are done. |
| 1250 | * Otherwise assign a new fid to the port, and fix up |
| 1251 | * the bridge configuration. |
| 1252 | */ |
| 1253 | if (br_port_mask == (1 << port)) |
| 1254 | return 0; |
| 1255 | |
| 1256 | mutex_lock(&ps->smi_mutex); |
| 1257 | |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1258 | newfid = find_next_zero_bit(ps->fid_bitmap, VLAN_N_VID, 1); |
| 1259 | if (unlikely(newfid > ps->num_ports)) { |
| 1260 | netdev_err(ds->ports[port], "all first %d FIDs are used\n", |
| 1261 | ps->num_ports); |
| 1262 | ret = -ENOSPC; |
| 1263 | goto unlock; |
| 1264 | } |
| 1265 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1266 | ps->fid[port] = newfid; |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1267 | set_bit(newfid, ps->fid_bitmap); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1268 | ps->bridge_mask[fid] &= ~(1 << port); |
| 1269 | ps->bridge_mask[newfid] = 1 << port; |
| 1270 | |
| 1271 | ret = _mv88e6xxx_update_bridge_config(ds, fid); |
| 1272 | if (!ret) |
| 1273 | ret = _mv88e6xxx_update_bridge_config(ds, newfid); |
| 1274 | |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 1275 | unlock: |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1276 | mutex_unlock(&ps->smi_mutex); |
| 1277 | |
| 1278 | return ret; |
| 1279 | } |
| 1280 | |
| 1281 | int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state) |
| 1282 | { |
| 1283 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1284 | int stp_state; |
| 1285 | |
| 1286 | switch (state) { |
| 1287 | case BR_STATE_DISABLED: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1288 | stp_state = PORT_CONTROL_STATE_DISABLED; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1289 | break; |
| 1290 | case BR_STATE_BLOCKING: |
| 1291 | case BR_STATE_LISTENING: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1292 | stp_state = PORT_CONTROL_STATE_BLOCKING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1293 | break; |
| 1294 | case BR_STATE_LEARNING: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1295 | stp_state = PORT_CONTROL_STATE_LEARNING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1296 | break; |
| 1297 | case BR_STATE_FORWARDING: |
| 1298 | default: |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1299 | stp_state = PORT_CONTROL_STATE_FORWARDING; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 1300 | break; |
| 1301 | } |
| 1302 | |
| 1303 | netdev_dbg(ds->ports[port], "port state %d [%d]\n", state, stp_state); |
| 1304 | |
| 1305 | /* mv88e6xxx_port_stp_update may be called with softirqs disabled, |
| 1306 | * so we can not update the port state directly but need to schedule it. |
| 1307 | */ |
| 1308 | ps->port_state[port] = stp_state; |
| 1309 | set_bit(port, &ps->port_state_update_mask); |
| 1310 | schedule_work(&ps->bridge_work); |
| 1311 | |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1315 | int mv88e6xxx_port_pvid_get(struct dsa_switch *ds, int port, u16 *pvid) |
| 1316 | { |
| 1317 | int ret; |
| 1318 | |
| 1319 | ret = mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_DEFAULT_VLAN); |
| 1320 | if (ret < 0) |
| 1321 | return ret; |
| 1322 | |
| 1323 | *pvid = ret & PORT_DEFAULT_VLAN_MASK; |
| 1324 | |
| 1325 | return 0; |
| 1326 | } |
| 1327 | |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1328 | int mv88e6xxx_port_pvid_set(struct dsa_switch *ds, int port, u16 pvid) |
| 1329 | { |
| 1330 | return mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_DEFAULT_VLAN, |
| 1331 | pvid & PORT_DEFAULT_VLAN_MASK); |
| 1332 | } |
| 1333 | |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 1334 | static int _mv88e6xxx_vtu_wait(struct dsa_switch *ds) |
| 1335 | { |
| 1336 | return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_VTU_OP, |
| 1337 | GLOBAL_VTU_OP_BUSY); |
| 1338 | } |
| 1339 | |
| 1340 | static int _mv88e6xxx_vtu_cmd(struct dsa_switch *ds, u16 op) |
| 1341 | { |
| 1342 | int ret; |
| 1343 | |
| 1344 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_OP, op); |
| 1345 | if (ret < 0) |
| 1346 | return ret; |
| 1347 | |
| 1348 | return _mv88e6xxx_vtu_wait(ds); |
| 1349 | } |
| 1350 | |
| 1351 | static int _mv88e6xxx_vtu_stu_flush(struct dsa_switch *ds) |
| 1352 | { |
| 1353 | int ret; |
| 1354 | |
| 1355 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1356 | if (ret < 0) |
| 1357 | return ret; |
| 1358 | |
| 1359 | return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_FLUSH_ALL); |
| 1360 | } |
| 1361 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1362 | static int _mv88e6xxx_vtu_stu_data_read(struct dsa_switch *ds, |
| 1363 | struct mv88e6xxx_vtu_stu_entry *entry, |
| 1364 | unsigned int nibble_offset) |
| 1365 | { |
| 1366 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1367 | u16 regs[3]; |
| 1368 | int i; |
| 1369 | int ret; |
| 1370 | |
| 1371 | for (i = 0; i < 3; ++i) { |
| 1372 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1373 | GLOBAL_VTU_DATA_0_3 + i); |
| 1374 | if (ret < 0) |
| 1375 | return ret; |
| 1376 | |
| 1377 | regs[i] = ret; |
| 1378 | } |
| 1379 | |
| 1380 | for (i = 0; i < ps->num_ports; ++i) { |
| 1381 | unsigned int shift = (i % 4) * 4 + nibble_offset; |
| 1382 | u16 reg = regs[i / 4]; |
| 1383 | |
| 1384 | entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK; |
| 1385 | } |
| 1386 | |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1390 | static int _mv88e6xxx_vtu_stu_data_write(struct dsa_switch *ds, |
| 1391 | struct mv88e6xxx_vtu_stu_entry *entry, |
| 1392 | unsigned int nibble_offset) |
| 1393 | { |
| 1394 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1395 | u16 regs[3] = { 0 }; |
| 1396 | int i; |
| 1397 | int ret; |
| 1398 | |
| 1399 | for (i = 0; i < ps->num_ports; ++i) { |
| 1400 | unsigned int shift = (i % 4) * 4 + nibble_offset; |
| 1401 | u8 data = entry->data[i]; |
| 1402 | |
| 1403 | regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift; |
| 1404 | } |
| 1405 | |
| 1406 | for (i = 0; i < 3; ++i) { |
| 1407 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, |
| 1408 | GLOBAL_VTU_DATA_0_3 + i, regs[i]); |
| 1409 | if (ret < 0) |
| 1410 | return ret; |
| 1411 | } |
| 1412 | |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1416 | static int _mv88e6xxx_vtu_getnext(struct dsa_switch *ds, u16 vid, |
| 1417 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1418 | { |
| 1419 | struct mv88e6xxx_vtu_stu_entry next = { 0 }; |
| 1420 | int ret; |
| 1421 | |
| 1422 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1423 | if (ret < 0) |
| 1424 | return ret; |
| 1425 | |
| 1426 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_VID, |
| 1427 | vid & GLOBAL_VTU_VID_MASK); |
| 1428 | if (ret < 0) |
| 1429 | return ret; |
| 1430 | |
| 1431 | ret = _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_VTU_GET_NEXT); |
| 1432 | if (ret < 0) |
| 1433 | return ret; |
| 1434 | |
| 1435 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_VTU_VID); |
| 1436 | if (ret < 0) |
| 1437 | return ret; |
| 1438 | |
| 1439 | next.vid = ret & GLOBAL_VTU_VID_MASK; |
| 1440 | next.valid = !!(ret & GLOBAL_VTU_VID_VALID); |
| 1441 | |
| 1442 | if (next.valid) { |
| 1443 | ret = _mv88e6xxx_vtu_stu_data_read(ds, &next, 0); |
| 1444 | if (ret < 0) |
| 1445 | return ret; |
| 1446 | |
| 1447 | if (mv88e6xxx_6097_family(ds) || mv88e6xxx_6165_family(ds) || |
| 1448 | mv88e6xxx_6351_family(ds) || mv88e6xxx_6352_family(ds)) { |
| 1449 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1450 | GLOBAL_VTU_FID); |
| 1451 | if (ret < 0) |
| 1452 | return ret; |
| 1453 | |
| 1454 | next.fid = ret & GLOBAL_VTU_FID_MASK; |
| 1455 | |
| 1456 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1457 | GLOBAL_VTU_SID); |
| 1458 | if (ret < 0) |
| 1459 | return ret; |
| 1460 | |
| 1461 | next.sid = ret & GLOBAL_VTU_SID_MASK; |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | *entry = next; |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1469 | static int _mv88e6xxx_vtu_loadpurge(struct dsa_switch *ds, |
| 1470 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1471 | { |
| 1472 | u16 reg = 0; |
| 1473 | int ret; |
| 1474 | |
| 1475 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1476 | if (ret < 0) |
| 1477 | return ret; |
| 1478 | |
| 1479 | if (!entry->valid) |
| 1480 | goto loadpurge; |
| 1481 | |
| 1482 | /* Write port member tags */ |
| 1483 | ret = _mv88e6xxx_vtu_stu_data_write(ds, entry, 0); |
| 1484 | if (ret < 0) |
| 1485 | return ret; |
| 1486 | |
| 1487 | if (mv88e6xxx_6097_family(ds) || mv88e6xxx_6165_family(ds) || |
| 1488 | mv88e6xxx_6351_family(ds) || mv88e6xxx_6352_family(ds)) { |
| 1489 | reg = entry->sid & GLOBAL_VTU_SID_MASK; |
| 1490 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_SID, reg); |
| 1491 | if (ret < 0) |
| 1492 | return ret; |
| 1493 | |
| 1494 | reg = entry->fid & GLOBAL_VTU_FID_MASK; |
| 1495 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_FID, reg); |
| 1496 | if (ret < 0) |
| 1497 | return ret; |
| 1498 | } |
| 1499 | |
| 1500 | reg = GLOBAL_VTU_VID_VALID; |
| 1501 | loadpurge: |
| 1502 | reg |= entry->vid & GLOBAL_VTU_VID_MASK; |
| 1503 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_VID, reg); |
| 1504 | if (ret < 0) |
| 1505 | return ret; |
| 1506 | |
| 1507 | return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_VTU_LOAD_PURGE); |
| 1508 | } |
| 1509 | |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 1510 | static int _mv88e6xxx_stu_getnext(struct dsa_switch *ds, u8 sid, |
| 1511 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1512 | { |
| 1513 | struct mv88e6xxx_vtu_stu_entry next = { 0 }; |
| 1514 | int ret; |
| 1515 | |
| 1516 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1517 | if (ret < 0) |
| 1518 | return ret; |
| 1519 | |
| 1520 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_SID, |
| 1521 | sid & GLOBAL_VTU_SID_MASK); |
| 1522 | if (ret < 0) |
| 1523 | return ret; |
| 1524 | |
| 1525 | ret = _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_STU_GET_NEXT); |
| 1526 | if (ret < 0) |
| 1527 | return ret; |
| 1528 | |
| 1529 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_VTU_SID); |
| 1530 | if (ret < 0) |
| 1531 | return ret; |
| 1532 | |
| 1533 | next.sid = ret & GLOBAL_VTU_SID_MASK; |
| 1534 | |
| 1535 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_VTU_VID); |
| 1536 | if (ret < 0) |
| 1537 | return ret; |
| 1538 | |
| 1539 | next.valid = !!(ret & GLOBAL_VTU_VID_VALID); |
| 1540 | |
| 1541 | if (next.valid) { |
| 1542 | ret = _mv88e6xxx_vtu_stu_data_read(ds, &next, 2); |
| 1543 | if (ret < 0) |
| 1544 | return ret; |
| 1545 | } |
| 1546 | |
| 1547 | *entry = next; |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
| 1551 | static int _mv88e6xxx_stu_loadpurge(struct dsa_switch *ds, |
| 1552 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1553 | { |
| 1554 | u16 reg = 0; |
| 1555 | int ret; |
| 1556 | |
| 1557 | ret = _mv88e6xxx_vtu_wait(ds); |
| 1558 | if (ret < 0) |
| 1559 | return ret; |
| 1560 | |
| 1561 | if (!entry->valid) |
| 1562 | goto loadpurge; |
| 1563 | |
| 1564 | /* Write port states */ |
| 1565 | ret = _mv88e6xxx_vtu_stu_data_write(ds, entry, 2); |
| 1566 | if (ret < 0) |
| 1567 | return ret; |
| 1568 | |
| 1569 | reg = GLOBAL_VTU_VID_VALID; |
| 1570 | loadpurge: |
| 1571 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_VID, reg); |
| 1572 | if (ret < 0) |
| 1573 | return ret; |
| 1574 | |
| 1575 | reg = entry->sid & GLOBAL_VTU_SID_MASK; |
| 1576 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_SID, reg); |
| 1577 | if (ret < 0) |
| 1578 | return ret; |
| 1579 | |
| 1580 | return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_STU_LOAD_PURGE); |
| 1581 | } |
| 1582 | |
| 1583 | static int _mv88e6xxx_vlan_init(struct dsa_switch *ds, u16 vid, |
| 1584 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1585 | { |
| 1586 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1587 | struct mv88e6xxx_vtu_stu_entry vlan = { |
| 1588 | .valid = true, |
| 1589 | .vid = vid, |
| 1590 | }; |
| 1591 | int i; |
| 1592 | |
| 1593 | /* exclude all ports except the CPU */ |
| 1594 | for (i = 0; i < ps->num_ports; ++i) |
| 1595 | vlan.data[i] = dsa_is_cpu_port(ds, i) ? |
| 1596 | GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED : |
| 1597 | GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; |
| 1598 | |
| 1599 | if (mv88e6xxx_6097_family(ds) || mv88e6xxx_6165_family(ds) || |
| 1600 | mv88e6xxx_6351_family(ds) || mv88e6xxx_6352_family(ds)) { |
| 1601 | struct mv88e6xxx_vtu_stu_entry vstp; |
| 1602 | int err; |
| 1603 | |
| 1604 | /* Adding a VTU entry requires a valid STU entry. As VSTP is not |
| 1605 | * implemented, only one STU entry is needed to cover all VTU |
| 1606 | * entries. Thus, validate the SID 0. |
| 1607 | */ |
| 1608 | vlan.sid = 0; |
| 1609 | err = _mv88e6xxx_stu_getnext(ds, GLOBAL_VTU_SID_MASK, &vstp); |
| 1610 | if (err) |
| 1611 | return err; |
| 1612 | |
| 1613 | if (vstp.sid != vlan.sid || !vstp.valid) { |
| 1614 | memset(&vstp, 0, sizeof(vstp)); |
| 1615 | vstp.valid = true; |
| 1616 | vstp.sid = vlan.sid; |
| 1617 | |
| 1618 | err = _mv88e6xxx_stu_loadpurge(ds, &vstp); |
| 1619 | if (err) |
| 1620 | return err; |
| 1621 | } |
| 1622 | |
| 1623 | /* Non-bridged ports and bridge groups use FIDs from 1 to |
| 1624 | * num_ports; VLANs use FIDs from num_ports+1 to 4095. |
| 1625 | */ |
| 1626 | vlan.fid = find_next_zero_bit(ps->fid_bitmap, VLAN_N_VID, |
| 1627 | ps->num_ports + 1); |
| 1628 | if (unlikely(vlan.fid == VLAN_N_VID)) { |
| 1629 | pr_err("no more FID available for VLAN %d\n", vid); |
| 1630 | return -ENOSPC; |
| 1631 | } |
| 1632 | |
| 1633 | err = _mv88e6xxx_flush_fid(ds, vlan.fid); |
| 1634 | if (err) |
| 1635 | return err; |
| 1636 | |
| 1637 | set_bit(vlan.fid, ps->fid_bitmap); |
| 1638 | } |
| 1639 | |
| 1640 | *entry = vlan; |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port, u16 vid, |
| 1645 | bool untagged) |
| 1646 | { |
| 1647 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1648 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 1649 | int err; |
| 1650 | |
| 1651 | mutex_lock(&ps->smi_mutex); |
| 1652 | err = _mv88e6xxx_vtu_getnext(ds, vid - 1, &vlan); |
| 1653 | if (err) |
| 1654 | goto unlock; |
| 1655 | |
| 1656 | if (vlan.vid != vid || !vlan.valid) { |
| 1657 | err = _mv88e6xxx_vlan_init(ds, vid, &vlan); |
| 1658 | if (err) |
| 1659 | goto unlock; |
| 1660 | } |
| 1661 | |
| 1662 | vlan.data[port] = untagged ? |
| 1663 | GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED : |
| 1664 | GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED; |
| 1665 | |
| 1666 | err = _mv88e6xxx_vtu_loadpurge(ds, &vlan); |
| 1667 | unlock: |
| 1668 | mutex_unlock(&ps->smi_mutex); |
| 1669 | |
| 1670 | return err; |
| 1671 | } |
| 1672 | |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 1673 | int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, u16 vid) |
| 1674 | { |
| 1675 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1676 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 1677 | bool keep = false; |
| 1678 | int i, err; |
| 1679 | |
| 1680 | mutex_lock(&ps->smi_mutex); |
| 1681 | |
| 1682 | err = _mv88e6xxx_vtu_getnext(ds, vid - 1, &vlan); |
| 1683 | if (err) |
| 1684 | goto unlock; |
| 1685 | |
| 1686 | if (vlan.vid != vid || !vlan.valid || |
| 1687 | vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) { |
| 1688 | err = -ENOENT; |
| 1689 | goto unlock; |
| 1690 | } |
| 1691 | |
| 1692 | vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; |
| 1693 | |
| 1694 | /* keep the VLAN unless all ports are excluded */ |
| 1695 | for (i = 0; i < ps->num_ports; ++i) { |
| 1696 | if (dsa_is_cpu_port(ds, i)) |
| 1697 | continue; |
| 1698 | |
| 1699 | if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) { |
| 1700 | keep = true; |
| 1701 | break; |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | vlan.valid = keep; |
| 1706 | err = _mv88e6xxx_vtu_loadpurge(ds, &vlan); |
| 1707 | if (err) |
| 1708 | goto unlock; |
| 1709 | |
| 1710 | if (!keep) |
| 1711 | clear_bit(vlan.fid, ps->fid_bitmap); |
| 1712 | |
| 1713 | unlock: |
| 1714 | mutex_unlock(&ps->smi_mutex); |
| 1715 | |
| 1716 | return err; |
| 1717 | } |
| 1718 | |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1719 | static int _mv88e6xxx_port_vtu_getnext(struct dsa_switch *ds, int port, u16 vid, |
| 1720 | struct mv88e6xxx_vtu_stu_entry *entry) |
| 1721 | { |
| 1722 | int err; |
| 1723 | |
| 1724 | do { |
| 1725 | if (vid == 4095) |
| 1726 | return -ENOENT; |
| 1727 | |
| 1728 | err = _mv88e6xxx_vtu_getnext(ds, vid, entry); |
| 1729 | if (err) |
| 1730 | return err; |
| 1731 | |
| 1732 | if (!entry->valid) |
| 1733 | return -ENOENT; |
| 1734 | |
| 1735 | vid = entry->vid; |
| 1736 | } while (entry->data[port] != GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED && |
| 1737 | entry->data[port] != GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED); |
| 1738 | |
| 1739 | return 0; |
| 1740 | } |
| 1741 | |
Vivien Didelot | b8fee95 | 2015-08-13 12:52:19 -0400 | [diff] [blame] | 1742 | int mv88e6xxx_vlan_getnext(struct dsa_switch *ds, u16 *vid, |
| 1743 | unsigned long *ports, unsigned long *untagged) |
| 1744 | { |
| 1745 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1746 | struct mv88e6xxx_vtu_stu_entry next; |
| 1747 | int port; |
| 1748 | int err; |
| 1749 | |
| 1750 | if (*vid == 4095) |
| 1751 | return -ENOENT; |
| 1752 | |
| 1753 | mutex_lock(&ps->smi_mutex); |
| 1754 | err = _mv88e6xxx_vtu_getnext(ds, *vid, &next); |
| 1755 | mutex_unlock(&ps->smi_mutex); |
| 1756 | |
| 1757 | if (err) |
| 1758 | return err; |
| 1759 | |
| 1760 | if (!next.valid) |
| 1761 | return -ENOENT; |
| 1762 | |
| 1763 | *vid = next.vid; |
| 1764 | |
| 1765 | for (port = 0; port < ps->num_ports; ++port) { |
| 1766 | clear_bit(port, ports); |
| 1767 | clear_bit(port, untagged); |
| 1768 | |
| 1769 | if (dsa_is_cpu_port(ds, port)) |
| 1770 | continue; |
| 1771 | |
| 1772 | if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED || |
| 1773 | next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED) |
| 1774 | set_bit(port, ports); |
| 1775 | |
| 1776 | if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED) |
| 1777 | set_bit(port, untagged); |
| 1778 | } |
| 1779 | |
| 1780 | return 0; |
| 1781 | } |
| 1782 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 1783 | static int _mv88e6xxx_atu_mac_write(struct dsa_switch *ds, |
| 1784 | const unsigned char *addr) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1785 | { |
| 1786 | int i, ret; |
| 1787 | |
| 1788 | for (i = 0; i < 3; i++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1789 | ret = _mv88e6xxx_reg_write( |
| 1790 | ds, REG_GLOBAL, GLOBAL_ATU_MAC_01 + i, |
| 1791 | (addr[i * 2] << 8) | addr[i * 2 + 1]); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1792 | if (ret < 0) |
| 1793 | return ret; |
| 1794 | } |
| 1795 | |
| 1796 | return 0; |
| 1797 | } |
| 1798 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 1799 | 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] | 1800 | { |
| 1801 | int i, ret; |
| 1802 | |
| 1803 | for (i = 0; i < 3; i++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 1804 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, |
| 1805 | GLOBAL_ATU_MAC_01 + i); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1806 | if (ret < 0) |
| 1807 | return ret; |
| 1808 | addr[i * 2] = ret >> 8; |
| 1809 | addr[i * 2 + 1] = ret & 0xff; |
| 1810 | } |
| 1811 | |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1815 | static int _mv88e6xxx_atu_load(struct dsa_switch *ds, |
| 1816 | struct mv88e6xxx_atu_entry *entry) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1817 | { |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1818 | int ret; |
| 1819 | |
| 1820 | ret = _mv88e6xxx_atu_wait(ds); |
| 1821 | if (ret < 0) |
| 1822 | return ret; |
| 1823 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1824 | ret = _mv88e6xxx_atu_mac_write(ds, entry->mac); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1825 | if (ret < 0) |
| 1826 | return ret; |
| 1827 | |
Vivien Didelot | 37705b7 | 2015-09-04 14:34:11 -0400 | [diff] [blame] | 1828 | ret = _mv88e6xxx_atu_data_write(ds, entry); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1829 | if (ret < 0) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1830 | return ret; |
| 1831 | |
Vivien Didelot | 70cc99d | 2015-09-04 14:34:10 -0400 | [diff] [blame] | 1832 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_FID, entry->fid); |
| 1833 | if (ret < 0) |
| 1834 | return ret; |
| 1835 | |
| 1836 | return _mv88e6xxx_atu_cmd(ds, GLOBAL_ATU_OP_LOAD_DB); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1837 | } |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1838 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1839 | static int _mv88e6xxx_port_vid_to_fid(struct dsa_switch *ds, int port, u16 vid) |
| 1840 | { |
| 1841 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1842 | struct mv88e6xxx_vtu_stu_entry vlan; |
| 1843 | int err; |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1844 | |
| 1845 | if (vid == 0) |
| 1846 | return ps->fid[port]; |
| 1847 | |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1848 | err = _mv88e6xxx_port_vtu_getnext(ds, port, vid - 1, &vlan); |
| 1849 | if (err) |
| 1850 | return err; |
| 1851 | |
| 1852 | if (vlan.vid == vid) |
| 1853 | return vlan.fid; |
| 1854 | |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1855 | return -ENOENT; |
| 1856 | } |
| 1857 | |
| 1858 | static int _mv88e6xxx_port_fdb_load(struct dsa_switch *ds, int port, |
| 1859 | const unsigned char *addr, u16 vid, |
| 1860 | u8 state) |
| 1861 | { |
| 1862 | struct mv88e6xxx_atu_entry entry = { 0 }; |
| 1863 | int ret; |
| 1864 | |
| 1865 | ret = _mv88e6xxx_port_vid_to_fid(ds, port, vid); |
| 1866 | if (ret < 0) |
| 1867 | return ret; |
| 1868 | |
| 1869 | entry.fid = ret; |
| 1870 | entry.state = state; |
| 1871 | ether_addr_copy(entry.mac, addr); |
| 1872 | if (state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 1873 | entry.trunk = false; |
| 1874 | entry.portv_trunkid = BIT(port); |
| 1875 | } |
| 1876 | |
| 1877 | return _mv88e6xxx_atu_load(ds, &entry); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1880 | int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port, |
| 1881 | const unsigned char *addr, u16 vid) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1882 | { |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1883 | int state = is_multicast_ether_addr(addr) ? |
| 1884 | GLOBAL_ATU_DATA_STATE_MC_STATIC : |
| 1885 | GLOBAL_ATU_DATA_STATE_UC_STATIC; |
| 1886 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 6630e23 | 2015-08-06 01:44:07 -0400 | [diff] [blame] | 1887 | int ret; |
| 1888 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1889 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1890 | ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid, state); |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1891 | mutex_unlock(&ps->smi_mutex); |
| 1892 | |
| 1893 | return ret; |
| 1894 | } |
| 1895 | |
| 1896 | int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, |
| 1897 | const unsigned char *addr, u16 vid) |
| 1898 | { |
| 1899 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 1900 | int ret; |
| 1901 | |
| 1902 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | fd231c8 | 2015-08-10 09:09:50 -0400 | [diff] [blame] | 1903 | ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid, |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1904 | GLOBAL_ATU_DATA_STATE_UNUSED); |
| 1905 | mutex_unlock(&ps->smi_mutex); |
| 1906 | |
| 1907 | return ret; |
| 1908 | } |
| 1909 | |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1910 | static int _mv88e6xxx_atu_getnext(struct dsa_switch *ds, u16 fid, |
| 1911 | const unsigned char *addr, |
| 1912 | struct mv88e6xxx_atu_entry *entry) |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1913 | { |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1914 | struct mv88e6xxx_atu_entry next = { 0 }; |
| 1915 | int ret; |
| 1916 | |
| 1917 | next.fid = fid; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1918 | |
| 1919 | ret = _mv88e6xxx_atu_wait(ds); |
| 1920 | if (ret < 0) |
| 1921 | return ret; |
| 1922 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 1923 | ret = _mv88e6xxx_atu_mac_write(ds, addr); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1924 | if (ret < 0) |
| 1925 | return ret; |
| 1926 | |
Vivien Didelot | 70cc99d | 2015-09-04 14:34:10 -0400 | [diff] [blame] | 1927 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_FID, fid); |
| 1928 | if (ret < 0) |
| 1929 | return ret; |
| 1930 | |
| 1931 | ret = _mv88e6xxx_atu_cmd(ds, GLOBAL_ATU_OP_GET_NEXT_DB); |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1932 | if (ret < 0) |
| 1933 | return ret; |
| 1934 | |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1935 | ret = _mv88e6xxx_atu_mac_read(ds, next.mac); |
| 1936 | if (ret < 0) |
| 1937 | return ret; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1938 | |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1939 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA); |
| 1940 | if (ret < 0) |
| 1941 | return ret; |
| 1942 | |
| 1943 | next.state = ret & GLOBAL_ATU_DATA_STATE_MASK; |
| 1944 | if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) { |
| 1945 | unsigned int mask, shift; |
| 1946 | |
| 1947 | if (ret & GLOBAL_ATU_DATA_TRUNK) { |
| 1948 | next.trunk = true; |
| 1949 | mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK; |
| 1950 | shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT; |
| 1951 | } else { |
| 1952 | next.trunk = false; |
| 1953 | mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK; |
| 1954 | shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT; |
| 1955 | } |
| 1956 | |
| 1957 | next.portv_trunkid = (ret & mask) >> shift; |
| 1958 | } |
| 1959 | |
| 1960 | *entry = next; |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1961 | return 0; |
| 1962 | } |
| 1963 | |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 1964 | /* get next entry for port */ |
| 1965 | int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port, |
Vivien Didelot | 2a778e1 | 2015-08-10 09:09:49 -0400 | [diff] [blame] | 1966 | unsigned char *addr, u16 *vid, bool *is_static) |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 1967 | { |
| 1968 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1969 | struct mv88e6xxx_atu_entry next; |
| 1970 | u16 fid; |
Vivien Didelot | 8782051 | 2015-08-06 01:44:08 -0400 | [diff] [blame] | 1971 | int ret; |
| 1972 | |
| 1973 | mutex_lock(&ps->smi_mutex); |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1974 | |
| 1975 | ret = _mv88e6xxx_port_vid_to_fid(ds, port, *vid); |
| 1976 | if (ret < 0) |
| 1977 | goto unlock; |
| 1978 | fid = ret; |
| 1979 | |
| 1980 | do { |
| 1981 | if (is_broadcast_ether_addr(addr)) { |
Vivien Didelot | 02512b6 | 2015-08-13 12:52:20 -0400 | [diff] [blame] | 1982 | struct mv88e6xxx_vtu_stu_entry vtu; |
| 1983 | |
| 1984 | ret = _mv88e6xxx_port_vtu_getnext(ds, port, *vid, &vtu); |
| 1985 | if (ret < 0) |
| 1986 | goto unlock; |
| 1987 | |
| 1988 | *vid = vtu.vid; |
| 1989 | fid = vtu.fid; |
Vivien Didelot | 1d19404 | 2015-08-10 09:09:51 -0400 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | ret = _mv88e6xxx_atu_getnext(ds, fid, addr, &next); |
| 1993 | if (ret < 0) |
| 1994 | goto unlock; |
| 1995 | |
| 1996 | ether_addr_copy(addr, next.mac); |
| 1997 | |
| 1998 | if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED) |
| 1999 | continue; |
| 2000 | } while (next.trunk || (next.portv_trunkid & BIT(port)) == 0); |
| 2001 | |
| 2002 | *is_static = next.state == (is_multicast_ether_addr(addr) ? |
| 2003 | GLOBAL_ATU_DATA_STATE_MC_STATIC : |
| 2004 | GLOBAL_ATU_DATA_STATE_UC_STATIC); |
| 2005 | unlock: |
Guenter Roeck | defb05b | 2015-03-26 18:36:38 -0700 | [diff] [blame] | 2006 | mutex_unlock(&ps->smi_mutex); |
| 2007 | |
| 2008 | return ret; |
| 2009 | } |
| 2010 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2011 | static void mv88e6xxx_bridge_work(struct work_struct *work) |
| 2012 | { |
| 2013 | struct mv88e6xxx_priv_state *ps; |
| 2014 | struct dsa_switch *ds; |
| 2015 | int port; |
| 2016 | |
| 2017 | ps = container_of(work, struct mv88e6xxx_priv_state, bridge_work); |
| 2018 | ds = ((struct dsa_switch *)ps) - 1; |
| 2019 | |
| 2020 | while (ps->port_state_update_mask) { |
| 2021 | port = __ffs(ps->port_state_update_mask); |
| 2022 | clear_bit(port, &ps->port_state_update_mask); |
| 2023 | mv88e6xxx_set_port_state(ds, port, ps->port_state[port]); |
| 2024 | } |
| 2025 | } |
| 2026 | |
Andrew Lunn | dbde9e6 | 2015-05-06 01:09:48 +0200 | [diff] [blame] | 2027 | static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2028 | { |
| 2029 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2030 | int ret, fid; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2031 | u16 reg; |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2032 | |
| 2033 | mutex_lock(&ps->smi_mutex); |
| 2034 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2035 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2036 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2037 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2038 | mv88e6xxx_6065_family(ds) || mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2039 | /* MAC Forcing register: don't force link, speed, |
| 2040 | * duplex or flow control state to any particular |
| 2041 | * values on physical ports, but force the CPU port |
| 2042 | * and all DSA ports to their maximum bandwidth and |
| 2043 | * full duplex. |
| 2044 | */ |
| 2045 | reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_PCS_CTRL); |
Andrew Lunn | 60045cb | 2015-08-17 23:52:51 +0200 | [diff] [blame] | 2046 | if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2047 | reg |= PORT_PCS_CTRL_FORCE_LINK | |
| 2048 | PORT_PCS_CTRL_LINK_UP | |
| 2049 | PORT_PCS_CTRL_DUPLEX_FULL | |
| 2050 | PORT_PCS_CTRL_FORCE_DUPLEX; |
| 2051 | if (mv88e6xxx_6065_family(ds)) |
| 2052 | reg |= PORT_PCS_CTRL_100; |
| 2053 | else |
| 2054 | reg |= PORT_PCS_CTRL_1000; |
| 2055 | } else { |
| 2056 | reg |= PORT_PCS_CTRL_UNFORCED; |
| 2057 | } |
| 2058 | |
| 2059 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2060 | PORT_PCS_CTRL, reg); |
| 2061 | if (ret) |
| 2062 | goto abort; |
| 2063 | } |
| 2064 | |
| 2065 | /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock, |
| 2066 | * disable Header mode, enable IGMP/MLD snooping, disable VLAN |
| 2067 | * tunneling, determine priority by looking at 802.1p and IP |
| 2068 | * priority fields (IP prio has precedence), and set STP state |
| 2069 | * to Forwarding. |
| 2070 | * |
| 2071 | * If this is the CPU link, use DSA or EDSA tagging depending |
| 2072 | * on which tagging mode was configured. |
| 2073 | * |
| 2074 | * If this is a link to another switch, use DSA tagging mode. |
| 2075 | * |
| 2076 | * If this is the upstream port for this switch, enable |
| 2077 | * forwarding of unknown unicasts and multicasts. |
| 2078 | */ |
| 2079 | reg = 0; |
| 2080 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2081 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2082 | mv88e6xxx_6095_family(ds) || mv88e6xxx_6065_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2083 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6320_family(ds)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2084 | reg = PORT_CONTROL_IGMP_MLD_SNOOP | |
| 2085 | PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP | |
| 2086 | PORT_CONTROL_STATE_FORWARDING; |
| 2087 | if (dsa_is_cpu_port(ds, port)) { |
| 2088 | if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds)) |
| 2089 | reg |= PORT_CONTROL_DSA_TAG; |
| 2090 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2091 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2092 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2093 | if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA) |
| 2094 | reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA; |
| 2095 | else |
| 2096 | reg |= PORT_CONTROL_FRAME_MODE_DSA; |
| 2097 | } |
| 2098 | |
| 2099 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2100 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2101 | mv88e6xxx_6095_family(ds) || mv88e6xxx_6065_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2102 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2103 | if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA) |
| 2104 | reg |= PORT_CONTROL_EGRESS_ADD_TAG; |
| 2105 | } |
| 2106 | } |
Andrew Lunn | 6083ce7 | 2015-08-17 23:52:52 +0200 | [diff] [blame] | 2107 | if (dsa_is_dsa_port(ds, port)) { |
| 2108 | if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds)) |
| 2109 | reg |= PORT_CONTROL_DSA_TAG; |
| 2110 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2111 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2112 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2113 | reg |= PORT_CONTROL_FRAME_MODE_DSA; |
Andrew Lunn | 6083ce7 | 2015-08-17 23:52:52 +0200 | [diff] [blame] | 2114 | } |
| 2115 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2116 | if (port == dsa_upstream_port(ds)) |
| 2117 | reg |= PORT_CONTROL_FORWARD_UNKNOWN | |
| 2118 | PORT_CONTROL_FORWARD_UNKNOWN_MC; |
| 2119 | } |
| 2120 | if (reg) { |
| 2121 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2122 | PORT_CONTROL, reg); |
| 2123 | if (ret) |
| 2124 | goto abort; |
| 2125 | } |
| 2126 | |
Vivien Didelot | 8efdda4 | 2015-08-13 12:52:23 -0400 | [diff] [blame] | 2127 | /* Port Control 2: don't force a good FCS, set the maximum frame size to |
| 2128 | * 10240 bytes, enable secure 802.1q tags, don't discard tagged or |
| 2129 | * untagged frames on this port, do a destination address lookup on all |
| 2130 | * received packets as usual, disable ARP mirroring and don't send a |
| 2131 | * copy of all transmitted/received frames on this port to the CPU. |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2132 | */ |
| 2133 | reg = 0; |
| 2134 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2135 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2136 | mv88e6xxx_6095_family(ds) || mv88e6xxx_6320_family(ds)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2137 | reg = PORT_CONTROL_2_MAP_DA; |
| 2138 | |
| 2139 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2140 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6320_family(ds)) |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2141 | reg |= PORT_CONTROL_2_JUMBO_10240; |
| 2142 | |
| 2143 | if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds)) { |
| 2144 | /* Set the upstream port this port should use */ |
| 2145 | reg |= dsa_upstream_port(ds); |
| 2146 | /* enable forwarding of unknown multicast addresses to |
| 2147 | * the upstream port |
| 2148 | */ |
| 2149 | if (port == dsa_upstream_port(ds)) |
| 2150 | reg |= PORT_CONTROL_2_FORWARD_UNKNOWN; |
| 2151 | } |
| 2152 | |
Vivien Didelot | f5117ce | 2015-08-19 18:54:55 -0400 | [diff] [blame] | 2153 | reg |= PORT_CONTROL_2_8021Q_FALLBACK; |
Vivien Didelot | 8efdda4 | 2015-08-13 12:52:23 -0400 | [diff] [blame] | 2154 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2155 | if (reg) { |
| 2156 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2157 | PORT_CONTROL_2, reg); |
| 2158 | if (ret) |
| 2159 | goto abort; |
| 2160 | } |
| 2161 | |
| 2162 | /* Port Association Vector: when learning source addresses |
| 2163 | * of packets, add the address to the address database using |
| 2164 | * a port bitmap that has only the bit for this port set and |
| 2165 | * the other bits clear. |
| 2166 | */ |
| 2167 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_ASSOC_VECTOR, |
| 2168 | 1 << port); |
| 2169 | if (ret) |
| 2170 | goto abort; |
| 2171 | |
| 2172 | /* Egress rate control 2: disable egress rate control. */ |
| 2173 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_RATE_CONTROL_2, |
| 2174 | 0x0000); |
| 2175 | if (ret) |
| 2176 | goto abort; |
| 2177 | |
| 2178 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2179 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2180 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2181 | /* Do not limit the period of time that this port can |
| 2182 | * be paused for by the remote end or the period of |
| 2183 | * time that this port can pause the remote end. |
| 2184 | */ |
| 2185 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2186 | PORT_PAUSE_CTRL, 0x0000); |
| 2187 | if (ret) |
| 2188 | goto abort; |
| 2189 | |
| 2190 | /* Port ATU control: disable limiting the number of |
| 2191 | * address database entries that this port is allowed |
| 2192 | * to use. |
| 2193 | */ |
| 2194 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2195 | PORT_ATU_CONTROL, 0x0000); |
| 2196 | /* Priority Override: disable DA, SA and VTU priority |
| 2197 | * override. |
| 2198 | */ |
| 2199 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2200 | PORT_PRI_OVERRIDE, 0x0000); |
| 2201 | if (ret) |
| 2202 | goto abort; |
| 2203 | |
| 2204 | /* Port Ethertype: use the Ethertype DSA Ethertype |
| 2205 | * value. |
| 2206 | */ |
| 2207 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2208 | PORT_ETH_TYPE, ETH_P_EDSA); |
| 2209 | if (ret) |
| 2210 | goto abort; |
| 2211 | /* Tag Remap: use an identity 802.1p prio -> switch |
| 2212 | * prio mapping. |
| 2213 | */ |
| 2214 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2215 | PORT_TAG_REGMAP_0123, 0x3210); |
| 2216 | if (ret) |
| 2217 | goto abort; |
| 2218 | |
| 2219 | /* Tag Remap 2: use an identity 802.1p prio -> switch |
| 2220 | * prio mapping. |
| 2221 | */ |
| 2222 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2223 | PORT_TAG_REGMAP_4567, 0x7654); |
| 2224 | if (ret) |
| 2225 | goto abort; |
| 2226 | } |
| 2227 | |
| 2228 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2229 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2230 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) || |
| 2231 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2232 | /* Rate Control: disable ingress rate limiting. */ |
| 2233 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), |
| 2234 | PORT_RATE_CONTROL, 0x0001); |
| 2235 | if (ret) |
| 2236 | goto abort; |
| 2237 | } |
| 2238 | |
Guenter Roeck | 366f0a0 | 2015-03-26 18:36:30 -0700 | [diff] [blame] | 2239 | /* Port Control 1: disable trunking, disable sending |
| 2240 | * learning messages to this port. |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2241 | */ |
Vivien Didelot | 614f03f | 2015-04-20 17:19:23 -0400 | [diff] [blame] | 2242 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL_1, 0x0000); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2243 | if (ret) |
| 2244 | goto abort; |
| 2245 | |
| 2246 | /* Port based VLAN map: give each port its own address |
| 2247 | * database, allow the CPU port to talk to each of the 'real' |
| 2248 | * ports, and allow each of the 'real' ports to only talk to |
| 2249 | * the upstream port. |
| 2250 | */ |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 2251 | fid = port + 1; |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2252 | ps->fid[port] = fid; |
Vivien Didelot | 194fea7 | 2015-08-10 09:09:47 -0400 | [diff] [blame] | 2253 | set_bit(fid, ps->fid_bitmap); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2254 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2255 | if (!dsa_is_cpu_port(ds, port)) |
| 2256 | ps->bridge_mask[fid] = 1 << port; |
| 2257 | |
| 2258 | ret = _mv88e6xxx_update_port_config(ds, port); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2259 | if (ret) |
| 2260 | goto abort; |
| 2261 | |
| 2262 | /* Default VLAN ID and priority: don't set a default VLAN |
| 2263 | * ID, and set the default packet priority to zero. |
| 2264 | */ |
Vivien Didelot | 47cf1e6 | 2015-04-20 17:43:26 -0400 | [diff] [blame] | 2265 | ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_DEFAULT_VLAN, |
| 2266 | 0x0000); |
Guenter Roeck | d827e88 | 2015-03-26 18:36:29 -0700 | [diff] [blame] | 2267 | abort: |
| 2268 | mutex_unlock(&ps->smi_mutex); |
| 2269 | return ret; |
| 2270 | } |
| 2271 | |
Andrew Lunn | dbde9e6 | 2015-05-06 01:09:48 +0200 | [diff] [blame] | 2272 | int mv88e6xxx_setup_ports(struct dsa_switch *ds) |
| 2273 | { |
| 2274 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2275 | int ret; |
| 2276 | int i; |
| 2277 | |
| 2278 | for (i = 0; i < ps->num_ports; i++) { |
| 2279 | ret = mv88e6xxx_setup_port(ds, i); |
| 2280 | if (ret < 0) |
| 2281 | return ret; |
| 2282 | } |
| 2283 | return 0; |
| 2284 | } |
| 2285 | |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 2286 | static int mv88e6xxx_regs_show(struct seq_file *s, void *p) |
| 2287 | { |
| 2288 | struct dsa_switch *ds = s->private; |
| 2289 | |
| 2290 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2291 | int reg, port; |
| 2292 | |
| 2293 | seq_puts(s, " GLOBAL GLOBAL2 "); |
| 2294 | for (port = 0 ; port < ps->num_ports; port++) |
| 2295 | seq_printf(s, " %2d ", port); |
| 2296 | seq_puts(s, "\n"); |
| 2297 | |
| 2298 | for (reg = 0; reg < 32; reg++) { |
| 2299 | seq_printf(s, "%2x: ", reg); |
| 2300 | seq_printf(s, " %4x %4x ", |
| 2301 | mv88e6xxx_reg_read(ds, REG_GLOBAL, reg), |
| 2302 | mv88e6xxx_reg_read(ds, REG_GLOBAL2, reg)); |
| 2303 | |
| 2304 | for (port = 0 ; port < ps->num_ports; port++) |
| 2305 | seq_printf(s, "%4x ", |
| 2306 | mv88e6xxx_reg_read(ds, REG_PORT(port), reg)); |
| 2307 | seq_puts(s, "\n"); |
| 2308 | } |
| 2309 | |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
| 2313 | static int mv88e6xxx_regs_open(struct inode *inode, struct file *file) |
| 2314 | { |
| 2315 | return single_open(file, mv88e6xxx_regs_show, inode->i_private); |
| 2316 | } |
| 2317 | |
| 2318 | static const struct file_operations mv88e6xxx_regs_fops = { |
| 2319 | .open = mv88e6xxx_regs_open, |
| 2320 | .read = seq_read, |
| 2321 | .llseek = no_llseek, |
| 2322 | .release = single_release, |
| 2323 | .owner = THIS_MODULE, |
| 2324 | }; |
| 2325 | |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2326 | static void mv88e6xxx_atu_show_header(struct seq_file *s) |
| 2327 | { |
| 2328 | seq_puts(s, "DB T/P Vec State Addr\n"); |
| 2329 | } |
| 2330 | |
| 2331 | static void mv88e6xxx_atu_show_entry(struct seq_file *s, int dbnum, |
| 2332 | unsigned char *addr, int data) |
| 2333 | { |
| 2334 | bool trunk = !!(data & GLOBAL_ATU_DATA_TRUNK); |
| 2335 | int portvec = ((data & GLOBAL_ATU_DATA_PORT_VECTOR_MASK) >> |
| 2336 | GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT); |
| 2337 | int state = data & GLOBAL_ATU_DATA_STATE_MASK; |
| 2338 | |
| 2339 | seq_printf(s, "%03x %5s %10pb %x %pM\n", |
| 2340 | dbnum, (trunk ? "Trunk" : "Port"), &portvec, state, addr); |
| 2341 | } |
| 2342 | |
| 2343 | static int mv88e6xxx_atu_show_db(struct seq_file *s, struct dsa_switch *ds, |
| 2344 | int dbnum) |
| 2345 | { |
| 2346 | unsigned char bcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 2347 | unsigned char addr[6]; |
| 2348 | int ret, data, state; |
| 2349 | |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 2350 | ret = _mv88e6xxx_atu_mac_write(ds, bcast); |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2351 | if (ret < 0) |
| 2352 | return ret; |
| 2353 | |
| 2354 | do { |
Vivien Didelot | 70cc99d | 2015-09-04 14:34:10 -0400 | [diff] [blame] | 2355 | ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_FID, |
| 2356 | dbnum); |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2357 | if (ret < 0) |
| 2358 | return ret; |
Vivien Didelot | 70cc99d | 2015-09-04 14:34:10 -0400 | [diff] [blame] | 2359 | |
| 2360 | ret = _mv88e6xxx_atu_cmd(ds, GLOBAL_ATU_OP_GET_NEXT_DB); |
| 2361 | if (ret < 0) |
| 2362 | return ret; |
| 2363 | |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2364 | data = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA); |
| 2365 | if (data < 0) |
| 2366 | return data; |
| 2367 | |
| 2368 | state = data & GLOBAL_ATU_DATA_STATE_MASK; |
| 2369 | if (state == GLOBAL_ATU_DATA_STATE_UNUSED) |
| 2370 | break; |
Vivien Didelot | c5723ac | 2015-08-10 09:09:48 -0400 | [diff] [blame] | 2371 | ret = _mv88e6xxx_atu_mac_read(ds, addr); |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2372 | if (ret < 0) |
| 2373 | return ret; |
| 2374 | mv88e6xxx_atu_show_entry(s, dbnum, addr, data); |
| 2375 | } while (state != GLOBAL_ATU_DATA_STATE_UNUSED); |
| 2376 | |
| 2377 | return 0; |
| 2378 | } |
| 2379 | |
| 2380 | static int mv88e6xxx_atu_show(struct seq_file *s, void *p) |
| 2381 | { |
| 2382 | struct dsa_switch *ds = s->private; |
| 2383 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2384 | int dbnum; |
| 2385 | |
| 2386 | mv88e6xxx_atu_show_header(s); |
| 2387 | |
| 2388 | for (dbnum = 0; dbnum < 255; dbnum++) { |
| 2389 | mutex_lock(&ps->smi_mutex); |
| 2390 | mv88e6xxx_atu_show_db(s, ds, dbnum); |
| 2391 | mutex_unlock(&ps->smi_mutex); |
| 2392 | } |
| 2393 | |
| 2394 | return 0; |
| 2395 | } |
| 2396 | |
| 2397 | static int mv88e6xxx_atu_open(struct inode *inode, struct file *file) |
| 2398 | { |
| 2399 | return single_open(file, mv88e6xxx_atu_show, inode->i_private); |
| 2400 | } |
| 2401 | |
| 2402 | static const struct file_operations mv88e6xxx_atu_fops = { |
| 2403 | .open = mv88e6xxx_atu_open, |
| 2404 | .read = seq_read, |
| 2405 | .llseek = no_llseek, |
| 2406 | .release = single_release, |
| 2407 | .owner = THIS_MODULE, |
| 2408 | }; |
| 2409 | |
Andrew Lunn | 532c7a3 | 2015-06-20 18:42:31 +0200 | [diff] [blame] | 2410 | static void mv88e6xxx_stats_show_header(struct seq_file *s, |
| 2411 | struct mv88e6xxx_priv_state *ps) |
| 2412 | { |
| 2413 | int port; |
| 2414 | |
| 2415 | seq_puts(s, " Statistic "); |
| 2416 | for (port = 0 ; port < ps->num_ports; port++) |
| 2417 | seq_printf(s, "Port %2d ", port); |
| 2418 | seq_puts(s, "\n"); |
| 2419 | } |
| 2420 | |
| 2421 | static int mv88e6xxx_stats_show(struct seq_file *s, void *p) |
| 2422 | { |
| 2423 | struct dsa_switch *ds = s->private; |
| 2424 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2425 | struct mv88e6xxx_hw_stat *stats = mv88e6xxx_hw_stats; |
| 2426 | int port, stat, max_stats; |
| 2427 | uint64_t value; |
| 2428 | |
| 2429 | if (have_sw_in_discards(ds)) |
| 2430 | max_stats = ARRAY_SIZE(mv88e6xxx_hw_stats); |
| 2431 | else |
| 2432 | max_stats = ARRAY_SIZE(mv88e6xxx_hw_stats) - 3; |
| 2433 | |
| 2434 | mv88e6xxx_stats_show_header(s, ps); |
| 2435 | |
| 2436 | mutex_lock(&ps->smi_mutex); |
| 2437 | |
| 2438 | for (stat = 0; stat < max_stats; stat++) { |
| 2439 | seq_printf(s, "%19s: ", stats[stat].string); |
| 2440 | for (port = 0 ; port < ps->num_ports; port++) { |
| 2441 | _mv88e6xxx_stats_snapshot(ds, port); |
| 2442 | value = _mv88e6xxx_get_ethtool_stat(ds, stat, stats, |
| 2443 | port); |
| 2444 | seq_printf(s, "%8llu ", value); |
| 2445 | } |
| 2446 | seq_puts(s, "\n"); |
| 2447 | } |
| 2448 | mutex_unlock(&ps->smi_mutex); |
| 2449 | |
| 2450 | return 0; |
| 2451 | } |
| 2452 | |
| 2453 | static int mv88e6xxx_stats_open(struct inode *inode, struct file *file) |
| 2454 | { |
| 2455 | return single_open(file, mv88e6xxx_stats_show, inode->i_private); |
| 2456 | } |
| 2457 | |
| 2458 | static const struct file_operations mv88e6xxx_stats_fops = { |
| 2459 | .open = mv88e6xxx_stats_open, |
| 2460 | .read = seq_read, |
| 2461 | .llseek = no_llseek, |
| 2462 | .release = single_release, |
| 2463 | .owner = THIS_MODULE, |
| 2464 | }; |
| 2465 | |
Andrew Lunn | d35bd87 | 2015-06-20 18:42:32 +0200 | [diff] [blame] | 2466 | static int mv88e6xxx_device_map_show(struct seq_file *s, void *p) |
| 2467 | { |
| 2468 | struct dsa_switch *ds = s->private; |
| 2469 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2470 | int target, ret; |
| 2471 | |
| 2472 | seq_puts(s, "Target Port\n"); |
| 2473 | |
| 2474 | mutex_lock(&ps->smi_mutex); |
| 2475 | for (target = 0; target < 32; target++) { |
| 2476 | ret = _mv88e6xxx_reg_write( |
| 2477 | ds, REG_GLOBAL2, GLOBAL2_DEVICE_MAPPING, |
| 2478 | target << GLOBAL2_DEVICE_MAPPING_TARGET_SHIFT); |
| 2479 | if (ret < 0) |
| 2480 | goto out; |
| 2481 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL2, |
| 2482 | GLOBAL2_DEVICE_MAPPING); |
| 2483 | seq_printf(s, " %2d %2d\n", target, |
| 2484 | ret & GLOBAL2_DEVICE_MAPPING_PORT_MASK); |
| 2485 | } |
| 2486 | out: |
| 2487 | mutex_unlock(&ps->smi_mutex); |
| 2488 | |
| 2489 | return 0; |
| 2490 | } |
| 2491 | |
| 2492 | static int mv88e6xxx_device_map_open(struct inode *inode, struct file *file) |
| 2493 | { |
| 2494 | return single_open(file, mv88e6xxx_device_map_show, inode->i_private); |
| 2495 | } |
| 2496 | |
| 2497 | static const struct file_operations mv88e6xxx_device_map_fops = { |
| 2498 | .open = mv88e6xxx_device_map_open, |
| 2499 | .read = seq_read, |
| 2500 | .llseek = no_llseek, |
| 2501 | .release = single_release, |
| 2502 | .owner = THIS_MODULE, |
| 2503 | }; |
| 2504 | |
Andrew Lunn | 56d95e2 | 2015-06-20 18:42:33 +0200 | [diff] [blame] | 2505 | static int mv88e6xxx_scratch_show(struct seq_file *s, void *p) |
| 2506 | { |
| 2507 | struct dsa_switch *ds = s->private; |
| 2508 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2509 | int reg, ret; |
| 2510 | |
| 2511 | seq_puts(s, "Register Value\n"); |
| 2512 | |
| 2513 | mutex_lock(&ps->smi_mutex); |
| 2514 | for (reg = 0; reg < 0x80; reg++) { |
| 2515 | ret = _mv88e6xxx_reg_write( |
| 2516 | ds, REG_GLOBAL2, GLOBAL2_SCRATCH_MISC, |
| 2517 | reg << GLOBAL2_SCRATCH_REGISTER_SHIFT); |
| 2518 | if (ret < 0) |
| 2519 | goto out; |
| 2520 | |
| 2521 | ret = _mv88e6xxx_scratch_wait(ds); |
| 2522 | if (ret < 0) |
| 2523 | goto out; |
| 2524 | |
| 2525 | ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL2, |
| 2526 | GLOBAL2_SCRATCH_MISC); |
| 2527 | seq_printf(s, " %2x %2x\n", reg, |
| 2528 | ret & GLOBAL2_SCRATCH_VALUE_MASK); |
| 2529 | } |
| 2530 | out: |
| 2531 | mutex_unlock(&ps->smi_mutex); |
| 2532 | |
| 2533 | return 0; |
| 2534 | } |
| 2535 | |
| 2536 | static int mv88e6xxx_scratch_open(struct inode *inode, struct file *file) |
| 2537 | { |
| 2538 | return single_open(file, mv88e6xxx_scratch_show, inode->i_private); |
| 2539 | } |
| 2540 | |
| 2541 | static const struct file_operations mv88e6xxx_scratch_fops = { |
| 2542 | .open = mv88e6xxx_scratch_open, |
| 2543 | .read = seq_read, |
| 2544 | .llseek = no_llseek, |
| 2545 | .release = single_release, |
| 2546 | .owner = THIS_MODULE, |
| 2547 | }; |
| 2548 | |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2549 | int mv88e6xxx_setup_common(struct dsa_switch *ds) |
| 2550 | { |
| 2551 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 2552 | char *name; |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2553 | |
| 2554 | mutex_init(&ps->smi_mutex); |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2555 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 2556 | ps->id = REG_READ(REG_PORT(0), PORT_SWITCH_ID) & 0xfff0; |
Andrew Lunn | a8f064c | 2015-03-26 18:36:40 -0700 | [diff] [blame] | 2557 | |
Guenter Roeck | facd95b | 2015-03-26 18:36:35 -0700 | [diff] [blame] | 2558 | INIT_WORK(&ps->bridge_work, mv88e6xxx_bridge_work); |
| 2559 | |
Andrew Lunn | 87c8cef | 2015-06-20 18:42:28 +0200 | [diff] [blame] | 2560 | name = kasprintf(GFP_KERNEL, "dsa%d", ds->index); |
| 2561 | ps->dbgfs = debugfs_create_dir(name, NULL); |
| 2562 | kfree(name); |
| 2563 | |
| 2564 | debugfs_create_file("regs", S_IRUGO, ps->dbgfs, ds, |
| 2565 | &mv88e6xxx_regs_fops); |
| 2566 | |
Andrew Lunn | 8a0a265 | 2015-06-20 18:42:29 +0200 | [diff] [blame] | 2567 | debugfs_create_file("atu", S_IRUGO, ps->dbgfs, ds, |
| 2568 | &mv88e6xxx_atu_fops); |
| 2569 | |
Andrew Lunn | 532c7a3 | 2015-06-20 18:42:31 +0200 | [diff] [blame] | 2570 | debugfs_create_file("stats", S_IRUGO, ps->dbgfs, ds, |
| 2571 | &mv88e6xxx_stats_fops); |
| 2572 | |
Andrew Lunn | d35bd87 | 2015-06-20 18:42:32 +0200 | [diff] [blame] | 2573 | debugfs_create_file("device_map", S_IRUGO, ps->dbgfs, ds, |
| 2574 | &mv88e6xxx_device_map_fops); |
Andrew Lunn | 56d95e2 | 2015-06-20 18:42:33 +0200 | [diff] [blame] | 2575 | |
| 2576 | debugfs_create_file("scratch", S_IRUGO, ps->dbgfs, ds, |
| 2577 | &mv88e6xxx_scratch_fops); |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 2578 | return 0; |
| 2579 | } |
| 2580 | |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2581 | int mv88e6xxx_setup_global(struct dsa_switch *ds) |
| 2582 | { |
| 2583 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2584 | int ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2585 | int i; |
| 2586 | |
| 2587 | /* Set the default address aging time to 5 minutes, and |
| 2588 | * enable address learn messages to be sent to all message |
| 2589 | * ports. |
| 2590 | */ |
| 2591 | REG_WRITE(REG_GLOBAL, GLOBAL_ATU_CONTROL, |
| 2592 | 0x0140 | GLOBAL_ATU_CONTROL_LEARN2ALL); |
| 2593 | |
| 2594 | /* Configure the IP ToS mapping registers. */ |
| 2595 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_0, 0x0000); |
| 2596 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_1, 0x0000); |
| 2597 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_2, 0x5555); |
| 2598 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_3, 0x5555); |
| 2599 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_4, 0xaaaa); |
| 2600 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_5, 0xaaaa); |
| 2601 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_6, 0xffff); |
| 2602 | REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_7, 0xffff); |
| 2603 | |
| 2604 | /* Configure the IEEE 802.1p priority mapping register. */ |
| 2605 | REG_WRITE(REG_GLOBAL, GLOBAL_IEEE_PRI, 0xfa41); |
| 2606 | |
| 2607 | /* Send all frames with destination addresses matching |
| 2608 | * 01:80:c2:00:00:0x to the CPU port. |
| 2609 | */ |
| 2610 | REG_WRITE(REG_GLOBAL2, GLOBAL2_MGMT_EN_0X, 0xffff); |
| 2611 | |
| 2612 | /* Ignore removed tag data on doubly tagged packets, disable |
| 2613 | * flow control messages, force flow control priority to the |
| 2614 | * highest, and send all special multicast frames to the CPU |
| 2615 | * port at the highest priority. |
| 2616 | */ |
| 2617 | REG_WRITE(REG_GLOBAL2, GLOBAL2_SWITCH_MGMT, |
| 2618 | 0x7 | GLOBAL2_SWITCH_MGMT_RSVD2CPU | 0x70 | |
| 2619 | GLOBAL2_SWITCH_MGMT_FORCE_FLOW_CTRL_PRI); |
| 2620 | |
| 2621 | /* Program the DSA routing table. */ |
| 2622 | for (i = 0; i < 32; i++) { |
| 2623 | int nexthop = 0x1f; |
| 2624 | |
| 2625 | if (ds->pd->rtable && |
| 2626 | i != ds->index && i < ds->dst->pd->nr_chips) |
| 2627 | nexthop = ds->pd->rtable[i] & 0x1f; |
| 2628 | |
| 2629 | REG_WRITE(REG_GLOBAL2, GLOBAL2_DEVICE_MAPPING, |
| 2630 | GLOBAL2_DEVICE_MAPPING_UPDATE | |
| 2631 | (i << GLOBAL2_DEVICE_MAPPING_TARGET_SHIFT) | |
| 2632 | nexthop); |
| 2633 | } |
| 2634 | |
| 2635 | /* Clear all trunk masks. */ |
| 2636 | for (i = 0; i < 8; i++) |
| 2637 | REG_WRITE(REG_GLOBAL2, GLOBAL2_TRUNK_MASK, |
| 2638 | 0x8000 | (i << GLOBAL2_TRUNK_MASK_NUM_SHIFT) | |
| 2639 | ((1 << ps->num_ports) - 1)); |
| 2640 | |
| 2641 | /* Clear all trunk mappings. */ |
| 2642 | for (i = 0; i < 16; i++) |
| 2643 | REG_WRITE(REG_GLOBAL2, GLOBAL2_TRUNK_MAPPING, |
| 2644 | GLOBAL2_TRUNK_MAPPING_UPDATE | |
| 2645 | (i << GLOBAL2_TRUNK_MAPPING_ID_SHIFT)); |
| 2646 | |
| 2647 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2648 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
| 2649 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2650 | /* Send all frames with destination addresses matching |
| 2651 | * 01:80:c2:00:00:2x to the CPU port. |
| 2652 | */ |
| 2653 | REG_WRITE(REG_GLOBAL2, GLOBAL2_MGMT_EN_2X, 0xffff); |
| 2654 | |
| 2655 | /* Initialise cross-chip port VLAN table to reset |
| 2656 | * defaults. |
| 2657 | */ |
| 2658 | REG_WRITE(REG_GLOBAL2, GLOBAL2_PVT_ADDR, 0x9000); |
| 2659 | |
| 2660 | /* Clear the priority override table. */ |
| 2661 | for (i = 0; i < 16; i++) |
| 2662 | REG_WRITE(REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE, |
| 2663 | 0x8000 | (i << 8)); |
| 2664 | } |
| 2665 | |
| 2666 | if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) || |
| 2667 | mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) || |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 2668 | mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) || |
| 2669 | mv88e6xxx_6320_family(ds)) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2670 | /* Disable ingress rate limiting by resetting all |
| 2671 | * ingress rate limit registers to their initial |
| 2672 | * state. |
| 2673 | */ |
| 2674 | for (i = 0; i < ps->num_ports; i++) |
| 2675 | REG_WRITE(REG_GLOBAL2, GLOBAL2_INGRESS_OP, |
| 2676 | 0x9000 | (i << 8)); |
| 2677 | } |
| 2678 | |
Andrew Lunn | db687a5 | 2015-06-20 21:31:29 +0200 | [diff] [blame] | 2679 | /* Clear the statistics counters for all ports */ |
| 2680 | REG_WRITE(REG_GLOBAL, GLOBAL_STATS_OP, GLOBAL_STATS_OP_FLUSH_ALL); |
| 2681 | |
| 2682 | /* Wait for the flush to complete. */ |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2683 | mutex_lock(&ps->smi_mutex); |
| 2684 | ret = _mv88e6xxx_stats_wait(ds); |
Vivien Didelot | 6b17e86 | 2015-08-13 12:52:18 -0400 | [diff] [blame] | 2685 | if (ret < 0) |
| 2686 | goto unlock; |
| 2687 | |
| 2688 | /* Clear all the VTU and STU entries */ |
| 2689 | ret = _mv88e6xxx_vtu_stu_flush(ds); |
| 2690 | unlock: |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2691 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | db687a5 | 2015-06-20 21:31:29 +0200 | [diff] [blame] | 2692 | |
Vivien Didelot | 24751e2 | 2015-08-03 09:17:44 -0400 | [diff] [blame] | 2693 | return ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 2694 | } |
| 2695 | |
Andrew Lunn | 143a830 | 2015-04-02 04:06:34 +0200 | [diff] [blame] | 2696 | int mv88e6xxx_switch_reset(struct dsa_switch *ds, bool ppu_active) |
| 2697 | { |
| 2698 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2699 | u16 is_reset = (ppu_active ? 0x8800 : 0xc800); |
| 2700 | unsigned long timeout; |
| 2701 | int ret; |
| 2702 | int i; |
| 2703 | |
| 2704 | /* Set all ports to the disabled state. */ |
| 2705 | for (i = 0; i < ps->num_ports; i++) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 2706 | ret = REG_READ(REG_PORT(i), PORT_CONTROL); |
| 2707 | REG_WRITE(REG_PORT(i), PORT_CONTROL, ret & 0xfffc); |
Andrew Lunn | 143a830 | 2015-04-02 04:06:34 +0200 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | /* Wait for transmit queues to drain. */ |
| 2711 | usleep_range(2000, 4000); |
| 2712 | |
| 2713 | /* Reset the switch. Keep the PPU active if requested. The PPU |
| 2714 | * needs to be active to support indirect phy register access |
| 2715 | * through global registers 0x18 and 0x19. |
| 2716 | */ |
| 2717 | if (ppu_active) |
| 2718 | REG_WRITE(REG_GLOBAL, 0x04, 0xc000); |
| 2719 | else |
| 2720 | REG_WRITE(REG_GLOBAL, 0x04, 0xc400); |
| 2721 | |
| 2722 | /* Wait up to one second for reset to complete. */ |
| 2723 | timeout = jiffies + 1 * HZ; |
| 2724 | while (time_before(jiffies, timeout)) { |
| 2725 | ret = REG_READ(REG_GLOBAL, 0x00); |
| 2726 | if ((ret & is_reset) == is_reset) |
| 2727 | break; |
| 2728 | usleep_range(1000, 2000); |
| 2729 | } |
| 2730 | if (time_after(jiffies, timeout)) |
| 2731 | return -ETIMEDOUT; |
| 2732 | |
| 2733 | return 0; |
| 2734 | } |
| 2735 | |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2736 | int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg) |
| 2737 | { |
| 2738 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2739 | int ret; |
| 2740 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2741 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2742 | ret = _mv88e6xxx_phy_write_indirect(ds, port, 0x16, page); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2743 | if (ret < 0) |
| 2744 | goto error; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2745 | ret = _mv88e6xxx_phy_read_indirect(ds, port, reg); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2746 | error: |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2747 | _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2748 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2749 | return ret; |
| 2750 | } |
| 2751 | |
| 2752 | int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page, |
| 2753 | int reg, int val) |
| 2754 | { |
| 2755 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2756 | int ret; |
| 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_indirect(ds, port, 0x16, page); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2760 | if (ret < 0) |
| 2761 | goto error; |
| 2762 | |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2763 | ret = _mv88e6xxx_phy_write_indirect(ds, port, reg, val); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2764 | error: |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2765 | _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2766 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2767 | return ret; |
| 2768 | } |
| 2769 | |
| 2770 | static int mv88e6xxx_port_to_phy_addr(struct dsa_switch *ds, int port) |
| 2771 | { |
| 2772 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2773 | |
| 2774 | if (port >= 0 && port < ps->num_ports) |
| 2775 | return port; |
| 2776 | return -EINVAL; |
| 2777 | } |
| 2778 | |
| 2779 | int |
| 2780 | mv88e6xxx_phy_read(struct dsa_switch *ds, int port, int regnum) |
| 2781 | { |
| 2782 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2783 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2784 | int ret; |
| 2785 | |
| 2786 | if (addr < 0) |
| 2787 | return addr; |
| 2788 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2789 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2790 | ret = _mv88e6xxx_phy_read(ds, addr, regnum); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2791 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2792 | return ret; |
| 2793 | } |
| 2794 | |
| 2795 | int |
| 2796 | mv88e6xxx_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val) |
| 2797 | { |
| 2798 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2799 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2800 | int ret; |
| 2801 | |
| 2802 | if (addr < 0) |
| 2803 | return addr; |
| 2804 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2805 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2806 | ret = _mv88e6xxx_phy_write(ds, addr, regnum, val); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2807 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2808 | return ret; |
| 2809 | } |
| 2810 | |
| 2811 | int |
| 2812 | mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int port, int regnum) |
| 2813 | { |
| 2814 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2815 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2816 | int ret; |
| 2817 | |
| 2818 | if (addr < 0) |
| 2819 | return addr; |
| 2820 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2821 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2822 | ret = _mv88e6xxx_phy_read_indirect(ds, addr, regnum); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2823 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2824 | return ret; |
| 2825 | } |
| 2826 | |
| 2827 | int |
| 2828 | mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int port, int regnum, |
| 2829 | u16 val) |
| 2830 | { |
| 2831 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2832 | int addr = mv88e6xxx_port_to_phy_addr(ds, port); |
| 2833 | int ret; |
| 2834 | |
| 2835 | if (addr < 0) |
| 2836 | return addr; |
| 2837 | |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2838 | mutex_lock(&ps->smi_mutex); |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2839 | ret = _mv88e6xxx_phy_write_indirect(ds, addr, regnum, val); |
Andrew Lunn | 3898c14 | 2015-05-06 01:09:53 +0200 | [diff] [blame] | 2840 | mutex_unlock(&ps->smi_mutex); |
Andrew Lunn | 49143585 | 2015-04-02 04:06:35 +0200 | [diff] [blame] | 2841 | return ret; |
| 2842 | } |
| 2843 | |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 2844 | #ifdef CONFIG_NET_DSA_HWMON |
| 2845 | |
| 2846 | static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp) |
| 2847 | { |
| 2848 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 2849 | int ret; |
| 2850 | int val; |
| 2851 | |
| 2852 | *temp = 0; |
| 2853 | |
| 2854 | mutex_lock(&ps->smi_mutex); |
| 2855 | |
| 2856 | ret = _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x6); |
| 2857 | if (ret < 0) |
| 2858 | goto error; |
| 2859 | |
| 2860 | /* Enable temperature sensor */ |
| 2861 | ret = _mv88e6xxx_phy_read(ds, 0x0, 0x1a); |
| 2862 | if (ret < 0) |
| 2863 | goto error; |
| 2864 | |
| 2865 | ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret | (1 << 5)); |
| 2866 | if (ret < 0) |
| 2867 | goto error; |
| 2868 | |
| 2869 | /* Wait for temperature to stabilize */ |
| 2870 | usleep_range(10000, 12000); |
| 2871 | |
| 2872 | val = _mv88e6xxx_phy_read(ds, 0x0, 0x1a); |
| 2873 | if (val < 0) { |
| 2874 | ret = val; |
| 2875 | goto error; |
| 2876 | } |
| 2877 | |
| 2878 | /* Disable temperature sensor */ |
| 2879 | ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret & ~(1 << 5)); |
| 2880 | if (ret < 0) |
| 2881 | goto error; |
| 2882 | |
| 2883 | *temp = ((val & 0x1f) - 5) * 5; |
| 2884 | |
| 2885 | error: |
| 2886 | _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x0); |
| 2887 | mutex_unlock(&ps->smi_mutex); |
| 2888 | return ret; |
| 2889 | } |
| 2890 | |
| 2891 | static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp) |
| 2892 | { |
| 2893 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2894 | int ret; |
| 2895 | |
| 2896 | *temp = 0; |
| 2897 | |
| 2898 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 27); |
| 2899 | if (ret < 0) |
| 2900 | return ret; |
| 2901 | |
| 2902 | *temp = (ret & 0xff) - 25; |
| 2903 | |
| 2904 | return 0; |
| 2905 | } |
| 2906 | |
| 2907 | int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp) |
| 2908 | { |
| 2909 | if (mv88e6xxx_6320_family(ds) || mv88e6xxx_6352_family(ds)) |
| 2910 | return mv88e63xx_get_temp(ds, temp); |
| 2911 | |
| 2912 | return mv88e61xx_get_temp(ds, temp); |
| 2913 | } |
| 2914 | |
| 2915 | int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp) |
| 2916 | { |
| 2917 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2918 | int ret; |
| 2919 | |
| 2920 | if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds)) |
| 2921 | return -EOPNOTSUPP; |
| 2922 | |
| 2923 | *temp = 0; |
| 2924 | |
| 2925 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26); |
| 2926 | if (ret < 0) |
| 2927 | return ret; |
| 2928 | |
| 2929 | *temp = (((ret >> 8) & 0x1f) * 5) - 25; |
| 2930 | |
| 2931 | return 0; |
| 2932 | } |
| 2933 | |
| 2934 | int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp) |
| 2935 | { |
| 2936 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2937 | int ret; |
| 2938 | |
| 2939 | if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds)) |
| 2940 | return -EOPNOTSUPP; |
| 2941 | |
| 2942 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26); |
| 2943 | if (ret < 0) |
| 2944 | return ret; |
| 2945 | temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); |
| 2946 | return mv88e6xxx_phy_page_write(ds, phy, 6, 26, |
| 2947 | (ret & 0xe0ff) | (temp << 8)); |
| 2948 | } |
| 2949 | |
| 2950 | int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm) |
| 2951 | { |
| 2952 | int phy = mv88e6xxx_6320_family(ds) ? 3 : 0; |
| 2953 | int ret; |
| 2954 | |
| 2955 | if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds)) |
| 2956 | return -EOPNOTSUPP; |
| 2957 | |
| 2958 | *alarm = false; |
| 2959 | |
| 2960 | ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26); |
| 2961 | if (ret < 0) |
| 2962 | return ret; |
| 2963 | |
| 2964 | *alarm = !!(ret & 0x40); |
| 2965 | |
| 2966 | return 0; |
| 2967 | } |
| 2968 | #endif /* CONFIG_NET_DSA_HWMON */ |
| 2969 | |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 2970 | static int __init mv88e6xxx_init(void) |
| 2971 | { |
| 2972 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) |
| 2973 | register_switch_driver(&mv88e6131_switch_driver); |
| 2974 | #endif |
| 2975 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65) |
| 2976 | register_switch_driver(&mv88e6123_61_65_switch_driver); |
| 2977 | #endif |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 2978 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6352) |
| 2979 | register_switch_driver(&mv88e6352_switch_driver); |
| 2980 | #endif |
Andrew Lunn | 42f2725 | 2014-09-12 23:58:44 +0200 | [diff] [blame] | 2981 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6171) |
| 2982 | register_switch_driver(&mv88e6171_switch_driver); |
| 2983 | #endif |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 2984 | return 0; |
| 2985 | } |
| 2986 | module_init(mv88e6xxx_init); |
| 2987 | |
| 2988 | static void __exit mv88e6xxx_cleanup(void) |
| 2989 | { |
Andrew Lunn | 42f2725 | 2014-09-12 23:58:44 +0200 | [diff] [blame] | 2990 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6171) |
| 2991 | unregister_switch_driver(&mv88e6171_switch_driver); |
| 2992 | #endif |
Vivien Didelot | 4212b543 | 2015-05-01 10:43:52 -0400 | [diff] [blame] | 2993 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6352) |
| 2994 | unregister_switch_driver(&mv88e6352_switch_driver); |
| 2995 | #endif |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 2996 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65) |
| 2997 | unregister_switch_driver(&mv88e6123_61_65_switch_driver); |
| 2998 | #endif |
| 2999 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) |
| 3000 | unregister_switch_driver(&mv88e6131_switch_driver); |
| 3001 | #endif |
| 3002 | } |
| 3003 | module_exit(mv88e6xxx_cleanup); |
Ben Hutchings | 3d825ed | 2011-11-25 14:37:16 +0000 | [diff] [blame] | 3004 | |
| 3005 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>"); |
| 3006 | MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips"); |
| 3007 | MODULE_LICENSE("GPL"); |