blob: 647d5d45c1d6cdf4603248b7b560eb9434de561c [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 Lunnc8c1b392015-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 Didelot68b8f602017-07-17 13:03:45 -0400813static int mv88e6xxx_energy_detect_read(struct mv88e6xxx_chip *chip, int port,
814 struct ethtool_eee *eee)
815{
816 int err;
817
818 if (!chip->info->ops->phy_energy_detect_read)
819 return -EOPNOTSUPP;
820
821 /* assign eee->eee_enabled and eee->tx_lpi_enabled */
822 err = chip->info->ops->phy_energy_detect_read(chip, port, eee);
823 if (err)
824 return err;
825
826 /* assign eee->eee_active */
827 return mv88e6xxx_port_status_eee(chip, port, eee);
828}
829
830static int mv88e6xxx_energy_detect_write(struct mv88e6xxx_chip *chip, int port,
831 struct ethtool_eee *eee)
832{
833 if (!chip->info->ops->phy_energy_detect_write)
834 return -EOPNOTSUPP;
835
836 return chip->info->ops->phy_energy_detect_write(chip, port, eee);
837}
838
Vivien Didelotf81ec902016-05-09 13:22:58 -0400839static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
840 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800841{
Vivien Didelot04bed142016-08-31 18:06:13 -0400842 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400843 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800844
Vivien Didelotfad09c72016-06-21 12:28:20 -0400845 mutex_lock(&chip->reg_lock);
Vivien Didelot68b8f602017-07-17 13:03:45 -0400846 err = mv88e6xxx_energy_detect_read(chip, port, e);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400847 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -0400848
849 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800850}
851
Vivien Didelotf81ec902016-05-09 13:22:58 -0400852static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
853 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800854{
Vivien Didelot04bed142016-08-31 18:06:13 -0400855 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400856 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800857
Vivien Didelotfad09c72016-06-21 12:28:20 -0400858 mutex_lock(&chip->reg_lock);
Vivien Didelot68b8f602017-07-17 13:03:45 -0400859 err = mv88e6xxx_energy_detect_write(chip, port, e);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400860 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200861
Vivien Didelot9c938292016-08-15 17:19:02 -0400862 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800863}
864
Vivien Didelote5887a22017-03-30 17:37:11 -0400865static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700866{
Vivien Didelote5887a22017-03-30 17:37:11 -0400867 struct dsa_switch *ds = NULL;
868 struct net_device *br;
869 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500870 int i;
871
Vivien Didelote5887a22017-03-30 17:37:11 -0400872 if (dev < DSA_MAX_SWITCHES)
873 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500874
Vivien Didelote5887a22017-03-30 17:37:11 -0400875 /* Prevent frames from unknown switch or port */
876 if (!ds || port >= ds->num_ports)
877 return 0;
878
879 /* Frames from DSA links and CPU ports can egress any local port */
880 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
881 return mv88e6xxx_port_mask(chip);
882
883 br = ds->ports[port].bridge_dev;
884 pvlan = 0;
885
886 /* Frames from user ports can egress any local DSA links and CPU ports,
887 * as well as any local member of their bridge group.
888 */
889 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
890 if (dsa_is_cpu_port(chip->ds, i) ||
891 dsa_is_dsa_port(chip->ds, i) ||
892 (br && chip->ds->ports[i].bridge_dev == br))
893 pvlan |= BIT(i);
894
895 return pvlan;
896}
897
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400898static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400899{
900 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500901
902 /* prevent frames from going back out of the port they came in on */
903 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700904
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100905 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700906}
907
Vivien Didelotf81ec902016-05-09 13:22:58 -0400908static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
909 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700910{
Vivien Didelot04bed142016-08-31 18:06:13 -0400911 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -0400912 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700913
Vivien Didelotfad09c72016-06-21 12:28:20 -0400914 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -0400915 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400916 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400917
918 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400919 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700920}
921
Vivien Didelot9e907d72017-07-17 13:03:43 -0400922static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
923{
924 if (chip->info->ops->pot_clear)
925 return chip->info->ops->pot_clear(chip);
926
927 return 0;
928}
929
Vivien Didelot51c901a2017-07-17 13:03:41 -0400930static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
931{
932 if (chip->info->ops->mgmt_rsvd2cpu)
933 return chip->info->ops->mgmt_rsvd2cpu(chip);
934
935 return 0;
936}
937
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500938static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
939{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500940 int err;
941
Vivien Didelotdaefc942017-03-11 16:12:54 -0500942 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
943 if (err)
944 return err;
945
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500946 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
947 if (err)
948 return err;
949
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500950 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
951}
952
Vivien Didelotcd8da8b2017-06-19 10:55:36 -0400953static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
954{
955 int port;
956 int err;
957
958 if (!chip->info->ops->irl_init_all)
959 return 0;
960
961 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
962 /* Disable ingress rate limiting by resetting all per port
963 * ingress rate limit resources to their initial state.
964 */
965 err = chip->info->ops->irl_init_all(chip, port);
966 if (err)
967 return err;
968 }
969
970 return 0;
971}
972
Vivien Didelot17a15942017-03-30 17:37:09 -0400973static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
974{
975 u16 pvlan = 0;
976
977 if (!mv88e6xxx_has_pvt(chip))
978 return -EOPNOTSUPP;
979
980 /* Skip the local source device, which uses in-chip port VLAN */
981 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -0400982 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -0400983
984 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
985}
986
Vivien Didelot81228992017-03-30 17:37:08 -0400987static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
988{
Vivien Didelot17a15942017-03-30 17:37:09 -0400989 int dev, port;
990 int err;
991
Vivien Didelot81228992017-03-30 17:37:08 -0400992 if (!mv88e6xxx_has_pvt(chip))
993 return 0;
994
995 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
996 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
997 */
Vivien Didelot17a15942017-03-30 17:37:09 -0400998 err = mv88e6xxx_g2_misc_4_bit_port(chip);
999 if (err)
1000 return err;
1001
1002 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1003 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1004 err = mv88e6xxx_pvt_map(chip, dev, port);
1005 if (err)
1006 return err;
1007 }
1008 }
1009
1010 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001011}
1012
Vivien Didelot749efcb2016-09-22 16:49:24 -04001013static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1014{
1015 struct mv88e6xxx_chip *chip = ds->priv;
1016 int err;
1017
1018 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001019 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001020 mutex_unlock(&chip->reg_lock);
1021
1022 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001023 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001024}
1025
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001026static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1027{
1028 if (!chip->info->max_vid)
1029 return 0;
1030
1031 return mv88e6xxx_g1_vtu_flush(chip);
1032}
1033
Vivien Didelotf1394b782017-05-01 14:05:22 -04001034static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1035 struct mv88e6xxx_vtu_entry *entry)
1036{
1037 if (!chip->info->ops->vtu_getnext)
1038 return -EOPNOTSUPP;
1039
1040 return chip->info->ops->vtu_getnext(chip, entry);
1041}
1042
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001043static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1044 struct mv88e6xxx_vtu_entry *entry)
1045{
1046 if (!chip->info->ops->vtu_loadpurge)
1047 return -EOPNOTSUPP;
1048
1049 return chip->info->ops->vtu_loadpurge(chip, entry);
1050}
1051
Vivien Didelotf81ec902016-05-09 13:22:58 -04001052static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1053 struct switchdev_obj_port_vlan *vlan,
Vivien Didelot438ff532017-05-17 15:46:05 -04001054 switchdev_obj_dump_cb_t *cb)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001055{
Vivien Didelot04bed142016-08-31 18:06:13 -04001056 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001057 struct mv88e6xxx_vtu_entry next = {
1058 .vid = chip->info->max_vid,
1059 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001060 u16 pvid;
1061 int err;
1062
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001063 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001064 return -EOPNOTSUPP;
1065
Vivien Didelotfad09c72016-06-21 12:28:20 -04001066 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001067
Vivien Didelot77064f32016-11-04 03:23:30 +01001068 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001069 if (err)
1070 goto unlock;
1071
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001072 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001073 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001074 if (err)
1075 break;
1076
1077 if (!next.valid)
1078 break;
1079
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001080 if (next.member[port] ==
1081 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001082 continue;
1083
1084 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001085 vlan->vid_begin = next.vid;
1086 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001087 vlan->flags = 0;
1088
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001089 if (next.member[port] ==
1090 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001091 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1092
1093 if (next.vid == pvid)
1094 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1095
1096 err = cb(&vlan->obj);
1097 if (err)
1098 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001099 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001100
1101unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001102 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001103
1104 return err;
1105}
1106
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001107static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001108{
1109 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001110 struct mv88e6xxx_vtu_entry vlan = {
1111 .vid = chip->info->max_vid,
1112 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001113 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001114
1115 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1116
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001117 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001118 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001119 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001120 if (err)
1121 return err;
1122
1123 set_bit(*fid, fid_bitmap);
1124 }
1125
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001126 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001127 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001128 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001129 if (err)
1130 return err;
1131
1132 if (!vlan.valid)
1133 break;
1134
1135 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001136 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001137
1138 /* The reset value 0x000 is used to indicate that multiple address
1139 * databases are not needed. Return the next positive available.
1140 */
1141 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001142 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001143 return -ENOSPC;
1144
1145 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001146 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001147}
1148
Vivien Didelot567aa592017-05-01 14:05:25 -04001149static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1150 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001151{
1152 int err;
1153
1154 if (!vid)
1155 return -EINVAL;
1156
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001157 entry->vid = vid - 1;
1158 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001159
Vivien Didelotf1394b782017-05-01 14:05:22 -04001160 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001161 if (err)
1162 return err;
1163
Vivien Didelot567aa592017-05-01 14:05:25 -04001164 if (entry->vid == vid && entry->valid)
1165 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001166
Vivien Didelot567aa592017-05-01 14:05:25 -04001167 if (new) {
1168 int i;
1169
1170 /* Initialize a fresh VLAN entry */
1171 memset(entry, 0, sizeof(*entry));
1172 entry->valid = true;
1173 entry->vid = vid;
1174
Vivien Didelot553a7682017-06-07 18:12:16 -04001175 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001176 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001177 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001178 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001179
1180 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001181 }
1182
Vivien Didelot567aa592017-05-01 14:05:25 -04001183 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1184 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001185}
1186
Vivien Didelotda9c3592016-02-12 12:09:40 -05001187static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1188 u16 vid_begin, u16 vid_end)
1189{
Vivien Didelot04bed142016-08-31 18:06:13 -04001190 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001191 struct mv88e6xxx_vtu_entry vlan = {
1192 .vid = vid_begin - 1,
1193 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001194 int i, err;
1195
1196 if (!vid_begin)
1197 return -EOPNOTSUPP;
1198
Vivien Didelotfad09c72016-06-21 12:28:20 -04001199 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001200
Vivien Didelotda9c3592016-02-12 12:09:40 -05001201 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001202 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001203 if (err)
1204 goto unlock;
1205
1206 if (!vlan.valid)
1207 break;
1208
1209 if (vlan.vid > vid_end)
1210 break;
1211
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001212 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001213 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1214 continue;
1215
Andrew Lunn66e28092016-12-11 21:07:19 +01001216 if (!ds->ports[port].netdev)
1217 continue;
1218
Vivien Didelotbd00e0532017-05-01 14:05:11 -04001219 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001220 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001221 continue;
1222
Vivien Didelotfae8a252017-01-27 15:29:42 -05001223 if (ds->ports[i].bridge_dev ==
1224 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001225 break; /* same bridge, check next VLAN */
1226
Vivien Didelotfae8a252017-01-27 15:29:42 -05001227 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001228 continue;
1229
Vivien Didelot774439e52017-06-08 18:34:08 -04001230 dev_err(ds->dev, "p%d: hw VLAN %d already used by %s\n",
1231 port, vlan.vid,
1232 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001233 err = -EOPNOTSUPP;
1234 goto unlock;
1235 }
1236 } while (vlan.vid < vid_end);
1237
1238unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001239 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001240
1241 return err;
1242}
1243
Vivien Didelotf81ec902016-05-09 13:22:58 -04001244static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1245 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001246{
Vivien Didelot04bed142016-08-31 18:06:13 -04001247 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001248 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1249 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001250 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001251
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001252 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001253 return -EOPNOTSUPP;
1254
Vivien Didelotfad09c72016-06-21 12:28:20 -04001255 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001256 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001257 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001258
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001259 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001260}
1261
Vivien Didelot57d32312016-06-20 13:13:58 -04001262static int
1263mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1264 const struct switchdev_obj_port_vlan *vlan,
1265 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001266{
Vivien Didelot04bed142016-08-31 18:06:13 -04001267 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001268 int err;
1269
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001270 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001271 return -EOPNOTSUPP;
1272
Vivien Didelotda9c3592016-02-12 12:09:40 -05001273 /* If the requested port doesn't belong to the same bridge as the VLAN
1274 * members, do not support it (yet) and fallback to software VLAN.
1275 */
1276 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1277 vlan->vid_end);
1278 if (err)
1279 return err;
1280
Vivien Didelot76e398a2015-11-01 12:33:55 -05001281 /* We don't need any dynamic resource from the kernel (yet),
1282 * so skip the prepare phase.
1283 */
1284 return 0;
1285}
1286
Vivien Didelotfad09c72016-06-21 12:28:20 -04001287static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001288 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001289{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001290 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001291 int err;
1292
Vivien Didelot567aa592017-05-01 14:05:25 -04001293 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001294 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001295 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001296
Vivien Didelotc91498e2017-06-07 18:12:13 -04001297 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001298
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001299 return mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001300}
1301
Vivien Didelotf81ec902016-05-09 13:22:58 -04001302static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1303 const struct switchdev_obj_port_vlan *vlan,
1304 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001305{
Vivien Didelot04bed142016-08-31 18:06:13 -04001306 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001307 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1308 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001309 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001310 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001311
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001312 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001313 return;
1314
Vivien Didelotc91498e2017-06-07 18:12:13 -04001315 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001316 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001317 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001318 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001319 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001320 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001321
Vivien Didelotfad09c72016-06-21 12:28:20 -04001322 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001323
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001324 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001325 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001326 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1327 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001328
Vivien Didelot77064f32016-11-04 03:23:30 +01001329 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001330 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1331 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001332
Vivien Didelotfad09c72016-06-21 12:28:20 -04001333 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001334}
1335
Vivien Didelotfad09c72016-06-21 12:28:20 -04001336static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001337 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001338{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001339 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001340 int i, err;
1341
Vivien Didelot567aa592017-05-01 14:05:25 -04001342 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001343 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001344 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001345
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001346 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001347 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001348 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001349
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001350 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001351
1352 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001353 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001354 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001355 if (vlan.member[i] !=
1356 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001357 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001358 break;
1359 }
1360 }
1361
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001362 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001363 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001364 return err;
1365
Vivien Didelote606ca32017-03-11 16:12:55 -05001366 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001367}
1368
Vivien Didelotf81ec902016-05-09 13:22:58 -04001369static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1370 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001371{
Vivien Didelot04bed142016-08-31 18:06:13 -04001372 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001373 u16 pvid, vid;
1374 int err = 0;
1375
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001376 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001377 return -EOPNOTSUPP;
1378
Vivien Didelotfad09c72016-06-21 12:28:20 -04001379 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001380
Vivien Didelot77064f32016-11-04 03:23:30 +01001381 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001382 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001383 goto unlock;
1384
Vivien Didelot76e398a2015-11-01 12:33:55 -05001385 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001386 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001387 if (err)
1388 goto unlock;
1389
1390 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001391 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001392 if (err)
1393 goto unlock;
1394 }
1395 }
1396
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001397unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001398 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001399
1400 return err;
1401}
1402
Vivien Didelot83dabd12016-08-31 11:50:04 -04001403static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1404 const unsigned char *addr, u16 vid,
1405 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001406{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001407 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001408 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001409 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001410
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001411 /* Null VLAN ID corresponds to the port private database */
1412 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001413 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001414 else
Vivien Didelot567aa592017-05-01 14:05:25 -04001415 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001416 if (err)
1417 return err;
1418
Vivien Didelot27c0e602017-06-15 12:14:01 -04001419 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001420 ether_addr_copy(entry.mac, addr);
1421 eth_addr_dec(entry.mac);
1422
1423 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001424 if (err)
1425 return err;
1426
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001427 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelot27c0e602017-06-15 12:14:01 -04001428 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001429 !ether_addr_equal(entry.mac, addr)) {
1430 memset(&entry, 0, sizeof(entry));
1431 ether_addr_copy(entry.mac, addr);
1432 }
1433
Vivien Didelot88472932016-09-19 19:56:11 -04001434 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelot27c0e602017-06-15 12:14:01 -04001435 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001436 entry.portvec &= ~BIT(port);
1437 if (!entry.portvec)
Vivien Didelot27c0e602017-06-15 12:14:01 -04001438 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelot88472932016-09-19 19:56:11 -04001439 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001440 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001441 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001442 }
1443
Vivien Didelot9c13c022017-03-11 16:12:52 -05001444 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001445}
1446
Vivien Didelotf81ec902016-05-09 13:22:58 -04001447static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1448 const struct switchdev_obj_port_fdb *fdb,
1449 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001450{
1451 /* We don't need any dynamic resource from the kernel (yet),
1452 * so skip the prepare phase.
1453 */
1454 return 0;
1455}
1456
Vivien Didelotf81ec902016-05-09 13:22:58 -04001457static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1458 const struct switchdev_obj_port_fdb *fdb,
1459 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001460{
Vivien Didelot04bed142016-08-31 18:06:13 -04001461 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001462
Vivien Didelotfad09c72016-06-21 12:28:20 -04001463 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001464 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001465 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04001466 dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
1467 port);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001468 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001469}
1470
Vivien Didelotf81ec902016-05-09 13:22:58 -04001471static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1472 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001473{
Vivien Didelot04bed142016-08-31 18:06:13 -04001474 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001475 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001476
Vivien Didelotfad09c72016-06-21 12:28:20 -04001477 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001478 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001479 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001480 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001481
Vivien Didelot83dabd12016-08-31 11:50:04 -04001482 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001483}
1484
Vivien Didelot83dabd12016-08-31 11:50:04 -04001485static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1486 u16 fid, u16 vid, int port,
1487 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001488 switchdev_obj_dump_cb_t *cb)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001489{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001490 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001491 int err;
1492
Vivien Didelot27c0e602017-06-15 12:14:01 -04001493 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001494 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001495
1496 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001497 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001498 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001499 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001500
Vivien Didelot27c0e602017-06-15 12:14:01 -04001501 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001502 break;
1503
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001504 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001505 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001506
Vivien Didelot83dabd12016-08-31 11:50:04 -04001507 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1508 struct switchdev_obj_port_fdb *fdb;
1509
1510 if (!is_unicast_ether_addr(addr.mac))
1511 continue;
1512
1513 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001514 fdb->vid = vid;
1515 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot27c0e602017-06-15 12:14:01 -04001516 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001517 fdb->ndm_state = NUD_NOARP;
1518 else
1519 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001520 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1521 struct switchdev_obj_port_mdb *mdb;
1522
1523 if (!is_multicast_ether_addr(addr.mac))
1524 continue;
1525
1526 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1527 mdb->vid = vid;
1528 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001529 } else {
1530 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001531 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001532
1533 err = cb(obj);
1534 if (err)
1535 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001536 } while (!is_broadcast_ether_addr(addr.mac));
1537
1538 return err;
1539}
1540
Vivien Didelot83dabd12016-08-31 11:50:04 -04001541static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1542 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001543 switchdev_obj_dump_cb_t *cb)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001544{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001545 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001546 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001547 };
1548 u16 fid;
1549 int err;
1550
1551 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001552 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001553 if (err)
1554 return err;
1555
1556 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1557 if (err)
1558 return err;
1559
1560 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001561 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001562 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001563 if (err)
1564 return err;
1565
1566 if (!vlan.valid)
1567 break;
1568
1569 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1570 obj, cb);
1571 if (err)
1572 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001573 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001574
1575 return err;
1576}
1577
Vivien Didelotf81ec902016-05-09 13:22:58 -04001578static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1579 struct switchdev_obj_port_fdb *fdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04001580 switchdev_obj_dump_cb_t *cb)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001581{
Vivien Didelot04bed142016-08-31 18:06:13 -04001582 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001583 int err;
1584
Vivien Didelotfad09c72016-06-21 12:28:20 -04001585 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001586 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001587 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001588
1589 return err;
1590}
1591
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001592static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1593 struct net_device *br)
1594{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001595 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001596 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001597 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001598 int err;
1599
1600 /* Remap the Port VLAN of each local bridge group member */
1601 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1602 if (chip->ds->ports[port].bridge_dev == br) {
1603 err = mv88e6xxx_port_vlan_map(chip, port);
1604 if (err)
1605 return err;
1606 }
1607 }
1608
Vivien Didelote96a6e02017-03-30 17:37:13 -04001609 if (!mv88e6xxx_has_pvt(chip))
1610 return 0;
1611
1612 /* Remap the Port VLAN of each cross-chip bridge group member */
1613 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1614 ds = chip->ds->dst->ds[dev];
1615 if (!ds)
1616 break;
1617
1618 for (port = 0; port < ds->num_ports; ++port) {
1619 if (ds->ports[port].bridge_dev == br) {
1620 err = mv88e6xxx_pvt_map(chip, dev, port);
1621 if (err)
1622 return err;
1623 }
1624 }
1625 }
1626
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001627 return 0;
1628}
1629
Vivien Didelotf81ec902016-05-09 13:22:58 -04001630static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001631 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001632{
Vivien Didelot04bed142016-08-31 18:06:13 -04001633 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001634 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001635
Vivien Didelotfad09c72016-06-21 12:28:20 -04001636 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001637 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001638 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001639
Vivien Didelot466dfa02016-02-26 13:16:05 -05001640 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001641}
1642
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001643static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1644 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001645{
Vivien Didelot04bed142016-08-31 18:06:13 -04001646 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001647
Vivien Didelotfad09c72016-06-21 12:28:20 -04001648 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001649 if (mv88e6xxx_bridge_map(chip, br) ||
1650 mv88e6xxx_port_vlan_map(chip, port))
1651 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001652 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001653}
1654
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001655static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1656 int port, struct net_device *br)
1657{
1658 struct mv88e6xxx_chip *chip = ds->priv;
1659 int err;
1660
1661 if (!mv88e6xxx_has_pvt(chip))
1662 return 0;
1663
1664 mutex_lock(&chip->reg_lock);
1665 err = mv88e6xxx_pvt_map(chip, dev, port);
1666 mutex_unlock(&chip->reg_lock);
1667
1668 return err;
1669}
1670
1671static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1672 int port, struct net_device *br)
1673{
1674 struct mv88e6xxx_chip *chip = ds->priv;
1675
1676 if (!mv88e6xxx_has_pvt(chip))
1677 return;
1678
1679 mutex_lock(&chip->reg_lock);
1680 if (mv88e6xxx_pvt_map(chip, dev, port))
1681 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1682 mutex_unlock(&chip->reg_lock);
1683}
1684
Vivien Didelot17e708b2016-12-05 17:30:27 -05001685static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1686{
1687 if (chip->info->ops->reset)
1688 return chip->info->ops->reset(chip);
1689
1690 return 0;
1691}
1692
Vivien Didelot309eca62016-12-05 17:30:26 -05001693static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1694{
1695 struct gpio_desc *gpiod = chip->reset;
1696
1697 /* If there is a GPIO connected to the reset pin, toggle it */
1698 if (gpiod) {
1699 gpiod_set_value_cansleep(gpiod, 1);
1700 usleep_range(10000, 20000);
1701 gpiod_set_value_cansleep(gpiod, 0);
1702 usleep_range(10000, 20000);
1703 }
1704}
1705
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001706static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1707{
1708 int i, err;
1709
1710 /* Set all ports to the Disabled state */
1711 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001712 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001713 if (err)
1714 return err;
1715 }
1716
1717 /* Wait for transmit queues to drain,
1718 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1719 */
1720 usleep_range(2000, 4000);
1721
1722 return 0;
1723}
1724
Vivien Didelotfad09c72016-06-21 12:28:20 -04001725static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001726{
Vivien Didelota935c052016-09-29 12:21:53 -04001727 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001728
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001729 err = mv88e6xxx_disable_ports(chip);
1730 if (err)
1731 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001732
Vivien Didelot309eca62016-12-05 17:30:26 -05001733 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001734
Vivien Didelot17e708b2016-12-05 17:30:27 -05001735 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001736}
1737
Vivien Didelot43145572017-03-11 16:12:59 -05001738static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001739 enum mv88e6xxx_frame_mode frame,
1740 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001741{
1742 int err;
1743
Vivien Didelot43145572017-03-11 16:12:59 -05001744 if (!chip->info->ops->port_set_frame_mode)
1745 return -EOPNOTSUPP;
1746
1747 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001748 if (err)
1749 return err;
1750
Vivien Didelot43145572017-03-11 16:12:59 -05001751 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1752 if (err)
1753 return err;
1754
1755 if (chip->info->ops->port_set_ether_type)
1756 return chip->info->ops->port_set_ether_type(chip, port, etype);
1757
1758 return 0;
1759}
1760
1761static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1762{
1763 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001764 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001765 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001766}
1767
1768static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1769{
1770 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001771 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001772 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001773}
1774
1775static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1776{
1777 return mv88e6xxx_set_port_mode(chip, port,
1778 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001779 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1780 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001781}
1782
1783static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1784{
1785 if (dsa_is_dsa_port(chip->ds, port))
1786 return mv88e6xxx_set_port_mode_dsa(chip, port);
1787
1788 if (dsa_is_normal_port(chip->ds, port))
1789 return mv88e6xxx_set_port_mode_normal(chip, port);
1790
1791 /* Setup CPU port mode depending on its supported tag format */
1792 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1793 return mv88e6xxx_set_port_mode_dsa(chip, port);
1794
1795 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1796 return mv88e6xxx_set_port_mode_edsa(chip, port);
1797
1798 return -EINVAL;
1799}
1800
Vivien Didelotea698f42017-03-11 16:12:50 -05001801static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1802{
1803 bool message = dsa_is_dsa_port(chip->ds, port);
1804
1805 return mv88e6xxx_port_set_message_port(chip, port, message);
1806}
1807
Vivien Didelot601aeed2017-03-11 16:13:00 -05001808static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1809{
1810 bool flood = port == dsa_upstream_port(chip->ds);
1811
1812 /* Upstream ports flood frames with unknown unicast or multicast DA */
1813 if (chip->info->ops->port_set_egress_floods)
1814 return chip->info->ops->port_set_egress_floods(chip, port,
1815 flood, flood);
1816
1817 return 0;
1818}
1819
Andrew Lunn6d917822017-05-26 01:03:21 +02001820static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1821 bool on)
1822{
Vivien Didelot523a8902017-05-26 18:02:42 -04001823 if (chip->info->ops->serdes_power)
1824 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001825
Vivien Didelot523a8902017-05-26 18:02:42 -04001826 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001827}
1828
Vivien Didelotfad09c72016-06-21 12:28:20 -04001829static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001830{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001831 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001832 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001833 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001834
Vivien Didelotd78343d2016-11-04 03:23:36 +01001835 /* MAC Forcing register: don't force link, speed, duplex or flow control
1836 * state to any particular values on physical ports, but force the CPU
1837 * port and all DSA ports to their maximum bandwidth and full duplex.
1838 */
1839 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1840 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1841 SPEED_MAX, DUPLEX_FULL,
1842 PHY_INTERFACE_MODE_NA);
1843 else
1844 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1845 SPEED_UNFORCED, DUPLEX_UNFORCED,
1846 PHY_INTERFACE_MODE_NA);
1847 if (err)
1848 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001849
1850 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1851 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1852 * tunneling, determine priority by looking at 802.1p and IP
1853 * priority fields (IP prio has precedence), and set STP state
1854 * to Forwarding.
1855 *
1856 * If this is the CPU link, use DSA or EDSA tagging depending
1857 * on which tagging mode was configured.
1858 *
1859 * If this is a link to another switch, use DSA tagging mode.
1860 *
1861 * If this is the upstream port for this switch, enable
1862 * forwarding of unknown unicasts and multicasts.
1863 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04001864 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
1865 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
1866 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1867 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001868 if (err)
1869 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001870
Vivien Didelot601aeed2017-03-11 16:13:00 -05001871 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001872 if (err)
1873 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001874
Vivien Didelot601aeed2017-03-11 16:13:00 -05001875 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001876 if (err)
1877 return err;
1878
Andrew Lunn04aca992017-05-26 01:03:24 +02001879 /* Enable the SERDES interface for DSA and CPU ports. Normal
1880 * ports SERDES are enabled when the port is enabled, thus
1881 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001882 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001883 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1884 err = mv88e6xxx_serdes_power(chip, port, true);
1885 if (err)
1886 return err;
1887 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001888
Vivien Didelot8efdda42015-08-13 12:52:23 -04001889 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001890 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001891 * untagged frames on this port, do a destination address lookup on all
1892 * received packets as usual, disable ARP mirroring and don't send a
1893 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001894 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001895 err = mv88e6xxx_port_set_map_da(chip, port);
1896 if (err)
1897 return err;
1898
Andrew Lunn54d792f2015-05-06 01:09:47 +02001899 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01001900 if (chip->info->ops->port_set_upstream_port) {
1901 err = chip->info->ops->port_set_upstream_port(
1902 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001903 if (err)
1904 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001905 }
1906
Andrew Lunna23b2962017-02-04 20:15:28 +01001907 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001908 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01001909 if (err)
1910 return err;
1911
Vivien Didelotcd782652017-06-08 18:34:13 -04001912 if (chip->info->ops->port_set_jumbo_size) {
1913 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01001914 if (err)
1915 return err;
1916 }
1917
Andrew Lunn54d792f2015-05-06 01:09:47 +02001918 /* Port Association Vector: when learning source addresses
1919 * of packets, add the address to the address database using
1920 * a port bitmap that has only the bit for this port set and
1921 * the other bits clear.
1922 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001923 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001924 /* Disable learning for CPU port */
1925 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001926 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001927
Vivien Didelot2a4614e2017-06-12 12:37:43 -04001928 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
1929 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001930 if (err)
1931 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001932
1933 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04001934 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
1935 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001936 if (err)
1937 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001938
Vivien Didelot08984322017-06-08 18:34:12 -04001939 if (chip->info->ops->port_pause_limit) {
1940 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001941 if (err)
1942 return err;
1943 }
1944
Vivien Didelotc8c94892017-03-11 16:13:01 -05001945 if (chip->info->ops->port_disable_learn_limit) {
1946 err = chip->info->ops->port_disable_learn_limit(chip, port);
1947 if (err)
1948 return err;
1949 }
1950
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001951 if (chip->info->ops->port_disable_pri_override) {
1952 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001953 if (err)
1954 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01001955 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02001956
Andrew Lunnef0a7312016-12-03 04:35:16 +01001957 if (chip->info->ops->port_tag_remap) {
1958 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001959 if (err)
1960 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001961 }
1962
Andrew Lunnef70b112016-12-03 04:45:18 +01001963 if (chip->info->ops->port_egress_rate_limiting) {
1964 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001965 if (err)
1966 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001967 }
1968
Vivien Didelotea698f42017-03-11 16:12:50 -05001969 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001970 if (err)
1971 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001972
Vivien Didelot207afda2016-04-14 14:42:09 -04001973 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001974 * database, and allow bidirectional communication between the
1975 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07001976 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001977 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001978 if (err)
1979 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001980
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001981 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001982 if (err)
1983 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001984
1985 /* Default VLAN ID and priority: don't set a default VLAN
1986 * ID, and set the default packet priority to zero.
1987 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04001988 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02001989}
1990
Andrew Lunn04aca992017-05-26 01:03:24 +02001991static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
1992 struct phy_device *phydev)
1993{
1994 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04001995 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02001996
1997 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001998 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02001999 mutex_unlock(&chip->reg_lock);
2000
2001 return err;
2002}
2003
2004static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2005 struct phy_device *phydev)
2006{
2007 struct mv88e6xxx_chip *chip = ds->priv;
2008
2009 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002010 if (mv88e6xxx_serdes_power(chip, port, false))
2011 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002012 mutex_unlock(&chip->reg_lock);
2013}
2014
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002015static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2016 unsigned int ageing_time)
2017{
Vivien Didelot04bed142016-08-31 18:06:13 -04002018 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002019 int err;
2020
2021 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002022 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002023 mutex_unlock(&chip->reg_lock);
2024
2025 return err;
2026}
2027
Vivien Didelot97299342016-07-18 20:45:30 -04002028static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002029{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002030 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002031 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002032 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002033
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002034 if (chip->info->ops->set_cpu_port) {
2035 err = chip->info->ops->set_cpu_port(chip, upstream_port);
Andrew Lunn33641992016-12-03 04:35:17 +01002036 if (err)
2037 return err;
2038 }
2039
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002040 if (chip->info->ops->set_egress_port) {
2041 err = chip->info->ops->set_egress_port(chip, upstream_port);
Andrew Lunn33641992016-12-03 04:35:17 +01002042 if (err)
2043 return err;
2044 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002045
Vivien Didelot50484ff2016-05-09 13:22:54 -04002046 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelotd77f4322017-06-15 12:14:03 -04002047 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2048 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
Vivien Didelota935c052016-09-29 12:21:53 -04002049 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002050 if (err)
2051 return err;
2052
Vivien Didelot08a01262016-05-09 13:22:50 -04002053 /* Configure the IP ToS mapping registers. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002054 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002055 if (err)
2056 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002057 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002058 if (err)
2059 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002060 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002061 if (err)
2062 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002063 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002064 if (err)
2065 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002066 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002067 if (err)
2068 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002069 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002070 if (err)
2071 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002072 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002073 if (err)
2074 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002075 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002076 if (err)
2077 return err;
2078
2079 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002080 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002081 if (err)
2082 return err;
2083
Andrew Lunnde2273872016-11-21 23:27:01 +01002084 /* Initialize the statistics unit */
2085 err = mv88e6xxx_stats_set_histogram(chip);
2086 if (err)
2087 return err;
2088
Vivien Didelot97299342016-07-18 20:45:30 -04002089 /* Clear the statistics counters for all ports */
Vivien Didelot57d1ef32017-06-15 12:14:05 -04002090 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_STATS_OP,
2091 MV88E6XXX_G1_STATS_OP_BUSY |
2092 MV88E6XXX_G1_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002093 if (err)
2094 return err;
2095
2096 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002097 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002098 if (err)
2099 return err;
2100
2101 return 0;
2102}
2103
Vivien Didelotf81ec902016-05-09 13:22:58 -04002104static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002105{
Vivien Didelot04bed142016-08-31 18:06:13 -04002106 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002107 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002108 int i;
2109
Vivien Didelotfad09c72016-06-21 12:28:20 -04002110 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002111 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002112
Vivien Didelotfad09c72016-06-21 12:28:20 -04002113 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002114
Vivien Didelot97299342016-07-18 20:45:30 -04002115 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002116 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002117 err = mv88e6xxx_setup_port(chip, i);
2118 if (err)
2119 goto unlock;
2120 }
2121
2122 /* Setup Switch Global 1 Registers */
2123 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002124 if (err)
2125 goto unlock;
2126
Vivien Didelot97299342016-07-18 20:45:30 -04002127 /* Setup Switch Global 2 Registers */
Vivien Didelot9069c132017-07-17 13:03:44 -04002128 if (chip->info->global2_addr) {
Vivien Didelot97299342016-07-18 20:45:30 -04002129 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002130 if (err)
2131 goto unlock;
2132 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002133
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002134 err = mv88e6xxx_irl_setup(chip);
2135 if (err)
2136 goto unlock;
2137
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002138 err = mv88e6xxx_phy_setup(chip);
2139 if (err)
2140 goto unlock;
2141
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002142 err = mv88e6xxx_vtu_setup(chip);
2143 if (err)
2144 goto unlock;
2145
Vivien Didelot81228992017-03-30 17:37:08 -04002146 err = mv88e6xxx_pvt_setup(chip);
2147 if (err)
2148 goto unlock;
2149
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002150 err = mv88e6xxx_atu_setup(chip);
2151 if (err)
2152 goto unlock;
2153
Vivien Didelot9e907d72017-07-17 13:03:43 -04002154 err = mv88e6xxx_pot_setup(chip);
2155 if (err)
2156 goto unlock;
2157
Vivien Didelot51c901a2017-07-17 13:03:41 -04002158 err = mv88e6xxx_rsvd2cpu_setup(chip);
2159 if (err)
2160 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002161
Vivien Didelot6b17e862015-08-13 12:52:18 -04002162unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002163 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002164
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002165 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002166}
2167
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002168static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2169{
Vivien Didelot04bed142016-08-31 18:06:13 -04002170 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002171 int err;
2172
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002173 if (!chip->info->ops->set_switch_mac)
2174 return -EOPNOTSUPP;
2175
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002176 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002177 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002178 mutex_unlock(&chip->reg_lock);
2179
2180 return err;
2181}
2182
Vivien Didelote57e5e72016-08-15 17:19:00 -04002183static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002184{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002185 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2186 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002187 u16 val;
2188 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002189
Andrew Lunnee26a222017-01-24 14:53:48 +01002190 if (!chip->info->ops->phy_read)
2191 return -EOPNOTSUPP;
2192
Vivien Didelotfad09c72016-06-21 12:28:20 -04002193 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002194 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002195 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002196
Andrew Lunnda9f3302017-02-01 03:40:05 +01002197 if (reg == MII_PHYSID2) {
2198 /* Some internal PHYS don't have a model number. Use
2199 * the mv88e6390 family model number instead.
2200 */
2201 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002202 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002203 }
2204
Vivien Didelote57e5e72016-08-15 17:19:00 -04002205 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002206}
2207
Vivien Didelote57e5e72016-08-15 17:19:00 -04002208static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002209{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002210 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2211 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002212 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002213
Andrew Lunnee26a222017-01-24 14:53:48 +01002214 if (!chip->info->ops->phy_write)
2215 return -EOPNOTSUPP;
2216
Vivien Didelotfad09c72016-06-21 12:28:20 -04002217 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002218 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002219 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002220
2221 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002222}
2223
Vivien Didelotfad09c72016-06-21 12:28:20 -04002224static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002225 struct device_node *np,
2226 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002227{
2228 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002229 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002230 struct mii_bus *bus;
2231 int err;
2232
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002233 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002234 if (!bus)
2235 return -ENOMEM;
2236
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002237 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002238 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002239 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002240 INIT_LIST_HEAD(&mdio_bus->list);
2241 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002242
Andrew Lunnb516d452016-06-04 21:17:06 +02002243 if (np) {
2244 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002245 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002246 } else {
2247 bus->name = "mv88e6xxx SMI";
2248 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2249 }
2250
2251 bus->read = mv88e6xxx_mdio_read;
2252 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002253 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002254
Andrew Lunna3c53be52017-01-24 14:53:50 +01002255 if (np)
2256 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002257 else
2258 err = mdiobus_register(bus);
2259 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002260 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002261 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002262 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002263
2264 if (external)
2265 list_add_tail(&mdio_bus->list, &chip->mdios);
2266 else
2267 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002268
2269 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002270}
2271
Andrew Lunna3c53be52017-01-24 14:53:50 +01002272static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2273 { .compatible = "marvell,mv88e6xxx-mdio-external",
2274 .data = (void *)true },
2275 { },
2276};
2277
2278static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2279 struct device_node *np)
2280{
2281 const struct of_device_id *match;
2282 struct device_node *child;
2283 int err;
2284
2285 /* Always register one mdio bus for the internal/default mdio
2286 * bus. This maybe represented in the device tree, but is
2287 * optional.
2288 */
2289 child = of_get_child_by_name(np, "mdio");
2290 err = mv88e6xxx_mdio_register(chip, child, false);
2291 if (err)
2292 return err;
2293
2294 /* Walk the device tree, and see if there are any other nodes
2295 * which say they are compatible with the external mdio
2296 * bus.
2297 */
2298 for_each_available_child_of_node(np, child) {
2299 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2300 if (match) {
2301 err = mv88e6xxx_mdio_register(chip, child, true);
2302 if (err)
2303 return err;
2304 }
2305 }
2306
2307 return 0;
2308}
2309
2310static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002311
2312{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002313 struct mv88e6xxx_mdio_bus *mdio_bus;
2314 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002315
Andrew Lunna3c53be52017-01-24 14:53:50 +01002316 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2317 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002318
Andrew Lunna3c53be52017-01-24 14:53:50 +01002319 mdiobus_unregister(bus);
2320 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002321}
2322
Vivien Didelot855b1932016-07-20 18:18:35 -04002323static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2324{
Vivien Didelot04bed142016-08-31 18:06:13 -04002325 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002326
2327 return chip->eeprom_len;
2328}
2329
Vivien Didelot855b1932016-07-20 18:18:35 -04002330static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2331 struct ethtool_eeprom *eeprom, u8 *data)
2332{
Vivien Didelot04bed142016-08-31 18:06:13 -04002333 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002334 int err;
2335
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002336 if (!chip->info->ops->get_eeprom)
2337 return -EOPNOTSUPP;
2338
Vivien Didelot855b1932016-07-20 18:18:35 -04002339 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002340 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002341 mutex_unlock(&chip->reg_lock);
2342
2343 if (err)
2344 return err;
2345
2346 eeprom->magic = 0xc3ec4951;
2347
2348 return 0;
2349}
2350
Vivien Didelot855b1932016-07-20 18:18:35 -04002351static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2352 struct ethtool_eeprom *eeprom, u8 *data)
2353{
Vivien Didelot04bed142016-08-31 18:06:13 -04002354 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002355 int err;
2356
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002357 if (!chip->info->ops->set_eeprom)
2358 return -EOPNOTSUPP;
2359
Vivien Didelot855b1932016-07-20 18:18:35 -04002360 if (eeprom->magic != 0xc3ec4951)
2361 return -EINVAL;
2362
2363 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002364 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002365 mutex_unlock(&chip->reg_lock);
2366
2367 return err;
2368}
2369
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002370static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002371 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002372 .irl_init_all = mv88e6352_g2_irl_init_all,
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 Lunnef0a7312016-12-03 04:35:16 +01002379 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002380 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002381 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002382 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002383 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002384 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002385 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002386 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002387 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002388 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2389 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002390 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002391 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2392 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002393 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002394 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002395 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002396 .ppu_enable = mv88e6185_g1_ppu_enable,
2397 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002398 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002399 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002400 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002401};
2402
2403static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002404 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002405 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002406 .phy_read = mv88e6185_phy_ppu_read,
2407 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002408 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002409 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002410 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002411 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002412 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002413 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002414 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002415 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2416 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002417 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002418 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002419 .ppu_enable = mv88e6185_g1_ppu_enable,
2420 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002421 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002422 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002423 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002424};
2425
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002426static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002427 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002428 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002429 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2430 .phy_read = mv88e6xxx_g2_smi_phy_read,
2431 .phy_write = mv88e6xxx_g2_smi_phy_write,
2432 .port_set_link = mv88e6xxx_port_set_link,
2433 .port_set_duplex = mv88e6xxx_port_set_duplex,
2434 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002435 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002436 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002437 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002438 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002439 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002440 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002441 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002442 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002443 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002444 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2445 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2446 .stats_get_strings = mv88e6095_stats_get_strings,
2447 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002448 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2449 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002450 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002451 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002452 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002453 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002454 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002455 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002456};
2457
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002458static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002459 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002460 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002461 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002462 .phy_read = mv88e6xxx_g2_smi_phy_read,
2463 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002464 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002465 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002466 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002467 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002468 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002469 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002470 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002471 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002472 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2473 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002474 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002475 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2476 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002477 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002478 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002479 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002480 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002481 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002482 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002483};
2484
2485static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002486 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002487 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002488 .phy_read = mv88e6185_phy_ppu_read,
2489 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002490 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002491 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002492 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002493 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002494 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002495 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002496 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002497 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002498 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002499 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002500 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002501 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002502 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2503 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002504 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002505 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2506 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002507 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002508 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002509 .ppu_enable = mv88e6185_g1_ppu_enable,
2510 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002511 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002512 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002513 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002514};
2515
Vivien Didelot990e27b2017-03-28 13:50:32 -04002516static const struct mv88e6xxx_ops mv88e6141_ops = {
2517 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002518 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002519 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2520 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2521 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2522 .phy_read = mv88e6xxx_g2_smi_phy_read,
2523 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002524 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
2525 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002526 .port_set_link = mv88e6xxx_port_set_link,
2527 .port_set_duplex = mv88e6xxx_port_set_duplex,
2528 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2529 .port_set_speed = mv88e6390_port_set_speed,
2530 .port_tag_remap = mv88e6095_port_tag_remap,
2531 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2532 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2533 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002534 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002535 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002536 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002537 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2538 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2539 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2540 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2541 .stats_get_strings = mv88e6320_stats_get_strings,
2542 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002543 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2544 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002545 .watchdog_ops = &mv88e6390_watchdog_ops,
2546 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002547 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002548 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002549 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002550 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002551};
2552
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002553static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002554 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002555 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002556 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002557 .phy_read = mv88e6xxx_g2_smi_phy_read,
2558 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002559 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002560 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002561 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002562 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002563 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002564 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002565 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002566 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002567 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002568 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002569 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002570 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002571 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002572 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2573 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002574 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002575 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2576 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002577 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002578 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002579 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002580 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002581 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002582 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002583};
2584
2585static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002586 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002587 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002588 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002589 .phy_read = mv88e6165_phy_read,
2590 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002591 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002592 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002593 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002594 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002595 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002596 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002597 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2598 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002599 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002600 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2601 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002602 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002603 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002604 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002605 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002606 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002607 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002608};
2609
2610static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002611 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002612 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002613 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002614 .phy_read = mv88e6xxx_g2_smi_phy_read,
2615 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002616 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002617 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002618 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002619 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002620 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002621 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002622 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002623 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002624 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002625 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002626 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002627 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002628 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002629 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002630 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2631 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002632 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002633 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2634 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002635 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002636 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002637 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002638 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002639 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002640 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002641};
2642
2643static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002644 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002645 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002646 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2647 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002648 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002649 .phy_read = mv88e6xxx_g2_smi_phy_read,
2650 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002651 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
2652 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002653 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002654 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002655 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002656 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002657 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002658 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002659 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002660 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002661 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002662 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002663 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002664 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002665 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002666 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002667 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2668 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002669 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002670 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2671 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002672 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002673 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002674 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002675 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002676 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002677 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002678 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002679};
2680
2681static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002682 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002683 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002684 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002685 .phy_read = mv88e6xxx_g2_smi_phy_read,
2686 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002687 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002688 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002689 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002690 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002691 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002692 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002693 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002694 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002695 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002696 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002697 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002698 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002699 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002700 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002701 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2702 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002703 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002704 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2705 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002706 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002707 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002708 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002709 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002710 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002711 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002712};
2713
2714static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002715 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002716 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002717 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2718 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002719 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002720 .phy_read = mv88e6xxx_g2_smi_phy_read,
2721 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002722 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
2723 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002724 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002725 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002726 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002727 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002728 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002729 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002730 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002731 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002732 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002733 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002734 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002735 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002736 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002737 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002738 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2739 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002740 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002741 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2742 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002743 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002744 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002745 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002746 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002747 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002748 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002749 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002750};
2751
2752static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002753 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002754 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002755 .phy_read = mv88e6185_phy_ppu_read,
2756 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002757 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002758 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002759 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002760 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002761 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002762 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002763 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002764 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002765 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2766 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002767 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002768 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2769 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002770 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002771 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002772 .ppu_enable = mv88e6185_g1_ppu_enable,
2773 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002774 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002775 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002776 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002777};
2778
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002779static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002780 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002781 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002782 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2783 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002784 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2785 .phy_read = mv88e6xxx_g2_smi_phy_read,
2786 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002787 .phy_energy_detect_read = mv88e6390_phy_energy_detect_read,
2788 .phy_energy_detect_write = mv88e6390_phy_energy_detect_write,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002789 .port_set_link = mv88e6xxx_port_set_link,
2790 .port_set_duplex = mv88e6xxx_port_set_duplex,
2791 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2792 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002793 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002794 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002795 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002796 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002797 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002798 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002799 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002800 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002801 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002802 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2803 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002804 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002805 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2806 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002807 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002808 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002809 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002810 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002811 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2812 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002813 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002814};
2815
2816static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002817 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002818 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002819 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2820 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002821 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2822 .phy_read = mv88e6xxx_g2_smi_phy_read,
2823 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002824 .phy_energy_detect_read = mv88e6390_phy_energy_detect_read,
2825 .phy_energy_detect_write = mv88e6390_phy_energy_detect_write,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002826 .port_set_link = mv88e6xxx_port_set_link,
2827 .port_set_duplex = mv88e6xxx_port_set_duplex,
2828 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2829 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002830 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002831 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002832 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002833 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002834 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002835 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002836 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002837 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002838 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002839 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2840 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002841 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002842 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2843 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002844 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002845 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002846 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002847 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002848 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2849 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002850 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002851};
2852
2853static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002854 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002855 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002856 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2857 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002858 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2859 .phy_read = mv88e6xxx_g2_smi_phy_read,
2860 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002861 .phy_energy_detect_read = mv88e6390_phy_energy_detect_read,
2862 .phy_energy_detect_write = mv88e6390_phy_energy_detect_write,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002863 .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,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002872 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002873 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002874 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002875 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002876 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2877 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002878 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002879 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2880 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002881 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002882 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002883 .pot_clear = mv88e6xxx_g2_pot_clear,
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 mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002891 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002892 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002893 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2894 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002895 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002896 .phy_read = mv88e6xxx_g2_smi_phy_read,
2897 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002898 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
2899 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002900 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002901 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002902 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002903 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002904 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002905 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002906 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002907 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002908 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002909 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002910 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002911 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002912 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002913 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002914 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2915 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002916 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002917 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2918 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002919 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002920 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002921 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002922 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002923 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002924 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002925 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002926};
2927
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002928static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002929 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002930 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002931 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2932 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002933 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2934 .phy_read = mv88e6xxx_g2_smi_phy_read,
2935 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002936 .phy_energy_detect_read = mv88e6390_phy_energy_detect_read,
2937 .phy_energy_detect_write = mv88e6390_phy_energy_detect_write,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002938 .port_set_link = mv88e6xxx_port_set_link,
2939 .port_set_duplex = mv88e6xxx_port_set_duplex,
2940 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2941 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002942 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002943 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002944 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002945 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002946 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002947 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002948 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002949 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002950 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002951 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002952 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2953 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002954 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002955 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2956 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002957 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002958 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002959 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002960 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002961 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2962 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002963 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002964};
2965
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002966static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002967 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002968 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002969 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2970 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002971 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002972 .phy_read = mv88e6xxx_g2_smi_phy_read,
2973 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04002974 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
2975 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002976 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002977 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002978 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002979 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002980 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002981 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002982 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002983 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002984 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002985 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002986 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002987 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002988 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002989 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2990 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002991 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002992 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2993 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002994 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002995 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002996 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002997 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002998 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002999};
3000
3001static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003002 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003003 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003004 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3005 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003006 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003007 .phy_read = mv88e6xxx_g2_smi_phy_read,
3008 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04003009 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
3010 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003011 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003012 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003013 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003014 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003015 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003016 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003017 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003018 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003019 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003020 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003021 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003022 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003023 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003024 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3025 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003026 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003027 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3028 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003029 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003030 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003031 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003032};
3033
Vivien Didelot16e329a2017-03-28 13:50:33 -04003034static const struct mv88e6xxx_ops mv88e6341_ops = {
3035 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003036 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003037 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3038 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3039 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3040 .phy_read = mv88e6xxx_g2_smi_phy_read,
3041 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04003042 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
3043 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003044 .port_set_link = mv88e6xxx_port_set_link,
3045 .port_set_duplex = mv88e6xxx_port_set_duplex,
3046 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3047 .port_set_speed = mv88e6390_port_set_speed,
3048 .port_tag_remap = mv88e6095_port_tag_remap,
3049 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3050 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3051 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003052 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003053 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003054 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003055 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3056 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3057 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3058 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3059 .stats_get_strings = mv88e6320_stats_get_strings,
3060 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003061 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3062 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003063 .watchdog_ops = &mv88e6390_watchdog_ops,
3064 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003065 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003066 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003067 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003068 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003069};
3070
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003071static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003072 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003073 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003074 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003075 .phy_read = mv88e6xxx_g2_smi_phy_read,
3076 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003077 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003078 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003079 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003080 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003081 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003082 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003083 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003084 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003085 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003086 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003087 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003088 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003089 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003090 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003091 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3092 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003093 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003094 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3095 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003096 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003097 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003098 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003099 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003100 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003101 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003102};
3103
3104static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003105 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003106 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003107 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003108 .phy_read = mv88e6xxx_g2_smi_phy_read,
3109 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003110 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003111 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003112 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003113 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003114 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003115 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003116 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003117 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003118 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003119 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003120 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003121 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003122 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003123 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003124 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3125 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003126 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003127 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3128 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003129 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003130 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003131 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003132 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003133 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003134 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003135};
3136
3137static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003138 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003139 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003140 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3141 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003142 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003143 .phy_read = mv88e6xxx_g2_smi_phy_read,
3144 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04003145 .phy_energy_detect_read = mv88e6352_phy_energy_detect_read,
3146 .phy_energy_detect_write = mv88e6352_phy_energy_detect_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003147 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003148 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003149 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003150 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003151 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003152 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003153 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003154 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003155 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003156 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003157 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003158 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003159 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003160 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003161 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3162 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003163 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003164 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3165 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003166 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003167 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003168 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003169 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003170 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003171 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003172 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003173};
3174
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003175static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003176 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003177 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003178 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3179 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003180 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3181 .phy_read = mv88e6xxx_g2_smi_phy_read,
3182 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04003183 .phy_energy_detect_read = mv88e6390_phy_energy_detect_read,
3184 .phy_energy_detect_write = mv88e6390_phy_energy_detect_write,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003185 .port_set_link = mv88e6xxx_port_set_link,
3186 .port_set_duplex = mv88e6xxx_port_set_duplex,
3187 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3188 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003189 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003190 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003191 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003192 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003193 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003194 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003195 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003196 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003197 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003198 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003199 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003200 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003201 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3202 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003203 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003204 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3205 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003206 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003207 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003208 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003209 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003210 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3211 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003212 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003213};
3214
3215static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003216 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003217 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003218 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3219 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003220 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3221 .phy_read = mv88e6xxx_g2_smi_phy_read,
3222 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot68b8f602017-07-17 13:03:45 -04003223 .phy_energy_detect_read = mv88e6390_phy_energy_detect_read,
3224 .phy_energy_detect_write = mv88e6390_phy_energy_detect_write,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003225 .port_set_link = mv88e6xxx_port_set_link,
3226 .port_set_duplex = mv88e6xxx_port_set_duplex,
3227 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3228 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003229 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003230 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003231 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003232 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003233 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003234 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003235 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003236 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003237 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003238 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003239 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003240 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003241 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3242 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003243 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003244 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3245 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003246 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003247 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003248 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003249 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003250 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3251 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003252 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003253};
3254
Vivien Didelotf81ec902016-05-09 13:22:58 -04003255static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3256 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003257 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003258 .family = MV88E6XXX_FAMILY_6097,
3259 .name = "Marvell 88E6085",
3260 .num_databases = 4096,
3261 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003262 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003263 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003264 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003265 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003266 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003267 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003268 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003269 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003270 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003271 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003272 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003273 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003274 },
3275
3276 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003277 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003278 .family = MV88E6XXX_FAMILY_6095,
3279 .name = "Marvell 88E6095/88E6095F",
3280 .num_databases = 256,
3281 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003282 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003283 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003284 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003285 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003286 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003287 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003288 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003289 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003290 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003291 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003292 },
3293
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003294 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003295 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003296 .family = MV88E6XXX_FAMILY_6097,
3297 .name = "Marvell 88E6097/88E6097F",
3298 .num_databases = 4096,
3299 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003300 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003301 .port_base_addr = 0x10,
3302 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003303 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003304 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003305 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003306 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003307 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003308 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003309 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003310 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003311 .ops = &mv88e6097_ops,
3312 },
3313
Vivien Didelotf81ec902016-05-09 13:22:58 -04003314 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003315 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003316 .family = MV88E6XXX_FAMILY_6165,
3317 .name = "Marvell 88E6123",
3318 .num_databases = 4096,
3319 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003320 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003321 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003322 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003323 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003324 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003325 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003326 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003327 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003328 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003329 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003330 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003331 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003332 },
3333
3334 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003335 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003336 .family = MV88E6XXX_FAMILY_6185,
3337 .name = "Marvell 88E6131",
3338 .num_databases = 256,
3339 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003340 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003341 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003342 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003343 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003344 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003345 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003346 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003347 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003348 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003349 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003350 },
3351
Vivien Didelot990e27b2017-03-28 13:50:32 -04003352 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003353 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003354 .family = MV88E6XXX_FAMILY_6341,
3355 .name = "Marvell 88E6341",
3356 .num_databases = 4096,
3357 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003358 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003359 .port_base_addr = 0x10,
3360 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003361 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003362 .age_time_coeff = 3750,
3363 .atu_move_port_mask = 0x1f,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003364 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003365 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003366 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003367 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003368 .ops = &mv88e6141_ops,
3369 },
3370
Vivien Didelotf81ec902016-05-09 13:22:58 -04003371 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003372 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003373 .family = MV88E6XXX_FAMILY_6165,
3374 .name = "Marvell 88E6161",
3375 .num_databases = 4096,
3376 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003377 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003378 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003379 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003380 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003381 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003382 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003383 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003384 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003385 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003386 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003387 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003388 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003389 },
3390
3391 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003392 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003393 .family = MV88E6XXX_FAMILY_6165,
3394 .name = "Marvell 88E6165",
3395 .num_databases = 4096,
3396 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003397 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003398 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003399 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003400 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003401 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003402 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003403 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003404 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003405 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003406 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003407 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003408 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003409 },
3410
3411 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003412 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003413 .family = MV88E6XXX_FAMILY_6351,
3414 .name = "Marvell 88E6171",
3415 .num_databases = 4096,
3416 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003417 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003418 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003419 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003420 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003421 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003422 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003423 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003424 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003425 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003426 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003427 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003428 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003429 },
3430
3431 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003432 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003433 .family = MV88E6XXX_FAMILY_6352,
3434 .name = "Marvell 88E6172",
3435 .num_databases = 4096,
3436 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003437 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003438 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003439 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003440 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003441 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003442 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003443 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003444 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003445 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003446 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003447 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003448 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003449 },
3450
3451 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003452 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003453 .family = MV88E6XXX_FAMILY_6351,
3454 .name = "Marvell 88E6175",
3455 .num_databases = 4096,
3456 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003457 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003458 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003459 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003460 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003461 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003462 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003463 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003464 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003465 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003466 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003467 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003468 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003469 },
3470
3471 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003472 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003473 .family = MV88E6XXX_FAMILY_6352,
3474 .name = "Marvell 88E6176",
3475 .num_databases = 4096,
3476 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003477 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003478 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003479 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003480 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003481 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003482 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003483 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003484 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003485 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003486 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003487 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003488 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003489 },
3490
3491 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003492 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003493 .family = MV88E6XXX_FAMILY_6185,
3494 .name = "Marvell 88E6185",
3495 .num_databases = 256,
3496 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003497 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003498 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003499 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003500 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003501 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003502 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003503 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003504 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003505 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003506 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003507 },
3508
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003509 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003510 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003511 .family = MV88E6XXX_FAMILY_6390,
3512 .name = "Marvell 88E6190",
3513 .num_databases = 4096,
3514 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003515 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003516 .port_base_addr = 0x0,
3517 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003518 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003519 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003520 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003521 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003522 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003523 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003524 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003525 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003526 .ops = &mv88e6190_ops,
3527 },
3528
3529 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003530 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003531 .family = MV88E6XXX_FAMILY_6390,
3532 .name = "Marvell 88E6190X",
3533 .num_databases = 4096,
3534 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003535 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003536 .port_base_addr = 0x0,
3537 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003538 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003539 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003540 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003541 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003542 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003543 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003544 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003545 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003546 .ops = &mv88e6190x_ops,
3547 },
3548
3549 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003550 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003551 .family = MV88E6XXX_FAMILY_6390,
3552 .name = "Marvell 88E6191",
3553 .num_databases = 4096,
3554 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003555 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003556 .port_base_addr = 0x0,
3557 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003558 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003559 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003560 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003561 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003562 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003563 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003564 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003565 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003566 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003567 },
3568
Vivien Didelotf81ec902016-05-09 13:22:58 -04003569 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003570 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003571 .family = MV88E6XXX_FAMILY_6352,
3572 .name = "Marvell 88E6240",
3573 .num_databases = 4096,
3574 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003575 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003576 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003577 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003578 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003579 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003580 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003581 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003582 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003583 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003584 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003585 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003586 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003587 },
3588
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003589 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003590 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003591 .family = MV88E6XXX_FAMILY_6390,
3592 .name = "Marvell 88E6290",
3593 .num_databases = 4096,
3594 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003595 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003596 .port_base_addr = 0x0,
3597 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003598 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003599 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003600 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003601 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003602 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003603 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003604 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003605 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003606 .ops = &mv88e6290_ops,
3607 },
3608
Vivien Didelotf81ec902016-05-09 13:22:58 -04003609 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003610 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003611 .family = MV88E6XXX_FAMILY_6320,
3612 .name = "Marvell 88E6320",
3613 .num_databases = 4096,
3614 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003615 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003616 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003617 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003618 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003619 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003620 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003621 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003622 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003623 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003624 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003625 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003626 },
3627
3628 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003629 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003630 .family = MV88E6XXX_FAMILY_6320,
3631 .name = "Marvell 88E6321",
3632 .num_databases = 4096,
3633 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003634 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003635 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003636 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003637 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003638 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003639 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003640 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003641 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003642 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003643 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003644 },
3645
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003646 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003647 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003648 .family = MV88E6XXX_FAMILY_6341,
3649 .name = "Marvell 88E6341",
3650 .num_databases = 4096,
3651 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003652 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003653 .port_base_addr = 0x10,
3654 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003655 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003656 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003657 .atu_move_port_mask = 0x1f,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003658 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003659 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003660 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003661 .tag_protocol = DSA_TAG_PROTO_EDSA,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003662 .ops = &mv88e6341_ops,
3663 },
3664
Vivien Didelotf81ec902016-05-09 13:22:58 -04003665 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003666 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003667 .family = MV88E6XXX_FAMILY_6351,
3668 .name = "Marvell 88E6350",
3669 .num_databases = 4096,
3670 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003671 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003672 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003673 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003674 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003675 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003676 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003677 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003678 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003679 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003680 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003681 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003682 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003683 },
3684
3685 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003686 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003687 .family = MV88E6XXX_FAMILY_6351,
3688 .name = "Marvell 88E6351",
3689 .num_databases = 4096,
3690 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003691 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003692 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003693 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003694 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003695 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003696 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003697 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003698 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003699 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003700 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003701 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003702 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003703 },
3704
3705 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003706 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003707 .family = MV88E6XXX_FAMILY_6352,
3708 .name = "Marvell 88E6352",
3709 .num_databases = 4096,
3710 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003711 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003712 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003713 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003714 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003715 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003716 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003717 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003718 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003719 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003720 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003721 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003722 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003723 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003724 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003725 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003726 .family = MV88E6XXX_FAMILY_6390,
3727 .name = "Marvell 88E6390",
3728 .num_databases = 4096,
3729 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003730 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003731 .port_base_addr = 0x0,
3732 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003733 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003734 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003735 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003736 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003737 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003738 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003739 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003740 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003741 .ops = &mv88e6390_ops,
3742 },
3743 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003744 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003745 .family = MV88E6XXX_FAMILY_6390,
3746 .name = "Marvell 88E6390X",
3747 .num_databases = 4096,
3748 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003749 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003750 .port_base_addr = 0x0,
3751 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003752 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003753 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003754 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003755 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003756 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003757 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003758 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003759 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003760 .ops = &mv88e6390x_ops,
3761 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003762};
3763
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003764static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003765{
Vivien Didelota439c062016-04-17 13:23:58 -04003766 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003767
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003768 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3769 if (mv88e6xxx_table[i].prod_num == prod_num)
3770 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003771
Vivien Didelotb9b37712015-10-30 19:39:48 -04003772 return NULL;
3773}
3774
Vivien Didelotfad09c72016-06-21 12:28:20 -04003775static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003776{
3777 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003778 unsigned int prod_num, rev;
3779 u16 id;
3780 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003781
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003782 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04003783 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003784 mutex_unlock(&chip->reg_lock);
3785 if (err)
3786 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003787
Vivien Didelot107fcc12017-06-12 12:37:36 -04003788 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
3789 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003790
3791 info = mv88e6xxx_lookup_info(prod_num);
3792 if (!info)
3793 return -ENODEV;
3794
Vivien Didelotcaac8542016-06-20 13:14:09 -04003795 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003796 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003797
Vivien Didelotca070c12016-09-02 14:45:34 -04003798 err = mv88e6xxx_g2_require(chip);
3799 if (err)
3800 return err;
3801
Vivien Didelotfad09c72016-06-21 12:28:20 -04003802 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3803 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003804
3805 return 0;
3806}
3807
Vivien Didelotfad09c72016-06-21 12:28:20 -04003808static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003809{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003810 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003811
Vivien Didelotfad09c72016-06-21 12:28:20 -04003812 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3813 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003814 return NULL;
3815
Vivien Didelotfad09c72016-06-21 12:28:20 -04003816 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003817
Vivien Didelotfad09c72016-06-21 12:28:20 -04003818 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003819 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003820
Vivien Didelotfad09c72016-06-21 12:28:20 -04003821 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003822}
3823
Vivien Didelotfad09c72016-06-21 12:28:20 -04003824static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003825 struct mii_bus *bus, int sw_addr)
3826{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003827 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003828 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003829 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003830 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003831 else
3832 return -EINVAL;
3833
Vivien Didelotfad09c72016-06-21 12:28:20 -04003834 chip->bus = bus;
3835 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003836
3837 return 0;
3838}
3839
Andrew Lunn7b314362016-08-22 16:01:01 +02003840static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3841{
Vivien Didelot04bed142016-08-31 18:06:13 -04003842 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003843
Andrew Lunn443d5a12016-12-03 04:35:18 +01003844 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003845}
3846
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003847static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3848 struct device *host_dev, int sw_addr,
3849 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003850{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003851 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003852 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003853 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003854
Vivien Didelota439c062016-04-17 13:23:58 -04003855 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003856 if (!bus)
3857 return NULL;
3858
Vivien Didelotfad09c72016-06-21 12:28:20 -04003859 chip = mv88e6xxx_alloc_chip(dsa_dev);
3860 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003861 return NULL;
3862
Vivien Didelotcaac8542016-06-20 13:14:09 -04003863 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003864 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003865
Vivien Didelotfad09c72016-06-21 12:28:20 -04003866 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003867 if (err)
3868 goto free;
3869
Vivien Didelotfad09c72016-06-21 12:28:20 -04003870 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003871 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003872 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003873
Andrew Lunndc30c352016-10-16 19:56:49 +02003874 mutex_lock(&chip->reg_lock);
3875 err = mv88e6xxx_switch_reset(chip);
3876 mutex_unlock(&chip->reg_lock);
3877 if (err)
3878 goto free;
3879
Vivien Didelote57e5e72016-08-15 17:19:00 -04003880 mv88e6xxx_phy_init(chip);
3881
Andrew Lunna3c53be52017-01-24 14:53:50 +01003882 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003883 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003884 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003885
Vivien Didelotfad09c72016-06-21 12:28:20 -04003886 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003887
Vivien Didelotfad09c72016-06-21 12:28:20 -04003888 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003889free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003890 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003891
3892 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003893}
3894
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003895static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3896 const struct switchdev_obj_port_mdb *mdb,
3897 struct switchdev_trans *trans)
3898{
3899 /* We don't need any dynamic resource from the kernel (yet),
3900 * so skip the prepare phase.
3901 */
3902
3903 return 0;
3904}
3905
3906static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3907 const struct switchdev_obj_port_mdb *mdb,
3908 struct switchdev_trans *trans)
3909{
Vivien Didelot04bed142016-08-31 18:06:13 -04003910 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003911
3912 mutex_lock(&chip->reg_lock);
3913 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003914 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04003915 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
3916 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003917 mutex_unlock(&chip->reg_lock);
3918}
3919
3920static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3921 const struct switchdev_obj_port_mdb *mdb)
3922{
Vivien Didelot04bed142016-08-31 18:06:13 -04003923 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003924 int err;
3925
3926 mutex_lock(&chip->reg_lock);
3927 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003928 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003929 mutex_unlock(&chip->reg_lock);
3930
3931 return err;
3932}
3933
3934static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3935 struct switchdev_obj_port_mdb *mdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04003936 switchdev_obj_dump_cb_t *cb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003937{
Vivien Didelot04bed142016-08-31 18:06:13 -04003938 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003939 int err;
3940
3941 mutex_lock(&chip->reg_lock);
3942 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3943 mutex_unlock(&chip->reg_lock);
3944
3945 return err;
3946}
3947
Florian Fainellia82f67a2017-01-08 14:52:08 -08003948static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003949 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02003950 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003951 .setup = mv88e6xxx_setup,
3952 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003953 .adjust_link = mv88e6xxx_adjust_link,
3954 .get_strings = mv88e6xxx_get_strings,
3955 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3956 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02003957 .port_enable = mv88e6xxx_port_enable,
3958 .port_disable = mv88e6xxx_port_disable,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003959 .set_eee = mv88e6xxx_set_eee,
3960 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003961 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003962 .get_eeprom = mv88e6xxx_get_eeprom,
3963 .set_eeprom = mv88e6xxx_set_eeprom,
3964 .get_regs_len = mv88e6xxx_get_regs_len,
3965 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003966 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003967 .port_bridge_join = mv88e6xxx_port_bridge_join,
3968 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3969 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04003970 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003971 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3972 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3973 .port_vlan_add = mv88e6xxx_port_vlan_add,
3974 .port_vlan_del = mv88e6xxx_port_vlan_del,
3975 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3976 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3977 .port_fdb_add = mv88e6xxx_port_fdb_add,
3978 .port_fdb_del = mv88e6xxx_port_fdb_del,
3979 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003980 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3981 .port_mdb_add = mv88e6xxx_port_mdb_add,
3982 .port_mdb_del = mv88e6xxx_port_mdb_del,
3983 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04003984 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
3985 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003986};
3987
Florian Fainelliab3d4082017-01-08 14:52:07 -08003988static struct dsa_switch_driver mv88e6xxx_switch_drv = {
3989 .ops = &mv88e6xxx_switch_ops,
3990};
3991
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003992static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003993{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003994 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003995 struct dsa_switch *ds;
3996
Vivien Didelot73b12042017-03-30 17:37:10 -04003997 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003998 if (!ds)
3999 return -ENOMEM;
4000
Vivien Didelotfad09c72016-06-21 12:28:20 -04004001 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004002 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004003 ds->ageing_time_min = chip->info->age_time_coeff;
4004 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004005
4006 dev_set_drvdata(dev, ds);
4007
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004008 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004009}
4010
Vivien Didelotfad09c72016-06-21 12:28:20 -04004011static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004012{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004013 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004014}
4015
Vivien Didelot57d32312016-06-20 13:13:58 -04004016static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004017{
4018 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004019 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004020 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004021 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004022 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004023 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004024
Vivien Didelotcaac8542016-06-20 13:14:09 -04004025 compat_info = of_device_get_match_data(dev);
4026 if (!compat_info)
4027 return -EINVAL;
4028
Vivien Didelotfad09c72016-06-21 12:28:20 -04004029 chip = mv88e6xxx_alloc_chip(dev);
4030 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004031 return -ENOMEM;
4032
Vivien Didelotfad09c72016-06-21 12:28:20 -04004033 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004034
Vivien Didelotfad09c72016-06-21 12:28:20 -04004035 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004036 if (err)
4037 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004038
Andrew Lunnb4308f02016-11-21 23:26:55 +01004039 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4040 if (IS_ERR(chip->reset))
4041 return PTR_ERR(chip->reset);
4042
Vivien Didelotfad09c72016-06-21 12:28:20 -04004043 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004044 if (err)
4045 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004046
Vivien Didelote57e5e72016-08-15 17:19:00 -04004047 mv88e6xxx_phy_init(chip);
4048
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004049 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004050 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004051 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004052
Andrew Lunndc30c352016-10-16 19:56:49 +02004053 mutex_lock(&chip->reg_lock);
4054 err = mv88e6xxx_switch_reset(chip);
4055 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004056 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004057 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004058
Andrew Lunndc30c352016-10-16 19:56:49 +02004059 chip->irq = of_irq_get(np, 0);
4060 if (chip->irq == -EPROBE_DEFER) {
4061 err = chip->irq;
4062 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004063 }
4064
Andrew Lunndc30c352016-10-16 19:56:49 +02004065 if (chip->irq > 0) {
4066 /* Has to be performed before the MDIO bus is created,
4067 * because the PHYs will link there interrupts to these
4068 * interrupt controllers
4069 */
4070 mutex_lock(&chip->reg_lock);
4071 err = mv88e6xxx_g1_irq_setup(chip);
4072 mutex_unlock(&chip->reg_lock);
4073
4074 if (err)
4075 goto out;
4076
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004077 if (chip->info->g2_irqs > 0) {
Andrew Lunndc30c352016-10-16 19:56:49 +02004078 err = mv88e6xxx_g2_irq_setup(chip);
4079 if (err)
4080 goto out_g1_irq;
4081 }
4082 }
4083
Andrew Lunna3c53be52017-01-24 14:53:50 +01004084 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004085 if (err)
4086 goto out_g2_irq;
4087
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004088 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004089 if (err)
4090 goto out_mdio;
4091
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004092 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004093
4094out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004095 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004096out_g2_irq:
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004097 if (chip->info->g2_irqs > 0 && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004098 mv88e6xxx_g2_irq_free(chip);
4099out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004100 if (chip->irq > 0) {
4101 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004102 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004103 mutex_unlock(&chip->reg_lock);
4104 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004105out:
4106 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004107}
4108
4109static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4110{
4111 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004112 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004113
Andrew Lunn930188c2016-08-22 16:01:03 +02004114 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004115 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004116 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004117
Andrew Lunn467126442016-11-20 20:14:15 +01004118 if (chip->irq > 0) {
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004119 if (chip->info->g2_irqs > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004120 mv88e6xxx_g2_irq_free(chip);
4121 mv88e6xxx_g1_irq_free(chip);
4122 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004123}
4124
4125static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004126 {
4127 .compatible = "marvell,mv88e6085",
4128 .data = &mv88e6xxx_table[MV88E6085],
4129 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004130 {
4131 .compatible = "marvell,mv88e6190",
4132 .data = &mv88e6xxx_table[MV88E6190],
4133 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004134 { /* sentinel */ },
4135};
4136
4137MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4138
4139static struct mdio_driver mv88e6xxx_driver = {
4140 .probe = mv88e6xxx_probe,
4141 .remove = mv88e6xxx_remove,
4142 .mdiodrv.driver = {
4143 .name = "mv88e6085",
4144 .of_match_table = mv88e6xxx_of_match,
4145 },
4146};
4147
Ben Hutchings98e67302011-11-25 14:36:19 +00004148static int __init mv88e6xxx_init(void)
4149{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004150 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004151 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004152}
4153module_init(mv88e6xxx_init);
4154
4155static void __exit mv88e6xxx_cleanup(void)
4156{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004157 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004158 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004159}
4160module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004161
4162MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4163MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4164MODULE_LICENSE("GPL");