blob: 94939a24dd62d034a556b7dfacd88387caba3700 [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>
Andrew Lunn877b7cb2018-05-19 22:31:34 +020031#include <linux/platform_data/mv88e6xxx.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000032#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010033#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000034#include <linux/phy.h>
Russell Kingc9a23562018-05-10 13:17:35 -070035#include <linux/phylink.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000036#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040037
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040038#include "chip.h"
Vivien Didelota935c052016-09-29 12:21:53 -040039#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040040#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010041#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020042#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010043#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010044#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020045#include "serdes.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000046
Vivien Didelotfad09c72016-06-21 12:28:20 -040047static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040048{
Vivien Didelotfad09c72016-06-21 12:28:20 -040049 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
50 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040051 dump_stack();
52 }
53}
54
Vivien Didelot914b32f2016-06-20 13:14:11 -040055/* The switch ADDR[4:1] configuration pins define the chip SMI device address
56 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
57 *
58 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
59 * is the only device connected to the SMI master. In this mode it responds to
60 * all 32 possible SMI addresses, and thus maps directly the internal devices.
61 *
62 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
63 * multiple devices to share the SMI interface. In this mode it responds to only
64 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000065 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040066
Vivien Didelotfad09c72016-06-21 12:28:20 -040067static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040068 int addr, int reg, u16 *val)
69{
Vivien Didelotfad09c72016-06-21 12:28:20 -040070 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040071 return -EOPNOTSUPP;
72
Vivien Didelotfad09c72016-06-21 12:28:20 -040073 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040074}
75
Vivien Didelotfad09c72016-06-21 12:28:20 -040076static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040077 int addr, int reg, u16 val)
78{
Vivien Didelotfad09c72016-06-21 12:28:20 -040079 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040080 return -EOPNOTSUPP;
81
Vivien Didelotfad09c72016-06-21 12:28:20 -040082 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040083}
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 int addr, int reg, u16 *val)
87{
88 int ret;
89
Vivien Didelotfad09c72016-06-21 12:28:20 -040090 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040091 if (ret < 0)
92 return ret;
93
94 *val = ret & 0xffff;
95
96 return 0;
97}
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 int addr, int reg, u16 val)
101{
102 int ret;
103
Vivien Didelotfad09c72016-06-21 12:28:20 -0400104 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400105 if (ret < 0)
106 return ret;
107
108 return 0;
109}
110
Vivien Didelotc08026a2016-09-29 12:21:59 -0400111static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400112 .read = mv88e6xxx_smi_single_chip_read,
113 .write = mv88e6xxx_smi_single_chip_write,
114};
115
Vivien Didelotfad09c72016-06-21 12:28:20 -0400116static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000117{
118 int ret;
119 int i;
120
121 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400122 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000123 if (ret < 0)
124 return ret;
125
Andrew Lunncca8b132015-04-02 04:06:39 +0200126 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000127 return 0;
128 }
129
130 return -ETIMEDOUT;
131}
132
Vivien Didelotfad09c72016-06-21 12:28:20 -0400133static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400134 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135{
136 int ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000140 if (ret < 0)
141 return ret;
142
Barry Grussling3675c8d2013-01-08 16:05:53 +0000143 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400144 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200145 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Barry Grussling3675c8d2013-01-08 16:05:53 +0000154 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400155 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000156 if (ret < 0)
157 return ret;
158
Vivien Didelot914b32f2016-06-20 13:14:11 -0400159 *val = ret & 0xffff;
160
161 return 0;
162}
163
Vivien Didelotfad09c72016-06-21 12:28:20 -0400164static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400165 int addr, int reg, u16 val)
166{
167 int ret;
168
169 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 if (ret < 0)
177 return ret;
178
179 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400180 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400181 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
182 if (ret < 0)
183 return ret;
184
185 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400186 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400187 if (ret < 0)
188 return ret;
189
190 return 0;
191}
192
Vivien Didelotc08026a2016-09-29 12:21:59 -0400193static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194 .read = mv88e6xxx_smi_multi_chip_read,
195 .write = mv88e6xxx_smi_multi_chip_write,
196};
197
Vivien Didelotec561272016-09-02 14:45:33 -0400198int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400199{
200 int err;
201
Vivien Didelotfad09c72016-06-21 12:28:20 -0400202 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400203
Vivien Didelotfad09c72016-06-21 12:28:20 -0400204 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400205 if (err)
206 return err;
207
Vivien Didelotfad09c72016-06-21 12:28:20 -0400208 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400209 addr, reg, *val);
210
211 return 0;
212}
213
Vivien Didelotec561272016-09-02 14:45:33 -0400214int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400215{
216 int err;
217
Vivien Didelotfad09c72016-06-21 12:28:20 -0400218 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400219
Vivien Didelotfad09c72016-06-21 12:28:20 -0400220 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400221 if (err)
222 return err;
223
Vivien Didelotfad09c72016-06-21 12:28:20 -0400224 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400225 addr, reg, val);
226
227 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000228}
229
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200230struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100231{
232 struct mv88e6xxx_mdio_bus *mdio_bus;
233
234 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
235 list);
236 if (!mdio_bus)
237 return NULL;
238
239 return mdio_bus->bus;
240}
241
Andrew Lunndc30c352016-10-16 19:56:49 +0200242static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
243{
244 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
245 unsigned int n = d->hwirq;
246
247 chip->g1_irq.masked |= (1 << n);
248}
249
250static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
251{
252 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
253 unsigned int n = d->hwirq;
254
255 chip->g1_irq.masked &= ~(1 << n);
256}
257
Andrew Lunn294d7112018-02-22 22:58:32 +0100258static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200259{
Andrew Lunndc30c352016-10-16 19:56:49 +0200260 unsigned int nhandled = 0;
261 unsigned int sub_irq;
262 unsigned int n;
263 u16 reg;
264 int err;
265
266 mutex_lock(&chip->reg_lock);
Vivien Didelot82466922017-06-15 12:13:59 -0400267 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200268 mutex_unlock(&chip->reg_lock);
269
270 if (err)
271 goto out;
272
273 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
274 if (reg & (1 << n)) {
275 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
276 handle_nested_irq(sub_irq);
277 ++nhandled;
278 }
279 }
280out:
281 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
282}
283
Andrew Lunn294d7112018-02-22 22:58:32 +0100284static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
285{
286 struct mv88e6xxx_chip *chip = dev_id;
287
288 return mv88e6xxx_g1_irq_thread_work(chip);
289}
290
Andrew Lunndc30c352016-10-16 19:56:49 +0200291static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
292{
293 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
294
295 mutex_lock(&chip->reg_lock);
296}
297
298static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
299{
300 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
301 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
302 u16 reg;
303 int err;
304
Vivien Didelotd77f4322017-06-15 12:14:03 -0400305 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200306 if (err)
307 goto out;
308
309 reg &= ~mask;
310 reg |= (~chip->g1_irq.masked & mask);
311
Vivien Didelotd77f4322017-06-15 12:14:03 -0400312 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200313 if (err)
314 goto out;
315
316out:
317 mutex_unlock(&chip->reg_lock);
318}
319
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530320static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200321 .name = "mv88e6xxx-g1",
322 .irq_mask = mv88e6xxx_g1_irq_mask,
323 .irq_unmask = mv88e6xxx_g1_irq_unmask,
324 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
325 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
326};
327
328static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
329 unsigned int irq,
330 irq_hw_number_t hwirq)
331{
332 struct mv88e6xxx_chip *chip = d->host_data;
333
334 irq_set_chip_data(irq, d->host_data);
335 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
336 irq_set_noprobe(irq);
337
338 return 0;
339}
340
341static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
342 .map = mv88e6xxx_g1_irq_domain_map,
343 .xlate = irq_domain_xlate_twocell,
344};
345
Andrew Lunn294d7112018-02-22 22:58:32 +0100346static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200347{
348 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100349 u16 mask;
350
Vivien Didelotd77f4322017-06-15 12:14:03 -0400351 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100352 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400353 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100354
Andreas Färber5edef2f2016-11-27 23:26:28 +0100355 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100356 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200357 irq_dispose_mapping(virq);
358 }
359
Andrew Lunna3db3d32016-11-20 20:14:14 +0100360 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200361}
362
Andrew Lunn294d7112018-02-22 22:58:32 +0100363static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
364{
Andrew Lunnb19e5c12018-03-08 21:21:36 +0100365 mv88e6xxx_g1_irq_free_common(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100366
367 free_irq(chip->irq, chip);
368}
369
370static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200371{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100372 int err, irq, virq;
373 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200374
375 chip->g1_irq.nirqs = chip->info->g1_irqs;
376 chip->g1_irq.domain = irq_domain_add_simple(
377 NULL, chip->g1_irq.nirqs, 0,
378 &mv88e6xxx_g1_irq_domain_ops, chip);
379 if (!chip->g1_irq.domain)
380 return -ENOMEM;
381
382 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
383 irq_create_mapping(chip->g1_irq.domain, irq);
384
385 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
386 chip->g1_irq.masked = ~0;
387
Vivien Didelotd77f4322017-06-15 12:14:03 -0400388 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200389 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100390 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200391
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100392 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200393
Vivien Didelotd77f4322017-06-15 12:14:03 -0400394 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200395 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100396 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200397
398 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400399 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200400 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100401 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200402
Andrew Lunndc30c352016-10-16 19:56:49 +0200403 return 0;
404
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100405out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100406 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400407 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100408
409out_mapping:
410 for (irq = 0; irq < 16; irq++) {
411 virq = irq_find_mapping(chip->g1_irq.domain, irq);
412 irq_dispose_mapping(virq);
413 }
414
415 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200416
417 return err;
418}
419
Andrew Lunn294d7112018-02-22 22:58:32 +0100420static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
421{
422 int err;
423
424 err = mv88e6xxx_g1_irq_setup_common(chip);
425 if (err)
426 return err;
427
428 err = request_threaded_irq(chip->irq, NULL,
429 mv88e6xxx_g1_irq_thread_fn,
Andrew Lunn422a9fd62018-03-25 23:43:14 +0200430 IRQF_ONESHOT,
Andrew Lunn294d7112018-02-22 22:58:32 +0100431 dev_name(chip->dev), chip);
432 if (err)
433 mv88e6xxx_g1_irq_free_common(chip);
434
435 return err;
436}
437
438static void mv88e6xxx_irq_poll(struct kthread_work *work)
439{
440 struct mv88e6xxx_chip *chip = container_of(work,
441 struct mv88e6xxx_chip,
442 irq_poll_work.work);
443 mv88e6xxx_g1_irq_thread_work(chip);
444
445 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
446 msecs_to_jiffies(100));
447}
448
449static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
450{
451 int err;
452
453 err = mv88e6xxx_g1_irq_setup_common(chip);
454 if (err)
455 return err;
456
457 kthread_init_delayed_work(&chip->irq_poll_work,
458 mv88e6xxx_irq_poll);
459
460 chip->kworker = kthread_create_worker(0, dev_name(chip->dev));
461 if (IS_ERR(chip->kworker))
462 return PTR_ERR(chip->kworker);
463
464 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
465 msecs_to_jiffies(100));
466
467 return 0;
468}
469
470static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
471{
Andrew Lunn71f74ae2018-03-25 23:43:15 +0200472 mv88e6xxx_g1_irq_free_common(chip);
473
Andrew Lunn294d7112018-02-22 22:58:32 +0100474 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
475 kthread_destroy_worker(chip->kworker);
476}
477
Vivien Didelotec561272016-09-02 14:45:33 -0400478int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400479{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200480 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400481
Andrew Lunn6441e6692016-08-19 00:01:55 +0200482 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400483 u16 val;
484 int err;
485
486 err = mv88e6xxx_read(chip, addr, reg, &val);
487 if (err)
488 return err;
489
490 if (!(val & mask))
491 return 0;
492
493 usleep_range(1000, 2000);
494 }
495
Andrew Lunn30853552016-08-19 00:01:57 +0200496 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400497 return -ETIMEDOUT;
498}
499
Vivien Didelotf22ab642016-07-18 20:45:31 -0400500/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400501int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400502{
503 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200504 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400505
506 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200507 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
508 if (err)
509 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400510
511 /* Set the Update bit to trigger a write operation */
512 val = BIT(15) | update;
513
514 return mv88e6xxx_write(chip, addr, reg, val);
515}
516
Vivien Didelotd78343d2016-11-04 03:23:36 +0100517static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
518 int link, int speed, int duplex,
519 phy_interface_t mode)
520{
521 int err;
522
523 if (!chip->info->ops->port_set_link)
524 return 0;
525
526 /* Port's MAC control must not be changed unless the link is down */
527 err = chip->info->ops->port_set_link(chip, port, 0);
528 if (err)
529 return err;
530
531 if (chip->info->ops->port_set_speed) {
532 err = chip->info->ops->port_set_speed(chip, port, speed);
533 if (err && err != -EOPNOTSUPP)
534 goto restore_link;
535 }
536
537 if (chip->info->ops->port_set_duplex) {
538 err = chip->info->ops->port_set_duplex(chip, port, duplex);
539 if (err && err != -EOPNOTSUPP)
540 goto restore_link;
541 }
542
543 if (chip->info->ops->port_set_rgmii_delay) {
544 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
545 if (err && err != -EOPNOTSUPP)
546 goto restore_link;
547 }
548
Andrew Lunnf39908d2017-02-04 20:02:50 +0100549 if (chip->info->ops->port_set_cmode) {
550 err = chip->info->ops->port_set_cmode(chip, port, mode);
551 if (err && err != -EOPNOTSUPP)
552 goto restore_link;
553 }
554
Vivien Didelotd78343d2016-11-04 03:23:36 +0100555 err = 0;
556restore_link:
557 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400558 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100559
560 return err;
561}
562
Andrew Lunndea87022015-08-31 15:56:47 +0200563/* We expect the switch to perform auto negotiation if there is a real
564 * phy. However, in the case of a fixed link phy, we force the port
565 * settings from the fixed link settings.
566 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400567static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
568 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200569{
Vivien Didelot04bed142016-08-31 18:06:13 -0400570 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200571 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200572
573 if (!phy_is_pseudo_fixed_link(phydev))
574 return;
575
Vivien Didelotfad09c72016-06-21 12:28:20 -0400576 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100577 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
578 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400579 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100580
581 if (err && err != -EOPNOTSUPP)
Vivien Didelot774439e52017-06-08 18:34:08 -0400582 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
Andrew Lunndea87022015-08-31 15:56:47 +0200583}
584
Russell Kingc9a23562018-05-10 13:17:35 -0700585static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
586 unsigned long *supported,
587 struct phylink_link_state *state)
588{
589}
590
591static int mv88e6xxx_link_state(struct dsa_switch *ds, int port,
592 struct phylink_link_state *state)
593{
594 struct mv88e6xxx_chip *chip = ds->priv;
595 int err;
596
597 mutex_lock(&chip->reg_lock);
598 err = mv88e6xxx_port_link_state(chip, port, state);
599 mutex_unlock(&chip->reg_lock);
600
601 return err;
602}
603
604static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
605 unsigned int mode,
606 const struct phylink_link_state *state)
607{
608 struct mv88e6xxx_chip *chip = ds->priv;
609 int speed, duplex, link, err;
610
611 if (mode == MLO_AN_PHY)
612 return;
613
614 if (mode == MLO_AN_FIXED) {
615 link = LINK_FORCED_UP;
616 speed = state->speed;
617 duplex = state->duplex;
618 } else {
619 speed = SPEED_UNFORCED;
620 duplex = DUPLEX_UNFORCED;
621 link = LINK_UNFORCED;
622 }
623
624 mutex_lock(&chip->reg_lock);
625 err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex,
626 state->interface);
627 mutex_unlock(&chip->reg_lock);
628
629 if (err && err != -EOPNOTSUPP)
630 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
631}
632
633static void mv88e6xxx_mac_link_force(struct dsa_switch *ds, int port, int link)
634{
635 struct mv88e6xxx_chip *chip = ds->priv;
636 int err;
637
638 mutex_lock(&chip->reg_lock);
639 err = chip->info->ops->port_set_link(chip, port, link);
640 mutex_unlock(&chip->reg_lock);
641
642 if (err)
643 dev_err(chip->dev, "p%d: failed to force MAC link\n", port);
644}
645
646static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
647 unsigned int mode,
648 phy_interface_t interface)
649{
650 if (mode == MLO_AN_FIXED)
651 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_DOWN);
652}
653
654static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
655 unsigned int mode, phy_interface_t interface,
656 struct phy_device *phydev)
657{
658 if (mode == MLO_AN_FIXED)
659 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_UP);
660}
661
Andrew Lunna605a0f2016-11-21 23:26:58 +0100662static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000663{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100664 if (!chip->info->ops->stats_snapshot)
665 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000666
Andrew Lunna605a0f2016-11-21 23:26:58 +0100667 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000668}
669
Andrew Lunne413e7e2015-04-02 04:06:38 +0200670static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100671 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
672 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
673 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
674 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
675 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
676 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
677 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
678 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
679 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
680 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
681 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
682 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
683 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
684 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
685 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
686 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
687 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
688 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
689 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
690 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
691 { "single", 4, 0x14, STATS_TYPE_BANK0, },
692 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
693 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
694 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
695 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
696 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
697 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
698 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
699 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
700 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
701 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
702 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
703 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
704 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
705 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
706 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
707 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
708 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
709 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
710 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
711 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
712 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
713 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
714 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
715 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
716 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
717 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
718 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
719 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
720 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
721 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
722 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
723 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
724 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
725 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
726 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
727 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
728 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
729 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200730};
731
Vivien Didelotfad09c72016-06-21 12:28:20 -0400732static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100733 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100734 int port, u16 bank1_select,
735 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200736{
Andrew Lunn80c46272015-06-20 18:42:30 +0200737 u32 low;
738 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100739 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200740 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200741 u64 value;
742
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100743 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100744 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200745 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
746 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800747 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200748
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200749 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100750 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200751 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
752 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800753 return U64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200754 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200755 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100756 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100757 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100758 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100759 /* fall through */
760 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100761 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100762 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100763 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100764 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500765 break;
766 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800767 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200768 }
769 value = (((u64)high) << 16) | low;
770 return value;
771}
772
Andrew Lunn436fe172018-03-01 02:02:29 +0100773static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
774 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100775{
776 struct mv88e6xxx_hw_stat *stat;
777 int i, j;
778
779 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
780 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100781 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100782 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
783 ETH_GSTRING_LEN);
784 j++;
785 }
786 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100787
788 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100789}
790
Andrew Lunn436fe172018-03-01 02:02:29 +0100791static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
792 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100793{
Andrew Lunn436fe172018-03-01 02:02:29 +0100794 return mv88e6xxx_stats_get_strings(chip, data,
795 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100796}
797
Andrew Lunn436fe172018-03-01 02:02:29 +0100798static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
799 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100800{
Andrew Lunn436fe172018-03-01 02:02:29 +0100801 return mv88e6xxx_stats_get_strings(chip, data,
802 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100803}
804
Andrew Lunn65f60e42018-03-28 23:50:28 +0200805static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
806 "atu_member_violation",
807 "atu_miss_violation",
808 "atu_full_violation",
809 "vtu_member_violation",
810 "vtu_miss_violation",
811};
812
813static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
814{
815 unsigned int i;
816
817 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
818 strlcpy(data + i * ETH_GSTRING_LEN,
819 mv88e6xxx_atu_vtu_stats_strings[i],
820 ETH_GSTRING_LEN);
821}
822
Andrew Lunndfafe442016-11-21 23:27:02 +0100823static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700824 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100825{
Vivien Didelot04bed142016-08-31 18:06:13 -0400826 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100827 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100828
Florian Fainelli89f09042018-04-25 12:12:50 -0700829 if (stringset != ETH_SS_STATS)
830 return;
831
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100832 mutex_lock(&chip->reg_lock);
833
Andrew Lunndfafe442016-11-21 23:27:02 +0100834 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100835 count = chip->info->ops->stats_get_strings(chip, data);
836
837 if (chip->info->ops->serdes_get_strings) {
838 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200839 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100840 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100841
Andrew Lunn65f60e42018-03-28 23:50:28 +0200842 data += count * ETH_GSTRING_LEN;
843 mv88e6xxx_atu_vtu_get_strings(data);
844
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100845 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100846}
847
848static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
849 int types)
850{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100851 struct mv88e6xxx_hw_stat *stat;
852 int i, j;
853
854 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
855 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100857 j++;
858 }
859 return j;
860}
861
Andrew Lunndfafe442016-11-21 23:27:02 +0100862static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
863{
864 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
865 STATS_TYPE_PORT);
866}
867
868static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
869{
870 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
871 STATS_TYPE_BANK1);
872}
873
Florian Fainelli89f09042018-04-25 12:12:50 -0700874static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +0100875{
876 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100877 int serdes_count = 0;
878 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100879
Florian Fainelli89f09042018-04-25 12:12:50 -0700880 if (sset != ETH_SS_STATS)
881 return 0;
882
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100883 mutex_lock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100884 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100885 count = chip->info->ops->stats_get_sset_count(chip);
886 if (count < 0)
887 goto out;
888
889 if (chip->info->ops->serdes_get_sset_count)
890 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
891 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +0200892 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +0100893 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200894 goto out;
895 }
896 count += serdes_count;
897 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
898
Andrew Lunn436fe172018-03-01 02:02:29 +0100899out:
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100900 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100901
Andrew Lunn436fe172018-03-01 02:02:29 +0100902 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +0100903}
904
Andrew Lunn436fe172018-03-01 02:02:29 +0100905static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
906 uint64_t *data, int types,
907 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100908{
909 struct mv88e6xxx_hw_stat *stat;
910 int i, j;
911
912 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
913 stat = &mv88e6xxx_hw_stats[i];
914 if (stat->type & types) {
Andrew Lunn377cda12018-02-15 14:38:34 +0100915 mutex_lock(&chip->reg_lock);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100916 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
917 bank1_select,
918 histogram);
Andrew Lunn377cda12018-02-15 14:38:34 +0100919 mutex_unlock(&chip->reg_lock);
920
Andrew Lunn052f9472016-11-21 23:27:03 +0100921 j++;
922 }
923 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100924 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +0100925}
926
Andrew Lunn436fe172018-03-01 02:02:29 +0100927static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
928 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100929{
930 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100931 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400932 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100933}
934
Andrew Lunn436fe172018-03-01 02:02:29 +0100935static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
936 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100937{
938 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100939 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400940 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
941 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100942}
943
Andrew Lunn436fe172018-03-01 02:02:29 +0100944static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
945 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +0100946{
947 return mv88e6xxx_stats_get_stats(chip, port, data,
948 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400949 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
950 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100951}
952
Andrew Lunn65f60e42018-03-28 23:50:28 +0200953static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
954 uint64_t *data)
955{
956 *data++ = chip->ports[port].atu_member_violation;
957 *data++ = chip->ports[port].atu_miss_violation;
958 *data++ = chip->ports[port].atu_full_violation;
959 *data++ = chip->ports[port].vtu_member_violation;
960 *data++ = chip->ports[port].vtu_miss_violation;
961}
962
Andrew Lunn052f9472016-11-21 23:27:03 +0100963static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
964 uint64_t *data)
965{
Andrew Lunn436fe172018-03-01 02:02:29 +0100966 int count = 0;
967
Andrew Lunn052f9472016-11-21 23:27:03 +0100968 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +0100969 count = chip->info->ops->stats_get_stats(chip, port, data);
970
Andrew Lunn65f60e42018-03-28 23:50:28 +0200971 mutex_lock(&chip->reg_lock);
Andrew Lunn436fe172018-03-01 02:02:29 +0100972 if (chip->info->ops->serdes_get_stats) {
973 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200974 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100975 }
Andrew Lunn65f60e42018-03-28 23:50:28 +0200976 data += count;
977 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
978 mutex_unlock(&chip->reg_lock);
Andrew Lunn052f9472016-11-21 23:27:03 +0100979}
980
Vivien Didelotf81ec902016-05-09 13:22:58 -0400981static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
982 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000983{
Vivien Didelot04bed142016-08-31 18:06:13 -0400984 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000985 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000986
Vivien Didelotfad09c72016-06-21 12:28:20 -0400987 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000988
Andrew Lunna605a0f2016-11-21 23:26:58 +0100989 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +0100990 mutex_unlock(&chip->reg_lock);
991
992 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000993 return;
Andrew Lunn052f9472016-11-21 23:27:03 +0100994
995 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000996
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000997}
Ben Hutchings98e67302011-11-25 14:36:19 +0000998
Vivien Didelotf81ec902016-05-09 13:22:58 -0400999static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001000{
1001 return 32 * sizeof(u16);
1002}
1003
Vivien Didelotf81ec902016-05-09 13:22:58 -04001004static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1005 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001006{
Vivien Didelot04bed142016-08-31 18:06:13 -04001007 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001008 int err;
1009 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001010 u16 *p = _p;
1011 int i;
1012
1013 regs->version = 0;
1014
1015 memset(p, 0xff, 32 * sizeof(u16));
1016
Vivien Didelotfad09c72016-06-21 12:28:20 -04001017 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001018
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001019 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001020
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001021 err = mv88e6xxx_port_read(chip, port, i, &reg);
1022 if (!err)
1023 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001024 }
Vivien Didelot23062512016-05-09 13:22:45 -04001025
Vivien Didelotfad09c72016-06-21 12:28:20 -04001026 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001027}
1028
Vivien Didelot08f50062017-08-01 16:32:41 -04001029static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1030 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001031{
Vivien Didelot5480db62017-08-01 16:32:40 -04001032 /* Nothing to do on the port's MAC */
1033 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001034}
1035
Vivien Didelot08f50062017-08-01 16:32:41 -04001036static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1037 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001038{
Vivien Didelot5480db62017-08-01 16:32:40 -04001039 /* Nothing to do on the port's MAC */
1040 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001041}
1042
Vivien Didelote5887a22017-03-30 17:37:11 -04001043static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001044{
Vivien Didelote5887a22017-03-30 17:37:11 -04001045 struct dsa_switch *ds = NULL;
1046 struct net_device *br;
1047 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001048 int i;
1049
Vivien Didelote5887a22017-03-30 17:37:11 -04001050 if (dev < DSA_MAX_SWITCHES)
1051 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001052
Vivien Didelote5887a22017-03-30 17:37:11 -04001053 /* Prevent frames from unknown switch or port */
1054 if (!ds || port >= ds->num_ports)
1055 return 0;
1056
1057 /* Frames from DSA links and CPU ports can egress any local port */
1058 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1059 return mv88e6xxx_port_mask(chip);
1060
1061 br = ds->ports[port].bridge_dev;
1062 pvlan = 0;
1063
1064 /* Frames from user ports can egress any local DSA links and CPU ports,
1065 * as well as any local member of their bridge group.
1066 */
1067 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1068 if (dsa_is_cpu_port(chip->ds, i) ||
1069 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -04001070 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -04001071 pvlan |= BIT(i);
1072
1073 return pvlan;
1074}
1075
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001076static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001077{
1078 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001079
1080 /* prevent frames from going back out of the port they came in on */
1081 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001082
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001083 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001084}
1085
Vivien Didelotf81ec902016-05-09 13:22:58 -04001086static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1087 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001088{
Vivien Didelot04bed142016-08-31 18:06:13 -04001089 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001090 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001091
Vivien Didelotfad09c72016-06-21 12:28:20 -04001092 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -04001093 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001094 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001095
1096 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001097 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001098}
1099
Vivien Didelot93e18d62018-05-11 17:16:35 -04001100static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1101{
1102 int err;
1103
1104 if (chip->info->ops->ieee_pri_map) {
1105 err = chip->info->ops->ieee_pri_map(chip);
1106 if (err)
1107 return err;
1108 }
1109
1110 if (chip->info->ops->ip_pri_map) {
1111 err = chip->info->ops->ip_pri_map(chip);
1112 if (err)
1113 return err;
1114 }
1115
1116 return 0;
1117}
1118
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001119static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1120{
1121 int target, port;
1122 int err;
1123
1124 if (!chip->info->global2_addr)
1125 return 0;
1126
1127 /* Initialize the routing port to the 32 possible target devices */
1128 for (target = 0; target < 32; target++) {
1129 port = 0x1f;
1130 if (target < DSA_MAX_SWITCHES)
1131 if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
1132 port = chip->ds->rtable[target];
1133
1134 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1135 if (err)
1136 return err;
1137 }
1138
Vivien Didelot02317e62018-05-09 11:38:49 -04001139 if (chip->info->ops->set_cascade_port) {
1140 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1141 err = chip->info->ops->set_cascade_port(chip, port);
1142 if (err)
1143 return err;
1144 }
1145
Vivien Didelot23c98912018-05-09 11:38:50 -04001146 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1147 if (err)
1148 return err;
1149
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001150 return 0;
1151}
1152
Vivien Didelotb28f8722018-04-26 21:56:44 -04001153static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1154{
1155 /* Clear all trunk masks and mapping */
1156 if (chip->info->global2_addr)
1157 return mv88e6xxx_g2_trunk_clear(chip);
1158
1159 return 0;
1160}
1161
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001162static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1163{
1164 if (chip->info->ops->rmu_disable)
1165 return chip->info->ops->rmu_disable(chip);
1166
1167 return 0;
1168}
1169
Vivien Didelot9e907d72017-07-17 13:03:43 -04001170static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1171{
1172 if (chip->info->ops->pot_clear)
1173 return chip->info->ops->pot_clear(chip);
1174
1175 return 0;
1176}
1177
Vivien Didelot51c901a2017-07-17 13:03:41 -04001178static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1179{
1180 if (chip->info->ops->mgmt_rsvd2cpu)
1181 return chip->info->ops->mgmt_rsvd2cpu(chip);
1182
1183 return 0;
1184}
1185
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001186static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1187{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001188 int err;
1189
Vivien Didelotdaefc942017-03-11 16:12:54 -05001190 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1191 if (err)
1192 return err;
1193
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001194 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1195 if (err)
1196 return err;
1197
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001198 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1199}
1200
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001201static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1202{
1203 int port;
1204 int err;
1205
1206 if (!chip->info->ops->irl_init_all)
1207 return 0;
1208
1209 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1210 /* Disable ingress rate limiting by resetting all per port
1211 * ingress rate limit resources to their initial state.
1212 */
1213 err = chip->info->ops->irl_init_all(chip, port);
1214 if (err)
1215 return err;
1216 }
1217
1218 return 0;
1219}
1220
Vivien Didelot04a69a12017-10-13 14:18:05 -04001221static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1222{
1223 if (chip->info->ops->set_switch_mac) {
1224 u8 addr[ETH_ALEN];
1225
1226 eth_random_addr(addr);
1227
1228 return chip->info->ops->set_switch_mac(chip, addr);
1229 }
1230
1231 return 0;
1232}
1233
Vivien Didelot17a15942017-03-30 17:37:09 -04001234static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1235{
1236 u16 pvlan = 0;
1237
1238 if (!mv88e6xxx_has_pvt(chip))
1239 return -EOPNOTSUPP;
1240
1241 /* Skip the local source device, which uses in-chip port VLAN */
1242 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001243 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001244
1245 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1246}
1247
Vivien Didelot81228992017-03-30 17:37:08 -04001248static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1249{
Vivien Didelot17a15942017-03-30 17:37:09 -04001250 int dev, port;
1251 int err;
1252
Vivien Didelot81228992017-03-30 17:37:08 -04001253 if (!mv88e6xxx_has_pvt(chip))
1254 return 0;
1255
1256 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1257 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1258 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001259 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1260 if (err)
1261 return err;
1262
1263 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1264 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1265 err = mv88e6xxx_pvt_map(chip, dev, port);
1266 if (err)
1267 return err;
1268 }
1269 }
1270
1271 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001272}
1273
Vivien Didelot749efcb2016-09-22 16:49:24 -04001274static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1275{
1276 struct mv88e6xxx_chip *chip = ds->priv;
1277 int err;
1278
1279 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001280 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001281 mutex_unlock(&chip->reg_lock);
1282
1283 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001284 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001285}
1286
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001287static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1288{
1289 if (!chip->info->max_vid)
1290 return 0;
1291
1292 return mv88e6xxx_g1_vtu_flush(chip);
1293}
1294
Vivien Didelotf1394b782017-05-01 14:05:22 -04001295static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1296 struct mv88e6xxx_vtu_entry *entry)
1297{
1298 if (!chip->info->ops->vtu_getnext)
1299 return -EOPNOTSUPP;
1300
1301 return chip->info->ops->vtu_getnext(chip, entry);
1302}
1303
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001304static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1305 struct mv88e6xxx_vtu_entry *entry)
1306{
1307 if (!chip->info->ops->vtu_loadpurge)
1308 return -EOPNOTSUPP;
1309
1310 return chip->info->ops->vtu_loadpurge(chip, entry);
1311}
1312
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001313static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001314{
1315 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001316 struct mv88e6xxx_vtu_entry vlan = {
1317 .vid = chip->info->max_vid,
1318 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001319 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001320
1321 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1322
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001323 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001324 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001325 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001326 if (err)
1327 return err;
1328
1329 set_bit(*fid, fid_bitmap);
1330 }
1331
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001332 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001333 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001334 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001335 if (err)
1336 return err;
1337
1338 if (!vlan.valid)
1339 break;
1340
1341 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001342 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001343
1344 /* The reset value 0x000 is used to indicate that multiple address
1345 * databases are not needed. Return the next positive available.
1346 */
1347 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001348 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001349 return -ENOSPC;
1350
1351 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001352 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001353}
1354
Vivien Didelot567aa592017-05-01 14:05:25 -04001355static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1356 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001357{
1358 int err;
1359
1360 if (!vid)
1361 return -EINVAL;
1362
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001363 entry->vid = vid - 1;
1364 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001365
Vivien Didelotf1394b782017-05-01 14:05:22 -04001366 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001367 if (err)
1368 return err;
1369
Vivien Didelot567aa592017-05-01 14:05:25 -04001370 if (entry->vid == vid && entry->valid)
1371 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001372
Vivien Didelot567aa592017-05-01 14:05:25 -04001373 if (new) {
1374 int i;
1375
1376 /* Initialize a fresh VLAN entry */
1377 memset(entry, 0, sizeof(*entry));
1378 entry->valid = true;
1379 entry->vid = vid;
1380
Vivien Didelot553a7682017-06-07 18:12:16 -04001381 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001382 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001383 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001384 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001385
1386 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001387 }
1388
Vivien Didelot567aa592017-05-01 14:05:25 -04001389 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1390 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001391}
1392
Vivien Didelotda9c3592016-02-12 12:09:40 -05001393static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1394 u16 vid_begin, u16 vid_end)
1395{
Vivien Didelot04bed142016-08-31 18:06:13 -04001396 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001397 struct mv88e6xxx_vtu_entry vlan = {
1398 .vid = vid_begin - 1,
1399 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001400 int i, err;
1401
Andrew Lunndb06ae412017-09-25 23:32:20 +02001402 /* DSA and CPU ports have to be members of multiple vlans */
1403 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1404 return 0;
1405
Vivien Didelotda9c3592016-02-12 12:09:40 -05001406 if (!vid_begin)
1407 return -EOPNOTSUPP;
1408
Vivien Didelotfad09c72016-06-21 12:28:20 -04001409 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001410
Vivien Didelotda9c3592016-02-12 12:09:40 -05001411 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001412 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001413 if (err)
1414 goto unlock;
1415
1416 if (!vlan.valid)
1417 break;
1418
1419 if (vlan.vid > vid_end)
1420 break;
1421
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001422 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001423 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1424 continue;
1425
Andrew Lunncd886462017-11-09 22:29:53 +01001426 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001427 continue;
1428
Vivien Didelotbd00e052017-05-01 14:05:11 -04001429 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001430 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001431 continue;
1432
Vivien Didelotc8652c82017-10-16 11:12:19 -04001433 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001434 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001435 break; /* same bridge, check next VLAN */
1436
Vivien Didelotc8652c82017-10-16 11:12:19 -04001437 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001438 continue;
1439
Andrew Lunn743fcc22017-11-09 22:29:54 +01001440 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1441 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001442 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001443 err = -EOPNOTSUPP;
1444 goto unlock;
1445 }
1446 } while (vlan.vid < vid_end);
1447
1448unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001449 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001450
1451 return err;
1452}
1453
Vivien Didelotf81ec902016-05-09 13:22:58 -04001454static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1455 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001456{
Vivien Didelot04bed142016-08-31 18:06:13 -04001457 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001458 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1459 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001460 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001461
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001462 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001463 return -EOPNOTSUPP;
1464
Vivien Didelotfad09c72016-06-21 12:28:20 -04001465 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001466 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001467 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001468
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001469 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001470}
1471
Vivien Didelot57d32312016-06-20 13:13:58 -04001472static int
1473mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001474 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001475{
Vivien Didelot04bed142016-08-31 18:06:13 -04001476 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001477 int err;
1478
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001479 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001480 return -EOPNOTSUPP;
1481
Vivien Didelotda9c3592016-02-12 12:09:40 -05001482 /* If the requested port doesn't belong to the same bridge as the VLAN
1483 * members, do not support it (yet) and fallback to software VLAN.
1484 */
1485 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1486 vlan->vid_end);
1487 if (err)
1488 return err;
1489
Vivien Didelot76e398a2015-11-01 12:33:55 -05001490 /* We don't need any dynamic resource from the kernel (yet),
1491 * so skip the prepare phase.
1492 */
1493 return 0;
1494}
1495
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001496static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1497 const unsigned char *addr, u16 vid,
1498 u8 state)
1499{
1500 struct mv88e6xxx_vtu_entry vlan;
1501 struct mv88e6xxx_atu_entry entry;
1502 int err;
1503
1504 /* Null VLAN ID corresponds to the port private database */
1505 if (vid == 0)
1506 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1507 else
1508 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1509 if (err)
1510 return err;
1511
1512 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1513 ether_addr_copy(entry.mac, addr);
1514 eth_addr_dec(entry.mac);
1515
1516 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1517 if (err)
1518 return err;
1519
1520 /* Initialize a fresh ATU entry if it isn't found */
1521 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1522 !ether_addr_equal(entry.mac, addr)) {
1523 memset(&entry, 0, sizeof(entry));
1524 ether_addr_copy(entry.mac, addr);
1525 }
1526
1527 /* Purge the ATU entry only if no port is using it anymore */
1528 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1529 entry.portvec &= ~BIT(port);
1530 if (!entry.portvec)
1531 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1532 } else {
1533 entry.portvec |= BIT(port);
1534 entry.state = state;
1535 }
1536
1537 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1538}
1539
Andrew Lunn87fa8862017-11-09 22:29:56 +01001540static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1541 u16 vid)
1542{
1543 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1544 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1545
1546 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1547}
1548
1549static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1550{
1551 int port;
1552 int err;
1553
1554 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1555 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1556 if (err)
1557 return err;
1558 }
1559
1560 return 0;
1561}
1562
Vivien Didelotfad09c72016-06-21 12:28:20 -04001563static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001564 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001565{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001566 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001567 int err;
1568
Vivien Didelot567aa592017-05-01 14:05:25 -04001569 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001570 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001571 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001572
Vivien Didelotc91498e2017-06-07 18:12:13 -04001573 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001574
Andrew Lunn87fa8862017-11-09 22:29:56 +01001575 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1576 if (err)
1577 return err;
1578
1579 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001580}
1581
Vivien Didelotf81ec902016-05-09 13:22:58 -04001582static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001583 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001584{
Vivien Didelot04bed142016-08-31 18:06:13 -04001585 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001586 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1587 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001588 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001589 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001590
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001591 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001592 return;
1593
Vivien Didelotc91498e2017-06-07 18:12:13 -04001594 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001595 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001596 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001597 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001598 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001599 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001600
Vivien Didelotfad09c72016-06-21 12:28:20 -04001601 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001602
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001603 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001604 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001605 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1606 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001607
Vivien Didelot77064f32016-11-04 03:23:30 +01001608 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001609 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1610 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001611
Vivien Didelotfad09c72016-06-21 12:28:20 -04001612 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001613}
1614
Vivien Didelotfad09c72016-06-21 12:28:20 -04001615static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001616 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001617{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001618 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001619 int i, err;
1620
Vivien Didelot567aa592017-05-01 14:05:25 -04001621 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001622 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001623 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001624
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001625 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001626 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001627 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001628
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001629 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001630
1631 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001632 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001633 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001634 if (vlan.member[i] !=
1635 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001636 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001637 break;
1638 }
1639 }
1640
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001641 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001642 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001643 return err;
1644
Vivien Didelote606ca32017-03-11 16:12:55 -05001645 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001646}
1647
Vivien Didelotf81ec902016-05-09 13:22:58 -04001648static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1649 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001650{
Vivien Didelot04bed142016-08-31 18:06:13 -04001651 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001652 u16 pvid, vid;
1653 int err = 0;
1654
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001655 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001656 return -EOPNOTSUPP;
1657
Vivien Didelotfad09c72016-06-21 12:28:20 -04001658 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001659
Vivien Didelot77064f32016-11-04 03:23:30 +01001660 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001661 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001662 goto unlock;
1663
Vivien Didelot76e398a2015-11-01 12:33:55 -05001664 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001665 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001666 if (err)
1667 goto unlock;
1668
1669 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001670 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001671 if (err)
1672 goto unlock;
1673 }
1674 }
1675
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001676unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001677 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001678
1679 return err;
1680}
1681
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001682static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1683 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001684{
Vivien Didelot04bed142016-08-31 18:06:13 -04001685 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001686 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001687
Vivien Didelotfad09c72016-06-21 12:28:20 -04001688 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001689 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1690 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001691 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001692
1693 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001694}
1695
Vivien Didelotf81ec902016-05-09 13:22:58 -04001696static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001697 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001698{
Vivien Didelot04bed142016-08-31 18:06:13 -04001699 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001700 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001701
Vivien Didelotfad09c72016-06-21 12:28:20 -04001702 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001703 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001704 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001705 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001706
Vivien Didelot83dabd12016-08-31 11:50:04 -04001707 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001708}
1709
Vivien Didelot83dabd12016-08-31 11:50:04 -04001710static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1711 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001712 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001713{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001714 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001715 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001716 int err;
1717
Vivien Didelot27c0e602017-06-15 12:14:01 -04001718 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001719 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001720
1721 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001722 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001723 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001724 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001725 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001726 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001727
Vivien Didelot27c0e602017-06-15 12:14:01 -04001728 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001729 break;
1730
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001731 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001732 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001733
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001734 if (!is_unicast_ether_addr(addr.mac))
1735 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001736
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001737 is_static = (addr.state ==
1738 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1739 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001740 if (err)
1741 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001742 } while (!is_broadcast_ether_addr(addr.mac));
1743
1744 return err;
1745}
1746
Vivien Didelot83dabd12016-08-31 11:50:04 -04001747static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001748 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001749{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001750 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001751 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001752 };
1753 u16 fid;
1754 int err;
1755
1756 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001757 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001758 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001759 mutex_unlock(&chip->reg_lock);
1760
Vivien Didelot83dabd12016-08-31 11:50:04 -04001761 if (err)
1762 return err;
1763
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001764 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001765 if (err)
1766 return err;
1767
1768 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001769 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001770 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001771 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001772 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001773 if (err)
1774 return err;
1775
1776 if (!vlan.valid)
1777 break;
1778
1779 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001780 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001781 if (err)
1782 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001783 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001784
1785 return err;
1786}
1787
Vivien Didelotf81ec902016-05-09 13:22:58 -04001788static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001789 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001790{
Vivien Didelot04bed142016-08-31 18:06:13 -04001791 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001792
Andrew Lunna61e5402018-02-15 14:38:35 +01001793 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001794}
1795
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001796static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1797 struct net_device *br)
1798{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001799 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001800 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001801 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001802 int err;
1803
1804 /* Remap the Port VLAN of each local bridge group member */
1805 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1806 if (chip->ds->ports[port].bridge_dev == br) {
1807 err = mv88e6xxx_port_vlan_map(chip, port);
1808 if (err)
1809 return err;
1810 }
1811 }
1812
Vivien Didelote96a6e02017-03-30 17:37:13 -04001813 if (!mv88e6xxx_has_pvt(chip))
1814 return 0;
1815
1816 /* Remap the Port VLAN of each cross-chip bridge group member */
1817 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1818 ds = chip->ds->dst->ds[dev];
1819 if (!ds)
1820 break;
1821
1822 for (port = 0; port < ds->num_ports; ++port) {
1823 if (ds->ports[port].bridge_dev == br) {
1824 err = mv88e6xxx_pvt_map(chip, dev, port);
1825 if (err)
1826 return err;
1827 }
1828 }
1829 }
1830
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001831 return 0;
1832}
1833
Vivien Didelotf81ec902016-05-09 13:22:58 -04001834static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001835 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001836{
Vivien Didelot04bed142016-08-31 18:06:13 -04001837 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001838 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001839
Vivien Didelotfad09c72016-06-21 12:28:20 -04001840 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001841 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001842 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001843
Vivien Didelot466dfa02016-02-26 13:16:05 -05001844 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001845}
1846
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001847static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1848 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001849{
Vivien Didelot04bed142016-08-31 18:06:13 -04001850 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001851
Vivien Didelotfad09c72016-06-21 12:28:20 -04001852 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001853 if (mv88e6xxx_bridge_map(chip, br) ||
1854 mv88e6xxx_port_vlan_map(chip, port))
1855 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001856 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001857}
1858
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001859static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1860 int port, struct net_device *br)
1861{
1862 struct mv88e6xxx_chip *chip = ds->priv;
1863 int err;
1864
1865 if (!mv88e6xxx_has_pvt(chip))
1866 return 0;
1867
1868 mutex_lock(&chip->reg_lock);
1869 err = mv88e6xxx_pvt_map(chip, dev, port);
1870 mutex_unlock(&chip->reg_lock);
1871
1872 return err;
1873}
1874
1875static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1876 int port, struct net_device *br)
1877{
1878 struct mv88e6xxx_chip *chip = ds->priv;
1879
1880 if (!mv88e6xxx_has_pvt(chip))
1881 return;
1882
1883 mutex_lock(&chip->reg_lock);
1884 if (mv88e6xxx_pvt_map(chip, dev, port))
1885 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1886 mutex_unlock(&chip->reg_lock);
1887}
1888
Vivien Didelot17e708b2016-12-05 17:30:27 -05001889static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1890{
1891 if (chip->info->ops->reset)
1892 return chip->info->ops->reset(chip);
1893
1894 return 0;
1895}
1896
Vivien Didelot309eca62016-12-05 17:30:26 -05001897static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1898{
1899 struct gpio_desc *gpiod = chip->reset;
1900
1901 /* If there is a GPIO connected to the reset pin, toggle it */
1902 if (gpiod) {
1903 gpiod_set_value_cansleep(gpiod, 1);
1904 usleep_range(10000, 20000);
1905 gpiod_set_value_cansleep(gpiod, 0);
1906 usleep_range(10000, 20000);
1907 }
1908}
1909
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001910static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1911{
1912 int i, err;
1913
1914 /* Set all ports to the Disabled state */
1915 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001916 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001917 if (err)
1918 return err;
1919 }
1920
1921 /* Wait for transmit queues to drain,
1922 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1923 */
1924 usleep_range(2000, 4000);
1925
1926 return 0;
1927}
1928
Vivien Didelotfad09c72016-06-21 12:28:20 -04001929static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001930{
Vivien Didelota935c052016-09-29 12:21:53 -04001931 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001932
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001933 err = mv88e6xxx_disable_ports(chip);
1934 if (err)
1935 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001936
Vivien Didelot309eca62016-12-05 17:30:26 -05001937 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001938
Vivien Didelot17e708b2016-12-05 17:30:27 -05001939 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001940}
1941
Vivien Didelot43145572017-03-11 16:12:59 -05001942static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001943 enum mv88e6xxx_frame_mode frame,
1944 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001945{
1946 int err;
1947
Vivien Didelot43145572017-03-11 16:12:59 -05001948 if (!chip->info->ops->port_set_frame_mode)
1949 return -EOPNOTSUPP;
1950
1951 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001952 if (err)
1953 return err;
1954
Vivien Didelot43145572017-03-11 16:12:59 -05001955 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1956 if (err)
1957 return err;
1958
1959 if (chip->info->ops->port_set_ether_type)
1960 return chip->info->ops->port_set_ether_type(chip, port, etype);
1961
1962 return 0;
1963}
1964
1965static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1966{
1967 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001968 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001969 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001970}
1971
1972static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1973{
1974 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001975 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001976 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001977}
1978
1979static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1980{
1981 return mv88e6xxx_set_port_mode(chip, port,
1982 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001983 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1984 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001985}
1986
1987static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1988{
1989 if (dsa_is_dsa_port(chip->ds, port))
1990 return mv88e6xxx_set_port_mode_dsa(chip, port);
1991
Vivien Didelot2b3e9892017-10-26 11:22:54 -04001992 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05001993 return mv88e6xxx_set_port_mode_normal(chip, port);
1994
1995 /* Setup CPU port mode depending on its supported tag format */
1996 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1997 return mv88e6xxx_set_port_mode_dsa(chip, port);
1998
1999 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2000 return mv88e6xxx_set_port_mode_edsa(chip, port);
2001
2002 return -EINVAL;
2003}
2004
Vivien Didelotea698f42017-03-11 16:12:50 -05002005static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2006{
2007 bool message = dsa_is_dsa_port(chip->ds, port);
2008
2009 return mv88e6xxx_port_set_message_port(chip, port, message);
2010}
2011
Vivien Didelot601aeed2017-03-11 16:13:00 -05002012static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2013{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002014 struct dsa_switch *ds = chip->ds;
2015 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002016
2017 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002018 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002019 if (chip->info->ops->port_set_egress_floods)
2020 return chip->info->ops->port_set_egress_floods(chip, port,
2021 flood, flood);
2022
2023 return 0;
2024}
2025
Andrew Lunn6d917822017-05-26 01:03:21 +02002026static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2027 bool on)
2028{
Vivien Didelot523a8902017-05-26 18:02:42 -04002029 if (chip->info->ops->serdes_power)
2030 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02002031
Vivien Didelot523a8902017-05-26 18:02:42 -04002032 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02002033}
2034
Vivien Didelotfa371c82017-12-05 15:34:10 -05002035static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2036{
2037 struct dsa_switch *ds = chip->ds;
2038 int upstream_port;
2039 int err;
2040
Vivien Didelot07073c72017-12-05 15:34:13 -05002041 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002042 if (chip->info->ops->port_set_upstream_port) {
2043 err = chip->info->ops->port_set_upstream_port(chip, port,
2044 upstream_port);
2045 if (err)
2046 return err;
2047 }
2048
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002049 if (port == upstream_port) {
2050 if (chip->info->ops->set_cpu_port) {
2051 err = chip->info->ops->set_cpu_port(chip,
2052 upstream_port);
2053 if (err)
2054 return err;
2055 }
2056
2057 if (chip->info->ops->set_egress_port) {
2058 err = chip->info->ops->set_egress_port(chip,
2059 upstream_port);
2060 if (err)
2061 return err;
2062 }
2063 }
2064
Vivien Didelotfa371c82017-12-05 15:34:10 -05002065 return 0;
2066}
2067
Vivien Didelotfad09c72016-06-21 12:28:20 -04002068static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002069{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002070 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002071 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002072 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002073
Vivien Didelotd78343d2016-11-04 03:23:36 +01002074 /* MAC Forcing register: don't force link, speed, duplex or flow control
2075 * state to any particular values on physical ports, but force the CPU
2076 * port and all DSA ports to their maximum bandwidth and full duplex.
2077 */
2078 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2079 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2080 SPEED_MAX, DUPLEX_FULL,
2081 PHY_INTERFACE_MODE_NA);
2082 else
2083 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2084 SPEED_UNFORCED, DUPLEX_UNFORCED,
2085 PHY_INTERFACE_MODE_NA);
2086 if (err)
2087 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002088
2089 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2090 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2091 * tunneling, determine priority by looking at 802.1p and IP
2092 * priority fields (IP prio has precedence), and set STP state
2093 * to Forwarding.
2094 *
2095 * If this is the CPU link, use DSA or EDSA tagging depending
2096 * on which tagging mode was configured.
2097 *
2098 * If this is a link to another switch, use DSA tagging mode.
2099 *
2100 * If this is the upstream port for this switch, enable
2101 * forwarding of unknown unicasts and multicasts.
2102 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002103 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2104 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2105 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2106 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002107 if (err)
2108 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002109
Vivien Didelot601aeed2017-03-11 16:13:00 -05002110 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002111 if (err)
2112 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002113
Vivien Didelot601aeed2017-03-11 16:13:00 -05002114 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002115 if (err)
2116 return err;
2117
Andrew Lunn04aca992017-05-26 01:03:24 +02002118 /* Enable the SERDES interface for DSA and CPU ports. Normal
2119 * ports SERDES are enabled when the port is enabled, thus
2120 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002121 */
Andrew Lunn04aca992017-05-26 01:03:24 +02002122 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
2123 err = mv88e6xxx_serdes_power(chip, port, true);
2124 if (err)
2125 return err;
2126 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002127
Vivien Didelot8efdda42015-08-13 12:52:23 -04002128 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002129 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002130 * untagged frames on this port, do a destination address lookup on all
2131 * received packets as usual, disable ARP mirroring and don't send a
2132 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002133 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002134 err = mv88e6xxx_port_set_map_da(chip, port);
2135 if (err)
2136 return err;
2137
Vivien Didelotfa371c82017-12-05 15:34:10 -05002138 err = mv88e6xxx_setup_upstream_port(chip, port);
2139 if (err)
2140 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002141
Andrew Lunna23b2962017-02-04 20:15:28 +01002142 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002143 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002144 if (err)
2145 return err;
2146
Vivien Didelotcd782652017-06-08 18:34:13 -04002147 if (chip->info->ops->port_set_jumbo_size) {
2148 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002149 if (err)
2150 return err;
2151 }
2152
Andrew Lunn54d792f2015-05-06 01:09:47 +02002153 /* Port Association Vector: when learning source addresses
2154 * of packets, add the address to the address database using
2155 * a port bitmap that has only the bit for this port set and
2156 * the other bits clear.
2157 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002158 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002159 /* Disable learning for CPU port */
2160 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002161 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002162
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002163 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2164 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002165 if (err)
2166 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002167
2168 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002169 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2170 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002171 if (err)
2172 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002173
Vivien Didelot08984322017-06-08 18:34:12 -04002174 if (chip->info->ops->port_pause_limit) {
2175 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002176 if (err)
2177 return err;
2178 }
2179
Vivien Didelotc8c94892017-03-11 16:13:01 -05002180 if (chip->info->ops->port_disable_learn_limit) {
2181 err = chip->info->ops->port_disable_learn_limit(chip, port);
2182 if (err)
2183 return err;
2184 }
2185
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002186 if (chip->info->ops->port_disable_pri_override) {
2187 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002188 if (err)
2189 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002190 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002191
Andrew Lunnef0a7312016-12-03 04:35:16 +01002192 if (chip->info->ops->port_tag_remap) {
2193 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002194 if (err)
2195 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002196 }
2197
Andrew Lunnef70b112016-12-03 04:45:18 +01002198 if (chip->info->ops->port_egress_rate_limiting) {
2199 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002200 if (err)
2201 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002202 }
2203
Vivien Didelotea698f42017-03-11 16:12:50 -05002204 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002205 if (err)
2206 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002207
Vivien Didelot207afda2016-04-14 14:42:09 -04002208 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002209 * database, and allow bidirectional communication between the
2210 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002211 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002212 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002213 if (err)
2214 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002215
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002216 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002217 if (err)
2218 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002219
2220 /* Default VLAN ID and priority: don't set a default VLAN
2221 * ID, and set the default packet priority to zero.
2222 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002223 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002224}
2225
Andrew Lunn04aca992017-05-26 01:03:24 +02002226static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2227 struct phy_device *phydev)
2228{
2229 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002230 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002231
2232 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002233 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002234 mutex_unlock(&chip->reg_lock);
2235
2236 return err;
2237}
2238
2239static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2240 struct phy_device *phydev)
2241{
2242 struct mv88e6xxx_chip *chip = ds->priv;
2243
2244 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002245 if (mv88e6xxx_serdes_power(chip, port, false))
2246 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002247 mutex_unlock(&chip->reg_lock);
2248}
2249
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002250static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2251 unsigned int ageing_time)
2252{
Vivien Didelot04bed142016-08-31 18:06:13 -04002253 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002254 int err;
2255
2256 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002257 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002258 mutex_unlock(&chip->reg_lock);
2259
2260 return err;
2261}
2262
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002263static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002264{
2265 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002266
Andrew Lunnde2273872016-11-21 23:27:01 +01002267 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002268 if (chip->info->ops->stats_set_histogram) {
2269 err = chip->info->ops->stats_set_histogram(chip);
2270 if (err)
2271 return err;
2272 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002273
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002274 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002275}
2276
Vivien Didelotf81ec902016-05-09 13:22:58 -04002277static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002278{
Vivien Didelot04bed142016-08-31 18:06:13 -04002279 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002280 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002281 int i;
2282
Vivien Didelotfad09c72016-06-21 12:28:20 -04002283 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002284 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002285
Vivien Didelotfad09c72016-06-21 12:28:20 -04002286 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002287
Vivien Didelot97299342016-07-18 20:45:30 -04002288 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002289 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002290 if (dsa_is_unused_port(ds, i))
2291 continue;
2292
Vivien Didelot97299342016-07-18 20:45:30 -04002293 err = mv88e6xxx_setup_port(chip, i);
2294 if (err)
2295 goto unlock;
2296 }
2297
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002298 err = mv88e6xxx_irl_setup(chip);
2299 if (err)
2300 goto unlock;
2301
Vivien Didelot04a69a12017-10-13 14:18:05 -04002302 err = mv88e6xxx_mac_setup(chip);
2303 if (err)
2304 goto unlock;
2305
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002306 err = mv88e6xxx_phy_setup(chip);
2307 if (err)
2308 goto unlock;
2309
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002310 err = mv88e6xxx_vtu_setup(chip);
2311 if (err)
2312 goto unlock;
2313
Vivien Didelot81228992017-03-30 17:37:08 -04002314 err = mv88e6xxx_pvt_setup(chip);
2315 if (err)
2316 goto unlock;
2317
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002318 err = mv88e6xxx_atu_setup(chip);
2319 if (err)
2320 goto unlock;
2321
Andrew Lunn87fa8862017-11-09 22:29:56 +01002322 err = mv88e6xxx_broadcast_setup(chip, 0);
2323 if (err)
2324 goto unlock;
2325
Vivien Didelot9e907d72017-07-17 13:03:43 -04002326 err = mv88e6xxx_pot_setup(chip);
2327 if (err)
2328 goto unlock;
2329
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002330 err = mv88e6xxx_rmu_setup(chip);
2331 if (err)
2332 goto unlock;
2333
Vivien Didelot51c901a2017-07-17 13:03:41 -04002334 err = mv88e6xxx_rsvd2cpu_setup(chip);
2335 if (err)
2336 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002337
Vivien Didelotb28f8722018-04-26 21:56:44 -04002338 err = mv88e6xxx_trunk_setup(chip);
2339 if (err)
2340 goto unlock;
2341
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002342 err = mv88e6xxx_devmap_setup(chip);
2343 if (err)
2344 goto unlock;
2345
Vivien Didelot93e18d62018-05-11 17:16:35 -04002346 err = mv88e6xxx_pri_setup(chip);
2347 if (err)
2348 goto unlock;
2349
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002350 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002351 if (chip->info->ptp_support) {
2352 err = mv88e6xxx_ptp_setup(chip);
2353 if (err)
2354 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002355
2356 err = mv88e6xxx_hwtstamp_setup(chip);
2357 if (err)
2358 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002359 }
2360
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002361 err = mv88e6xxx_stats_setup(chip);
2362 if (err)
2363 goto unlock;
2364
Vivien Didelot6b17e862015-08-13 12:52:18 -04002365unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002366 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002367
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002368 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002369}
2370
Vivien Didelote57e5e72016-08-15 17:19:00 -04002371static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002372{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002373 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2374 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002375 u16 val;
2376 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002377
Andrew Lunnee26a222017-01-24 14:53:48 +01002378 if (!chip->info->ops->phy_read)
2379 return -EOPNOTSUPP;
2380
Vivien Didelotfad09c72016-06-21 12:28:20 -04002381 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002382 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002383 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002384
Andrew Lunnda9f3302017-02-01 03:40:05 +01002385 if (reg == MII_PHYSID2) {
2386 /* Some internal PHYS don't have a model number. Use
2387 * the mv88e6390 family model number instead.
2388 */
2389 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002390 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002391 }
2392
Vivien Didelote57e5e72016-08-15 17:19:00 -04002393 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002394}
2395
Vivien Didelote57e5e72016-08-15 17:19:00 -04002396static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002397{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002398 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2399 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002400 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002401
Andrew Lunnee26a222017-01-24 14:53:48 +01002402 if (!chip->info->ops->phy_write)
2403 return -EOPNOTSUPP;
2404
Vivien Didelotfad09c72016-06-21 12:28:20 -04002405 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002406 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002407 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002408
2409 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002410}
2411
Vivien Didelotfad09c72016-06-21 12:28:20 -04002412static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002413 struct device_node *np,
2414 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002415{
2416 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002417 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002418 struct mii_bus *bus;
2419 int err;
2420
Andrew Lunn2510bab2018-02-22 01:51:49 +01002421 if (external) {
2422 mutex_lock(&chip->reg_lock);
2423 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2424 mutex_unlock(&chip->reg_lock);
2425
2426 if (err)
2427 return err;
2428 }
2429
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002430 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002431 if (!bus)
2432 return -ENOMEM;
2433
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002434 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002435 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002436 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002437 INIT_LIST_HEAD(&mdio_bus->list);
2438 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002439
Andrew Lunnb516d452016-06-04 21:17:06 +02002440 if (np) {
2441 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002442 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002443 } else {
2444 bus->name = "mv88e6xxx SMI";
2445 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2446 }
2447
2448 bus->read = mv88e6xxx_mdio_read;
2449 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002450 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002451
Andrew Lunn6f882842018-03-17 20:32:05 +01002452 if (!external) {
2453 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2454 if (err)
2455 return err;
2456 }
2457
Florian Fainelli00e798c2018-05-15 16:56:19 -07002458 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002459 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002460 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002461 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002462 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002463 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002464
2465 if (external)
2466 list_add_tail(&mdio_bus->list, &chip->mdios);
2467 else
2468 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002469
2470 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002471}
2472
Andrew Lunna3c53be52017-01-24 14:53:50 +01002473static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2474 { .compatible = "marvell,mv88e6xxx-mdio-external",
2475 .data = (void *)true },
2476 { },
2477};
2478
Andrew Lunn3126aee2017-12-07 01:05:57 +01002479static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2480
2481{
2482 struct mv88e6xxx_mdio_bus *mdio_bus;
2483 struct mii_bus *bus;
2484
2485 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2486 bus = mdio_bus->bus;
2487
Andrew Lunn6f882842018-03-17 20:32:05 +01002488 if (!mdio_bus->external)
2489 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2490
Andrew Lunn3126aee2017-12-07 01:05:57 +01002491 mdiobus_unregister(bus);
2492 }
2493}
2494
Andrew Lunna3c53be52017-01-24 14:53:50 +01002495static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2496 struct device_node *np)
2497{
2498 const struct of_device_id *match;
2499 struct device_node *child;
2500 int err;
2501
2502 /* Always register one mdio bus for the internal/default mdio
2503 * bus. This maybe represented in the device tree, but is
2504 * optional.
2505 */
2506 child = of_get_child_by_name(np, "mdio");
2507 err = mv88e6xxx_mdio_register(chip, child, false);
2508 if (err)
2509 return err;
2510
2511 /* Walk the device tree, and see if there are any other nodes
2512 * which say they are compatible with the external mdio
2513 * bus.
2514 */
2515 for_each_available_child_of_node(np, child) {
2516 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2517 if (match) {
2518 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002519 if (err) {
2520 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002521 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002522 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002523 }
2524 }
2525
2526 return 0;
2527}
2528
Vivien Didelot855b1932016-07-20 18:18:35 -04002529static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2530{
Vivien Didelot04bed142016-08-31 18:06:13 -04002531 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002532
2533 return chip->eeprom_len;
2534}
2535
Vivien Didelot855b1932016-07-20 18:18:35 -04002536static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2537 struct ethtool_eeprom *eeprom, u8 *data)
2538{
Vivien Didelot04bed142016-08-31 18:06:13 -04002539 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002540 int err;
2541
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002542 if (!chip->info->ops->get_eeprom)
2543 return -EOPNOTSUPP;
2544
Vivien Didelot855b1932016-07-20 18:18:35 -04002545 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002546 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002547 mutex_unlock(&chip->reg_lock);
2548
2549 if (err)
2550 return err;
2551
2552 eeprom->magic = 0xc3ec4951;
2553
2554 return 0;
2555}
2556
Vivien Didelot855b1932016-07-20 18:18:35 -04002557static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2558 struct ethtool_eeprom *eeprom, u8 *data)
2559{
Vivien Didelot04bed142016-08-31 18:06:13 -04002560 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002561 int err;
2562
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002563 if (!chip->info->ops->set_eeprom)
2564 return -EOPNOTSUPP;
2565
Vivien Didelot855b1932016-07-20 18:18:35 -04002566 if (eeprom->magic != 0xc3ec4951)
2567 return -EINVAL;
2568
2569 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002570 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002571 mutex_unlock(&chip->reg_lock);
2572
2573 return err;
2574}
2575
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002576static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002577 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002578 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2579 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002580 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002581 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002582 .phy_read = mv88e6185_phy_ppu_read,
2583 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002584 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002585 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002586 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002587 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002588 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002589 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002590 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002591 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002592 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002593 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002594 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002595 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002596 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002597 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2598 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002599 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002600 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2601 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002602 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002603 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002604 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002605 .ppu_enable = mv88e6185_g1_ppu_enable,
2606 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002607 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002608 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002609 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002610 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behún5bafeb6e2018-05-04 19:26:10 +02002611 .serdes_power = mv88e6341_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002612};
2613
2614static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002615 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002616 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2617 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002618 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002619 .phy_read = mv88e6185_phy_ppu_read,
2620 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002621 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002622 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002623 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002624 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002625 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002626 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002627 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002628 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002629 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2630 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002631 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002632 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002633 .ppu_enable = mv88e6185_g1_ppu_enable,
2634 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002635 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002636 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002637 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002638};
2639
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002640static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002641 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002642 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2643 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002644 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002645 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2646 .phy_read = mv88e6xxx_g2_smi_phy_read,
2647 .phy_write = mv88e6xxx_g2_smi_phy_write,
2648 .port_set_link = mv88e6xxx_port_set_link,
2649 .port_set_duplex = mv88e6xxx_port_set_duplex,
2650 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002651 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002652 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002653 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002654 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002655 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002656 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002657 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002658 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002659 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002660 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002661 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002662 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2663 .stats_get_strings = mv88e6095_stats_get_strings,
2664 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002665 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2666 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002667 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002668 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002669 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002670 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002671 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002672 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002673 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002674};
2675
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002676static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002677 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002678 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2679 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002680 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002681 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002682 .phy_read = mv88e6xxx_g2_smi_phy_read,
2683 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002684 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002685 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002686 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002687 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002688 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002689 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002690 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002691 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002692 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002693 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2694 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002695 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002696 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2697 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002698 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002699 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002700 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002701 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002702 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002703 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002704};
2705
2706static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002707 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002708 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2709 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002710 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002711 .phy_read = mv88e6185_phy_ppu_read,
2712 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002713 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002714 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002715 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002716 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002717 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002718 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002719 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002720 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002721 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002722 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002723 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002724 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002725 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002726 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2727 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002728 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002729 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2730 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002731 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002732 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002733 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04002734 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002735 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002736 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002737 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002738 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002739};
2740
Vivien Didelot990e27b2017-03-28 13:50:32 -04002741static const struct mv88e6xxx_ops mv88e6141_ops = {
2742 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002743 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2744 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002745 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002746 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2747 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2748 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2749 .phy_read = mv88e6xxx_g2_smi_phy_read,
2750 .phy_write = mv88e6xxx_g2_smi_phy_write,
2751 .port_set_link = mv88e6xxx_port_set_link,
2752 .port_set_duplex = mv88e6xxx_port_set_duplex,
2753 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2754 .port_set_speed = mv88e6390_port_set_speed,
2755 .port_tag_remap = mv88e6095_port_tag_remap,
2756 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2757 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2758 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002759 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002760 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002761 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002762 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2763 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2764 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002765 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002766 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2767 .stats_get_strings = mv88e6320_stats_get_strings,
2768 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002769 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2770 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002771 .watchdog_ops = &mv88e6390_watchdog_ops,
2772 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002773 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002774 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002775 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002776 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002777 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002778};
2779
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002780static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002781 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002782 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2783 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002784 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002785 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002786 .phy_read = mv88e6xxx_g2_smi_phy_read,
2787 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002788 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002789 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002790 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002791 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002792 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002793 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002794 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002795 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002796 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002797 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002798 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002799 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002800 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002801 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002802 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2803 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002804 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002805 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2806 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002807 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002808 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002809 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002810 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002811 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002812 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002813};
2814
2815static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002816 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002817 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2818 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002819 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002820 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002821 .phy_read = mv88e6165_phy_read,
2822 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002823 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002824 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002825 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002826 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002827 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002828 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002829 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002830 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2831 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002832 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002833 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2834 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002835 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002836 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002837 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002838 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002839 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002840 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002841};
2842
2843static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002844 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002845 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2846 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002847 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002848 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002849 .phy_read = mv88e6xxx_g2_smi_phy_read,
2850 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002851 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002852 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002853 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002854 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002855 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002856 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002857 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002858 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002859 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002860 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002861 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002862 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002863 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002864 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002865 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002866 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2867 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002868 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002869 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2870 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002871 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002872 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002873 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002874 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002875 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002876 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002877};
2878
2879static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002880 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002881 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2882 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002883 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002884 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2885 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002886 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002887 .phy_read = mv88e6xxx_g2_smi_phy_read,
2888 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002889 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002890 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002891 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002892 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002893 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002894 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002895 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002896 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002897 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002898 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002899 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002900 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002901 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002902 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002903 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002904 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2905 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002906 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002907 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2908 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002909 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002910 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002911 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002912 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002913 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002914 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002915 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002916 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002917 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002918};
2919
2920static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002921 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002922 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2923 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002924 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002925 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002926 .phy_read = mv88e6xxx_g2_smi_phy_read,
2927 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002928 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002929 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002930 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002931 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002932 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002933 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002934 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002935 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002936 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002937 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002938 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002939 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002940 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002941 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002942 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002943 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2944 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002945 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002946 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2947 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002948 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002949 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002950 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002951 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002952 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002953 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behún5bafeb6e2018-05-04 19:26:10 +02002954 .serdes_power = mv88e6341_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002955};
2956
2957static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002958 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002959 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2960 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002961 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002962 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2963 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002964 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002965 .phy_read = mv88e6xxx_g2_smi_phy_read,
2966 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002967 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002968 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002969 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002970 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002971 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002972 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002973 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002974 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002975 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002976 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002977 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002978 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002979 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002980 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002981 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002982 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2983 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002984 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002985 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2986 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002987 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002988 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002989 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002990 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002991 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002992 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002993 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002994 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002995 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002996};
2997
2998static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002999 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003000 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3001 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003002 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003003 .phy_read = mv88e6185_phy_ppu_read,
3004 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003005 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003006 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003007 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003008 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003009 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003010 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003011 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003012 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003013 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003014 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3015 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003016 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003017 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3018 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003019 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003020 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003021 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003022 .ppu_enable = mv88e6185_g1_ppu_enable,
3023 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003024 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003025 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003026 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003027};
3028
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003029static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003030 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003031 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003032 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3033 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003034 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3035 .phy_read = mv88e6xxx_g2_smi_phy_read,
3036 .phy_write = mv88e6xxx_g2_smi_phy_write,
3037 .port_set_link = mv88e6xxx_port_set_link,
3038 .port_set_duplex = mv88e6xxx_port_set_duplex,
3039 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3040 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003041 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003042 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003043 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003044 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003045 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003046 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003047 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003048 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003049 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003050 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3051 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003052 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003053 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3054 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003055 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003056 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003057 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003058 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003059 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003060 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3061 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003062 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003063 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003064};
3065
3066static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003067 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003068 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003069 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3070 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003071 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3072 .phy_read = mv88e6xxx_g2_smi_phy_read,
3073 .phy_write = mv88e6xxx_g2_smi_phy_write,
3074 .port_set_link = mv88e6xxx_port_set_link,
3075 .port_set_duplex = mv88e6xxx_port_set_duplex,
3076 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3077 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003078 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003079 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003080 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003081 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003082 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003083 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003084 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003085 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003086 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003087 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3088 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003089 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003090 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3091 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003092 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003093 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003094 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003095 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003096 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003097 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3098 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003099 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003100 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003101};
3102
3103static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003104 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003105 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003106 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3107 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003108 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3109 .phy_read = mv88e6xxx_g2_smi_phy_read,
3110 .phy_write = mv88e6xxx_g2_smi_phy_write,
3111 .port_set_link = mv88e6xxx_port_set_link,
3112 .port_set_duplex = mv88e6xxx_port_set_duplex,
3113 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3114 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003115 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003116 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003117 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003118 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003119 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003120 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003121 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003122 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003123 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003124 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3125 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003126 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003127 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3128 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003129 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003130 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003131 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003132 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003133 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003134 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3135 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003136 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003137 .avb_ops = &mv88e6390_avb_ops,
3138 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003139};
3140
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003141static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003142 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003143 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3144 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003145 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003146 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3147 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003148 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003149 .phy_read = mv88e6xxx_g2_smi_phy_read,
3150 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003151 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003152 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003153 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003154 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003155 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003156 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003157 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003158 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003159 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003160 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003161 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003162 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003163 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003164 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003165 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003166 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3167 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003168 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003169 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3170 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003171 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003172 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003173 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003174 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003175 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003176 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003177 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003178 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003179 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003180 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003181 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003182};
3183
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003184static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003185 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003186 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003187 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3188 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003189 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3190 .phy_read = mv88e6xxx_g2_smi_phy_read,
3191 .phy_write = mv88e6xxx_g2_smi_phy_write,
3192 .port_set_link = mv88e6xxx_port_set_link,
3193 .port_set_duplex = mv88e6xxx_port_set_duplex,
3194 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3195 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003196 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003197 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003198 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003199 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003200 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003201 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003202 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003203 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003204 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003205 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003206 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3207 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003208 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003209 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3210 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003211 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003212 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003213 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003214 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003215 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003216 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3217 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003218 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003219 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003220 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003221 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003222};
3223
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003224static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003225 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003226 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3227 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003228 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003229 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3230 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003231 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003232 .phy_read = mv88e6xxx_g2_smi_phy_read,
3233 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003234 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003235 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003236 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003237 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003238 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003239 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003240 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003241 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003242 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003243 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003244 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003245 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003246 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003247 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003248 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3249 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003250 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003251 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3252 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003253 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003254 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003255 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003256 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003257 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003258 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003259 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003260 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003261};
3262
3263static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003264 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003265 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3266 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003267 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003268 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3269 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003270 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003271 .phy_read = mv88e6xxx_g2_smi_phy_read,
3272 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003273 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003274 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003275 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003276 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003277 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003278 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003279 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003280 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003281 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003282 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003283 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003284 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003285 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003286 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003287 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3288 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003289 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003290 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3291 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003292 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003293 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003294 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003295 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003296 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003297 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003298};
3299
Vivien Didelot16e329a2017-03-28 13:50:33 -04003300static const struct mv88e6xxx_ops mv88e6341_ops = {
3301 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003302 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3303 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003304 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003305 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3306 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3307 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3308 .phy_read = mv88e6xxx_g2_smi_phy_read,
3309 .phy_write = mv88e6xxx_g2_smi_phy_write,
3310 .port_set_link = mv88e6xxx_port_set_link,
3311 .port_set_duplex = mv88e6xxx_port_set_duplex,
3312 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3313 .port_set_speed = mv88e6390_port_set_speed,
3314 .port_tag_remap = mv88e6095_port_tag_remap,
3315 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3316 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3317 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003318 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003319 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003320 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003321 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3322 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3323 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003324 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003325 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3326 .stats_get_strings = mv88e6320_stats_get_strings,
3327 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003328 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3329 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003330 .watchdog_ops = &mv88e6390_watchdog_ops,
3331 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003332 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003333 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003334 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003335 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003336 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003337 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003338 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003339};
3340
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003341static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003342 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003343 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3344 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003345 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003346 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003347 .phy_read = mv88e6xxx_g2_smi_phy_read,
3348 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003349 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003350 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003351 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003352 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003353 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003354 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003355 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003356 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003357 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003358 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003359 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003360 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003361 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003362 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003363 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003364 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3365 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003366 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003367 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3368 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003369 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003370 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003371 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003372 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003373 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003374 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003375};
3376
3377static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003378 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003379 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3380 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003381 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003382 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003383 .phy_read = mv88e6xxx_g2_smi_phy_read,
3384 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003385 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003386 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003387 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003388 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003389 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003390 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003391 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003392 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003393 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003394 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003395 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003396 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003397 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003398 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003399 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003400 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3401 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003402 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003403 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3404 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003405 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003406 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003407 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003408 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003409 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003410 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003411 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003412 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003413};
3414
3415static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003416 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003417 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3418 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003419 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003420 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3421 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003422 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003423 .phy_read = mv88e6xxx_g2_smi_phy_read,
3424 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003425 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003426 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003427 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003428 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003429 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003430 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003431 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003432 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003433 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003434 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003435 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003436 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003437 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003438 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003439 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003440 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3441 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003442 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003443 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3444 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003445 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003446 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003447 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003448 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003449 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003450 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003451 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003452 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003453 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003454 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003455 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01003456 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
3457 .serdes_get_strings = mv88e6352_serdes_get_strings,
3458 .serdes_get_stats = mv88e6352_serdes_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003459};
3460
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003461static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003462 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003463 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003464 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3465 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003466 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3467 .phy_read = mv88e6xxx_g2_smi_phy_read,
3468 .phy_write = mv88e6xxx_g2_smi_phy_write,
3469 .port_set_link = mv88e6xxx_port_set_link,
3470 .port_set_duplex = mv88e6xxx_port_set_duplex,
3471 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3472 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003473 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003474 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003475 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003476 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003477 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003478 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003479 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003480 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003481 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003482 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003483 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003484 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003485 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3486 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003487 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003488 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3489 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003490 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003491 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003492 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003493 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003494 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003495 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3496 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003497 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003498 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003499 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003500 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003501};
3502
3503static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003504 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003505 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003506 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3507 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003508 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3509 .phy_read = mv88e6xxx_g2_smi_phy_read,
3510 .phy_write = mv88e6xxx_g2_smi_phy_write,
3511 .port_set_link = mv88e6xxx_port_set_link,
3512 .port_set_duplex = mv88e6xxx_port_set_duplex,
3513 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3514 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003515 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003516 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003517 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003518 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003519 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003520 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003521 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003522 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003523 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003524 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003525 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003526 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003527 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3528 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003529 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003530 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3531 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003532 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003533 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003534 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003535 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003536 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003537 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3538 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003539 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003540 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003541 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003542 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003543};
3544
Vivien Didelotf81ec902016-05-09 13:22:58 -04003545static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3546 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003547 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003548 .family = MV88E6XXX_FAMILY_6097,
3549 .name = "Marvell 88E6085",
3550 .num_databases = 4096,
3551 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003552 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003553 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003554 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003555 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003556 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003557 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003558 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003559 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003560 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003561 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003562 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003563 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003564 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003565 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003566 },
3567
3568 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003569 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003570 .family = MV88E6XXX_FAMILY_6095,
3571 .name = "Marvell 88E6095/88E6095F",
3572 .num_databases = 256,
3573 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003574 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003575 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003576 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003577 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003578 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003579 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003580 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003581 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003582 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003583 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003584 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003585 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003586 },
3587
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003588 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003589 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003590 .family = MV88E6XXX_FAMILY_6097,
3591 .name = "Marvell 88E6097/88E6097F",
3592 .num_databases = 4096,
3593 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003594 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003595 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003596 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003597 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003598 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003599 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003600 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003601 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003602 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003603 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003604 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003605 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003606 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003607 .ops = &mv88e6097_ops,
3608 },
3609
Vivien Didelotf81ec902016-05-09 13:22:58 -04003610 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003611 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003612 .family = MV88E6XXX_FAMILY_6165,
3613 .name = "Marvell 88E6123",
3614 .num_databases = 4096,
3615 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01003616 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003617 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003618 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003619 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003620 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003621 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003622 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003623 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003624 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003625 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003626 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003627 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003628 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003629 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003630 },
3631
3632 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003633 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003634 .family = MV88E6XXX_FAMILY_6185,
3635 .name = "Marvell 88E6131",
3636 .num_databases = 256,
3637 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003638 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003639 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003640 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003641 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003642 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003643 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003644 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003645 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003646 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003647 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003648 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003649 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003650 },
3651
Vivien Didelot990e27b2017-03-28 13:50:32 -04003652 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003653 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003654 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01003655 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04003656 .num_databases = 4096,
3657 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003658 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003659 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003660 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003661 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003662 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003663 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003664 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003665 .age_time_coeff = 3750,
3666 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003667 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003668 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003669 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003670 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003671 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003672 .ops = &mv88e6141_ops,
3673 },
3674
Vivien Didelotf81ec902016-05-09 13:22:58 -04003675 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003676 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003677 .family = MV88E6XXX_FAMILY_6165,
3678 .name = "Marvell 88E6161",
3679 .num_databases = 4096,
3680 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003681 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003682 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003683 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003684 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003685 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003686 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003687 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003688 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003689 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003690 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003691 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003692 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003693 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003694 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003695 },
3696
3697 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003698 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003699 .family = MV88E6XXX_FAMILY_6165,
3700 .name = "Marvell 88E6165",
3701 .num_databases = 4096,
3702 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003703 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003704 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003705 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003706 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003707 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003708 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003709 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003710 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003711 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003712 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003713 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003714 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003715 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003716 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003717 },
3718
3719 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003720 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003721 .family = MV88E6XXX_FAMILY_6351,
3722 .name = "Marvell 88E6171",
3723 .num_databases = 4096,
3724 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003725 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003726 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003727 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003728 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003729 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003730 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003731 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003732 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003733 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003734 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003735 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003736 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003737 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003738 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003739 },
3740
3741 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003742 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003743 .family = MV88E6XXX_FAMILY_6352,
3744 .name = "Marvell 88E6172",
3745 .num_databases = 4096,
3746 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003747 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003748 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003749 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003750 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003751 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003752 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003753 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003754 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003755 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003756 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003757 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003758 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003759 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003760 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003761 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003762 },
3763
3764 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003765 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003766 .family = MV88E6XXX_FAMILY_6351,
3767 .name = "Marvell 88E6175",
3768 .num_databases = 4096,
3769 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003770 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003771 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003772 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003773 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003774 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003775 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003776 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003777 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003778 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003779 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003780 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003781 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003782 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003783 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003784 },
3785
3786 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003787 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003788 .family = MV88E6XXX_FAMILY_6352,
3789 .name = "Marvell 88E6176",
3790 .num_databases = 4096,
3791 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003792 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003793 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003794 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003795 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003796 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003797 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003798 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003799 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003800 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003801 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003802 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003803 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003804 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003805 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003806 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003807 },
3808
3809 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003810 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003811 .family = MV88E6XXX_FAMILY_6185,
3812 .name = "Marvell 88E6185",
3813 .num_databases = 256,
3814 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003815 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003816 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003817 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003818 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003819 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003820 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003821 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003822 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003823 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003824 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003825 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003826 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003827 },
3828
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003829 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003830 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003831 .family = MV88E6XXX_FAMILY_6390,
3832 .name = "Marvell 88E6190",
3833 .num_databases = 4096,
3834 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003835 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003836 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003837 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003838 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003839 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003840 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003841 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003842 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003843 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003844 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003845 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003846 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003847 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003848 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003849 .ops = &mv88e6190_ops,
3850 },
3851
3852 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003853 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003854 .family = MV88E6XXX_FAMILY_6390,
3855 .name = "Marvell 88E6190X",
3856 .num_databases = 4096,
3857 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003858 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003859 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003860 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003861 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003862 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003863 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003864 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003865 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003866 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003867 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003868 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003869 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003870 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003871 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003872 .ops = &mv88e6190x_ops,
3873 },
3874
3875 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003876 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003877 .family = MV88E6XXX_FAMILY_6390,
3878 .name = "Marvell 88E6191",
3879 .num_databases = 4096,
3880 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003881 .num_internal_phys = 11,
Vivien Didelot931d1822017-05-01 14:05:27 -04003882 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003883 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003884 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003885 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003886 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003887 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003888 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003889 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003890 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003891 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003892 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003893 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003894 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003895 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003896 },
3897
Vivien Didelotf81ec902016-05-09 13:22:58 -04003898 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003899 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003900 .family = MV88E6XXX_FAMILY_6352,
3901 .name = "Marvell 88E6240",
3902 .num_databases = 4096,
3903 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003904 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003905 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003906 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003907 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003908 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003909 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003910 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003911 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003912 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003913 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003914 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003915 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003916 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003917 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003918 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003919 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003920 },
3921
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003922 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003923 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003924 .family = MV88E6XXX_FAMILY_6390,
3925 .name = "Marvell 88E6290",
3926 .num_databases = 4096,
3927 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003928 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003929 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003930 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003931 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003932 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003933 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003934 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003935 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003936 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003937 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003938 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003939 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003940 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003941 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003942 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003943 .ops = &mv88e6290_ops,
3944 },
3945
Vivien Didelotf81ec902016-05-09 13:22:58 -04003946 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003947 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003948 .family = MV88E6XXX_FAMILY_6320,
3949 .name = "Marvell 88E6320",
3950 .num_databases = 4096,
3951 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003952 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003953 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003954 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003955 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003956 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003957 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003958 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003959 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003960 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003961 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003962 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003963 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003964 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003965 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003966 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003967 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003968 },
3969
3970 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003971 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003972 .family = MV88E6XXX_FAMILY_6320,
3973 .name = "Marvell 88E6321",
3974 .num_databases = 4096,
3975 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003976 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003977 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003978 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003979 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003980 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003981 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003982 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003983 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003984 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003985 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003986 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003987 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003988 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003989 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003990 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003991 },
3992
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003993 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003994 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003995 .family = MV88E6XXX_FAMILY_6341,
3996 .name = "Marvell 88E6341",
3997 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01003998 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003999 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004000 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004001 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004002 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004003 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004004 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004005 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004006 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05004007 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004008 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004009 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004010 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004011 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004012 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004013 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004014 .ops = &mv88e6341_ops,
4015 },
4016
Vivien Didelotf81ec902016-05-09 13:22:58 -04004017 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004018 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004019 .family = MV88E6XXX_FAMILY_6351,
4020 .name = "Marvell 88E6350",
4021 .num_databases = 4096,
4022 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004023 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004024 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004025 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004026 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004027 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004028 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004029 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004030 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004031 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004032 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004033 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004034 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004035 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004036 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004037 },
4038
4039 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004040 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004041 .family = MV88E6XXX_FAMILY_6351,
4042 .name = "Marvell 88E6351",
4043 .num_databases = 4096,
4044 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004045 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004046 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004047 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004048 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004049 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004050 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004051 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004052 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004053 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004054 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004055 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004056 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004057 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004058 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004059 },
4060
4061 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004062 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004063 .family = MV88E6XXX_FAMILY_6352,
4064 .name = "Marvell 88E6352",
4065 .num_databases = 4096,
4066 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004067 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004068 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004069 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004070 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004071 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004072 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004073 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004074 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004075 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004076 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004077 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004078 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004079 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004080 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004081 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004082 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004083 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004084 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004085 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004086 .family = MV88E6XXX_FAMILY_6390,
4087 .name = "Marvell 88E6390",
4088 .num_databases = 4096,
4089 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01004090 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004091 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004092 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004093 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004094 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004095 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004096 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004097 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004098 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004099 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004100 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004101 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004102 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004103 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004104 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004105 .ops = &mv88e6390_ops,
4106 },
4107 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004108 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004109 .family = MV88E6XXX_FAMILY_6390,
4110 .name = "Marvell 88E6390X",
4111 .num_databases = 4096,
4112 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01004113 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004114 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004115 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004116 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004117 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004118 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004119 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004120 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004121 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004122 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004123 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004124 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004125 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004126 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004127 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004128 .ops = &mv88e6390x_ops,
4129 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004130};
4131
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004132static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004133{
Vivien Didelota439c062016-04-17 13:23:58 -04004134 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004135
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004136 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4137 if (mv88e6xxx_table[i].prod_num == prod_num)
4138 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004139
Vivien Didelotb9b37712015-10-30 19:39:48 -04004140 return NULL;
4141}
4142
Vivien Didelotfad09c72016-06-21 12:28:20 -04004143static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004144{
4145 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004146 unsigned int prod_num, rev;
4147 u16 id;
4148 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004149
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004150 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04004151 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004152 mutex_unlock(&chip->reg_lock);
4153 if (err)
4154 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004155
Vivien Didelot107fcc12017-06-12 12:37:36 -04004156 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
4157 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004158
4159 info = mv88e6xxx_lookup_info(prod_num);
4160 if (!info)
4161 return -ENODEV;
4162
Vivien Didelotcaac8542016-06-20 13:14:09 -04004163 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004164 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004165
Vivien Didelotca070c12016-09-02 14:45:34 -04004166 err = mv88e6xxx_g2_require(chip);
4167 if (err)
4168 return err;
4169
Vivien Didelotfad09c72016-06-21 12:28:20 -04004170 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4171 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004172
4173 return 0;
4174}
4175
Vivien Didelotfad09c72016-06-21 12:28:20 -04004176static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004177{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004178 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004179
Vivien Didelotfad09c72016-06-21 12:28:20 -04004180 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4181 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004182 return NULL;
4183
Vivien Didelotfad09c72016-06-21 12:28:20 -04004184 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004185
Vivien Didelotfad09c72016-06-21 12:28:20 -04004186 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004187 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004188
Vivien Didelotfad09c72016-06-21 12:28:20 -04004189 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004190}
4191
Vivien Didelotfad09c72016-06-21 12:28:20 -04004192static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004193 struct mii_bus *bus, int sw_addr)
4194{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004195 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004196 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004197 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004198 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004199 else
4200 return -EINVAL;
4201
Vivien Didelotfad09c72016-06-21 12:28:20 -04004202 chip->bus = bus;
4203 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004204
4205 return 0;
4206}
4207
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08004208static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4209 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02004210{
Vivien Didelot04bed142016-08-31 18:06:13 -04004211 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004212
Andrew Lunn443d5a12016-12-03 04:35:18 +01004213 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004214}
4215
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004216#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004217static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4218 struct device *host_dev, int sw_addr,
4219 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004220{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004221 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004222 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004223 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004224
Vivien Didelota439c062016-04-17 13:23:58 -04004225 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004226 if (!bus)
4227 return NULL;
4228
Vivien Didelotfad09c72016-06-21 12:28:20 -04004229 chip = mv88e6xxx_alloc_chip(dsa_dev);
4230 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004231 return NULL;
4232
Vivien Didelotcaac8542016-06-20 13:14:09 -04004233 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004234 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004235
Vivien Didelotfad09c72016-06-21 12:28:20 -04004236 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004237 if (err)
4238 goto free;
4239
Vivien Didelotfad09c72016-06-21 12:28:20 -04004240 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004241 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004242 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004243
Andrew Lunndc30c352016-10-16 19:56:49 +02004244 mutex_lock(&chip->reg_lock);
4245 err = mv88e6xxx_switch_reset(chip);
4246 mutex_unlock(&chip->reg_lock);
4247 if (err)
4248 goto free;
4249
Vivien Didelote57e5e72016-08-15 17:19:00 -04004250 mv88e6xxx_phy_init(chip);
4251
Andrew Lunna3c53be52017-01-24 14:53:50 +01004252 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004253 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004254 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004255
Vivien Didelotfad09c72016-06-21 12:28:20 -04004256 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004257
Vivien Didelotfad09c72016-06-21 12:28:20 -04004258 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004259free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004260 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004261
4262 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004263}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004264#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02004265
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004266static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004267 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004268{
4269 /* We don't need any dynamic resource from the kernel (yet),
4270 * so skip the prepare phase.
4271 */
4272
4273 return 0;
4274}
4275
4276static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004277 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004278{
Vivien Didelot04bed142016-08-31 18:06:13 -04004279 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004280
4281 mutex_lock(&chip->reg_lock);
4282 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004283 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004284 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4285 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004286 mutex_unlock(&chip->reg_lock);
4287}
4288
4289static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4290 const struct switchdev_obj_port_mdb *mdb)
4291{
Vivien Didelot04bed142016-08-31 18:06:13 -04004292 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004293 int err;
4294
4295 mutex_lock(&chip->reg_lock);
4296 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004297 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004298 mutex_unlock(&chip->reg_lock);
4299
4300 return err;
4301}
4302
Florian Fainellia82f67a2017-01-08 14:52:08 -08004303static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004304#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004305 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004306#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02004307 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004308 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004309 .adjust_link = mv88e6xxx_adjust_link,
Russell Kingc9a23562018-05-10 13:17:35 -07004310 .phylink_validate = mv88e6xxx_validate,
4311 .phylink_mac_link_state = mv88e6xxx_link_state,
4312 .phylink_mac_config = mv88e6xxx_mac_config,
4313 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
4314 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004315 .get_strings = mv88e6xxx_get_strings,
4316 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4317 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004318 .port_enable = mv88e6xxx_port_enable,
4319 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004320 .get_mac_eee = mv88e6xxx_get_mac_eee,
4321 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004322 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004323 .get_eeprom = mv88e6xxx_get_eeprom,
4324 .set_eeprom = mv88e6xxx_set_eeprom,
4325 .get_regs_len = mv88e6xxx_get_regs_len,
4326 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004327 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004328 .port_bridge_join = mv88e6xxx_port_bridge_join,
4329 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4330 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004331 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004332 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4333 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4334 .port_vlan_add = mv88e6xxx_port_vlan_add,
4335 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004336 .port_fdb_add = mv88e6xxx_port_fdb_add,
4337 .port_fdb_del = mv88e6xxx_port_fdb_del,
4338 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004339 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4340 .port_mdb_add = mv88e6xxx_port_mdb_add,
4341 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004342 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4343 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004344 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4345 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4346 .port_txtstamp = mv88e6xxx_port_txtstamp,
4347 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4348 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004349};
4350
Florian Fainelliab3d4082017-01-08 14:52:07 -08004351static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4352 .ops = &mv88e6xxx_switch_ops,
4353};
4354
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004355static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004356{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004357 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004358 struct dsa_switch *ds;
4359
Vivien Didelot73b12042017-03-30 17:37:10 -04004360 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004361 if (!ds)
4362 return -ENOMEM;
4363
Vivien Didelotfad09c72016-06-21 12:28:20 -04004364 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004365 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004366 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004367 ds->ageing_time_min = chip->info->age_time_coeff;
4368 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004369
4370 dev_set_drvdata(dev, ds);
4371
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004372 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004373}
4374
Vivien Didelotfad09c72016-06-21 12:28:20 -04004375static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004376{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004377 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004378}
4379
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004380static const void *pdata_device_get_match_data(struct device *dev)
4381{
4382 const struct of_device_id *matches = dev->driver->of_match_table;
4383 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
4384
4385 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
4386 matches++) {
4387 if (!strcmp(pdata->compatible, matches->compatible))
4388 return matches->data;
4389 }
4390 return NULL;
4391}
4392
Vivien Didelot57d32312016-06-20 13:13:58 -04004393static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004394{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004395 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04004396 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004397 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004398 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004399 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004400 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02004401 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004402
Andrew Lunn7bb8c992018-05-31 00:15:42 +02004403 if (!np && !pdata)
4404 return -EINVAL;
4405
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004406 if (np)
4407 compat_info = of_device_get_match_data(dev);
4408
4409 if (pdata) {
4410 compat_info = pdata_device_get_match_data(dev);
4411
4412 if (!pdata->netdev)
4413 return -EINVAL;
4414
4415 for (port = 0; port < DSA_MAX_PORTS; port++) {
4416 if (!(pdata->enabled_ports & (1 << port)))
4417 continue;
4418 if (strcmp(pdata->cd.port_names[port], "cpu"))
4419 continue;
4420 pdata->cd.netdev[port] = &pdata->netdev->dev;
4421 break;
4422 }
4423 }
4424
Vivien Didelotcaac8542016-06-20 13:14:09 -04004425 if (!compat_info)
4426 return -EINVAL;
4427
Vivien Didelotfad09c72016-06-21 12:28:20 -04004428 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004429 if (!chip) {
4430 err = -ENOMEM;
4431 goto out;
4432 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004433
Vivien Didelotfad09c72016-06-21 12:28:20 -04004434 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004435
Vivien Didelotfad09c72016-06-21 12:28:20 -04004436 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004437 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004438 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004439
Andrew Lunnb4308f02016-11-21 23:26:55 +01004440 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004441 if (IS_ERR(chip->reset)) {
4442 err = PTR_ERR(chip->reset);
4443 goto out;
4444 }
Andrew Lunnb4308f02016-11-21 23:26:55 +01004445
Vivien Didelotfad09c72016-06-21 12:28:20 -04004446 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004447 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004448 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004449
Vivien Didelote57e5e72016-08-15 17:19:00 -04004450 mv88e6xxx_phy_init(chip);
4451
Andrew Lunn00baabe2018-05-19 22:31:35 +02004452 if (chip->info->ops->get_eeprom) {
4453 if (np)
4454 of_property_read_u32(np, "eeprom-length",
4455 &chip->eeprom_len);
4456 else
4457 chip->eeprom_len = pdata->eeprom_len;
4458 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004459
Andrew Lunndc30c352016-10-16 19:56:49 +02004460 mutex_lock(&chip->reg_lock);
4461 err = mv88e6xxx_switch_reset(chip);
4462 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004463 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004464 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004465
Andrew Lunndc30c352016-10-16 19:56:49 +02004466 chip->irq = of_irq_get(np, 0);
4467 if (chip->irq == -EPROBE_DEFER) {
4468 err = chip->irq;
4469 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004470 }
4471
Andrew Lunn294d7112018-02-22 22:58:32 +01004472 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01004473 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01004474 * controllers
4475 */
4476 mutex_lock(&chip->reg_lock);
4477 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004478 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004479 else
4480 err = mv88e6xxx_irq_poll_setup(chip);
4481 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004482
Andrew Lunn294d7112018-02-22 22:58:32 +01004483 if (err)
4484 goto out;
4485
4486 if (chip->info->g2_irqs > 0) {
4487 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004488 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004489 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004490 }
4491
Andrew Lunn294d7112018-02-22 22:58:32 +01004492 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4493 if (err)
4494 goto out_g2_irq;
4495
4496 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4497 if (err)
4498 goto out_g1_atu_prob_irq;
4499
Andrew Lunna3c53be52017-01-24 14:53:50 +01004500 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004501 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004502 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004503
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004504 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004505 if (err)
4506 goto out_mdio;
4507
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004508 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004509
4510out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004511 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004512out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004513 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004514out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004515 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004516out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004517 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004518 mv88e6xxx_g2_irq_free(chip);
4519out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004520 mutex_lock(&chip->reg_lock);
4521 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004522 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004523 else
4524 mv88e6xxx_irq_poll_free(chip);
4525 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004526out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004527 if (pdata)
4528 dev_put(pdata->netdev);
4529
Andrew Lunndc30c352016-10-16 19:56:49 +02004530 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004531}
4532
4533static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4534{
4535 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004536 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004537
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004538 if (chip->info->ptp_support) {
4539 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004540 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004541 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004542
Andrew Lunn930188c2016-08-22 16:01:03 +02004543 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004544 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004545 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004546
Andrew Lunn76f38f12018-03-17 20:21:09 +01004547 mv88e6xxx_g1_vtu_prob_irq_free(chip);
4548 mv88e6xxx_g1_atu_prob_irq_free(chip);
4549
4550 if (chip->info->g2_irqs > 0)
4551 mv88e6xxx_g2_irq_free(chip);
4552
4553 mutex_lock(&chip->reg_lock);
4554 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004555 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01004556 else
4557 mv88e6xxx_irq_poll_free(chip);
4558 mutex_unlock(&chip->reg_lock);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004559}
4560
4561static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004562 {
4563 .compatible = "marvell,mv88e6085",
4564 .data = &mv88e6xxx_table[MV88E6085],
4565 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004566 {
4567 .compatible = "marvell,mv88e6190",
4568 .data = &mv88e6xxx_table[MV88E6190],
4569 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004570 { /* sentinel */ },
4571};
4572
4573MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4574
4575static struct mdio_driver mv88e6xxx_driver = {
4576 .probe = mv88e6xxx_probe,
4577 .remove = mv88e6xxx_remove,
4578 .mdiodrv.driver = {
4579 .name = "mv88e6085",
4580 .of_match_table = mv88e6xxx_of_match,
4581 },
4582};
4583
Ben Hutchings98e67302011-11-25 14:36:19 +00004584static int __init mv88e6xxx_init(void)
4585{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004586 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004587 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004588}
4589module_init(mv88e6xxx_init);
4590
4591static void __exit mv88e6xxx_cleanup(void)
4592{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004593 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004594 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004595}
4596module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004597
4598MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4599MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4600MODULE_LICENSE("GPL");