blob: 46e8d1871847ac52d4a67c6de12b1820b23679ca [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
7 *
Vivien Didelot4333d612017-03-28 15:10:36 -04008 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
9 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * 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 Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040035
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040036#include "chip.h"
Vivien Didelota935c052016-09-29 12:21:53 -040037#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040038#include "global2.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020039#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020041#include "serdes.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000042
Vivien Didelotfad09c72016-06-21 12:28:20 -040043static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040044{
Vivien Didelotfad09c72016-06-21 12:28:20 -040045 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
46 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040047 dump_stack();
48 }
49}
50
Vivien Didelot914b32f2016-06-20 13:14:11 -040051/* The switch ADDR[4:1] configuration pins define the chip SMI device address
52 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
53 *
54 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
55 * is the only device connected to the SMI master. In this mode it responds to
56 * all 32 possible SMI addresses, and thus maps directly the internal devices.
57 *
58 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
59 * multiple devices to share the SMI interface. In this mode it responds to only
60 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000061 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040062
Vivien Didelotfad09c72016-06-21 12:28:20 -040063static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040064 int addr, int reg, u16 *val)
65{
Vivien Didelotfad09c72016-06-21 12:28:20 -040066 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040067 return -EOPNOTSUPP;
68
Vivien Didelotfad09c72016-06-21 12:28:20 -040069 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040070}
71
Vivien Didelotfad09c72016-06-21 12:28:20 -040072static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040073 int addr, int reg, u16 val)
74{
Vivien Didelotfad09c72016-06-21 12:28:20 -040075 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040076 return -EOPNOTSUPP;
77
Vivien Didelotfad09c72016-06-21 12:28:20 -040078 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040079}
80
Vivien Didelotfad09c72016-06-21 12:28:20 -040081static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040082 int addr, int reg, u16 *val)
83{
84 int ret;
85
Vivien Didelotfad09c72016-06-21 12:28:20 -040086 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040087 if (ret < 0)
88 return ret;
89
90 *val = ret & 0xffff;
91
92 return 0;
93}
94
Vivien Didelotfad09c72016-06-21 12:28:20 -040095static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040096 int addr, int reg, u16 val)
97{
98 int ret;
99
Vivien Didelotfad09c72016-06-21 12:28:20 -0400100 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400101 if (ret < 0)
102 return ret;
103
104 return 0;
105}
106
Vivien Didelotc08026a2016-09-29 12:21:59 -0400107static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400108 .read = mv88e6xxx_smi_single_chip_read,
109 .write = mv88e6xxx_smi_single_chip_write,
110};
111
Vivien Didelotfad09c72016-06-21 12:28:20 -0400112static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000113{
114 int ret;
115 int i;
116
117 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400118 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000119 if (ret < 0)
120 return ret;
121
Andrew Lunncca8b132015-04-02 04:06:39 +0200122 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000123 return 0;
124 }
125
126 return -ETIMEDOUT;
127}
128
Vivien Didelotfad09c72016-06-21 12:28:20 -0400129static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400130 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000131{
132 int ret;
133
Barry Grussling3675c8d2013-01-08 16:05:53 +0000134 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400135 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000136 if (ret < 0)
137 return ret;
138
Barry Grussling3675c8d2013-01-08 16:05:53 +0000139 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400140 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200141 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000142 if (ret < 0)
143 return ret;
144
Barry Grussling3675c8d2013-01-08 16:05:53 +0000145 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400146 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000147 if (ret < 0)
148 return ret;
149
Barry Grussling3675c8d2013-01-08 16:05:53 +0000150 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400151 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000152 if (ret < 0)
153 return ret;
154
Vivien Didelot914b32f2016-06-20 13:14:11 -0400155 *val = ret & 0xffff;
156
157 return 0;
158}
159
Vivien Didelotfad09c72016-06-21 12:28:20 -0400160static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400161 int addr, int reg, u16 val)
162{
163 int ret;
164
165 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400166 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400167 if (ret < 0)
168 return ret;
169
170 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400171 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400172 if (ret < 0)
173 return ret;
174
175 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400176 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400177 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
178 if (ret < 0)
179 return ret;
180
181 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400182 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400183 if (ret < 0)
184 return ret;
185
186 return 0;
187}
188
Vivien Didelotc08026a2016-09-29 12:21:59 -0400189static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400190 .read = mv88e6xxx_smi_multi_chip_read,
191 .write = mv88e6xxx_smi_multi_chip_write,
192};
193
Vivien Didelotec561272016-09-02 14:45:33 -0400194int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400195{
196 int err;
197
Vivien Didelotfad09c72016-06-21 12:28:20 -0400198 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400199
Vivien Didelotfad09c72016-06-21 12:28:20 -0400200 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400201 if (err)
202 return err;
203
Vivien Didelotfad09c72016-06-21 12:28:20 -0400204 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400205 addr, reg, *val);
206
207 return 0;
208}
209
Vivien Didelotec561272016-09-02 14:45:33 -0400210int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400211{
212 int err;
213
Vivien Didelotfad09c72016-06-21 12:28:20 -0400214 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400215
Vivien Didelotfad09c72016-06-21 12:28:20 -0400216 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400217 if (err)
218 return err;
219
Vivien Didelotfad09c72016-06-21 12:28:20 -0400220 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400221 addr, reg, val);
222
223 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000224}
225
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200226struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100227{
228 struct mv88e6xxx_mdio_bus *mdio_bus;
229
230 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
231 list);
232 if (!mdio_bus)
233 return NULL;
234
235 return mdio_bus->bus;
236}
237
Andrew Lunndc30c352016-10-16 19:56:49 +0200238static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
239{
240 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
241 unsigned int n = d->hwirq;
242
243 chip->g1_irq.masked |= (1 << n);
244}
245
246static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
247{
248 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
249 unsigned int n = d->hwirq;
250
251 chip->g1_irq.masked &= ~(1 << n);
252}
253
254static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
255{
256 struct mv88e6xxx_chip *chip = dev_id;
257 unsigned int nhandled = 0;
258 unsigned int sub_irq;
259 unsigned int n;
260 u16 reg;
261 int err;
262
263 mutex_lock(&chip->reg_lock);
Vivien Didelot82466922017-06-15 12:13:59 -0400264 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200265 mutex_unlock(&chip->reg_lock);
266
267 if (err)
268 goto out;
269
270 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
271 if (reg & (1 << n)) {
272 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
273 handle_nested_irq(sub_irq);
274 ++nhandled;
275 }
276 }
277out:
278 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
279}
280
281static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
282{
283 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
284
285 mutex_lock(&chip->reg_lock);
286}
287
288static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
289{
290 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
291 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
292 u16 reg;
293 int err;
294
Vivien Didelotd77f4322017-06-15 12:14:03 -0400295 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200296 if (err)
297 goto out;
298
299 reg &= ~mask;
300 reg |= (~chip->g1_irq.masked & mask);
301
Vivien Didelotd77f4322017-06-15 12:14:03 -0400302 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200303 if (err)
304 goto out;
305
306out:
307 mutex_unlock(&chip->reg_lock);
308}
309
310static struct irq_chip mv88e6xxx_g1_irq_chip = {
311 .name = "mv88e6xxx-g1",
312 .irq_mask = mv88e6xxx_g1_irq_mask,
313 .irq_unmask = mv88e6xxx_g1_irq_unmask,
314 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
315 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
316};
317
318static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
319 unsigned int irq,
320 irq_hw_number_t hwirq)
321{
322 struct mv88e6xxx_chip *chip = d->host_data;
323
324 irq_set_chip_data(irq, d->host_data);
325 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
326 irq_set_noprobe(irq);
327
328 return 0;
329}
330
331static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
332 .map = mv88e6xxx_g1_irq_domain_map,
333 .xlate = irq_domain_xlate_twocell,
334};
335
336static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
337{
338 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100339 u16 mask;
340
Vivien Didelotd77f4322017-06-15 12:14:03 -0400341 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100342 mask |= GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400343 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100344
345 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200346
Andreas Färber5edef2f2016-11-27 23:26:28 +0100347 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100348 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200349 irq_dispose_mapping(virq);
350 }
351
Andrew Lunna3db3d32016-11-20 20:14:14 +0100352 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200353}
354
355static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
356{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100357 int err, irq, virq;
358 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200359
360 chip->g1_irq.nirqs = chip->info->g1_irqs;
361 chip->g1_irq.domain = irq_domain_add_simple(
362 NULL, chip->g1_irq.nirqs, 0,
363 &mv88e6xxx_g1_irq_domain_ops, chip);
364 if (!chip->g1_irq.domain)
365 return -ENOMEM;
366
367 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
368 irq_create_mapping(chip->g1_irq.domain, irq);
369
370 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
371 chip->g1_irq.masked = ~0;
372
Vivien Didelotd77f4322017-06-15 12:14:03 -0400373 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200374 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100375 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200376
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100377 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200378
Vivien Didelotd77f4322017-06-15 12:14:03 -0400379 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200380 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100381 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200382
383 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400384 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200385 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100386 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200387
388 err = request_threaded_irq(chip->irq, NULL,
389 mv88e6xxx_g1_irq_thread_fn,
390 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
391 dev_name(chip->dev), chip);
392 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100393 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200394
395 return 0;
396
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100397out_disable:
398 mask |= GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400399 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100400
401out_mapping:
402 for (irq = 0; irq < 16; irq++) {
403 virq = irq_find_mapping(chip->g1_irq.domain, irq);
404 irq_dispose_mapping(virq);
405 }
406
407 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200408
409 return err;
410}
411
Vivien Didelotec561272016-09-02 14:45:33 -0400412int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400413{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200414 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400415
Andrew Lunn6441e6692016-08-19 00:01:55 +0200416 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400417 u16 val;
418 int err;
419
420 err = mv88e6xxx_read(chip, addr, reg, &val);
421 if (err)
422 return err;
423
424 if (!(val & mask))
425 return 0;
426
427 usleep_range(1000, 2000);
428 }
429
Andrew Lunn30853552016-08-19 00:01:57 +0200430 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400431 return -ETIMEDOUT;
432}
433
Vivien Didelotf22ab642016-07-18 20:45:31 -0400434/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400435int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400436{
437 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200438 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400439
440 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200441 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
442 if (err)
443 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400444
445 /* Set the Update bit to trigger a write operation */
446 val = BIT(15) | update;
447
448 return mv88e6xxx_write(chip, addr, reg, val);
449}
450
Vivien Didelotd78343d2016-11-04 03:23:36 +0100451static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
452 int link, int speed, int duplex,
453 phy_interface_t mode)
454{
455 int err;
456
457 if (!chip->info->ops->port_set_link)
458 return 0;
459
460 /* Port's MAC control must not be changed unless the link is down */
461 err = chip->info->ops->port_set_link(chip, port, 0);
462 if (err)
463 return err;
464
465 if (chip->info->ops->port_set_speed) {
466 err = chip->info->ops->port_set_speed(chip, port, speed);
467 if (err && err != -EOPNOTSUPP)
468 goto restore_link;
469 }
470
471 if (chip->info->ops->port_set_duplex) {
472 err = chip->info->ops->port_set_duplex(chip, port, duplex);
473 if (err && err != -EOPNOTSUPP)
474 goto restore_link;
475 }
476
477 if (chip->info->ops->port_set_rgmii_delay) {
478 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
479 if (err && err != -EOPNOTSUPP)
480 goto restore_link;
481 }
482
Andrew Lunnf39908d2017-02-04 20:02:50 +0100483 if (chip->info->ops->port_set_cmode) {
484 err = chip->info->ops->port_set_cmode(chip, port, mode);
485 if (err && err != -EOPNOTSUPP)
486 goto restore_link;
487 }
488
Vivien Didelotd78343d2016-11-04 03:23:36 +0100489 err = 0;
490restore_link:
491 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400492 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100493
494 return err;
495}
496
Andrew Lunndea87022015-08-31 15:56:47 +0200497/* We expect the switch to perform auto negotiation if there is a real
498 * phy. However, in the case of a fixed link phy, we force the port
499 * settings from the fixed link settings.
500 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400501static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
502 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200503{
Vivien Didelot04bed142016-08-31 18:06:13 -0400504 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200505 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200506
507 if (!phy_is_pseudo_fixed_link(phydev))
508 return;
509
Vivien Didelotfad09c72016-06-21 12:28:20 -0400510 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100511 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
512 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400513 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100514
515 if (err && err != -EOPNOTSUPP)
Vivien Didelot774439e52017-06-08 18:34:08 -0400516 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
Andrew Lunndea87022015-08-31 15:56:47 +0200517}
518
Andrew Lunna605a0f2016-11-21 23:26:58 +0100519static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000520{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100521 if (!chip->info->ops->stats_snapshot)
522 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000523
Andrew Lunna605a0f2016-11-21 23:26:58 +0100524 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000525}
526
Andrew Lunne413e7e2015-04-02 04:06:38 +0200527static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100528 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
529 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
530 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
531 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
532 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
533 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
534 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
535 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
536 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
537 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
538 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
539 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
540 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
541 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
542 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
543 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
544 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
545 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
546 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
547 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
548 { "single", 4, 0x14, STATS_TYPE_BANK0, },
549 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
550 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
551 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
552 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
553 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
554 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
555 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
556 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
557 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
558 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
559 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
560 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
561 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
562 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
563 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
564 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
565 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
566 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
567 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
568 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
569 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
570 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
571 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
572 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
573 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
574 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
575 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
576 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
577 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
578 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
579 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
580 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
581 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
582 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
583 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
584 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
585 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
586 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200587};
588
Vivien Didelotfad09c72016-06-21 12:28:20 -0400589static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100590 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100591 int port, u16 bank1_select,
592 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200593{
Andrew Lunn80c46272015-06-20 18:42:30 +0200594 u32 low;
595 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100596 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200597 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200598 u64 value;
599
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100600 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100601 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200602 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
603 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200604 return UINT64_MAX;
605
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200606 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200607 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200608 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
609 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200610 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200611 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200612 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100613 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100614 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100615 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100616 /* fall through */
617 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100618 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100619 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200620 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100621 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500622 break;
623 default:
624 return UINT64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200625 }
626 value = (((u64)high) << 16) | low;
627 return value;
628}
629
Andrew Lunndfafe442016-11-21 23:27:02 +0100630static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
631 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100632{
633 struct mv88e6xxx_hw_stat *stat;
634 int i, j;
635
636 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
637 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100638 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100639 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
640 ETH_GSTRING_LEN);
641 j++;
642 }
643 }
644}
645
Andrew Lunndfafe442016-11-21 23:27:02 +0100646static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
647 uint8_t *data)
648{
649 mv88e6xxx_stats_get_strings(chip, data,
650 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
651}
652
653static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
654 uint8_t *data)
655{
656 mv88e6xxx_stats_get_strings(chip, data,
657 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
658}
659
660static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
661 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100662{
Vivien Didelot04bed142016-08-31 18:06:13 -0400663 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100664
665 if (chip->info->ops->stats_get_strings)
666 chip->info->ops->stats_get_strings(chip, data);
667}
668
669static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
670 int types)
671{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100672 struct mv88e6xxx_hw_stat *stat;
673 int i, j;
674
675 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
676 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100677 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100678 j++;
679 }
680 return j;
681}
682
Andrew Lunndfafe442016-11-21 23:27:02 +0100683static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
684{
685 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
686 STATS_TYPE_PORT);
687}
688
689static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
690{
691 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
692 STATS_TYPE_BANK1);
693}
694
695static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
696{
697 struct mv88e6xxx_chip *chip = ds->priv;
698
699 if (chip->info->ops->stats_get_sset_count)
700 return chip->info->ops->stats_get_sset_count(chip);
701
702 return 0;
703}
704
Andrew Lunn052f9472016-11-21 23:27:03 +0100705static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100706 uint64_t *data, int types,
707 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100708{
709 struct mv88e6xxx_hw_stat *stat;
710 int i, j;
711
712 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
713 stat = &mv88e6xxx_hw_stats[i];
714 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100715 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
716 bank1_select,
717 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100718 j++;
719 }
720 }
721}
722
723static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
724 uint64_t *data)
725{
726 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100727 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400728 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100729}
730
731static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
732 uint64_t *data)
733{
734 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100735 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400736 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
737 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100738}
739
740static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
741 uint64_t *data)
742{
743 return mv88e6xxx_stats_get_stats(chip, port, data,
744 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400745 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
746 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100747}
748
749static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
750 uint64_t *data)
751{
752 if (chip->info->ops->stats_get_stats)
753 chip->info->ops->stats_get_stats(chip, port, data);
754}
755
Vivien Didelotf81ec902016-05-09 13:22:58 -0400756static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
757 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000758{
Vivien Didelot04bed142016-08-31 18:06:13 -0400759 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000760 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000761
Vivien Didelotfad09c72016-06-21 12:28:20 -0400762 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000763
Andrew Lunna605a0f2016-11-21 23:26:58 +0100764 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000765 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400766 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000767 return;
768 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100769
770 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000771
Vivien Didelotfad09c72016-06-21 12:28:20 -0400772 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000773}
Ben Hutchings98e67302011-11-25 14:36:19 +0000774
Andrew Lunnde2273872016-11-21 23:27:01 +0100775static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
776{
777 if (chip->info->ops->stats_set_histogram)
778 return chip->info->ops->stats_set_histogram(chip);
779
780 return 0;
781}
782
Vivien Didelotf81ec902016-05-09 13:22:58 -0400783static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700784{
785 return 32 * sizeof(u16);
786}
787
Vivien Didelotf81ec902016-05-09 13:22:58 -0400788static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
789 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700790{
Vivien Didelot04bed142016-08-31 18:06:13 -0400791 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200792 int err;
793 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700794 u16 *p = _p;
795 int i;
796
797 regs->version = 0;
798
799 memset(p, 0xff, 32 * sizeof(u16));
800
Vivien Didelotfad09c72016-06-21 12:28:20 -0400801 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400802
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700803 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700804
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200805 err = mv88e6xxx_port_read(chip, port, i, &reg);
806 if (!err)
807 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700808 }
Vivien Didelot23062512016-05-09 13:22:45 -0400809
Vivien Didelotfad09c72016-06-21 12:28:20 -0400810 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700811}
812
Vivien Didelotf81ec902016-05-09 13:22:58 -0400813static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
814 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800815{
Vivien Didelot04bed142016-08-31 18:06:13 -0400816 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400817 u16 reg;
818 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800819
Vivien Didelotfad09c72016-06-21 12:28:20 -0400820 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400821 return -EOPNOTSUPP;
822
Vivien Didelotfad09c72016-06-21 12:28:20 -0400823 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200824
Vivien Didelot9c938292016-08-15 17:19:02 -0400825 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
826 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200827 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800828
829 e->eee_enabled = !!(reg & 0x0200);
830 e->tx_lpi_enabled = !!(reg & 0x0100);
831
Vivien Didelot5f83dc92017-06-12 12:37:33 -0400832 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -0400833 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200834 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800835
Vivien Didelot5f83dc92017-06-12 12:37:33 -0400836 e->eee_active = !!(reg & MV88E6352_PORT_STS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200837out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400838 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -0400839
840 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800841}
842
Vivien Didelotf81ec902016-05-09 13:22:58 -0400843static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
844 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800845{
Vivien Didelot04bed142016-08-31 18:06:13 -0400846 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400847 u16 reg;
848 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800849
Vivien Didelotfad09c72016-06-21 12:28:20 -0400850 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400851 return -EOPNOTSUPP;
852
Vivien Didelotfad09c72016-06-21 12:28:20 -0400853 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800854
Vivien Didelot9c938292016-08-15 17:19:02 -0400855 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
856 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200857 goto out;
858
Vivien Didelot9c938292016-08-15 17:19:02 -0400859 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +0200860 if (e->eee_enabled)
861 reg |= 0x0200;
862 if (e->tx_lpi_enabled)
863 reg |= 0x0100;
864
Vivien Didelot9c938292016-08-15 17:19:02 -0400865 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200866out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400867 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200868
Vivien Didelot9c938292016-08-15 17:19:02 -0400869 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800870}
871
Vivien Didelote5887a22017-03-30 17:37:11 -0400872static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700873{
Vivien Didelote5887a22017-03-30 17:37:11 -0400874 struct dsa_switch *ds = NULL;
875 struct net_device *br;
876 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500877 int i;
878
Vivien Didelote5887a22017-03-30 17:37:11 -0400879 if (dev < DSA_MAX_SWITCHES)
880 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500881
Vivien Didelote5887a22017-03-30 17:37:11 -0400882 /* Prevent frames from unknown switch or port */
883 if (!ds || port >= ds->num_ports)
884 return 0;
885
886 /* Frames from DSA links and CPU ports can egress any local port */
887 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
888 return mv88e6xxx_port_mask(chip);
889
890 br = ds->ports[port].bridge_dev;
891 pvlan = 0;
892
893 /* Frames from user ports can egress any local DSA links and CPU ports,
894 * as well as any local member of their bridge group.
895 */
896 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
897 if (dsa_is_cpu_port(chip->ds, i) ||
898 dsa_is_dsa_port(chip->ds, i) ||
899 (br && chip->ds->ports[i].bridge_dev == br))
900 pvlan |= BIT(i);
901
902 return pvlan;
903}
904
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400905static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400906{
907 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500908
909 /* prevent frames from going back out of the port they came in on */
910 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700911
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100912 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700913}
914
Vivien Didelotf81ec902016-05-09 13:22:58 -0400915static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
916 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700917{
Vivien Didelot04bed142016-08-31 18:06:13 -0400918 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -0400919 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700920
Vivien Didelotfad09c72016-06-21 12:28:20 -0400921 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -0400922 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400923 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400924
925 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400926 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700927}
928
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500929static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
930{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500931 int err;
932
Vivien Didelotdaefc942017-03-11 16:12:54 -0500933 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
934 if (err)
935 return err;
936
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500937 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
938 if (err)
939 return err;
940
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500941 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
942}
943
Vivien Didelot17a15942017-03-30 17:37:09 -0400944static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
945{
946 u16 pvlan = 0;
947
948 if (!mv88e6xxx_has_pvt(chip))
949 return -EOPNOTSUPP;
950
951 /* Skip the local source device, which uses in-chip port VLAN */
952 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -0400953 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -0400954
955 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
956}
957
Vivien Didelot81228992017-03-30 17:37:08 -0400958static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
959{
Vivien Didelot17a15942017-03-30 17:37:09 -0400960 int dev, port;
961 int err;
962
Vivien Didelot81228992017-03-30 17:37:08 -0400963 if (!mv88e6xxx_has_pvt(chip))
964 return 0;
965
966 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
967 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
968 */
Vivien Didelot17a15942017-03-30 17:37:09 -0400969 err = mv88e6xxx_g2_misc_4_bit_port(chip);
970 if (err)
971 return err;
972
973 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
974 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
975 err = mv88e6xxx_pvt_map(chip, dev, port);
976 if (err)
977 return err;
978 }
979 }
980
981 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -0400982}
983
Vivien Didelot749efcb2016-09-22 16:49:24 -0400984static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
985{
986 struct mv88e6xxx_chip *chip = ds->priv;
987 int err;
988
989 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -0500990 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -0400991 mutex_unlock(&chip->reg_lock);
992
993 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400994 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -0400995}
996
Vivien Didelotb486d7c2017-05-01 14:05:13 -0400997static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
998{
999 if (!chip->info->max_vid)
1000 return 0;
1001
1002 return mv88e6xxx_g1_vtu_flush(chip);
1003}
1004
Vivien Didelotf1394b782017-05-01 14:05:22 -04001005static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1006 struct mv88e6xxx_vtu_entry *entry)
1007{
1008 if (!chip->info->ops->vtu_getnext)
1009 return -EOPNOTSUPP;
1010
1011 return chip->info->ops->vtu_getnext(chip, entry);
1012}
1013
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001014static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1015 struct mv88e6xxx_vtu_entry *entry)
1016{
1017 if (!chip->info->ops->vtu_loadpurge)
1018 return -EOPNOTSUPP;
1019
1020 return chip->info->ops->vtu_loadpurge(chip, entry);
1021}
1022
Vivien Didelotf81ec902016-05-09 13:22:58 -04001023static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1024 struct switchdev_obj_port_vlan *vlan,
Vivien Didelot438ff532017-05-17 15:46:05 -04001025 switchdev_obj_dump_cb_t *cb)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001026{
Vivien Didelot04bed142016-08-31 18:06:13 -04001027 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001028 struct mv88e6xxx_vtu_entry next = {
1029 .vid = chip->info->max_vid,
1030 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001031 u16 pvid;
1032 int err;
1033
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001034 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001035 return -EOPNOTSUPP;
1036
Vivien Didelotfad09c72016-06-21 12:28:20 -04001037 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001038
Vivien Didelot77064f32016-11-04 03:23:30 +01001039 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001040 if (err)
1041 goto unlock;
1042
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001043 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001044 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001045 if (err)
1046 break;
1047
1048 if (!next.valid)
1049 break;
1050
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001051 if (next.member[port] ==
1052 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001053 continue;
1054
1055 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001056 vlan->vid_begin = next.vid;
1057 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001058 vlan->flags = 0;
1059
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001060 if (next.member[port] ==
1061 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001062 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1063
1064 if (next.vid == pvid)
1065 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1066
1067 err = cb(&vlan->obj);
1068 if (err)
1069 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001070 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001071
1072unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001073 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001074
1075 return err;
1076}
1077
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001078static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001079{
1080 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001081 struct mv88e6xxx_vtu_entry vlan = {
1082 .vid = chip->info->max_vid,
1083 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001084 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001085
1086 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1087
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001088 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001089 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001090 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001091 if (err)
1092 return err;
1093
1094 set_bit(*fid, fid_bitmap);
1095 }
1096
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001097 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001098 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001099 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001100 if (err)
1101 return err;
1102
1103 if (!vlan.valid)
1104 break;
1105
1106 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001107 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001108
1109 /* The reset value 0x000 is used to indicate that multiple address
1110 * databases are not needed. Return the next positive available.
1111 */
1112 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001113 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001114 return -ENOSPC;
1115
1116 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001117 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001118}
1119
Vivien Didelot567aa592017-05-01 14:05:25 -04001120static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1121 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001122{
1123 int err;
1124
1125 if (!vid)
1126 return -EINVAL;
1127
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001128 entry->vid = vid - 1;
1129 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001130
Vivien Didelotf1394b782017-05-01 14:05:22 -04001131 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001132 if (err)
1133 return err;
1134
Vivien Didelot567aa592017-05-01 14:05:25 -04001135 if (entry->vid == vid && entry->valid)
1136 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001137
Vivien Didelot567aa592017-05-01 14:05:25 -04001138 if (new) {
1139 int i;
1140
1141 /* Initialize a fresh VLAN entry */
1142 memset(entry, 0, sizeof(*entry));
1143 entry->valid = true;
1144 entry->vid = vid;
1145
Vivien Didelot553a7682017-06-07 18:12:16 -04001146 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001147 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001148 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001149 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001150
1151 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001152 }
1153
Vivien Didelot567aa592017-05-01 14:05:25 -04001154 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1155 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001156}
1157
Vivien Didelotda9c3592016-02-12 12:09:40 -05001158static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1159 u16 vid_begin, u16 vid_end)
1160{
Vivien Didelot04bed142016-08-31 18:06:13 -04001161 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001162 struct mv88e6xxx_vtu_entry vlan = {
1163 .vid = vid_begin - 1,
1164 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001165 int i, err;
1166
1167 if (!vid_begin)
1168 return -EOPNOTSUPP;
1169
Vivien Didelotfad09c72016-06-21 12:28:20 -04001170 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001171
Vivien Didelotda9c3592016-02-12 12:09:40 -05001172 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001173 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001174 if (err)
1175 goto unlock;
1176
1177 if (!vlan.valid)
1178 break;
1179
1180 if (vlan.vid > vid_end)
1181 break;
1182
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001183 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001184 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1185 continue;
1186
Andrew Lunn66e28092016-12-11 21:07:19 +01001187 if (!ds->ports[port].netdev)
1188 continue;
1189
Vivien Didelotbd00e052017-05-01 14:05:11 -04001190 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001191 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001192 continue;
1193
Vivien Didelotfae8a252017-01-27 15:29:42 -05001194 if (ds->ports[i].bridge_dev ==
1195 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001196 break; /* same bridge, check next VLAN */
1197
Vivien Didelotfae8a252017-01-27 15:29:42 -05001198 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001199 continue;
1200
Vivien Didelot774439e52017-06-08 18:34:08 -04001201 dev_err(ds->dev, "p%d: hw VLAN %d already used by %s\n",
1202 port, vlan.vid,
1203 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001204 err = -EOPNOTSUPP;
1205 goto unlock;
1206 }
1207 } while (vlan.vid < vid_end);
1208
1209unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001211
1212 return err;
1213}
1214
Vivien Didelotf81ec902016-05-09 13:22:58 -04001215static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1216 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001217{
Vivien Didelot04bed142016-08-31 18:06:13 -04001218 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001219 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1220 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001221 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001222
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001223 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001224 return -EOPNOTSUPP;
1225
Vivien Didelotfad09c72016-06-21 12:28:20 -04001226 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001227 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001228 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001229
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001230 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001231}
1232
Vivien Didelot57d32312016-06-20 13:13:58 -04001233static int
1234mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1235 const struct switchdev_obj_port_vlan *vlan,
1236 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001237{
Vivien Didelot04bed142016-08-31 18:06:13 -04001238 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001239 int err;
1240
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001241 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001242 return -EOPNOTSUPP;
1243
Vivien Didelotda9c3592016-02-12 12:09:40 -05001244 /* If the requested port doesn't belong to the same bridge as the VLAN
1245 * members, do not support it (yet) and fallback to software VLAN.
1246 */
1247 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1248 vlan->vid_end);
1249 if (err)
1250 return err;
1251
Vivien Didelot76e398a2015-11-01 12:33:55 -05001252 /* We don't need any dynamic resource from the kernel (yet),
1253 * so skip the prepare phase.
1254 */
1255 return 0;
1256}
1257
Vivien Didelotfad09c72016-06-21 12:28:20 -04001258static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001259 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001260{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001261 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001262 int err;
1263
Vivien Didelot567aa592017-05-01 14:05:25 -04001264 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001265 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001266 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001267
Vivien Didelotc91498e2017-06-07 18:12:13 -04001268 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001269
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001270 return mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001271}
1272
Vivien Didelotf81ec902016-05-09 13:22:58 -04001273static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1274 const struct switchdev_obj_port_vlan *vlan,
1275 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001276{
Vivien Didelot04bed142016-08-31 18:06:13 -04001277 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001278 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1279 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001280 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001281 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001282
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001283 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001284 return;
1285
Vivien Didelotc91498e2017-06-07 18:12:13 -04001286 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001287 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001288 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001289 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001290 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001291 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001292
Vivien Didelotfad09c72016-06-21 12:28:20 -04001293 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001294
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001295 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001296 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001297 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1298 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001299
Vivien Didelot77064f32016-11-04 03:23:30 +01001300 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001301 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1302 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001303
Vivien Didelotfad09c72016-06-21 12:28:20 -04001304 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001305}
1306
Vivien Didelotfad09c72016-06-21 12:28:20 -04001307static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001308 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001309{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001310 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001311 int i, err;
1312
Vivien Didelot567aa592017-05-01 14:05:25 -04001313 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001314 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001315 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001316
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001317 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001318 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001319 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001320
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001321 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001322
1323 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001324 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001325 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001326 if (vlan.member[i] !=
1327 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001328 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001329 break;
1330 }
1331 }
1332
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001333 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001334 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001335 return err;
1336
Vivien Didelote606ca32017-03-11 16:12:55 -05001337 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001338}
1339
Vivien Didelotf81ec902016-05-09 13:22:58 -04001340static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1341 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001342{
Vivien Didelot04bed142016-08-31 18:06:13 -04001343 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001344 u16 pvid, vid;
1345 int err = 0;
1346
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001347 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001348 return -EOPNOTSUPP;
1349
Vivien Didelotfad09c72016-06-21 12:28:20 -04001350 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001351
Vivien Didelot77064f32016-11-04 03:23:30 +01001352 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001353 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001354 goto unlock;
1355
Vivien Didelot76e398a2015-11-01 12:33:55 -05001356 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001357 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001358 if (err)
1359 goto unlock;
1360
1361 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001362 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001363 if (err)
1364 goto unlock;
1365 }
1366 }
1367
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001368unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001369 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001370
1371 return err;
1372}
1373
Vivien Didelot83dabd12016-08-31 11:50:04 -04001374static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1375 const unsigned char *addr, u16 vid,
1376 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001377{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001378 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001379 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001380 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001381
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001382 /* Null VLAN ID corresponds to the port private database */
1383 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001384 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001385 else
Vivien Didelot567aa592017-05-01 14:05:25 -04001386 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001387 if (err)
1388 return err;
1389
Vivien Didelot27c0e602017-06-15 12:14:01 -04001390 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001391 ether_addr_copy(entry.mac, addr);
1392 eth_addr_dec(entry.mac);
1393
1394 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001395 if (err)
1396 return err;
1397
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001398 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelot27c0e602017-06-15 12:14:01 -04001399 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001400 !ether_addr_equal(entry.mac, addr)) {
1401 memset(&entry, 0, sizeof(entry));
1402 ether_addr_copy(entry.mac, addr);
1403 }
1404
Vivien Didelot88472932016-09-19 19:56:11 -04001405 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelot27c0e602017-06-15 12:14:01 -04001406 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001407 entry.portvec &= ~BIT(port);
1408 if (!entry.portvec)
Vivien Didelot27c0e602017-06-15 12:14:01 -04001409 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelot88472932016-09-19 19:56:11 -04001410 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001411 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001412 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001413 }
1414
Vivien Didelot9c13c022017-03-11 16:12:52 -05001415 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001416}
1417
Vivien Didelotf81ec902016-05-09 13:22:58 -04001418static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1419 const struct switchdev_obj_port_fdb *fdb,
1420 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001421{
1422 /* We don't need any dynamic resource from the kernel (yet),
1423 * so skip the prepare phase.
1424 */
1425 return 0;
1426}
1427
Vivien Didelotf81ec902016-05-09 13:22:58 -04001428static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1429 const struct switchdev_obj_port_fdb *fdb,
1430 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001431{
Vivien Didelot04bed142016-08-31 18:06:13 -04001432 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001433
Vivien Didelotfad09c72016-06-21 12:28:20 -04001434 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001435 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001436 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04001437 dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
1438 port);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001439 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001440}
1441
Vivien Didelotf81ec902016-05-09 13:22:58 -04001442static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1443 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001444{
Vivien Didelot04bed142016-08-31 18:06:13 -04001445 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001446 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001447
Vivien Didelotfad09c72016-06-21 12:28:20 -04001448 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001449 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001450 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001451 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001452
Vivien Didelot83dabd12016-08-31 11:50:04 -04001453 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001454}
1455
Vivien Didelot83dabd12016-08-31 11:50:04 -04001456static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1457 u16 fid, u16 vid, int port,
1458 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001459 switchdev_obj_dump_cb_t *cb)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001460{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001461 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001462 int err;
1463
Vivien Didelot27c0e602017-06-15 12:14:01 -04001464 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001465 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001466
1467 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001468 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001469 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001470 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001471
Vivien Didelot27c0e602017-06-15 12:14:01 -04001472 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001473 break;
1474
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001475 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001476 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001477
Vivien Didelot83dabd12016-08-31 11:50:04 -04001478 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1479 struct switchdev_obj_port_fdb *fdb;
1480
1481 if (!is_unicast_ether_addr(addr.mac))
1482 continue;
1483
1484 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001485 fdb->vid = vid;
1486 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot27c0e602017-06-15 12:14:01 -04001487 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001488 fdb->ndm_state = NUD_NOARP;
1489 else
1490 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001491 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1492 struct switchdev_obj_port_mdb *mdb;
1493
1494 if (!is_multicast_ether_addr(addr.mac))
1495 continue;
1496
1497 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1498 mdb->vid = vid;
1499 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001500 } else {
1501 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001502 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001503
1504 err = cb(obj);
1505 if (err)
1506 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001507 } while (!is_broadcast_ether_addr(addr.mac));
1508
1509 return err;
1510}
1511
Vivien Didelot83dabd12016-08-31 11:50:04 -04001512static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1513 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001514 switchdev_obj_dump_cb_t *cb)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001515{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001516 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001517 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001518 };
1519 u16 fid;
1520 int err;
1521
1522 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001523 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001524 if (err)
1525 return err;
1526
1527 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1528 if (err)
1529 return err;
1530
1531 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001532 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001533 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001534 if (err)
1535 return err;
1536
1537 if (!vlan.valid)
1538 break;
1539
1540 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1541 obj, cb);
1542 if (err)
1543 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001544 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001545
1546 return err;
1547}
1548
Vivien Didelotf81ec902016-05-09 13:22:58 -04001549static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1550 struct switchdev_obj_port_fdb *fdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04001551 switchdev_obj_dump_cb_t *cb)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001552{
Vivien Didelot04bed142016-08-31 18:06:13 -04001553 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001554 int err;
1555
Vivien Didelotfad09c72016-06-21 12:28:20 -04001556 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001557 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001558 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001559
1560 return err;
1561}
1562
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001563static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1564 struct net_device *br)
1565{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001566 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001567 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001568 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001569 int err;
1570
1571 /* Remap the Port VLAN of each local bridge group member */
1572 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1573 if (chip->ds->ports[port].bridge_dev == br) {
1574 err = mv88e6xxx_port_vlan_map(chip, port);
1575 if (err)
1576 return err;
1577 }
1578 }
1579
Vivien Didelote96a6e02017-03-30 17:37:13 -04001580 if (!mv88e6xxx_has_pvt(chip))
1581 return 0;
1582
1583 /* Remap the Port VLAN of each cross-chip bridge group member */
1584 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1585 ds = chip->ds->dst->ds[dev];
1586 if (!ds)
1587 break;
1588
1589 for (port = 0; port < ds->num_ports; ++port) {
1590 if (ds->ports[port].bridge_dev == br) {
1591 err = mv88e6xxx_pvt_map(chip, dev, port);
1592 if (err)
1593 return err;
1594 }
1595 }
1596 }
1597
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001598 return 0;
1599}
1600
Vivien Didelotf81ec902016-05-09 13:22:58 -04001601static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001602 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001603{
Vivien Didelot04bed142016-08-31 18:06:13 -04001604 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001605 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001606
Vivien Didelotfad09c72016-06-21 12:28:20 -04001607 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001608 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001609 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001610
Vivien Didelot466dfa02016-02-26 13:16:05 -05001611 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001612}
1613
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001614static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1615 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001616{
Vivien Didelot04bed142016-08-31 18:06:13 -04001617 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001618
Vivien Didelotfad09c72016-06-21 12:28:20 -04001619 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001620 if (mv88e6xxx_bridge_map(chip, br) ||
1621 mv88e6xxx_port_vlan_map(chip, port))
1622 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001623 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001624}
1625
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001626static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1627 int port, struct net_device *br)
1628{
1629 struct mv88e6xxx_chip *chip = ds->priv;
1630 int err;
1631
1632 if (!mv88e6xxx_has_pvt(chip))
1633 return 0;
1634
1635 mutex_lock(&chip->reg_lock);
1636 err = mv88e6xxx_pvt_map(chip, dev, port);
1637 mutex_unlock(&chip->reg_lock);
1638
1639 return err;
1640}
1641
1642static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1643 int port, struct net_device *br)
1644{
1645 struct mv88e6xxx_chip *chip = ds->priv;
1646
1647 if (!mv88e6xxx_has_pvt(chip))
1648 return;
1649
1650 mutex_lock(&chip->reg_lock);
1651 if (mv88e6xxx_pvt_map(chip, dev, port))
1652 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1653 mutex_unlock(&chip->reg_lock);
1654}
1655
Vivien Didelot17e708b2016-12-05 17:30:27 -05001656static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1657{
1658 if (chip->info->ops->reset)
1659 return chip->info->ops->reset(chip);
1660
1661 return 0;
1662}
1663
Vivien Didelot309eca62016-12-05 17:30:26 -05001664static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1665{
1666 struct gpio_desc *gpiod = chip->reset;
1667
1668 /* If there is a GPIO connected to the reset pin, toggle it */
1669 if (gpiod) {
1670 gpiod_set_value_cansleep(gpiod, 1);
1671 usleep_range(10000, 20000);
1672 gpiod_set_value_cansleep(gpiod, 0);
1673 usleep_range(10000, 20000);
1674 }
1675}
1676
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001677static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1678{
1679 int i, err;
1680
1681 /* Set all ports to the Disabled state */
1682 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001683 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001684 if (err)
1685 return err;
1686 }
1687
1688 /* Wait for transmit queues to drain,
1689 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1690 */
1691 usleep_range(2000, 4000);
1692
1693 return 0;
1694}
1695
Vivien Didelotfad09c72016-06-21 12:28:20 -04001696static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001697{
Vivien Didelota935c052016-09-29 12:21:53 -04001698 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001699
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001700 err = mv88e6xxx_disable_ports(chip);
1701 if (err)
1702 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001703
Vivien Didelot309eca62016-12-05 17:30:26 -05001704 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001705
Vivien Didelot17e708b2016-12-05 17:30:27 -05001706 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001707}
1708
Vivien Didelot43145572017-03-11 16:12:59 -05001709static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001710 enum mv88e6xxx_frame_mode frame,
1711 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001712{
1713 int err;
1714
Vivien Didelot43145572017-03-11 16:12:59 -05001715 if (!chip->info->ops->port_set_frame_mode)
1716 return -EOPNOTSUPP;
1717
1718 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001719 if (err)
1720 return err;
1721
Vivien Didelot43145572017-03-11 16:12:59 -05001722 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1723 if (err)
1724 return err;
1725
1726 if (chip->info->ops->port_set_ether_type)
1727 return chip->info->ops->port_set_ether_type(chip, port, etype);
1728
1729 return 0;
1730}
1731
1732static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1733{
1734 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001735 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001736 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001737}
1738
1739static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1740{
1741 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001742 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001743 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001744}
1745
1746static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1747{
1748 return mv88e6xxx_set_port_mode(chip, port,
1749 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001750 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1751 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001752}
1753
1754static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1755{
1756 if (dsa_is_dsa_port(chip->ds, port))
1757 return mv88e6xxx_set_port_mode_dsa(chip, port);
1758
1759 if (dsa_is_normal_port(chip->ds, port))
1760 return mv88e6xxx_set_port_mode_normal(chip, port);
1761
1762 /* Setup CPU port mode depending on its supported tag format */
1763 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1764 return mv88e6xxx_set_port_mode_dsa(chip, port);
1765
1766 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1767 return mv88e6xxx_set_port_mode_edsa(chip, port);
1768
1769 return -EINVAL;
1770}
1771
Vivien Didelotea698f42017-03-11 16:12:50 -05001772static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1773{
1774 bool message = dsa_is_dsa_port(chip->ds, port);
1775
1776 return mv88e6xxx_port_set_message_port(chip, port, message);
1777}
1778
Vivien Didelot601aeed2017-03-11 16:13:00 -05001779static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1780{
1781 bool flood = port == dsa_upstream_port(chip->ds);
1782
1783 /* Upstream ports flood frames with unknown unicast or multicast DA */
1784 if (chip->info->ops->port_set_egress_floods)
1785 return chip->info->ops->port_set_egress_floods(chip, port,
1786 flood, flood);
1787
1788 return 0;
1789}
1790
Andrew Lunn6d917822017-05-26 01:03:21 +02001791static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1792 bool on)
1793{
Vivien Didelot523a8902017-05-26 18:02:42 -04001794 if (chip->info->ops->serdes_power)
1795 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001796
Vivien Didelot523a8902017-05-26 18:02:42 -04001797 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001798}
1799
Vivien Didelotfad09c72016-06-21 12:28:20 -04001800static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001801{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001802 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001803 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001804 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001805
Vivien Didelotd78343d2016-11-04 03:23:36 +01001806 /* MAC Forcing register: don't force link, speed, duplex or flow control
1807 * state to any particular values on physical ports, but force the CPU
1808 * port and all DSA ports to their maximum bandwidth and full duplex.
1809 */
1810 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1811 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1812 SPEED_MAX, DUPLEX_FULL,
1813 PHY_INTERFACE_MODE_NA);
1814 else
1815 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1816 SPEED_UNFORCED, DUPLEX_UNFORCED,
1817 PHY_INTERFACE_MODE_NA);
1818 if (err)
1819 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001820
1821 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1822 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1823 * tunneling, determine priority by looking at 802.1p and IP
1824 * priority fields (IP prio has precedence), and set STP state
1825 * to Forwarding.
1826 *
1827 * If this is the CPU link, use DSA or EDSA tagging depending
1828 * on which tagging mode was configured.
1829 *
1830 * If this is a link to another switch, use DSA tagging mode.
1831 *
1832 * If this is the upstream port for this switch, enable
1833 * forwarding of unknown unicasts and multicasts.
1834 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04001835 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
1836 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
1837 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1838 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001839 if (err)
1840 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001841
Vivien Didelot601aeed2017-03-11 16:13:00 -05001842 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001843 if (err)
1844 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001845
Vivien Didelot601aeed2017-03-11 16:13:00 -05001846 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001847 if (err)
1848 return err;
1849
Andrew Lunn04aca992017-05-26 01:03:24 +02001850 /* Enable the SERDES interface for DSA and CPU ports. Normal
1851 * ports SERDES are enabled when the port is enabled, thus
1852 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001853 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001854 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1855 err = mv88e6xxx_serdes_power(chip, port, true);
1856 if (err)
1857 return err;
1858 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001859
Vivien Didelot8efdda42015-08-13 12:52:23 -04001860 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001861 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001862 * untagged frames on this port, do a destination address lookup on all
1863 * received packets as usual, disable ARP mirroring and don't send a
1864 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001865 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001866 err = mv88e6xxx_port_set_map_da(chip, port);
1867 if (err)
1868 return err;
1869
Andrew Lunn54d792f2015-05-06 01:09:47 +02001870 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01001871 if (chip->info->ops->port_set_upstream_port) {
1872 err = chip->info->ops->port_set_upstream_port(
1873 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001874 if (err)
1875 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001876 }
1877
Andrew Lunna23b2962017-02-04 20:15:28 +01001878 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001879 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01001880 if (err)
1881 return err;
1882
Vivien Didelotcd782652017-06-08 18:34:13 -04001883 if (chip->info->ops->port_set_jumbo_size) {
1884 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01001885 if (err)
1886 return err;
1887 }
1888
Andrew Lunn54d792f2015-05-06 01:09:47 +02001889 /* Port Association Vector: when learning source addresses
1890 * of packets, add the address to the address database using
1891 * a port bitmap that has only the bit for this port set and
1892 * the other bits clear.
1893 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001894 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001895 /* Disable learning for CPU port */
1896 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001897 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001898
Vivien Didelot2a4614e2017-06-12 12:37:43 -04001899 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
1900 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001901 if (err)
1902 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001903
1904 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04001905 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
1906 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001907 if (err)
1908 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001909
Vivien Didelot08984322017-06-08 18:34:12 -04001910 if (chip->info->ops->port_pause_limit) {
1911 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001912 if (err)
1913 return err;
1914 }
1915
Vivien Didelotc8c94892017-03-11 16:13:01 -05001916 if (chip->info->ops->port_disable_learn_limit) {
1917 err = chip->info->ops->port_disable_learn_limit(chip, port);
1918 if (err)
1919 return err;
1920 }
1921
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001922 if (chip->info->ops->port_disable_pri_override) {
1923 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001924 if (err)
1925 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01001926 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02001927
Andrew Lunnef0a7312016-12-03 04:35:16 +01001928 if (chip->info->ops->port_tag_remap) {
1929 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001930 if (err)
1931 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001932 }
1933
Andrew Lunnef70b112016-12-03 04:45:18 +01001934 if (chip->info->ops->port_egress_rate_limiting) {
1935 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001936 if (err)
1937 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001938 }
1939
Vivien Didelotea698f42017-03-11 16:12:50 -05001940 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001941 if (err)
1942 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001943
Vivien Didelot207afda2016-04-14 14:42:09 -04001944 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001945 * database, and allow bidirectional communication between the
1946 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07001947 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001948 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001949 if (err)
1950 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001951
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001952 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001953 if (err)
1954 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001955
1956 /* Default VLAN ID and priority: don't set a default VLAN
1957 * ID, and set the default packet priority to zero.
1958 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04001959 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02001960}
1961
Andrew Lunn04aca992017-05-26 01:03:24 +02001962static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
1963 struct phy_device *phydev)
1964{
1965 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04001966 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02001967
1968 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001969 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02001970 mutex_unlock(&chip->reg_lock);
1971
1972 return err;
1973}
1974
1975static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
1976 struct phy_device *phydev)
1977{
1978 struct mv88e6xxx_chip *chip = ds->priv;
1979
1980 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001981 if (mv88e6xxx_serdes_power(chip, port, false))
1982 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02001983 mutex_unlock(&chip->reg_lock);
1984}
1985
Vivien Didelot2cfcd962016-07-18 20:45:40 -04001986static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
1987 unsigned int ageing_time)
1988{
Vivien Didelot04bed142016-08-31 18:06:13 -04001989 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04001990 int err;
1991
1992 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05001993 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04001994 mutex_unlock(&chip->reg_lock);
1995
1996 return err;
1997}
1998
Vivien Didelot97299342016-07-18 20:45:30 -04001999static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002000{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002001 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002002 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002003 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002004
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002005 if (chip->info->ops->set_cpu_port) {
2006 err = chip->info->ops->set_cpu_port(chip, upstream_port);
Andrew Lunn33641992016-12-03 04:35:17 +01002007 if (err)
2008 return err;
2009 }
2010
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002011 if (chip->info->ops->set_egress_port) {
2012 err = chip->info->ops->set_egress_port(chip, upstream_port);
Andrew Lunn33641992016-12-03 04:35:17 +01002013 if (err)
2014 return err;
2015 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002016
Vivien Didelot50484ff2016-05-09 13:22:54 -04002017 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelotd77f4322017-06-15 12:14:03 -04002018 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2019 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
Vivien Didelota935c052016-09-29 12:21:53 -04002020 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002021 if (err)
2022 return err;
2023
Vivien Didelot08a01262016-05-09 13:22:50 -04002024 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002025 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002026 if (err)
2027 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002028 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002029 if (err)
2030 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002031 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002032 if (err)
2033 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002034 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002035 if (err)
2036 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002037 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002038 if (err)
2039 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002040 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002041 if (err)
2042 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002043 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002044 if (err)
2045 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002046 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002047 if (err)
2048 return err;
2049
2050 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002051 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002052 if (err)
2053 return err;
2054
Andrew Lunnde2273872016-11-21 23:27:01 +01002055 /* Initialize the statistics unit */
2056 err = mv88e6xxx_stats_set_histogram(chip);
2057 if (err)
2058 return err;
2059
Vivien Didelot97299342016-07-18 20:45:30 -04002060 /* Clear the statistics counters for all ports */
Vivien Didelot57d1ef32017-06-15 12:14:05 -04002061 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_STATS_OP,
2062 MV88E6XXX_G1_STATS_OP_BUSY |
2063 MV88E6XXX_G1_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002064 if (err)
2065 return err;
2066
2067 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002068 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002069 if (err)
2070 return err;
2071
2072 return 0;
2073}
2074
Vivien Didelotf81ec902016-05-09 13:22:58 -04002075static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002076{
Vivien Didelot04bed142016-08-31 18:06:13 -04002077 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002078 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002079 int i;
2080
Vivien Didelotfad09c72016-06-21 12:28:20 -04002081 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002082 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002083
Vivien Didelotfad09c72016-06-21 12:28:20 -04002084 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002085
Vivien Didelot97299342016-07-18 20:45:30 -04002086 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002087 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002088 err = mv88e6xxx_setup_port(chip, i);
2089 if (err)
2090 goto unlock;
2091 }
2092
2093 /* Setup Switch Global 1 Registers */
2094 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002095 if (err)
2096 goto unlock;
2097
Vivien Didelot97299342016-07-18 20:45:30 -04002098 /* Setup Switch Global 2 Registers */
2099 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2100 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002101 if (err)
2102 goto unlock;
2103 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002104
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002105 err = mv88e6xxx_phy_setup(chip);
2106 if (err)
2107 goto unlock;
2108
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002109 err = mv88e6xxx_vtu_setup(chip);
2110 if (err)
2111 goto unlock;
2112
Vivien Didelot81228992017-03-30 17:37:08 -04002113 err = mv88e6xxx_pvt_setup(chip);
2114 if (err)
2115 goto unlock;
2116
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002117 err = mv88e6xxx_atu_setup(chip);
2118 if (err)
2119 goto unlock;
2120
Andrew Lunn6e55f692016-12-03 04:45:16 +01002121 /* Some generations have the configuration of sending reserved
2122 * management frames to the CPU in global2, others in
2123 * global1. Hence it does not fit the two setup functions
2124 * above.
2125 */
2126 if (chip->info->ops->mgmt_rsvd2cpu) {
2127 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2128 if (err)
2129 goto unlock;
2130 }
2131
Vivien Didelot6b17e862015-08-13 12:52:18 -04002132unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002133 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002134
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002135 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002136}
2137
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002138static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2139{
Vivien Didelot04bed142016-08-31 18:06:13 -04002140 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002141 int err;
2142
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002143 if (!chip->info->ops->set_switch_mac)
2144 return -EOPNOTSUPP;
2145
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002146 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002147 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002148 mutex_unlock(&chip->reg_lock);
2149
2150 return err;
2151}
2152
Vivien Didelote57e5e72016-08-15 17:19:00 -04002153static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002154{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002155 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2156 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002157 u16 val;
2158 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002159
Andrew Lunnee26a222017-01-24 14:53:48 +01002160 if (!chip->info->ops->phy_read)
2161 return -EOPNOTSUPP;
2162
Vivien Didelotfad09c72016-06-21 12:28:20 -04002163 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002164 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002165 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002166
Andrew Lunnda9f3302017-02-01 03:40:05 +01002167 if (reg == MII_PHYSID2) {
2168 /* Some internal PHYS don't have a model number. Use
2169 * the mv88e6390 family model number instead.
2170 */
2171 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002172 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002173 }
2174
Vivien Didelote57e5e72016-08-15 17:19:00 -04002175 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002176}
2177
Vivien Didelote57e5e72016-08-15 17:19:00 -04002178static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002179{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002180 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2181 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002182 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002183
Andrew Lunnee26a222017-01-24 14:53:48 +01002184 if (!chip->info->ops->phy_write)
2185 return -EOPNOTSUPP;
2186
Vivien Didelotfad09c72016-06-21 12:28:20 -04002187 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002188 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002189 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002190
2191 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002192}
2193
Vivien Didelotfad09c72016-06-21 12:28:20 -04002194static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002195 struct device_node *np,
2196 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002197{
2198 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002199 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002200 struct mii_bus *bus;
2201 int err;
2202
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002203 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002204 if (!bus)
2205 return -ENOMEM;
2206
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002207 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002208 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002209 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002210 INIT_LIST_HEAD(&mdio_bus->list);
2211 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002212
Andrew Lunnb516d452016-06-04 21:17:06 +02002213 if (np) {
2214 bus->name = np->full_name;
2215 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2216 } else {
2217 bus->name = "mv88e6xxx SMI";
2218 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2219 }
2220
2221 bus->read = mv88e6xxx_mdio_read;
2222 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002223 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002224
Andrew Lunna3c53be52017-01-24 14:53:50 +01002225 if (np)
2226 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002227 else
2228 err = mdiobus_register(bus);
2229 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002230 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002231 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002232 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002233
2234 if (external)
2235 list_add_tail(&mdio_bus->list, &chip->mdios);
2236 else
2237 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002238
2239 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002240}
2241
Andrew Lunna3c53be52017-01-24 14:53:50 +01002242static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2243 { .compatible = "marvell,mv88e6xxx-mdio-external",
2244 .data = (void *)true },
2245 { },
2246};
2247
2248static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2249 struct device_node *np)
2250{
2251 const struct of_device_id *match;
2252 struct device_node *child;
2253 int err;
2254
2255 /* Always register one mdio bus for the internal/default mdio
2256 * bus. This maybe represented in the device tree, but is
2257 * optional.
2258 */
2259 child = of_get_child_by_name(np, "mdio");
2260 err = mv88e6xxx_mdio_register(chip, child, false);
2261 if (err)
2262 return err;
2263
2264 /* Walk the device tree, and see if there are any other nodes
2265 * which say they are compatible with the external mdio
2266 * bus.
2267 */
2268 for_each_available_child_of_node(np, child) {
2269 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2270 if (match) {
2271 err = mv88e6xxx_mdio_register(chip, child, true);
2272 if (err)
2273 return err;
2274 }
2275 }
2276
2277 return 0;
2278}
2279
2280static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002281
2282{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002283 struct mv88e6xxx_mdio_bus *mdio_bus;
2284 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002285
Andrew Lunna3c53be52017-01-24 14:53:50 +01002286 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2287 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002288
Andrew Lunna3c53be52017-01-24 14:53:50 +01002289 mdiobus_unregister(bus);
2290 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002291}
2292
Vivien Didelot855b1932016-07-20 18:18:35 -04002293static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2294{
Vivien Didelot04bed142016-08-31 18:06:13 -04002295 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002296
2297 return chip->eeprom_len;
2298}
2299
Vivien Didelot855b1932016-07-20 18:18:35 -04002300static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2301 struct ethtool_eeprom *eeprom, u8 *data)
2302{
Vivien Didelot04bed142016-08-31 18:06:13 -04002303 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002304 int err;
2305
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002306 if (!chip->info->ops->get_eeprom)
2307 return -EOPNOTSUPP;
2308
Vivien Didelot855b1932016-07-20 18:18:35 -04002309 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002310 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002311 mutex_unlock(&chip->reg_lock);
2312
2313 if (err)
2314 return err;
2315
2316 eeprom->magic = 0xc3ec4951;
2317
2318 return 0;
2319}
2320
Vivien Didelot855b1932016-07-20 18:18:35 -04002321static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2322 struct ethtool_eeprom *eeprom, u8 *data)
2323{
Vivien Didelot04bed142016-08-31 18:06:13 -04002324 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002325 int err;
2326
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002327 if (!chip->info->ops->set_eeprom)
2328 return -EOPNOTSUPP;
2329
Vivien Didelot855b1932016-07-20 18:18:35 -04002330 if (eeprom->magic != 0xc3ec4951)
2331 return -EINVAL;
2332
2333 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002334 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002335 mutex_unlock(&chip->reg_lock);
2336
2337 return err;
2338}
2339
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002340static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002341 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002342 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002343 .phy_read = mv88e6185_phy_ppu_read,
2344 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002345 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002346 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002347 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002348 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002349 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002350 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002351 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002352 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002353 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002354 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002355 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002356 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002357 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2358 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002359 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002360 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2361 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002362 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002363 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002364 .ppu_enable = mv88e6185_g1_ppu_enable,
2365 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002366 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002367 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002368 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002369};
2370
2371static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002372 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002373 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002374 .phy_read = mv88e6185_phy_ppu_read,
2375 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002376 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002377 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002378 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002379 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002380 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002381 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002382 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002383 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2384 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002385 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002386 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002387 .ppu_enable = mv88e6185_g1_ppu_enable,
2388 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002389 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002390 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002391 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002392};
2393
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002394static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002395 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002396 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2397 .phy_read = mv88e6xxx_g2_smi_phy_read,
2398 .phy_write = mv88e6xxx_g2_smi_phy_write,
2399 .port_set_link = mv88e6xxx_port_set_link,
2400 .port_set_duplex = mv88e6xxx_port_set_duplex,
2401 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002402 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002403 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002404 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002405 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002406 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002407 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002408 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002409 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002410 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002411 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2412 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2413 .stats_get_strings = mv88e6095_stats_get_strings,
2414 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002415 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2416 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002417 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002418 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002419 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002420 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002421 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002422};
2423
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002424static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002425 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002426 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002427 .phy_read = mv88e6xxx_g2_smi_phy_read,
2428 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002429 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002430 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002431 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002432 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002433 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002434 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002435 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002436 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002437 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2438 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002439 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002440 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2441 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002442 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002443 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002444 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002445 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002446 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002447};
2448
2449static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002450 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002451 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002452 .phy_read = mv88e6185_phy_ppu_read,
2453 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002454 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002455 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002456 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002457 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002458 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002459 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002460 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002461 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002462 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002463 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002464 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002465 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002466 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2467 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002468 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002469 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2470 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002471 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002472 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002473 .ppu_enable = mv88e6185_g1_ppu_enable,
2474 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002475 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002476 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002477 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002478};
2479
Vivien Didelot990e27b2017-03-28 13:50:32 -04002480static const struct mv88e6xxx_ops mv88e6141_ops = {
2481 /* MV88E6XXX_FAMILY_6341 */
2482 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2483 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2484 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2485 .phy_read = mv88e6xxx_g2_smi_phy_read,
2486 .phy_write = mv88e6xxx_g2_smi_phy_write,
2487 .port_set_link = mv88e6xxx_port_set_link,
2488 .port_set_duplex = mv88e6xxx_port_set_duplex,
2489 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2490 .port_set_speed = mv88e6390_port_set_speed,
2491 .port_tag_remap = mv88e6095_port_tag_remap,
2492 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2493 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2494 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002495 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002496 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002497 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002498 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2499 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2500 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2501 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2502 .stats_get_strings = mv88e6320_stats_get_strings,
2503 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002504 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2505 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002506 .watchdog_ops = &mv88e6390_watchdog_ops,
2507 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2508 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002509 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002510 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002511};
2512
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002513static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002514 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002515 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002516 .phy_read = mv88e6xxx_g2_smi_phy_read,
2517 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002518 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002519 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002520 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002521 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002522 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002523 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002524 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002525 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002526 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002527 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002528 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002529 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002530 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002531 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2532 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002533 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002534 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2535 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002536 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002537 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002538 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002539 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002540 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002541};
2542
2543static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002544 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002545 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002546 .phy_read = mv88e6165_phy_read,
2547 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002548 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002549 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002550 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002551 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002552 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002553 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002554 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2555 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002556 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002557 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2558 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002559 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002560 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002561 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002562 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002563 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002564};
2565
2566static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002567 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002568 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002569 .phy_read = mv88e6xxx_g2_smi_phy_read,
2570 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002571 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002572 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002573 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002574 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002575 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002576 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002577 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002578 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002579 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002580 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002581 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002582 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002583 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002584 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002585 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2586 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002587 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002588 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2589 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002590 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002591 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002592 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002593 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002594 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002595};
2596
2597static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002598 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002599 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2600 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002601 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002602 .phy_read = mv88e6xxx_g2_smi_phy_read,
2603 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002604 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002605 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002606 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002607 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002608 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002609 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002610 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002611 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002612 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002613 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002614 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002615 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002616 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002617 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002618 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2619 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002620 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002621 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2622 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002623 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002624 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002625 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002626 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002627 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002628 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002629};
2630
2631static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002632 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002633 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002634 .phy_read = mv88e6xxx_g2_smi_phy_read,
2635 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002636 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002637 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002638 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002639 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002640 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002641 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002642 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002643 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002644 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002645 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002646 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002647 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002648 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002649 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002650 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2651 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002652 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002653 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2654 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002655 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002656 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002657 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002658 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002659 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002660};
2661
2662static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002663 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002664 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2665 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002666 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002667 .phy_read = mv88e6xxx_g2_smi_phy_read,
2668 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002669 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002670 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002671 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002672 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002673 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002674 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002675 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002676 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002677 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002678 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002679 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002680 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002681 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002682 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002683 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2684 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002685 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002686 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2687 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002688 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002689 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002690 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002691 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002692 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002693 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002694};
2695
2696static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002697 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002698 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002699 .phy_read = mv88e6185_phy_ppu_read,
2700 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002701 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002702 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002703 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002704 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002705 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002706 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002707 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002708 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002709 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2710 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002711 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002712 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2713 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002714 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002715 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002716 .ppu_enable = mv88e6185_g1_ppu_enable,
2717 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002718 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002719 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002720 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002721};
2722
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002723static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002724 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002725 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2726 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002727 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2728 .phy_read = mv88e6xxx_g2_smi_phy_read,
2729 .phy_write = mv88e6xxx_g2_smi_phy_write,
2730 .port_set_link = mv88e6xxx_port_set_link,
2731 .port_set_duplex = mv88e6xxx_port_set_duplex,
2732 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2733 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002734 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002735 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002736 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002737 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002738 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002739 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002740 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002741 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002742 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002743 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2744 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002745 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002746 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2747 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002748 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002749 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002750 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002751 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2752 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002753 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002754};
2755
2756static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002757 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002758 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2759 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002760 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2761 .phy_read = mv88e6xxx_g2_smi_phy_read,
2762 .phy_write = mv88e6xxx_g2_smi_phy_write,
2763 .port_set_link = mv88e6xxx_port_set_link,
2764 .port_set_duplex = mv88e6xxx_port_set_duplex,
2765 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2766 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002767 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002768 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002769 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002770 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002771 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002772 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002773 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002774 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002775 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002776 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2777 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002778 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002779 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2780 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002781 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002782 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002783 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002784 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2785 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002786 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002787};
2788
2789static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002790 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002791 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2792 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002793 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2794 .phy_read = mv88e6xxx_g2_smi_phy_read,
2795 .phy_write = mv88e6xxx_g2_smi_phy_write,
2796 .port_set_link = mv88e6xxx_port_set_link,
2797 .port_set_duplex = mv88e6xxx_port_set_duplex,
2798 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2799 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002800 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002801 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002802 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002803 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002804 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002805 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002806 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002807 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002808 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002809 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2810 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002811 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002812 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2813 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002814 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002815 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002816 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002817 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2818 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002819 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002820};
2821
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002822static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002823 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002824 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2825 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002826 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002827 .phy_read = mv88e6xxx_g2_smi_phy_read,
2828 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002829 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002830 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002831 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002832 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002833 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002834 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002835 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002836 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002837 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002838 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002839 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002840 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002841 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002842 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002843 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2844 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002845 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002846 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2847 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002848 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002849 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002850 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002851 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002852 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002853 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002854};
2855
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002856static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002857 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002858 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2859 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002860 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2861 .phy_read = mv88e6xxx_g2_smi_phy_read,
2862 .phy_write = mv88e6xxx_g2_smi_phy_write,
2863 .port_set_link = mv88e6xxx_port_set_link,
2864 .port_set_duplex = mv88e6xxx_port_set_duplex,
2865 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2866 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002867 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002868 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002869 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002870 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002871 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002872 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002873 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002874 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002875 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002876 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002877 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2878 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002879 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002880 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2881 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002882 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002883 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002884 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002885 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2886 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002887 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002888};
2889
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002890static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002891 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002892 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2893 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002894 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002895 .phy_read = mv88e6xxx_g2_smi_phy_read,
2896 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002897 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002898 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002899 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002900 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002901 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002902 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002903 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002904 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002905 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002906 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002907 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002908 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002909 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002910 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2911 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002912 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002913 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2914 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002915 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002916 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002917 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002918 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002919};
2920
2921static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002922 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002923 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2924 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002925 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002926 .phy_read = mv88e6xxx_g2_smi_phy_read,
2927 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002928 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002929 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002930 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002931 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002932 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002933 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002934 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002935 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002936 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002937 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002938 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002939 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002940 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002941 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2942 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002943 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002944 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2945 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002946 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002947 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002948 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002949};
2950
Vivien Didelot16e329a2017-03-28 13:50:33 -04002951static const struct mv88e6xxx_ops mv88e6341_ops = {
2952 /* MV88E6XXX_FAMILY_6341 */
2953 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2954 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2955 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2956 .phy_read = mv88e6xxx_g2_smi_phy_read,
2957 .phy_write = mv88e6xxx_g2_smi_phy_write,
2958 .port_set_link = mv88e6xxx_port_set_link,
2959 .port_set_duplex = mv88e6xxx_port_set_duplex,
2960 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2961 .port_set_speed = mv88e6390_port_set_speed,
2962 .port_tag_remap = mv88e6095_port_tag_remap,
2963 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2964 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2965 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002966 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04002967 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002968 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04002969 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2970 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2971 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2972 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2973 .stats_get_strings = mv88e6320_stats_get_strings,
2974 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002975 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2976 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04002977 .watchdog_ops = &mv88e6390_watchdog_ops,
2978 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2979 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002980 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002981 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot16e329a2017-03-28 13:50:33 -04002982};
2983
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002984static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002985 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002986 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002987 .phy_read = mv88e6xxx_g2_smi_phy_read,
2988 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002989 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002990 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002991 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002992 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002993 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002994 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002995 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002996 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002997 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002998 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002999 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003000 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003001 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003002 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003003 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3004 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003005 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003006 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3007 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003008 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003009 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003010 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003011 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003012 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003013};
3014
3015static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003016 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003017 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003018 .phy_read = mv88e6xxx_g2_smi_phy_read,
3019 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003020 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003021 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003022 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003023 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003024 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003025 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003026 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003027 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003028 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003029 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003030 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003031 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003032 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003033 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003034 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3035 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003036 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003037 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3038 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003039 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003040 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003041 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003042 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003043 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003044};
3045
3046static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003047 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003048 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3049 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003050 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003051 .phy_read = mv88e6xxx_g2_smi_phy_read,
3052 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003053 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003054 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003055 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003056 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003057 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003058 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003059 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003060 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003061 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003062 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003063 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003064 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003065 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003066 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003067 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3068 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003069 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003070 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3071 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003072 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003073 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003074 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003075 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003076 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003077 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003078};
3079
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003080static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003081 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003082 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3083 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003084 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3085 .phy_read = mv88e6xxx_g2_smi_phy_read,
3086 .phy_write = mv88e6xxx_g2_smi_phy_write,
3087 .port_set_link = mv88e6xxx_port_set_link,
3088 .port_set_duplex = mv88e6xxx_port_set_duplex,
3089 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3090 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003091 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003092 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003093 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003094 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003095 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003096 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003097 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003098 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003099 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003100 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003101 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003102 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003103 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3104 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003105 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003106 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3107 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003108 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003109 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003110 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003111 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3112 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003113 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003114};
3115
3116static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003117 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003118 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3119 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003120 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3121 .phy_read = mv88e6xxx_g2_smi_phy_read,
3122 .phy_write = mv88e6xxx_g2_smi_phy_write,
3123 .port_set_link = mv88e6xxx_port_set_link,
3124 .port_set_duplex = mv88e6xxx_port_set_duplex,
3125 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3126 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003127 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003128 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003129 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003130 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003131 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003132 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003133 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003134 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003135 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003136 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003137 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003138 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3139 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003140 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003141 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3142 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003143 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003144 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003145 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003146 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3147 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003148 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003149};
3150
Vivien Didelotf81ec902016-05-09 13:22:58 -04003151static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3152 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003153 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003154 .family = MV88E6XXX_FAMILY_6097,
3155 .name = "Marvell 88E6085",
3156 .num_databases = 4096,
3157 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003158 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003159 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003160 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003161 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003162 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003163 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003164 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003165 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003166 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003167 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003168 },
3169
3170 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003171 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003172 .family = MV88E6XXX_FAMILY_6095,
3173 .name = "Marvell 88E6095/88E6095F",
3174 .num_databases = 256,
3175 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003176 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003177 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003178 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003179 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003180 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003181 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003182 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003183 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003184 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003185 },
3186
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003187 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003188 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003189 .family = MV88E6XXX_FAMILY_6097,
3190 .name = "Marvell 88E6097/88E6097F",
3191 .num_databases = 4096,
3192 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003193 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003194 .port_base_addr = 0x10,
3195 .global1_addr = 0x1b,
3196 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003197 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003198 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003199 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003200 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003201 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3202 .ops = &mv88e6097_ops,
3203 },
3204
Vivien Didelotf81ec902016-05-09 13:22:58 -04003205 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003206 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003207 .family = MV88E6XXX_FAMILY_6165,
3208 .name = "Marvell 88E6123",
3209 .num_databases = 4096,
3210 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003211 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003212 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003213 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003214 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003215 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003216 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003217 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003218 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003219 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003220 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003221 },
3222
3223 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003224 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003225 .family = MV88E6XXX_FAMILY_6185,
3226 .name = "Marvell 88E6131",
3227 .num_databases = 256,
3228 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003229 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003230 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003231 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003232 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003233 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003234 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003235 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003236 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003237 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003238 },
3239
Vivien Didelot990e27b2017-03-28 13:50:32 -04003240 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003241 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003242 .family = MV88E6XXX_FAMILY_6341,
3243 .name = "Marvell 88E6341",
3244 .num_databases = 4096,
3245 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003246 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003247 .port_base_addr = 0x10,
3248 .global1_addr = 0x1b,
3249 .age_time_coeff = 3750,
3250 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003251 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003252 .tag_protocol = DSA_TAG_PROTO_EDSA,
3253 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3254 .ops = &mv88e6141_ops,
3255 },
3256
Vivien Didelotf81ec902016-05-09 13:22:58 -04003257 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003258 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003259 .family = MV88E6XXX_FAMILY_6165,
3260 .name = "Marvell 88E6161",
3261 .num_databases = 4096,
3262 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003263 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003264 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003265 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003266 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003267 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003268 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003269 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003270 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003271 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003272 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003273 },
3274
3275 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003276 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003277 .family = MV88E6XXX_FAMILY_6165,
3278 .name = "Marvell 88E6165",
3279 .num_databases = 4096,
3280 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003281 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003282 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003283 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003284 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003285 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003286 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003287 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003288 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003289 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003290 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003291 },
3292
3293 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003294 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003295 .family = MV88E6XXX_FAMILY_6351,
3296 .name = "Marvell 88E6171",
3297 .num_databases = 4096,
3298 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003299 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003300 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003301 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003302 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003303 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003304 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003305 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003306 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003307 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003308 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003309 },
3310
3311 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003312 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003313 .family = MV88E6XXX_FAMILY_6352,
3314 .name = "Marvell 88E6172",
3315 .num_databases = 4096,
3316 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003317 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003318 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003319 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003320 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003321 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003322 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003323 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003324 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003325 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003326 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003327 },
3328
3329 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003330 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003331 .family = MV88E6XXX_FAMILY_6351,
3332 .name = "Marvell 88E6175",
3333 .num_databases = 4096,
3334 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003335 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003336 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003337 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003338 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003339 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003340 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003341 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003342 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003343 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003344 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003345 },
3346
3347 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003348 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003349 .family = MV88E6XXX_FAMILY_6352,
3350 .name = "Marvell 88E6176",
3351 .num_databases = 4096,
3352 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003353 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003354 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003355 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003356 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003357 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003358 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003359 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003360 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003361 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003362 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003363 },
3364
3365 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003366 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003367 .family = MV88E6XXX_FAMILY_6185,
3368 .name = "Marvell 88E6185",
3369 .num_databases = 256,
3370 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003371 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003372 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003373 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003374 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003375 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003376 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003377 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003378 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003379 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003380 },
3381
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003382 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003383 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003384 .family = MV88E6XXX_FAMILY_6390,
3385 .name = "Marvell 88E6190",
3386 .num_databases = 4096,
3387 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003388 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003389 .port_base_addr = 0x0,
3390 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003391 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003392 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003393 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003394 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003395 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003396 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3397 .ops = &mv88e6190_ops,
3398 },
3399
3400 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003401 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003402 .family = MV88E6XXX_FAMILY_6390,
3403 .name = "Marvell 88E6190X",
3404 .num_databases = 4096,
3405 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003406 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003407 .port_base_addr = 0x0,
3408 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003409 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003410 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003411 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003412 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003413 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003414 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3415 .ops = &mv88e6190x_ops,
3416 },
3417
3418 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003419 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003420 .family = MV88E6XXX_FAMILY_6390,
3421 .name = "Marvell 88E6191",
3422 .num_databases = 4096,
3423 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003424 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003425 .port_base_addr = 0x0,
3426 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003427 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003428 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003429 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003430 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003431 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003432 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003433 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003434 },
3435
Vivien Didelotf81ec902016-05-09 13:22:58 -04003436 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003437 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003438 .family = MV88E6XXX_FAMILY_6352,
3439 .name = "Marvell 88E6240",
3440 .num_databases = 4096,
3441 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003442 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003443 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003444 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003445 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003446 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003447 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003448 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003449 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003450 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003451 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003452 },
3453
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003454 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003455 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003456 .family = MV88E6XXX_FAMILY_6390,
3457 .name = "Marvell 88E6290",
3458 .num_databases = 4096,
3459 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003460 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003461 .port_base_addr = 0x0,
3462 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003463 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003464 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003465 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003466 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003467 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003468 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3469 .ops = &mv88e6290_ops,
3470 },
3471
Vivien Didelotf81ec902016-05-09 13:22:58 -04003472 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003473 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003474 .family = MV88E6XXX_FAMILY_6320,
3475 .name = "Marvell 88E6320",
3476 .num_databases = 4096,
3477 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003478 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003479 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003480 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003481 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003482 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003483 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003484 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003485 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003486 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003487 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003488 },
3489
3490 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003491 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003492 .family = MV88E6XXX_FAMILY_6320,
3493 .name = "Marvell 88E6321",
3494 .num_databases = 4096,
3495 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003496 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003497 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003498 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003499 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003500 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003501 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003502 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003503 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003504 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003505 },
3506
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003507 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003508 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003509 .family = MV88E6XXX_FAMILY_6341,
3510 .name = "Marvell 88E6341",
3511 .num_databases = 4096,
3512 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003513 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003514 .port_base_addr = 0x10,
3515 .global1_addr = 0x1b,
3516 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003517 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003518 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003519 .tag_protocol = DSA_TAG_PROTO_EDSA,
3520 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3521 .ops = &mv88e6341_ops,
3522 },
3523
Vivien Didelotf81ec902016-05-09 13:22:58 -04003524 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003525 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003526 .family = MV88E6XXX_FAMILY_6351,
3527 .name = "Marvell 88E6350",
3528 .num_databases = 4096,
3529 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003530 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003531 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003532 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003533 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003534 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003535 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003536 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003537 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003538 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003539 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003540 },
3541
3542 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003543 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003544 .family = MV88E6XXX_FAMILY_6351,
3545 .name = "Marvell 88E6351",
3546 .num_databases = 4096,
3547 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003548 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003549 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003550 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003551 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003552 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003553 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003554 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003555 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003556 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003557 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003558 },
3559
3560 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003561 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003562 .family = MV88E6XXX_FAMILY_6352,
3563 .name = "Marvell 88E6352",
3564 .num_databases = 4096,
3565 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003566 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003567 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003568 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003569 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003570 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003571 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003572 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003573 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003574 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003575 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003576 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003577 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003578 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003579 .family = MV88E6XXX_FAMILY_6390,
3580 .name = "Marvell 88E6390",
3581 .num_databases = 4096,
3582 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003583 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003584 .port_base_addr = 0x0,
3585 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003586 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003587 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003588 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003589 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003590 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003591 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3592 .ops = &mv88e6390_ops,
3593 },
3594 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003595 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003596 .family = MV88E6XXX_FAMILY_6390,
3597 .name = "Marvell 88E6390X",
3598 .num_databases = 4096,
3599 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003600 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003601 .port_base_addr = 0x0,
3602 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003603 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003604 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003605 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003606 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003607 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003608 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3609 .ops = &mv88e6390x_ops,
3610 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003611};
3612
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003613static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003614{
Vivien Didelota439c062016-04-17 13:23:58 -04003615 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003616
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003617 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3618 if (mv88e6xxx_table[i].prod_num == prod_num)
3619 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003620
Vivien Didelotb9b37712015-10-30 19:39:48 -04003621 return NULL;
3622}
3623
Vivien Didelotfad09c72016-06-21 12:28:20 -04003624static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003625{
3626 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003627 unsigned int prod_num, rev;
3628 u16 id;
3629 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003630
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003631 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04003632 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003633 mutex_unlock(&chip->reg_lock);
3634 if (err)
3635 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003636
Vivien Didelot107fcc12017-06-12 12:37:36 -04003637 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
3638 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003639
3640 info = mv88e6xxx_lookup_info(prod_num);
3641 if (!info)
3642 return -ENODEV;
3643
Vivien Didelotcaac8542016-06-20 13:14:09 -04003644 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003645 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003646
Vivien Didelotca070c12016-09-02 14:45:34 -04003647 err = mv88e6xxx_g2_require(chip);
3648 if (err)
3649 return err;
3650
Vivien Didelotfad09c72016-06-21 12:28:20 -04003651 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3652 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003653
3654 return 0;
3655}
3656
Vivien Didelotfad09c72016-06-21 12:28:20 -04003657static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003658{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003659 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003660
Vivien Didelotfad09c72016-06-21 12:28:20 -04003661 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3662 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003663 return NULL;
3664
Vivien Didelotfad09c72016-06-21 12:28:20 -04003665 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003666
Vivien Didelotfad09c72016-06-21 12:28:20 -04003667 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003668 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003669
Vivien Didelotfad09c72016-06-21 12:28:20 -04003670 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003671}
3672
Vivien Didelotfad09c72016-06-21 12:28:20 -04003673static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003674 struct mii_bus *bus, int sw_addr)
3675{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003676 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003677 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003678 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003679 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003680 else
3681 return -EINVAL;
3682
Vivien Didelotfad09c72016-06-21 12:28:20 -04003683 chip->bus = bus;
3684 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003685
3686 return 0;
3687}
3688
Andrew Lunn7b314362016-08-22 16:01:01 +02003689static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3690{
Vivien Didelot04bed142016-08-31 18:06:13 -04003691 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003692
Andrew Lunn443d5a12016-12-03 04:35:18 +01003693 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003694}
3695
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003696static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3697 struct device *host_dev, int sw_addr,
3698 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003699{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003700 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003701 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003702 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003703
Vivien Didelota439c062016-04-17 13:23:58 -04003704 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003705 if (!bus)
3706 return NULL;
3707
Vivien Didelotfad09c72016-06-21 12:28:20 -04003708 chip = mv88e6xxx_alloc_chip(dsa_dev);
3709 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003710 return NULL;
3711
Vivien Didelotcaac8542016-06-20 13:14:09 -04003712 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003713 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003714
Vivien Didelotfad09c72016-06-21 12:28:20 -04003715 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003716 if (err)
3717 goto free;
3718
Vivien Didelotfad09c72016-06-21 12:28:20 -04003719 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003720 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003721 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003722
Andrew Lunndc30c352016-10-16 19:56:49 +02003723 mutex_lock(&chip->reg_lock);
3724 err = mv88e6xxx_switch_reset(chip);
3725 mutex_unlock(&chip->reg_lock);
3726 if (err)
3727 goto free;
3728
Vivien Didelote57e5e72016-08-15 17:19:00 -04003729 mv88e6xxx_phy_init(chip);
3730
Andrew Lunna3c53be52017-01-24 14:53:50 +01003731 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003732 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003733 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003734
Vivien Didelotfad09c72016-06-21 12:28:20 -04003735 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003736
Vivien Didelotfad09c72016-06-21 12:28:20 -04003737 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003738free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003739 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003740
3741 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003742}
3743
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003744static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3745 const struct switchdev_obj_port_mdb *mdb,
3746 struct switchdev_trans *trans)
3747{
3748 /* We don't need any dynamic resource from the kernel (yet),
3749 * so skip the prepare phase.
3750 */
3751
3752 return 0;
3753}
3754
3755static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3756 const struct switchdev_obj_port_mdb *mdb,
3757 struct switchdev_trans *trans)
3758{
Vivien Didelot04bed142016-08-31 18:06:13 -04003759 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003760
3761 mutex_lock(&chip->reg_lock);
3762 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003763 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04003764 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
3765 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003766 mutex_unlock(&chip->reg_lock);
3767}
3768
3769static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3770 const struct switchdev_obj_port_mdb *mdb)
3771{
Vivien Didelot04bed142016-08-31 18:06:13 -04003772 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003773 int err;
3774
3775 mutex_lock(&chip->reg_lock);
3776 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003777 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003778 mutex_unlock(&chip->reg_lock);
3779
3780 return err;
3781}
3782
3783static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3784 struct switchdev_obj_port_mdb *mdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04003785 switchdev_obj_dump_cb_t *cb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003786{
Vivien Didelot04bed142016-08-31 18:06:13 -04003787 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003788 int err;
3789
3790 mutex_lock(&chip->reg_lock);
3791 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3792 mutex_unlock(&chip->reg_lock);
3793
3794 return err;
3795}
3796
Florian Fainellia82f67a2017-01-08 14:52:08 -08003797static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003798 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02003799 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003800 .setup = mv88e6xxx_setup,
3801 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003802 .adjust_link = mv88e6xxx_adjust_link,
3803 .get_strings = mv88e6xxx_get_strings,
3804 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3805 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02003806 .port_enable = mv88e6xxx_port_enable,
3807 .port_disable = mv88e6xxx_port_disable,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003808 .set_eee = mv88e6xxx_set_eee,
3809 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003810 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003811 .get_eeprom = mv88e6xxx_get_eeprom,
3812 .set_eeprom = mv88e6xxx_set_eeprom,
3813 .get_regs_len = mv88e6xxx_get_regs_len,
3814 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003815 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003816 .port_bridge_join = mv88e6xxx_port_bridge_join,
3817 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3818 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04003819 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003820 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3821 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3822 .port_vlan_add = mv88e6xxx_port_vlan_add,
3823 .port_vlan_del = mv88e6xxx_port_vlan_del,
3824 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3825 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3826 .port_fdb_add = mv88e6xxx_port_fdb_add,
3827 .port_fdb_del = mv88e6xxx_port_fdb_del,
3828 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003829 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3830 .port_mdb_add = mv88e6xxx_port_mdb_add,
3831 .port_mdb_del = mv88e6xxx_port_mdb_del,
3832 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04003833 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
3834 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003835};
3836
Florian Fainelliab3d4082017-01-08 14:52:07 -08003837static struct dsa_switch_driver mv88e6xxx_switch_drv = {
3838 .ops = &mv88e6xxx_switch_ops,
3839};
3840
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003841static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003842{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003843 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003844 struct dsa_switch *ds;
3845
Vivien Didelot73b12042017-03-30 17:37:10 -04003846 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003847 if (!ds)
3848 return -ENOMEM;
3849
Vivien Didelotfad09c72016-06-21 12:28:20 -04003850 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04003851 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04003852 ds->ageing_time_min = chip->info->age_time_coeff;
3853 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003854
3855 dev_set_drvdata(dev, ds);
3856
Vivien Didelot23c9ee42017-05-26 18:12:51 -04003857 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003858}
3859
Vivien Didelotfad09c72016-06-21 12:28:20 -04003860static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003861{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003862 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003863}
3864
Vivien Didelot57d32312016-06-20 13:13:58 -04003865static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003866{
3867 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003868 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003869 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003870 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003871 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02003872 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003873
Vivien Didelotcaac8542016-06-20 13:14:09 -04003874 compat_info = of_device_get_match_data(dev);
3875 if (!compat_info)
3876 return -EINVAL;
3877
Vivien Didelotfad09c72016-06-21 12:28:20 -04003878 chip = mv88e6xxx_alloc_chip(dev);
3879 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003880 return -ENOMEM;
3881
Vivien Didelotfad09c72016-06-21 12:28:20 -04003882 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003883
Vivien Didelotfad09c72016-06-21 12:28:20 -04003884 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003885 if (err)
3886 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003887
Andrew Lunnb4308f02016-11-21 23:26:55 +01003888 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
3889 if (IS_ERR(chip->reset))
3890 return PTR_ERR(chip->reset);
3891
Vivien Didelotfad09c72016-06-21 12:28:20 -04003892 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003893 if (err)
3894 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003895
Vivien Didelote57e5e72016-08-15 17:19:00 -04003896 mv88e6xxx_phy_init(chip);
3897
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003898 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003899 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003900 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003901
Andrew Lunndc30c352016-10-16 19:56:49 +02003902 mutex_lock(&chip->reg_lock);
3903 err = mv88e6xxx_switch_reset(chip);
3904 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02003905 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02003906 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02003907
Andrew Lunndc30c352016-10-16 19:56:49 +02003908 chip->irq = of_irq_get(np, 0);
3909 if (chip->irq == -EPROBE_DEFER) {
3910 err = chip->irq;
3911 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02003912 }
3913
Andrew Lunndc30c352016-10-16 19:56:49 +02003914 if (chip->irq > 0) {
3915 /* Has to be performed before the MDIO bus is created,
3916 * because the PHYs will link there interrupts to these
3917 * interrupt controllers
3918 */
3919 mutex_lock(&chip->reg_lock);
3920 err = mv88e6xxx_g1_irq_setup(chip);
3921 mutex_unlock(&chip->reg_lock);
3922
3923 if (err)
3924 goto out;
3925
3926 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
3927 err = mv88e6xxx_g2_irq_setup(chip);
3928 if (err)
3929 goto out_g1_irq;
3930 }
3931 }
3932
Andrew Lunna3c53be52017-01-24 14:53:50 +01003933 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02003934 if (err)
3935 goto out_g2_irq;
3936
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003937 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003938 if (err)
3939 goto out_mdio;
3940
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003941 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02003942
3943out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01003944 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003945out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01003946 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02003947 mv88e6xxx_g2_irq_free(chip);
3948out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003949 if (chip->irq > 0) {
3950 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01003951 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003952 mutex_unlock(&chip->reg_lock);
3953 }
Andrew Lunndc30c352016-10-16 19:56:49 +02003954out:
3955 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003956}
3957
3958static void mv88e6xxx_remove(struct mdio_device *mdiodev)
3959{
3960 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04003961 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003962
Andrew Lunn930188c2016-08-22 16:01:03 +02003963 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003964 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003965 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003966
Andrew Lunn467126442016-11-20 20:14:15 +01003967 if (chip->irq > 0) {
3968 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
3969 mv88e6xxx_g2_irq_free(chip);
3970 mv88e6xxx_g1_irq_free(chip);
3971 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003972}
3973
3974static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04003975 {
3976 .compatible = "marvell,mv88e6085",
3977 .data = &mv88e6xxx_table[MV88E6085],
3978 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003979 {
3980 .compatible = "marvell,mv88e6190",
3981 .data = &mv88e6xxx_table[MV88E6190],
3982 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003983 { /* sentinel */ },
3984};
3985
3986MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
3987
3988static struct mdio_driver mv88e6xxx_driver = {
3989 .probe = mv88e6xxx_probe,
3990 .remove = mv88e6xxx_remove,
3991 .mdiodrv.driver = {
3992 .name = "mv88e6085",
3993 .of_match_table = mv88e6xxx_of_match,
3994 },
3995};
3996
Ben Hutchings98e67302011-11-25 14:36:19 +00003997static int __init mv88e6xxx_init(void)
3998{
Florian Fainelliab3d4082017-01-08 14:52:07 -08003999 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004000 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004001}
4002module_init(mv88e6xxx_init);
4003
4004static void __exit mv88e6xxx_cleanup(void)
4005{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004006 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004007 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004008}
4009module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004010
4011MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4012MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4013MODULE_LICENSE("GPL");