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