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