blob: 962b4e873bf93e0a93ab515fbbc92bf47ad00672 [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))
492 netdev_err(chip->ds->ports[port].netdev,
493 "failed to restore MAC's link\n");
494
495 return err;
496}
497
Andrew Lunndea87022015-08-31 15:56:47 +0200498/* We expect the switch to perform auto negotiation if there is a real
499 * phy. However, in the case of a fixed link phy, we force the port
500 * settings from the fixed link settings.
501 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400502static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
503 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200504{
Vivien Didelot04bed142016-08-31 18:06:13 -0400505 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200506 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200507
508 if (!phy_is_pseudo_fixed_link(phydev))
509 return;
510
Vivien Didelotfad09c72016-06-21 12:28:20 -0400511 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100512 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
513 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400514 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100515
516 if (err && err != -EOPNOTSUPP)
517 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200518}
519
Andrew Lunna605a0f2016-11-21 23:26:58 +0100520static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000521{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100522 if (!chip->info->ops->stats_snapshot)
523 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000524
Andrew Lunna605a0f2016-11-21 23:26:58 +0100525 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000526}
527
Andrew Lunne413e7e2015-04-02 04:06:38 +0200528static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100529 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
530 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
531 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
532 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
533 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
534 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
535 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
536 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
537 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
538 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
539 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
540 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
541 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
542 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
543 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
544 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
545 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
546 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
547 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
548 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
549 { "single", 4, 0x14, STATS_TYPE_BANK0, },
550 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
551 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
552 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
553 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
554 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
555 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
556 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
557 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
558 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
559 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
560 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
561 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
562 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
563 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
564 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
565 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
566 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
567 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
568 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
569 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
570 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
571 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
572 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
573 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
574 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
575 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
576 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
577 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
578 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
579 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
580 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
581 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
582 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
583 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
584 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
585 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
586 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
587 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200588};
589
Vivien Didelotfad09c72016-06-21 12:28:20 -0400590static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100591 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100592 int port, u16 bank1_select,
593 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200594{
Andrew Lunn80c46272015-06-20 18:42:30 +0200595 u32 low;
596 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100597 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200598 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200599 u64 value;
600
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100601 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100602 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200603 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
604 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200605 return UINT64_MAX;
606
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200607 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200608 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200609 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
610 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200611 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200612 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200613 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100614 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100615 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100616 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100617 /* fall through */
618 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100619 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100620 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200621 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100622 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500623 break;
624 default:
625 return UINT64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200626 }
627 value = (((u64)high) << 16) | low;
628 return value;
629}
630
Andrew Lunndfafe442016-11-21 23:27:02 +0100631static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
632 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100633{
634 struct mv88e6xxx_hw_stat *stat;
635 int i, j;
636
637 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
638 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100639 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100640 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
641 ETH_GSTRING_LEN);
642 j++;
643 }
644 }
645}
646
Andrew Lunndfafe442016-11-21 23:27:02 +0100647static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
648 uint8_t *data)
649{
650 mv88e6xxx_stats_get_strings(chip, data,
651 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
652}
653
654static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
655 uint8_t *data)
656{
657 mv88e6xxx_stats_get_strings(chip, data,
658 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
659}
660
661static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
662 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100663{
Vivien Didelot04bed142016-08-31 18:06:13 -0400664 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100665
666 if (chip->info->ops->stats_get_strings)
667 chip->info->ops->stats_get_strings(chip, data);
668}
669
670static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
671 int types)
672{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100673 struct mv88e6xxx_hw_stat *stat;
674 int i, j;
675
676 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
677 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100678 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100679 j++;
680 }
681 return j;
682}
683
Andrew Lunndfafe442016-11-21 23:27:02 +0100684static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
685{
686 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
687 STATS_TYPE_PORT);
688}
689
690static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
691{
692 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
693 STATS_TYPE_BANK1);
694}
695
696static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
697{
698 struct mv88e6xxx_chip *chip = ds->priv;
699
700 if (chip->info->ops->stats_get_sset_count)
701 return chip->info->ops->stats_get_sset_count(chip);
702
703 return 0;
704}
705
Andrew Lunn052f9472016-11-21 23:27:03 +0100706static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100707 uint64_t *data, int types,
708 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100709{
710 struct mv88e6xxx_hw_stat *stat;
711 int i, j;
712
713 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
714 stat = &mv88e6xxx_hw_stats[i];
715 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100716 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
717 bank1_select,
718 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100719 j++;
720 }
721 }
722}
723
724static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
725 uint64_t *data)
726{
727 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100728 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
729 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100730}
731
732static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
733 uint64_t *data)
734{
735 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100736 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
737 GLOBAL_STATS_OP_BANK_1_BIT_9,
738 GLOBAL_STATS_OP_HIST_RX_TX);
739}
740
741static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
742 uint64_t *data)
743{
744 return mv88e6xxx_stats_get_stats(chip, port, data,
745 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
746 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100747}
748
749static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
750 uint64_t *data)
751{
752 if (chip->info->ops->stats_get_stats)
753 chip->info->ops->stats_get_stats(chip, port, data);
754}
755
Vivien Didelotf81ec902016-05-09 13:22:58 -0400756static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
757 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000758{
Vivien Didelot04bed142016-08-31 18:06:13 -0400759 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000760 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000761
Vivien Didelotfad09c72016-06-21 12:28:20 -0400762 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000763
Andrew Lunna605a0f2016-11-21 23:26:58 +0100764 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000765 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400766 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000767 return;
768 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100769
770 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000771
Vivien Didelotfad09c72016-06-21 12:28:20 -0400772 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000773}
Ben Hutchings98e67302011-11-25 14:36:19 +0000774
Andrew Lunnde2273872016-11-21 23:27:01 +0100775static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
776{
777 if (chip->info->ops->stats_set_histogram)
778 return chip->info->ops->stats_set_histogram(chip);
779
780 return 0;
781}
782
Vivien Didelotf81ec902016-05-09 13:22:58 -0400783static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700784{
785 return 32 * sizeof(u16);
786}
787
Vivien Didelotf81ec902016-05-09 13:22:58 -0400788static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
789 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700790{
Vivien Didelot04bed142016-08-31 18:06:13 -0400791 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200792 int err;
793 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700794 u16 *p = _p;
795 int i;
796
797 regs->version = 0;
798
799 memset(p, 0xff, 32 * sizeof(u16));
800
Vivien Didelotfad09c72016-06-21 12:28:20 -0400801 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400802
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700803 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700804
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200805 err = mv88e6xxx_port_read(chip, port, i, &reg);
806 if (!err)
807 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700808 }
Vivien Didelot23062512016-05-09 13:22:45 -0400809
Vivien Didelotfad09c72016-06-21 12:28:20 -0400810 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700811}
812
Vivien Didelotf81ec902016-05-09 13:22:58 -0400813static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
814 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800815{
Vivien Didelot04bed142016-08-31 18:06:13 -0400816 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400817 u16 reg;
818 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800819
Vivien Didelotfad09c72016-06-21 12:28:20 -0400820 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400821 return -EOPNOTSUPP;
822
Vivien Didelotfad09c72016-06-21 12:28:20 -0400823 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200824
Vivien Didelot9c938292016-08-15 17:19:02 -0400825 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
826 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200827 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800828
829 e->eee_enabled = !!(reg & 0x0200);
830 e->tx_lpi_enabled = !!(reg & 0x0100);
831
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200832 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -0400833 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200834 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800835
Andrew Lunncca8b132015-04-02 04:06:39 +0200836 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200837out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400838 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -0400839
840 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800841}
842
Vivien Didelotf81ec902016-05-09 13:22:58 -0400843static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
844 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800845{
Vivien Didelot04bed142016-08-31 18:06:13 -0400846 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -0400847 u16 reg;
848 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800849
Vivien Didelotfad09c72016-06-21 12:28:20 -0400850 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400851 return -EOPNOTSUPP;
852
Vivien Didelotfad09c72016-06-21 12:28:20 -0400853 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800854
Vivien Didelot9c938292016-08-15 17:19:02 -0400855 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
856 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200857 goto out;
858
Vivien Didelot9c938292016-08-15 17:19:02 -0400859 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +0200860 if (e->eee_enabled)
861 reg |= 0x0200;
862 if (e->tx_lpi_enabled)
863 reg |= 0x0100;
864
Vivien Didelot9c938292016-08-15 17:19:02 -0400865 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200866out:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400867 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200868
Vivien Didelot9c938292016-08-15 17:19:02 -0400869 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800870}
871
Vivien Didelote5887a22017-03-30 17:37:11 -0400872static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700873{
Vivien Didelote5887a22017-03-30 17:37:11 -0400874 struct dsa_switch *ds = NULL;
875 struct net_device *br;
876 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500877 int i;
878
Vivien Didelote5887a22017-03-30 17:37:11 -0400879 if (dev < DSA_MAX_SWITCHES)
880 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500881
Vivien Didelote5887a22017-03-30 17:37:11 -0400882 /* Prevent frames from unknown switch or port */
883 if (!ds || port >= ds->num_ports)
884 return 0;
885
886 /* Frames from DSA links and CPU ports can egress any local port */
887 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
888 return mv88e6xxx_port_mask(chip);
889
890 br = ds->ports[port].bridge_dev;
891 pvlan = 0;
892
893 /* Frames from user ports can egress any local DSA links and CPU ports,
894 * as well as any local member of their bridge group.
895 */
896 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
897 if (dsa_is_cpu_port(chip->ds, i) ||
898 dsa_is_dsa_port(chip->ds, i) ||
899 (br && chip->ds->ports[i].bridge_dev == br))
900 pvlan |= BIT(i);
901
902 return pvlan;
903}
904
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400905static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400906{
907 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500908
909 /* prevent frames from going back out of the port they came in on */
910 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700911
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100912 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700913}
914
Vivien Didelotf81ec902016-05-09 13:22:58 -0400915static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
916 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700917{
Vivien Didelot04bed142016-08-31 18:06:13 -0400918 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700919 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -0400920 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700921
922 switch (state) {
923 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +0200924 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700925 break;
926 case BR_STATE_BLOCKING:
927 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +0200928 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700929 break;
930 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +0200931 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700932 break;
933 case BR_STATE_FORWARDING:
934 default:
Andrew Lunncca8b132015-04-02 04:06:39 +0200935 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700936 break;
937 }
938
Vivien Didelotfad09c72016-06-21 12:28:20 -0400939 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +0100940 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400941 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400942
943 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +0100944 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700945}
946
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500947static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
948{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500949 int err;
950
Vivien Didelotdaefc942017-03-11 16:12:54 -0500951 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
952 if (err)
953 return err;
954
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500955 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
956 if (err)
957 return err;
958
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500959 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
960}
961
Vivien Didelot17a15942017-03-30 17:37:09 -0400962static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
963{
964 u16 pvlan = 0;
965
966 if (!mv88e6xxx_has_pvt(chip))
967 return -EOPNOTSUPP;
968
969 /* Skip the local source device, which uses in-chip port VLAN */
970 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -0400971 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -0400972
973 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
974}
975
Vivien Didelot81228992017-03-30 17:37:08 -0400976static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
977{
Vivien Didelot17a15942017-03-30 17:37:09 -0400978 int dev, port;
979 int err;
980
Vivien Didelot81228992017-03-30 17:37:08 -0400981 if (!mv88e6xxx_has_pvt(chip))
982 return 0;
983
984 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
985 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
986 */
Vivien Didelot17a15942017-03-30 17:37:09 -0400987 err = mv88e6xxx_g2_misc_4_bit_port(chip);
988 if (err)
989 return err;
990
991 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
992 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
993 err = mv88e6xxx_pvt_map(chip, dev, port);
994 if (err)
995 return err;
996 }
997 }
998
999 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001000}
1001
Vivien Didelot749efcb2016-09-22 16:49:24 -04001002static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1003{
1004 struct mv88e6xxx_chip *chip = ds->priv;
1005 int err;
1006
1007 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001008 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001009 mutex_unlock(&chip->reg_lock);
1010
1011 if (err)
1012 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1013}
1014
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001015static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1016{
1017 if (!chip->info->max_vid)
1018 return 0;
1019
1020 return mv88e6xxx_g1_vtu_flush(chip);
1021}
1022
Vivien Didelotf1394b782017-05-01 14:05:22 -04001023static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1024 struct mv88e6xxx_vtu_entry *entry)
1025{
1026 if (!chip->info->ops->vtu_getnext)
1027 return -EOPNOTSUPP;
1028
1029 return chip->info->ops->vtu_getnext(chip, entry);
1030}
1031
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001032static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1033 struct mv88e6xxx_vtu_entry *entry)
1034{
1035 if (!chip->info->ops->vtu_loadpurge)
1036 return -EOPNOTSUPP;
1037
1038 return chip->info->ops->vtu_loadpurge(chip, entry);
1039}
1040
Vivien Didelotf81ec902016-05-09 13:22:58 -04001041static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1042 struct switchdev_obj_port_vlan *vlan,
Vivien Didelot438ff532017-05-17 15:46:05 -04001043 switchdev_obj_dump_cb_t *cb)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001044{
Vivien Didelot04bed142016-08-31 18:06:13 -04001045 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001046 struct mv88e6xxx_vtu_entry next = {
1047 .vid = chip->info->max_vid,
1048 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001049 u16 pvid;
1050 int err;
1051
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001052 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001053 return -EOPNOTSUPP;
1054
Vivien Didelotfad09c72016-06-21 12:28:20 -04001055 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001056
Vivien Didelot77064f32016-11-04 03:23:30 +01001057 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001058 if (err)
1059 goto unlock;
1060
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001061 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001062 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001063 if (err)
1064 break;
1065
1066 if (!next.valid)
1067 break;
1068
Vivien Didelotbd00e052017-05-01 14:05:11 -04001069 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001070 continue;
1071
1072 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001073 vlan->vid_begin = next.vid;
1074 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001075 vlan->flags = 0;
1076
Vivien Didelotbd00e052017-05-01 14:05:11 -04001077 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001078 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1079
1080 if (next.vid == pvid)
1081 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1082
1083 err = cb(&vlan->obj);
1084 if (err)
1085 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001086 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001087
1088unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001089 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001090
1091 return err;
1092}
1093
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001094static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001095{
1096 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001097 struct mv88e6xxx_vtu_entry vlan = {
1098 .vid = chip->info->max_vid,
1099 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001100 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001101
1102 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1103
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001104 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001105 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001106 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001107 if (err)
1108 return err;
1109
1110 set_bit(*fid, fid_bitmap);
1111 }
1112
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001113 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001114 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001115 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001116 if (err)
1117 return err;
1118
1119 if (!vlan.valid)
1120 break;
1121
1122 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001123 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001124
1125 /* The reset value 0x000 is used to indicate that multiple address
1126 * databases are not needed. Return the next positive available.
1127 */
1128 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001129 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001130 return -ENOSPC;
1131
1132 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001133 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001134}
1135
Vivien Didelot567aa592017-05-01 14:05:25 -04001136static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1137 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001138{
1139 int err;
1140
1141 if (!vid)
1142 return -EINVAL;
1143
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001144 entry->vid = vid - 1;
1145 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001146
Vivien Didelotf1394b782017-05-01 14:05:22 -04001147 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001148 if (err)
1149 return err;
1150
Vivien Didelot567aa592017-05-01 14:05:25 -04001151 if (entry->vid == vid && entry->valid)
1152 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001153
Vivien Didelot567aa592017-05-01 14:05:25 -04001154 if (new) {
1155 int i;
1156
1157 /* Initialize a fresh VLAN entry */
1158 memset(entry, 0, sizeof(*entry));
1159 entry->valid = true;
1160 entry->vid = vid;
1161
1162 /* Include only CPU and DSA ports */
1163 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1164 entry->member[i] = dsa_is_normal_port(chip->ds, i) ?
1165 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER :
1166 GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1167
1168 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001169 }
1170
Vivien Didelot567aa592017-05-01 14:05:25 -04001171 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1172 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001173}
1174
Vivien Didelotda9c3592016-02-12 12:09:40 -05001175static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1176 u16 vid_begin, u16 vid_end)
1177{
Vivien Didelot04bed142016-08-31 18:06:13 -04001178 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001179 struct mv88e6xxx_vtu_entry vlan = {
1180 .vid = vid_begin - 1,
1181 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001182 int i, err;
1183
1184 if (!vid_begin)
1185 return -EOPNOTSUPP;
1186
Vivien Didelotfad09c72016-06-21 12:28:20 -04001187 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001188
Vivien Didelotda9c3592016-02-12 12:09:40 -05001189 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001190 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001191 if (err)
1192 goto unlock;
1193
1194 if (!vlan.valid)
1195 break;
1196
1197 if (vlan.vid > vid_end)
1198 break;
1199
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001200 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001201 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1202 continue;
1203
Andrew Lunn66e28092016-12-11 21:07:19 +01001204 if (!ds->ports[port].netdev)
1205 continue;
1206
Vivien Didelotbd00e052017-05-01 14:05:11 -04001207 if (vlan.member[i] ==
Vivien Didelotda9c3592016-02-12 12:09:40 -05001208 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1209 continue;
1210
Vivien Didelotfae8a252017-01-27 15:29:42 -05001211 if (ds->ports[i].bridge_dev ==
1212 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001213 break; /* same bridge, check next VLAN */
1214
Vivien Didelotfae8a252017-01-27 15:29:42 -05001215 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001216 continue;
1217
Andrew Lunnc8b09802016-06-04 21:16:57 +02001218 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001219 "hardware VLAN %d already used by %s\n",
1220 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001221 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001222 err = -EOPNOTSUPP;
1223 goto unlock;
1224 }
1225 } while (vlan.vid < vid_end);
1226
1227unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001228 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001229
1230 return err;
1231}
1232
Vivien Didelotf81ec902016-05-09 13:22:58 -04001233static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1234 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001235{
Vivien Didelot04bed142016-08-31 18:06:13 -04001236 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001237 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001238 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001239 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001240
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001241 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001242 return -EOPNOTSUPP;
1243
Vivien Didelotfad09c72016-06-21 12:28:20 -04001244 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001245 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001246 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001247
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001248 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001249}
1250
Vivien Didelot57d32312016-06-20 13:13:58 -04001251static int
1252mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1253 const struct switchdev_obj_port_vlan *vlan,
1254 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001255{
Vivien Didelot04bed142016-08-31 18:06:13 -04001256 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001257 int err;
1258
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001259 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001260 return -EOPNOTSUPP;
1261
Vivien Didelotda9c3592016-02-12 12:09:40 -05001262 /* If the requested port doesn't belong to the same bridge as the VLAN
1263 * members, do not support it (yet) and fallback to software VLAN.
1264 */
1265 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1266 vlan->vid_end);
1267 if (err)
1268 return err;
1269
Vivien Didelot76e398a2015-11-01 12:33:55 -05001270 /* We don't need any dynamic resource from the kernel (yet),
1271 * so skip the prepare phase.
1272 */
1273 return 0;
1274}
1275
Vivien Didelotfad09c72016-06-21 12:28:20 -04001276static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001277 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001278{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001279 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001280 int err;
1281
Vivien Didelot567aa592017-05-01 14:05:25 -04001282 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001283 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001284 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001285
Vivien Didelotc91498e2017-06-07 18:12:13 -04001286 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001287
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001288 return mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001289}
1290
Vivien Didelotf81ec902016-05-09 13:22:58 -04001291static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1292 const struct switchdev_obj_port_vlan *vlan,
1293 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001294{
Vivien Didelot04bed142016-08-31 18:06:13 -04001295 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001296 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1297 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001298 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001299 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001300
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001301 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001302 return;
1303
Vivien Didelotc91498e2017-06-07 18:12:13 -04001304 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1305 member = GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1306 else if (untagged)
1307 member = GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED;
1308 else
1309 member = GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1310
Vivien Didelotfad09c72016-06-21 12:28:20 -04001311 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001312
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001313 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001314 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001315 netdev_err(ds->ports[port].netdev,
1316 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001317 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001318
Vivien Didelot77064f32016-11-04 03:23:30 +01001319 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001320 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001321 vlan->vid_end);
1322
Vivien Didelotfad09c72016-06-21 12:28:20 -04001323 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001324}
1325
Vivien Didelotfad09c72016-06-21 12:28:20 -04001326static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001327 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001328{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001329 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001330 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001331 int i, err;
1332
Vivien Didelot567aa592017-05-01 14:05:25 -04001333 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001334 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001335 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001336
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001337 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelotbd00e052017-05-01 14:05:11 -04001338 if (vlan.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001339 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001340
Vivien Didelotbd00e052017-05-01 14:05:11 -04001341 vlan.member[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001342
1343 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001344 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001345 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001346 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001347 continue;
1348
Vivien Didelotbd00e052017-05-01 14:05:11 -04001349 if (vlan.member[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001350 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001351 break;
1352 }
1353 }
1354
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001355 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001356 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001357 return err;
1358
Vivien Didelote606ca32017-03-11 16:12:55 -05001359 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001360}
1361
Vivien Didelotf81ec902016-05-09 13:22:58 -04001362static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1363 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001364{
Vivien Didelot04bed142016-08-31 18:06:13 -04001365 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001366 u16 pvid, vid;
1367 int err = 0;
1368
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001369 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001370 return -EOPNOTSUPP;
1371
Vivien Didelotfad09c72016-06-21 12:28:20 -04001372 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001373
Vivien Didelot77064f32016-11-04 03:23:30 +01001374 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001375 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001376 goto unlock;
1377
Vivien Didelot76e398a2015-11-01 12:33:55 -05001378 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001379 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001380 if (err)
1381 goto unlock;
1382
1383 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001384 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001385 if (err)
1386 goto unlock;
1387 }
1388 }
1389
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001390unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001391 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001392
1393 return err;
1394}
1395
Vivien Didelot83dabd12016-08-31 11:50:04 -04001396static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1397 const unsigned char *addr, u16 vid,
1398 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001399{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001400 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001401 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001402 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001403
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001404 /* Null VLAN ID corresponds to the port private database */
1405 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001406 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001407 else
Vivien Didelot567aa592017-05-01 14:05:25 -04001408 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001409 if (err)
1410 return err;
1411
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001412 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1413 ether_addr_copy(entry.mac, addr);
1414 eth_addr_dec(entry.mac);
1415
1416 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001417 if (err)
1418 return err;
1419
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001420 /* Initialize a fresh ATU entry if it isn't found */
1421 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1422 !ether_addr_equal(entry.mac, addr)) {
1423 memset(&entry, 0, sizeof(entry));
1424 ether_addr_copy(entry.mac, addr);
1425 }
1426
Vivien Didelot88472932016-09-19 19:56:11 -04001427 /* Purge the ATU entry only if no port is using it anymore */
1428 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001429 entry.portvec &= ~BIT(port);
1430 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001431 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1432 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001433 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001434 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001435 }
1436
Vivien Didelot9c13c022017-03-11 16:12:52 -05001437 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001438}
1439
Vivien Didelotf81ec902016-05-09 13:22:58 -04001440static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1441 const struct switchdev_obj_port_fdb *fdb,
1442 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001443{
1444 /* We don't need any dynamic resource from the kernel (yet),
1445 * so skip the prepare phase.
1446 */
1447 return 0;
1448}
1449
Vivien Didelotf81ec902016-05-09 13:22:58 -04001450static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1451 const struct switchdev_obj_port_fdb *fdb,
1452 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001453{
Vivien Didelot04bed142016-08-31 18:06:13 -04001454 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001455
Vivien Didelotfad09c72016-06-21 12:28:20 -04001456 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001457 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1458 GLOBAL_ATU_DATA_STATE_UC_STATIC))
1459 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001460 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001461}
1462
Vivien Didelotf81ec902016-05-09 13:22:58 -04001463static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1464 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001465{
Vivien Didelot04bed142016-08-31 18:06:13 -04001466 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001467 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001468
Vivien Didelotfad09c72016-06-21 12:28:20 -04001469 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001470 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1471 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001472 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001473
Vivien Didelot83dabd12016-08-31 11:50:04 -04001474 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001475}
1476
Vivien Didelot83dabd12016-08-31 11:50:04 -04001477static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1478 u16 fid, u16 vid, int port,
1479 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001480 switchdev_obj_dump_cb_t *cb)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001481{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001482 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001483 int err;
1484
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001485 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1486 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001487
1488 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001489 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001490 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001491 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001492
1493 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1494 break;
1495
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001496 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001497 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001498
Vivien Didelot83dabd12016-08-31 11:50:04 -04001499 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1500 struct switchdev_obj_port_fdb *fdb;
1501
1502 if (!is_unicast_ether_addr(addr.mac))
1503 continue;
1504
1505 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001506 fdb->vid = vid;
1507 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001508 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
1509 fdb->ndm_state = NUD_NOARP;
1510 else
1511 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001512 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1513 struct switchdev_obj_port_mdb *mdb;
1514
1515 if (!is_multicast_ether_addr(addr.mac))
1516 continue;
1517
1518 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1519 mdb->vid = vid;
1520 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001521 } else {
1522 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001523 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001524
1525 err = cb(obj);
1526 if (err)
1527 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001528 } while (!is_broadcast_ether_addr(addr.mac));
1529
1530 return err;
1531}
1532
Vivien Didelot83dabd12016-08-31 11:50:04 -04001533static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1534 struct switchdev_obj *obj,
Vivien Didelot438ff532017-05-17 15:46:05 -04001535 switchdev_obj_dump_cb_t *cb)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001536{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001537 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001538 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001539 };
1540 u16 fid;
1541 int err;
1542
1543 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001544 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001545 if (err)
1546 return err;
1547
1548 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1549 if (err)
1550 return err;
1551
1552 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001553 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001554 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001555 if (err)
1556 return err;
1557
1558 if (!vlan.valid)
1559 break;
1560
1561 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1562 obj, cb);
1563 if (err)
1564 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001565 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001566
1567 return err;
1568}
1569
Vivien Didelotf81ec902016-05-09 13:22:58 -04001570static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1571 struct switchdev_obj_port_fdb *fdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04001572 switchdev_obj_dump_cb_t *cb)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001573{
Vivien Didelot04bed142016-08-31 18:06:13 -04001574 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001575 int err;
1576
Vivien Didelotfad09c72016-06-21 12:28:20 -04001577 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001578 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001579 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001580
1581 return err;
1582}
1583
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001584static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1585 struct net_device *br)
1586{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001587 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001588 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001589 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001590 int err;
1591
1592 /* Remap the Port VLAN of each local bridge group member */
1593 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1594 if (chip->ds->ports[port].bridge_dev == br) {
1595 err = mv88e6xxx_port_vlan_map(chip, port);
1596 if (err)
1597 return err;
1598 }
1599 }
1600
Vivien Didelote96a6e02017-03-30 17:37:13 -04001601 if (!mv88e6xxx_has_pvt(chip))
1602 return 0;
1603
1604 /* Remap the Port VLAN of each cross-chip bridge group member */
1605 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1606 ds = chip->ds->dst->ds[dev];
1607 if (!ds)
1608 break;
1609
1610 for (port = 0; port < ds->num_ports; ++port) {
1611 if (ds->ports[port].bridge_dev == br) {
1612 err = mv88e6xxx_pvt_map(chip, dev, port);
1613 if (err)
1614 return err;
1615 }
1616 }
1617 }
1618
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001619 return 0;
1620}
1621
Vivien Didelotf81ec902016-05-09 13:22:58 -04001622static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001623 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001624{
Vivien Didelot04bed142016-08-31 18:06:13 -04001625 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001626 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001627
Vivien Didelotfad09c72016-06-21 12:28:20 -04001628 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001629 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001630 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001631
Vivien Didelot466dfa02016-02-26 13:16:05 -05001632 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001633}
1634
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001635static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1636 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001637{
Vivien Didelot04bed142016-08-31 18:06:13 -04001638 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001639
Vivien Didelotfad09c72016-06-21 12:28:20 -04001640 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001641 if (mv88e6xxx_bridge_map(chip, br) ||
1642 mv88e6xxx_port_vlan_map(chip, port))
1643 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001644 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001645}
1646
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001647static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1648 int port, struct net_device *br)
1649{
1650 struct mv88e6xxx_chip *chip = ds->priv;
1651 int err;
1652
1653 if (!mv88e6xxx_has_pvt(chip))
1654 return 0;
1655
1656 mutex_lock(&chip->reg_lock);
1657 err = mv88e6xxx_pvt_map(chip, dev, port);
1658 mutex_unlock(&chip->reg_lock);
1659
1660 return err;
1661}
1662
1663static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1664 int port, struct net_device *br)
1665{
1666 struct mv88e6xxx_chip *chip = ds->priv;
1667
1668 if (!mv88e6xxx_has_pvt(chip))
1669 return;
1670
1671 mutex_lock(&chip->reg_lock);
1672 if (mv88e6xxx_pvt_map(chip, dev, port))
1673 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1674 mutex_unlock(&chip->reg_lock);
1675}
1676
Vivien Didelot17e708b2016-12-05 17:30:27 -05001677static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1678{
1679 if (chip->info->ops->reset)
1680 return chip->info->ops->reset(chip);
1681
1682 return 0;
1683}
1684
Vivien Didelot309eca62016-12-05 17:30:26 -05001685static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1686{
1687 struct gpio_desc *gpiod = chip->reset;
1688
1689 /* If there is a GPIO connected to the reset pin, toggle it */
1690 if (gpiod) {
1691 gpiod_set_value_cansleep(gpiod, 1);
1692 usleep_range(10000, 20000);
1693 gpiod_set_value_cansleep(gpiod, 0);
1694 usleep_range(10000, 20000);
1695 }
1696}
1697
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001698static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1699{
1700 int i, err;
1701
1702 /* Set all ports to the Disabled state */
1703 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1704 err = mv88e6xxx_port_set_state(chip, i,
1705 PORT_CONTROL_STATE_DISABLED);
1706 if (err)
1707 return err;
1708 }
1709
1710 /* Wait for transmit queues to drain,
1711 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1712 */
1713 usleep_range(2000, 4000);
1714
1715 return 0;
1716}
1717
Vivien Didelotfad09c72016-06-21 12:28:20 -04001718static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001719{
Vivien Didelota935c052016-09-29 12:21:53 -04001720 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001721
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001722 err = mv88e6xxx_disable_ports(chip);
1723 if (err)
1724 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001725
Vivien Didelot309eca62016-12-05 17:30:26 -05001726 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001727
Vivien Didelot17e708b2016-12-05 17:30:27 -05001728 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001729}
1730
Vivien Didelot43145572017-03-11 16:12:59 -05001731static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1732 enum mv88e6xxx_frame_mode frame, u16 egress,
1733 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001734{
1735 int err;
1736
Vivien Didelot43145572017-03-11 16:12:59 -05001737 if (!chip->info->ops->port_set_frame_mode)
1738 return -EOPNOTSUPP;
1739
1740 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001741 if (err)
1742 return err;
1743
Vivien Didelot43145572017-03-11 16:12:59 -05001744 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1745 if (err)
1746 return err;
1747
1748 if (chip->info->ops->port_set_ether_type)
1749 return chip->info->ops->port_set_ether_type(chip, port, etype);
1750
1751 return 0;
1752}
1753
1754static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1755{
1756 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1757 PORT_CONTROL_EGRESS_UNMODIFIED,
1758 PORT_ETH_TYPE_DEFAULT);
1759}
1760
1761static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1762{
1763 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1764 PORT_CONTROL_EGRESS_UNMODIFIED,
1765 PORT_ETH_TYPE_DEFAULT);
1766}
1767
1768static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1769{
1770 return mv88e6xxx_set_port_mode(chip, port,
1771 MV88E6XXX_FRAME_MODE_ETHERTYPE,
1772 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
1773}
1774
1775static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1776{
1777 if (dsa_is_dsa_port(chip->ds, port))
1778 return mv88e6xxx_set_port_mode_dsa(chip, port);
1779
1780 if (dsa_is_normal_port(chip->ds, port))
1781 return mv88e6xxx_set_port_mode_normal(chip, port);
1782
1783 /* Setup CPU port mode depending on its supported tag format */
1784 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1785 return mv88e6xxx_set_port_mode_dsa(chip, port);
1786
1787 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1788 return mv88e6xxx_set_port_mode_edsa(chip, port);
1789
1790 return -EINVAL;
1791}
1792
Vivien Didelotea698f42017-03-11 16:12:50 -05001793static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1794{
1795 bool message = dsa_is_dsa_port(chip->ds, port);
1796
1797 return mv88e6xxx_port_set_message_port(chip, port, message);
1798}
1799
Vivien Didelot601aeed2017-03-11 16:13:00 -05001800static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1801{
1802 bool flood = port == dsa_upstream_port(chip->ds);
1803
1804 /* Upstream ports flood frames with unknown unicast or multicast DA */
1805 if (chip->info->ops->port_set_egress_floods)
1806 return chip->info->ops->port_set_egress_floods(chip, port,
1807 flood, flood);
1808
1809 return 0;
1810}
1811
Andrew Lunn6d917822017-05-26 01:03:21 +02001812static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1813 bool on)
1814{
Vivien Didelot523a8902017-05-26 18:02:42 -04001815 if (chip->info->ops->serdes_power)
1816 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001817
Vivien Didelot523a8902017-05-26 18:02:42 -04001818 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001819}
1820
Vivien Didelotfad09c72016-06-21 12:28:20 -04001821static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001822{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001823 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001824 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001825 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001826
Vivien Didelotd78343d2016-11-04 03:23:36 +01001827 /* MAC Forcing register: don't force link, speed, duplex or flow control
1828 * state to any particular values on physical ports, but force the CPU
1829 * port and all DSA ports to their maximum bandwidth and full duplex.
1830 */
1831 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1832 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1833 SPEED_MAX, DUPLEX_FULL,
1834 PHY_INTERFACE_MODE_NA);
1835 else
1836 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1837 SPEED_UNFORCED, DUPLEX_UNFORCED,
1838 PHY_INTERFACE_MODE_NA);
1839 if (err)
1840 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001841
1842 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1843 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1844 * tunneling, determine priority by looking at 802.1p and IP
1845 * priority fields (IP prio has precedence), and set STP state
1846 * to Forwarding.
1847 *
1848 * If this is the CPU link, use DSA or EDSA tagging depending
1849 * on which tagging mode was configured.
1850 *
1851 * If this is a link to another switch, use DSA tagging mode.
1852 *
1853 * If this is the upstream port for this switch, enable
1854 * forwarding of unknown unicasts and multicasts.
1855 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01001856 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02001857 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
1858 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01001859 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
1860 if (err)
1861 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001862
Vivien Didelot601aeed2017-03-11 16:13:00 -05001863 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001864 if (err)
1865 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001866
Vivien Didelot601aeed2017-03-11 16:13:00 -05001867 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001868 if (err)
1869 return err;
1870
Andrew Lunn04aca992017-05-26 01:03:24 +02001871 /* Enable the SERDES interface for DSA and CPU ports. Normal
1872 * ports SERDES are enabled when the port is enabled, thus
1873 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001874 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001875 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1876 err = mv88e6xxx_serdes_power(chip, port, true);
1877 if (err)
1878 return err;
1879 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001880
Vivien Didelot8efdda42015-08-13 12:52:23 -04001881 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001882 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001883 * untagged frames on this port, do a destination address lookup on all
1884 * received packets as usual, disable ARP mirroring and don't send a
1885 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001886 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001887 err = mv88e6xxx_port_set_map_da(chip, port);
1888 if (err)
1889 return err;
1890
Andrew Lunn54d792f2015-05-06 01:09:47 +02001891 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01001892 if (chip->info->ops->port_set_upstream_port) {
1893 err = chip->info->ops->port_set_upstream_port(
1894 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001895 if (err)
1896 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001897 }
1898
Andrew Lunna23b2962017-02-04 20:15:28 +01001899 err = mv88e6xxx_port_set_8021q_mode(chip, port,
1900 PORT_CONTROL_2_8021Q_DISABLED);
1901 if (err)
1902 return err;
1903
Andrew Lunn5f436662016-12-03 04:45:17 +01001904 if (chip->info->ops->port_jumbo_config) {
1905 err = chip->info->ops->port_jumbo_config(chip, port);
1906 if (err)
1907 return err;
1908 }
1909
Andrew Lunn54d792f2015-05-06 01:09:47 +02001910 /* Port Association Vector: when learning source addresses
1911 * of packets, add the address to the address database using
1912 * a port bitmap that has only the bit for this port set and
1913 * the other bits clear.
1914 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001915 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001916 /* Disable learning for CPU port */
1917 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001918 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001919
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001920 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
1921 if (err)
1922 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001923
1924 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001925 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
1926 if (err)
1927 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001928
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001929 if (chip->info->ops->port_pause_config) {
1930 err = chip->info->ops->port_pause_config(chip, port);
1931 if (err)
1932 return err;
1933 }
1934
Vivien Didelotc8c94892017-03-11 16:13:01 -05001935 if (chip->info->ops->port_disable_learn_limit) {
1936 err = chip->info->ops->port_disable_learn_limit(chip, port);
1937 if (err)
1938 return err;
1939 }
1940
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001941 if (chip->info->ops->port_disable_pri_override) {
1942 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001943 if (err)
1944 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01001945 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02001946
Andrew Lunnef0a7312016-12-03 04:35:16 +01001947 if (chip->info->ops->port_tag_remap) {
1948 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001949 if (err)
1950 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001951 }
1952
Andrew Lunnef70b112016-12-03 04:45:18 +01001953 if (chip->info->ops->port_egress_rate_limiting) {
1954 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001955 if (err)
1956 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001957 }
1958
Vivien Didelotea698f42017-03-11 16:12:50 -05001959 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001960 if (err)
1961 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001962
Vivien Didelot207afda2016-04-14 14:42:09 -04001963 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001964 * database, and allow bidirectional communication between the
1965 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07001966 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001967 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001968 if (err)
1969 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001970
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001971 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001972 if (err)
1973 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001974
1975 /* Default VLAN ID and priority: don't set a default VLAN
1976 * ID, and set the default packet priority to zero.
1977 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001978 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02001979}
1980
Andrew Lunn04aca992017-05-26 01:03:24 +02001981static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
1982 struct phy_device *phydev)
1983{
1984 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04001985 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02001986
1987 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04001988 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02001989 mutex_unlock(&chip->reg_lock);
1990
1991 return err;
1992}
1993
1994static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
1995 struct phy_device *phydev)
1996{
1997 struct mv88e6xxx_chip *chip = ds->priv;
1998
1999 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002000 if (mv88e6xxx_serdes_power(chip, port, false))
2001 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002002 mutex_unlock(&chip->reg_lock);
2003}
2004
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002005static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002006{
2007 int err;
2008
Vivien Didelota935c052016-09-29 12:21:53 -04002009 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002010 if (err)
2011 return err;
2012
Vivien Didelota935c052016-09-29 12:21:53 -04002013 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002014 if (err)
2015 return err;
2016
Vivien Didelota935c052016-09-29 12:21:53 -04002017 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2018 if (err)
2019 return err;
2020
2021 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002022}
2023
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002024static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2025 unsigned int ageing_time)
2026{
Vivien Didelot04bed142016-08-31 18:06:13 -04002027 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002028 int err;
2029
2030 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002031 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002032 mutex_unlock(&chip->reg_lock);
2033
2034 return err;
2035}
2036
Vivien Didelot97299342016-07-18 20:45:30 -04002037static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002038{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002039 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002040 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002041 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002042
Andrew Lunn33641992016-12-03 04:35:17 +01002043 if (chip->info->ops->g1_set_cpu_port) {
2044 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2045 if (err)
2046 return err;
2047 }
2048
2049 if (chip->info->ops->g1_set_egress_port) {
2050 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2051 if (err)
2052 return err;
2053 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002054
Vivien Didelot50484ff2016-05-09 13:22:54 -04002055 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002056 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2057 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2058 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002059 if (err)
2060 return err;
2061
Vivien Didelot08a01262016-05-09 13:22:50 -04002062 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002063 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002064 if (err)
2065 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002066 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002067 if (err)
2068 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002069 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002070 if (err)
2071 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002072 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002073 if (err)
2074 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002075 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002076 if (err)
2077 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002078 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002079 if (err)
2080 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002081 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002082 if (err)
2083 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002084 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002085 if (err)
2086 return err;
2087
2088 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002089 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002090 if (err)
2091 return err;
2092
Andrew Lunnde2273872016-11-21 23:27:01 +01002093 /* Initialize the statistics unit */
2094 err = mv88e6xxx_stats_set_histogram(chip);
2095 if (err)
2096 return err;
2097
Vivien Didelot97299342016-07-18 20:45:30 -04002098 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002099 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2100 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002101 if (err)
2102 return err;
2103
2104 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002105 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002106 if (err)
2107 return err;
2108
2109 return 0;
2110}
2111
Vivien Didelotf81ec902016-05-09 13:22:58 -04002112static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002113{
Vivien Didelot04bed142016-08-31 18:06:13 -04002114 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002115 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002116 int i;
2117
Vivien Didelotfad09c72016-06-21 12:28:20 -04002118 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002119 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002120
Vivien Didelotfad09c72016-06-21 12:28:20 -04002121 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002122
Vivien Didelot97299342016-07-18 20:45:30 -04002123 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002124 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002125 err = mv88e6xxx_setup_port(chip, i);
2126 if (err)
2127 goto unlock;
2128 }
2129
2130 /* Setup Switch Global 1 Registers */
2131 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002132 if (err)
2133 goto unlock;
2134
Vivien Didelot97299342016-07-18 20:45:30 -04002135 /* Setup Switch Global 2 Registers */
2136 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2137 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002138 if (err)
2139 goto unlock;
2140 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002141
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002142 err = mv88e6xxx_phy_setup(chip);
2143 if (err)
2144 goto unlock;
2145
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002146 err = mv88e6xxx_vtu_setup(chip);
2147 if (err)
2148 goto unlock;
2149
Vivien Didelot81228992017-03-30 17:37:08 -04002150 err = mv88e6xxx_pvt_setup(chip);
2151 if (err)
2152 goto unlock;
2153
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002154 err = mv88e6xxx_atu_setup(chip);
2155 if (err)
2156 goto unlock;
2157
Andrew Lunn6e55f692016-12-03 04:45:16 +01002158 /* Some generations have the configuration of sending reserved
2159 * management frames to the CPU in global2, others in
2160 * global1. Hence it does not fit the two setup functions
2161 * above.
2162 */
2163 if (chip->info->ops->mgmt_rsvd2cpu) {
2164 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2165 if (err)
2166 goto unlock;
2167 }
2168
Vivien Didelot6b17e862015-08-13 12:52:18 -04002169unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002170 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002171
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002172 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002173}
2174
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002175static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2176{
Vivien Didelot04bed142016-08-31 18:06:13 -04002177 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002178 int err;
2179
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002180 if (!chip->info->ops->set_switch_mac)
2181 return -EOPNOTSUPP;
2182
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002183 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002184 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002185 mutex_unlock(&chip->reg_lock);
2186
2187 return err;
2188}
2189
Vivien Didelote57e5e72016-08-15 17:19:00 -04002190static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
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 u16 val;
2195 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002196
Andrew Lunnee26a222017-01-24 14:53:48 +01002197 if (!chip->info->ops->phy_read)
2198 return -EOPNOTSUPP;
2199
Vivien Didelotfad09c72016-06-21 12:28:20 -04002200 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002201 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002202 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002203
Andrew Lunnda9f3302017-02-01 03:40:05 +01002204 if (reg == MII_PHYSID2) {
2205 /* Some internal PHYS don't have a model number. Use
2206 * the mv88e6390 family model number instead.
2207 */
2208 if (!(val & 0x3f0))
2209 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2210 }
2211
Vivien Didelote57e5e72016-08-15 17:19:00 -04002212 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002213}
2214
Vivien Didelote57e5e72016-08-15 17:19:00 -04002215static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002216{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002217 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2218 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002219 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002220
Andrew Lunnee26a222017-01-24 14:53:48 +01002221 if (!chip->info->ops->phy_write)
2222 return -EOPNOTSUPP;
2223
Vivien Didelotfad09c72016-06-21 12:28:20 -04002224 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002225 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002226 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002227
2228 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002229}
2230
Vivien Didelotfad09c72016-06-21 12:28:20 -04002231static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002232 struct device_node *np,
2233 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002234{
2235 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002236 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002237 struct mii_bus *bus;
2238 int err;
2239
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002240 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002241 if (!bus)
2242 return -ENOMEM;
2243
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002244 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002245 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002246 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002247 INIT_LIST_HEAD(&mdio_bus->list);
2248 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002249
Andrew Lunnb516d452016-06-04 21:17:06 +02002250 if (np) {
2251 bus->name = np->full_name;
2252 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2253 } else {
2254 bus->name = "mv88e6xxx SMI";
2255 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2256 }
2257
2258 bus->read = mv88e6xxx_mdio_read;
2259 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002260 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002261
Andrew Lunna3c53be52017-01-24 14:53:50 +01002262 if (np)
2263 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002264 else
2265 err = mdiobus_register(bus);
2266 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002267 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002268 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002269 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002270
2271 if (external)
2272 list_add_tail(&mdio_bus->list, &chip->mdios);
2273 else
2274 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002275
2276 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002277}
2278
Andrew Lunna3c53be52017-01-24 14:53:50 +01002279static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2280 { .compatible = "marvell,mv88e6xxx-mdio-external",
2281 .data = (void *)true },
2282 { },
2283};
2284
2285static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2286 struct device_node *np)
2287{
2288 const struct of_device_id *match;
2289 struct device_node *child;
2290 int err;
2291
2292 /* Always register one mdio bus for the internal/default mdio
2293 * bus. This maybe represented in the device tree, but is
2294 * optional.
2295 */
2296 child = of_get_child_by_name(np, "mdio");
2297 err = mv88e6xxx_mdio_register(chip, child, false);
2298 if (err)
2299 return err;
2300
2301 /* Walk the device tree, and see if there are any other nodes
2302 * which say they are compatible with the external mdio
2303 * bus.
2304 */
2305 for_each_available_child_of_node(np, child) {
2306 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2307 if (match) {
2308 err = mv88e6xxx_mdio_register(chip, child, true);
2309 if (err)
2310 return err;
2311 }
2312 }
2313
2314 return 0;
2315}
2316
2317static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002318
2319{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002320 struct mv88e6xxx_mdio_bus *mdio_bus;
2321 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002322
Andrew Lunna3c53be52017-01-24 14:53:50 +01002323 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2324 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002325
Andrew Lunna3c53be52017-01-24 14:53:50 +01002326 mdiobus_unregister(bus);
2327 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002328}
2329
Vivien Didelot855b1932016-07-20 18:18:35 -04002330static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2331{
Vivien Didelot04bed142016-08-31 18:06:13 -04002332 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002333
2334 return chip->eeprom_len;
2335}
2336
Vivien Didelot855b1932016-07-20 18:18:35 -04002337static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2338 struct ethtool_eeprom *eeprom, u8 *data)
2339{
Vivien Didelot04bed142016-08-31 18:06:13 -04002340 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002341 int err;
2342
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002343 if (!chip->info->ops->get_eeprom)
2344 return -EOPNOTSUPP;
2345
Vivien Didelot855b1932016-07-20 18:18:35 -04002346 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002347 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002348 mutex_unlock(&chip->reg_lock);
2349
2350 if (err)
2351 return err;
2352
2353 eeprom->magic = 0xc3ec4951;
2354
2355 return 0;
2356}
2357
Vivien Didelot855b1932016-07-20 18:18:35 -04002358static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2359 struct ethtool_eeprom *eeprom, u8 *data)
2360{
Vivien Didelot04bed142016-08-31 18:06:13 -04002361 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002362 int err;
2363
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002364 if (!chip->info->ops->set_eeprom)
2365 return -EOPNOTSUPP;
2366
Vivien Didelot855b1932016-07-20 18:18:35 -04002367 if (eeprom->magic != 0xc3ec4951)
2368 return -EINVAL;
2369
2370 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002371 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002372 mutex_unlock(&chip->reg_lock);
2373
2374 return err;
2375}
2376
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002377static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002378 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002379 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002380 .phy_read = mv88e6185_phy_ppu_read,
2381 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002382 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002383 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002384 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002385 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002386 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002387 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002388 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002389 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002390 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002391 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002392 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002393 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002394 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2395 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002396 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002397 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2398 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002399 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002400 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002401 .ppu_enable = mv88e6185_g1_ppu_enable,
2402 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002403 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002404 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002405 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002406};
2407
2408static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002409 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002410 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002411 .phy_read = mv88e6185_phy_ppu_read,
2412 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002413 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002414 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002415 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002416 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002417 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002418 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002419 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002420 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2421 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002422 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002423 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002424 .ppu_enable = mv88e6185_g1_ppu_enable,
2425 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002426 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002427 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002428 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002429};
2430
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002431static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002432 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002433 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2434 .phy_read = mv88e6xxx_g2_smi_phy_read,
2435 .phy_write = mv88e6xxx_g2_smi_phy_write,
2436 .port_set_link = mv88e6xxx_port_set_link,
2437 .port_set_duplex = mv88e6xxx_port_set_duplex,
2438 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002439 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002440 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002441 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002442 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002443 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002444 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002445 .port_pause_config = mv88e6097_port_pause_config,
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,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002448 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2449 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2450 .stats_get_strings = mv88e6095_stats_get_strings,
2451 .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,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +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,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002459};
2460
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002461static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002462 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002463 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002464 .phy_read = mv88e6xxx_g2_smi_phy_read,
2465 .phy_write = mv88e6xxx_g2_smi_phy_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 Lunn56995cb2016-12-03 04:35:19 +01002469 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002470 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002471 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002472 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002473 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002474 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2475 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002476 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002477 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2478 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002479 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002480 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002481 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002482 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002483 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002484};
2485
2486static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002487 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002488 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002489 .phy_read = mv88e6185_phy_ppu_read,
2490 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002491 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002492 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002493 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002494 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002495 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002496 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002497 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002498 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002499 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002500 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002501 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002502 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002503 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2504 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002505 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002506 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2507 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002508 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002509 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002510 .ppu_enable = mv88e6185_g1_ppu_enable,
2511 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002512 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002513 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002514 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002515};
2516
Vivien Didelot990e27b2017-03-28 13:50:32 -04002517static const struct mv88e6xxx_ops mv88e6141_ops = {
2518 /* MV88E6XXX_FAMILY_6341 */
2519 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2520 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2521 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2522 .phy_read = mv88e6xxx_g2_smi_phy_read,
2523 .phy_write = mv88e6xxx_g2_smi_phy_write,
2524 .port_set_link = mv88e6xxx_port_set_link,
2525 .port_set_duplex = mv88e6xxx_port_set_duplex,
2526 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2527 .port_set_speed = mv88e6390_port_set_speed,
2528 .port_tag_remap = mv88e6095_port_tag_remap,
2529 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2530 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2531 .port_set_ether_type = mv88e6351_port_set_ether_type,
2532 .port_jumbo_config = mv88e6165_port_jumbo_config,
2533 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2534 .port_pause_config = mv88e6097_port_pause_config,
2535 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2536 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2537 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2538 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2539 .stats_get_strings = mv88e6320_stats_get_strings,
2540 .stats_get_stats = mv88e6390_stats_get_stats,
2541 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2542 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2543 .watchdog_ops = &mv88e6390_watchdog_ops,
2544 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2545 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002546 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002547 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002548};
2549
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002550static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002551 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002552 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002553 .phy_read = mv88e6xxx_g2_smi_phy_read,
2554 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002555 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002556 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002557 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002558 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002559 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002560 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002561 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002562 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002563 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002564 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002565 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002566 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002567 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002568 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2569 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002570 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002571 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2572 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002573 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002574 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002575 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002576 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002577 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002578};
2579
2580static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002581 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002582 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002583 .phy_read = mv88e6165_phy_read,
2584 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002585 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002586 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002587 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002588 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002589 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002590 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002591 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2592 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002593 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002594 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2595 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002596 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002597 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002598 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002599 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002600 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002601};
2602
2603static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002604 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002605 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002606 .phy_read = mv88e6xxx_g2_smi_phy_read,
2607 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002608 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002609 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002610 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002611 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002612 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002613 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002614 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002615 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002616 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002617 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002618 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002619 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002620 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002621 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002622 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2623 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002624 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002625 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2626 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002627 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002628 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002629 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002630 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002631 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002632};
2633
2634static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002635 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002636 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2637 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002638 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002639 .phy_read = mv88e6xxx_g2_smi_phy_read,
2640 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002641 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002642 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002643 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002644 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002645 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002646 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002647 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002648 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002649 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002650 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002651 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002652 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002653 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002654 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002655 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2656 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002657 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002658 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2659 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002660 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002661 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002662 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002663 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002664 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002665 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002666};
2667
2668static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002669 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002670 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002671 .phy_read = mv88e6xxx_g2_smi_phy_read,
2672 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002673 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002674 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002675 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002676 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002677 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002678 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002679 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002680 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002681 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002682 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002683 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002684 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002685 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002686 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002687 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2688 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002689 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002690 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2691 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002692 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002693 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002694 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002695 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002696 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002697};
2698
2699static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002700 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002701 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2702 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002703 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002704 .phy_read = mv88e6xxx_g2_smi_phy_read,
2705 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002706 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002707 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002708 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002709 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002710 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002711 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002712 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002713 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002714 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002715 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002716 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002717 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002718 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002719 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002720 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2721 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002722 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002723 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2724 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002725 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002726 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002727 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002728 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002729 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002730 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002731};
2732
2733static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002734 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002735 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002736 .phy_read = mv88e6185_phy_ppu_read,
2737 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002738 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002739 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002740 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002741 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002742 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002743 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002744 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002745 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002746 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2747 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002748 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002749 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2750 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002751 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002752 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002753 .ppu_enable = mv88e6185_g1_ppu_enable,
2754 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002755 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002756 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002757 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002758};
2759
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002760static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002761 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002762 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2763 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002764 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2765 .phy_read = mv88e6xxx_g2_smi_phy_read,
2766 .phy_write = mv88e6xxx_g2_smi_phy_write,
2767 .port_set_link = mv88e6xxx_port_set_link,
2768 .port_set_duplex = mv88e6xxx_port_set_duplex,
2769 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2770 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002771 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002772 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002773 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002774 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002775 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002776 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002777 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002778 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002779 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002780 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2781 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002782 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002783 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2784 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002785 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002786 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002787 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002788 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2789 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002790 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002791};
2792
2793static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002794 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002795 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2796 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002797 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2798 .phy_read = mv88e6xxx_g2_smi_phy_read,
2799 .phy_write = mv88e6xxx_g2_smi_phy_write,
2800 .port_set_link = mv88e6xxx_port_set_link,
2801 .port_set_duplex = mv88e6xxx_port_set_duplex,
2802 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2803 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002804 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002805 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002806 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002807 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002808 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002809 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002810 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002811 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002812 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002813 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2814 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002815 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002816 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2817 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002818 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002819 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002820 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002821 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2822 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002823 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002824};
2825
2826static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002827 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002828 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2829 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002830 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2831 .phy_read = mv88e6xxx_g2_smi_phy_read,
2832 .phy_write = mv88e6xxx_g2_smi_phy_write,
2833 .port_set_link = mv88e6xxx_port_set_link,
2834 .port_set_duplex = mv88e6xxx_port_set_duplex,
2835 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2836 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002837 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002838 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002839 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002840 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002841 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002842 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002843 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002844 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002845 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002846 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2847 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002848 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002849 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2850 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002851 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002852 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002853 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002854 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2855 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002856 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002857};
2858
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002859static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002860 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002861 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2862 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002863 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002864 .phy_read = mv88e6xxx_g2_smi_phy_read,
2865 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002866 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002867 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002868 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002869 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002870 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002871 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002872 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002873 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002874 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002875 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002876 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002877 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002878 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002879 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002880 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2881 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002882 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002883 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2884 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002885 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002886 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002887 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002888 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002889 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002890 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002891};
2892
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002893static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002894 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002895 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2896 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002897 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2898 .phy_read = mv88e6xxx_g2_smi_phy_read,
2899 .phy_write = mv88e6xxx_g2_smi_phy_write,
2900 .port_set_link = mv88e6xxx_port_set_link,
2901 .port_set_duplex = mv88e6xxx_port_set_duplex,
2902 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2903 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002904 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002905 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002906 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002907 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002908 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002909 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002910 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002911 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002912 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002913 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002914 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2915 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002916 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002917 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2918 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002919 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002920 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002921 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002922 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2923 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002924 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002925};
2926
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002927static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002928 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002929 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2930 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002931 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002932 .phy_read = mv88e6xxx_g2_smi_phy_read,
2933 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002934 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002935 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002936 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002937 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002938 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002939 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002940 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002941 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002942 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002943 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002944 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002945 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002946 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002947 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2948 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002949 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002950 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2951 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002952 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002953 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002954 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002955 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002956};
2957
2958static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002959 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002960 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2961 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002962 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002963 .phy_read = mv88e6xxx_g2_smi_phy_read,
2964 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002965 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002966 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002967 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002968 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002969 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002970 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002971 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002972 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002973 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002974 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002975 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002976 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002977 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002978 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2979 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002980 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002981 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2982 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002983 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002984 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002985 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002986};
2987
Vivien Didelot16e329a2017-03-28 13:50:33 -04002988static const struct mv88e6xxx_ops mv88e6341_ops = {
2989 /* MV88E6XXX_FAMILY_6341 */
2990 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2991 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2992 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2993 .phy_read = mv88e6xxx_g2_smi_phy_read,
2994 .phy_write = mv88e6xxx_g2_smi_phy_write,
2995 .port_set_link = mv88e6xxx_port_set_link,
2996 .port_set_duplex = mv88e6xxx_port_set_duplex,
2997 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2998 .port_set_speed = mv88e6390_port_set_speed,
2999 .port_tag_remap = mv88e6095_port_tag_remap,
3000 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3001 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3002 .port_set_ether_type = mv88e6351_port_set_ether_type,
3003 .port_jumbo_config = mv88e6165_port_jumbo_config,
3004 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3005 .port_pause_config = mv88e6097_port_pause_config,
3006 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3007 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3008 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3009 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3010 .stats_get_strings = mv88e6320_stats_get_strings,
3011 .stats_get_stats = mv88e6390_stats_get_stats,
3012 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3013 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3014 .watchdog_ops = &mv88e6390_watchdog_ops,
3015 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3016 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003017 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003018 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003019};
3020
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003021static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003022 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003023 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003024 .phy_read = mv88e6xxx_g2_smi_phy_read,
3025 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003026 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003027 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003028 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003029 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003030 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003031 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003032 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003033 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003034 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003035 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003036 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003037 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003038 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003039 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003040 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3041 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003042 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003043 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3044 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003045 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003046 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003047 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003048 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003049 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003050};
3051
3052static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003053 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003054 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003055 .phy_read = mv88e6xxx_g2_smi_phy_read,
3056 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003057 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003058 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003059 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003060 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003061 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003062 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003063 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003064 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003065 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003066 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003067 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003068 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003069 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003070 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003071 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3072 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003073 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003074 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3075 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003076 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003077 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003078 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003079 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003080 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003081};
3082
3083static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003084 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003085 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3086 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003087 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003088 .phy_read = mv88e6xxx_g2_smi_phy_read,
3089 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003090 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003091 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003092 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003093 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003094 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003095 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003096 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003097 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003098 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003099 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003100 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003101 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003102 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003103 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003104 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3105 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003106 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003107 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3108 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003109 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003110 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003111 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003112 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003113 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003114 .serdes_power = mv88e6352_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003115};
3116
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003117static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003118 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003119 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3120 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003121 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3122 .phy_read = mv88e6xxx_g2_smi_phy_read,
3123 .phy_write = mv88e6xxx_g2_smi_phy_write,
3124 .port_set_link = mv88e6xxx_port_set_link,
3125 .port_set_duplex = mv88e6xxx_port_set_duplex,
3126 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3127 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003128 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003129 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003130 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003131 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003132 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003133 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003134 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003135 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003136 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003137 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003138 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003139 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003140 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3141 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003142 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003143 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3144 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003145 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003146 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003147 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003148 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3149 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003150 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003151};
3152
3153static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003154 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003155 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3156 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003157 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3158 .phy_read = mv88e6xxx_g2_smi_phy_read,
3159 .phy_write = mv88e6xxx_g2_smi_phy_write,
3160 .port_set_link = mv88e6xxx_port_set_link,
3161 .port_set_duplex = mv88e6xxx_port_set_duplex,
3162 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3163 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003164 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003165 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003166 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003167 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003168 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003169 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003170 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003171 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003172 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003173 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003174 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003175 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3176 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003177 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003178 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3179 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003180 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003181 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003182 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003183 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3184 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003185 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003186};
3187
Vivien Didelotf81ec902016-05-09 13:22:58 -04003188static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3189 [MV88E6085] = {
3190 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3191 .family = MV88E6XXX_FAMILY_6097,
3192 .name = "Marvell 88E6085",
3193 .num_databases = 4096,
3194 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003195 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003196 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003197 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003198 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003199 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003200 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003201 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003202 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003203 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003204 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003205 },
3206
3207 [MV88E6095] = {
3208 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3209 .family = MV88E6XXX_FAMILY_6095,
3210 .name = "Marvell 88E6095/88E6095F",
3211 .num_databases = 256,
3212 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003213 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003214 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003215 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003216 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003217 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003218 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003219 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003220 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003221 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003222 },
3223
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003224 [MV88E6097] = {
3225 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3226 .family = MV88E6XXX_FAMILY_6097,
3227 .name = "Marvell 88E6097/88E6097F",
3228 .num_databases = 4096,
3229 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003230 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003231 .port_base_addr = 0x10,
3232 .global1_addr = 0x1b,
3233 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003234 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003235 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003236 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003237 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003238 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3239 .ops = &mv88e6097_ops,
3240 },
3241
Vivien Didelotf81ec902016-05-09 13:22:58 -04003242 [MV88E6123] = {
3243 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3244 .family = MV88E6XXX_FAMILY_6165,
3245 .name = "Marvell 88E6123",
3246 .num_databases = 4096,
3247 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003248 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003249 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003250 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003251 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003252 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003253 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003254 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003255 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003256 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003257 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003258 },
3259
3260 [MV88E6131] = {
3261 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3262 .family = MV88E6XXX_FAMILY_6185,
3263 .name = "Marvell 88E6131",
3264 .num_databases = 256,
3265 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003266 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003267 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003268 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003269 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003270 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003271 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003272 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003273 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003274 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003275 },
3276
Vivien Didelot990e27b2017-03-28 13:50:32 -04003277 [MV88E6141] = {
3278 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3279 .family = MV88E6XXX_FAMILY_6341,
3280 .name = "Marvell 88E6341",
3281 .num_databases = 4096,
3282 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003283 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003284 .port_base_addr = 0x10,
3285 .global1_addr = 0x1b,
3286 .age_time_coeff = 3750,
3287 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003288 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003289 .tag_protocol = DSA_TAG_PROTO_EDSA,
3290 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3291 .ops = &mv88e6141_ops,
3292 },
3293
Vivien Didelotf81ec902016-05-09 13:22:58 -04003294 [MV88E6161] = {
3295 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3296 .family = MV88E6XXX_FAMILY_6165,
3297 .name = "Marvell 88E6161",
3298 .num_databases = 4096,
3299 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003300 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003301 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003302 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003303 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003304 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003305 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003306 .pvt = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003307 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003308 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003309 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003310 },
3311
3312 [MV88E6165] = {
3313 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3314 .family = MV88E6XXX_FAMILY_6165,
3315 .name = "Marvell 88E6165",
3316 .num_databases = 4096,
3317 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003318 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003319 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003320 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003321 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003322 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003323 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003324 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003325 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003326 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003327 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003328 },
3329
3330 [MV88E6171] = {
3331 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3332 .family = MV88E6XXX_FAMILY_6351,
3333 .name = "Marvell 88E6171",
3334 .num_databases = 4096,
3335 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003336 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003337 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003338 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003339 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003340 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003341 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003342 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003343 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003344 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003345 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003346 },
3347
3348 [MV88E6172] = {
3349 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3350 .family = MV88E6XXX_FAMILY_6352,
3351 .name = "Marvell 88E6172",
3352 .num_databases = 4096,
3353 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003354 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003355 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003356 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003357 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003358 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003359 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003360 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003361 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003362 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003363 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003364 },
3365
3366 [MV88E6175] = {
3367 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3368 .family = MV88E6XXX_FAMILY_6351,
3369 .name = "Marvell 88E6175",
3370 .num_databases = 4096,
3371 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003372 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003373 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003374 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003375 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003376 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003377 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003378 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003379 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003380 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003381 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003382 },
3383
3384 [MV88E6176] = {
3385 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3386 .family = MV88E6XXX_FAMILY_6352,
3387 .name = "Marvell 88E6176",
3388 .num_databases = 4096,
3389 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003390 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003391 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003392 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003393 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003394 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003395 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003396 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003397 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003398 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003399 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003400 },
3401
3402 [MV88E6185] = {
3403 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3404 .family = MV88E6XXX_FAMILY_6185,
3405 .name = "Marvell 88E6185",
3406 .num_databases = 256,
3407 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003408 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003409 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003410 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003411 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003412 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003413 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003414 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003415 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003416 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003417 },
3418
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003419 [MV88E6190] = {
3420 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3421 .family = MV88E6XXX_FAMILY_6390,
3422 .name = "Marvell 88E6190",
3423 .num_databases = 4096,
3424 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003425 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003426 .port_base_addr = 0x0,
3427 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003428 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003429 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003430 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003431 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003432 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003433 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3434 .ops = &mv88e6190_ops,
3435 },
3436
3437 [MV88E6190X] = {
3438 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3439 .family = MV88E6XXX_FAMILY_6390,
3440 .name = "Marvell 88E6190X",
3441 .num_databases = 4096,
3442 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003443 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003444 .port_base_addr = 0x0,
3445 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003446 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003447 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003448 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003449 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003450 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003451 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3452 .ops = &mv88e6190x_ops,
3453 },
3454
3455 [MV88E6191] = {
3456 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3457 .family = MV88E6XXX_FAMILY_6390,
3458 .name = "Marvell 88E6191",
3459 .num_databases = 4096,
3460 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003461 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003462 .port_base_addr = 0x0,
3463 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003464 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003465 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003466 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003467 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003468 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003469 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003470 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003471 },
3472
Vivien Didelotf81ec902016-05-09 13:22:58 -04003473 [MV88E6240] = {
3474 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3475 .family = MV88E6XXX_FAMILY_6352,
3476 .name = "Marvell 88E6240",
3477 .num_databases = 4096,
3478 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003479 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003480 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003481 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003482 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003483 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003484 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003485 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003486 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003487 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003488 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003489 },
3490
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003491 [MV88E6290] = {
3492 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3493 .family = MV88E6XXX_FAMILY_6390,
3494 .name = "Marvell 88E6290",
3495 .num_databases = 4096,
3496 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003497 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003498 .port_base_addr = 0x0,
3499 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003500 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003501 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003502 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003503 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003504 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003505 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3506 .ops = &mv88e6290_ops,
3507 },
3508
Vivien Didelotf81ec902016-05-09 13:22:58 -04003509 [MV88E6320] = {
3510 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3511 .family = MV88E6XXX_FAMILY_6320,
3512 .name = "Marvell 88E6320",
3513 .num_databases = 4096,
3514 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003515 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003516 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003517 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003518 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003519 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003520 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003521 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003522 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003523 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003524 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003525 },
3526
3527 [MV88E6321] = {
3528 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3529 .family = MV88E6XXX_FAMILY_6320,
3530 .name = "Marvell 88E6321",
3531 .num_databases = 4096,
3532 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003533 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003534 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003535 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003536 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003537 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003538 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003539 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003540 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003541 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003542 },
3543
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003544 [MV88E6341] = {
3545 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3546 .family = MV88E6XXX_FAMILY_6341,
3547 .name = "Marvell 88E6341",
3548 .num_databases = 4096,
3549 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003550 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003551 .port_base_addr = 0x10,
3552 .global1_addr = 0x1b,
3553 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003554 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003555 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003556 .tag_protocol = DSA_TAG_PROTO_EDSA,
3557 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3558 .ops = &mv88e6341_ops,
3559 },
3560
Vivien Didelotf81ec902016-05-09 13:22:58 -04003561 [MV88E6350] = {
3562 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3563 .family = MV88E6XXX_FAMILY_6351,
3564 .name = "Marvell 88E6350",
3565 .num_databases = 4096,
3566 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003567 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003568 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003569 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003570 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003571 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003572 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003573 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003574 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003575 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003576 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003577 },
3578
3579 [MV88E6351] = {
3580 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3581 .family = MV88E6XXX_FAMILY_6351,
3582 .name = "Marvell 88E6351",
3583 .num_databases = 4096,
3584 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003585 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003586 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003587 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003588 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003589 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003590 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003591 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003592 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003593 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003594 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003595 },
3596
3597 [MV88E6352] = {
3598 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3599 .family = MV88E6XXX_FAMILY_6352,
3600 .name = "Marvell 88E6352",
3601 .num_databases = 4096,
3602 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003603 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003604 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003605 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003606 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003607 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003608 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003609 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003610 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003611 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003612 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003613 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003614 [MV88E6390] = {
3615 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3616 .family = MV88E6XXX_FAMILY_6390,
3617 .name = "Marvell 88E6390",
3618 .num_databases = 4096,
3619 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003620 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003621 .port_base_addr = 0x0,
3622 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003623 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003624 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003625 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003626 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003627 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003628 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3629 .ops = &mv88e6390_ops,
3630 },
3631 [MV88E6390X] = {
3632 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3633 .family = MV88E6XXX_FAMILY_6390,
3634 .name = "Marvell 88E6390X",
3635 .num_databases = 4096,
3636 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003637 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003638 .port_base_addr = 0x0,
3639 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003640 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003641 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003642 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003643 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003644 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003645 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3646 .ops = &mv88e6390x_ops,
3647 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003648};
3649
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003650static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003651{
Vivien Didelota439c062016-04-17 13:23:58 -04003652 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003653
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003654 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3655 if (mv88e6xxx_table[i].prod_num == prod_num)
3656 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003657
Vivien Didelotb9b37712015-10-30 19:39:48 -04003658 return NULL;
3659}
3660
Vivien Didelotfad09c72016-06-21 12:28:20 -04003661static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003662{
3663 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003664 unsigned int prod_num, rev;
3665 u16 id;
3666 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003667
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003668 mutex_lock(&chip->reg_lock);
3669 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3670 mutex_unlock(&chip->reg_lock);
3671 if (err)
3672 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003673
3674 prod_num = (id & 0xfff0) >> 4;
3675 rev = id & 0x000f;
3676
3677 info = mv88e6xxx_lookup_info(prod_num);
3678 if (!info)
3679 return -ENODEV;
3680
Vivien Didelotcaac8542016-06-20 13:14:09 -04003681 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003682 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003683
Vivien Didelotca070c12016-09-02 14:45:34 -04003684 err = mv88e6xxx_g2_require(chip);
3685 if (err)
3686 return err;
3687
Vivien Didelotfad09c72016-06-21 12:28:20 -04003688 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3689 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003690
3691 return 0;
3692}
3693
Vivien Didelotfad09c72016-06-21 12:28:20 -04003694static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003695{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003696 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003697
Vivien Didelotfad09c72016-06-21 12:28:20 -04003698 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3699 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003700 return NULL;
3701
Vivien Didelotfad09c72016-06-21 12:28:20 -04003702 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003703
Vivien Didelotfad09c72016-06-21 12:28:20 -04003704 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003705 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003706
Vivien Didelotfad09c72016-06-21 12:28:20 -04003707 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003708}
3709
Vivien Didelotfad09c72016-06-21 12:28:20 -04003710static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003711 struct mii_bus *bus, int sw_addr)
3712{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003713 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003714 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003715 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003716 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003717 else
3718 return -EINVAL;
3719
Vivien Didelotfad09c72016-06-21 12:28:20 -04003720 chip->bus = bus;
3721 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003722
3723 return 0;
3724}
3725
Andrew Lunn7b314362016-08-22 16:01:01 +02003726static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3727{
Vivien Didelot04bed142016-08-31 18:06:13 -04003728 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003729
Andrew Lunn443d5a12016-12-03 04:35:18 +01003730 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003731}
3732
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003733static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3734 struct device *host_dev, int sw_addr,
3735 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003736{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003737 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003738 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003739 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003740
Vivien Didelota439c062016-04-17 13:23:58 -04003741 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003742 if (!bus)
3743 return NULL;
3744
Vivien Didelotfad09c72016-06-21 12:28:20 -04003745 chip = mv88e6xxx_alloc_chip(dsa_dev);
3746 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003747 return NULL;
3748
Vivien Didelotcaac8542016-06-20 13:14:09 -04003749 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003750 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003751
Vivien Didelotfad09c72016-06-21 12:28:20 -04003752 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003753 if (err)
3754 goto free;
3755
Vivien Didelotfad09c72016-06-21 12:28:20 -04003756 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003757 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003758 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003759
Andrew Lunndc30c352016-10-16 19:56:49 +02003760 mutex_lock(&chip->reg_lock);
3761 err = mv88e6xxx_switch_reset(chip);
3762 mutex_unlock(&chip->reg_lock);
3763 if (err)
3764 goto free;
3765
Vivien Didelote57e5e72016-08-15 17:19:00 -04003766 mv88e6xxx_phy_init(chip);
3767
Andrew Lunna3c53be52017-01-24 14:53:50 +01003768 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003769 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003770 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003771
Vivien Didelotfad09c72016-06-21 12:28:20 -04003772 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003773
Vivien Didelotfad09c72016-06-21 12:28:20 -04003774 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003775free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003776 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003777
3778 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003779}
3780
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003781static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3782 const struct switchdev_obj_port_mdb *mdb,
3783 struct switchdev_trans *trans)
3784{
3785 /* We don't need any dynamic resource from the kernel (yet),
3786 * so skip the prepare phase.
3787 */
3788
3789 return 0;
3790}
3791
3792static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3793 const struct switchdev_obj_port_mdb *mdb,
3794 struct switchdev_trans *trans)
3795{
Vivien Didelot04bed142016-08-31 18:06:13 -04003796 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003797
3798 mutex_lock(&chip->reg_lock);
3799 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3800 GLOBAL_ATU_DATA_STATE_MC_STATIC))
3801 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
3802 mutex_unlock(&chip->reg_lock);
3803}
3804
3805static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3806 const struct switchdev_obj_port_mdb *mdb)
3807{
Vivien Didelot04bed142016-08-31 18:06:13 -04003808 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003809 int err;
3810
3811 mutex_lock(&chip->reg_lock);
3812 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3813 GLOBAL_ATU_DATA_STATE_UNUSED);
3814 mutex_unlock(&chip->reg_lock);
3815
3816 return err;
3817}
3818
3819static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3820 struct switchdev_obj_port_mdb *mdb,
Vivien Didelot438ff532017-05-17 15:46:05 -04003821 switchdev_obj_dump_cb_t *cb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003822{
Vivien Didelot04bed142016-08-31 18:06:13 -04003823 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003824 int err;
3825
3826 mutex_lock(&chip->reg_lock);
3827 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3828 mutex_unlock(&chip->reg_lock);
3829
3830 return err;
3831}
3832
Florian Fainellia82f67a2017-01-08 14:52:08 -08003833static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003834 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02003835 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003836 .setup = mv88e6xxx_setup,
3837 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003838 .adjust_link = mv88e6xxx_adjust_link,
3839 .get_strings = mv88e6xxx_get_strings,
3840 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3841 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02003842 .port_enable = mv88e6xxx_port_enable,
3843 .port_disable = mv88e6xxx_port_disable,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003844 .set_eee = mv88e6xxx_set_eee,
3845 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003846 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003847 .get_eeprom = mv88e6xxx_get_eeprom,
3848 .set_eeprom = mv88e6xxx_set_eeprom,
3849 .get_regs_len = mv88e6xxx_get_regs_len,
3850 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003851 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003852 .port_bridge_join = mv88e6xxx_port_bridge_join,
3853 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3854 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04003855 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003856 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3857 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3858 .port_vlan_add = mv88e6xxx_port_vlan_add,
3859 .port_vlan_del = mv88e6xxx_port_vlan_del,
3860 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3861 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3862 .port_fdb_add = mv88e6xxx_port_fdb_add,
3863 .port_fdb_del = mv88e6xxx_port_fdb_del,
3864 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003865 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3866 .port_mdb_add = mv88e6xxx_port_mdb_add,
3867 .port_mdb_del = mv88e6xxx_port_mdb_del,
3868 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04003869 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
3870 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003871};
3872
Florian Fainelliab3d4082017-01-08 14:52:07 -08003873static struct dsa_switch_driver mv88e6xxx_switch_drv = {
3874 .ops = &mv88e6xxx_switch_ops,
3875};
3876
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003877static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003878{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003879 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003880 struct dsa_switch *ds;
3881
Vivien Didelot73b12042017-03-30 17:37:10 -04003882 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003883 if (!ds)
3884 return -ENOMEM;
3885
Vivien Didelotfad09c72016-06-21 12:28:20 -04003886 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04003887 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04003888 ds->ageing_time_min = chip->info->age_time_coeff;
3889 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003890
3891 dev_set_drvdata(dev, ds);
3892
Vivien Didelot23c9ee42017-05-26 18:12:51 -04003893 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003894}
3895
Vivien Didelotfad09c72016-06-21 12:28:20 -04003896static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003897{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003898 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003899}
3900
Vivien Didelot57d32312016-06-20 13:13:58 -04003901static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003902{
3903 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003904 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003905 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003906 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003907 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02003908 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003909
Vivien Didelotcaac8542016-06-20 13:14:09 -04003910 compat_info = of_device_get_match_data(dev);
3911 if (!compat_info)
3912 return -EINVAL;
3913
Vivien Didelotfad09c72016-06-21 12:28:20 -04003914 chip = mv88e6xxx_alloc_chip(dev);
3915 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003916 return -ENOMEM;
3917
Vivien Didelotfad09c72016-06-21 12:28:20 -04003918 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003919
Vivien Didelotfad09c72016-06-21 12:28:20 -04003920 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003921 if (err)
3922 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003923
Andrew Lunnb4308f02016-11-21 23:26:55 +01003924 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
3925 if (IS_ERR(chip->reset))
3926 return PTR_ERR(chip->reset);
3927
Vivien Didelotfad09c72016-06-21 12:28:20 -04003928 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003929 if (err)
3930 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003931
Vivien Didelote57e5e72016-08-15 17:19:00 -04003932 mv88e6xxx_phy_init(chip);
3933
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003934 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003935 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003936 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003937
Andrew Lunndc30c352016-10-16 19:56:49 +02003938 mutex_lock(&chip->reg_lock);
3939 err = mv88e6xxx_switch_reset(chip);
3940 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02003941 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02003942 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02003943
Andrew Lunndc30c352016-10-16 19:56:49 +02003944 chip->irq = of_irq_get(np, 0);
3945 if (chip->irq == -EPROBE_DEFER) {
3946 err = chip->irq;
3947 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02003948 }
3949
Andrew Lunndc30c352016-10-16 19:56:49 +02003950 if (chip->irq > 0) {
3951 /* Has to be performed before the MDIO bus is created,
3952 * because the PHYs will link there interrupts to these
3953 * interrupt controllers
3954 */
3955 mutex_lock(&chip->reg_lock);
3956 err = mv88e6xxx_g1_irq_setup(chip);
3957 mutex_unlock(&chip->reg_lock);
3958
3959 if (err)
3960 goto out;
3961
3962 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
3963 err = mv88e6xxx_g2_irq_setup(chip);
3964 if (err)
3965 goto out_g1_irq;
3966 }
3967 }
3968
Andrew Lunna3c53be52017-01-24 14:53:50 +01003969 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02003970 if (err)
3971 goto out_g2_irq;
3972
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08003973 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003974 if (err)
3975 goto out_mdio;
3976
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003977 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02003978
3979out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01003980 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003981out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01003982 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02003983 mv88e6xxx_g2_irq_free(chip);
3984out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003985 if (chip->irq > 0) {
3986 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01003987 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01003988 mutex_unlock(&chip->reg_lock);
3989 }
Andrew Lunndc30c352016-10-16 19:56:49 +02003990out:
3991 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003992}
3993
3994static void mv88e6xxx_remove(struct mdio_device *mdiodev)
3995{
3996 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04003997 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003998
Andrew Lunn930188c2016-08-22 16:01:03 +02003999 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004000 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004001 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004002
Andrew Lunn467126442016-11-20 20:14:15 +01004003 if (chip->irq > 0) {
4004 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4005 mv88e6xxx_g2_irq_free(chip);
4006 mv88e6xxx_g1_irq_free(chip);
4007 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004008}
4009
4010static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004011 {
4012 .compatible = "marvell,mv88e6085",
4013 .data = &mv88e6xxx_table[MV88E6085],
4014 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004015 {
4016 .compatible = "marvell,mv88e6190",
4017 .data = &mv88e6xxx_table[MV88E6190],
4018 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004019 { /* sentinel */ },
4020};
4021
4022MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4023
4024static struct mdio_driver mv88e6xxx_driver = {
4025 .probe = mv88e6xxx_probe,
4026 .remove = mv88e6xxx_remove,
4027 .mdiodrv.driver = {
4028 .name = "mv88e6085",
4029 .of_match_table = mv88e6xxx_of_match,
4030 },
4031};
4032
Ben Hutchings98e67302011-11-25 14:36:19 +00004033static int __init mv88e6xxx_init(void)
4034{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004035 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004036 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004037}
4038module_init(mv88e6xxx_init);
4039
4040static void __exit mv88e6xxx_cleanup(void)
4041{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004042 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004043 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004044}
4045module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004046
4047MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4048MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4049MODULE_LICENSE("GPL");