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