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