blob: 51f2797ecb5228fa63bc3f23e6dad9dfa7b35934 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
7 *
Vivien Didelot4333d612017-03-28 15:10:36 -04008 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
9 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040035
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040036#include "chip.h"
Vivien Didelota935c052016-09-29 12:21:53 -040037#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040038#include "global2.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020039#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020041#include "serdes.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000042
Vivien Didelotfad09c72016-06-21 12:28:20 -040043static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040044{
Vivien Didelotfad09c72016-06-21 12:28:20 -040045 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
46 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040047 dump_stack();
48 }
49}
50
Vivien Didelot914b32f2016-06-20 13:14:11 -040051/* The switch ADDR[4:1] configuration pins define the chip SMI device address
52 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
53 *
54 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
55 * is the only device connected to the SMI master. In this mode it responds to
56 * all 32 possible SMI addresses, and thus maps directly the internal devices.
57 *
58 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
59 * multiple devices to share the SMI interface. In this mode it responds to only
60 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000061 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040062
Vivien Didelotfad09c72016-06-21 12:28:20 -040063static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040064 int addr, int reg, u16 *val)
65{
Vivien Didelotfad09c72016-06-21 12:28:20 -040066 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040067 return -EOPNOTSUPP;
68
Vivien Didelotfad09c72016-06-21 12:28:20 -040069 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040070}
71
Vivien Didelotfad09c72016-06-21 12:28:20 -040072static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040073 int addr, int reg, u16 val)
74{
Vivien Didelotfad09c72016-06-21 12:28:20 -040075 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040076 return -EOPNOTSUPP;
77
Vivien Didelotfad09c72016-06-21 12:28:20 -040078 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040079}
80
Vivien Didelotfad09c72016-06-21 12:28:20 -040081static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040082 int addr, int reg, u16 *val)
83{
84 int ret;
85
Vivien Didelotfad09c72016-06-21 12:28:20 -040086 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040087 if (ret < 0)
88 return ret;
89
90 *val = ret & 0xffff;
91
92 return 0;
93}
94
Vivien Didelotfad09c72016-06-21 12:28:20 -040095static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040096 int addr, int reg, u16 val)
97{
98 int ret;
99
Vivien Didelotfad09c72016-06-21 12:28:20 -0400100 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400101 if (ret < 0)
102 return ret;
103
104 return 0;
105}
106
Vivien Didelotc08026a2016-09-29 12:21:59 -0400107static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400108 .read = mv88e6xxx_smi_single_chip_read,
109 .write = mv88e6xxx_smi_single_chip_write,
110};
111
Vivien Didelotfad09c72016-06-21 12:28:20 -0400112static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000113{
114 int ret;
115 int i;
116
117 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400118 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000119 if (ret < 0)
120 return ret;
121
Andrew Lunncca8b132015-04-02 04:06:39 +0200122 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000123 return 0;
124 }
125
126 return -ETIMEDOUT;
127}
128
Vivien Didelotfad09c72016-06-21 12:28:20 -0400129static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400130 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000131{
132 int ret;
133
Barry Grussling3675c8d2013-01-08 16:05:53 +0000134 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400135 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000136 if (ret < 0)
137 return ret;
138
Barry Grussling3675c8d2013-01-08 16:05:53 +0000139 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400140 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200141 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000142 if (ret < 0)
143 return ret;
144
Barry Grussling3675c8d2013-01-08 16:05:53 +0000145 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400146 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000147 if (ret < 0)
148 return ret;
149
Barry Grussling3675c8d2013-01-08 16:05:53 +0000150 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400151 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000152 if (ret < 0)
153 return ret;
154
Vivien Didelot914b32f2016-06-20 13:14:11 -0400155 *val = ret & 0xffff;
156
157 return 0;
158}
159
Vivien Didelotfad09c72016-06-21 12:28:20 -0400160static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400161 int addr, int reg, u16 val)
162{
163 int ret;
164
165 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400166 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400167 if (ret < 0)
168 return ret;
169
170 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400171 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400172 if (ret < 0)
173 return ret;
174
175 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400176 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400177 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
178 if (ret < 0)
179 return ret;
180
181 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400182 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400183 if (ret < 0)
184 return ret;
185
186 return 0;
187}
188
Vivien Didelotc08026a2016-09-29 12:21:59 -0400189static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400190 .read = mv88e6xxx_smi_multi_chip_read,
191 .write = mv88e6xxx_smi_multi_chip_write,
192};
193
Vivien Didelotec561272016-09-02 14:45:33 -0400194int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400195{
196 int err;
197
Vivien Didelotfad09c72016-06-21 12:28:20 -0400198 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400199
Vivien Didelotfad09c72016-06-21 12:28:20 -0400200 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400201 if (err)
202 return err;
203
Vivien Didelotfad09c72016-06-21 12:28:20 -0400204 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400205 addr, reg, *val);
206
207 return 0;
208}
209
Vivien Didelotec561272016-09-02 14:45:33 -0400210int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400211{
212 int err;
213
Vivien Didelotfad09c72016-06-21 12:28:20 -0400214 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400215
Vivien Didelotfad09c72016-06-21 12:28:20 -0400216 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400217 if (err)
218 return err;
219
Vivien Didelotfad09c72016-06-21 12:28:20 -0400220 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400221 addr, reg, val);
222
223 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000224}
225
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200226struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100227{
228 struct mv88e6xxx_mdio_bus *mdio_bus;
229
230 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
231 list);
232 if (!mdio_bus)
233 return NULL;
234
235 return mdio_bus->bus;
236}
237
Andrew Lunndc30c352016-10-16 19:56:49 +0200238static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
239{
240 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
241 unsigned int n = d->hwirq;
242
243 chip->g1_irq.masked |= (1 << n);
244}
245
246static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
247{
248 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
249 unsigned int n = d->hwirq;
250
251 chip->g1_irq.masked &= ~(1 << n);
252}
253
254static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
255{
256 struct mv88e6xxx_chip *chip = dev_id;
257 unsigned int nhandled = 0;
258 unsigned int sub_irq;
259 unsigned int n;
260 u16 reg;
261 int err;
262
263 mutex_lock(&chip->reg_lock);
Vivien Didelot82466922017-06-15 12:13:59 -0400264 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200265 mutex_unlock(&chip->reg_lock);
266
267 if (err)
268 goto out;
269
270 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
271 if (reg & (1 << n)) {
272 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
273 handle_nested_irq(sub_irq);
274 ++nhandled;
275 }
276 }
277out:
278 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
279}
280
281static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
282{
283 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
284
285 mutex_lock(&chip->reg_lock);
286}
287
288static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
289{
290 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
291 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
292 u16 reg;
293 int err;
294
Vivien Didelotd77f4322017-06-15 12:14:03 -0400295 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200296 if (err)
297 goto out;
298
299 reg &= ~mask;
300 reg |= (~chip->g1_irq.masked & mask);
301
Vivien Didelotd77f4322017-06-15 12:14:03 -0400302 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200303 if (err)
304 goto out;
305
306out:
307 mutex_unlock(&chip->reg_lock);
308}
309
310static struct irq_chip mv88e6xxx_g1_irq_chip = {
311 .name = "mv88e6xxx-g1",
312 .irq_mask = mv88e6xxx_g1_irq_mask,
313 .irq_unmask = mv88e6xxx_g1_irq_unmask,
314 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
315 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
316};
317
318static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
319 unsigned int irq,
320 irq_hw_number_t hwirq)
321{
322 struct mv88e6xxx_chip *chip = d->host_data;
323
324 irq_set_chip_data(irq, d->host_data);
325 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
326 irq_set_noprobe(irq);
327
328 return 0;
329}
330
331static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
332 .map = mv88e6xxx_g1_irq_domain_map,
333 .xlate = irq_domain_xlate_twocell,
334};
335
336static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
337{
338 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100339 u16 mask;
340
Vivien Didelotd77f4322017-06-15 12:14:03 -0400341 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100342 mask |= GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400343 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100344
345 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200346
Andreas Färber5edef2f2016-11-27 23:26:28 +0100347 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100348 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200349 irq_dispose_mapping(virq);
350 }
351
Andrew Lunna3db3d32016-11-20 20:14:14 +0100352 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200353}
354
355static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
356{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100357 int err, irq, virq;
358 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200359
360 chip->g1_irq.nirqs = chip->info->g1_irqs;
361 chip->g1_irq.domain = irq_domain_add_simple(
362 NULL, chip->g1_irq.nirqs, 0,
363 &mv88e6xxx_g1_irq_domain_ops, chip);
364 if (!chip->g1_irq.domain)
365 return -ENOMEM;
366
367 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
368 irq_create_mapping(chip->g1_irq.domain, irq);
369
370 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
371 chip->g1_irq.masked = ~0;
372
Vivien Didelotd77f4322017-06-15 12:14:03 -0400373 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200374 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100375 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200376
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100377 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200378
Vivien Didelotd77f4322017-06-15 12:14:03 -0400379 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200380 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100381 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200382
383 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400384 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200385 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100386 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200387
388 err = request_threaded_irq(chip->irq, NULL,
389 mv88e6xxx_g1_irq_thread_fn,
390 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
391 dev_name(chip->dev), chip);
392 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100393 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200394
395 return 0;
396
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100397out_disable:
398 mask |= GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400399 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100400
401out_mapping:
402 for (irq = 0; irq < 16; irq++) {
403 virq = irq_find_mapping(chip->g1_irq.domain, irq);
404 irq_dispose_mapping(virq);
405 }
406
407 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200408
409 return err;
410}
411
Vivien Didelotec561272016-09-02 14:45:33 -0400412int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400413{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200414 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400415
Andrew Lunn6441e6692016-08-19 00:01:55 +0200416 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400417 u16 val;
418 int err;
419
420 err = mv88e6xxx_read(chip, addr, reg, &val);
421 if (err)
422 return err;
423
424 if (!(val & mask))
425 return 0;
426
427 usleep_range(1000, 2000);
428 }
429
Andrew Lunn30853552016-08-19 00:01:57 +0200430 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400431 return -ETIMEDOUT;
432}
433
Vivien Didelotf22ab642016-07-18 20:45:31 -0400434/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400435int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400436{
437 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200438 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400439
440 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200441 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
442 if (err)
443 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400444
445 /* Set the Update bit to trigger a write operation */
446 val = BIT(15) | update;
447
448 return mv88e6xxx_write(chip, addr, reg, val);
449}
450
Vivien Didelotd78343d2016-11-04 03:23:36 +0100451static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
452 int link, int speed, int duplex,
453 phy_interface_t mode)
454{
455 int err;
456
457 if (!chip->info->ops->port_set_link)
458 return 0;
459
460 /* Port's MAC control must not be changed unless the link is down */
461 err = chip->info->ops->port_set_link(chip, port, 0);
462 if (err)
463 return err;
464
465 if (chip->info->ops->port_set_speed) {
466 err = chip->info->ops->port_set_speed(chip, port, speed);
467 if (err && err != -EOPNOTSUPP)
468 goto restore_link;
469 }
470
471 if (chip->info->ops->port_set_duplex) {
472 err = chip->info->ops->port_set_duplex(chip, port, duplex);
473 if (err && err != -EOPNOTSUPP)
474 goto restore_link;
475 }
476
477 if (chip->info->ops->port_set_rgmii_delay) {
478 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
479 if (err && err != -EOPNOTSUPP)
480 goto restore_link;
481 }
482
Andrew Lunnf39908d2017-02-04 20:02:50 +0100483 if (chip->info->ops->port_set_cmode) {
484 err = chip->info->ops->port_set_cmode(chip, port, mode);
485 if (err && err != -EOPNOTSUPP)
486 goto restore_link;
487 }
488
Vivien Didelotd78343d2016-11-04 03:23:36 +0100489 err = 0;
490restore_link:
491 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400492 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100493
494 return err;
495}
496
Andrew Lunndea87022015-08-31 15:56:47 +0200497/* We expect the switch to perform auto negotiation if there is a real
498 * phy. However, in the case of a fixed link phy, we force the port
499 * settings from the fixed link settings.
500 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400501static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
502 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200503{
Vivien Didelot04bed142016-08-31 18:06:13 -0400504 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200505 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200506
507 if (!phy_is_pseudo_fixed_link(phydev))
508 return;
509
Vivien Didelotfad09c72016-06-21 12:28:20 -0400510 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100511 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
512 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400513 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100514
515 if (err && err != -EOPNOTSUPP)
Vivien Didelot774439e52017-06-08 18:34:08 -0400516 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
Andrew Lunndea87022015-08-31 15:56:47 +0200517}
518
Andrew Lunna605a0f2016-11-21 23:26:58 +0100519static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000520{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100521 if (!chip->info->ops->stats_snapshot)
522 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000523
Andrew Lunna605a0f2016-11-21 23:26:58 +0100524 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000525}
526
Andrew Lunne413e7e2015-04-02 04:06:38 +0200527static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100528 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
529 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
530 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
531 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
532 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
533 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
534 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
535 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
536 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
537 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
538 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
539 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
540 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
541 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
542 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
543 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
544 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
545 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
546 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
547 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
548 { "single", 4, 0x14, STATS_TYPE_BANK0, },
549 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
550 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
551 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
552 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
553 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
554 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
555 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
556 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
557 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
558 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
559 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
560 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
561 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
562 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
563 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
564 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
565 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
566 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
567 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
568 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
569 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
570 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
571 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
572 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
573 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
574 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
575 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
576 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
577 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
578 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
579 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
580 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
581 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
582 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
583 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
584 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
585 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
586 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200587};
588
Vivien Didelotfad09c72016-06-21 12:28:20 -0400589static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100590 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100591 int port, u16 bank1_select,
592 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200593{
Andrew Lunn80c46272015-06-20 18:42:30 +0200594 u32 low;
595 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100596 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200597 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200598 u64 value;
599
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100600 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100601 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200602 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
603 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200604 return UINT64_MAX;
605
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200606 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200607 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200608 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
609 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200610 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200611 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200612 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100613 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100614 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100615 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100616 /* fall through */
617 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100618 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100619 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200620 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100621 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500622 break;
623 default:
624 return UINT64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200625 }
626 value = (((u64)high) << 16) | low;
627 return value;
628}
629
Andrew Lunndfafe442016-11-21 23:27:02 +0100630static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
631 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100632{
633 struct mv88e6xxx_hw_stat *stat;
634 int i, j;
635
636 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
637 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100638 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100639 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
640 ETH_GSTRING_LEN);
641 j++;
642 }
643 }
644}
645
Andrew Lunndfafe442016-11-21 23:27:02 +0100646static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
647 uint8_t *data)
648{
649 mv88e6xxx_stats_get_strings(chip, data,
650 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
651}
652
653static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
654 uint8_t *data)
655{
656 mv88e6xxx_stats_get_strings(chip, data,
657 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
658}
659
660static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
661 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100662{
Vivien Didelot04bed142016-08-31 18:06:13 -0400663 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100664
665 if (chip->info->ops->stats_get_strings)
666 chip->info->ops->stats_get_strings(chip, data);
667}
668
669static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
670 int types)
671{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100672 struct mv88e6xxx_hw_stat *stat;
673 int i, j;
674
675 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
676 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100677 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100678 j++;
679 }
680 return j;
681}
682
Andrew Lunndfafe442016-11-21 23:27:02 +0100683static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
684{
685 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
686 STATS_TYPE_PORT);
687}
688
689static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
690{
691 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
692 STATS_TYPE_BANK1);
693}
694
695static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
696{
697 struct mv88e6xxx_chip *chip = ds->priv;
698
699 if (chip->info->ops->stats_get_sset_count)
700 return chip->info->ops->stats_get_sset_count(chip);
701
702 return 0;
703}
704
Andrew Lunn052f9472016-11-21 23:27:03 +0100705static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100706 uint64_t *data, int types,
707 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100708{
709 struct mv88e6xxx_hw_stat *stat;
710 int i, j;
711
712 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
713 stat = &mv88e6xxx_hw_stats[i];
714 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100715 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
716 bank1_select,
717 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100718 j++;
719 }
720 }
721}
722
723static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
724 uint64_t *data)
725{
726 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100727 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400728 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100729}
730
731static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
732 uint64_t *data)
733{
734 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100735 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400736 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
737 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100738}
739
740static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
741 uint64_t *data)
742{
743 return mv88e6xxx_stats_get_stats(chip, port, data,
744 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400745 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
746 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100747}
748
749static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
750 uint64_t *data)
751{
752 if (chip->info->ops->stats_get_stats)
753 chip->info->ops->stats_get_stats(chip, port, data);
754}
755
Vivien Didelotf81ec902016-05-09 13:22:58 -0400756static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
757 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000758{
Vivien Didelot04bed142016-08-31 18:06:13 -0400759 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000760 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000761
Vivien Didelotfad09c72016-06-21 12:28:20 -0400762 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000763
Andrew Lunna605a0f2016-11-21 23:26:58 +0100764 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000765 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400766 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000767 return;
768 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100769
770 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000771
Vivien Didelotfad09c72016-06-21 12:28:20 -0400772 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000773}
Ben Hutchings98e67302011-11-25 14:36:19 +0000774
Andrew Lunnde2273872016-11-21 23:27:01 +0100775static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
776{
777 if (chip->info->ops->stats_set_histogram)
778 return chip->info->ops->stats_set_histogram(chip);
779
780 return 0;
781}
782
Vivien Didelotf81ec902016-05-09 13:22:58 -0400783static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700784{
785 return 32 * sizeof(u16);
786}
787
Vivien Didelotf81ec902016-05-09 13:22:58 -0400788static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
789 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700790{
Vivien Didelot04bed142016-08-31 18:06:13 -0400791 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200792 int err;
793 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700794 u16 *p = _p;
795 int i;
796
797 regs->version = 0;
798
799 memset(p, 0xff, 32 * sizeof(u16));
800
Vivien Didelotfad09c72016-06-21 12:28:20 -0400801 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400802
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700803 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700804
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200805 err = mv88e6xxx_port_read(chip, port, i, &reg);
806 if (!err)
807 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700808 }
Vivien Didelot23062512016-05-09 13:22:45 -0400809
Vivien Didelotfad09c72016-06-21 12:28:20 -0400810 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700811}
812
Vivien Didelotf81ec902016-05-09 13:22:58 -0400813static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
814 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800815{
Vivien Didelot04bed142016-08-31 18:06:13 -0400816 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400817 u16 reg;
818 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800819
Vivien Didelotfad09c72016-06-21 12:28:20 -0400820 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400821 return -EOPNOTSUPP;
822
Vivien Didelotfad09c72016-06-21 12:28:20 -0400823 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200824
Vivien Didelot9c938292016-08-15 17:19:02 -0400825 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
826 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200827 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800828
829 e->eee_enabled = !!(reg & 0x0200);
830 e->tx_lpi_enabled = !!(reg & 0x0100);
831
Vivien Didelot5f83dc92017-06-12 12:37:33 -0400832 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -0400833 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200834 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800835
Vivien Didelot5f83dc92017-06-12 12:37:33 -0400836 e->eee_active = !!(reg & MV88E6352_PORT_STS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200837out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400838 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -0400839
840 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800841}
842
Vivien Didelotf81ec902016-05-09 13:22:58 -0400843static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
844 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800845{
Vivien Didelot04bed142016-08-31 18:06:13 -0400846 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400847 u16 reg;
848 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800849
Vivien Didelotfad09c72016-06-21 12:28:20 -0400850 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400851 return -EOPNOTSUPP;
852
Vivien Didelotfad09c72016-06-21 12:28:20 -0400853 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800854
Vivien Didelot9c938292016-08-15 17:19:02 -0400855 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
856 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200857 goto out;
858
Vivien Didelot9c938292016-08-15 17:19:02 -0400859 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +0200860 if (e->eee_enabled)
861 reg |= 0x0200;
862 if (e->tx_lpi_enabled)
863 reg |= 0x0100;
864
Vivien Didelot9c938292016-08-15 17:19:02 -0400865 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200866out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400867 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200868
Vivien Didelot9c938292016-08-15 17:19:02 -0400869 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800870}
871
Vivien Didelote5887a22017-03-30 17:37:11 -0400872static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700873{
Vivien Didelote5887a22017-03-30 17:37:11 -0400874 struct dsa_switch *ds = NULL;
875 struct net_device *br;
876 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500877 int i;
878
Vivien Didelote5887a22017-03-30 17:37:11 -0400879 if (dev < DSA_MAX_SWITCHES)
880 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500881
Vivien Didelote5887a22017-03-30 17:37:11 -0400882 /* Prevent frames from unknown switch or port */
883 if (!ds || port >= ds->num_ports)
884 return 0;
885
886 /* Frames from DSA links and CPU ports can egress any local port */
887 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
888 return mv88e6xxx_port_mask(chip);
889
890 br = ds->ports[port].bridge_dev;
891 pvlan = 0;
892
893 /* Frames from user ports can egress any local DSA links and CPU ports,
894 * as well as any local member of their bridge group.
895 */
896 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
897 if (dsa_is_cpu_port(chip->ds, i) ||
898 dsa_is_dsa_port(chip->ds, i) ||
899 (br && chip->ds->ports[i].bridge_dev == br))
900 pvlan |= BIT(i);
901
902 return pvlan;
903}
904
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400905static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400906{
907 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500908
909 /* prevent frames from going back out of the port they came in on */
910 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700911
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100912 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700913}
914
Vivien Didelotf81ec902016-05-09 13:22:58 -0400915static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
916 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700917{
Vivien Didelot04bed142016-08-31 18:06:13 -0400918 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -0400919 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700920
Vivien Didelotfad09c72016-06-21 12:28:20 -0400921 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -0400922 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400923 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400924
925 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400926 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700927}
928
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500929static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
930{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500931 int err;
932
Vivien Didelotdaefc942017-03-11 16:12:54 -0500933 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
934 if (err)
935 return err;
936
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500937 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
938 if (err)
939 return err;
940
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500941 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
942}
943
Vivien Didelotcd8da8b2017-06-19 10:55:36 -0400944static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
945{
946 int port;
947 int err;
948
949 if (!chip->info->ops->irl_init_all)
950 return 0;
951
952 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
953 /* Disable ingress rate limiting by resetting all per port
954 * ingress rate limit resources to their initial state.
955 */
956 err = chip->info->ops->irl_init_all(chip, port);
957 if (err)
958 return err;
959 }
960
961 return 0;
962}
963
Vivien Didelot17a15942017-03-30 17:37:09 -0400964static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
965{
966 u16 pvlan = 0;
967
968 if (!mv88e6xxx_has_pvt(chip))
969 return -EOPNOTSUPP;
970
971 /* Skip the local source device, which uses in-chip port VLAN */
972 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -0400973 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -0400974
975 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
976}
977
Vivien Didelot81228992017-03-30 17:37:08 -0400978static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
979{
Vivien Didelot17a15942017-03-30 17:37:09 -0400980 int dev, port;
981 int err;
982
Vivien Didelot81228992017-03-30 17:37:08 -0400983 if (!mv88e6xxx_has_pvt(chip))
984 return 0;
985
986 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
987 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
988 */
Vivien Didelot17a15942017-03-30 17:37:09 -0400989 err = mv88e6xxx_g2_misc_4_bit_port(chip);
990 if (err)
991 return err;
992
993 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
994 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
995 err = mv88e6xxx_pvt_map(chip, dev, port);
996 if (err)
997 return err;
998 }
999 }
1000
1001 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001002}
1003
Vivien Didelot749efcb2016-09-22 16:49:24 -04001004static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1005{
1006 struct mv88e6xxx_chip *chip = ds->priv;
1007 int err;
1008
1009 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001010 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001011 mutex_unlock(&chip->reg_lock);
1012
1013 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001014 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001015}
1016
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001017static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1018{
1019 if (!chip->info->max_vid)
1020 return 0;
1021
1022 return mv88e6xxx_g1_vtu_flush(chip);
1023}
1024
Vivien Didelotf1394b782017-05-01 14:05:22 -04001025static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1026 struct mv88e6xxx_vtu_entry *entry)
1027{
1028 if (!chip->info->ops->vtu_getnext)
1029 return -EOPNOTSUPP;
1030
1031 return chip->info->ops->vtu_getnext(chip, entry);
1032}
1033
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001034static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1035 struct mv88e6xxx_vtu_entry *entry)
1036{
1037 if (!chip->info->ops->vtu_loadpurge)
1038 return -EOPNOTSUPP;
1039
1040 return chip->info->ops->vtu_loadpurge(chip, entry);
1041}
1042
Vivien Didelotf81ec902016-05-09 13:22:58 -04001043static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1044 struct switchdev_obj_port_vlan *vlan,
Vivien Didelot438ff532017-05-17 15:46:05 -04001045 switchdev_obj_dump_cb_t *cb)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001046{
Vivien Didelot04bed142016-08-31 18:06:13 -04001047 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001048 struct mv88e6xxx_vtu_entry next = {
1049 .vid = chip->info->max_vid,
1050 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001051 u16 pvid;
1052 int err;
1053
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001054 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001055 return -EOPNOTSUPP;
1056
Vivien Didelotfad09c72016-06-21 12:28:20 -04001057 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001058
Vivien Didelot77064f32016-11-04 03:23:30 +01001059 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001060 if (err)
1061 goto unlock;
1062
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001063 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001064 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001065 if (err)
1066 break;
1067
1068 if (!next.valid)
1069 break;
1070
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001071 if (next.member[port] ==
1072 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001073 continue;
1074
1075 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001076 vlan->vid_begin = next.vid;
1077 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001078 vlan->flags = 0;
1079
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001080 if (next.member[port] ==
1081 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001082 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1083
1084 if (next.vid == pvid)
1085 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1086
1087 err = cb(&vlan->obj);
1088 if (err)
1089 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001090 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001091
1092unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001093 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001094
1095 return err;
1096}
1097
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001098static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001099{
1100 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001101 struct mv88e6xxx_vtu_entry vlan = {
1102 .vid = chip->info->max_vid,
1103 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001104 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001105
1106 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1107
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001108 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001109 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001110 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001111 if (err)
1112 return err;
1113
1114 set_bit(*fid, fid_bitmap);
1115 }
1116
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001117 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001118 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001119 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001120 if (err)
1121 return err;
1122
1123 if (!vlan.valid)
1124 break;
1125
1126 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001127 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001128
1129 /* The reset value 0x000 is used to indicate that multiple address
1130 * databases are not needed. Return the next positive available.
1131 */
1132 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001133 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001134 return -ENOSPC;
1135
1136 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001137 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001138}
1139
Vivien Didelot567aa592017-05-01 14:05:25 -04001140static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1141 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001142{
1143 int err;
1144
1145 if (!vid)
1146 return -EINVAL;
1147
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001148 entry->vid = vid - 1;
1149 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001150
Vivien Didelotf1394b782017-05-01 14:05:22 -04001151 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001152 if (err)
1153 return err;
1154
Vivien Didelot567aa592017-05-01 14:05:25 -04001155 if (entry->vid == vid && entry->valid)
1156 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001157
Vivien Didelot567aa592017-05-01 14:05:25 -04001158 if (new) {
1159 int i;
1160
1161 /* Initialize a fresh VLAN entry */
1162 memset(entry, 0, sizeof(*entry));
1163 entry->valid = true;
1164 entry->vid = vid;
1165
Vivien Didelot553a7682017-06-07 18:12:16 -04001166 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001167 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001168 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001169 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001170
1171 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001172 }
1173
Vivien Didelot567aa592017-05-01 14:05:25 -04001174 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1175 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001176}
1177
Vivien Didelotda9c3592016-02-12 12:09:40 -05001178static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1179 u16 vid_begin, u16 vid_end)
1180{
Vivien Didelot04bed142016-08-31 18:06:13 -04001181 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001182 struct mv88e6xxx_vtu_entry vlan = {
1183 .vid = vid_begin - 1,
1184 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001185 int i, err;
1186
1187 if (!vid_begin)
1188 return -EOPNOTSUPP;
1189
Vivien Didelotfad09c72016-06-21 12:28:20 -04001190 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001191
Vivien Didelotda9c3592016-02-12 12:09:40 -05001192 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001193 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001194 if (err)
1195 goto unlock;
1196
1197 if (!vlan.valid)
1198 break;
1199
1200 if (vlan.vid > vid_end)
1201 break;
1202
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001203 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001204 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1205 continue;
1206
Andrew Lunn66e28092016-12-11 21:07:19 +01001207 if (!ds->ports[port].netdev)
1208 continue;
1209
Vivien Didelotbd00e052017-05-01 14:05:11 -04001210 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001211 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001212 continue;
1213
Vivien Didelotfae8a252017-01-27 15:29:42 -05001214 if (ds->ports[i].bridge_dev ==
1215 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001216 break; /* same bridge, check next VLAN */
1217
Vivien Didelotfae8a252017-01-27 15:29:42 -05001218 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001219 continue;
1220
Vivien Didelot774439e52017-06-08 18:34:08 -04001221 dev_err(ds->dev, "p%d: hw VLAN %d already used by %s\n",
1222 port, vlan.vid,
1223 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001224 err = -EOPNOTSUPP;
1225 goto unlock;
1226 }
1227 } while (vlan.vid < vid_end);
1228
1229unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001230 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001231
1232 return err;
1233}
1234
Vivien Didelotf81ec902016-05-09 13:22:58 -04001235static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1236 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001237{
Vivien Didelot04bed142016-08-31 18:06:13 -04001238 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001239 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1240 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001241 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001242
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001243 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001244 return -EOPNOTSUPP;
1245
Vivien Didelotfad09c72016-06-21 12:28:20 -04001246 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001247 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001248 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001249
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001250 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001251}
1252
Vivien Didelot57d32312016-06-20 13:13:58 -04001253static int
1254mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1255 const struct switchdev_obj_port_vlan *vlan,
1256 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001257{
Vivien Didelot04bed142016-08-31 18:06:13 -04001258 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001259 int err;
1260
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001261 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001262 return -EOPNOTSUPP;
1263
Vivien Didelotda9c3592016-02-12 12:09:40 -05001264 /* If the requested port doesn't belong to the same bridge as the VLAN
1265 * members, do not support it (yet) and fallback to software VLAN.
1266 */
1267 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1268 vlan->vid_end);
1269 if (err)
1270 return err;
1271
Vivien Didelot76e398a2015-11-01 12:33:55 -05001272 /* We don't need any dynamic resource from the kernel (yet),
1273 * so skip the prepare phase.
1274 */
1275 return 0;
1276}
1277
Vivien Didelotfad09c72016-06-21 12:28:20 -04001278static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001279 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001280{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001281 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001282 int err;
1283
Vivien Didelot567aa592017-05-01 14:05:25 -04001284 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001285 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001286 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001287
Vivien Didelotc91498e2017-06-07 18:12:13 -04001288 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001289
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001290 return mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001291}
1292
Vivien Didelotf81ec902016-05-09 13:22:58 -04001293static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1294 const struct switchdev_obj_port_vlan *vlan,
1295 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001296{
Vivien Didelot04bed142016-08-31 18:06:13 -04001297 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001298 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1299 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001300 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001301 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001302
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001303 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001304 return;
1305
Vivien Didelotc91498e2017-06-07 18:12:13 -04001306 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001307 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001308 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001309 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001310 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001311 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001312
Vivien Didelotfad09c72016-06-21 12:28:20 -04001313 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001314
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001315 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001316 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001317 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1318 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001319
Vivien Didelot77064f32016-11-04 03:23:30 +01001320 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001321 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1322 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001323
Vivien Didelotfad09c72016-06-21 12:28:20 -04001324 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001325}
1326
Vivien Didelotfad09c72016-06-21 12:28:20 -04001327static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001328 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001329{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001330 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001331 int i, err;
1332
Vivien Didelot567aa592017-05-01 14:05:25 -04001333 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001334 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001335 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001336
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001337 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001338 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001339 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001340
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001341 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001342
1343 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001344 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001345 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001346 if (vlan.member[i] !=
1347 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001348 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001349 break;
1350 }
1351 }
1352
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001353 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001354 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001355 return err;
1356
Vivien Didelote606ca32017-03-11 16:12:55 -05001357 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001358}
1359
Vivien Didelotf81ec902016-05-09 13:22:58 -04001360static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1361 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001362{
Vivien Didelot04bed142016-08-31 18:06:13 -04001363 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001364 u16 pvid, vid;
1365 int err = 0;
1366
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001367 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001368 return -EOPNOTSUPP;
1369
Vivien Didelotfad09c72016-06-21 12:28:20 -04001370 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001371
Vivien Didelot77064f32016-11-04 03:23:30 +01001372 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001373 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001374 goto unlock;
1375
Vivien Didelot76e398a2015-11-01 12:33:55 -05001376 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001377 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001378 if (err)
1379 goto unlock;
1380
1381 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001382 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001383 if (err)
1384 goto unlock;
1385 }
1386 }
1387
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001388unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001389 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001390
1391 return err;
1392}
1393
Vivien Didelot83dabd12016-08-31 11:50:04 -04001394static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1395 const unsigned char *addr, u16 vid,
1396 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001397{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001398 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001399 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001400 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001401
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001402 /* Null VLAN ID corresponds to the port private database */
1403 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001404 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001405 else
Vivien Didelot567aa592017-05-01 14:05:25 -04001406 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001407 if (err)
1408 return err;
1409
Vivien Didelot27c0e602017-06-15 12:14:01 -04001410 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001411 ether_addr_copy(entry.mac, addr);
1412 eth_addr_dec(entry.mac);
1413
1414 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001415 if (err)
1416 return err;
1417
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001418 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelot27c0e602017-06-15 12:14:01 -04001419 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001420 !ether_addr_equal(entry.mac, addr)) {
1421 memset(&entry, 0, sizeof(entry));
1422 ether_addr_copy(entry.mac, addr);
1423 }
1424
Vivien Didelot88472932016-09-19 19:56:11 -04001425 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelot27c0e602017-06-15 12:14:01 -04001426 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001427 entry.portvec &= ~BIT(port);
1428 if (!entry.portvec)
Vivien Didelot27c0e602017-06-15 12:14:01 -04001429 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelot88472932016-09-19 19:56:11 -04001430 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001431 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001432 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001433 }
1434
Vivien Didelot9c13c022017-03-11 16:12:52 -05001435 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001436}
1437
Vivien Didelotf81ec902016-05-09 13:22:58 -04001438static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1439 const struct switchdev_obj_port_fdb *fdb,
1440 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001441{
1442 /* We don't need any dynamic resource from the kernel (yet),
1443 * so skip the prepare phase.
1444 */
1445 return 0;
1446}
1447
Vivien Didelotf81ec902016-05-09 13:22:58 -04001448static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1449 const struct switchdev_obj_port_fdb *fdb,
1450 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001451{
Vivien Didelot04bed142016-08-31 18:06:13 -04001452 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001453
Vivien Didelotfad09c72016-06-21 12:28:20 -04001454 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001455 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001456 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04001457 dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
1458 port);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001459 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001460}
1461
Vivien Didelotf81ec902016-05-09 13:22:58 -04001462static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1463 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001464{
Vivien Didelot04bed142016-08-31 18:06:13 -04001465 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001466 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001467
Vivien Didelotfad09c72016-06-21 12:28:20 -04001468 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001469 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001470 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001471 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001472
Vivien Didelot83dabd12016-08-31 11:50:04 -04001473 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001474}
1475
Vivien Didelot83dabd12016-08-31 11:50:04 -04001476static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1477 u16 fid, u16 vid, int port,
1478 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001479 switchdev_obj_dump_cb_t *cb)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001480{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001481 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001482 int err;
1483
Vivien Didelot27c0e602017-06-15 12:14:01 -04001484 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001485 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001486
1487 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001488 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001489 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001490 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001491
Vivien Didelot27c0e602017-06-15 12:14:01 -04001492 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001493 break;
1494
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001495 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001496 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001497
Vivien Didelot83dabd12016-08-31 11:50:04 -04001498 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1499 struct switchdev_obj_port_fdb *fdb;
1500
1501 if (!is_unicast_ether_addr(addr.mac))
1502 continue;
1503
1504 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001505 fdb->vid = vid;
1506 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot27c0e602017-06-15 12:14:01 -04001507 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001508 fdb->ndm_state = NUD_NOARP;
1509 else
1510 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001511 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1512 struct switchdev_obj_port_mdb *mdb;
1513
1514 if (!is_multicast_ether_addr(addr.mac))
1515 continue;
1516
1517 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1518 mdb->vid = vid;
1519 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001520 } else {
1521 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001522 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001523
1524 err = cb(obj);
1525 if (err)
1526 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001527 } while (!is_broadcast_ether_addr(addr.mac));
1528
1529 return err;
1530}
1531
Vivien Didelot83dabd12016-08-31 11:50:04 -04001532static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1533 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001534 switchdev_obj_dump_cb_t *cb)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001535{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001536 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001537 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001538 };
1539 u16 fid;
1540 int err;
1541
1542 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001543 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001544 if (err)
1545 return err;
1546
1547 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1548 if (err)
1549 return err;
1550
1551 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001552 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001553 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001554 if (err)
1555 return err;
1556
1557 if (!vlan.valid)
1558 break;
1559
1560 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1561 obj, cb);
1562 if (err)
1563 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001564 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001565
1566 return err;
1567}
1568
Vivien Didelotf81ec902016-05-09 13:22:58 -04001569static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1570 struct switchdev_obj_port_fdb *fdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04001571 switchdev_obj_dump_cb_t *cb)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001572{
Vivien Didelot04bed142016-08-31 18:06:13 -04001573 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001574 int err;
1575
Vivien Didelotfad09c72016-06-21 12:28:20 -04001576 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001577 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001578 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001579
1580 return err;
1581}
1582
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001583static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1584 struct net_device *br)
1585{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001586 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001587 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001588 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001589 int err;
1590
1591 /* Remap the Port VLAN of each local bridge group member */
1592 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1593 if (chip->ds->ports[port].bridge_dev == br) {
1594 err = mv88e6xxx_port_vlan_map(chip, port);
1595 if (err)
1596 return err;
1597 }
1598 }
1599
Vivien Didelote96a6e02017-03-30 17:37:13 -04001600 if (!mv88e6xxx_has_pvt(chip))
1601 return 0;
1602
1603 /* Remap the Port VLAN of each cross-chip bridge group member */
1604 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1605 ds = chip->ds->dst->ds[dev];
1606 if (!ds)
1607 break;
1608
1609 for (port = 0; port < ds->num_ports; ++port) {
1610 if (ds->ports[port].bridge_dev == br) {
1611 err = mv88e6xxx_pvt_map(chip, dev, port);
1612 if (err)
1613 return err;
1614 }
1615 }
1616 }
1617
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001618 return 0;
1619}
1620
Vivien Didelotf81ec902016-05-09 13:22:58 -04001621static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001622 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001623{
Vivien Didelot04bed142016-08-31 18:06:13 -04001624 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001625 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001626
Vivien Didelotfad09c72016-06-21 12:28:20 -04001627 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001628 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001629 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001630
Vivien Didelot466dfa02016-02-26 13:16:05 -05001631 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001632}
1633
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001634static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1635 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001636{
Vivien Didelot04bed142016-08-31 18:06:13 -04001637 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001638
Vivien Didelotfad09c72016-06-21 12:28:20 -04001639 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001640 if (mv88e6xxx_bridge_map(chip, br) ||
1641 mv88e6xxx_port_vlan_map(chip, port))
1642 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001643 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001644}
1645
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001646static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1647 int port, struct net_device *br)
1648{
1649 struct mv88e6xxx_chip *chip = ds->priv;
1650 int err;
1651
1652 if (!mv88e6xxx_has_pvt(chip))
1653 return 0;
1654
1655 mutex_lock(&chip->reg_lock);
1656 err = mv88e6xxx_pvt_map(chip, dev, port);
1657 mutex_unlock(&chip->reg_lock);
1658
1659 return err;
1660}
1661
1662static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1663 int port, struct net_device *br)
1664{
1665 struct mv88e6xxx_chip *chip = ds->priv;
1666
1667 if (!mv88e6xxx_has_pvt(chip))
1668 return;
1669
1670 mutex_lock(&chip->reg_lock);
1671 if (mv88e6xxx_pvt_map(chip, dev, port))
1672 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1673 mutex_unlock(&chip->reg_lock);
1674}
1675
Vivien Didelot17e708b2016-12-05 17:30:27 -05001676static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1677{
1678 if (chip->info->ops->reset)
1679 return chip->info->ops->reset(chip);
1680
1681 return 0;
1682}
1683
Vivien Didelot309eca62016-12-05 17:30:26 -05001684static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1685{
1686 struct gpio_desc *gpiod = chip->reset;
1687
1688 /* If there is a GPIO connected to the reset pin, toggle it */
1689 if (gpiod) {
1690 gpiod_set_value_cansleep(gpiod, 1);
1691 usleep_range(10000, 20000);
1692 gpiod_set_value_cansleep(gpiod, 0);
1693 usleep_range(10000, 20000);
1694 }
1695}
1696
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001697static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1698{
1699 int i, err;
1700
1701 /* Set all ports to the Disabled state */
1702 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001703 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001704 if (err)
1705 return err;
1706 }
1707
1708 /* Wait for transmit queues to drain,
1709 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1710 */
1711 usleep_range(2000, 4000);
1712
1713 return 0;
1714}
1715
Vivien Didelotfad09c72016-06-21 12:28:20 -04001716static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001717{
Vivien Didelota935c052016-09-29 12:21:53 -04001718 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001719
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001720 err = mv88e6xxx_disable_ports(chip);
1721 if (err)
1722 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001723
Vivien Didelot309eca62016-12-05 17:30:26 -05001724 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001725
Vivien Didelot17e708b2016-12-05 17:30:27 -05001726 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001727}
1728
Vivien Didelot43145572017-03-11 16:12:59 -05001729static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001730 enum mv88e6xxx_frame_mode frame,
1731 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001732{
1733 int err;
1734
Vivien Didelot43145572017-03-11 16:12:59 -05001735 if (!chip->info->ops->port_set_frame_mode)
1736 return -EOPNOTSUPP;
1737
1738 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001739 if (err)
1740 return err;
1741
Vivien Didelot43145572017-03-11 16:12:59 -05001742 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1743 if (err)
1744 return err;
1745
1746 if (chip->info->ops->port_set_ether_type)
1747 return chip->info->ops->port_set_ether_type(chip, port, etype);
1748
1749 return 0;
1750}
1751
1752static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1753{
1754 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001755 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001756 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001757}
1758
1759static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1760{
1761 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001762 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001763 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001764}
1765
1766static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1767{
1768 return mv88e6xxx_set_port_mode(chip, port,
1769 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001770 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1771 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001772}
1773
1774static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1775{
1776 if (dsa_is_dsa_port(chip->ds, port))
1777 return mv88e6xxx_set_port_mode_dsa(chip, port);
1778
1779 if (dsa_is_normal_port(chip->ds, port))
1780 return mv88e6xxx_set_port_mode_normal(chip, port);
1781
1782 /* Setup CPU port mode depending on its supported tag format */
1783 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1784 return mv88e6xxx_set_port_mode_dsa(chip, port);
1785
1786 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1787 return mv88e6xxx_set_port_mode_edsa(chip, port);
1788
1789 return -EINVAL;
1790}
1791
Vivien Didelotea698f42017-03-11 16:12:50 -05001792static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1793{
1794 bool message = dsa_is_dsa_port(chip->ds, port);
1795
1796 return mv88e6xxx_port_set_message_port(chip, port, message);
1797}
1798
Vivien Didelot601aeed2017-03-11 16:13:00 -05001799static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1800{
1801 bool flood = port == dsa_upstream_port(chip->ds);
1802
1803 /* Upstream ports flood frames with unknown unicast or multicast DA */
1804 if (chip->info->ops->port_set_egress_floods)
1805 return chip->info->ops->port_set_egress_floods(chip, port,
1806 flood, flood);
1807
1808 return 0;
1809}
1810
Andrew Lunn6d917822017-05-26 01:03:21 +02001811static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1812 bool on)
1813{
Vivien Didelot523a8902017-05-26 18:02:42 -04001814 if (chip->info->ops->serdes_power)
1815 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001816
Vivien Didelot523a8902017-05-26 18:02:42 -04001817 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001818}
1819
Vivien Didelotfad09c72016-06-21 12:28:20 -04001820static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001821{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001822 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001823 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001824 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001825
Vivien Didelotd78343d2016-11-04 03:23:36 +01001826 /* MAC Forcing register: don't force link, speed, duplex or flow control
1827 * state to any particular values on physical ports, but force the CPU
1828 * port and all DSA ports to their maximum bandwidth and full duplex.
1829 */
1830 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1831 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1832 SPEED_MAX, DUPLEX_FULL,
1833 PHY_INTERFACE_MODE_NA);
1834 else
1835 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1836 SPEED_UNFORCED, DUPLEX_UNFORCED,
1837 PHY_INTERFACE_MODE_NA);
1838 if (err)
1839 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001840
1841 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1842 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1843 * tunneling, determine priority by looking at 802.1p and IP
1844 * priority fields (IP prio has precedence), and set STP state
1845 * to Forwarding.
1846 *
1847 * If this is the CPU link, use DSA or EDSA tagging depending
1848 * on which tagging mode was configured.
1849 *
1850 * If this is a link to another switch, use DSA tagging mode.
1851 *
1852 * If this is the upstream port for this switch, enable
1853 * forwarding of unknown unicasts and multicasts.
1854 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04001855 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
1856 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
1857 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1858 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001859 if (err)
1860 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001861
Vivien Didelot601aeed2017-03-11 16:13:00 -05001862 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001863 if (err)
1864 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001865
Vivien Didelot601aeed2017-03-11 16:13:00 -05001866 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001867 if (err)
1868 return err;
1869
Andrew Lunn04aca992017-05-26 01:03:24 +02001870 /* Enable the SERDES interface for DSA and CPU ports. Normal
1871 * ports SERDES are enabled when the port is enabled, thus
1872 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001873 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001874 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1875 err = mv88e6xxx_serdes_power(chip, port, true);
1876 if (err)
1877 return err;
1878 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001879
Vivien Didelot8efdda42015-08-13 12:52:23 -04001880 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001881 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001882 * untagged frames on this port, do a destination address lookup on all
1883 * received packets as usual, disable ARP mirroring and don't send a
1884 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001885 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001886 err = mv88e6xxx_port_set_map_da(chip, port);
1887 if (err)
1888 return err;
1889
Andrew Lunn54d792f2015-05-06 01:09:47 +02001890 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01001891 if (chip->info->ops->port_set_upstream_port) {
1892 err = chip->info->ops->port_set_upstream_port(
1893 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001894 if (err)
1895 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001896 }
1897
Andrew Lunna23b2962017-02-04 20:15:28 +01001898 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001899 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01001900 if (err)
1901 return err;
1902
Vivien Didelotcd782652017-06-08 18:34:13 -04001903 if (chip->info->ops->port_set_jumbo_size) {
1904 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01001905 if (err)
1906 return err;
1907 }
1908
Andrew Lunn54d792f2015-05-06 01:09:47 +02001909 /* Port Association Vector: when learning source addresses
1910 * of packets, add the address to the address database using
1911 * a port bitmap that has only the bit for this port set and
1912 * the other bits clear.
1913 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001914 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001915 /* Disable learning for CPU port */
1916 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001917 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001918
Vivien Didelot2a4614e2017-06-12 12:37:43 -04001919 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
1920 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001921 if (err)
1922 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001923
1924 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04001925 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
1926 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001927 if (err)
1928 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001929
Vivien Didelot08984322017-06-08 18:34:12 -04001930 if (chip->info->ops->port_pause_limit) {
1931 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001932 if (err)
1933 return err;
1934 }
1935
Vivien Didelotc8c94892017-03-11 16:13:01 -05001936 if (chip->info->ops->port_disable_learn_limit) {
1937 err = chip->info->ops->port_disable_learn_limit(chip, port);
1938 if (err)
1939 return err;
1940 }
1941
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001942 if (chip->info->ops->port_disable_pri_override) {
1943 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001944 if (err)
1945 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01001946 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02001947
Andrew Lunnef0a7312016-12-03 04:35:16 +01001948 if (chip->info->ops->port_tag_remap) {
1949 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001950 if (err)
1951 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001952 }
1953
Andrew Lunnef70b112016-12-03 04:45:18 +01001954 if (chip->info->ops->port_egress_rate_limiting) {
1955 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001956 if (err)
1957 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001958 }
1959
Vivien Didelotea698f42017-03-11 16:12:50 -05001960 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001961 if (err)
1962 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001963
Vivien Didelot207afda2016-04-14 14:42:09 -04001964 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001965 * database, and allow bidirectional communication between the
1966 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07001967 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001968 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001969 if (err)
1970 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001971
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001972 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001973 if (err)
1974 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001975
1976 /* Default VLAN ID and priority: don't set a default VLAN
1977 * ID, and set the default packet priority to zero.
1978 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04001979 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02001980}
1981
Andrew Lunn04aca992017-05-26 01:03:24 +02001982static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
1983 struct phy_device *phydev)
1984{
1985 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04001986 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02001987
1988 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001989 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02001990 mutex_unlock(&chip->reg_lock);
1991
1992 return err;
1993}
1994
1995static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
1996 struct phy_device *phydev)
1997{
1998 struct mv88e6xxx_chip *chip = ds->priv;
1999
2000 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002001 if (mv88e6xxx_serdes_power(chip, port, false))
2002 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002003 mutex_unlock(&chip->reg_lock);
2004}
2005
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002006static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2007 unsigned int ageing_time)
2008{
Vivien Didelot04bed142016-08-31 18:06:13 -04002009 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002010 int err;
2011
2012 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002013 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002014 mutex_unlock(&chip->reg_lock);
2015
2016 return err;
2017}
2018
Vivien Didelot97299342016-07-18 20:45:30 -04002019static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002020{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002021 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002022 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002023 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002024
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002025 if (chip->info->ops->set_cpu_port) {
2026 err = chip->info->ops->set_cpu_port(chip, upstream_port);
Andrew Lunn33641992016-12-03 04:35:17 +01002027 if (err)
2028 return err;
2029 }
2030
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002031 if (chip->info->ops->set_egress_port) {
2032 err = chip->info->ops->set_egress_port(chip, upstream_port);
Andrew Lunn33641992016-12-03 04:35:17 +01002033 if (err)
2034 return err;
2035 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002036
Vivien Didelot50484ff2016-05-09 13:22:54 -04002037 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelotd77f4322017-06-15 12:14:03 -04002038 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2039 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
Vivien Didelota935c052016-09-29 12:21:53 -04002040 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002041 if (err)
2042 return err;
2043
Vivien Didelot08a01262016-05-09 13:22:50 -04002044 /* Configure the IP ToS mapping registers. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002045 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002046 if (err)
2047 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002048 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002049 if (err)
2050 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002051 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002052 if (err)
2053 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002054 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
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_4, 0xaaaa);
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_5, 0xaaaa);
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_6, 0xffff);
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_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002067 if (err)
2068 return err;
2069
2070 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002071 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002072 if (err)
2073 return err;
2074
Andrew Lunnde2273872016-11-21 23:27:01 +01002075 /* Initialize the statistics unit */
2076 err = mv88e6xxx_stats_set_histogram(chip);
2077 if (err)
2078 return err;
2079
Vivien Didelot97299342016-07-18 20:45:30 -04002080 /* Clear the statistics counters for all ports */
Vivien Didelot57d1ef32017-06-15 12:14:05 -04002081 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_STATS_OP,
2082 MV88E6XXX_G1_STATS_OP_BUSY |
2083 MV88E6XXX_G1_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002084 if (err)
2085 return err;
2086
2087 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002088 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002089 if (err)
2090 return err;
2091
2092 return 0;
2093}
2094
Vivien Didelotf81ec902016-05-09 13:22:58 -04002095static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002096{
Vivien Didelot04bed142016-08-31 18:06:13 -04002097 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002098 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002099 int i;
2100
Vivien Didelotfad09c72016-06-21 12:28:20 -04002101 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002102 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002103
Vivien Didelotfad09c72016-06-21 12:28:20 -04002104 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002105
Vivien Didelot97299342016-07-18 20:45:30 -04002106 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002107 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002108 err = mv88e6xxx_setup_port(chip, i);
2109 if (err)
2110 goto unlock;
2111 }
2112
2113 /* Setup Switch Global 1 Registers */
2114 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002115 if (err)
2116 goto unlock;
2117
Vivien Didelot97299342016-07-18 20:45:30 -04002118 /* Setup Switch Global 2 Registers */
2119 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2120 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002121 if (err)
2122 goto unlock;
2123 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002124
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002125 err = mv88e6xxx_irl_setup(chip);
2126 if (err)
2127 goto unlock;
2128
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002129 err = mv88e6xxx_phy_setup(chip);
2130 if (err)
2131 goto unlock;
2132
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002133 err = mv88e6xxx_vtu_setup(chip);
2134 if (err)
2135 goto unlock;
2136
Vivien Didelot81228992017-03-30 17:37:08 -04002137 err = mv88e6xxx_pvt_setup(chip);
2138 if (err)
2139 goto unlock;
2140
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002141 err = mv88e6xxx_atu_setup(chip);
2142 if (err)
2143 goto unlock;
2144
Andrew Lunn6e55f692016-12-03 04:45:16 +01002145 /* Some generations have the configuration of sending reserved
2146 * management frames to the CPU in global2, others in
2147 * global1. Hence it does not fit the two setup functions
2148 * above.
2149 */
2150 if (chip->info->ops->mgmt_rsvd2cpu) {
2151 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2152 if (err)
2153 goto unlock;
2154 }
2155
Vivien Didelot6b17e862015-08-13 12:52:18 -04002156unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002157 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002158
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002159 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002160}
2161
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002162static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2163{
Vivien Didelot04bed142016-08-31 18:06:13 -04002164 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002165 int err;
2166
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002167 if (!chip->info->ops->set_switch_mac)
2168 return -EOPNOTSUPP;
2169
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002170 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002171 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002172 mutex_unlock(&chip->reg_lock);
2173
2174 return err;
2175}
2176
Vivien Didelote57e5e72016-08-15 17:19:00 -04002177static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002178{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002179 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2180 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002181 u16 val;
2182 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002183
Andrew Lunnee26a222017-01-24 14:53:48 +01002184 if (!chip->info->ops->phy_read)
2185 return -EOPNOTSUPP;
2186
Vivien Didelotfad09c72016-06-21 12:28:20 -04002187 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002188 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002189 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002190
Andrew Lunnda9f3302017-02-01 03:40:05 +01002191 if (reg == MII_PHYSID2) {
2192 /* Some internal PHYS don't have a model number. Use
2193 * the mv88e6390 family model number instead.
2194 */
2195 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002196 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002197 }
2198
Vivien Didelote57e5e72016-08-15 17:19:00 -04002199 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002200}
2201
Vivien Didelote57e5e72016-08-15 17:19:00 -04002202static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002203{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002204 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2205 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002206 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002207
Andrew Lunnee26a222017-01-24 14:53:48 +01002208 if (!chip->info->ops->phy_write)
2209 return -EOPNOTSUPP;
2210
Vivien Didelotfad09c72016-06-21 12:28:20 -04002211 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002212 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002213 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002214
2215 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002216}
2217
Vivien Didelotfad09c72016-06-21 12:28:20 -04002218static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002219 struct device_node *np,
2220 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002221{
2222 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002223 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002224 struct mii_bus *bus;
2225 int err;
2226
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002227 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002228 if (!bus)
2229 return -ENOMEM;
2230
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002231 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002232 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002233 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002234 INIT_LIST_HEAD(&mdio_bus->list);
2235 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002236
Andrew Lunnb516d452016-06-04 21:17:06 +02002237 if (np) {
2238 bus->name = np->full_name;
2239 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2240 } else {
2241 bus->name = "mv88e6xxx SMI";
2242 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2243 }
2244
2245 bus->read = mv88e6xxx_mdio_read;
2246 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002247 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002248
Andrew Lunna3c53be52017-01-24 14:53:50 +01002249 if (np)
2250 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002251 else
2252 err = mdiobus_register(bus);
2253 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002254 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002255 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002256 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002257
2258 if (external)
2259 list_add_tail(&mdio_bus->list, &chip->mdios);
2260 else
2261 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002262
2263 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002264}
2265
Andrew Lunna3c53be52017-01-24 14:53:50 +01002266static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2267 { .compatible = "marvell,mv88e6xxx-mdio-external",
2268 .data = (void *)true },
2269 { },
2270};
2271
2272static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2273 struct device_node *np)
2274{
2275 const struct of_device_id *match;
2276 struct device_node *child;
2277 int err;
2278
2279 /* Always register one mdio bus for the internal/default mdio
2280 * bus. This maybe represented in the device tree, but is
2281 * optional.
2282 */
2283 child = of_get_child_by_name(np, "mdio");
2284 err = mv88e6xxx_mdio_register(chip, child, false);
2285 if (err)
2286 return err;
2287
2288 /* Walk the device tree, and see if there are any other nodes
2289 * which say they are compatible with the external mdio
2290 * bus.
2291 */
2292 for_each_available_child_of_node(np, child) {
2293 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2294 if (match) {
2295 err = mv88e6xxx_mdio_register(chip, child, true);
2296 if (err)
2297 return err;
2298 }
2299 }
2300
2301 return 0;
2302}
2303
2304static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002305
2306{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002307 struct mv88e6xxx_mdio_bus *mdio_bus;
2308 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002309
Andrew Lunna3c53be52017-01-24 14:53:50 +01002310 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2311 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002312
Andrew Lunna3c53be52017-01-24 14:53:50 +01002313 mdiobus_unregister(bus);
2314 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002315}
2316
Vivien Didelot855b1932016-07-20 18:18:35 -04002317static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2318{
Vivien Didelot04bed142016-08-31 18:06:13 -04002319 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002320
2321 return chip->eeprom_len;
2322}
2323
Vivien Didelot855b1932016-07-20 18:18:35 -04002324static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2325 struct ethtool_eeprom *eeprom, u8 *data)
2326{
Vivien Didelot04bed142016-08-31 18:06:13 -04002327 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002328 int err;
2329
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002330 if (!chip->info->ops->get_eeprom)
2331 return -EOPNOTSUPP;
2332
Vivien Didelot855b1932016-07-20 18:18:35 -04002333 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002334 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002335 mutex_unlock(&chip->reg_lock);
2336
2337 if (err)
2338 return err;
2339
2340 eeprom->magic = 0xc3ec4951;
2341
2342 return 0;
2343}
2344
Vivien Didelot855b1932016-07-20 18:18:35 -04002345static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2346 struct ethtool_eeprom *eeprom, u8 *data)
2347{
Vivien Didelot04bed142016-08-31 18:06:13 -04002348 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002349 int err;
2350
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002351 if (!chip->info->ops->set_eeprom)
2352 return -EOPNOTSUPP;
2353
Vivien Didelot855b1932016-07-20 18:18:35 -04002354 if (eeprom->magic != 0xc3ec4951)
2355 return -EINVAL;
2356
2357 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002358 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002359 mutex_unlock(&chip->reg_lock);
2360
2361 return err;
2362}
2363
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002364static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002365 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002366 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002367 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002368 .phy_read = mv88e6185_phy_ppu_read,
2369 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002370 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002371 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002372 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002373 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002374 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002375 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002376 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002377 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002378 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002379 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002380 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002381 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002382 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2383 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002384 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002385 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2386 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002387 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002388 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002389 .ppu_enable = mv88e6185_g1_ppu_enable,
2390 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002391 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002392 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002393 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002394};
2395
2396static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002397 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002398 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002399 .phy_read = mv88e6185_phy_ppu_read,
2400 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002401 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002402 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002403 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002404 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002405 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002406 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002407 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002408 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2409 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002410 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002411 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002412 .ppu_enable = mv88e6185_g1_ppu_enable,
2413 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002414 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002415 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002416 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002417};
2418
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002419static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002420 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002421 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002422 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2423 .phy_read = mv88e6xxx_g2_smi_phy_read,
2424 .phy_write = mv88e6xxx_g2_smi_phy_write,
2425 .port_set_link = mv88e6xxx_port_set_link,
2426 .port_set_duplex = mv88e6xxx_port_set_duplex,
2427 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002428 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002429 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002430 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002431 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002432 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002433 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002434 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002435 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002436 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002437 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2438 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2439 .stats_get_strings = mv88e6095_stats_get_strings,
2440 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002441 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2442 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002443 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002444 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002445 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002446 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002447 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002448};
2449
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002450static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002451 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002452 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002453 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002454 .phy_read = mv88e6xxx_g2_smi_phy_read,
2455 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002456 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002457 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002458 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002459 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002460 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002461 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002462 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002463 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002464 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2465 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002466 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002467 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2468 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002469 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002470 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002471 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002472 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002473 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002474};
2475
2476static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002477 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002478 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002479 .phy_read = mv88e6185_phy_ppu_read,
2480 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002481 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002482 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002483 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002484 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002485 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002486 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002487 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002488 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002489 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002490 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002491 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002492 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002493 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2494 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002495 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002496 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2497 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002498 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002499 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002500 .ppu_enable = mv88e6185_g1_ppu_enable,
2501 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002502 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002503 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002504 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002505};
2506
Vivien Didelot990e27b2017-03-28 13:50:32 -04002507static const struct mv88e6xxx_ops mv88e6141_ops = {
2508 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002509 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002510 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2511 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2512 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2513 .phy_read = mv88e6xxx_g2_smi_phy_read,
2514 .phy_write = mv88e6xxx_g2_smi_phy_write,
2515 .port_set_link = mv88e6xxx_port_set_link,
2516 .port_set_duplex = mv88e6xxx_port_set_duplex,
2517 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2518 .port_set_speed = mv88e6390_port_set_speed,
2519 .port_tag_remap = mv88e6095_port_tag_remap,
2520 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2521 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2522 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002523 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002524 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002525 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002526 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2527 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2528 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2529 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2530 .stats_get_strings = mv88e6320_stats_get_strings,
2531 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002532 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2533 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002534 .watchdog_ops = &mv88e6390_watchdog_ops,
2535 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2536 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002537 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002538 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002539};
2540
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002541static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002542 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002543 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002544 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002545 .phy_read = mv88e6xxx_g2_smi_phy_read,
2546 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002547 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002548 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002549 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002550 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002551 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002552 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002553 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002554 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002555 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002556 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002557 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002558 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002559 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002560 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2561 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002562 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002563 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2564 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002565 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002566 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002567 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002568 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002569 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002570};
2571
2572static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002573 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002574 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002575 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002576 .phy_read = mv88e6165_phy_read,
2577 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002578 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002579 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002580 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002581 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002582 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002583 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002584 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2585 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002586 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002587 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2588 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002589 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002590 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002591 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002592 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002593 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002594};
2595
2596static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002597 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002598 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002599 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002600 .phy_read = mv88e6xxx_g2_smi_phy_read,
2601 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002602 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002603 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002604 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002605 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002606 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002607 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002608 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002609 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002610 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002611 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002612 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002613 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002614 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002615 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002616 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2617 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002618 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002619 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2620 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002621 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002622 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002623 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002624 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002625 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002626};
2627
2628static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002629 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002630 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002631 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2632 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002633 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002634 .phy_read = mv88e6xxx_g2_smi_phy_read,
2635 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002636 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002637 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002638 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002639 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002640 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002641 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002642 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002643 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002644 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002645 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002646 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002647 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002648 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002649 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002650 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2651 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002652 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002653 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2654 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002655 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002656 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002657 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002658 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002659 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002660 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002661};
2662
2663static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002664 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002665 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002666 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002667 .phy_read = mv88e6xxx_g2_smi_phy_read,
2668 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002669 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002670 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002671 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002672 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002673 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002674 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002675 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002676 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002677 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002678 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002679 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002680 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002681 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002682 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002683 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2684 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002685 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002686 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2687 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002688 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002689 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002690 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002691 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002692 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002693};
2694
2695static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002696 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002697 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002698 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2699 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002700 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002701 .phy_read = mv88e6xxx_g2_smi_phy_read,
2702 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002703 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002704 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002705 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002706 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002707 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002708 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002709 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002710 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002711 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002712 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002713 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002714 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002715 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002716 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002717 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2718 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002719 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002720 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2721 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002722 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002723 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002724 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002725 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002726 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002727 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002728};
2729
2730static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002731 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002732 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002733 .phy_read = mv88e6185_phy_ppu_read,
2734 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002735 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002736 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002737 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002738 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002739 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002740 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002741 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002742 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002743 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2744 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002745 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002746 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2747 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002748 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002749 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002750 .ppu_enable = mv88e6185_g1_ppu_enable,
2751 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002752 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002753 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002754 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002755};
2756
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002757static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002758 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002759 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002760 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2761 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002762 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2763 .phy_read = mv88e6xxx_g2_smi_phy_read,
2764 .phy_write = mv88e6xxx_g2_smi_phy_write,
2765 .port_set_link = mv88e6xxx_port_set_link,
2766 .port_set_duplex = mv88e6xxx_port_set_duplex,
2767 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2768 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002769 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002770 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002771 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002772 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002773 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002774 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002775 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002776 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002777 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002778 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2779 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002780 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002781 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2782 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002783 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002784 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002785 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002786 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2787 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002788 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002789};
2790
2791static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002792 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002793 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002794 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2795 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002796 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2797 .phy_read = mv88e6xxx_g2_smi_phy_read,
2798 .phy_write = mv88e6xxx_g2_smi_phy_write,
2799 .port_set_link = mv88e6xxx_port_set_link,
2800 .port_set_duplex = mv88e6xxx_port_set_duplex,
2801 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2802 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002803 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002804 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002805 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002806 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002807 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002808 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002809 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002810 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002811 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002812 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2813 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002814 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002815 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2816 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002817 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002818 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002819 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002820 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2821 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002822 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002823};
2824
2825static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002826 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002827 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002828 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2829 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002830 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2831 .phy_read = mv88e6xxx_g2_smi_phy_read,
2832 .phy_write = mv88e6xxx_g2_smi_phy_write,
2833 .port_set_link = mv88e6xxx_port_set_link,
2834 .port_set_duplex = mv88e6xxx_port_set_duplex,
2835 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2836 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002837 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002838 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002839 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002840 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002841 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002842 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002843 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002844 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002845 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002846 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2847 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002848 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002849 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2850 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002851 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002852 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002853 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002854 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2855 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002856 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002857};
2858
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002859static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002860 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002861 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002862 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2863 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002864 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002865 .phy_read = mv88e6xxx_g2_smi_phy_read,
2866 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002867 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002868 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002869 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002870 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002871 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002872 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002873 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002874 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002875 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002876 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002877 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002878 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002879 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002880 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002881 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2882 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002883 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002884 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2885 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002886 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002887 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002888 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002889 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002890 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002891 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002892};
2893
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002894static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002895 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002896 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002897 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2898 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002899 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2900 .phy_read = mv88e6xxx_g2_smi_phy_read,
2901 .phy_write = mv88e6xxx_g2_smi_phy_write,
2902 .port_set_link = mv88e6xxx_port_set_link,
2903 .port_set_duplex = mv88e6xxx_port_set_duplex,
2904 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2905 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002906 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002907 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002908 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002909 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002910 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002911 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002912 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002913 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002914 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002915 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002916 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2917 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002918 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002919 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2920 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002921 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002922 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002923 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002924 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2925 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002926 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002927};
2928
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002929static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002930 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002931 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002932 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2933 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002934 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002935 .phy_read = mv88e6xxx_g2_smi_phy_read,
2936 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002937 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002938 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002939 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002940 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002941 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002942 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002943 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002944 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002945 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002946 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002947 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002948 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002949 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002950 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2951 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002952 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002953 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2954 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002955 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002956 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002957 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002958 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002959};
2960
2961static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04002962 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002963 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002964 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2965 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002966 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002967 .phy_read = mv88e6xxx_g2_smi_phy_read,
2968 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002969 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002970 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002971 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002972 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002973 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002974 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002975 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002976 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002977 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002978 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002979 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002980 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002981 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002982 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2983 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002984 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002985 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2986 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002987 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002988 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002989 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002990};
2991
Vivien Didelot16e329a2017-03-28 13:50:33 -04002992static const struct mv88e6xxx_ops mv88e6341_ops = {
2993 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002994 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04002995 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2996 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2997 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2998 .phy_read = mv88e6xxx_g2_smi_phy_read,
2999 .phy_write = mv88e6xxx_g2_smi_phy_write,
3000 .port_set_link = mv88e6xxx_port_set_link,
3001 .port_set_duplex = mv88e6xxx_port_set_duplex,
3002 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3003 .port_set_speed = mv88e6390_port_set_speed,
3004 .port_tag_remap = mv88e6095_port_tag_remap,
3005 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3006 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3007 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003008 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003009 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003010 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003011 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3012 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3013 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3014 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3015 .stats_get_strings = mv88e6320_stats_get_strings,
3016 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003017 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3018 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003019 .watchdog_ops = &mv88e6390_watchdog_ops,
3020 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3021 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003022 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003023 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003024};
3025
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003026static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003027 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003028 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003029 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003030 .phy_read = mv88e6xxx_g2_smi_phy_read,
3031 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003032 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003033 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003034 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003035 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003036 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003037 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003038 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003039 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003040 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003041 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003042 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003043 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003044 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003045 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003046 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3047 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003048 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003049 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3050 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003051 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003052 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003053 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003054 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003055 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003056};
3057
3058static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003059 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003060 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003061 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003062 .phy_read = mv88e6xxx_g2_smi_phy_read,
3063 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003064 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003065 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003066 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003067 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003068 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003069 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003070 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003071 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003072 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003073 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003074 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003075 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003076 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003077 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003078 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3079 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003080 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003081 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3082 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003083 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003084 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003085 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003086 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003087 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003088};
3089
3090static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003091 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003092 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003093 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3094 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003095 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003096 .phy_read = mv88e6xxx_g2_smi_phy_read,
3097 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003098 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003099 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003100 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003101 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003102 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003103 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003104 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003105 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003106 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003107 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003108 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003109 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003110 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003111 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003112 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3113 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003114 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003115 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3116 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003117 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003118 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003119 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003120 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003121 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003122 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003123};
3124
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003125static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003126 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003127 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003128 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3129 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003130 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3131 .phy_read = mv88e6xxx_g2_smi_phy_read,
3132 .phy_write = mv88e6xxx_g2_smi_phy_write,
3133 .port_set_link = mv88e6xxx_port_set_link,
3134 .port_set_duplex = mv88e6xxx_port_set_duplex,
3135 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3136 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003137 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003138 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003139 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003140 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003141 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003142 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003143 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003144 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003145 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003146 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003147 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003148 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003149 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3150 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003151 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003152 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3153 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003154 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003155 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003156 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003157 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3158 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003159 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003160};
3161
3162static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003163 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003164 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003165 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3166 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003167 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3168 .phy_read = mv88e6xxx_g2_smi_phy_read,
3169 .phy_write = mv88e6xxx_g2_smi_phy_write,
3170 .port_set_link = mv88e6xxx_port_set_link,
3171 .port_set_duplex = mv88e6xxx_port_set_duplex,
3172 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3173 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003174 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003175 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003176 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003177 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003178 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003179 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003180 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003181 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003182 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003183 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003184 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003185 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3186 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003187 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003188 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3189 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003190 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003191 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003192 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003193 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3194 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003195 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003196};
3197
Vivien Didelotf81ec902016-05-09 13:22:58 -04003198static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3199 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003200 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003201 .family = MV88E6XXX_FAMILY_6097,
3202 .name = "Marvell 88E6085",
3203 .num_databases = 4096,
3204 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003205 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003206 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003207 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003208 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003209 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003210 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003211 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003212 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003213 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003214 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003215 },
3216
3217 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003218 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003219 .family = MV88E6XXX_FAMILY_6095,
3220 .name = "Marvell 88E6095/88E6095F",
3221 .num_databases = 256,
3222 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003223 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003224 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003225 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003226 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003227 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003228 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003229 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003230 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003231 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003232 },
3233
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003234 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003235 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003236 .family = MV88E6XXX_FAMILY_6097,
3237 .name = "Marvell 88E6097/88E6097F",
3238 .num_databases = 4096,
3239 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003240 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003241 .port_base_addr = 0x10,
3242 .global1_addr = 0x1b,
3243 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003244 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003245 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003246 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003247 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003248 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3249 .ops = &mv88e6097_ops,
3250 },
3251
Vivien Didelotf81ec902016-05-09 13:22:58 -04003252 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003253 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003254 .family = MV88E6XXX_FAMILY_6165,
3255 .name = "Marvell 88E6123",
3256 .num_databases = 4096,
3257 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003258 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003259 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003260 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003261 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003262 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003263 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003264 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003265 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003266 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003267 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003268 },
3269
3270 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003271 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003272 .family = MV88E6XXX_FAMILY_6185,
3273 .name = "Marvell 88E6131",
3274 .num_databases = 256,
3275 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003276 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003277 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003278 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003279 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003280 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003281 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003282 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003283 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003284 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003285 },
3286
Vivien Didelot990e27b2017-03-28 13:50:32 -04003287 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003288 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003289 .family = MV88E6XXX_FAMILY_6341,
3290 .name = "Marvell 88E6341",
3291 .num_databases = 4096,
3292 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003293 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003294 .port_base_addr = 0x10,
3295 .global1_addr = 0x1b,
3296 .age_time_coeff = 3750,
3297 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003298 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003299 .tag_protocol = DSA_TAG_PROTO_EDSA,
3300 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3301 .ops = &mv88e6141_ops,
3302 },
3303
Vivien Didelotf81ec902016-05-09 13:22:58 -04003304 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003305 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003306 .family = MV88E6XXX_FAMILY_6165,
3307 .name = "Marvell 88E6161",
3308 .num_databases = 4096,
3309 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003310 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003311 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003312 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003313 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003314 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003315 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003316 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003317 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003318 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003319 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003320 },
3321
3322 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003323 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003324 .family = MV88E6XXX_FAMILY_6165,
3325 .name = "Marvell 88E6165",
3326 .num_databases = 4096,
3327 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003328 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003329 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003330 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003331 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003332 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003333 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003334 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003335 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003336 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003337 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003338 },
3339
3340 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003341 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003342 .family = MV88E6XXX_FAMILY_6351,
3343 .name = "Marvell 88E6171",
3344 .num_databases = 4096,
3345 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003346 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003347 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003348 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003349 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003350 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003351 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003352 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003353 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003354 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003355 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003356 },
3357
3358 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003359 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003360 .family = MV88E6XXX_FAMILY_6352,
3361 .name = "Marvell 88E6172",
3362 .num_databases = 4096,
3363 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003364 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003365 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003366 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003367 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003368 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003369 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003370 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003371 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003372 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003373 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003374 },
3375
3376 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003377 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003378 .family = MV88E6XXX_FAMILY_6351,
3379 .name = "Marvell 88E6175",
3380 .num_databases = 4096,
3381 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003382 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003383 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003384 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003385 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003386 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003387 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003388 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003389 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003390 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003391 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003392 },
3393
3394 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003395 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003396 .family = MV88E6XXX_FAMILY_6352,
3397 .name = "Marvell 88E6176",
3398 .num_databases = 4096,
3399 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003400 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003401 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003402 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003403 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003404 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003405 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003406 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003407 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003408 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003409 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003410 },
3411
3412 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003413 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003414 .family = MV88E6XXX_FAMILY_6185,
3415 .name = "Marvell 88E6185",
3416 .num_databases = 256,
3417 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003418 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003419 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003420 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003421 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003422 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003423 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003424 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003425 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003426 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003427 },
3428
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003429 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003430 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003431 .family = MV88E6XXX_FAMILY_6390,
3432 .name = "Marvell 88E6190",
3433 .num_databases = 4096,
3434 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003435 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003436 .port_base_addr = 0x0,
3437 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003438 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003439 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003440 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003441 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003442 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003443 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3444 .ops = &mv88e6190_ops,
3445 },
3446
3447 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003448 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003449 .family = MV88E6XXX_FAMILY_6390,
3450 .name = "Marvell 88E6190X",
3451 .num_databases = 4096,
3452 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003453 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003454 .port_base_addr = 0x0,
3455 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003456 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003457 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003458 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003459 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003460 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003461 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3462 .ops = &mv88e6190x_ops,
3463 },
3464
3465 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003466 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003467 .family = MV88E6XXX_FAMILY_6390,
3468 .name = "Marvell 88E6191",
3469 .num_databases = 4096,
3470 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003471 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003472 .port_base_addr = 0x0,
3473 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003474 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003475 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003476 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003477 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003478 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003479 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003480 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003481 },
3482
Vivien Didelotf81ec902016-05-09 13:22:58 -04003483 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003484 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003485 .family = MV88E6XXX_FAMILY_6352,
3486 .name = "Marvell 88E6240",
3487 .num_databases = 4096,
3488 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003489 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003490 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003491 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003492 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003493 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003494 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003495 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003496 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003497 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003498 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003499 },
3500
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003501 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003502 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003503 .family = MV88E6XXX_FAMILY_6390,
3504 .name = "Marvell 88E6290",
3505 .num_databases = 4096,
3506 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003507 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003508 .port_base_addr = 0x0,
3509 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003510 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003511 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003512 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003513 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003514 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003515 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3516 .ops = &mv88e6290_ops,
3517 },
3518
Vivien Didelotf81ec902016-05-09 13:22:58 -04003519 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003520 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003521 .family = MV88E6XXX_FAMILY_6320,
3522 .name = "Marvell 88E6320",
3523 .num_databases = 4096,
3524 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003525 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003526 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003527 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003528 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003529 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003530 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003531 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003532 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003533 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003534 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003535 },
3536
3537 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003538 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003539 .family = MV88E6XXX_FAMILY_6320,
3540 .name = "Marvell 88E6321",
3541 .num_databases = 4096,
3542 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003543 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003544 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003545 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003546 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003547 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003548 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003549 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003550 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003551 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003552 },
3553
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003554 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003555 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003556 .family = MV88E6XXX_FAMILY_6341,
3557 .name = "Marvell 88E6341",
3558 .num_databases = 4096,
3559 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003560 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003561 .port_base_addr = 0x10,
3562 .global1_addr = 0x1b,
3563 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003564 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003565 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003566 .tag_protocol = DSA_TAG_PROTO_EDSA,
3567 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3568 .ops = &mv88e6341_ops,
3569 },
3570
Vivien Didelotf81ec902016-05-09 13:22:58 -04003571 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003572 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003573 .family = MV88E6XXX_FAMILY_6351,
3574 .name = "Marvell 88E6350",
3575 .num_databases = 4096,
3576 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003577 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003578 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003579 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003580 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003581 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003582 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003583 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003584 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003585 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003586 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003587 },
3588
3589 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003590 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003591 .family = MV88E6XXX_FAMILY_6351,
3592 .name = "Marvell 88E6351",
3593 .num_databases = 4096,
3594 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003595 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003596 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003597 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003598 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003599 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003600 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003601 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003602 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003603 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003604 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003605 },
3606
3607 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003608 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003609 .family = MV88E6XXX_FAMILY_6352,
3610 .name = "Marvell 88E6352",
3611 .num_databases = 4096,
3612 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003613 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003614 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003615 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003616 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003617 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003618 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003619 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003620 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003621 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003622 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003623 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003624 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003625 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003626 .family = MV88E6XXX_FAMILY_6390,
3627 .name = "Marvell 88E6390",
3628 .num_databases = 4096,
3629 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003630 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003631 .port_base_addr = 0x0,
3632 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003633 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003634 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003635 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003636 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003637 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003638 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3639 .ops = &mv88e6390_ops,
3640 },
3641 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003642 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003643 .family = MV88E6XXX_FAMILY_6390,
3644 .name = "Marvell 88E6390X",
3645 .num_databases = 4096,
3646 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003647 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003648 .port_base_addr = 0x0,
3649 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003650 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003651 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003652 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003653 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003654 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003655 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3656 .ops = &mv88e6390x_ops,
3657 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003658};
3659
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003660static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003661{
Vivien Didelota439c062016-04-17 13:23:58 -04003662 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003663
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003664 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3665 if (mv88e6xxx_table[i].prod_num == prod_num)
3666 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003667
Vivien Didelotb9b37712015-10-30 19:39:48 -04003668 return NULL;
3669}
3670
Vivien Didelotfad09c72016-06-21 12:28:20 -04003671static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003672{
3673 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003674 unsigned int prod_num, rev;
3675 u16 id;
3676 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003677
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003678 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04003679 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003680 mutex_unlock(&chip->reg_lock);
3681 if (err)
3682 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003683
Vivien Didelot107fcc12017-06-12 12:37:36 -04003684 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
3685 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003686
3687 info = mv88e6xxx_lookup_info(prod_num);
3688 if (!info)
3689 return -ENODEV;
3690
Vivien Didelotcaac8542016-06-20 13:14:09 -04003691 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003692 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003693
Vivien Didelotca070c12016-09-02 14:45:34 -04003694 err = mv88e6xxx_g2_require(chip);
3695 if (err)
3696 return err;
3697
Vivien Didelotfad09c72016-06-21 12:28:20 -04003698 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3699 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003700
3701 return 0;
3702}
3703
Vivien Didelotfad09c72016-06-21 12:28:20 -04003704static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003705{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003706 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003707
Vivien Didelotfad09c72016-06-21 12:28:20 -04003708 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3709 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003710 return NULL;
3711
Vivien Didelotfad09c72016-06-21 12:28:20 -04003712 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003713
Vivien Didelotfad09c72016-06-21 12:28:20 -04003714 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003715 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003716
Vivien Didelotfad09c72016-06-21 12:28:20 -04003717 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003718}
3719
Vivien Didelotfad09c72016-06-21 12:28:20 -04003720static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003721 struct mii_bus *bus, int sw_addr)
3722{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003723 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003724 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003725 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003726 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003727 else
3728 return -EINVAL;
3729
Vivien Didelotfad09c72016-06-21 12:28:20 -04003730 chip->bus = bus;
3731 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003732
3733 return 0;
3734}
3735
Andrew Lunn7b314362016-08-22 16:01:01 +02003736static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3737{
Vivien Didelot04bed142016-08-31 18:06:13 -04003738 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003739
Andrew Lunn443d5a12016-12-03 04:35:18 +01003740 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003741}
3742
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003743static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3744 struct device *host_dev, int sw_addr,
3745 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003746{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003747 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003748 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003749 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003750
Vivien Didelota439c062016-04-17 13:23:58 -04003751 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003752 if (!bus)
3753 return NULL;
3754
Vivien Didelotfad09c72016-06-21 12:28:20 -04003755 chip = mv88e6xxx_alloc_chip(dsa_dev);
3756 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003757 return NULL;
3758
Vivien Didelotcaac8542016-06-20 13:14:09 -04003759 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003760 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003761
Vivien Didelotfad09c72016-06-21 12:28:20 -04003762 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003763 if (err)
3764 goto free;
3765
Vivien Didelotfad09c72016-06-21 12:28:20 -04003766 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003767 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003768 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003769
Andrew Lunndc30c352016-10-16 19:56:49 +02003770 mutex_lock(&chip->reg_lock);
3771 err = mv88e6xxx_switch_reset(chip);
3772 mutex_unlock(&chip->reg_lock);
3773 if (err)
3774 goto free;
3775
Vivien Didelote57e5e72016-08-15 17:19:00 -04003776 mv88e6xxx_phy_init(chip);
3777
Andrew Lunna3c53be52017-01-24 14:53:50 +01003778 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003779 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003780 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003781
Vivien Didelotfad09c72016-06-21 12:28:20 -04003782 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003783
Vivien Didelotfad09c72016-06-21 12:28:20 -04003784 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003785free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003786 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003787
3788 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003789}
3790
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003791static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3792 const struct switchdev_obj_port_mdb *mdb,
3793 struct switchdev_trans *trans)
3794{
3795 /* We don't need any dynamic resource from the kernel (yet),
3796 * so skip the prepare phase.
3797 */
3798
3799 return 0;
3800}
3801
3802static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3803 const struct switchdev_obj_port_mdb *mdb,
3804 struct switchdev_trans *trans)
3805{
Vivien Didelot04bed142016-08-31 18:06:13 -04003806 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003807
3808 mutex_lock(&chip->reg_lock);
3809 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003810 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04003811 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
3812 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003813 mutex_unlock(&chip->reg_lock);
3814}
3815
3816static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3817 const struct switchdev_obj_port_mdb *mdb)
3818{
Vivien Didelot04bed142016-08-31 18:06:13 -04003819 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003820 int err;
3821
3822 mutex_lock(&chip->reg_lock);
3823 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003824 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003825 mutex_unlock(&chip->reg_lock);
3826
3827 return err;
3828}
3829
3830static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3831 struct switchdev_obj_port_mdb *mdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04003832 switchdev_obj_dump_cb_t *cb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003833{
Vivien Didelot04bed142016-08-31 18:06:13 -04003834 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003835 int err;
3836
3837 mutex_lock(&chip->reg_lock);
3838 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3839 mutex_unlock(&chip->reg_lock);
3840
3841 return err;
3842}
3843
Florian Fainellia82f67a2017-01-08 14:52:08 -08003844static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003845 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02003846 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003847 .setup = mv88e6xxx_setup,
3848 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003849 .adjust_link = mv88e6xxx_adjust_link,
3850 .get_strings = mv88e6xxx_get_strings,
3851 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3852 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02003853 .port_enable = mv88e6xxx_port_enable,
3854 .port_disable = mv88e6xxx_port_disable,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003855 .set_eee = mv88e6xxx_set_eee,
3856 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003857 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003858 .get_eeprom = mv88e6xxx_get_eeprom,
3859 .set_eeprom = mv88e6xxx_set_eeprom,
3860 .get_regs_len = mv88e6xxx_get_regs_len,
3861 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003862 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003863 .port_bridge_join = mv88e6xxx_port_bridge_join,
3864 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3865 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04003866 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003867 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3868 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3869 .port_vlan_add = mv88e6xxx_port_vlan_add,
3870 .port_vlan_del = mv88e6xxx_port_vlan_del,
3871 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3872 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3873 .port_fdb_add = mv88e6xxx_port_fdb_add,
3874 .port_fdb_del = mv88e6xxx_port_fdb_del,
3875 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003876 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3877 .port_mdb_add = mv88e6xxx_port_mdb_add,
3878 .port_mdb_del = mv88e6xxx_port_mdb_del,
3879 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04003880 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
3881 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003882};
3883
Florian Fainelliab3d4082017-01-08 14:52:07 -08003884static struct dsa_switch_driver mv88e6xxx_switch_drv = {
3885 .ops = &mv88e6xxx_switch_ops,
3886};
3887
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003888static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003889{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003890 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003891 struct dsa_switch *ds;
3892
Vivien Didelot73b12042017-03-30 17:37:10 -04003893 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003894 if (!ds)
3895 return -ENOMEM;
3896
Vivien Didelotfad09c72016-06-21 12:28:20 -04003897 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04003898 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04003899 ds->ageing_time_min = chip->info->age_time_coeff;
3900 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003901
3902 dev_set_drvdata(dev, ds);
3903
Vivien Didelot23c9ee42017-05-26 18:12:51 -04003904 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003905}
3906
Vivien Didelotfad09c72016-06-21 12:28:20 -04003907static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003908{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003909 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003910}
3911
Vivien Didelot57d32312016-06-20 13:13:58 -04003912static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003913{
3914 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003915 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003916 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003917 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003918 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02003919 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003920
Vivien Didelotcaac8542016-06-20 13:14:09 -04003921 compat_info = of_device_get_match_data(dev);
3922 if (!compat_info)
3923 return -EINVAL;
3924
Vivien Didelotfad09c72016-06-21 12:28:20 -04003925 chip = mv88e6xxx_alloc_chip(dev);
3926 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003927 return -ENOMEM;
3928
Vivien Didelotfad09c72016-06-21 12:28:20 -04003929 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003930
Vivien Didelotfad09c72016-06-21 12:28:20 -04003931 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003932 if (err)
3933 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003934
Andrew Lunnb4308f02016-11-21 23:26:55 +01003935 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
3936 if (IS_ERR(chip->reset))
3937 return PTR_ERR(chip->reset);
3938
Vivien Didelotfad09c72016-06-21 12:28:20 -04003939 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003940 if (err)
3941 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003942
Vivien Didelote57e5e72016-08-15 17:19:00 -04003943 mv88e6xxx_phy_init(chip);
3944
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003945 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003946 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003947 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003948
Andrew Lunndc30c352016-10-16 19:56:49 +02003949 mutex_lock(&chip->reg_lock);
3950 err = mv88e6xxx_switch_reset(chip);
3951 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02003952 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02003953 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02003954
Andrew Lunndc30c352016-10-16 19:56:49 +02003955 chip->irq = of_irq_get(np, 0);
3956 if (chip->irq == -EPROBE_DEFER) {
3957 err = chip->irq;
3958 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02003959 }
3960
Andrew Lunndc30c352016-10-16 19:56:49 +02003961 if (chip->irq > 0) {
3962 /* Has to be performed before the MDIO bus is created,
3963 * because the PHYs will link there interrupts to these
3964 * interrupt controllers
3965 */
3966 mutex_lock(&chip->reg_lock);
3967 err = mv88e6xxx_g1_irq_setup(chip);
3968 mutex_unlock(&chip->reg_lock);
3969
3970 if (err)
3971 goto out;
3972
3973 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
3974 err = mv88e6xxx_g2_irq_setup(chip);
3975 if (err)
3976 goto out_g1_irq;
3977 }
3978 }
3979
Andrew Lunna3c53be52017-01-24 14:53:50 +01003980 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02003981 if (err)
3982 goto out_g2_irq;
3983
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003984 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003985 if (err)
3986 goto out_mdio;
3987
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003988 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02003989
3990out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01003991 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003992out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01003993 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02003994 mv88e6xxx_g2_irq_free(chip);
3995out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003996 if (chip->irq > 0) {
3997 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01003998 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003999 mutex_unlock(&chip->reg_lock);
4000 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004001out:
4002 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004003}
4004
4005static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4006{
4007 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004008 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004009
Andrew Lunn930188c2016-08-22 16:01:03 +02004010 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004011 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004012 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004013
Andrew Lunn467126442016-11-20 20:14:15 +01004014 if (chip->irq > 0) {
4015 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4016 mv88e6xxx_g2_irq_free(chip);
4017 mv88e6xxx_g1_irq_free(chip);
4018 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004019}
4020
4021static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004022 {
4023 .compatible = "marvell,mv88e6085",
4024 .data = &mv88e6xxx_table[MV88E6085],
4025 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004026 {
4027 .compatible = "marvell,mv88e6190",
4028 .data = &mv88e6xxx_table[MV88E6190],
4029 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004030 { /* sentinel */ },
4031};
4032
4033MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4034
4035static struct mdio_driver mv88e6xxx_driver = {
4036 .probe = mv88e6xxx_probe,
4037 .remove = mv88e6xxx_remove,
4038 .mdiodrv.driver = {
4039 .name = "mv88e6085",
4040 .of_match_table = mv88e6xxx_of_match,
4041 },
4042};
4043
Ben Hutchings98e67302011-11-25 14:36:19 +00004044static int __init mv88e6xxx_init(void)
4045{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004046 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004047 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004048}
4049module_init(mv88e6xxx_init);
4050
4051static void __exit mv88e6xxx_cleanup(void)
4052{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004053 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004054 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004055}
4056module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004057
4058MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4059MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4060MODULE_LICENSE("GPL");