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