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 | { |
Andrew Lunn | 0dd12d5 | 2017-01-24 14:53:49 +0100 | [diff] [blame^] | 2905 | struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; |
| 2906 | struct mv88e6xxx_chip *chip = mdio_bus->chip; |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 2907 | u16 val; |
| 2908 | int err; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2909 | |
Vivien Didelot | 370b4ff | 2016-09-29 12:21:57 -0400 | [diff] [blame] | 2910 | if (phy >= mv88e6xxx_num_ports(chip)) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2911 | return 0xffff; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2912 | |
Andrew Lunn | ee26a22 | 2017-01-24 14:53:48 +0100 | [diff] [blame] | 2913 | if (!chip->info->ops->phy_read) |
| 2914 | return -EOPNOTSUPP; |
| 2915 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2916 | mutex_lock(&chip->reg_lock); |
Andrew Lunn | ee26a22 | 2017-01-24 14:53:48 +0100 | [diff] [blame] | 2917 | err = chip->info->ops->phy_read(chip, bus, phy, reg, &val); |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2918 | mutex_unlock(&chip->reg_lock); |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 2919 | |
| 2920 | return err ? err : val; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2921 | } |
| 2922 | |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 2923 | 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] | 2924 | { |
Andrew Lunn | 0dd12d5 | 2017-01-24 14:53:49 +0100 | [diff] [blame^] | 2925 | struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; |
| 2926 | struct mv88e6xxx_chip *chip = mdio_bus->chip; |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 2927 | int err; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2928 | |
Vivien Didelot | 370b4ff | 2016-09-29 12:21:57 -0400 | [diff] [blame] | 2929 | if (phy >= mv88e6xxx_num_ports(chip)) |
Andrew Lunn | 158bc06 | 2016-04-28 21:24:06 -0400 | [diff] [blame] | 2930 | return 0xffff; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2931 | |
Andrew Lunn | ee26a22 | 2017-01-24 14:53:48 +0100 | [diff] [blame] | 2932 | if (!chip->info->ops->phy_write) |
| 2933 | return -EOPNOTSUPP; |
| 2934 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2935 | mutex_lock(&chip->reg_lock); |
Andrew Lunn | ee26a22 | 2017-01-24 14:53:48 +0100 | [diff] [blame] | 2936 | err = chip->info->ops->phy_write(chip, bus, phy, reg, val); |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2937 | mutex_unlock(&chip->reg_lock); |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 2938 | |
| 2939 | return err; |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 2940 | } |
| 2941 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2942 | static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip, |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2943 | struct device_node *np) |
| 2944 | { |
| 2945 | static int index; |
Andrew Lunn | 0dd12d5 | 2017-01-24 14:53:49 +0100 | [diff] [blame^] | 2946 | struct mv88e6xxx_mdio_bus *mdio_bus; |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2947 | struct mii_bus *bus; |
| 2948 | int err; |
| 2949 | |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2950 | if (np) |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2951 | chip->mdio_np = of_get_child_by_name(np, "mdio"); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2952 | |
Andrew Lunn | 0dd12d5 | 2017-01-24 14:53:49 +0100 | [diff] [blame^] | 2953 | bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus)); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2954 | if (!bus) |
| 2955 | return -ENOMEM; |
| 2956 | |
Andrew Lunn | 0dd12d5 | 2017-01-24 14:53:49 +0100 | [diff] [blame^] | 2957 | mdio_bus = bus->priv; |
| 2958 | mdio_bus->chip = chip; |
| 2959 | |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2960 | if (np) { |
| 2961 | bus->name = np->full_name; |
| 2962 | snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name); |
| 2963 | } else { |
| 2964 | bus->name = "mv88e6xxx SMI"; |
| 2965 | snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++); |
| 2966 | } |
| 2967 | |
| 2968 | bus->read = mv88e6xxx_mdio_read; |
| 2969 | bus->write = mv88e6xxx_mdio_write; |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2970 | bus->parent = chip->dev; |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2971 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2972 | if (chip->mdio_np) |
| 2973 | err = of_mdiobus_register(bus, chip->mdio_np); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2974 | else |
| 2975 | err = mdiobus_register(bus); |
| 2976 | if (err) { |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2977 | dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2978 | goto out; |
| 2979 | } |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2980 | chip->mdio_bus = bus; |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2981 | |
| 2982 | return 0; |
| 2983 | |
| 2984 | out: |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2985 | if (chip->mdio_np) |
| 2986 | of_node_put(chip->mdio_np); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2987 | |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2991 | static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip) |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2992 | |
| 2993 | { |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2994 | struct mii_bus *bus = chip->mdio_bus; |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 2995 | |
| 2996 | mdiobus_unregister(bus); |
| 2997 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 2998 | if (chip->mdio_np) |
| 2999 | of_node_put(chip->mdio_np); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 3000 | } |
| 3001 | |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3002 | static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds) |
| 3003 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 3004 | struct mv88e6xxx_chip *chip = ds->priv; |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3005 | |
| 3006 | return chip->eeprom_len; |
| 3007 | } |
| 3008 | |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3009 | static int mv88e6xxx_get_eeprom(struct dsa_switch *ds, |
| 3010 | struct ethtool_eeprom *eeprom, u8 *data) |
| 3011 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 3012 | struct mv88e6xxx_chip *chip = ds->priv; |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3013 | int err; |
| 3014 | |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3015 | if (!chip->info->ops->get_eeprom) |
| 3016 | return -EOPNOTSUPP; |
| 3017 | |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3018 | mutex_lock(&chip->reg_lock); |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3019 | err = chip->info->ops->get_eeprom(chip, eeprom, data); |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3020 | mutex_unlock(&chip->reg_lock); |
| 3021 | |
| 3022 | if (err) |
| 3023 | return err; |
| 3024 | |
| 3025 | eeprom->magic = 0xc3ec4951; |
| 3026 | |
| 3027 | return 0; |
| 3028 | } |
| 3029 | |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3030 | static int mv88e6xxx_set_eeprom(struct dsa_switch *ds, |
| 3031 | struct ethtool_eeprom *eeprom, u8 *data) |
| 3032 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 3033 | struct mv88e6xxx_chip *chip = ds->priv; |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3034 | int err; |
| 3035 | |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3036 | if (!chip->info->ops->set_eeprom) |
| 3037 | return -EOPNOTSUPP; |
| 3038 | |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3039 | if (eeprom->magic != 0xc3ec4951) |
| 3040 | return -EINVAL; |
| 3041 | |
| 3042 | mutex_lock(&chip->reg_lock); |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3043 | err = chip->info->ops->set_eeprom(chip, eeprom, data); |
Vivien Didelot | 855b193 | 2016-07-20 18:18:35 -0400 | [diff] [blame] | 3044 | mutex_unlock(&chip->reg_lock); |
| 3045 | |
| 3046 | return err; |
| 3047 | } |
| 3048 | |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3049 | static const struct mv88e6xxx_ops mv88e6085_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3050 | /* MV88E6XXX_FAMILY_6097 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3051 | .set_switch_mac = mv88e6xxx_g1_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3052 | .phy_read = mv88e6xxx_phy_ppu_read, |
| 3053 | .phy_write = mv88e6xxx_phy_ppu_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3054 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3055 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3056 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3057 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3058 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3059 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3060 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3061 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3062 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3063 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3064 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3065 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3066 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3067 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3068 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3069 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | a199d8b | 2016-12-05 17:30:28 -0500 | [diff] [blame] | 3070 | .ppu_enable = mv88e6185_g1_ppu_enable, |
| 3071 | .ppu_disable = mv88e6185_g1_ppu_disable, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3072 | .reset = mv88e6185_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3073 | }; |
| 3074 | |
| 3075 | static const struct mv88e6xxx_ops mv88e6095_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3076 | /* MV88E6XXX_FAMILY_6095 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3077 | .set_switch_mac = mv88e6xxx_g1_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3078 | .phy_read = mv88e6xxx_phy_ppu_read, |
| 3079 | .phy_write = mv88e6xxx_phy_ppu_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3080 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3081 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3082 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3083 | .port_set_frame_mode = mv88e6085_port_set_frame_mode, |
| 3084 | .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3085 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3086 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3087 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3088 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3089 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | a199d8b | 2016-12-05 17:30:28 -0500 | [diff] [blame] | 3090 | .ppu_enable = mv88e6185_g1_ppu_enable, |
| 3091 | .ppu_disable = mv88e6185_g1_ppu_disable, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3092 | .reset = mv88e6185_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3093 | }; |
| 3094 | |
Stefan Eichenberger | 7d381a0 | 2016-11-22 17:47:21 +0100 | [diff] [blame] | 3095 | static const struct mv88e6xxx_ops mv88e6097_ops = { |
Stefan Eichenberger | 15da3cc | 2016-11-25 09:41:30 +0100 | [diff] [blame] | 3096 | /* MV88E6XXX_FAMILY_6097 */ |
Stefan Eichenberger | 7d381a0 | 2016-11-22 17:47:21 +0100 | [diff] [blame] | 3097 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3098 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3099 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3100 | .port_set_link = mv88e6xxx_port_set_link, |
| 3101 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3102 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3103 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3104 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3105 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3106 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3107 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3108 | .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3109 | .port_pause_config = mv88e6097_port_pause_config, |
Stefan Eichenberger | 7d381a0 | 2016-11-22 17:47:21 +0100 | [diff] [blame] | 3110 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
| 3111 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3112 | .stats_get_strings = mv88e6095_stats_get_strings, |
| 3113 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3114 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3115 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3116 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3117 | .reset = mv88e6352_g1_reset, |
Stefan Eichenberger | 7d381a0 | 2016-11-22 17:47:21 +0100 | [diff] [blame] | 3118 | }; |
| 3119 | |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3120 | static const struct mv88e6xxx_ops mv88e6123_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3121 | /* MV88E6XXX_FAMILY_6165 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3122 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Andrew Lunn | efb3e74 | 2017-01-24 14:53:47 +0100 | [diff] [blame] | 3123 | .phy_read = mv88e6165_phy_read, |
| 3124 | .phy_write = mv88e6165_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3125 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3126 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3127 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3128 | .port_set_frame_mode = mv88e6085_port_set_frame_mode, |
| 3129 | .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3130 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3131 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3132 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3133 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3134 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3135 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3136 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3137 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3138 | }; |
| 3139 | |
| 3140 | static const struct mv88e6xxx_ops mv88e6131_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3141 | /* MV88E6XXX_FAMILY_6185 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3142 | .set_switch_mac = mv88e6xxx_g1_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3143 | .phy_read = mv88e6xxx_phy_ppu_read, |
| 3144 | .phy_write = mv88e6xxx_phy_ppu_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3145 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3146 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3147 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3148 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3149 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3150 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3151 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3152 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3153 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3154 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3155 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3156 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3157 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3158 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3159 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3160 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3161 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | a199d8b | 2016-12-05 17:30:28 -0500 | [diff] [blame] | 3162 | .ppu_enable = mv88e6185_g1_ppu_enable, |
| 3163 | .ppu_disable = mv88e6185_g1_ppu_disable, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3164 | .reset = mv88e6185_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3165 | }; |
| 3166 | |
| 3167 | static const struct mv88e6xxx_ops mv88e6161_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3168 | /* MV88E6XXX_FAMILY_6165 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3169 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Andrew Lunn | efb3e74 | 2017-01-24 14:53:47 +0100 | [diff] [blame] | 3170 | .phy_read = mv88e6165_phy_read, |
| 3171 | .phy_write = mv88e6165_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3172 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3173 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3174 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3175 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3176 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3177 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3178 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3179 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3180 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3181 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3182 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3183 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3184 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3185 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3186 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3187 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3188 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3189 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3190 | }; |
| 3191 | |
| 3192 | static const struct mv88e6xxx_ops mv88e6165_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3193 | /* MV88E6XXX_FAMILY_6165 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3194 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Andrew Lunn | efb3e74 | 2017-01-24 14:53:47 +0100 | [diff] [blame] | 3195 | .phy_read = mv88e6165_phy_read, |
| 3196 | .phy_write = mv88e6165_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3197 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3198 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3199 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3200 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3201 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3202 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3203 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3204 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3205 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3206 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3207 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3208 | }; |
| 3209 | |
| 3210 | static const struct mv88e6xxx_ops mv88e6171_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3211 | /* MV88E6XXX_FAMILY_6351 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3212 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3213 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3214 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3215 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3216 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Andrew Lunn | 94d66ae | 2016-11-10 15:44:01 +0100 | [diff] [blame] | 3217 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3218 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3219 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3220 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3221 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3222 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3223 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3224 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3225 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3226 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3227 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3228 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3229 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3230 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3231 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3232 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3233 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3234 | }; |
| 3235 | |
| 3236 | static const struct mv88e6xxx_ops mv88e6172_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3237 | /* MV88E6XXX_FAMILY_6352 */ |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3238 | .get_eeprom = mv88e6xxx_g2_get_eeprom16, |
| 3239 | .set_eeprom = mv88e6xxx_g2_set_eeprom16, |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3240 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3241 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3242 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3243 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3244 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | a0a0f62 | 2016-11-04 03:23:34 +0100 | [diff] [blame] | 3245 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3246 | .port_set_speed = mv88e6352_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3247 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3248 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3249 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3250 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3251 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3252 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3253 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3254 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3255 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3256 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3257 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3258 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3259 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3260 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3261 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3262 | }; |
| 3263 | |
| 3264 | static const struct mv88e6xxx_ops mv88e6175_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3265 | /* MV88E6XXX_FAMILY_6351 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3266 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3267 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3268 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3269 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3270 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Andrew Lunn | 94d66ae | 2016-11-10 15:44:01 +0100 | [diff] [blame] | 3271 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3272 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3273 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3274 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3275 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3276 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3277 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3278 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3279 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3280 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3281 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3282 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3283 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3284 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3285 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3286 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3287 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3288 | }; |
| 3289 | |
| 3290 | static const struct mv88e6xxx_ops mv88e6176_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3291 | /* MV88E6XXX_FAMILY_6352 */ |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3292 | .get_eeprom = mv88e6xxx_g2_get_eeprom16, |
| 3293 | .set_eeprom = mv88e6xxx_g2_set_eeprom16, |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3294 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3295 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3296 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3297 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3298 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | a0a0f62 | 2016-11-04 03:23:34 +0100 | [diff] [blame] | 3299 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3300 | .port_set_speed = mv88e6352_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3301 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3302 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3303 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3304 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3305 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3306 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3307 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3308 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3309 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3310 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3311 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3312 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3313 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3314 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3315 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3316 | }; |
| 3317 | |
| 3318 | static const struct mv88e6xxx_ops mv88e6185_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3319 | /* MV88E6XXX_FAMILY_6185 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3320 | .set_switch_mac = mv88e6xxx_g1_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3321 | .phy_read = mv88e6xxx_phy_ppu_read, |
| 3322 | .phy_write = mv88e6xxx_phy_ppu_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3323 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3324 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3325 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3326 | .port_set_frame_mode = mv88e6085_port_set_frame_mode, |
| 3327 | .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3328 | .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3329 | .stats_snapshot = mv88e6xxx_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3330 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3331 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3332 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3333 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3334 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3335 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | a199d8b | 2016-12-05 17:30:28 -0500 | [diff] [blame] | 3336 | .ppu_enable = mv88e6185_g1_ppu_enable, |
| 3337 | .ppu_disable = mv88e6185_g1_ppu_disable, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3338 | .reset = mv88e6185_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3339 | }; |
| 3340 | |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3341 | static const struct mv88e6xxx_ops mv88e6190_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3342 | /* MV88E6XXX_FAMILY_6390 */ |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 3343 | .get_eeprom = mv88e6xxx_g2_get_eeprom8, |
| 3344 | .set_eeprom = mv88e6xxx_g2_set_eeprom8, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3345 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3346 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3347 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3348 | .port_set_link = mv88e6xxx_port_set_link, |
| 3349 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3350 | .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, |
| 3351 | .port_set_speed = mv88e6390_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3352 | .port_tag_remap = mv88e6390_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3353 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3354 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3355 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 3ce0e65 | 2016-12-03 04:45:20 +0100 | [diff] [blame] | 3356 | .port_pause_config = mv88e6390_port_pause_config, |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 3357 | .stats_snapshot = mv88e6390_g1_stats_snapshot, |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame] | 3358 | .stats_set_histogram = mv88e6390_g1_stats_set_histogram, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3359 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3360 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | e0d8b61 | 2016-11-21 23:27:04 +0100 | [diff] [blame] | 3361 | .stats_get_stats = mv88e6390_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3362 | .g1_set_cpu_port = mv88e6390_g1_set_cpu_port, |
| 3363 | .g1_set_egress_port = mv88e6390_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3364 | .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3365 | .reset = mv88e6352_g1_reset, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3366 | }; |
| 3367 | |
| 3368 | static const struct mv88e6xxx_ops mv88e6190x_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3369 | /* MV88E6XXX_FAMILY_6390 */ |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 3370 | .get_eeprom = mv88e6xxx_g2_get_eeprom8, |
| 3371 | .set_eeprom = mv88e6xxx_g2_set_eeprom8, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3372 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3373 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3374 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3375 | .port_set_link = mv88e6xxx_port_set_link, |
| 3376 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3377 | .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, |
| 3378 | .port_set_speed = mv88e6390x_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3379 | .port_tag_remap = mv88e6390_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3380 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3381 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3382 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 3ce0e65 | 2016-12-03 04:45:20 +0100 | [diff] [blame] | 3383 | .port_pause_config = mv88e6390_port_pause_config, |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 3384 | .stats_snapshot = mv88e6390_g1_stats_snapshot, |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame] | 3385 | .stats_set_histogram = mv88e6390_g1_stats_set_histogram, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3386 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3387 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | e0d8b61 | 2016-11-21 23:27:04 +0100 | [diff] [blame] | 3388 | .stats_get_stats = mv88e6390_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3389 | .g1_set_cpu_port = mv88e6390_g1_set_cpu_port, |
| 3390 | .g1_set_egress_port = mv88e6390_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3391 | .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3392 | .reset = mv88e6352_g1_reset, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3393 | }; |
| 3394 | |
| 3395 | static const struct mv88e6xxx_ops mv88e6191_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3396 | /* MV88E6XXX_FAMILY_6390 */ |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 3397 | .get_eeprom = mv88e6xxx_g2_get_eeprom8, |
| 3398 | .set_eeprom = mv88e6xxx_g2_set_eeprom8, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3399 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3400 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3401 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3402 | .port_set_link = mv88e6xxx_port_set_link, |
| 3403 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3404 | .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, |
| 3405 | .port_set_speed = mv88e6390_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3406 | .port_tag_remap = mv88e6390_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3407 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3408 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3409 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 3ce0e65 | 2016-12-03 04:45:20 +0100 | [diff] [blame] | 3410 | .port_pause_config = mv88e6390_port_pause_config, |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 3411 | .stats_snapshot = mv88e6390_g1_stats_snapshot, |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame] | 3412 | .stats_set_histogram = mv88e6390_g1_stats_set_histogram, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3413 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3414 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | e0d8b61 | 2016-11-21 23:27:04 +0100 | [diff] [blame] | 3415 | .stats_get_stats = mv88e6390_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3416 | .g1_set_cpu_port = mv88e6390_g1_set_cpu_port, |
| 3417 | .g1_set_egress_port = mv88e6390_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3418 | .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3419 | .reset = mv88e6352_g1_reset, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3420 | }; |
| 3421 | |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3422 | static const struct mv88e6xxx_ops mv88e6240_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3423 | /* MV88E6XXX_FAMILY_6352 */ |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3424 | .get_eeprom = mv88e6xxx_g2_get_eeprom16, |
| 3425 | .set_eeprom = mv88e6xxx_g2_set_eeprom16, |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3426 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3427 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3428 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3429 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3430 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | a0a0f62 | 2016-11-04 03:23:34 +0100 | [diff] [blame] | 3431 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3432 | .port_set_speed = mv88e6352_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3433 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3434 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3435 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3436 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3437 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3438 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3439 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3440 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3441 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3442 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3443 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3444 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3445 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3446 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3447 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3448 | }; |
| 3449 | |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3450 | static const struct mv88e6xxx_ops mv88e6290_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3451 | /* MV88E6XXX_FAMILY_6390 */ |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 3452 | .get_eeprom = mv88e6xxx_g2_get_eeprom8, |
| 3453 | .set_eeprom = mv88e6xxx_g2_set_eeprom8, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3454 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3455 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3456 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3457 | .port_set_link = mv88e6xxx_port_set_link, |
| 3458 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3459 | .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, |
| 3460 | .port_set_speed = mv88e6390_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3461 | .port_tag_remap = mv88e6390_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3462 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3463 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3464 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 3ce0e65 | 2016-12-03 04:45:20 +0100 | [diff] [blame] | 3465 | .port_pause_config = mv88e6390_port_pause_config, |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 3466 | .stats_snapshot = mv88e6390_g1_stats_snapshot, |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame] | 3467 | .stats_set_histogram = mv88e6390_g1_stats_set_histogram, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3468 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3469 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | e0d8b61 | 2016-11-21 23:27:04 +0100 | [diff] [blame] | 3470 | .stats_get_stats = mv88e6390_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3471 | .g1_set_cpu_port = mv88e6390_g1_set_cpu_port, |
| 3472 | .g1_set_egress_port = mv88e6390_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3473 | .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3474 | .reset = mv88e6352_g1_reset, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3475 | }; |
| 3476 | |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3477 | static const struct mv88e6xxx_ops mv88e6320_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3478 | /* MV88E6XXX_FAMILY_6320 */ |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3479 | .get_eeprom = mv88e6xxx_g2_get_eeprom16, |
| 3480 | .set_eeprom = mv88e6xxx_g2_set_eeprom16, |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3481 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3482 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3483 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3484 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3485 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3486 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3487 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3488 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3489 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3490 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3491 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3492 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3493 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3494 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3495 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3496 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3497 | .stats_get_stats = mv88e6320_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3498 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3499 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3500 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3501 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3502 | }; |
| 3503 | |
| 3504 | static const struct mv88e6xxx_ops mv88e6321_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3505 | /* MV88E6XXX_FAMILY_6321 */ |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3506 | .get_eeprom = mv88e6xxx_g2_get_eeprom16, |
| 3507 | .set_eeprom = mv88e6xxx_g2_set_eeprom16, |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3508 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3509 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3510 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3511 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3512 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3513 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3514 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3515 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3516 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3517 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3518 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3519 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3520 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3521 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3522 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3523 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3524 | .stats_get_stats = mv88e6320_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3525 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3526 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3527 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3528 | }; |
| 3529 | |
| 3530 | static const struct mv88e6xxx_ops mv88e6350_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3531 | /* MV88E6XXX_FAMILY_6351 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3532 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3533 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3534 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3535 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3536 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Andrew Lunn | 94d66ae | 2016-11-10 15:44:01 +0100 | [diff] [blame] | 3537 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3538 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3539 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3540 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3541 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3542 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3543 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3544 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3545 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3546 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3547 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3548 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3549 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3550 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3551 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3552 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3553 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3554 | }; |
| 3555 | |
| 3556 | static const struct mv88e6xxx_ops mv88e6351_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3557 | /* MV88E6XXX_FAMILY_6351 */ |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3558 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3559 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3560 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3561 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3562 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Andrew Lunn | 94d66ae | 2016-11-10 15:44:01 +0100 | [diff] [blame] | 3563 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3564 | .port_set_speed = mv88e6185_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3565 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3566 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3567 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3568 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3569 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3570 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3571 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3572 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3573 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3574 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3575 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3576 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3577 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3578 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3579 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3580 | }; |
| 3581 | |
| 3582 | static const struct mv88e6xxx_ops mv88e6352_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3583 | /* MV88E6XXX_FAMILY_6352 */ |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 3584 | .get_eeprom = mv88e6xxx_g2_get_eeprom16, |
| 3585 | .set_eeprom = mv88e6xxx_g2_set_eeprom16, |
Vivien Didelot | b073d4e | 2016-09-29 12:22:01 -0400 | [diff] [blame] | 3586 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3587 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3588 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
Vivien Didelot | 08ef7f1 | 2016-11-04 03:23:32 +0100 | [diff] [blame] | 3589 | .port_set_link = mv88e6xxx_port_set_link, |
Vivien Didelot | 7f1ae07 | 2016-11-04 03:23:33 +0100 | [diff] [blame] | 3590 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
Vivien Didelot | a0a0f62 | 2016-11-04 03:23:34 +0100 | [diff] [blame] | 3591 | .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, |
Vivien Didelot | 96a2b40 | 2016-11-04 03:23:35 +0100 | [diff] [blame] | 3592 | .port_set_speed = mv88e6352_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3593 | .port_tag_remap = mv88e6095_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3594 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3595 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3596 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3597 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3598 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | b35d322a | 2016-12-03 04:45:19 +0100 | [diff] [blame] | 3599 | .port_pause_config = mv88e6097_port_pause_config, |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 3600 | .stats_snapshot = mv88e6320_g1_stats_snapshot, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3601 | .stats_get_sset_count = mv88e6095_stats_get_sset_count, |
| 3602 | .stats_get_strings = mv88e6095_stats_get_strings, |
Andrew Lunn | 052f947 | 2016-11-21 23:27:03 +0100 | [diff] [blame] | 3603 | .stats_get_stats = mv88e6095_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3604 | .g1_set_cpu_port = mv88e6095_g1_set_cpu_port, |
| 3605 | .g1_set_egress_port = mv88e6095_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3606 | .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3607 | .reset = mv88e6352_g1_reset, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3608 | }; |
| 3609 | |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3610 | static const struct mv88e6xxx_ops mv88e6390_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3611 | /* MV88E6XXX_FAMILY_6390 */ |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 3612 | .get_eeprom = mv88e6xxx_g2_get_eeprom8, |
| 3613 | .set_eeprom = mv88e6xxx_g2_set_eeprom8, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3614 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3615 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3616 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3617 | .port_set_link = mv88e6xxx_port_set_link, |
| 3618 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3619 | .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, |
| 3620 | .port_set_speed = mv88e6390_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3621 | .port_tag_remap = mv88e6390_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3622 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3623 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3624 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3625 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3626 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | 3ce0e65 | 2016-12-03 04:45:20 +0100 | [diff] [blame] | 3627 | .port_pause_config = mv88e6390_port_pause_config, |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 3628 | .stats_snapshot = mv88e6390_g1_stats_snapshot, |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame] | 3629 | .stats_set_histogram = mv88e6390_g1_stats_set_histogram, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3630 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3631 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | e0d8b61 | 2016-11-21 23:27:04 +0100 | [diff] [blame] | 3632 | .stats_get_stats = mv88e6390_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3633 | .g1_set_cpu_port = mv88e6390_g1_set_cpu_port, |
| 3634 | .g1_set_egress_port = mv88e6390_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3635 | .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3636 | .reset = mv88e6352_g1_reset, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3637 | }; |
| 3638 | |
| 3639 | static const struct mv88e6xxx_ops mv88e6390x_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3640 | /* MV88E6XXX_FAMILY_6390 */ |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 3641 | .get_eeprom = mv88e6xxx_g2_get_eeprom8, |
| 3642 | .set_eeprom = mv88e6xxx_g2_set_eeprom8, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3643 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3644 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3645 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3646 | .port_set_link = mv88e6xxx_port_set_link, |
| 3647 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3648 | .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, |
| 3649 | .port_set_speed = mv88e6390x_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3650 | .port_tag_remap = mv88e6390_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3651 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3652 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3653 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 5f43666 | 2016-12-03 04:45:17 +0100 | [diff] [blame] | 3654 | .port_jumbo_config = mv88e6165_port_jumbo_config, |
Andrew Lunn | ef70b11 | 2016-12-03 04:45:18 +0100 | [diff] [blame] | 3655 | .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, |
Andrew Lunn | 3ce0e65 | 2016-12-03 04:45:20 +0100 | [diff] [blame] | 3656 | .port_pause_config = mv88e6390_port_pause_config, |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 3657 | .stats_snapshot = mv88e6390_g1_stats_snapshot, |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame] | 3658 | .stats_set_histogram = mv88e6390_g1_stats_set_histogram, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3659 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3660 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | e0d8b61 | 2016-11-21 23:27:04 +0100 | [diff] [blame] | 3661 | .stats_get_stats = mv88e6390_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3662 | .g1_set_cpu_port = mv88e6390_g1_set_cpu_port, |
| 3663 | .g1_set_egress_port = mv88e6390_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3664 | .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3665 | .reset = mv88e6352_g1_reset, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3666 | }; |
| 3667 | |
| 3668 | static const struct mv88e6xxx_ops mv88e6391_ops = { |
Andrew Lunn | 4b325d8 | 2016-11-21 23:26:59 +0100 | [diff] [blame] | 3669 | /* MV88E6XXX_FAMILY_6390 */ |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 3670 | .get_eeprom = mv88e6xxx_g2_get_eeprom8, |
| 3671 | .set_eeprom = mv88e6xxx_g2_set_eeprom8, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3672 | .set_switch_mac = mv88e6xxx_g2_set_switch_mac, |
| 3673 | .phy_read = mv88e6xxx_g2_smi_phy_read, |
| 3674 | .phy_write = mv88e6xxx_g2_smi_phy_write, |
| 3675 | .port_set_link = mv88e6xxx_port_set_link, |
| 3676 | .port_set_duplex = mv88e6xxx_port_set_duplex, |
| 3677 | .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, |
| 3678 | .port_set_speed = mv88e6390_port_set_speed, |
Andrew Lunn | ef0a731 | 2016-12-03 04:35:16 +0100 | [diff] [blame] | 3679 | .port_tag_remap = mv88e6390_port_tag_remap, |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3680 | .port_set_frame_mode = mv88e6351_port_set_frame_mode, |
| 3681 | .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns, |
| 3682 | .port_set_ether_type = mv88e6351_port_set_ether_type, |
Andrew Lunn | 3ce0e65 | 2016-12-03 04:45:20 +0100 | [diff] [blame] | 3683 | .port_pause_config = mv88e6390_port_pause_config, |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 3684 | .stats_snapshot = mv88e6390_g1_stats_snapshot, |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame] | 3685 | .stats_set_histogram = mv88e6390_g1_stats_set_histogram, |
Andrew Lunn | dfafe44 | 2016-11-21 23:27:02 +0100 | [diff] [blame] | 3686 | .stats_get_sset_count = mv88e6320_stats_get_sset_count, |
| 3687 | .stats_get_strings = mv88e6320_stats_get_strings, |
Andrew Lunn | e0d8b61 | 2016-11-21 23:27:04 +0100 | [diff] [blame] | 3688 | .stats_get_stats = mv88e6390_stats_get_stats, |
Andrew Lunn | 3364199 | 2016-12-03 04:35:17 +0100 | [diff] [blame] | 3689 | .g1_set_cpu_port = mv88e6390_g1_set_cpu_port, |
| 3690 | .g1_set_egress_port = mv88e6390_g1_set_egress_port, |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 3691 | .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, |
Vivien Didelot | 17e708b | 2016-12-05 17:30:27 -0500 | [diff] [blame] | 3692 | .reset = mv88e6352_g1_reset, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3693 | }; |
| 3694 | |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 3695 | static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip, |
| 3696 | const struct mv88e6xxx_ops *ops) |
| 3697 | { |
| 3698 | if (!ops->port_set_frame_mode) { |
| 3699 | dev_err(chip->dev, "Missing port_set_frame_mode"); |
| 3700 | return -EINVAL; |
| 3701 | } |
| 3702 | |
| 3703 | if (!ops->port_set_egress_unknowns) { |
| 3704 | dev_err(chip->dev, "Missing port_set_egress_mode"); |
| 3705 | return -EINVAL; |
| 3706 | } |
| 3707 | |
| 3708 | return 0; |
| 3709 | } |
| 3710 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3711 | static const struct mv88e6xxx_info mv88e6xxx_table[] = { |
| 3712 | [MV88E6085] = { |
| 3713 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6085, |
| 3714 | .family = MV88E6XXX_FAMILY_6097, |
| 3715 | .name = "Marvell 88E6085", |
| 3716 | .num_databases = 4096, |
| 3717 | .num_ports = 10, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3718 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3719 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3720 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3721 | .g1_irqs = 8, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3722 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3723 | .flags = MV88E6XXX_FLAGS_FAMILY_6097, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3724 | .ops = &mv88e6085_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3725 | }, |
| 3726 | |
| 3727 | [MV88E6095] = { |
| 3728 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6095, |
| 3729 | .family = MV88E6XXX_FAMILY_6095, |
| 3730 | .name = "Marvell 88E6095/88E6095F", |
| 3731 | .num_databases = 256, |
| 3732 | .num_ports = 11, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3733 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3734 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3735 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3736 | .g1_irqs = 8, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3737 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3738 | .flags = MV88E6XXX_FLAGS_FAMILY_6095, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3739 | .ops = &mv88e6095_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3740 | }, |
| 3741 | |
Stefan Eichenberger | 7d381a0 | 2016-11-22 17:47:21 +0100 | [diff] [blame] | 3742 | [MV88E6097] = { |
| 3743 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6097, |
| 3744 | .family = MV88E6XXX_FAMILY_6097, |
| 3745 | .name = "Marvell 88E6097/88E6097F", |
| 3746 | .num_databases = 4096, |
| 3747 | .num_ports = 11, |
| 3748 | .port_base_addr = 0x10, |
| 3749 | .global1_addr = 0x1b, |
| 3750 | .age_time_coeff = 15000, |
Stefan Eichenberger | c534178 | 2016-11-25 09:41:29 +0100 | [diff] [blame] | 3751 | .g1_irqs = 8, |
Stefan Eichenberger | 2bfcfcd | 2016-12-05 14:12:42 +0100 | [diff] [blame] | 3752 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Stefan Eichenberger | 7d381a0 | 2016-11-22 17:47:21 +0100 | [diff] [blame] | 3753 | .flags = MV88E6XXX_FLAGS_FAMILY_6097, |
| 3754 | .ops = &mv88e6097_ops, |
| 3755 | }, |
| 3756 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3757 | [MV88E6123] = { |
| 3758 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6123, |
| 3759 | .family = MV88E6XXX_FAMILY_6165, |
| 3760 | .name = "Marvell 88E6123", |
| 3761 | .num_databases = 4096, |
| 3762 | .num_ports = 3, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3763 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3764 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3765 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3766 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3767 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3768 | .flags = MV88E6XXX_FLAGS_FAMILY_6165, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3769 | .ops = &mv88e6123_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3770 | }, |
| 3771 | |
| 3772 | [MV88E6131] = { |
| 3773 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6131, |
| 3774 | .family = MV88E6XXX_FAMILY_6185, |
| 3775 | .name = "Marvell 88E6131", |
| 3776 | .num_databases = 256, |
| 3777 | .num_ports = 8, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3778 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3779 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3780 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3781 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3782 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3783 | .flags = MV88E6XXX_FLAGS_FAMILY_6185, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3784 | .ops = &mv88e6131_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3785 | }, |
| 3786 | |
| 3787 | [MV88E6161] = { |
| 3788 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6161, |
| 3789 | .family = MV88E6XXX_FAMILY_6165, |
| 3790 | .name = "Marvell 88E6161", |
| 3791 | .num_databases = 4096, |
| 3792 | .num_ports = 6, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3793 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3794 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3795 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3796 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3797 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3798 | .flags = MV88E6XXX_FLAGS_FAMILY_6165, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3799 | .ops = &mv88e6161_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3800 | }, |
| 3801 | |
| 3802 | [MV88E6165] = { |
| 3803 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6165, |
| 3804 | .family = MV88E6XXX_FAMILY_6165, |
| 3805 | .name = "Marvell 88E6165", |
| 3806 | .num_databases = 4096, |
| 3807 | .num_ports = 6, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3808 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3809 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3810 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3811 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3812 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3813 | .flags = MV88E6XXX_FLAGS_FAMILY_6165, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3814 | .ops = &mv88e6165_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3815 | }, |
| 3816 | |
| 3817 | [MV88E6171] = { |
| 3818 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6171, |
| 3819 | .family = MV88E6XXX_FAMILY_6351, |
| 3820 | .name = "Marvell 88E6171", |
| 3821 | .num_databases = 4096, |
| 3822 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3823 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3824 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3825 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3826 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3827 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3828 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3829 | .ops = &mv88e6171_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3830 | }, |
| 3831 | |
| 3832 | [MV88E6172] = { |
| 3833 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6172, |
| 3834 | .family = MV88E6XXX_FAMILY_6352, |
| 3835 | .name = "Marvell 88E6172", |
| 3836 | .num_databases = 4096, |
| 3837 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3838 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3839 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3840 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3841 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3842 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3843 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3844 | .ops = &mv88e6172_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3845 | }, |
| 3846 | |
| 3847 | [MV88E6175] = { |
| 3848 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6175, |
| 3849 | .family = MV88E6XXX_FAMILY_6351, |
| 3850 | .name = "Marvell 88E6175", |
| 3851 | .num_databases = 4096, |
| 3852 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3853 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3854 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3855 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3856 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3857 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3858 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3859 | .ops = &mv88e6175_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3860 | }, |
| 3861 | |
| 3862 | [MV88E6176] = { |
| 3863 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6176, |
| 3864 | .family = MV88E6XXX_FAMILY_6352, |
| 3865 | .name = "Marvell 88E6176", |
| 3866 | .num_databases = 4096, |
| 3867 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3868 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3869 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3870 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3871 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3872 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3873 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3874 | .ops = &mv88e6176_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3875 | }, |
| 3876 | |
| 3877 | [MV88E6185] = { |
| 3878 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6185, |
| 3879 | .family = MV88E6XXX_FAMILY_6185, |
| 3880 | .name = "Marvell 88E6185", |
| 3881 | .num_databases = 256, |
| 3882 | .num_ports = 10, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3883 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3884 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3885 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3886 | .g1_irqs = 8, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3887 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3888 | .flags = MV88E6XXX_FLAGS_FAMILY_6185, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3889 | .ops = &mv88e6185_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3890 | }, |
| 3891 | |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3892 | [MV88E6190] = { |
| 3893 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6190, |
| 3894 | .family = MV88E6XXX_FAMILY_6390, |
| 3895 | .name = "Marvell 88E6190", |
| 3896 | .num_databases = 4096, |
| 3897 | .num_ports = 11, /* 10 + Z80 */ |
| 3898 | .port_base_addr = 0x0, |
| 3899 | .global1_addr = 0x1b, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3900 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3901 | .age_time_coeff = 15000, |
| 3902 | .g1_irqs = 9, |
| 3903 | .flags = MV88E6XXX_FLAGS_FAMILY_6390, |
| 3904 | .ops = &mv88e6190_ops, |
| 3905 | }, |
| 3906 | |
| 3907 | [MV88E6190X] = { |
| 3908 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X, |
| 3909 | .family = MV88E6XXX_FAMILY_6390, |
| 3910 | .name = "Marvell 88E6190X", |
| 3911 | .num_databases = 4096, |
| 3912 | .num_ports = 11, /* 10 + Z80 */ |
| 3913 | .port_base_addr = 0x0, |
| 3914 | .global1_addr = 0x1b, |
| 3915 | .age_time_coeff = 15000, |
| 3916 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3917 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3918 | .flags = MV88E6XXX_FLAGS_FAMILY_6390, |
| 3919 | .ops = &mv88e6190x_ops, |
| 3920 | }, |
| 3921 | |
| 3922 | [MV88E6191] = { |
| 3923 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6191, |
| 3924 | .family = MV88E6XXX_FAMILY_6390, |
| 3925 | .name = "Marvell 88E6191", |
| 3926 | .num_databases = 4096, |
| 3927 | .num_ports = 11, /* 10 + Z80 */ |
| 3928 | .port_base_addr = 0x0, |
| 3929 | .global1_addr = 0x1b, |
| 3930 | .age_time_coeff = 15000, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3931 | .g1_irqs = 9, |
| 3932 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3933 | .flags = MV88E6XXX_FLAGS_FAMILY_6390, |
| 3934 | .ops = &mv88e6391_ops, |
| 3935 | }, |
| 3936 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3937 | [MV88E6240] = { |
| 3938 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6240, |
| 3939 | .family = MV88E6XXX_FAMILY_6352, |
| 3940 | .name = "Marvell 88E6240", |
| 3941 | .num_databases = 4096, |
| 3942 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3943 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3944 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3945 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3946 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3947 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3948 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3949 | .ops = &mv88e6240_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3950 | }, |
| 3951 | |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3952 | [MV88E6290] = { |
| 3953 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6290, |
| 3954 | .family = MV88E6XXX_FAMILY_6390, |
| 3955 | .name = "Marvell 88E6290", |
| 3956 | .num_databases = 4096, |
| 3957 | .num_ports = 11, /* 10 + Z80 */ |
| 3958 | .port_base_addr = 0x0, |
| 3959 | .global1_addr = 0x1b, |
| 3960 | .age_time_coeff = 15000, |
| 3961 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3962 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 3963 | .flags = MV88E6XXX_FLAGS_FAMILY_6390, |
| 3964 | .ops = &mv88e6290_ops, |
| 3965 | }, |
| 3966 | |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3967 | [MV88E6320] = { |
| 3968 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6320, |
| 3969 | .family = MV88E6XXX_FAMILY_6320, |
| 3970 | .name = "Marvell 88E6320", |
| 3971 | .num_databases = 4096, |
| 3972 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3973 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3974 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3975 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3976 | .g1_irqs = 8, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3977 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3978 | .flags = MV88E6XXX_FLAGS_FAMILY_6320, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3979 | .ops = &mv88e6320_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3980 | }, |
| 3981 | |
| 3982 | [MV88E6321] = { |
| 3983 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6321, |
| 3984 | .family = MV88E6XXX_FAMILY_6320, |
| 3985 | .name = "Marvell 88E6321", |
| 3986 | .num_databases = 4096, |
| 3987 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 3988 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 3989 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 3990 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 3991 | .g1_irqs = 8, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 3992 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3993 | .flags = MV88E6XXX_FLAGS_FAMILY_6320, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 3994 | .ops = &mv88e6321_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 3995 | }, |
| 3996 | |
| 3997 | [MV88E6350] = { |
| 3998 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6350, |
| 3999 | .family = MV88E6XXX_FAMILY_6351, |
| 4000 | .name = "Marvell 88E6350", |
| 4001 | .num_databases = 4096, |
| 4002 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 4003 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 4004 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 4005 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4006 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 4007 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4008 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 4009 | .ops = &mv88e6350_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4010 | }, |
| 4011 | |
| 4012 | [MV88E6351] = { |
| 4013 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6351, |
| 4014 | .family = MV88E6XXX_FAMILY_6351, |
| 4015 | .name = "Marvell 88E6351", |
| 4016 | .num_databases = 4096, |
| 4017 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 4018 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 4019 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 4020 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4021 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 4022 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4023 | .flags = MV88E6XXX_FLAGS_FAMILY_6351, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 4024 | .ops = &mv88e6351_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4025 | }, |
| 4026 | |
| 4027 | [MV88E6352] = { |
| 4028 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6352, |
| 4029 | .family = MV88E6XXX_FAMILY_6352, |
| 4030 | .name = "Marvell 88E6352", |
| 4031 | .num_databases = 4096, |
| 4032 | .num_ports = 7, |
Vivien Didelot | 9dddd47 | 2016-06-20 13:14:10 -0400 | [diff] [blame] | 4033 | .port_base_addr = 0x10, |
Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 4034 | .global1_addr = 0x1b, |
Vivien Didelot | acddbd2 | 2016-07-18 20:45:39 -0400 | [diff] [blame] | 4035 | .age_time_coeff = 15000, |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4036 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 4037 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4038 | .flags = MV88E6XXX_FLAGS_FAMILY_6352, |
Vivien Didelot | b3469dd | 2016-09-29 12:22:00 -0400 | [diff] [blame] | 4039 | .ops = &mv88e6352_ops, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4040 | }, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 4041 | [MV88E6390] = { |
| 4042 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6390, |
| 4043 | .family = MV88E6XXX_FAMILY_6390, |
| 4044 | .name = "Marvell 88E6390", |
| 4045 | .num_databases = 4096, |
| 4046 | .num_ports = 11, /* 10 + Z80 */ |
| 4047 | .port_base_addr = 0x0, |
| 4048 | .global1_addr = 0x1b, |
| 4049 | .age_time_coeff = 15000, |
| 4050 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 4051 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 4052 | .flags = MV88E6XXX_FLAGS_FAMILY_6390, |
| 4053 | .ops = &mv88e6390_ops, |
| 4054 | }, |
| 4055 | [MV88E6390X] = { |
| 4056 | .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X, |
| 4057 | .family = MV88E6XXX_FAMILY_6390, |
| 4058 | .name = "Marvell 88E6390X", |
| 4059 | .num_databases = 4096, |
| 4060 | .num_ports = 11, /* 10 + Z80 */ |
| 4061 | .port_base_addr = 0x0, |
| 4062 | .global1_addr = 0x1b, |
| 4063 | .age_time_coeff = 15000, |
| 4064 | .g1_irqs = 9, |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 4065 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 4066 | .flags = MV88E6XXX_FLAGS_FAMILY_6390, |
| 4067 | .ops = &mv88e6390x_ops, |
| 4068 | }, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4069 | }; |
| 4070 | |
Vivien Didelot | 5f7c036 | 2016-06-20 13:14:04 -0400 | [diff] [blame] | 4071 | static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num) |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 4072 | { |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 4073 | int i; |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 4074 | |
Vivien Didelot | 5f7c036 | 2016-06-20 13:14:04 -0400 | [diff] [blame] | 4075 | for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i) |
| 4076 | if (mv88e6xxx_table[i].prod_num == prod_num) |
| 4077 | return &mv88e6xxx_table[i]; |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 4078 | |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 4079 | return NULL; |
| 4080 | } |
| 4081 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4082 | static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip) |
Vivien Didelot | bc46a3d | 2016-06-20 13:14:08 -0400 | [diff] [blame] | 4083 | { |
| 4084 | const struct mv88e6xxx_info *info; |
Vivien Didelot | 8f6345b | 2016-07-20 18:18:36 -0400 | [diff] [blame] | 4085 | unsigned int prod_num, rev; |
| 4086 | u16 id; |
| 4087 | int err; |
Vivien Didelot | bc46a3d | 2016-06-20 13:14:08 -0400 | [diff] [blame] | 4088 | |
Vivien Didelot | 8f6345b | 2016-07-20 18:18:36 -0400 | [diff] [blame] | 4089 | mutex_lock(&chip->reg_lock); |
| 4090 | err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id); |
| 4091 | mutex_unlock(&chip->reg_lock); |
| 4092 | if (err) |
| 4093 | return err; |
Vivien Didelot | bc46a3d | 2016-06-20 13:14:08 -0400 | [diff] [blame] | 4094 | |
| 4095 | prod_num = (id & 0xfff0) >> 4; |
| 4096 | rev = id & 0x000f; |
| 4097 | |
| 4098 | info = mv88e6xxx_lookup_info(prod_num); |
| 4099 | if (!info) |
| 4100 | return -ENODEV; |
| 4101 | |
Vivien Didelot | caac854 | 2016-06-20 13:14:09 -0400 | [diff] [blame] | 4102 | /* Update the compatible info with the probed one */ |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4103 | chip->info = info; |
Vivien Didelot | bc46a3d | 2016-06-20 13:14:08 -0400 | [diff] [blame] | 4104 | |
Vivien Didelot | ca070c1 | 2016-09-02 14:45:34 -0400 | [diff] [blame] | 4105 | err = mv88e6xxx_g2_require(chip); |
| 4106 | if (err) |
| 4107 | return err; |
| 4108 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4109 | dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n", |
| 4110 | chip->info->prod_num, chip->info->name, rev); |
Vivien Didelot | bc46a3d | 2016-06-20 13:14:08 -0400 | [diff] [blame] | 4111 | |
| 4112 | return 0; |
| 4113 | } |
| 4114 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4115 | static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev) |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4116 | { |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4117 | struct mv88e6xxx_chip *chip; |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4118 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4119 | chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); |
| 4120 | if (!chip) |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4121 | return NULL; |
| 4122 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4123 | chip->dev = dev; |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4124 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4125 | mutex_init(&chip->reg_lock); |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4126 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4127 | return chip; |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4128 | } |
| 4129 | |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 4130 | static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip) |
| 4131 | { |
Vivien Didelot | a199d8b | 2016-12-05 17:30:28 -0500 | [diff] [blame] | 4132 | if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable) |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 4133 | mv88e6xxx_ppu_state_init(chip); |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 4134 | } |
| 4135 | |
Andrew Lunn | 930188c | 2016-08-22 16:01:03 +0200 | [diff] [blame] | 4136 | static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip) |
| 4137 | { |
Vivien Didelot | a199d8b | 2016-12-05 17:30:28 -0500 | [diff] [blame] | 4138 | if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable) |
Andrew Lunn | 930188c | 2016-08-22 16:01:03 +0200 | [diff] [blame] | 4139 | mv88e6xxx_ppu_state_destroy(chip); |
Andrew Lunn | 930188c | 2016-08-22 16:01:03 +0200 | [diff] [blame] | 4140 | } |
| 4141 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4142 | static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip, |
Vivien Didelot | 4a70c4a | 2016-06-20 13:14:07 -0400 | [diff] [blame] | 4143 | struct mii_bus *bus, int sw_addr) |
| 4144 | { |
Vivien Didelot | 914b32f | 2016-06-20 13:14:11 -0400 | [diff] [blame] | 4145 | if (sw_addr == 0) |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4146 | chip->smi_ops = &mv88e6xxx_smi_single_chip_ops; |
Vivien Didelot | a0ffff2 | 2016-08-15 17:18:58 -0400 | [diff] [blame] | 4147 | else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP)) |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4148 | chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops; |
Vivien Didelot | 914b32f | 2016-06-20 13:14:11 -0400 | [diff] [blame] | 4149 | else |
| 4150 | return -EINVAL; |
| 4151 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4152 | chip->bus = bus; |
| 4153 | chip->sw_addr = sw_addr; |
Vivien Didelot | 4a70c4a | 2016-06-20 13:14:07 -0400 | [diff] [blame] | 4154 | |
| 4155 | return 0; |
| 4156 | } |
| 4157 | |
Andrew Lunn | 7b31436 | 2016-08-22 16:01:01 +0200 | [diff] [blame] | 4158 | static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds) |
| 4159 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 4160 | struct mv88e6xxx_chip *chip = ds->priv; |
Andrew Lunn | 2bbb33b | 2016-08-22 16:01:02 +0200 | [diff] [blame] | 4161 | |
Andrew Lunn | 443d5a1 | 2016-12-03 04:35:18 +0100 | [diff] [blame] | 4162 | return chip->info->tag_protocol; |
Andrew Lunn | 7b31436 | 2016-08-22 16:01:01 +0200 | [diff] [blame] | 4163 | } |
| 4164 | |
Andrew Lunn | fcdce7d | 2016-05-10 23:27:20 +0200 | [diff] [blame] | 4165 | static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, |
| 4166 | struct device *host_dev, int sw_addr, |
| 4167 | void **priv) |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 4168 | { |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4169 | struct mv88e6xxx_chip *chip; |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 4170 | struct mii_bus *bus; |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 4171 | int err; |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 4172 | |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 4173 | bus = dsa_host_dev_to_mii_bus(host_dev); |
Andrew Lunn | c156913 | 2016-04-13 02:40:45 +0200 | [diff] [blame] | 4174 | if (!bus) |
| 4175 | return NULL; |
| 4176 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4177 | chip = mv88e6xxx_alloc_chip(dsa_dev); |
| 4178 | if (!chip) |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4179 | return NULL; |
| 4180 | |
Vivien Didelot | caac854 | 2016-06-20 13:14:09 -0400 | [diff] [blame] | 4181 | /* Legacy SMI probing will only support chips similar to 88E6085 */ |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4182 | chip->info = &mv88e6xxx_table[MV88E6085]; |
Vivien Didelot | caac854 | 2016-06-20 13:14:09 -0400 | [diff] [blame] | 4183 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4184 | err = mv88e6xxx_smi_init(chip, bus, sw_addr); |
Vivien Didelot | 4a70c4a | 2016-06-20 13:14:07 -0400 | [diff] [blame] | 4185 | if (err) |
| 4186 | goto free; |
| 4187 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4188 | err = mv88e6xxx_detect(chip); |
Vivien Didelot | bc46a3d | 2016-06-20 13:14:08 -0400 | [diff] [blame] | 4189 | if (err) |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4190 | goto free; |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 4191 | |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4192 | mutex_lock(&chip->reg_lock); |
| 4193 | err = mv88e6xxx_switch_reset(chip); |
| 4194 | mutex_unlock(&chip->reg_lock); |
| 4195 | if (err) |
| 4196 | goto free; |
| 4197 | |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 4198 | mv88e6xxx_phy_init(chip); |
| 4199 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4200 | err = mv88e6xxx_mdio_register(chip, NULL); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 4201 | if (err) |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4202 | goto free; |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 4203 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4204 | *priv = chip; |
Vivien Didelot | a439c06 | 2016-04-17 13:23:58 -0400 | [diff] [blame] | 4205 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4206 | return chip->info->name; |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4207 | free: |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4208 | devm_kfree(dsa_dev, chip); |
Vivien Didelot | 469d729 | 2016-06-20 13:14:06 -0400 | [diff] [blame] | 4209 | |
| 4210 | return NULL; |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 4211 | } |
| 4212 | |
Vivien Didelot | 7df8fbd | 2016-08-31 11:50:05 -0400 | [diff] [blame] | 4213 | static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port, |
| 4214 | const struct switchdev_obj_port_mdb *mdb, |
| 4215 | struct switchdev_trans *trans) |
| 4216 | { |
| 4217 | /* We don't need any dynamic resource from the kernel (yet), |
| 4218 | * so skip the prepare phase. |
| 4219 | */ |
| 4220 | |
| 4221 | return 0; |
| 4222 | } |
| 4223 | |
| 4224 | static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port, |
| 4225 | const struct switchdev_obj_port_mdb *mdb, |
| 4226 | struct switchdev_trans *trans) |
| 4227 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 4228 | struct mv88e6xxx_chip *chip = ds->priv; |
Vivien Didelot | 7df8fbd | 2016-08-31 11:50:05 -0400 | [diff] [blame] | 4229 | |
| 4230 | mutex_lock(&chip->reg_lock); |
| 4231 | if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, |
| 4232 | GLOBAL_ATU_DATA_STATE_MC_STATIC)) |
| 4233 | netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n"); |
| 4234 | mutex_unlock(&chip->reg_lock); |
| 4235 | } |
| 4236 | |
| 4237 | static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port, |
| 4238 | const struct switchdev_obj_port_mdb *mdb) |
| 4239 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 4240 | struct mv88e6xxx_chip *chip = ds->priv; |
Vivien Didelot | 7df8fbd | 2016-08-31 11:50:05 -0400 | [diff] [blame] | 4241 | int err; |
| 4242 | |
| 4243 | mutex_lock(&chip->reg_lock); |
| 4244 | err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, |
| 4245 | GLOBAL_ATU_DATA_STATE_UNUSED); |
| 4246 | mutex_unlock(&chip->reg_lock); |
| 4247 | |
| 4248 | return err; |
| 4249 | } |
| 4250 | |
| 4251 | static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port, |
| 4252 | struct switchdev_obj_port_mdb *mdb, |
| 4253 | int (*cb)(struct switchdev_obj *obj)) |
| 4254 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 4255 | struct mv88e6xxx_chip *chip = ds->priv; |
Vivien Didelot | 7df8fbd | 2016-08-31 11:50:05 -0400 | [diff] [blame] | 4256 | int err; |
| 4257 | |
| 4258 | mutex_lock(&chip->reg_lock); |
| 4259 | err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb); |
| 4260 | mutex_unlock(&chip->reg_lock); |
| 4261 | |
| 4262 | return err; |
| 4263 | } |
| 4264 | |
Florian Fainelli | a82f67a | 2017-01-08 14:52:08 -0800 | [diff] [blame] | 4265 | static const struct dsa_switch_ops mv88e6xxx_switch_ops = { |
Andrew Lunn | fcdce7d | 2016-05-10 23:27:20 +0200 | [diff] [blame] | 4266 | .probe = mv88e6xxx_drv_probe, |
Andrew Lunn | 7b31436 | 2016-08-22 16:01:01 +0200 | [diff] [blame] | 4267 | .get_tag_protocol = mv88e6xxx_get_tag_protocol, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4268 | .setup = mv88e6xxx_setup, |
| 4269 | .set_addr = mv88e6xxx_set_addr, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4270 | .adjust_link = mv88e6xxx_adjust_link, |
| 4271 | .get_strings = mv88e6xxx_get_strings, |
| 4272 | .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, |
| 4273 | .get_sset_count = mv88e6xxx_get_sset_count, |
| 4274 | .set_eee = mv88e6xxx_set_eee, |
| 4275 | .get_eee = mv88e6xxx_get_eee, |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 4276 | .get_eeprom_len = mv88e6xxx_get_eeprom_len, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4277 | .get_eeprom = mv88e6xxx_get_eeprom, |
| 4278 | .set_eeprom = mv88e6xxx_set_eeprom, |
| 4279 | .get_regs_len = mv88e6xxx_get_regs_len, |
| 4280 | .get_regs = mv88e6xxx_get_regs, |
Vivien Didelot | 2cfcd96 | 2016-07-18 20:45:40 -0400 | [diff] [blame] | 4281 | .set_ageing_time = mv88e6xxx_set_ageing_time, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4282 | .port_bridge_join = mv88e6xxx_port_bridge_join, |
| 4283 | .port_bridge_leave = mv88e6xxx_port_bridge_leave, |
| 4284 | .port_stp_state_set = mv88e6xxx_port_stp_state_set, |
Vivien Didelot | 749efcb | 2016-09-22 16:49:24 -0400 | [diff] [blame] | 4285 | .port_fast_age = mv88e6xxx_port_fast_age, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4286 | .port_vlan_filtering = mv88e6xxx_port_vlan_filtering, |
| 4287 | .port_vlan_prepare = mv88e6xxx_port_vlan_prepare, |
| 4288 | .port_vlan_add = mv88e6xxx_port_vlan_add, |
| 4289 | .port_vlan_del = mv88e6xxx_port_vlan_del, |
| 4290 | .port_vlan_dump = mv88e6xxx_port_vlan_dump, |
| 4291 | .port_fdb_prepare = mv88e6xxx_port_fdb_prepare, |
| 4292 | .port_fdb_add = mv88e6xxx_port_fdb_add, |
| 4293 | .port_fdb_del = mv88e6xxx_port_fdb_del, |
| 4294 | .port_fdb_dump = mv88e6xxx_port_fdb_dump, |
Vivien Didelot | 7df8fbd | 2016-08-31 11:50:05 -0400 | [diff] [blame] | 4295 | .port_mdb_prepare = mv88e6xxx_port_mdb_prepare, |
| 4296 | .port_mdb_add = mv88e6xxx_port_mdb_add, |
| 4297 | .port_mdb_del = mv88e6xxx_port_mdb_del, |
| 4298 | .port_mdb_dump = mv88e6xxx_port_mdb_dump, |
Vivien Didelot | f81ec90 | 2016-05-09 13:22:58 -0400 | [diff] [blame] | 4299 | }; |
| 4300 | |
Florian Fainelli | ab3d408 | 2017-01-08 14:52:07 -0800 | [diff] [blame] | 4301 | static struct dsa_switch_driver mv88e6xxx_switch_drv = { |
| 4302 | .ops = &mv88e6xxx_switch_ops, |
| 4303 | }; |
| 4304 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4305 | static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip, |
Vivien Didelot | b7e66a5 | 2016-06-20 13:14:02 -0400 | [diff] [blame] | 4306 | struct device_node *np) |
| 4307 | { |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4308 | struct device *dev = chip->dev; |
Vivien Didelot | b7e66a5 | 2016-06-20 13:14:02 -0400 | [diff] [blame] | 4309 | struct dsa_switch *ds; |
| 4310 | |
| 4311 | ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); |
| 4312 | if (!ds) |
| 4313 | return -ENOMEM; |
| 4314 | |
| 4315 | ds->dev = dev; |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4316 | ds->priv = chip; |
Vivien Didelot | 9d490b4 | 2016-08-23 12:38:56 -0400 | [diff] [blame] | 4317 | ds->ops = &mv88e6xxx_switch_ops; |
Vivien Didelot | b7e66a5 | 2016-06-20 13:14:02 -0400 | [diff] [blame] | 4318 | |
| 4319 | dev_set_drvdata(dev, ds); |
| 4320 | |
| 4321 | return dsa_register_switch(ds, np); |
| 4322 | } |
| 4323 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4324 | static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip) |
Vivien Didelot | b7e66a5 | 2016-06-20 13:14:02 -0400 | [diff] [blame] | 4325 | { |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4326 | dsa_unregister_switch(chip->ds); |
Vivien Didelot | b7e66a5 | 2016-06-20 13:14:02 -0400 | [diff] [blame] | 4327 | } |
| 4328 | |
Vivien Didelot | 57d3231 | 2016-06-20 13:13:58 -0400 | [diff] [blame] | 4329 | static int mv88e6xxx_probe(struct mdio_device *mdiodev) |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4330 | { |
| 4331 | struct device *dev = &mdiodev->dev; |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 4332 | struct device_node *np = dev->of_node; |
Vivien Didelot | caac854 | 2016-06-20 13:14:09 -0400 | [diff] [blame] | 4333 | const struct mv88e6xxx_info *compat_info; |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4334 | struct mv88e6xxx_chip *chip; |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 4335 | u32 eeprom_len; |
Andrew Lunn | 52638f7 | 2016-05-10 23:27:22 +0200 | [diff] [blame] | 4336 | int err; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4337 | |
Vivien Didelot | caac854 | 2016-06-20 13:14:09 -0400 | [diff] [blame] | 4338 | compat_info = of_device_get_match_data(dev); |
| 4339 | if (!compat_info) |
| 4340 | return -EINVAL; |
| 4341 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4342 | chip = mv88e6xxx_alloc_chip(dev); |
| 4343 | if (!chip) |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4344 | return -ENOMEM; |
| 4345 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4346 | chip->info = compat_info; |
Vivien Didelot | caac854 | 2016-06-20 13:14:09 -0400 | [diff] [blame] | 4347 | |
Andrew Lunn | 56995cb | 2016-12-03 04:35:19 +0100 | [diff] [blame] | 4348 | err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops); |
| 4349 | if (err) |
| 4350 | return err; |
| 4351 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4352 | err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr); |
Vivien Didelot | 4a70c4a | 2016-06-20 13:14:07 -0400 | [diff] [blame] | 4353 | if (err) |
| 4354 | return err; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4355 | |
Andrew Lunn | b4308f0 | 2016-11-21 23:26:55 +0100 | [diff] [blame] | 4356 | chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); |
| 4357 | if (IS_ERR(chip->reset)) |
| 4358 | return PTR_ERR(chip->reset); |
| 4359 | |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4360 | err = mv88e6xxx_detect(chip); |
Vivien Didelot | bc46a3d | 2016-06-20 13:14:08 -0400 | [diff] [blame] | 4361 | if (err) |
| 4362 | return err; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4363 | |
Vivien Didelot | e57e5e7 | 2016-08-15 17:19:00 -0400 | [diff] [blame] | 4364 | mv88e6xxx_phy_init(chip); |
| 4365 | |
Vivien Didelot | ee4dc2e7 | 2016-09-29 12:22:02 -0400 | [diff] [blame] | 4366 | if (chip->info->ops->get_eeprom && |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 4367 | !of_property_read_u32(np, "eeprom-length", &eeprom_len)) |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4368 | chip->eeprom_len = eeprom_len; |
Andrew Lunn | f8cd875 | 2016-05-10 23:27:25 +0200 | [diff] [blame] | 4369 | |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4370 | mutex_lock(&chip->reg_lock); |
| 4371 | err = mv88e6xxx_switch_reset(chip); |
| 4372 | mutex_unlock(&chip->reg_lock); |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 4373 | if (err) |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4374 | goto out; |
Andrew Lunn | b516d45 | 2016-06-04 21:17:06 +0200 | [diff] [blame] | 4375 | |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4376 | chip->irq = of_irq_get(np, 0); |
| 4377 | if (chip->irq == -EPROBE_DEFER) { |
| 4378 | err = chip->irq; |
| 4379 | goto out; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 4380 | } |
| 4381 | |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4382 | if (chip->irq > 0) { |
| 4383 | /* Has to be performed before the MDIO bus is created, |
| 4384 | * because the PHYs will link there interrupts to these |
| 4385 | * interrupt controllers |
| 4386 | */ |
| 4387 | mutex_lock(&chip->reg_lock); |
| 4388 | err = mv88e6xxx_g1_irq_setup(chip); |
| 4389 | mutex_unlock(&chip->reg_lock); |
| 4390 | |
| 4391 | if (err) |
| 4392 | goto out; |
| 4393 | |
| 4394 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) { |
| 4395 | err = mv88e6xxx_g2_irq_setup(chip); |
| 4396 | if (err) |
| 4397 | goto out_g1_irq; |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | err = mv88e6xxx_mdio_register(chip, np); |
| 4402 | if (err) |
| 4403 | goto out_g2_irq; |
| 4404 | |
| 4405 | err = mv88e6xxx_register_switch(chip, np); |
| 4406 | if (err) |
| 4407 | goto out_mdio; |
| 4408 | |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4409 | return 0; |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4410 | |
| 4411 | out_mdio: |
| 4412 | mv88e6xxx_mdio_unregister(chip); |
| 4413 | out_g2_irq: |
Andrew Lunn | 46712644 | 2016-11-20 20:14:15 +0100 | [diff] [blame] | 4414 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0) |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4415 | mv88e6xxx_g2_irq_free(chip); |
| 4416 | out_g1_irq: |
Andrew Lunn | 61f7c3f | 2016-11-20 20:14:19 +0100 | [diff] [blame] | 4417 | if (chip->irq > 0) { |
| 4418 | mutex_lock(&chip->reg_lock); |
Andrew Lunn | 46712644 | 2016-11-20 20:14:15 +0100 | [diff] [blame] | 4419 | mv88e6xxx_g1_irq_free(chip); |
Andrew Lunn | 61f7c3f | 2016-11-20 20:14:19 +0100 | [diff] [blame] | 4420 | mutex_unlock(&chip->reg_lock); |
| 4421 | } |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4422 | out: |
| 4423 | return err; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | static void mv88e6xxx_remove(struct mdio_device *mdiodev) |
| 4427 | { |
| 4428 | struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 4429 | struct mv88e6xxx_chip *chip = ds->priv; |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4430 | |
Andrew Lunn | 930188c | 2016-08-22 16:01:03 +0200 | [diff] [blame] | 4431 | mv88e6xxx_phy_destroy(chip); |
Vivien Didelot | fad09c7 | 2016-06-21 12:28:20 -0400 | [diff] [blame] | 4432 | mv88e6xxx_unregister_switch(chip); |
| 4433 | mv88e6xxx_mdio_unregister(chip); |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 4434 | |
Andrew Lunn | 46712644 | 2016-11-20 20:14:15 +0100 | [diff] [blame] | 4435 | if (chip->irq > 0) { |
| 4436 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) |
| 4437 | mv88e6xxx_g2_irq_free(chip); |
| 4438 | mv88e6xxx_g1_irq_free(chip); |
| 4439 | } |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | static const struct of_device_id mv88e6xxx_of_match[] = { |
Vivien Didelot | caac854 | 2016-06-20 13:14:09 -0400 | [diff] [blame] | 4443 | { |
| 4444 | .compatible = "marvell,mv88e6085", |
| 4445 | .data = &mv88e6xxx_table[MV88E6085], |
| 4446 | }, |
Andrew Lunn | 1a3b39e | 2016-11-21 23:26:57 +0100 | [diff] [blame] | 4447 | { |
| 4448 | .compatible = "marvell,mv88e6190", |
| 4449 | .data = &mv88e6xxx_table[MV88E6190], |
| 4450 | }, |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4451 | { /* sentinel */ }, |
| 4452 | }; |
| 4453 | |
| 4454 | MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match); |
| 4455 | |
| 4456 | static struct mdio_driver mv88e6xxx_driver = { |
| 4457 | .probe = mv88e6xxx_probe, |
| 4458 | .remove = mv88e6xxx_remove, |
| 4459 | .mdiodrv.driver = { |
| 4460 | .name = "mv88e6085", |
| 4461 | .of_match_table = mv88e6xxx_of_match, |
| 4462 | }, |
| 4463 | }; |
| 4464 | |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 4465 | static int __init mv88e6xxx_init(void) |
| 4466 | { |
Florian Fainelli | ab3d408 | 2017-01-08 14:52:07 -0800 | [diff] [blame] | 4467 | register_switch_driver(&mv88e6xxx_switch_drv); |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4468 | return mdio_driver_register(&mv88e6xxx_driver); |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 4469 | } |
| 4470 | module_init(mv88e6xxx_init); |
| 4471 | |
| 4472 | static void __exit mv88e6xxx_cleanup(void) |
| 4473 | { |
Andrew Lunn | 14c7b3c | 2016-05-10 23:27:21 +0200 | [diff] [blame] | 4474 | mdio_driver_unregister(&mv88e6xxx_driver); |
Florian Fainelli | ab3d408 | 2017-01-08 14:52:07 -0800 | [diff] [blame] | 4475 | unregister_switch_driver(&mv88e6xxx_switch_drv); |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 4476 | } |
| 4477 | module_exit(mv88e6xxx_cleanup); |
Ben Hutchings | 3d825ed | 2011-11-25 14:37:16 +0000 | [diff] [blame] | 4478 | |
| 4479 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>"); |
| 4480 | MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips"); |
| 4481 | MODULE_LICENSE("GPL"); |