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