blob: bf7ad2e8b4d77fce91fd5aa3e9917f90cb8f76d4 [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);
264 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
265 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
295 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
296 if (err)
297 goto out;
298
299 reg &= ~mask;
300 reg |= (~chip->g1_irq.masked & mask);
301
302 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
303 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
341 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
342 mask |= GENMASK(chip->g1_irq.nirqs, 0);
343 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
344
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
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100373 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &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
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100379 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, 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 */
384 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
385 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);
399 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
400
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,
728 0, GLOBAL_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,
736 GLOBAL_STATS_OP_BANK_1_BIT_9,
737 GLOBAL_STATS_OP_HIST_RX_TX);
738}
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,
745 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100746}
747
748static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
749 uint64_t *data)
750{
751 if (chip->info->ops->stats_get_stats)
752 chip->info->ops->stats_get_stats(chip, port, data);
753}
754
Vivien Didelotf81ec902016-05-09 13:22:58 -0400755static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
756 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000757{
Vivien Didelot04bed142016-08-31 18:06:13 -0400758 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000759 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000760
Vivien Didelotfad09c72016-06-21 12:28:20 -0400761 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000762
Andrew Lunna605a0f2016-11-21 23:26:58 +0100763 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000764 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400765 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000766 return;
767 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100768
769 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000770
Vivien Didelotfad09c72016-06-21 12:28:20 -0400771 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000772}
Ben Hutchings98e67302011-11-25 14:36:19 +0000773
Andrew Lunnde2273872016-11-21 23:27:01 +0100774static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
775{
776 if (chip->info->ops->stats_set_histogram)
777 return chip->info->ops->stats_set_histogram(chip);
778
779 return 0;
780}
781
Vivien Didelotf81ec902016-05-09 13:22:58 -0400782static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700783{
784 return 32 * sizeof(u16);
785}
786
Vivien Didelotf81ec902016-05-09 13:22:58 -0400787static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
788 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700789{
Vivien Didelot04bed142016-08-31 18:06:13 -0400790 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200791 int err;
792 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700793 u16 *p = _p;
794 int i;
795
796 regs->version = 0;
797
798 memset(p, 0xff, 32 * sizeof(u16));
799
Vivien Didelotfad09c72016-06-21 12:28:20 -0400800 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400801
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700802 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700803
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200804 err = mv88e6xxx_port_read(chip, port, i, &reg);
805 if (!err)
806 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700807 }
Vivien Didelot23062512016-05-09 13:22:45 -0400808
Vivien Didelotfad09c72016-06-21 12:28:20 -0400809 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700810}
811
Vivien Didelotf81ec902016-05-09 13:22:58 -0400812static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
813 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800814{
Vivien Didelot04bed142016-08-31 18:06:13 -0400815 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400816 u16 reg;
817 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800818
Vivien Didelotfad09c72016-06-21 12:28:20 -0400819 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400820 return -EOPNOTSUPP;
821
Vivien Didelotfad09c72016-06-21 12:28:20 -0400822 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200823
Vivien Didelot9c938292016-08-15 17:19:02 -0400824 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
825 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200826 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800827
828 e->eee_enabled = !!(reg & 0x0200);
829 e->tx_lpi_enabled = !!(reg & 0x0100);
830
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200831 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -0400832 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200833 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800834
Andrew Lunncca8b132015-04-02 04:06:39 +0200835 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200836out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400837 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -0400838
839 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800840}
841
Vivien Didelotf81ec902016-05-09 13:22:58 -0400842static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
843 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800844{
Vivien Didelot04bed142016-08-31 18:06:13 -0400845 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400846 u16 reg;
847 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800848
Vivien Didelotfad09c72016-06-21 12:28:20 -0400849 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400850 return -EOPNOTSUPP;
851
Vivien Didelotfad09c72016-06-21 12:28:20 -0400852 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800853
Vivien Didelot9c938292016-08-15 17:19:02 -0400854 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
855 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200856 goto out;
857
Vivien Didelot9c938292016-08-15 17:19:02 -0400858 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +0200859 if (e->eee_enabled)
860 reg |= 0x0200;
861 if (e->tx_lpi_enabled)
862 reg |= 0x0100;
863
Vivien Didelot9c938292016-08-15 17:19:02 -0400864 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200865out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400866 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200867
Vivien Didelot9c938292016-08-15 17:19:02 -0400868 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800869}
870
Vivien Didelote5887a22017-03-30 17:37:11 -0400871static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700872{
Vivien Didelote5887a22017-03-30 17:37:11 -0400873 struct dsa_switch *ds = NULL;
874 struct net_device *br;
875 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500876 int i;
877
Vivien Didelote5887a22017-03-30 17:37:11 -0400878 if (dev < DSA_MAX_SWITCHES)
879 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500880
Vivien Didelote5887a22017-03-30 17:37:11 -0400881 /* Prevent frames from unknown switch or port */
882 if (!ds || port >= ds->num_ports)
883 return 0;
884
885 /* Frames from DSA links and CPU ports can egress any local port */
886 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
887 return mv88e6xxx_port_mask(chip);
888
889 br = ds->ports[port].bridge_dev;
890 pvlan = 0;
891
892 /* Frames from user ports can egress any local DSA links and CPU ports,
893 * as well as any local member of their bridge group.
894 */
895 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
896 if (dsa_is_cpu_port(chip->ds, i) ||
897 dsa_is_dsa_port(chip->ds, i) ||
898 (br && chip->ds->ports[i].bridge_dev == br))
899 pvlan |= BIT(i);
900
901 return pvlan;
902}
903
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400904static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400905{
906 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500907
908 /* prevent frames from going back out of the port they came in on */
909 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700910
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100911 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700912}
913
Vivien Didelotf81ec902016-05-09 13:22:58 -0400914static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
915 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700916{
Vivien Didelot04bed142016-08-31 18:06:13 -0400917 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700918 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -0400919 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700920
921 switch (state) {
922 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +0200923 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700924 break;
925 case BR_STATE_BLOCKING:
926 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +0200927 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700928 break;
929 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +0200930 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700931 break;
932 case BR_STATE_FORWARDING:
933 default:
Andrew Lunncca8b132015-04-02 04:06:39 +0200934 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700935 break;
936 }
937
Vivien Didelotfad09c72016-06-21 12:28:20 -0400938 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +0100939 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400940 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400941
942 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400943 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700944}
945
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500946static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
947{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500948 int err;
949
Vivien Didelotdaefc942017-03-11 16:12:54 -0500950 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
951 if (err)
952 return err;
953
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500954 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
955 if (err)
956 return err;
957
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500958 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
959}
960
Vivien Didelot17a15942017-03-30 17:37:09 -0400961static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
962{
963 u16 pvlan = 0;
964
965 if (!mv88e6xxx_has_pvt(chip))
966 return -EOPNOTSUPP;
967
968 /* Skip the local source device, which uses in-chip port VLAN */
969 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -0400970 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -0400971
972 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
973}
974
Vivien Didelot81228992017-03-30 17:37:08 -0400975static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
976{
Vivien Didelot17a15942017-03-30 17:37:09 -0400977 int dev, port;
978 int err;
979
Vivien Didelot81228992017-03-30 17:37:08 -0400980 if (!mv88e6xxx_has_pvt(chip))
981 return 0;
982
983 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
984 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
985 */
Vivien Didelot17a15942017-03-30 17:37:09 -0400986 err = mv88e6xxx_g2_misc_4_bit_port(chip);
987 if (err)
988 return err;
989
990 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
991 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
992 err = mv88e6xxx_pvt_map(chip, dev, port);
993 if (err)
994 return err;
995 }
996 }
997
998 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -0400999}
1000
Vivien Didelot749efcb2016-09-22 16:49:24 -04001001static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1002{
1003 struct mv88e6xxx_chip *chip = ds->priv;
1004 int err;
1005
1006 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001007 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001008 mutex_unlock(&chip->reg_lock);
1009
1010 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001011 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001012}
1013
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001014static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1015{
1016 if (!chip->info->max_vid)
1017 return 0;
1018
1019 return mv88e6xxx_g1_vtu_flush(chip);
1020}
1021
Vivien Didelotf1394b782017-05-01 14:05:22 -04001022static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1023 struct mv88e6xxx_vtu_entry *entry)
1024{
1025 if (!chip->info->ops->vtu_getnext)
1026 return -EOPNOTSUPP;
1027
1028 return chip->info->ops->vtu_getnext(chip, entry);
1029}
1030
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001031static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1032 struct mv88e6xxx_vtu_entry *entry)
1033{
1034 if (!chip->info->ops->vtu_loadpurge)
1035 return -EOPNOTSUPP;
1036
1037 return chip->info->ops->vtu_loadpurge(chip, entry);
1038}
1039
Vivien Didelotf81ec902016-05-09 13:22:58 -04001040static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1041 struct switchdev_obj_port_vlan *vlan,
Vivien Didelot438ff532017-05-17 15:46:05 -04001042 switchdev_obj_dump_cb_t *cb)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001043{
Vivien Didelot04bed142016-08-31 18:06:13 -04001044 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001045 struct mv88e6xxx_vtu_entry next = {
1046 .vid = chip->info->max_vid,
1047 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001048 u16 pvid;
1049 int err;
1050
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001051 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001052 return -EOPNOTSUPP;
1053
Vivien Didelotfad09c72016-06-21 12:28:20 -04001054 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001055
Vivien Didelot77064f32016-11-04 03:23:30 +01001056 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001057 if (err)
1058 goto unlock;
1059
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001060 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001061 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001062 if (err)
1063 break;
1064
1065 if (!next.valid)
1066 break;
1067
Vivien Didelotbd00e052017-05-01 14:05:11 -04001068 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001069 continue;
1070
1071 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001072 vlan->vid_begin = next.vid;
1073 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001074 vlan->flags = 0;
1075
Vivien Didelotbd00e052017-05-01 14:05:11 -04001076 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001077 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1078
1079 if (next.vid == pvid)
1080 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1081
1082 err = cb(&vlan->obj);
1083 if (err)
1084 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001085 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001086
1087unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001088 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001089
1090 return err;
1091}
1092
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001093static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001094{
1095 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001096 struct mv88e6xxx_vtu_entry vlan = {
1097 .vid = chip->info->max_vid,
1098 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001099 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001100
1101 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1102
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001103 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001104 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001105 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001106 if (err)
1107 return err;
1108
1109 set_bit(*fid, fid_bitmap);
1110 }
1111
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001112 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001113 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001114 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001115 if (err)
1116 return err;
1117
1118 if (!vlan.valid)
1119 break;
1120
1121 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001122 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001123
1124 /* The reset value 0x000 is used to indicate that multiple address
1125 * databases are not needed. Return the next positive available.
1126 */
1127 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001129 return -ENOSPC;
1130
1131 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001132 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001133}
1134
Vivien Didelot567aa592017-05-01 14:05:25 -04001135static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1136 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001137{
1138 int err;
1139
1140 if (!vid)
1141 return -EINVAL;
1142
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001143 entry->vid = vid - 1;
1144 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001145
Vivien Didelotf1394b782017-05-01 14:05:22 -04001146 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001147 if (err)
1148 return err;
1149
Vivien Didelot567aa592017-05-01 14:05:25 -04001150 if (entry->vid == vid && entry->valid)
1151 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001152
Vivien Didelot567aa592017-05-01 14:05:25 -04001153 if (new) {
1154 int i;
1155
1156 /* Initialize a fresh VLAN entry */
1157 memset(entry, 0, sizeof(*entry));
1158 entry->valid = true;
1159 entry->vid = vid;
1160
Vivien Didelot553a7682017-06-07 18:12:16 -04001161 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001162 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001163 entry->member[i] =
1164 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001165
1166 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001167 }
1168
Vivien Didelot567aa592017-05-01 14:05:25 -04001169 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1170 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001171}
1172
Vivien Didelotda9c3592016-02-12 12:09:40 -05001173static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1174 u16 vid_begin, u16 vid_end)
1175{
Vivien Didelot04bed142016-08-31 18:06:13 -04001176 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001177 struct mv88e6xxx_vtu_entry vlan = {
1178 .vid = vid_begin - 1,
1179 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001180 int i, err;
1181
1182 if (!vid_begin)
1183 return -EOPNOTSUPP;
1184
Vivien Didelotfad09c72016-06-21 12:28:20 -04001185 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001186
Vivien Didelotda9c3592016-02-12 12:09:40 -05001187 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001188 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001189 if (err)
1190 goto unlock;
1191
1192 if (!vlan.valid)
1193 break;
1194
1195 if (vlan.vid > vid_end)
1196 break;
1197
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001198 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001199 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1200 continue;
1201
Andrew Lunn66e28092016-12-11 21:07:19 +01001202 if (!ds->ports[port].netdev)
1203 continue;
1204
Vivien Didelotbd00e052017-05-01 14:05:11 -04001205 if (vlan.member[i] ==
Vivien Didelotda9c3592016-02-12 12:09:40 -05001206 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1207 continue;
1208
Vivien Didelotfae8a252017-01-27 15:29:42 -05001209 if (ds->ports[i].bridge_dev ==
1210 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001211 break; /* same bridge, check next VLAN */
1212
Vivien Didelotfae8a252017-01-27 15:29:42 -05001213 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001214 continue;
1215
Vivien Didelot774439e52017-06-08 18:34:08 -04001216 dev_err(ds->dev, "p%d: hw VLAN %d already used by %s\n",
1217 port, vlan.vid,
1218 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001219 err = -EOPNOTSUPP;
1220 goto unlock;
1221 }
1222 } while (vlan.vid < vid_end);
1223
1224unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001225 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001226
1227 return err;
1228}
1229
Vivien Didelotf81ec902016-05-09 13:22:58 -04001230static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1231 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001232{
Vivien Didelot04bed142016-08-31 18:06:13 -04001233 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001234 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001235 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001236 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001237
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001238 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001239 return -EOPNOTSUPP;
1240
Vivien Didelotfad09c72016-06-21 12:28:20 -04001241 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001242 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001243 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001244
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001245 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001246}
1247
Vivien Didelot57d32312016-06-20 13:13:58 -04001248static int
1249mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1250 const struct switchdev_obj_port_vlan *vlan,
1251 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001252{
Vivien Didelot04bed142016-08-31 18:06:13 -04001253 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001254 int err;
1255
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001256 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001257 return -EOPNOTSUPP;
1258
Vivien Didelotda9c3592016-02-12 12:09:40 -05001259 /* If the requested port doesn't belong to the same bridge as the VLAN
1260 * members, do not support it (yet) and fallback to software VLAN.
1261 */
1262 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1263 vlan->vid_end);
1264 if (err)
1265 return err;
1266
Vivien Didelot76e398a2015-11-01 12:33:55 -05001267 /* We don't need any dynamic resource from the kernel (yet),
1268 * so skip the prepare phase.
1269 */
1270 return 0;
1271}
1272
Vivien Didelotfad09c72016-06-21 12:28:20 -04001273static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001274 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001275{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001276 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001277 int err;
1278
Vivien Didelot567aa592017-05-01 14:05:25 -04001279 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001280 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001281 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001282
Vivien Didelotc91498e2017-06-07 18:12:13 -04001283 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001284
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001285 return mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001286}
1287
Vivien Didelotf81ec902016-05-09 13:22:58 -04001288static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1289 const struct switchdev_obj_port_vlan *vlan,
1290 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001291{
Vivien Didelot04bed142016-08-31 18:06:13 -04001292 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001293 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1294 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001295 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001296 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001297
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001298 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001299 return;
1300
Vivien Didelotc91498e2017-06-07 18:12:13 -04001301 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1302 member = GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1303 else if (untagged)
1304 member = GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED;
1305 else
1306 member = GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1307
Vivien Didelotfad09c72016-06-21 12:28:20 -04001308 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001309
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001310 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001311 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001312 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1313 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001314
Vivien Didelot77064f32016-11-04 03:23:30 +01001315 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001316 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1317 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001318
Vivien Didelotfad09c72016-06-21 12:28:20 -04001319 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001320}
1321
Vivien Didelotfad09c72016-06-21 12:28:20 -04001322static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001323 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001324{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001325 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001326 int i, err;
1327
Vivien Didelot567aa592017-05-01 14:05:25 -04001328 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001329 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001330 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001331
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001332 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelotbd00e052017-05-01 14:05:11 -04001333 if (vlan.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001334 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001335
Vivien Didelotbd00e052017-05-01 14:05:11 -04001336 vlan.member[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001337
1338 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001339 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001340 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotbd00e052017-05-01 14:05:11 -04001341 if (vlan.member[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001342 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001343 break;
1344 }
1345 }
1346
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001347 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001348 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001349 return err;
1350
Vivien Didelote606ca32017-03-11 16:12:55 -05001351 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001352}
1353
Vivien Didelotf81ec902016-05-09 13:22:58 -04001354static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1355 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001356{
Vivien Didelot04bed142016-08-31 18:06:13 -04001357 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001358 u16 pvid, vid;
1359 int err = 0;
1360
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001361 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001362 return -EOPNOTSUPP;
1363
Vivien Didelotfad09c72016-06-21 12:28:20 -04001364 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001365
Vivien Didelot77064f32016-11-04 03:23:30 +01001366 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001367 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001368 goto unlock;
1369
Vivien Didelot76e398a2015-11-01 12:33:55 -05001370 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001371 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001372 if (err)
1373 goto unlock;
1374
1375 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001376 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001377 if (err)
1378 goto unlock;
1379 }
1380 }
1381
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001382unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001383 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001384
1385 return err;
1386}
1387
Vivien Didelot83dabd12016-08-31 11:50:04 -04001388static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1389 const unsigned char *addr, u16 vid,
1390 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001391{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001392 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001393 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001394 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001395
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001396 /* Null VLAN ID corresponds to the port private database */
1397 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001398 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001399 else
Vivien Didelot567aa592017-05-01 14:05:25 -04001400 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001401 if (err)
1402 return err;
1403
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001404 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1405 ether_addr_copy(entry.mac, addr);
1406 eth_addr_dec(entry.mac);
1407
1408 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001409 if (err)
1410 return err;
1411
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001412 /* Initialize a fresh ATU entry if it isn't found */
1413 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1414 !ether_addr_equal(entry.mac, addr)) {
1415 memset(&entry, 0, sizeof(entry));
1416 ether_addr_copy(entry.mac, addr);
1417 }
1418
Vivien Didelot88472932016-09-19 19:56:11 -04001419 /* Purge the ATU entry only if no port is using it anymore */
1420 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001421 entry.portvec &= ~BIT(port);
1422 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001423 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1424 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001425 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001426 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001427 }
1428
Vivien Didelot9c13c022017-03-11 16:12:52 -05001429 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001430}
1431
Vivien Didelotf81ec902016-05-09 13:22:58 -04001432static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1433 const struct switchdev_obj_port_fdb *fdb,
1434 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001435{
1436 /* We don't need any dynamic resource from the kernel (yet),
1437 * so skip the prepare phase.
1438 */
1439 return 0;
1440}
1441
Vivien Didelotf81ec902016-05-09 13:22:58 -04001442static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1443 const struct switchdev_obj_port_fdb *fdb,
1444 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001445{
Vivien Didelot04bed142016-08-31 18:06:13 -04001446 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001447
Vivien Didelotfad09c72016-06-21 12:28:20 -04001448 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001449 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1450 GLOBAL_ATU_DATA_STATE_UC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04001451 dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
1452 port);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001453 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001454}
1455
Vivien Didelotf81ec902016-05-09 13:22:58 -04001456static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1457 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001458{
Vivien Didelot04bed142016-08-31 18:06:13 -04001459 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001460 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001461
Vivien Didelotfad09c72016-06-21 12:28:20 -04001462 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001463 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1464 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001465 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001466
Vivien Didelot83dabd12016-08-31 11:50:04 -04001467 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001468}
1469
Vivien Didelot83dabd12016-08-31 11:50:04 -04001470static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1471 u16 fid, u16 vid, int port,
1472 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001473 switchdev_obj_dump_cb_t *cb)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001474{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001475 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001476 int err;
1477
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001478 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1479 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001480
1481 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001482 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001483 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001484 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001485
1486 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1487 break;
1488
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001489 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001490 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001491
Vivien Didelot83dabd12016-08-31 11:50:04 -04001492 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1493 struct switchdev_obj_port_fdb *fdb;
1494
1495 if (!is_unicast_ether_addr(addr.mac))
1496 continue;
1497
1498 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001499 fdb->vid = vid;
1500 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001501 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
1502 fdb->ndm_state = NUD_NOARP;
1503 else
1504 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001505 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1506 struct switchdev_obj_port_mdb *mdb;
1507
1508 if (!is_multicast_ether_addr(addr.mac))
1509 continue;
1510
1511 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1512 mdb->vid = vid;
1513 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001514 } else {
1515 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001516 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001517
1518 err = cb(obj);
1519 if (err)
1520 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001521 } while (!is_broadcast_ether_addr(addr.mac));
1522
1523 return err;
1524}
1525
Vivien Didelot83dabd12016-08-31 11:50:04 -04001526static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1527 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001528 switchdev_obj_dump_cb_t *cb)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001529{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001530 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001531 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001532 };
1533 u16 fid;
1534 int err;
1535
1536 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001537 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001538 if (err)
1539 return err;
1540
1541 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1542 if (err)
1543 return err;
1544
1545 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001546 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001547 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001548 if (err)
1549 return err;
1550
1551 if (!vlan.valid)
1552 break;
1553
1554 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1555 obj, cb);
1556 if (err)
1557 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001558 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001559
1560 return err;
1561}
1562
Vivien Didelotf81ec902016-05-09 13:22:58 -04001563static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1564 struct switchdev_obj_port_fdb *fdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04001565 switchdev_obj_dump_cb_t *cb)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001566{
Vivien Didelot04bed142016-08-31 18:06:13 -04001567 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001568 int err;
1569
Vivien Didelotfad09c72016-06-21 12:28:20 -04001570 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001571 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001572 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001573
1574 return err;
1575}
1576
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001577static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1578 struct net_device *br)
1579{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001580 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001581 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001582 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001583 int err;
1584
1585 /* Remap the Port VLAN of each local bridge group member */
1586 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1587 if (chip->ds->ports[port].bridge_dev == br) {
1588 err = mv88e6xxx_port_vlan_map(chip, port);
1589 if (err)
1590 return err;
1591 }
1592 }
1593
Vivien Didelote96a6e02017-03-30 17:37:13 -04001594 if (!mv88e6xxx_has_pvt(chip))
1595 return 0;
1596
1597 /* Remap the Port VLAN of each cross-chip bridge group member */
1598 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1599 ds = chip->ds->dst->ds[dev];
1600 if (!ds)
1601 break;
1602
1603 for (port = 0; port < ds->num_ports; ++port) {
1604 if (ds->ports[port].bridge_dev == br) {
1605 err = mv88e6xxx_pvt_map(chip, dev, port);
1606 if (err)
1607 return err;
1608 }
1609 }
1610 }
1611
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001612 return 0;
1613}
1614
Vivien Didelotf81ec902016-05-09 13:22:58 -04001615static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001616 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001617{
Vivien Didelot04bed142016-08-31 18:06:13 -04001618 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001619 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001620
Vivien Didelotfad09c72016-06-21 12:28:20 -04001621 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001622 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001623 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001624
Vivien Didelot466dfa02016-02-26 13:16:05 -05001625 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001626}
1627
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001628static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1629 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001630{
Vivien Didelot04bed142016-08-31 18:06:13 -04001631 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001632
Vivien Didelotfad09c72016-06-21 12:28:20 -04001633 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001634 if (mv88e6xxx_bridge_map(chip, br) ||
1635 mv88e6xxx_port_vlan_map(chip, port))
1636 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001637 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001638}
1639
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001640static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1641 int port, struct net_device *br)
1642{
1643 struct mv88e6xxx_chip *chip = ds->priv;
1644 int err;
1645
1646 if (!mv88e6xxx_has_pvt(chip))
1647 return 0;
1648
1649 mutex_lock(&chip->reg_lock);
1650 err = mv88e6xxx_pvt_map(chip, dev, port);
1651 mutex_unlock(&chip->reg_lock);
1652
1653 return err;
1654}
1655
1656static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1657 int port, struct net_device *br)
1658{
1659 struct mv88e6xxx_chip *chip = ds->priv;
1660
1661 if (!mv88e6xxx_has_pvt(chip))
1662 return;
1663
1664 mutex_lock(&chip->reg_lock);
1665 if (mv88e6xxx_pvt_map(chip, dev, port))
1666 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1667 mutex_unlock(&chip->reg_lock);
1668}
1669
Vivien Didelot17e708b2016-12-05 17:30:27 -05001670static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1671{
1672 if (chip->info->ops->reset)
1673 return chip->info->ops->reset(chip);
1674
1675 return 0;
1676}
1677
Vivien Didelot309eca62016-12-05 17:30:26 -05001678static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1679{
1680 struct gpio_desc *gpiod = chip->reset;
1681
1682 /* If there is a GPIO connected to the reset pin, toggle it */
1683 if (gpiod) {
1684 gpiod_set_value_cansleep(gpiod, 1);
1685 usleep_range(10000, 20000);
1686 gpiod_set_value_cansleep(gpiod, 0);
1687 usleep_range(10000, 20000);
1688 }
1689}
1690
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001691static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1692{
1693 int i, err;
1694
1695 /* Set all ports to the Disabled state */
1696 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1697 err = mv88e6xxx_port_set_state(chip, i,
1698 PORT_CONTROL_STATE_DISABLED);
1699 if (err)
1700 return err;
1701 }
1702
1703 /* Wait for transmit queues to drain,
1704 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1705 */
1706 usleep_range(2000, 4000);
1707
1708 return 0;
1709}
1710
Vivien Didelotfad09c72016-06-21 12:28:20 -04001711static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001712{
Vivien Didelota935c052016-09-29 12:21:53 -04001713 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001714
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001715 err = mv88e6xxx_disable_ports(chip);
1716 if (err)
1717 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001718
Vivien Didelot309eca62016-12-05 17:30:26 -05001719 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001720
Vivien Didelot17e708b2016-12-05 17:30:27 -05001721 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001722}
1723
Vivien Didelot43145572017-03-11 16:12:59 -05001724static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1725 enum mv88e6xxx_frame_mode frame, u16 egress,
1726 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001727{
1728 int err;
1729
Vivien Didelot43145572017-03-11 16:12:59 -05001730 if (!chip->info->ops->port_set_frame_mode)
1731 return -EOPNOTSUPP;
1732
1733 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001734 if (err)
1735 return err;
1736
Vivien Didelot43145572017-03-11 16:12:59 -05001737 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1738 if (err)
1739 return err;
1740
1741 if (chip->info->ops->port_set_ether_type)
1742 return chip->info->ops->port_set_ether_type(chip, port, etype);
1743
1744 return 0;
1745}
1746
1747static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1748{
1749 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1750 PORT_CONTROL_EGRESS_UNMODIFIED,
1751 PORT_ETH_TYPE_DEFAULT);
1752}
1753
1754static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1755{
1756 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1757 PORT_CONTROL_EGRESS_UNMODIFIED,
1758 PORT_ETH_TYPE_DEFAULT);
1759}
1760
1761static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1762{
1763 return mv88e6xxx_set_port_mode(chip, port,
1764 MV88E6XXX_FRAME_MODE_ETHERTYPE,
1765 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
1766}
1767
1768static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1769{
1770 if (dsa_is_dsa_port(chip->ds, port))
1771 return mv88e6xxx_set_port_mode_dsa(chip, port);
1772
1773 if (dsa_is_normal_port(chip->ds, port))
1774 return mv88e6xxx_set_port_mode_normal(chip, port);
1775
1776 /* Setup CPU port mode depending on its supported tag format */
1777 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1778 return mv88e6xxx_set_port_mode_dsa(chip, port);
1779
1780 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1781 return mv88e6xxx_set_port_mode_edsa(chip, port);
1782
1783 return -EINVAL;
1784}
1785
Vivien Didelotea698f42017-03-11 16:12:50 -05001786static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1787{
1788 bool message = dsa_is_dsa_port(chip->ds, port);
1789
1790 return mv88e6xxx_port_set_message_port(chip, port, message);
1791}
1792
Vivien Didelot601aeed2017-03-11 16:13:00 -05001793static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1794{
1795 bool flood = port == dsa_upstream_port(chip->ds);
1796
1797 /* Upstream ports flood frames with unknown unicast or multicast DA */
1798 if (chip->info->ops->port_set_egress_floods)
1799 return chip->info->ops->port_set_egress_floods(chip, port,
1800 flood, flood);
1801
1802 return 0;
1803}
1804
Andrew Lunn6d917822017-05-26 01:03:21 +02001805static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1806 bool on)
1807{
Vivien Didelot523a8902017-05-26 18:02:42 -04001808 if (chip->info->ops->serdes_power)
1809 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001810
Vivien Didelot523a8902017-05-26 18:02:42 -04001811 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001812}
1813
Vivien Didelotfad09c72016-06-21 12:28:20 -04001814static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001815{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001816 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001817 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001818 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001819
Vivien Didelotd78343d2016-11-04 03:23:36 +01001820 /* MAC Forcing register: don't force link, speed, duplex or flow control
1821 * state to any particular values on physical ports, but force the CPU
1822 * port and all DSA ports to their maximum bandwidth and full duplex.
1823 */
1824 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1825 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1826 SPEED_MAX, DUPLEX_FULL,
1827 PHY_INTERFACE_MODE_NA);
1828 else
1829 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1830 SPEED_UNFORCED, DUPLEX_UNFORCED,
1831 PHY_INTERFACE_MODE_NA);
1832 if (err)
1833 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001834
1835 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1836 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1837 * tunneling, determine priority by looking at 802.1p and IP
1838 * priority fields (IP prio has precedence), and set STP state
1839 * to Forwarding.
1840 *
1841 * If this is the CPU link, use DSA or EDSA tagging depending
1842 * on which tagging mode was configured.
1843 *
1844 * If this is a link to another switch, use DSA tagging mode.
1845 *
1846 * If this is the upstream port for this switch, enable
1847 * forwarding of unknown unicasts and multicasts.
1848 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01001849 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02001850 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
1851 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01001852 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
1853 if (err)
1854 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001855
Vivien Didelot601aeed2017-03-11 16:13:00 -05001856 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001857 if (err)
1858 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001859
Vivien Didelot601aeed2017-03-11 16:13:00 -05001860 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001861 if (err)
1862 return err;
1863
Andrew Lunn04aca992017-05-26 01:03:24 +02001864 /* Enable the SERDES interface for DSA and CPU ports. Normal
1865 * ports SERDES are enabled when the port is enabled, thus
1866 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001867 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001868 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1869 err = mv88e6xxx_serdes_power(chip, port, true);
1870 if (err)
1871 return err;
1872 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001873
Vivien Didelot8efdda42015-08-13 12:52:23 -04001874 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001875 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001876 * untagged frames on this port, do a destination address lookup on all
1877 * received packets as usual, disable ARP mirroring and don't send a
1878 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001879 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001880 err = mv88e6xxx_port_set_map_da(chip, port);
1881 if (err)
1882 return err;
1883
Andrew Lunn54d792f2015-05-06 01:09:47 +02001884 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01001885 if (chip->info->ops->port_set_upstream_port) {
1886 err = chip->info->ops->port_set_upstream_port(
1887 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001888 if (err)
1889 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001890 }
1891
Andrew Lunna23b2962017-02-04 20:15:28 +01001892 err = mv88e6xxx_port_set_8021q_mode(chip, port,
1893 PORT_CONTROL_2_8021Q_DISABLED);
1894 if (err)
1895 return err;
1896
Andrew Lunn5f436662016-12-03 04:45:17 +01001897 if (chip->info->ops->port_jumbo_config) {
1898 err = chip->info->ops->port_jumbo_config(chip, port);
1899 if (err)
1900 return err;
1901 }
1902
Andrew Lunn54d792f2015-05-06 01:09:47 +02001903 /* Port Association Vector: when learning source addresses
1904 * of packets, add the address to the address database using
1905 * a port bitmap that has only the bit for this port set and
1906 * the other bits clear.
1907 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001908 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001909 /* Disable learning for CPU port */
1910 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001911 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001912
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001913 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
1914 if (err)
1915 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001916
1917 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001918 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
1919 if (err)
1920 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001921
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001922 if (chip->info->ops->port_pause_config) {
1923 err = chip->info->ops->port_pause_config(chip, port);
1924 if (err)
1925 return err;
1926 }
1927
Vivien Didelotc8c94892017-03-11 16:13:01 -05001928 if (chip->info->ops->port_disable_learn_limit) {
1929 err = chip->info->ops->port_disable_learn_limit(chip, port);
1930 if (err)
1931 return err;
1932 }
1933
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001934 if (chip->info->ops->port_disable_pri_override) {
1935 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001936 if (err)
1937 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01001938 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02001939
Andrew Lunnef0a7312016-12-03 04:35:16 +01001940 if (chip->info->ops->port_tag_remap) {
1941 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001942 if (err)
1943 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001944 }
1945
Andrew Lunnef70b112016-12-03 04:45:18 +01001946 if (chip->info->ops->port_egress_rate_limiting) {
1947 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001948 if (err)
1949 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001950 }
1951
Vivien Didelotea698f42017-03-11 16:12:50 -05001952 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001953 if (err)
1954 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001955
Vivien Didelot207afda2016-04-14 14:42:09 -04001956 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001957 * database, and allow bidirectional communication between the
1958 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07001959 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001960 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001961 if (err)
1962 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001963
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001964 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001965 if (err)
1966 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001967
1968 /* Default VLAN ID and priority: don't set a default VLAN
1969 * ID, and set the default packet priority to zero.
1970 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001971 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02001972}
1973
Andrew Lunn04aca992017-05-26 01:03:24 +02001974static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
1975 struct phy_device *phydev)
1976{
1977 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04001978 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02001979
1980 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001981 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02001982 mutex_unlock(&chip->reg_lock);
1983
1984 return err;
1985}
1986
1987static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
1988 struct phy_device *phydev)
1989{
1990 struct mv88e6xxx_chip *chip = ds->priv;
1991
1992 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001993 if (mv88e6xxx_serdes_power(chip, port, false))
1994 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02001995 mutex_unlock(&chip->reg_lock);
1996}
1997
Wei Yongjunaa0938c2016-10-18 15:53:37 +00001998static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04001999{
2000 int err;
2001
Vivien Didelota935c052016-09-29 12:21:53 -04002002 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002003 if (err)
2004 return err;
2005
Vivien Didelota935c052016-09-29 12:21:53 -04002006 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002007 if (err)
2008 return err;
2009
Vivien Didelota935c052016-09-29 12:21:53 -04002010 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2011 if (err)
2012 return err;
2013
2014 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002015}
2016
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002017static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2018 unsigned int ageing_time)
2019{
Vivien Didelot04bed142016-08-31 18:06:13 -04002020 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002021 int err;
2022
2023 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002024 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002025 mutex_unlock(&chip->reg_lock);
2026
2027 return err;
2028}
2029
Vivien Didelot97299342016-07-18 20:45:30 -04002030static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002031{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002032 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002033 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002034 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002035
Andrew Lunn33641992016-12-03 04:35:17 +01002036 if (chip->info->ops->g1_set_cpu_port) {
2037 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2038 if (err)
2039 return err;
2040 }
2041
2042 if (chip->info->ops->g1_set_egress_port) {
2043 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2044 if (err)
2045 return err;
2046 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002047
Vivien Didelot50484ff2016-05-09 13:22:54 -04002048 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002049 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2050 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2051 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002052 if (err)
2053 return err;
2054
Vivien Didelot08a01262016-05-09 13:22:50 -04002055 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002056 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002057 if (err)
2058 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002059 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002060 if (err)
2061 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002062 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002063 if (err)
2064 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002065 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002066 if (err)
2067 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002068 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002069 if (err)
2070 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002071 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002072 if (err)
2073 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002074 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002075 if (err)
2076 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002077 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002078 if (err)
2079 return err;
2080
2081 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002082 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002083 if (err)
2084 return err;
2085
Andrew Lunnde2273872016-11-21 23:27:01 +01002086 /* Initialize the statistics unit */
2087 err = mv88e6xxx_stats_set_histogram(chip);
2088 if (err)
2089 return err;
2090
Vivien Didelot97299342016-07-18 20:45:30 -04002091 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002092 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2093 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002094 if (err)
2095 return err;
2096
2097 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002098 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002099 if (err)
2100 return err;
2101
2102 return 0;
2103}
2104
Vivien Didelotf81ec902016-05-09 13:22:58 -04002105static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002106{
Vivien Didelot04bed142016-08-31 18:06:13 -04002107 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002108 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002109 int i;
2110
Vivien Didelotfad09c72016-06-21 12:28:20 -04002111 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002112 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002113
Vivien Didelotfad09c72016-06-21 12:28:20 -04002114 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002115
Vivien Didelot97299342016-07-18 20:45:30 -04002116 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002117 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002118 err = mv88e6xxx_setup_port(chip, i);
2119 if (err)
2120 goto unlock;
2121 }
2122
2123 /* Setup Switch Global 1 Registers */
2124 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002125 if (err)
2126 goto unlock;
2127
Vivien Didelot97299342016-07-18 20:45:30 -04002128 /* Setup Switch Global 2 Registers */
2129 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2130 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002131 if (err)
2132 goto unlock;
2133 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002134
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002135 err = mv88e6xxx_phy_setup(chip);
2136 if (err)
2137 goto unlock;
2138
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002139 err = mv88e6xxx_vtu_setup(chip);
2140 if (err)
2141 goto unlock;
2142
Vivien Didelot81228992017-03-30 17:37:08 -04002143 err = mv88e6xxx_pvt_setup(chip);
2144 if (err)
2145 goto unlock;
2146
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002147 err = mv88e6xxx_atu_setup(chip);
2148 if (err)
2149 goto unlock;
2150
Andrew Lunn6e55f692016-12-03 04:45:16 +01002151 /* Some generations have the configuration of sending reserved
2152 * management frames to the CPU in global2, others in
2153 * global1. Hence it does not fit the two setup functions
2154 * above.
2155 */
2156 if (chip->info->ops->mgmt_rsvd2cpu) {
2157 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2158 if (err)
2159 goto unlock;
2160 }
2161
Vivien Didelot6b17e862015-08-13 12:52:18 -04002162unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002163 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002164
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002165 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002166}
2167
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002168static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2169{
Vivien Didelot04bed142016-08-31 18:06:13 -04002170 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002171 int err;
2172
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002173 if (!chip->info->ops->set_switch_mac)
2174 return -EOPNOTSUPP;
2175
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002176 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002177 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002178 mutex_unlock(&chip->reg_lock);
2179
2180 return err;
2181}
2182
Vivien Didelote57e5e72016-08-15 17:19:00 -04002183static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002184{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002185 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2186 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002187 u16 val;
2188 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002189
Andrew Lunnee26a222017-01-24 14:53:48 +01002190 if (!chip->info->ops->phy_read)
2191 return -EOPNOTSUPP;
2192
Vivien Didelotfad09c72016-06-21 12:28:20 -04002193 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002194 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002195 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002196
Andrew Lunnda9f3302017-02-01 03:40:05 +01002197 if (reg == MII_PHYSID2) {
2198 /* Some internal PHYS don't have a model number. Use
2199 * the mv88e6390 family model number instead.
2200 */
2201 if (!(val & 0x3f0))
2202 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2203 }
2204
Vivien Didelote57e5e72016-08-15 17:19:00 -04002205 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002206}
2207
Vivien Didelote57e5e72016-08-15 17:19:00 -04002208static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002209{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002210 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2211 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002212 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002213
Andrew Lunnee26a222017-01-24 14:53:48 +01002214 if (!chip->info->ops->phy_write)
2215 return -EOPNOTSUPP;
2216
Vivien Didelotfad09c72016-06-21 12:28:20 -04002217 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002218 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002219 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002220
2221 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002222}
2223
Vivien Didelotfad09c72016-06-21 12:28:20 -04002224static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002225 struct device_node *np,
2226 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002227{
2228 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002229 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002230 struct mii_bus *bus;
2231 int err;
2232
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002233 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002234 if (!bus)
2235 return -ENOMEM;
2236
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002237 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002238 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002239 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002240 INIT_LIST_HEAD(&mdio_bus->list);
2241 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002242
Andrew Lunnb516d452016-06-04 21:17:06 +02002243 if (np) {
2244 bus->name = np->full_name;
2245 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2246 } else {
2247 bus->name = "mv88e6xxx SMI";
2248 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2249 }
2250
2251 bus->read = mv88e6xxx_mdio_read;
2252 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002253 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002254
Andrew Lunna3c53be52017-01-24 14:53:50 +01002255 if (np)
2256 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002257 else
2258 err = mdiobus_register(bus);
2259 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002260 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002261 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002262 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002263
2264 if (external)
2265 list_add_tail(&mdio_bus->list, &chip->mdios);
2266 else
2267 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002268
2269 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002270}
2271
Andrew Lunna3c53be52017-01-24 14:53:50 +01002272static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2273 { .compatible = "marvell,mv88e6xxx-mdio-external",
2274 .data = (void *)true },
2275 { },
2276};
2277
2278static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2279 struct device_node *np)
2280{
2281 const struct of_device_id *match;
2282 struct device_node *child;
2283 int err;
2284
2285 /* Always register one mdio bus for the internal/default mdio
2286 * bus. This maybe represented in the device tree, but is
2287 * optional.
2288 */
2289 child = of_get_child_by_name(np, "mdio");
2290 err = mv88e6xxx_mdio_register(chip, child, false);
2291 if (err)
2292 return err;
2293
2294 /* Walk the device tree, and see if there are any other nodes
2295 * which say they are compatible with the external mdio
2296 * bus.
2297 */
2298 for_each_available_child_of_node(np, child) {
2299 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2300 if (match) {
2301 err = mv88e6xxx_mdio_register(chip, child, true);
2302 if (err)
2303 return err;
2304 }
2305 }
2306
2307 return 0;
2308}
2309
2310static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002311
2312{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002313 struct mv88e6xxx_mdio_bus *mdio_bus;
2314 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002315
Andrew Lunna3c53be52017-01-24 14:53:50 +01002316 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2317 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002318
Andrew Lunna3c53be52017-01-24 14:53:50 +01002319 mdiobus_unregister(bus);
2320 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002321}
2322
Vivien Didelot855b1932016-07-20 18:18:35 -04002323static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2324{
Vivien Didelot04bed142016-08-31 18:06:13 -04002325 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002326
2327 return chip->eeprom_len;
2328}
2329
Vivien Didelot855b1932016-07-20 18:18:35 -04002330static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2331 struct ethtool_eeprom *eeprom, u8 *data)
2332{
Vivien Didelot04bed142016-08-31 18:06:13 -04002333 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002334 int err;
2335
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002336 if (!chip->info->ops->get_eeprom)
2337 return -EOPNOTSUPP;
2338
Vivien Didelot855b1932016-07-20 18:18:35 -04002339 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002340 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002341 mutex_unlock(&chip->reg_lock);
2342
2343 if (err)
2344 return err;
2345
2346 eeprom->magic = 0xc3ec4951;
2347
2348 return 0;
2349}
2350
Vivien Didelot855b1932016-07-20 18:18:35 -04002351static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2352 struct ethtool_eeprom *eeprom, u8 *data)
2353{
Vivien Didelot04bed142016-08-31 18:06:13 -04002354 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002355 int err;
2356
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002357 if (!chip->info->ops->set_eeprom)
2358 return -EOPNOTSUPP;
2359
Vivien Didelot855b1932016-07-20 18:18:35 -04002360 if (eeprom->magic != 0xc3ec4951)
2361 return -EINVAL;
2362
2363 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002364 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002365 mutex_unlock(&chip->reg_lock);
2366
2367 return err;
2368}
2369
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002370static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002371 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002372 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002373 .phy_read = mv88e6185_phy_ppu_read,
2374 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002375 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002376 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002377 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002378 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002379 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002380 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002381 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002382 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002383 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002384 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002385 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002386 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002387 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2388 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002389 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002390 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2391 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002392 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002393 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002394 .ppu_enable = mv88e6185_g1_ppu_enable,
2395 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002396 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002397 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002398 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002399};
2400
2401static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002402 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002403 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002404 .phy_read = mv88e6185_phy_ppu_read,
2405 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002406 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002407 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002408 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002409 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002410 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002411 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002412 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002413 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2414 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002415 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002416 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002417 .ppu_enable = mv88e6185_g1_ppu_enable,
2418 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002419 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002420 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002421 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002422};
2423
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002424static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002425 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002426 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2427 .phy_read = mv88e6xxx_g2_smi_phy_read,
2428 .phy_write = mv88e6xxx_g2_smi_phy_write,
2429 .port_set_link = mv88e6xxx_port_set_link,
2430 .port_set_duplex = mv88e6xxx_port_set_duplex,
2431 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002432 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002433 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002434 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002435 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002436 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002437 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002438 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002439 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002440 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002441 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2442 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2443 .stats_get_strings = mv88e6095_stats_get_strings,
2444 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002445 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2446 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002447 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002448 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002449 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002450 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002451 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002452};
2453
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002454static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002455 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002456 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002457 .phy_read = mv88e6xxx_g2_smi_phy_read,
2458 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002459 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002460 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002461 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002462 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002463 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002464 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002465 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002466 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002467 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2468 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002469 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002470 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2471 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002472 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002473 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002474 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002475 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002476 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002477};
2478
2479static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002480 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002481 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002482 .phy_read = mv88e6185_phy_ppu_read,
2483 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002484 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002485 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002486 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002487 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002488 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002489 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002490 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002491 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002492 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002493 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002494 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002495 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002496 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2497 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002498 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002499 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2500 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002501 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002502 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002503 .ppu_enable = mv88e6185_g1_ppu_enable,
2504 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002505 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002506 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002507 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002508};
2509
Vivien Didelot990e27b2017-03-28 13:50:32 -04002510static const struct mv88e6xxx_ops mv88e6141_ops = {
2511 /* MV88E6XXX_FAMILY_6341 */
2512 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2513 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2514 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2515 .phy_read = mv88e6xxx_g2_smi_phy_read,
2516 .phy_write = mv88e6xxx_g2_smi_phy_write,
2517 .port_set_link = mv88e6xxx_port_set_link,
2518 .port_set_duplex = mv88e6xxx_port_set_duplex,
2519 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2520 .port_set_speed = mv88e6390_port_set_speed,
2521 .port_tag_remap = mv88e6095_port_tag_remap,
2522 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2523 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2524 .port_set_ether_type = mv88e6351_port_set_ether_type,
2525 .port_jumbo_config = mv88e6165_port_jumbo_config,
2526 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2527 .port_pause_config = mv88e6097_port_pause_config,
2528 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2529 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2530 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2531 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2532 .stats_get_strings = mv88e6320_stats_get_strings,
2533 .stats_get_stats = mv88e6390_stats_get_stats,
2534 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2535 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2536 .watchdog_ops = &mv88e6390_watchdog_ops,
2537 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2538 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002539 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002540 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002541};
2542
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002543static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002544 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002545 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002546 .phy_read = mv88e6xxx_g2_smi_phy_read,
2547 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002548 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002549 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002550 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002551 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002552 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002553 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002554 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002555 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002556 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002557 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002558 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002559 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002560 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002561 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2562 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002563 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002564 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2565 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002566 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002567 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002568 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002569 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002570 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002571};
2572
2573static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002574 /* MV88E6XXX_FAMILY_6165 */
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,
Andrew Lunn33641992016-12-03 04:35:17 +01002587 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2588 .g1_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 Didelotb073d4e2016-09-29 12:22:01 -04002598 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002599 .phy_read = mv88e6xxx_g2_smi_phy_read,
2600 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002601 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002602 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002603 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002604 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002605 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002606 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002607 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002608 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002609 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002610 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002611 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002612 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002613 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002614 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002615 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2616 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002617 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002618 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2619 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002620 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002621 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002622 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002623 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002624 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002625};
2626
2627static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002628 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002629 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2630 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002631 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002632 .phy_read = mv88e6xxx_g2_smi_phy_read,
2633 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002634 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002635 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002636 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002637 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002638 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002639 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002640 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002641 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002642 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002643 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002644 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002645 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002646 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002647 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002648 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2649 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002650 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002651 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2652 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002653 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002654 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002655 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002656 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002657 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002658 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002659};
2660
2661static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002662 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002663 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002664 .phy_read = mv88e6xxx_g2_smi_phy_read,
2665 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002666 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002667 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002668 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002669 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002670 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002671 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002672 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002673 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002674 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002675 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002676 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002677 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002678 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002679 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002680 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2681 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002682 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002683 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2684 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002685 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002686 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002687 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002688 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002689 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002690};
2691
2692static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002693 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002694 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2695 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002696 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002697 .phy_read = mv88e6xxx_g2_smi_phy_read,
2698 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002699 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002700 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002701 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002702 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002703 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002704 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002705 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002706 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002707 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002708 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002709 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002710 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002711 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002712 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002713 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2714 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002715 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002716 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2717 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002718 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002719 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002720 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002721 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002722 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002723 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002724};
2725
2726static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002727 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002728 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002729 .phy_read = mv88e6185_phy_ppu_read,
2730 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002731 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002732 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002733 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002734 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002735 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002736 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002737 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002738 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002739 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2740 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002741 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002742 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2743 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002744 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002745 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002746 .ppu_enable = mv88e6185_g1_ppu_enable,
2747 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002748 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002749 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002750 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002751};
2752
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002753static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002754 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002755 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2756 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002757 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2758 .phy_read = mv88e6xxx_g2_smi_phy_read,
2759 .phy_write = mv88e6xxx_g2_smi_phy_write,
2760 .port_set_link = mv88e6xxx_port_set_link,
2761 .port_set_duplex = mv88e6xxx_port_set_duplex,
2762 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2763 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002764 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002765 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002766 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002767 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002768 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002769 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002770 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002771 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002772 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002773 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2774 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002775 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002776 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2777 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002778 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002779 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002780 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002781 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2782 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002783 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002784};
2785
2786static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002787 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002788 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2789 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002790 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2791 .phy_read = mv88e6xxx_g2_smi_phy_read,
2792 .phy_write = mv88e6xxx_g2_smi_phy_write,
2793 .port_set_link = mv88e6xxx_port_set_link,
2794 .port_set_duplex = mv88e6xxx_port_set_duplex,
2795 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2796 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002797 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002798 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002799 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002800 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002801 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002802 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002803 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002804 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002805 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002806 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2807 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002808 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002809 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2810 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002811 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002812 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002813 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002814 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2815 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002816 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002817};
2818
2819static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002820 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002821 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2822 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002823 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2824 .phy_read = mv88e6xxx_g2_smi_phy_read,
2825 .phy_write = mv88e6xxx_g2_smi_phy_write,
2826 .port_set_link = mv88e6xxx_port_set_link,
2827 .port_set_duplex = mv88e6xxx_port_set_duplex,
2828 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2829 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002830 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002831 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002832 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002833 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002834 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002835 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002836 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002837 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002838 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002839 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2840 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002841 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002842 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2843 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002844 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002845 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002846 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002847 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2848 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002849 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002850};
2851
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002852static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002853 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002854 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2855 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002856 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002857 .phy_read = mv88e6xxx_g2_smi_phy_read,
2858 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002859 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002860 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002861 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002862 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002863 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002864 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002865 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002866 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002867 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002868 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002869 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002870 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002871 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002872 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002873 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2874 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002875 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002876 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2877 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002878 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002879 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002880 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002881 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002882 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002883 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002884};
2885
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002886static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002887 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002888 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2889 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002890 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2891 .phy_read = mv88e6xxx_g2_smi_phy_read,
2892 .phy_write = mv88e6xxx_g2_smi_phy_write,
2893 .port_set_link = mv88e6xxx_port_set_link,
2894 .port_set_duplex = mv88e6xxx_port_set_duplex,
2895 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2896 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002897 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002898 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002899 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002900 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002901 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002902 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002903 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002904 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002905 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002906 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002907 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2908 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002909 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002910 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2911 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002912 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002913 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002914 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002915 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2916 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002917 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002918};
2919
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002920static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002921 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002922 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2923 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002924 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002925 .phy_read = mv88e6xxx_g2_smi_phy_read,
2926 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002927 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002928 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002929 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002930 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002931 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002932 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002933 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002934 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002935 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002936 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002937 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002938 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002939 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002940 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2941 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002942 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002943 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2944 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002945 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002946 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002947 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002948 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002949};
2950
2951static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002952 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002953 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2954 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002955 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002956 .phy_read = mv88e6xxx_g2_smi_phy_read,
2957 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002958 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002959 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002960 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002961 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002962 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002963 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002964 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002965 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002966 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002967 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002968 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002969 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002970 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002971 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2972 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002973 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002974 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2975 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002976 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002977 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002978 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002979};
2980
Vivien Didelot16e329a2017-03-28 13:50:33 -04002981static const struct mv88e6xxx_ops mv88e6341_ops = {
2982 /* MV88E6XXX_FAMILY_6341 */
2983 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2984 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2985 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2986 .phy_read = mv88e6xxx_g2_smi_phy_read,
2987 .phy_write = mv88e6xxx_g2_smi_phy_write,
2988 .port_set_link = mv88e6xxx_port_set_link,
2989 .port_set_duplex = mv88e6xxx_port_set_duplex,
2990 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2991 .port_set_speed = mv88e6390_port_set_speed,
2992 .port_tag_remap = mv88e6095_port_tag_remap,
2993 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2994 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2995 .port_set_ether_type = mv88e6351_port_set_ether_type,
2996 .port_jumbo_config = mv88e6165_port_jumbo_config,
2997 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2998 .port_pause_config = mv88e6097_port_pause_config,
2999 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3000 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3001 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3002 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3003 .stats_get_strings = mv88e6320_stats_get_strings,
3004 .stats_get_stats = mv88e6390_stats_get_stats,
3005 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3006 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3007 .watchdog_ops = &mv88e6390_watchdog_ops,
3008 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3009 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003010 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003011 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003012};
3013
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003014static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003015 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003016 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003017 .phy_read = mv88e6xxx_g2_smi_phy_read,
3018 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003019 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003020 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003021 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003022 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003023 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003024 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003025 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003026 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003027 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003028 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003029 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003030 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003031 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003032 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003033 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3034 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003035 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003036 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3037 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003038 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003039 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003040 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003041 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003042 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003043};
3044
3045static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003046 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003047 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003048 .phy_read = mv88e6xxx_g2_smi_phy_read,
3049 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003050 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003051 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003052 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003053 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003054 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003055 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003056 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003057 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003058 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003059 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003060 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003061 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003062 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003063 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003064 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3065 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003066 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003067 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3068 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003069 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003070 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003071 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003072 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003073 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003074};
3075
3076static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003077 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003078 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3079 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003080 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003081 .phy_read = mv88e6xxx_g2_smi_phy_read,
3082 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003083 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003084 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003085 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003086 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003087 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003088 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003089 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003090 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003091 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003092 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003093 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003094 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003095 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003096 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003097 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3098 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003099 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003100 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3101 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003102 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003103 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003104 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003105 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003106 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003107 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003108};
3109
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003110static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003111 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003112 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3113 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003114 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3115 .phy_read = mv88e6xxx_g2_smi_phy_read,
3116 .phy_write = mv88e6xxx_g2_smi_phy_write,
3117 .port_set_link = mv88e6xxx_port_set_link,
3118 .port_set_duplex = mv88e6xxx_port_set_duplex,
3119 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3120 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003121 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003122 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003123 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003124 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003125 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003126 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003127 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003128 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003129 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003130 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003131 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003132 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003133 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3134 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003135 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003136 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3137 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003138 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003139 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003140 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003141 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3142 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003143 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003144};
3145
3146static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003147 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003148 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3149 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003150 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3151 .phy_read = mv88e6xxx_g2_smi_phy_read,
3152 .phy_write = mv88e6xxx_g2_smi_phy_write,
3153 .port_set_link = mv88e6xxx_port_set_link,
3154 .port_set_duplex = mv88e6xxx_port_set_duplex,
3155 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3156 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003157 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003158 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003159 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003160 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003161 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003162 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003163 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003164 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003165 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003166 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003167 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003168 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3169 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003170 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003171 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3172 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003173 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003174 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003175 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003176 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3177 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003178 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003179};
3180
Vivien Didelotf81ec902016-05-09 13:22:58 -04003181static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3182 [MV88E6085] = {
3183 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3184 .family = MV88E6XXX_FAMILY_6097,
3185 .name = "Marvell 88E6085",
3186 .num_databases = 4096,
3187 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003188 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003189 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003190 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003191 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003192 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003193 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003194 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003195 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003196 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003197 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003198 },
3199
3200 [MV88E6095] = {
3201 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3202 .family = MV88E6XXX_FAMILY_6095,
3203 .name = "Marvell 88E6095/88E6095F",
3204 .num_databases = 256,
3205 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003206 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003207 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003208 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003209 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003210 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003211 .atu_move_port_mask = 0xf,
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_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003214 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003215 },
3216
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003217 [MV88E6097] = {
3218 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3219 .family = MV88E6XXX_FAMILY_6097,
3220 .name = "Marvell 88E6097/88E6097F",
3221 .num_databases = 4096,
3222 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003223 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003224 .port_base_addr = 0x10,
3225 .global1_addr = 0x1b,
3226 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003227 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003228 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003229 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003230 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003231 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3232 .ops = &mv88e6097_ops,
3233 },
3234
Vivien Didelotf81ec902016-05-09 13:22:58 -04003235 [MV88E6123] = {
3236 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3237 .family = MV88E6XXX_FAMILY_6165,
3238 .name = "Marvell 88E6123",
3239 .num_databases = 4096,
3240 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003241 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003242 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003243 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003244 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003245 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003246 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003247 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003248 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003249 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003250 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003251 },
3252
3253 [MV88E6131] = {
3254 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3255 .family = MV88E6XXX_FAMILY_6185,
3256 .name = "Marvell 88E6131",
3257 .num_databases = 256,
3258 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003259 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003260 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003261 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003262 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003263 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003264 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003265 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003266 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003267 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003268 },
3269
Vivien Didelot990e27b2017-03-28 13:50:32 -04003270 [MV88E6141] = {
3271 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3272 .family = MV88E6XXX_FAMILY_6341,
3273 .name = "Marvell 88E6341",
3274 .num_databases = 4096,
3275 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003276 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003277 .port_base_addr = 0x10,
3278 .global1_addr = 0x1b,
3279 .age_time_coeff = 3750,
3280 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003281 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003282 .tag_protocol = DSA_TAG_PROTO_EDSA,
3283 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3284 .ops = &mv88e6141_ops,
3285 },
3286
Vivien Didelotf81ec902016-05-09 13:22:58 -04003287 [MV88E6161] = {
3288 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3289 .family = MV88E6XXX_FAMILY_6165,
3290 .name = "Marvell 88E6161",
3291 .num_databases = 4096,
3292 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003293 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003294 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003295 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003296 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003297 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003298 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003299 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003300 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003301 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003302 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003303 },
3304
3305 [MV88E6165] = {
3306 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3307 .family = MV88E6XXX_FAMILY_6165,
3308 .name = "Marvell 88E6165",
3309 .num_databases = 4096,
3310 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003311 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003312 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003313 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003314 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003315 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003316 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003317 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003318 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003319 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003320 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003321 },
3322
3323 [MV88E6171] = {
3324 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3325 .family = MV88E6XXX_FAMILY_6351,
3326 .name = "Marvell 88E6171",
3327 .num_databases = 4096,
3328 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003329 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003330 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003331 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003332 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003333 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003334 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003335 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003336 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003337 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003338 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003339 },
3340
3341 [MV88E6172] = {
3342 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3343 .family = MV88E6XXX_FAMILY_6352,
3344 .name = "Marvell 88E6172",
3345 .num_databases = 4096,
3346 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003347 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003348 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003349 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003350 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003351 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003352 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003353 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003354 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003355 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003356 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003357 },
3358
3359 [MV88E6175] = {
3360 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3361 .family = MV88E6XXX_FAMILY_6351,
3362 .name = "Marvell 88E6175",
3363 .num_databases = 4096,
3364 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003365 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003366 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003367 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003368 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003369 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003370 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003371 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003372 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003373 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003374 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003375 },
3376
3377 [MV88E6176] = {
3378 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3379 .family = MV88E6XXX_FAMILY_6352,
3380 .name = "Marvell 88E6176",
3381 .num_databases = 4096,
3382 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003383 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003384 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003385 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003386 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003387 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003388 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003389 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003390 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003391 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003392 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003393 },
3394
3395 [MV88E6185] = {
3396 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3397 .family = MV88E6XXX_FAMILY_6185,
3398 .name = "Marvell 88E6185",
3399 .num_databases = 256,
3400 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003401 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003402 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003403 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003404 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003405 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003406 .atu_move_port_mask = 0xf,
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_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003409 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003410 },
3411
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003412 [MV88E6190] = {
3413 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3414 .family = MV88E6XXX_FAMILY_6390,
3415 .name = "Marvell 88E6190",
3416 .num_databases = 4096,
3417 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003418 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003419 .port_base_addr = 0x0,
3420 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003421 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003422 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003423 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003424 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003425 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003426 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3427 .ops = &mv88e6190_ops,
3428 },
3429
3430 [MV88E6190X] = {
3431 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3432 .family = MV88E6XXX_FAMILY_6390,
3433 .name = "Marvell 88E6190X",
3434 .num_databases = 4096,
3435 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003436 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003437 .port_base_addr = 0x0,
3438 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003439 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003440 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003441 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003442 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003443 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003444 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3445 .ops = &mv88e6190x_ops,
3446 },
3447
3448 [MV88E6191] = {
3449 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3450 .family = MV88E6XXX_FAMILY_6390,
3451 .name = "Marvell 88E6191",
3452 .num_databases = 4096,
3453 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003454 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003455 .port_base_addr = 0x0,
3456 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003457 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003458 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003459 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003460 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003461 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003462 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003463 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003464 },
3465
Vivien Didelotf81ec902016-05-09 13:22:58 -04003466 [MV88E6240] = {
3467 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3468 .family = MV88E6XXX_FAMILY_6352,
3469 .name = "Marvell 88E6240",
3470 .num_databases = 4096,
3471 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003472 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003473 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003474 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003475 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003476 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003477 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003478 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003479 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003480 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003481 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003482 },
3483
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003484 [MV88E6290] = {
3485 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3486 .family = MV88E6XXX_FAMILY_6390,
3487 .name = "Marvell 88E6290",
3488 .num_databases = 4096,
3489 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003490 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003491 .port_base_addr = 0x0,
3492 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003493 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003494 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003495 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003496 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003497 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003498 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3499 .ops = &mv88e6290_ops,
3500 },
3501
Vivien Didelotf81ec902016-05-09 13:22:58 -04003502 [MV88E6320] = {
3503 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3504 .family = MV88E6XXX_FAMILY_6320,
3505 .name = "Marvell 88E6320",
3506 .num_databases = 4096,
3507 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003508 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003509 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003510 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003511 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003512 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003513 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003514 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003515 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003516 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003517 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003518 },
3519
3520 [MV88E6321] = {
3521 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3522 .family = MV88E6XXX_FAMILY_6320,
3523 .name = "Marvell 88E6321",
3524 .num_databases = 4096,
3525 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003526 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003527 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003528 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003529 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003530 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003531 .atu_move_port_mask = 0xf,
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 = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003535 },
3536
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003537 [MV88E6341] = {
3538 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3539 .family = MV88E6XXX_FAMILY_6341,
3540 .name = "Marvell 88E6341",
3541 .num_databases = 4096,
3542 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003543 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003544 .port_base_addr = 0x10,
3545 .global1_addr = 0x1b,
3546 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003547 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003548 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003549 .tag_protocol = DSA_TAG_PROTO_EDSA,
3550 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3551 .ops = &mv88e6341_ops,
3552 },
3553
Vivien Didelotf81ec902016-05-09 13:22:58 -04003554 [MV88E6350] = {
3555 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3556 .family = MV88E6XXX_FAMILY_6351,
3557 .name = "Marvell 88E6350",
3558 .num_databases = 4096,
3559 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003560 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003561 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003562 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003563 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003564 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003565 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003566 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003567 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003568 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003569 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003570 },
3571
3572 [MV88E6351] = {
3573 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3574 .family = MV88E6XXX_FAMILY_6351,
3575 .name = "Marvell 88E6351",
3576 .num_databases = 4096,
3577 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003578 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003579 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003580 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003581 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003582 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003583 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003584 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003585 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003586 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003587 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003588 },
3589
3590 [MV88E6352] = {
3591 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3592 .family = MV88E6XXX_FAMILY_6352,
3593 .name = "Marvell 88E6352",
3594 .num_databases = 4096,
3595 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003596 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003597 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003598 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003599 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003600 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003601 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003602 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003603 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003604 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003605 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003606 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003607 [MV88E6390] = {
3608 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3609 .family = MV88E6XXX_FAMILY_6390,
3610 .name = "Marvell 88E6390",
3611 .num_databases = 4096,
3612 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003613 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003614 .port_base_addr = 0x0,
3615 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003616 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003617 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003618 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003619 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003620 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003621 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3622 .ops = &mv88e6390_ops,
3623 },
3624 [MV88E6390X] = {
3625 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3626 .family = MV88E6XXX_FAMILY_6390,
3627 .name = "Marvell 88E6390X",
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 = &mv88e6390x_ops,
3640 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003641};
3642
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003643static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003644{
Vivien Didelota439c062016-04-17 13:23:58 -04003645 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003646
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003647 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3648 if (mv88e6xxx_table[i].prod_num == prod_num)
3649 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003650
Vivien Didelotb9b37712015-10-30 19:39:48 -04003651 return NULL;
3652}
3653
Vivien Didelotfad09c72016-06-21 12:28:20 -04003654static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003655{
3656 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003657 unsigned int prod_num, rev;
3658 u16 id;
3659 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003660
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003661 mutex_lock(&chip->reg_lock);
3662 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3663 mutex_unlock(&chip->reg_lock);
3664 if (err)
3665 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003666
3667 prod_num = (id & 0xfff0) >> 4;
3668 rev = id & 0x000f;
3669
3670 info = mv88e6xxx_lookup_info(prod_num);
3671 if (!info)
3672 return -ENODEV;
3673
Vivien Didelotcaac8542016-06-20 13:14:09 -04003674 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003675 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003676
Vivien Didelotca070c12016-09-02 14:45:34 -04003677 err = mv88e6xxx_g2_require(chip);
3678 if (err)
3679 return err;
3680
Vivien Didelotfad09c72016-06-21 12:28:20 -04003681 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3682 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003683
3684 return 0;
3685}
3686
Vivien Didelotfad09c72016-06-21 12:28:20 -04003687static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003688{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003689 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003690
Vivien Didelotfad09c72016-06-21 12:28:20 -04003691 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3692 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003693 return NULL;
3694
Vivien Didelotfad09c72016-06-21 12:28:20 -04003695 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003696
Vivien Didelotfad09c72016-06-21 12:28:20 -04003697 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003698 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003699
Vivien Didelotfad09c72016-06-21 12:28:20 -04003700 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003701}
3702
Vivien Didelotfad09c72016-06-21 12:28:20 -04003703static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003704 struct mii_bus *bus, int sw_addr)
3705{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003706 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003707 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003708 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003709 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003710 else
3711 return -EINVAL;
3712
Vivien Didelotfad09c72016-06-21 12:28:20 -04003713 chip->bus = bus;
3714 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003715
3716 return 0;
3717}
3718
Andrew Lunn7b314362016-08-22 16:01:01 +02003719static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3720{
Vivien Didelot04bed142016-08-31 18:06:13 -04003721 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003722
Andrew Lunn443d5a12016-12-03 04:35:18 +01003723 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003724}
3725
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003726static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3727 struct device *host_dev, int sw_addr,
3728 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003729{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003730 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003731 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003732 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003733
Vivien Didelota439c062016-04-17 13:23:58 -04003734 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003735 if (!bus)
3736 return NULL;
3737
Vivien Didelotfad09c72016-06-21 12:28:20 -04003738 chip = mv88e6xxx_alloc_chip(dsa_dev);
3739 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003740 return NULL;
3741
Vivien Didelotcaac8542016-06-20 13:14:09 -04003742 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003743 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003744
Vivien Didelotfad09c72016-06-21 12:28:20 -04003745 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003746 if (err)
3747 goto free;
3748
Vivien Didelotfad09c72016-06-21 12:28:20 -04003749 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003750 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003751 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003752
Andrew Lunndc30c352016-10-16 19:56:49 +02003753 mutex_lock(&chip->reg_lock);
3754 err = mv88e6xxx_switch_reset(chip);
3755 mutex_unlock(&chip->reg_lock);
3756 if (err)
3757 goto free;
3758
Vivien Didelote57e5e72016-08-15 17:19:00 -04003759 mv88e6xxx_phy_init(chip);
3760
Andrew Lunna3c53be52017-01-24 14:53:50 +01003761 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003762 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003763 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003764
Vivien Didelotfad09c72016-06-21 12:28:20 -04003765 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003766
Vivien Didelotfad09c72016-06-21 12:28:20 -04003767 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003768free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003769 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003770
3771 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003772}
3773
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003774static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3775 const struct switchdev_obj_port_mdb *mdb,
3776 struct switchdev_trans *trans)
3777{
3778 /* We don't need any dynamic resource from the kernel (yet),
3779 * so skip the prepare phase.
3780 */
3781
3782 return 0;
3783}
3784
3785static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3786 const struct switchdev_obj_port_mdb *mdb,
3787 struct switchdev_trans *trans)
3788{
Vivien Didelot04bed142016-08-31 18:06:13 -04003789 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003790
3791 mutex_lock(&chip->reg_lock);
3792 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3793 GLOBAL_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04003794 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
3795 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003796 mutex_unlock(&chip->reg_lock);
3797}
3798
3799static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3800 const struct switchdev_obj_port_mdb *mdb)
3801{
Vivien Didelot04bed142016-08-31 18:06:13 -04003802 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003803 int err;
3804
3805 mutex_lock(&chip->reg_lock);
3806 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3807 GLOBAL_ATU_DATA_STATE_UNUSED);
3808 mutex_unlock(&chip->reg_lock);
3809
3810 return err;
3811}
3812
3813static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3814 struct switchdev_obj_port_mdb *mdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04003815 switchdev_obj_dump_cb_t *cb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003816{
Vivien Didelot04bed142016-08-31 18:06:13 -04003817 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003818 int err;
3819
3820 mutex_lock(&chip->reg_lock);
3821 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3822 mutex_unlock(&chip->reg_lock);
3823
3824 return err;
3825}
3826
Florian Fainellia82f67a2017-01-08 14:52:08 -08003827static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003828 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02003829 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003830 .setup = mv88e6xxx_setup,
3831 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003832 .adjust_link = mv88e6xxx_adjust_link,
3833 .get_strings = mv88e6xxx_get_strings,
3834 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3835 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02003836 .port_enable = mv88e6xxx_port_enable,
3837 .port_disable = mv88e6xxx_port_disable,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003838 .set_eee = mv88e6xxx_set_eee,
3839 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003840 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003841 .get_eeprom = mv88e6xxx_get_eeprom,
3842 .set_eeprom = mv88e6xxx_set_eeprom,
3843 .get_regs_len = mv88e6xxx_get_regs_len,
3844 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003845 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003846 .port_bridge_join = mv88e6xxx_port_bridge_join,
3847 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3848 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04003849 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003850 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3851 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3852 .port_vlan_add = mv88e6xxx_port_vlan_add,
3853 .port_vlan_del = mv88e6xxx_port_vlan_del,
3854 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3855 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3856 .port_fdb_add = mv88e6xxx_port_fdb_add,
3857 .port_fdb_del = mv88e6xxx_port_fdb_del,
3858 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003859 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3860 .port_mdb_add = mv88e6xxx_port_mdb_add,
3861 .port_mdb_del = mv88e6xxx_port_mdb_del,
3862 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04003863 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
3864 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003865};
3866
Florian Fainelliab3d4082017-01-08 14:52:07 -08003867static struct dsa_switch_driver mv88e6xxx_switch_drv = {
3868 .ops = &mv88e6xxx_switch_ops,
3869};
3870
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003871static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003872{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003873 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003874 struct dsa_switch *ds;
3875
Vivien Didelot73b12042017-03-30 17:37:10 -04003876 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003877 if (!ds)
3878 return -ENOMEM;
3879
Vivien Didelotfad09c72016-06-21 12:28:20 -04003880 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04003881 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04003882 ds->ageing_time_min = chip->info->age_time_coeff;
3883 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003884
3885 dev_set_drvdata(dev, ds);
3886
Vivien Didelot23c9ee42017-05-26 18:12:51 -04003887 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003888}
3889
Vivien Didelotfad09c72016-06-21 12:28:20 -04003890static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003891{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003892 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003893}
3894
Vivien Didelot57d32312016-06-20 13:13:58 -04003895static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003896{
3897 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003898 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003899 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003900 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003901 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02003902 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003903
Vivien Didelotcaac8542016-06-20 13:14:09 -04003904 compat_info = of_device_get_match_data(dev);
3905 if (!compat_info)
3906 return -EINVAL;
3907
Vivien Didelotfad09c72016-06-21 12:28:20 -04003908 chip = mv88e6xxx_alloc_chip(dev);
3909 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003910 return -ENOMEM;
3911
Vivien Didelotfad09c72016-06-21 12:28:20 -04003912 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003913
Vivien Didelotfad09c72016-06-21 12:28:20 -04003914 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003915 if (err)
3916 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003917
Andrew Lunnb4308f02016-11-21 23:26:55 +01003918 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
3919 if (IS_ERR(chip->reset))
3920 return PTR_ERR(chip->reset);
3921
Vivien Didelotfad09c72016-06-21 12:28:20 -04003922 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003923 if (err)
3924 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003925
Vivien Didelote57e5e72016-08-15 17:19:00 -04003926 mv88e6xxx_phy_init(chip);
3927
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003928 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003929 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003930 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003931
Andrew Lunndc30c352016-10-16 19:56:49 +02003932 mutex_lock(&chip->reg_lock);
3933 err = mv88e6xxx_switch_reset(chip);
3934 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02003935 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02003936 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02003937
Andrew Lunndc30c352016-10-16 19:56:49 +02003938 chip->irq = of_irq_get(np, 0);
3939 if (chip->irq == -EPROBE_DEFER) {
3940 err = chip->irq;
3941 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02003942 }
3943
Andrew Lunndc30c352016-10-16 19:56:49 +02003944 if (chip->irq > 0) {
3945 /* Has to be performed before the MDIO bus is created,
3946 * because the PHYs will link there interrupts to these
3947 * interrupt controllers
3948 */
3949 mutex_lock(&chip->reg_lock);
3950 err = mv88e6xxx_g1_irq_setup(chip);
3951 mutex_unlock(&chip->reg_lock);
3952
3953 if (err)
3954 goto out;
3955
3956 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
3957 err = mv88e6xxx_g2_irq_setup(chip);
3958 if (err)
3959 goto out_g1_irq;
3960 }
3961 }
3962
Andrew Lunna3c53be52017-01-24 14:53:50 +01003963 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02003964 if (err)
3965 goto out_g2_irq;
3966
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003967 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003968 if (err)
3969 goto out_mdio;
3970
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003971 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02003972
3973out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01003974 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003975out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01003976 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02003977 mv88e6xxx_g2_irq_free(chip);
3978out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003979 if (chip->irq > 0) {
3980 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01003981 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003982 mutex_unlock(&chip->reg_lock);
3983 }
Andrew Lunndc30c352016-10-16 19:56:49 +02003984out:
3985 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003986}
3987
3988static void mv88e6xxx_remove(struct mdio_device *mdiodev)
3989{
3990 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04003991 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003992
Andrew Lunn930188c2016-08-22 16:01:03 +02003993 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003994 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003995 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003996
Andrew Lunn467126442016-11-20 20:14:15 +01003997 if (chip->irq > 0) {
3998 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
3999 mv88e6xxx_g2_irq_free(chip);
4000 mv88e6xxx_g1_irq_free(chip);
4001 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004002}
4003
4004static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004005 {
4006 .compatible = "marvell,mv88e6085",
4007 .data = &mv88e6xxx_table[MV88E6085],
4008 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004009 {
4010 .compatible = "marvell,mv88e6190",
4011 .data = &mv88e6xxx_table[MV88E6190],
4012 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004013 { /* sentinel */ },
4014};
4015
4016MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4017
4018static struct mdio_driver mv88e6xxx_driver = {
4019 .probe = mv88e6xxx_probe,
4020 .remove = mv88e6xxx_remove,
4021 .mdiodrv.driver = {
4022 .name = "mv88e6085",
4023 .of_match_table = mv88e6xxx_of_match,
4024 },
4025};
4026
Ben Hutchings98e67302011-11-25 14:36:19 +00004027static int __init mv88e6xxx_init(void)
4028{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004029 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004030 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004031}
4032module_init(mv88e6xxx_init);
4033
4034static void __exit mv88e6xxx_cleanup(void)
4035{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004036 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004037 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004038}
4039module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004040
4041MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4042MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4043MODULE_LICENSE("GPL");