blob: e25d48ecf880bcf99e769bee2679e2464067c26d [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;
Vivien Didelot553eb542016-05-13 20:38:23 -0400918 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700919
Vivien Didelotfad09c72016-06-21 12:28:20 -0400920 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -0400921 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400922 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400923
924 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400925 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700926}
927
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500928static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
929{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500930 int err;
931
Vivien Didelotdaefc942017-03-11 16:12:54 -0500932 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
933 if (err)
934 return err;
935
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500936 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
937 if (err)
938 return err;
939
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500940 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
941}
942
Vivien Didelot17a15942017-03-30 17:37:09 -0400943static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
944{
945 u16 pvlan = 0;
946
947 if (!mv88e6xxx_has_pvt(chip))
948 return -EOPNOTSUPP;
949
950 /* Skip the local source device, which uses in-chip port VLAN */
951 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -0400952 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -0400953
954 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
955}
956
Vivien Didelot81228992017-03-30 17:37:08 -0400957static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
958{
Vivien Didelot17a15942017-03-30 17:37:09 -0400959 int dev, port;
960 int err;
961
Vivien Didelot81228992017-03-30 17:37:08 -0400962 if (!mv88e6xxx_has_pvt(chip))
963 return 0;
964
965 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
966 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
967 */
Vivien Didelot17a15942017-03-30 17:37:09 -0400968 err = mv88e6xxx_g2_misc_4_bit_port(chip);
969 if (err)
970 return err;
971
972 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
973 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
974 err = mv88e6xxx_pvt_map(chip, dev, port);
975 if (err)
976 return err;
977 }
978 }
979
980 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -0400981}
982
Vivien Didelot749efcb2016-09-22 16:49:24 -0400983static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
984{
985 struct mv88e6xxx_chip *chip = ds->priv;
986 int err;
987
988 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -0500989 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -0400990 mutex_unlock(&chip->reg_lock);
991
992 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400993 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -0400994}
995
Vivien Didelotb486d7c2017-05-01 14:05:13 -0400996static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
997{
998 if (!chip->info->max_vid)
999 return 0;
1000
1001 return mv88e6xxx_g1_vtu_flush(chip);
1002}
1003
Vivien Didelotf1394b782017-05-01 14:05:22 -04001004static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1005 struct mv88e6xxx_vtu_entry *entry)
1006{
1007 if (!chip->info->ops->vtu_getnext)
1008 return -EOPNOTSUPP;
1009
1010 return chip->info->ops->vtu_getnext(chip, entry);
1011}
1012
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001013static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1014 struct mv88e6xxx_vtu_entry *entry)
1015{
1016 if (!chip->info->ops->vtu_loadpurge)
1017 return -EOPNOTSUPP;
1018
1019 return chip->info->ops->vtu_loadpurge(chip, entry);
1020}
1021
Vivien Didelotf81ec902016-05-09 13:22:58 -04001022static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1023 struct switchdev_obj_port_vlan *vlan,
Vivien Didelot438ff532017-05-17 15:46:05 -04001024 switchdev_obj_dump_cb_t *cb)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001025{
Vivien Didelot04bed142016-08-31 18:06:13 -04001026 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001027 struct mv88e6xxx_vtu_entry next = {
1028 .vid = chip->info->max_vid,
1029 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001030 u16 pvid;
1031 int err;
1032
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001033 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001034 return -EOPNOTSUPP;
1035
Vivien Didelotfad09c72016-06-21 12:28:20 -04001036 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001037
Vivien Didelot77064f32016-11-04 03:23:30 +01001038 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001039 if (err)
1040 goto unlock;
1041
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001042 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001043 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001044 if (err)
1045 break;
1046
1047 if (!next.valid)
1048 break;
1049
Vivien Didelotbd00e052017-05-01 14:05:11 -04001050 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001051 continue;
1052
1053 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001054 vlan->vid_begin = next.vid;
1055 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001056 vlan->flags = 0;
1057
Vivien Didelotbd00e052017-05-01 14:05:11 -04001058 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001059 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1060
1061 if (next.vid == pvid)
1062 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1063
1064 err = cb(&vlan->obj);
1065 if (err)
1066 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001067 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001068
1069unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001070 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001071
1072 return err;
1073}
1074
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001075static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001076{
1077 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001078 struct mv88e6xxx_vtu_entry vlan = {
1079 .vid = chip->info->max_vid,
1080 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001081 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001082
1083 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1084
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001085 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001086 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001087 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001088 if (err)
1089 return err;
1090
1091 set_bit(*fid, fid_bitmap);
1092 }
1093
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001094 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001095 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001096 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001097 if (err)
1098 return err;
1099
1100 if (!vlan.valid)
1101 break;
1102
1103 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001104 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001105
1106 /* The reset value 0x000 is used to indicate that multiple address
1107 * databases are not needed. Return the next positive available.
1108 */
1109 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001110 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001111 return -ENOSPC;
1112
1113 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001114 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001115}
1116
Vivien Didelot567aa592017-05-01 14:05:25 -04001117static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1118 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001119{
1120 int err;
1121
1122 if (!vid)
1123 return -EINVAL;
1124
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001125 entry->vid = vid - 1;
1126 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001127
Vivien Didelotf1394b782017-05-01 14:05:22 -04001128 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001129 if (err)
1130 return err;
1131
Vivien Didelot567aa592017-05-01 14:05:25 -04001132 if (entry->vid == vid && entry->valid)
1133 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001134
Vivien Didelot567aa592017-05-01 14:05:25 -04001135 if (new) {
1136 int i;
1137
1138 /* Initialize a fresh VLAN entry */
1139 memset(entry, 0, sizeof(*entry));
1140 entry->valid = true;
1141 entry->vid = vid;
1142
Vivien Didelot553a7682017-06-07 18:12:16 -04001143 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001144 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001145 entry->member[i] =
1146 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001147
1148 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001149 }
1150
Vivien Didelot567aa592017-05-01 14:05:25 -04001151 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1152 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001153}
1154
Vivien Didelotda9c3592016-02-12 12:09:40 -05001155static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1156 u16 vid_begin, u16 vid_end)
1157{
Vivien Didelot04bed142016-08-31 18:06:13 -04001158 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001159 struct mv88e6xxx_vtu_entry vlan = {
1160 .vid = vid_begin - 1,
1161 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001162 int i, err;
1163
1164 if (!vid_begin)
1165 return -EOPNOTSUPP;
1166
Vivien Didelotfad09c72016-06-21 12:28:20 -04001167 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001168
Vivien Didelotda9c3592016-02-12 12:09:40 -05001169 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001170 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001171 if (err)
1172 goto unlock;
1173
1174 if (!vlan.valid)
1175 break;
1176
1177 if (vlan.vid > vid_end)
1178 break;
1179
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001180 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001181 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1182 continue;
1183
Andrew Lunn66e28092016-12-11 21:07:19 +01001184 if (!ds->ports[port].netdev)
1185 continue;
1186
Vivien Didelotbd00e052017-05-01 14:05:11 -04001187 if (vlan.member[i] ==
Vivien Didelotda9c3592016-02-12 12:09:40 -05001188 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1189 continue;
1190
Vivien Didelotfae8a252017-01-27 15:29:42 -05001191 if (ds->ports[i].bridge_dev ==
1192 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001193 break; /* same bridge, check next VLAN */
1194
Vivien Didelotfae8a252017-01-27 15:29:42 -05001195 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001196 continue;
1197
Vivien Didelot774439e52017-06-08 18:34:08 -04001198 dev_err(ds->dev, "p%d: hw VLAN %d already used by %s\n",
1199 port, vlan.vid,
1200 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001201 err = -EOPNOTSUPP;
1202 goto unlock;
1203 }
1204 } while (vlan.vid < vid_end);
1205
1206unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001207 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001208
1209 return err;
1210}
1211
Vivien Didelotf81ec902016-05-09 13:22:58 -04001212static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1213 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001214{
Vivien Didelot04bed142016-08-31 18:06:13 -04001215 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001216 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001217 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001218 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001219
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001220 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001221 return -EOPNOTSUPP;
1222
Vivien Didelotfad09c72016-06-21 12:28:20 -04001223 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001224 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001225 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001226
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001227 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001228}
1229
Vivien Didelot57d32312016-06-20 13:13:58 -04001230static int
1231mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1232 const struct switchdev_obj_port_vlan *vlan,
1233 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001234{
Vivien Didelot04bed142016-08-31 18:06:13 -04001235 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001236 int err;
1237
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 Didelotda9c3592016-02-12 12:09:40 -05001241 /* If the requested port doesn't belong to the same bridge as the VLAN
1242 * members, do not support it (yet) and fallback to software VLAN.
1243 */
1244 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1245 vlan->vid_end);
1246 if (err)
1247 return err;
1248
Vivien Didelot76e398a2015-11-01 12:33:55 -05001249 /* We don't need any dynamic resource from the kernel (yet),
1250 * so skip the prepare phase.
1251 */
1252 return 0;
1253}
1254
Vivien Didelotfad09c72016-06-21 12:28:20 -04001255static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001256 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001257{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001258 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001259 int err;
1260
Vivien Didelot567aa592017-05-01 14:05:25 -04001261 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001262 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001263 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001264
Vivien Didelotc91498e2017-06-07 18:12:13 -04001265 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001266
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001267 return mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001268}
1269
Vivien Didelotf81ec902016-05-09 13:22:58 -04001270static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1271 const struct switchdev_obj_port_vlan *vlan,
1272 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001273{
Vivien Didelot04bed142016-08-31 18:06:13 -04001274 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001275 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1276 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001277 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001278 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001279
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001280 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001281 return;
1282
Vivien Didelotc91498e2017-06-07 18:12:13 -04001283 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1284 member = GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1285 else if (untagged)
1286 member = GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED;
1287 else
1288 member = GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1289
Vivien Didelotfad09c72016-06-21 12:28:20 -04001290 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001291
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001292 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001293 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001294 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1295 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001296
Vivien Didelot77064f32016-11-04 03:23:30 +01001297 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001298 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1299 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001300
Vivien Didelotfad09c72016-06-21 12:28:20 -04001301 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001302}
1303
Vivien Didelotfad09c72016-06-21 12:28:20 -04001304static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001305 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001306{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001307 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001308 int i, err;
1309
Vivien Didelot567aa592017-05-01 14:05:25 -04001310 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001311 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001312 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001313
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001314 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelotbd00e052017-05-01 14:05:11 -04001315 if (vlan.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001316 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001317
Vivien Didelotbd00e052017-05-01 14:05:11 -04001318 vlan.member[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001319
1320 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001321 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001322 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotbd00e052017-05-01 14:05:11 -04001323 if (vlan.member[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001324 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001325 break;
1326 }
1327 }
1328
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001329 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001330 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001331 return err;
1332
Vivien Didelote606ca32017-03-11 16:12:55 -05001333 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001334}
1335
Vivien Didelotf81ec902016-05-09 13:22:58 -04001336static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1337 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001338{
Vivien Didelot04bed142016-08-31 18:06:13 -04001339 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001340 u16 pvid, vid;
1341 int err = 0;
1342
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001343 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001344 return -EOPNOTSUPP;
1345
Vivien Didelotfad09c72016-06-21 12:28:20 -04001346 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001347
Vivien Didelot77064f32016-11-04 03:23:30 +01001348 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001349 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001350 goto unlock;
1351
Vivien Didelot76e398a2015-11-01 12:33:55 -05001352 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001353 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001354 if (err)
1355 goto unlock;
1356
1357 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001358 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001359 if (err)
1360 goto unlock;
1361 }
1362 }
1363
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001364unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001365 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001366
1367 return err;
1368}
1369
Vivien Didelot83dabd12016-08-31 11:50:04 -04001370static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1371 const unsigned char *addr, u16 vid,
1372 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001373{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001374 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001375 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001376 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001377
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001378 /* Null VLAN ID corresponds to the port private database */
1379 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001380 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001381 else
Vivien Didelot567aa592017-05-01 14:05:25 -04001382 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001383 if (err)
1384 return err;
1385
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001386 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1387 ether_addr_copy(entry.mac, addr);
1388 eth_addr_dec(entry.mac);
1389
1390 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001391 if (err)
1392 return err;
1393
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001394 /* Initialize a fresh ATU entry if it isn't found */
1395 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1396 !ether_addr_equal(entry.mac, addr)) {
1397 memset(&entry, 0, sizeof(entry));
1398 ether_addr_copy(entry.mac, addr);
1399 }
1400
Vivien Didelot88472932016-09-19 19:56:11 -04001401 /* Purge the ATU entry only if no port is using it anymore */
1402 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001403 entry.portvec &= ~BIT(port);
1404 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001405 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1406 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001407 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001408 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001409 }
1410
Vivien Didelot9c13c022017-03-11 16:12:52 -05001411 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001412}
1413
Vivien Didelotf81ec902016-05-09 13:22:58 -04001414static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1415 const struct switchdev_obj_port_fdb *fdb,
1416 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001417{
1418 /* We don't need any dynamic resource from the kernel (yet),
1419 * so skip the prepare phase.
1420 */
1421 return 0;
1422}
1423
Vivien Didelotf81ec902016-05-09 13:22:58 -04001424static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1425 const struct switchdev_obj_port_fdb *fdb,
1426 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001427{
Vivien Didelot04bed142016-08-31 18:06:13 -04001428 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001429
Vivien Didelotfad09c72016-06-21 12:28:20 -04001430 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001431 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1432 GLOBAL_ATU_DATA_STATE_UC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04001433 dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
1434 port);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001435 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001436}
1437
Vivien Didelotf81ec902016-05-09 13:22:58 -04001438static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1439 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001440{
Vivien Didelot04bed142016-08-31 18:06:13 -04001441 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001442 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001443
Vivien Didelotfad09c72016-06-21 12:28:20 -04001444 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001445 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1446 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001447 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001448
Vivien Didelot83dabd12016-08-31 11:50:04 -04001449 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001450}
1451
Vivien Didelot83dabd12016-08-31 11:50:04 -04001452static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1453 u16 fid, u16 vid, int port,
1454 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001455 switchdev_obj_dump_cb_t *cb)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001456{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001457 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001458 int err;
1459
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001460 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1461 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001462
1463 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001464 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001465 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001466 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001467
1468 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1469 break;
1470
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001471 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001472 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001473
Vivien Didelot83dabd12016-08-31 11:50:04 -04001474 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1475 struct switchdev_obj_port_fdb *fdb;
1476
1477 if (!is_unicast_ether_addr(addr.mac))
1478 continue;
1479
1480 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001481 fdb->vid = vid;
1482 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001483 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
1484 fdb->ndm_state = NUD_NOARP;
1485 else
1486 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001487 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1488 struct switchdev_obj_port_mdb *mdb;
1489
1490 if (!is_multicast_ether_addr(addr.mac))
1491 continue;
1492
1493 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1494 mdb->vid = vid;
1495 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001496 } else {
1497 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001498 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001499
1500 err = cb(obj);
1501 if (err)
1502 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001503 } while (!is_broadcast_ether_addr(addr.mac));
1504
1505 return err;
1506}
1507
Vivien Didelot83dabd12016-08-31 11:50:04 -04001508static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1509 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001510 switchdev_obj_dump_cb_t *cb)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001511{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001512 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001513 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001514 };
1515 u16 fid;
1516 int err;
1517
1518 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001519 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001520 if (err)
1521 return err;
1522
1523 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1524 if (err)
1525 return err;
1526
1527 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001528 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001529 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001530 if (err)
1531 return err;
1532
1533 if (!vlan.valid)
1534 break;
1535
1536 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1537 obj, cb);
1538 if (err)
1539 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001540 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001541
1542 return err;
1543}
1544
Vivien Didelotf81ec902016-05-09 13:22:58 -04001545static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1546 struct switchdev_obj_port_fdb *fdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04001547 switchdev_obj_dump_cb_t *cb)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001548{
Vivien Didelot04bed142016-08-31 18:06:13 -04001549 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001550 int err;
1551
Vivien Didelotfad09c72016-06-21 12:28:20 -04001552 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001553 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001554 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001555
1556 return err;
1557}
1558
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001559static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1560 struct net_device *br)
1561{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001562 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001563 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001564 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001565 int err;
1566
1567 /* Remap the Port VLAN of each local bridge group member */
1568 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1569 if (chip->ds->ports[port].bridge_dev == br) {
1570 err = mv88e6xxx_port_vlan_map(chip, port);
1571 if (err)
1572 return err;
1573 }
1574 }
1575
Vivien Didelote96a6e02017-03-30 17:37:13 -04001576 if (!mv88e6xxx_has_pvt(chip))
1577 return 0;
1578
1579 /* Remap the Port VLAN of each cross-chip bridge group member */
1580 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1581 ds = chip->ds->dst->ds[dev];
1582 if (!ds)
1583 break;
1584
1585 for (port = 0; port < ds->num_ports; ++port) {
1586 if (ds->ports[port].bridge_dev == br) {
1587 err = mv88e6xxx_pvt_map(chip, dev, port);
1588 if (err)
1589 return err;
1590 }
1591 }
1592 }
1593
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001594 return 0;
1595}
1596
Vivien Didelotf81ec902016-05-09 13:22:58 -04001597static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001598 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001599{
Vivien Didelot04bed142016-08-31 18:06:13 -04001600 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001601 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001602
Vivien Didelotfad09c72016-06-21 12:28:20 -04001603 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001604 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001605 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001606
Vivien Didelot466dfa02016-02-26 13:16:05 -05001607 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001608}
1609
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001610static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1611 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001612{
Vivien Didelot04bed142016-08-31 18:06:13 -04001613 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001614
Vivien Didelotfad09c72016-06-21 12:28:20 -04001615 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001616 if (mv88e6xxx_bridge_map(chip, br) ||
1617 mv88e6xxx_port_vlan_map(chip, port))
1618 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001619 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001620}
1621
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001622static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1623 int port, struct net_device *br)
1624{
1625 struct mv88e6xxx_chip *chip = ds->priv;
1626 int err;
1627
1628 if (!mv88e6xxx_has_pvt(chip))
1629 return 0;
1630
1631 mutex_lock(&chip->reg_lock);
1632 err = mv88e6xxx_pvt_map(chip, dev, port);
1633 mutex_unlock(&chip->reg_lock);
1634
1635 return err;
1636}
1637
1638static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1639 int port, struct net_device *br)
1640{
1641 struct mv88e6xxx_chip *chip = ds->priv;
1642
1643 if (!mv88e6xxx_has_pvt(chip))
1644 return;
1645
1646 mutex_lock(&chip->reg_lock);
1647 if (mv88e6xxx_pvt_map(chip, dev, port))
1648 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1649 mutex_unlock(&chip->reg_lock);
1650}
1651
Vivien Didelot17e708b2016-12-05 17:30:27 -05001652static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1653{
1654 if (chip->info->ops->reset)
1655 return chip->info->ops->reset(chip);
1656
1657 return 0;
1658}
1659
Vivien Didelot309eca62016-12-05 17:30:26 -05001660static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1661{
1662 struct gpio_desc *gpiod = chip->reset;
1663
1664 /* If there is a GPIO connected to the reset pin, toggle it */
1665 if (gpiod) {
1666 gpiod_set_value_cansleep(gpiod, 1);
1667 usleep_range(10000, 20000);
1668 gpiod_set_value_cansleep(gpiod, 0);
1669 usleep_range(10000, 20000);
1670 }
1671}
1672
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001673static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1674{
1675 int i, err;
1676
1677 /* Set all ports to the Disabled state */
1678 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001679 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001680 if (err)
1681 return err;
1682 }
1683
1684 /* Wait for transmit queues to drain,
1685 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1686 */
1687 usleep_range(2000, 4000);
1688
1689 return 0;
1690}
1691
Vivien Didelotfad09c72016-06-21 12:28:20 -04001692static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001693{
Vivien Didelota935c052016-09-29 12:21:53 -04001694 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001695
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001696 err = mv88e6xxx_disable_ports(chip);
1697 if (err)
1698 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001699
Vivien Didelot309eca62016-12-05 17:30:26 -05001700 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001701
Vivien Didelot17e708b2016-12-05 17:30:27 -05001702 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001703}
1704
Vivien Didelot43145572017-03-11 16:12:59 -05001705static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001706 enum mv88e6xxx_frame_mode frame,
1707 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001708{
1709 int err;
1710
Vivien Didelot43145572017-03-11 16:12:59 -05001711 if (!chip->info->ops->port_set_frame_mode)
1712 return -EOPNOTSUPP;
1713
1714 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001715 if (err)
1716 return err;
1717
Vivien Didelot43145572017-03-11 16:12:59 -05001718 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1719 if (err)
1720 return err;
1721
1722 if (chip->info->ops->port_set_ether_type)
1723 return chip->info->ops->port_set_ether_type(chip, port, etype);
1724
1725 return 0;
1726}
1727
1728static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1729{
1730 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001731 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelot43145572017-03-11 16:12:59 -05001732 PORT_ETH_TYPE_DEFAULT);
1733}
1734
1735static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1736{
1737 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001738 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelot43145572017-03-11 16:12:59 -05001739 PORT_ETH_TYPE_DEFAULT);
1740}
1741
1742static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1743{
1744 return mv88e6xxx_set_port_mode(chip, port,
1745 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001746 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1747 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001748}
1749
1750static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1751{
1752 if (dsa_is_dsa_port(chip->ds, port))
1753 return mv88e6xxx_set_port_mode_dsa(chip, port);
1754
1755 if (dsa_is_normal_port(chip->ds, port))
1756 return mv88e6xxx_set_port_mode_normal(chip, port);
1757
1758 /* Setup CPU port mode depending on its supported tag format */
1759 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1760 return mv88e6xxx_set_port_mode_dsa(chip, port);
1761
1762 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1763 return mv88e6xxx_set_port_mode_edsa(chip, port);
1764
1765 return -EINVAL;
1766}
1767
Vivien Didelotea698f42017-03-11 16:12:50 -05001768static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1769{
1770 bool message = dsa_is_dsa_port(chip->ds, port);
1771
1772 return mv88e6xxx_port_set_message_port(chip, port, message);
1773}
1774
Vivien Didelot601aeed2017-03-11 16:13:00 -05001775static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1776{
1777 bool flood = port == dsa_upstream_port(chip->ds);
1778
1779 /* Upstream ports flood frames with unknown unicast or multicast DA */
1780 if (chip->info->ops->port_set_egress_floods)
1781 return chip->info->ops->port_set_egress_floods(chip, port,
1782 flood, flood);
1783
1784 return 0;
1785}
1786
Andrew Lunn6d917822017-05-26 01:03:21 +02001787static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1788 bool on)
1789{
Vivien Didelot523a8902017-05-26 18:02:42 -04001790 if (chip->info->ops->serdes_power)
1791 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001792
Vivien Didelot523a8902017-05-26 18:02:42 -04001793 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001794}
1795
Vivien Didelotfad09c72016-06-21 12:28:20 -04001796static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001797{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001798 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001799 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001800 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001801
Vivien Didelotd78343d2016-11-04 03:23:36 +01001802 /* MAC Forcing register: don't force link, speed, duplex or flow control
1803 * state to any particular values on physical ports, but force the CPU
1804 * port and all DSA ports to their maximum bandwidth and full duplex.
1805 */
1806 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1807 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1808 SPEED_MAX, DUPLEX_FULL,
1809 PHY_INTERFACE_MODE_NA);
1810 else
1811 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1812 SPEED_UNFORCED, DUPLEX_UNFORCED,
1813 PHY_INTERFACE_MODE_NA);
1814 if (err)
1815 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001816
1817 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1818 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1819 * tunneling, determine priority by looking at 802.1p and IP
1820 * priority fields (IP prio has precedence), and set STP state
1821 * to Forwarding.
1822 *
1823 * If this is the CPU link, use DSA or EDSA tagging depending
1824 * on which tagging mode was configured.
1825 *
1826 * If this is a link to another switch, use DSA tagging mode.
1827 *
1828 * If this is the upstream port for this switch, enable
1829 * forwarding of unknown unicasts and multicasts.
1830 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01001831 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02001832 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
1833 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01001834 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
1835 if (err)
1836 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001837
Vivien Didelot601aeed2017-03-11 16:13:00 -05001838 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001839 if (err)
1840 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001841
Vivien Didelot601aeed2017-03-11 16:13:00 -05001842 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001843 if (err)
1844 return err;
1845
Andrew Lunn04aca992017-05-26 01:03:24 +02001846 /* Enable the SERDES interface for DSA and CPU ports. Normal
1847 * ports SERDES are enabled when the port is enabled, thus
1848 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001849 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001850 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1851 err = mv88e6xxx_serdes_power(chip, port, true);
1852 if (err)
1853 return err;
1854 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001855
Vivien Didelot8efdda42015-08-13 12:52:23 -04001856 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001857 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001858 * untagged frames on this port, do a destination address lookup on all
1859 * received packets as usual, disable ARP mirroring and don't send a
1860 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001861 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001862 err = mv88e6xxx_port_set_map_da(chip, port);
1863 if (err)
1864 return err;
1865
Andrew Lunn54d792f2015-05-06 01:09:47 +02001866 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01001867 if (chip->info->ops->port_set_upstream_port) {
1868 err = chip->info->ops->port_set_upstream_port(
1869 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001870 if (err)
1871 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001872 }
1873
Andrew Lunna23b2962017-02-04 20:15:28 +01001874 err = mv88e6xxx_port_set_8021q_mode(chip, port,
1875 PORT_CONTROL_2_8021Q_DISABLED);
1876 if (err)
1877 return err;
1878
Andrew Lunn5f436662016-12-03 04:45:17 +01001879 if (chip->info->ops->port_jumbo_config) {
1880 err = chip->info->ops->port_jumbo_config(chip, port);
1881 if (err)
1882 return err;
1883 }
1884
Andrew Lunn54d792f2015-05-06 01:09:47 +02001885 /* Port Association Vector: when learning source addresses
1886 * of packets, add the address to the address database using
1887 * a port bitmap that has only the bit for this port set and
1888 * the other bits clear.
1889 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001890 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001891 /* Disable learning for CPU port */
1892 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001893 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001894
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001895 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
1896 if (err)
1897 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001898
1899 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001900 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
1901 if (err)
1902 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001903
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001904 if (chip->info->ops->port_pause_config) {
1905 err = chip->info->ops->port_pause_config(chip, port);
1906 if (err)
1907 return err;
1908 }
1909
Vivien Didelotc8c94892017-03-11 16:13:01 -05001910 if (chip->info->ops->port_disable_learn_limit) {
1911 err = chip->info->ops->port_disable_learn_limit(chip, port);
1912 if (err)
1913 return err;
1914 }
1915
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001916 if (chip->info->ops->port_disable_pri_override) {
1917 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001918 if (err)
1919 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01001920 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02001921
Andrew Lunnef0a7312016-12-03 04:35:16 +01001922 if (chip->info->ops->port_tag_remap) {
1923 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001924 if (err)
1925 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001926 }
1927
Andrew Lunnef70b112016-12-03 04:45:18 +01001928 if (chip->info->ops->port_egress_rate_limiting) {
1929 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001930 if (err)
1931 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001932 }
1933
Vivien Didelotea698f42017-03-11 16:12:50 -05001934 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001935 if (err)
1936 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001937
Vivien Didelot207afda2016-04-14 14:42:09 -04001938 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001939 * database, and allow bidirectional communication between the
1940 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07001941 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001942 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001943 if (err)
1944 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001945
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001946 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001947 if (err)
1948 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001949
1950 /* Default VLAN ID and priority: don't set a default VLAN
1951 * ID, and set the default packet priority to zero.
1952 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001953 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02001954}
1955
Andrew Lunn04aca992017-05-26 01:03:24 +02001956static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
1957 struct phy_device *phydev)
1958{
1959 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04001960 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02001961
1962 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001963 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02001964 mutex_unlock(&chip->reg_lock);
1965
1966 return err;
1967}
1968
1969static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
1970 struct phy_device *phydev)
1971{
1972 struct mv88e6xxx_chip *chip = ds->priv;
1973
1974 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001975 if (mv88e6xxx_serdes_power(chip, port, false))
1976 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02001977 mutex_unlock(&chip->reg_lock);
1978}
1979
Wei Yongjunaa0938c2016-10-18 15:53:37 +00001980static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04001981{
1982 int err;
1983
Vivien Didelota935c052016-09-29 12:21:53 -04001984 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04001985 if (err)
1986 return err;
1987
Vivien Didelota935c052016-09-29 12:21:53 -04001988 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04001989 if (err)
1990 return err;
1991
Vivien Didelota935c052016-09-29 12:21:53 -04001992 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
1993 if (err)
1994 return err;
1995
1996 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04001997}
1998
Vivien Didelot2cfcd962016-07-18 20:45:40 -04001999static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2000 unsigned int ageing_time)
2001{
Vivien Didelot04bed142016-08-31 18:06:13 -04002002 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002003 int err;
2004
2005 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002006 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002007 mutex_unlock(&chip->reg_lock);
2008
2009 return err;
2010}
2011
Vivien Didelot97299342016-07-18 20:45:30 -04002012static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002013{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002014 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002015 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002016 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002017
Andrew Lunn33641992016-12-03 04:35:17 +01002018 if (chip->info->ops->g1_set_cpu_port) {
2019 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2020 if (err)
2021 return err;
2022 }
2023
2024 if (chip->info->ops->g1_set_egress_port) {
2025 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2026 if (err)
2027 return err;
2028 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002029
Vivien Didelot50484ff2016-05-09 13:22:54 -04002030 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002031 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2032 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2033 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002034 if (err)
2035 return err;
2036
Vivien Didelot08a01262016-05-09 13:22:50 -04002037 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002038 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002039 if (err)
2040 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002041 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002042 if (err)
2043 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002044 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002045 if (err)
2046 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002047 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002048 if (err)
2049 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002050 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002051 if (err)
2052 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002053 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002054 if (err)
2055 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002056 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
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_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002060 if (err)
2061 return err;
2062
2063 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002064 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002065 if (err)
2066 return err;
2067
Andrew Lunnde2273872016-11-21 23:27:01 +01002068 /* Initialize the statistics unit */
2069 err = mv88e6xxx_stats_set_histogram(chip);
2070 if (err)
2071 return err;
2072
Vivien Didelot97299342016-07-18 20:45:30 -04002073 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002074 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2075 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002076 if (err)
2077 return err;
2078
2079 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002080 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002081 if (err)
2082 return err;
2083
2084 return 0;
2085}
2086
Vivien Didelotf81ec902016-05-09 13:22:58 -04002087static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002088{
Vivien Didelot04bed142016-08-31 18:06:13 -04002089 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002090 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002091 int i;
2092
Vivien Didelotfad09c72016-06-21 12:28:20 -04002093 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002094 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002095
Vivien Didelotfad09c72016-06-21 12:28:20 -04002096 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002097
Vivien Didelot97299342016-07-18 20:45:30 -04002098 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002099 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002100 err = mv88e6xxx_setup_port(chip, i);
2101 if (err)
2102 goto unlock;
2103 }
2104
2105 /* Setup Switch Global 1 Registers */
2106 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002107 if (err)
2108 goto unlock;
2109
Vivien Didelot97299342016-07-18 20:45:30 -04002110 /* Setup Switch Global 2 Registers */
2111 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2112 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002113 if (err)
2114 goto unlock;
2115 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002116
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002117 err = mv88e6xxx_phy_setup(chip);
2118 if (err)
2119 goto unlock;
2120
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002121 err = mv88e6xxx_vtu_setup(chip);
2122 if (err)
2123 goto unlock;
2124
Vivien Didelot81228992017-03-30 17:37:08 -04002125 err = mv88e6xxx_pvt_setup(chip);
2126 if (err)
2127 goto unlock;
2128
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002129 err = mv88e6xxx_atu_setup(chip);
2130 if (err)
2131 goto unlock;
2132
Andrew Lunn6e55f692016-12-03 04:45:16 +01002133 /* Some generations have the configuration of sending reserved
2134 * management frames to the CPU in global2, others in
2135 * global1. Hence it does not fit the two setup functions
2136 * above.
2137 */
2138 if (chip->info->ops->mgmt_rsvd2cpu) {
2139 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2140 if (err)
2141 goto unlock;
2142 }
2143
Vivien Didelot6b17e862015-08-13 12:52:18 -04002144unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002145 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002146
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002147 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002148}
2149
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002150static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2151{
Vivien Didelot04bed142016-08-31 18:06:13 -04002152 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002153 int err;
2154
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002155 if (!chip->info->ops->set_switch_mac)
2156 return -EOPNOTSUPP;
2157
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002158 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002159 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002160 mutex_unlock(&chip->reg_lock);
2161
2162 return err;
2163}
2164
Vivien Didelote57e5e72016-08-15 17:19:00 -04002165static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002166{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002167 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2168 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002169 u16 val;
2170 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002171
Andrew Lunnee26a222017-01-24 14:53:48 +01002172 if (!chip->info->ops->phy_read)
2173 return -EOPNOTSUPP;
2174
Vivien Didelotfad09c72016-06-21 12:28:20 -04002175 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002176 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002177 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002178
Andrew Lunnda9f3302017-02-01 03:40:05 +01002179 if (reg == MII_PHYSID2) {
2180 /* Some internal PHYS don't have a model number. Use
2181 * the mv88e6390 family model number instead.
2182 */
2183 if (!(val & 0x3f0))
2184 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2185 }
2186
Vivien Didelote57e5e72016-08-15 17:19:00 -04002187 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002188}
2189
Vivien Didelote57e5e72016-08-15 17:19:00 -04002190static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002191{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002192 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2193 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002194 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002195
Andrew Lunnee26a222017-01-24 14:53:48 +01002196 if (!chip->info->ops->phy_write)
2197 return -EOPNOTSUPP;
2198
Vivien Didelotfad09c72016-06-21 12:28:20 -04002199 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002200 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002201 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002202
2203 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002204}
2205
Vivien Didelotfad09c72016-06-21 12:28:20 -04002206static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002207 struct device_node *np,
2208 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002209{
2210 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002211 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002212 struct mii_bus *bus;
2213 int err;
2214
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002215 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002216 if (!bus)
2217 return -ENOMEM;
2218
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002219 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002220 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002221 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002222 INIT_LIST_HEAD(&mdio_bus->list);
2223 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002224
Andrew Lunnb516d452016-06-04 21:17:06 +02002225 if (np) {
2226 bus->name = np->full_name;
2227 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2228 } else {
2229 bus->name = "mv88e6xxx SMI";
2230 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2231 }
2232
2233 bus->read = mv88e6xxx_mdio_read;
2234 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002235 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002236
Andrew Lunna3c53be52017-01-24 14:53:50 +01002237 if (np)
2238 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002239 else
2240 err = mdiobus_register(bus);
2241 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002242 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002243 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002244 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002245
2246 if (external)
2247 list_add_tail(&mdio_bus->list, &chip->mdios);
2248 else
2249 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002250
2251 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002252}
2253
Andrew Lunna3c53be52017-01-24 14:53:50 +01002254static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2255 { .compatible = "marvell,mv88e6xxx-mdio-external",
2256 .data = (void *)true },
2257 { },
2258};
2259
2260static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2261 struct device_node *np)
2262{
2263 const struct of_device_id *match;
2264 struct device_node *child;
2265 int err;
2266
2267 /* Always register one mdio bus for the internal/default mdio
2268 * bus. This maybe represented in the device tree, but is
2269 * optional.
2270 */
2271 child = of_get_child_by_name(np, "mdio");
2272 err = mv88e6xxx_mdio_register(chip, child, false);
2273 if (err)
2274 return err;
2275
2276 /* Walk the device tree, and see if there are any other nodes
2277 * which say they are compatible with the external mdio
2278 * bus.
2279 */
2280 for_each_available_child_of_node(np, child) {
2281 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2282 if (match) {
2283 err = mv88e6xxx_mdio_register(chip, child, true);
2284 if (err)
2285 return err;
2286 }
2287 }
2288
2289 return 0;
2290}
2291
2292static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002293
2294{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002295 struct mv88e6xxx_mdio_bus *mdio_bus;
2296 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002297
Andrew Lunna3c53be52017-01-24 14:53:50 +01002298 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2299 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002300
Andrew Lunna3c53be52017-01-24 14:53:50 +01002301 mdiobus_unregister(bus);
2302 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002303}
2304
Vivien Didelot855b1932016-07-20 18:18:35 -04002305static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2306{
Vivien Didelot04bed142016-08-31 18:06:13 -04002307 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002308
2309 return chip->eeprom_len;
2310}
2311
Vivien Didelot855b1932016-07-20 18:18:35 -04002312static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2313 struct ethtool_eeprom *eeprom, u8 *data)
2314{
Vivien Didelot04bed142016-08-31 18:06:13 -04002315 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002316 int err;
2317
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002318 if (!chip->info->ops->get_eeprom)
2319 return -EOPNOTSUPP;
2320
Vivien Didelot855b1932016-07-20 18:18:35 -04002321 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002322 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002323 mutex_unlock(&chip->reg_lock);
2324
2325 if (err)
2326 return err;
2327
2328 eeprom->magic = 0xc3ec4951;
2329
2330 return 0;
2331}
2332
Vivien Didelot855b1932016-07-20 18:18:35 -04002333static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2334 struct ethtool_eeprom *eeprom, u8 *data)
2335{
Vivien Didelot04bed142016-08-31 18:06:13 -04002336 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002337 int err;
2338
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002339 if (!chip->info->ops->set_eeprom)
2340 return -EOPNOTSUPP;
2341
Vivien Didelot855b1932016-07-20 18:18:35 -04002342 if (eeprom->magic != 0xc3ec4951)
2343 return -EINVAL;
2344
2345 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002346 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002347 mutex_unlock(&chip->reg_lock);
2348
2349 return err;
2350}
2351
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002352static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002353 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002354 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002355 .phy_read = mv88e6185_phy_ppu_read,
2356 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002357 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002358 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002359 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002360 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002361 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002362 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002363 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002364 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002365 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002366 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002367 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002368 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002369 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2370 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002371 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002372 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2373 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002374 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002375 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002376 .ppu_enable = mv88e6185_g1_ppu_enable,
2377 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002378 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002379 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002380 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002381};
2382
2383static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002384 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002385 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002386 .phy_read = mv88e6185_phy_ppu_read,
2387 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002388 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002389 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002390 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002391 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002392 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002393 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002394 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002395 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2396 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002397 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002398 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002399 .ppu_enable = mv88e6185_g1_ppu_enable,
2400 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002401 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002402 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002403 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002404};
2405
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002406static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002407 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002408 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2409 .phy_read = mv88e6xxx_g2_smi_phy_read,
2410 .phy_write = mv88e6xxx_g2_smi_phy_write,
2411 .port_set_link = mv88e6xxx_port_set_link,
2412 .port_set_duplex = mv88e6xxx_port_set_duplex,
2413 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002414 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002415 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002416 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002417 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002418 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002419 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002420 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002421 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002422 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002423 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2424 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2425 .stats_get_strings = mv88e6095_stats_get_strings,
2426 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002427 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2428 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002429 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002430 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002431 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002432 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002433 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002434};
2435
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002436static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002437 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002438 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002439 .phy_read = mv88e6xxx_g2_smi_phy_read,
2440 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002441 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002442 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002443 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002444 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002445 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002446 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002447 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002448 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002449 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2450 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002451 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002452 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2453 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002454 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002455 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002456 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002457 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002458 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002459};
2460
2461static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002462 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002463 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002464 .phy_read = mv88e6185_phy_ppu_read,
2465 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002466 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002467 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002468 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002469 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002470 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002471 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002472 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002473 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002474 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002475 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002476 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002477 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002478 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2479 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002480 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002481 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2482 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002483 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002484 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002485 .ppu_enable = mv88e6185_g1_ppu_enable,
2486 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002487 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002488 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002489 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002490};
2491
Vivien Didelot990e27b2017-03-28 13:50:32 -04002492static const struct mv88e6xxx_ops mv88e6141_ops = {
2493 /* MV88E6XXX_FAMILY_6341 */
2494 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2495 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2496 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2497 .phy_read = mv88e6xxx_g2_smi_phy_read,
2498 .phy_write = mv88e6xxx_g2_smi_phy_write,
2499 .port_set_link = mv88e6xxx_port_set_link,
2500 .port_set_duplex = mv88e6xxx_port_set_duplex,
2501 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2502 .port_set_speed = mv88e6390_port_set_speed,
2503 .port_tag_remap = mv88e6095_port_tag_remap,
2504 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2505 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2506 .port_set_ether_type = mv88e6351_port_set_ether_type,
2507 .port_jumbo_config = mv88e6165_port_jumbo_config,
2508 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2509 .port_pause_config = mv88e6097_port_pause_config,
2510 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2511 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2512 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2513 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2514 .stats_get_strings = mv88e6320_stats_get_strings,
2515 .stats_get_stats = mv88e6390_stats_get_stats,
2516 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2517 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2518 .watchdog_ops = &mv88e6390_watchdog_ops,
2519 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2520 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002521 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002522 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002523};
2524
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002525static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002526 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002527 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002528 .phy_read = mv88e6xxx_g2_smi_phy_read,
2529 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002530 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002531 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002532 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002533 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002534 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002535 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002536 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002537 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002538 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002539 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002540 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002541 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002542 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002543 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2544 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002545 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002546 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2547 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002548 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002549 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002550 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002551 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002552 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002553};
2554
2555static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002556 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002557 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002558 .phy_read = mv88e6165_phy_read,
2559 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002560 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002561 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002562 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002563 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002564 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002565 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002566 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2567 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002568 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002569 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2570 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002571 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002572 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002573 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002574 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002575 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002576};
2577
2578static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002579 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002580 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002581 .phy_read = mv88e6xxx_g2_smi_phy_read,
2582 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002583 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002584 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002585 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002586 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002587 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002588 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002589 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002590 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002591 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002592 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002593 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002594 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002595 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002596 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002597 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2598 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002599 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002600 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2601 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002602 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002603 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002604 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002605 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002606 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002607};
2608
2609static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002610 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002611 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2612 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002613 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002614 .phy_read = mv88e6xxx_g2_smi_phy_read,
2615 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002616 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002617 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002618 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002619 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002620 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002621 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002622 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002623 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002624 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002625 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002626 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002627 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002628 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002629 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002630 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2631 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002632 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002633 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2634 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002635 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002636 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002637 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002638 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002639 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002640 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002641};
2642
2643static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002644 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002645 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002646 .phy_read = mv88e6xxx_g2_smi_phy_read,
2647 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002648 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002649 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002650 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002651 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002652 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002653 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002654 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002655 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002656 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002657 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002658 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002659 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002660 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002661 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002662 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2663 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002664 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002665 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2666 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002667 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002668 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002669 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002670 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002671 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002672};
2673
2674static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002675 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002676 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2677 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002678 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002679 .phy_read = mv88e6xxx_g2_smi_phy_read,
2680 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002681 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002682 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002683 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002684 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002685 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002686 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002687 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002688 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002689 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002690 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002691 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002692 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002693 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002694 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002695 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2696 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002697 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002698 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2699 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002700 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002701 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002702 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002703 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002704 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002705 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002706};
2707
2708static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002709 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002710 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002711 .phy_read = mv88e6185_phy_ppu_read,
2712 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002713 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002714 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002715 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002716 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002717 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002718 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002719 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002720 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002721 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2722 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002723 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002724 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2725 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002726 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002727 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002728 .ppu_enable = mv88e6185_g1_ppu_enable,
2729 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002730 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002731 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002732 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002733};
2734
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002735static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002736 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002737 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2738 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002739 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2740 .phy_read = mv88e6xxx_g2_smi_phy_read,
2741 .phy_write = mv88e6xxx_g2_smi_phy_write,
2742 .port_set_link = mv88e6xxx_port_set_link,
2743 .port_set_duplex = mv88e6xxx_port_set_duplex,
2744 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2745 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002746 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002747 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002748 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002749 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002750 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002751 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002752 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002753 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002754 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002755 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2756 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002757 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002758 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2759 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002760 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002761 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002762 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002763 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2764 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002765 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002766};
2767
2768static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002769 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002770 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2771 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002772 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2773 .phy_read = mv88e6xxx_g2_smi_phy_read,
2774 .phy_write = mv88e6xxx_g2_smi_phy_write,
2775 .port_set_link = mv88e6xxx_port_set_link,
2776 .port_set_duplex = mv88e6xxx_port_set_duplex,
2777 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2778 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002779 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002780 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002781 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002782 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002783 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002784 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002785 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002786 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002787 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002788 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2789 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002790 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002791 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2792 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002793 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002794 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002795 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002796 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2797 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002798 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002799};
2800
2801static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002802 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002803 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2804 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002805 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2806 .phy_read = mv88e6xxx_g2_smi_phy_read,
2807 .phy_write = mv88e6xxx_g2_smi_phy_write,
2808 .port_set_link = mv88e6xxx_port_set_link,
2809 .port_set_duplex = mv88e6xxx_port_set_duplex,
2810 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2811 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002812 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002813 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002814 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002815 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002816 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002817 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002818 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002819 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002820 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002821 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2822 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002823 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002824 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2825 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002826 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002827 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002828 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002829 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2830 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002831 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002832};
2833
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002834static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002835 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002836 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2837 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002838 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002839 .phy_read = mv88e6xxx_g2_smi_phy_read,
2840 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002841 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002842 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002843 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002844 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002845 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002846 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002847 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002848 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002849 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002850 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002851 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002852 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002853 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002854 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002855 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2856 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002857 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002858 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2859 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002860 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002861 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002862 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002863 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002864 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002865 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002866};
2867
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002868static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002869 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002870 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2871 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002872 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2873 .phy_read = mv88e6xxx_g2_smi_phy_read,
2874 .phy_write = mv88e6xxx_g2_smi_phy_write,
2875 .port_set_link = mv88e6xxx_port_set_link,
2876 .port_set_duplex = mv88e6xxx_port_set_duplex,
2877 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2878 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002879 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002880 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002881 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002882 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002883 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002884 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002885 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002886 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002887 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002888 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002889 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2890 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002891 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002892 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2893 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002894 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002895 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002896 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002897 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2898 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002899 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002900};
2901
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002902static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002903 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002904 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2905 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002906 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002907 .phy_read = mv88e6xxx_g2_smi_phy_read,
2908 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002909 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002910 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002911 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002912 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002913 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002914 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002915 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002916 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002917 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002918 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002919 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002920 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002921 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002922 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2923 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002924 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002925 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2926 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002927 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002928 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002929 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002930 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002931};
2932
2933static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002934 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002935 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2936 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002937 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002938 .phy_read = mv88e6xxx_g2_smi_phy_read,
2939 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002940 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002941 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002942 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002943 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002944 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002945 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002946 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002947 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002948 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002949 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002950 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002951 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002952 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002953 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2954 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002955 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002956 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2957 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002958 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002959 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002960 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002961};
2962
Vivien Didelot16e329a2017-03-28 13:50:33 -04002963static const struct mv88e6xxx_ops mv88e6341_ops = {
2964 /* MV88E6XXX_FAMILY_6341 */
2965 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2966 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2967 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2968 .phy_read = mv88e6xxx_g2_smi_phy_read,
2969 .phy_write = mv88e6xxx_g2_smi_phy_write,
2970 .port_set_link = mv88e6xxx_port_set_link,
2971 .port_set_duplex = mv88e6xxx_port_set_duplex,
2972 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2973 .port_set_speed = mv88e6390_port_set_speed,
2974 .port_tag_remap = mv88e6095_port_tag_remap,
2975 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2976 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2977 .port_set_ether_type = mv88e6351_port_set_ether_type,
2978 .port_jumbo_config = mv88e6165_port_jumbo_config,
2979 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2980 .port_pause_config = mv88e6097_port_pause_config,
2981 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2982 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2983 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2984 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2985 .stats_get_strings = mv88e6320_stats_get_strings,
2986 .stats_get_stats = mv88e6390_stats_get_stats,
2987 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2988 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2989 .watchdog_ops = &mv88e6390_watchdog_ops,
2990 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2991 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002992 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002993 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot16e329a2017-03-28 13:50:33 -04002994};
2995
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002996static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002997 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002998 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002999 .phy_read = mv88e6xxx_g2_smi_phy_read,
3000 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003001 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003002 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003003 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003004 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003005 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003006 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003007 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003008 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003009 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003010 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003011 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003012 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003013 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003014 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003015 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3016 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003017 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003018 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3019 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003020 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003021 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003022 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003023 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003024 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003025};
3026
3027static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003028 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003029 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003030 .phy_read = mv88e6xxx_g2_smi_phy_read,
3031 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003032 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003033 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003034 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003035 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003036 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003037 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003038 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003039 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003040 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003041 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003042 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003043 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003044 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003045 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003046 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3047 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003048 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003049 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3050 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003051 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003052 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003053 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003054 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003055 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003056};
3057
3058static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003059 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003060 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3061 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003062 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003063 .phy_read = mv88e6xxx_g2_smi_phy_read,
3064 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003065 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003066 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003067 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003068 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003069 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003070 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003071 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003072 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003073 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003074 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003075 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003076 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003077 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003078 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003079 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3080 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003081 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003082 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3083 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003084 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003085 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003086 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003087 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003088 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003089 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003090};
3091
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003092static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003093 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003094 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3095 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003096 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3097 .phy_read = mv88e6xxx_g2_smi_phy_read,
3098 .phy_write = mv88e6xxx_g2_smi_phy_write,
3099 .port_set_link = mv88e6xxx_port_set_link,
3100 .port_set_duplex = mv88e6xxx_port_set_duplex,
3101 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3102 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003103 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003104 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003105 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003106 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003107 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003108 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003109 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003110 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003111 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003112 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003113 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003114 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003115 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3116 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003117 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003118 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3119 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003120 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003121 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003122 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003123 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3124 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003125 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003126};
3127
3128static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003129 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003130 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3131 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003132 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3133 .phy_read = mv88e6xxx_g2_smi_phy_read,
3134 .phy_write = mv88e6xxx_g2_smi_phy_write,
3135 .port_set_link = mv88e6xxx_port_set_link,
3136 .port_set_duplex = mv88e6xxx_port_set_duplex,
3137 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3138 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003139 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003140 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003141 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003142 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003143 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003144 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003145 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003146 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003147 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003148 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003149 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003150 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3151 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003152 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003153 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3154 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003155 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003156 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003157 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003158 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3159 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003160 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003161};
3162
Vivien Didelotf81ec902016-05-09 13:22:58 -04003163static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3164 [MV88E6085] = {
3165 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3166 .family = MV88E6XXX_FAMILY_6097,
3167 .name = "Marvell 88E6085",
3168 .num_databases = 4096,
3169 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003170 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003171 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003172 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003173 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003174 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003175 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003176 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003177 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003178 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003179 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003180 },
3181
3182 [MV88E6095] = {
3183 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3184 .family = MV88E6XXX_FAMILY_6095,
3185 .name = "Marvell 88E6095/88E6095F",
3186 .num_databases = 256,
3187 .num_ports = 11,
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,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003194 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003195 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003196 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003197 },
3198
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003199 [MV88E6097] = {
3200 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3201 .family = MV88E6XXX_FAMILY_6097,
3202 .name = "Marvell 88E6097/88E6097F",
3203 .num_databases = 4096,
3204 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003205 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003206 .port_base_addr = 0x10,
3207 .global1_addr = 0x1b,
3208 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003209 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003210 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003211 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003212 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003213 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3214 .ops = &mv88e6097_ops,
3215 },
3216
Vivien Didelotf81ec902016-05-09 13:22:58 -04003217 [MV88E6123] = {
3218 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3219 .family = MV88E6XXX_FAMILY_6165,
3220 .name = "Marvell 88E6123",
3221 .num_databases = 4096,
3222 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003223 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003224 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003225 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003226 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003227 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003228 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003229 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003230 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003231 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003232 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003233 },
3234
3235 [MV88E6131] = {
3236 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3237 .family = MV88E6XXX_FAMILY_6185,
3238 .name = "Marvell 88E6131",
3239 .num_databases = 256,
3240 .num_ports = 8,
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,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003247 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003248 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003249 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003250 },
3251
Vivien Didelot990e27b2017-03-28 13:50:32 -04003252 [MV88E6141] = {
3253 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3254 .family = MV88E6XXX_FAMILY_6341,
3255 .name = "Marvell 88E6341",
3256 .num_databases = 4096,
3257 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003258 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003259 .port_base_addr = 0x10,
3260 .global1_addr = 0x1b,
3261 .age_time_coeff = 3750,
3262 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003263 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003264 .tag_protocol = DSA_TAG_PROTO_EDSA,
3265 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3266 .ops = &mv88e6141_ops,
3267 },
3268
Vivien Didelotf81ec902016-05-09 13:22:58 -04003269 [MV88E6161] = {
3270 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3271 .family = MV88E6XXX_FAMILY_6165,
3272 .name = "Marvell 88E6161",
3273 .num_databases = 4096,
3274 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003275 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003276 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003277 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003278 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003279 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003280 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003281 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003282 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003283 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003284 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003285 },
3286
3287 [MV88E6165] = {
3288 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3289 .family = MV88E6XXX_FAMILY_6165,
3290 .name = "Marvell 88E6165",
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 Lunn443d5a12016-12-03 04:35:18 +01003300 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003301 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003302 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003303 },
3304
3305 [MV88E6171] = {
3306 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3307 .family = MV88E6XXX_FAMILY_6351,
3308 .name = "Marvell 88E6171",
3309 .num_databases = 4096,
3310 .num_ports = 7,
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_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003319 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003320 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003321 },
3322
3323 [MV88E6172] = {
3324 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3325 .family = MV88E6XXX_FAMILY_6352,
3326 .name = "Marvell 88E6172",
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_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003338 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003339 },
3340
3341 [MV88E6175] = {
3342 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3343 .family = MV88E6XXX_FAMILY_6351,
3344 .name = "Marvell 88E6175",
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_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003356 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003357 },
3358
3359 [MV88E6176] = {
3360 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3361 .family = MV88E6XXX_FAMILY_6352,
3362 .name = "Marvell 88E6176",
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_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003374 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003375 },
3376
3377 [MV88E6185] = {
3378 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3379 .family = MV88E6XXX_FAMILY_6185,
3380 .name = "Marvell 88E6185",
3381 .num_databases = 256,
3382 .num_ports = 10,
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 = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003388 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003389 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003390 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003391 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003392 },
3393
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003394 [MV88E6190] = {
3395 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3396 .family = MV88E6XXX_FAMILY_6390,
3397 .name = "Marvell 88E6190",
3398 .num_databases = 4096,
3399 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003400 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003401 .port_base_addr = 0x0,
3402 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003403 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003404 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003405 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003406 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003407 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003408 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3409 .ops = &mv88e6190_ops,
3410 },
3411
3412 [MV88E6190X] = {
3413 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3414 .family = MV88E6XXX_FAMILY_6390,
3415 .name = "Marvell 88E6190X",
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 Lunnb91e0552017-02-02 00:46:15 +01003421 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003422 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003423 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003424 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003425 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003426 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3427 .ops = &mv88e6190x_ops,
3428 },
3429
3430 [MV88E6191] = {
3431 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3432 .family = MV88E6XXX_FAMILY_6390,
3433 .name = "Marvell 88E6191",
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 Lunn443d5a12016-12-03 04:35:18 +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,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003445 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003446 },
3447
Vivien Didelotf81ec902016-05-09 13:22:58 -04003448 [MV88E6240] = {
3449 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3450 .family = MV88E6XXX_FAMILY_6352,
3451 .name = "Marvell 88E6240",
3452 .num_databases = 4096,
3453 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003454 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003455 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003456 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003457 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003458 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003459 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003460 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003461 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003462 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003463 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003464 },
3465
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003466 [MV88E6290] = {
3467 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3468 .family = MV88E6XXX_FAMILY_6390,
3469 .name = "Marvell 88E6290",
3470 .num_databases = 4096,
3471 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003472 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003473 .port_base_addr = 0x0,
3474 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003475 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003476 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003477 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003478 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003479 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003480 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3481 .ops = &mv88e6290_ops,
3482 },
3483
Vivien Didelotf81ec902016-05-09 13:22:58 -04003484 [MV88E6320] = {
3485 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3486 .family = MV88E6XXX_FAMILY_6320,
3487 .name = "Marvell 88E6320",
3488 .num_databases = 4096,
3489 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003490 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003491 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003492 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003493 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003494 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003495 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003496 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003497 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003498 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003499 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003500 },
3501
3502 [MV88E6321] = {
3503 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3504 .family = MV88E6XXX_FAMILY_6320,
3505 .name = "Marvell 88E6321",
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,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003514 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003515 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003516 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003517 },
3518
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003519 [MV88E6341] = {
3520 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3521 .family = MV88E6XXX_FAMILY_6341,
3522 .name = "Marvell 88E6341",
3523 .num_databases = 4096,
3524 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003525 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003526 .port_base_addr = 0x10,
3527 .global1_addr = 0x1b,
3528 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003529 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003530 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003531 .tag_protocol = DSA_TAG_PROTO_EDSA,
3532 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3533 .ops = &mv88e6341_ops,
3534 },
3535
Vivien Didelotf81ec902016-05-09 13:22:58 -04003536 [MV88E6350] = {
3537 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3538 .family = MV88E6XXX_FAMILY_6351,
3539 .name = "Marvell 88E6350",
3540 .num_databases = 4096,
3541 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003542 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003543 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003544 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003545 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003546 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003547 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003548 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003549 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003550 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003551 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003552 },
3553
3554 [MV88E6351] = {
3555 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3556 .family = MV88E6XXX_FAMILY_6351,
3557 .name = "Marvell 88E6351",
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 = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003570 },
3571
3572 [MV88E6352] = {
3573 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3574 .family = MV88E6XXX_FAMILY_6352,
3575 .name = "Marvell 88E6352",
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_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003587 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003588 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003589 [MV88E6390] = {
3590 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3591 .family = MV88E6XXX_FAMILY_6390,
3592 .name = "Marvell 88E6390",
3593 .num_databases = 4096,
3594 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003595 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003596 .port_base_addr = 0x0,
3597 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003598 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003599 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003600 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003601 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003602 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003603 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3604 .ops = &mv88e6390_ops,
3605 },
3606 [MV88E6390X] = {
3607 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3608 .family = MV88E6XXX_FAMILY_6390,
3609 .name = "Marvell 88E6390X",
3610 .num_databases = 4096,
3611 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003612 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003613 .port_base_addr = 0x0,
3614 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003615 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003616 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003617 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003618 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003619 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003620 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3621 .ops = &mv88e6390x_ops,
3622 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003623};
3624
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003625static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003626{
Vivien Didelota439c062016-04-17 13:23:58 -04003627 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003628
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003629 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3630 if (mv88e6xxx_table[i].prod_num == prod_num)
3631 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003632
Vivien Didelotb9b37712015-10-30 19:39:48 -04003633 return NULL;
3634}
3635
Vivien Didelotfad09c72016-06-21 12:28:20 -04003636static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003637{
3638 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003639 unsigned int prod_num, rev;
3640 u16 id;
3641 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003642
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003643 mutex_lock(&chip->reg_lock);
3644 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3645 mutex_unlock(&chip->reg_lock);
3646 if (err)
3647 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003648
3649 prod_num = (id & 0xfff0) >> 4;
3650 rev = id & 0x000f;
3651
3652 info = mv88e6xxx_lookup_info(prod_num);
3653 if (!info)
3654 return -ENODEV;
3655
Vivien Didelotcaac8542016-06-20 13:14:09 -04003656 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003657 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003658
Vivien Didelotca070c12016-09-02 14:45:34 -04003659 err = mv88e6xxx_g2_require(chip);
3660 if (err)
3661 return err;
3662
Vivien Didelotfad09c72016-06-21 12:28:20 -04003663 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3664 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003665
3666 return 0;
3667}
3668
Vivien Didelotfad09c72016-06-21 12:28:20 -04003669static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003670{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003671 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003672
Vivien Didelotfad09c72016-06-21 12:28:20 -04003673 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3674 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003675 return NULL;
3676
Vivien Didelotfad09c72016-06-21 12:28:20 -04003677 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003678
Vivien Didelotfad09c72016-06-21 12:28:20 -04003679 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003680 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003681
Vivien Didelotfad09c72016-06-21 12:28:20 -04003682 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003683}
3684
Vivien Didelotfad09c72016-06-21 12:28:20 -04003685static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003686 struct mii_bus *bus, int sw_addr)
3687{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003688 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003689 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003690 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003691 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003692 else
3693 return -EINVAL;
3694
Vivien Didelotfad09c72016-06-21 12:28:20 -04003695 chip->bus = bus;
3696 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003697
3698 return 0;
3699}
3700
Andrew Lunn7b314362016-08-22 16:01:01 +02003701static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3702{
Vivien Didelot04bed142016-08-31 18:06:13 -04003703 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003704
Andrew Lunn443d5a12016-12-03 04:35:18 +01003705 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003706}
3707
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003708static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3709 struct device *host_dev, int sw_addr,
3710 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003711{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003712 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003713 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003714 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003715
Vivien Didelota439c062016-04-17 13:23:58 -04003716 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003717 if (!bus)
3718 return NULL;
3719
Vivien Didelotfad09c72016-06-21 12:28:20 -04003720 chip = mv88e6xxx_alloc_chip(dsa_dev);
3721 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003722 return NULL;
3723
Vivien Didelotcaac8542016-06-20 13:14:09 -04003724 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003725 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003726
Vivien Didelotfad09c72016-06-21 12:28:20 -04003727 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003728 if (err)
3729 goto free;
3730
Vivien Didelotfad09c72016-06-21 12:28:20 -04003731 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003732 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003733 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003734
Andrew Lunndc30c352016-10-16 19:56:49 +02003735 mutex_lock(&chip->reg_lock);
3736 err = mv88e6xxx_switch_reset(chip);
3737 mutex_unlock(&chip->reg_lock);
3738 if (err)
3739 goto free;
3740
Vivien Didelote57e5e72016-08-15 17:19:00 -04003741 mv88e6xxx_phy_init(chip);
3742
Andrew Lunna3c53be52017-01-24 14:53:50 +01003743 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003744 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003745 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003746
Vivien Didelotfad09c72016-06-21 12:28:20 -04003747 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003748
Vivien Didelotfad09c72016-06-21 12:28:20 -04003749 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003750free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003751 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003752
3753 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003754}
3755
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003756static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3757 const struct switchdev_obj_port_mdb *mdb,
3758 struct switchdev_trans *trans)
3759{
3760 /* We don't need any dynamic resource from the kernel (yet),
3761 * so skip the prepare phase.
3762 */
3763
3764 return 0;
3765}
3766
3767static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3768 const struct switchdev_obj_port_mdb *mdb,
3769 struct switchdev_trans *trans)
3770{
Vivien Didelot04bed142016-08-31 18:06:13 -04003771 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003772
3773 mutex_lock(&chip->reg_lock);
3774 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3775 GLOBAL_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04003776 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
3777 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003778 mutex_unlock(&chip->reg_lock);
3779}
3780
3781static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3782 const struct switchdev_obj_port_mdb *mdb)
3783{
Vivien Didelot04bed142016-08-31 18:06:13 -04003784 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003785 int err;
3786
3787 mutex_lock(&chip->reg_lock);
3788 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3789 GLOBAL_ATU_DATA_STATE_UNUSED);
3790 mutex_unlock(&chip->reg_lock);
3791
3792 return err;
3793}
3794
3795static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3796 struct switchdev_obj_port_mdb *mdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04003797 switchdev_obj_dump_cb_t *cb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003798{
Vivien Didelot04bed142016-08-31 18:06:13 -04003799 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003800 int err;
3801
3802 mutex_lock(&chip->reg_lock);
3803 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3804 mutex_unlock(&chip->reg_lock);
3805
3806 return err;
3807}
3808
Florian Fainellia82f67a2017-01-08 14:52:08 -08003809static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003810 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02003811 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003812 .setup = mv88e6xxx_setup,
3813 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003814 .adjust_link = mv88e6xxx_adjust_link,
3815 .get_strings = mv88e6xxx_get_strings,
3816 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3817 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02003818 .port_enable = mv88e6xxx_port_enable,
3819 .port_disable = mv88e6xxx_port_disable,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003820 .set_eee = mv88e6xxx_set_eee,
3821 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003822 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003823 .get_eeprom = mv88e6xxx_get_eeprom,
3824 .set_eeprom = mv88e6xxx_set_eeprom,
3825 .get_regs_len = mv88e6xxx_get_regs_len,
3826 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003827 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003828 .port_bridge_join = mv88e6xxx_port_bridge_join,
3829 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3830 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04003831 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003832 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3833 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3834 .port_vlan_add = mv88e6xxx_port_vlan_add,
3835 .port_vlan_del = mv88e6xxx_port_vlan_del,
3836 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3837 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3838 .port_fdb_add = mv88e6xxx_port_fdb_add,
3839 .port_fdb_del = mv88e6xxx_port_fdb_del,
3840 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003841 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3842 .port_mdb_add = mv88e6xxx_port_mdb_add,
3843 .port_mdb_del = mv88e6xxx_port_mdb_del,
3844 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04003845 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
3846 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003847};
3848
Florian Fainelliab3d4082017-01-08 14:52:07 -08003849static struct dsa_switch_driver mv88e6xxx_switch_drv = {
3850 .ops = &mv88e6xxx_switch_ops,
3851};
3852
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003853static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003854{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003855 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003856 struct dsa_switch *ds;
3857
Vivien Didelot73b12042017-03-30 17:37:10 -04003858 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003859 if (!ds)
3860 return -ENOMEM;
3861
Vivien Didelotfad09c72016-06-21 12:28:20 -04003862 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04003863 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04003864 ds->ageing_time_min = chip->info->age_time_coeff;
3865 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003866
3867 dev_set_drvdata(dev, ds);
3868
Vivien Didelot23c9ee42017-05-26 18:12:51 -04003869 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003870}
3871
Vivien Didelotfad09c72016-06-21 12:28:20 -04003872static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003873{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003874 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003875}
3876
Vivien Didelot57d32312016-06-20 13:13:58 -04003877static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003878{
3879 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003880 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003881 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003882 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003883 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02003884 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003885
Vivien Didelotcaac8542016-06-20 13:14:09 -04003886 compat_info = of_device_get_match_data(dev);
3887 if (!compat_info)
3888 return -EINVAL;
3889
Vivien Didelotfad09c72016-06-21 12:28:20 -04003890 chip = mv88e6xxx_alloc_chip(dev);
3891 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003892 return -ENOMEM;
3893
Vivien Didelotfad09c72016-06-21 12:28:20 -04003894 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003895
Vivien Didelotfad09c72016-06-21 12:28:20 -04003896 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003897 if (err)
3898 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003899
Andrew Lunnb4308f02016-11-21 23:26:55 +01003900 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
3901 if (IS_ERR(chip->reset))
3902 return PTR_ERR(chip->reset);
3903
Vivien Didelotfad09c72016-06-21 12:28:20 -04003904 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003905 if (err)
3906 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003907
Vivien Didelote57e5e72016-08-15 17:19:00 -04003908 mv88e6xxx_phy_init(chip);
3909
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003910 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003911 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003912 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003913
Andrew Lunndc30c352016-10-16 19:56:49 +02003914 mutex_lock(&chip->reg_lock);
3915 err = mv88e6xxx_switch_reset(chip);
3916 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02003917 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02003918 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02003919
Andrew Lunndc30c352016-10-16 19:56:49 +02003920 chip->irq = of_irq_get(np, 0);
3921 if (chip->irq == -EPROBE_DEFER) {
3922 err = chip->irq;
3923 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02003924 }
3925
Andrew Lunndc30c352016-10-16 19:56:49 +02003926 if (chip->irq > 0) {
3927 /* Has to be performed before the MDIO bus is created,
3928 * because the PHYs will link there interrupts to these
3929 * interrupt controllers
3930 */
3931 mutex_lock(&chip->reg_lock);
3932 err = mv88e6xxx_g1_irq_setup(chip);
3933 mutex_unlock(&chip->reg_lock);
3934
3935 if (err)
3936 goto out;
3937
3938 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
3939 err = mv88e6xxx_g2_irq_setup(chip);
3940 if (err)
3941 goto out_g1_irq;
3942 }
3943 }
3944
Andrew Lunna3c53be52017-01-24 14:53:50 +01003945 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02003946 if (err)
3947 goto out_g2_irq;
3948
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003949 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003950 if (err)
3951 goto out_mdio;
3952
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003953 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02003954
3955out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01003956 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003957out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01003958 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02003959 mv88e6xxx_g2_irq_free(chip);
3960out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003961 if (chip->irq > 0) {
3962 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01003963 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003964 mutex_unlock(&chip->reg_lock);
3965 }
Andrew Lunndc30c352016-10-16 19:56:49 +02003966out:
3967 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003968}
3969
3970static void mv88e6xxx_remove(struct mdio_device *mdiodev)
3971{
3972 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04003973 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003974
Andrew Lunn930188c2016-08-22 16:01:03 +02003975 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003976 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003977 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003978
Andrew Lunn467126442016-11-20 20:14:15 +01003979 if (chip->irq > 0) {
3980 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
3981 mv88e6xxx_g2_irq_free(chip);
3982 mv88e6xxx_g1_irq_free(chip);
3983 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003984}
3985
3986static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04003987 {
3988 .compatible = "marvell,mv88e6085",
3989 .data = &mv88e6xxx_table[MV88E6085],
3990 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003991 {
3992 .compatible = "marvell,mv88e6190",
3993 .data = &mv88e6xxx_table[MV88E6190],
3994 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003995 { /* sentinel */ },
3996};
3997
3998MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
3999
4000static struct mdio_driver mv88e6xxx_driver = {
4001 .probe = mv88e6xxx_probe,
4002 .remove = mv88e6xxx_remove,
4003 .mdiodrv.driver = {
4004 .name = "mv88e6085",
4005 .of_match_table = mv88e6xxx_of_match,
4006 },
4007};
4008
Ben Hutchings98e67302011-11-25 14:36:19 +00004009static int __init mv88e6xxx_init(void)
4010{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004011 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004012 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004013}
4014module_init(mv88e6xxx_init);
4015
4016static void __exit mv88e6xxx_cleanup(void)
4017{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004018 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004019 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004020}
4021module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004022
4023MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4024MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4025MODULE_LICENSE("GPL");