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