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