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