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