blob: 9ef07a06aceb6b467631d95cd78c8acfe21dd7da [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
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200346/* To be called with reg_lock held */
Andrew Lunn294d7112018-02-22 22:58:32 +0100347static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200348{
349 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100350 u16 mask;
351
Vivien Didelotd77f4322017-06-15 12:14:03 -0400352 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100353 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400354 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100355
Andreas Färber5edef2f2016-11-27 23:26:28 +0100356 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100357 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200358 irq_dispose_mapping(virq);
359 }
360
Andrew Lunna3db3d32016-11-20 20:14:14 +0100361 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200362}
363
Andrew Lunn294d7112018-02-22 22:58:32 +0100364static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
365{
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200366 /*
367 * free_irq must be called without reg_lock taken because the irq
368 * handler takes this lock, too.
369 */
Andrew Lunn294d7112018-02-22 22:58:32 +0100370 free_irq(chip->irq, chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200371
372 mutex_lock(&chip->reg_lock);
373 mv88e6xxx_g1_irq_free_common(chip);
374 mutex_unlock(&chip->reg_lock);
Andrew Lunn294d7112018-02-22 22:58:32 +0100375}
376
377static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200378{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100379 int err, irq, virq;
380 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200381
382 chip->g1_irq.nirqs = chip->info->g1_irqs;
383 chip->g1_irq.domain = irq_domain_add_simple(
384 NULL, chip->g1_irq.nirqs, 0,
385 &mv88e6xxx_g1_irq_domain_ops, chip);
386 if (!chip->g1_irq.domain)
387 return -ENOMEM;
388
389 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
390 irq_create_mapping(chip->g1_irq.domain, irq);
391
392 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
393 chip->g1_irq.masked = ~0;
394
Vivien Didelotd77f4322017-06-15 12:14:03 -0400395 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200396 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100397 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200398
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100399 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200400
Vivien Didelotd77f4322017-06-15 12:14:03 -0400401 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200402 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100403 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200404
405 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400406 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200407 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100408 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200409
Andrew Lunndc30c352016-10-16 19:56:49 +0200410 return 0;
411
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100412out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100413 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400414 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100415
416out_mapping:
417 for (irq = 0; irq < 16; irq++) {
418 virq = irq_find_mapping(chip->g1_irq.domain, irq);
419 irq_dispose_mapping(virq);
420 }
421
422 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200423
424 return err;
425}
426
Andrew Lunn294d7112018-02-22 22:58:32 +0100427static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
428{
429 int err;
430
431 err = mv88e6xxx_g1_irq_setup_common(chip);
432 if (err)
433 return err;
434
435 err = request_threaded_irq(chip->irq, NULL,
436 mv88e6xxx_g1_irq_thread_fn,
Andrew Lunn422a9fd62018-03-25 23:43:14 +0200437 IRQF_ONESHOT,
Andrew Lunn294d7112018-02-22 22:58:32 +0100438 dev_name(chip->dev), chip);
439 if (err)
440 mv88e6xxx_g1_irq_free_common(chip);
441
442 return err;
443}
444
445static void mv88e6xxx_irq_poll(struct kthread_work *work)
446{
447 struct mv88e6xxx_chip *chip = container_of(work,
448 struct mv88e6xxx_chip,
449 irq_poll_work.work);
450 mv88e6xxx_g1_irq_thread_work(chip);
451
452 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
453 msecs_to_jiffies(100));
454}
455
456static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
457{
458 int err;
459
460 err = mv88e6xxx_g1_irq_setup_common(chip);
461 if (err)
462 return err;
463
464 kthread_init_delayed_work(&chip->irq_poll_work,
465 mv88e6xxx_irq_poll);
466
467 chip->kworker = kthread_create_worker(0, dev_name(chip->dev));
468 if (IS_ERR(chip->kworker))
469 return PTR_ERR(chip->kworker);
470
471 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
472 msecs_to_jiffies(100));
473
474 return 0;
475}
476
477static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
478{
479 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
480 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200481
482 mutex_lock(&chip->reg_lock);
483 mv88e6xxx_g1_irq_free_common(chip);
484 mutex_unlock(&chip->reg_lock);
Andrew Lunn294d7112018-02-22 22:58:32 +0100485}
486
Vivien Didelotec561272016-09-02 14:45:33 -0400487int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400488{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200489 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400490
Andrew Lunn6441e6692016-08-19 00:01:55 +0200491 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400492 u16 val;
493 int err;
494
495 err = mv88e6xxx_read(chip, addr, reg, &val);
496 if (err)
497 return err;
498
499 if (!(val & mask))
500 return 0;
501
502 usleep_range(1000, 2000);
503 }
504
Andrew Lunn30853552016-08-19 00:01:57 +0200505 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400506 return -ETIMEDOUT;
507}
508
Vivien Didelotf22ab642016-07-18 20:45:31 -0400509/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400510int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400511{
512 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200513 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400514
515 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200516 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
517 if (err)
518 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400519
520 /* Set the Update bit to trigger a write operation */
521 val = BIT(15) | update;
522
523 return mv88e6xxx_write(chip, addr, reg, val);
524}
525
Vivien Didelotd78343d2016-11-04 03:23:36 +0100526static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
527 int link, int speed, int duplex,
528 phy_interface_t mode)
529{
530 int err;
531
532 if (!chip->info->ops->port_set_link)
533 return 0;
534
535 /* Port's MAC control must not be changed unless the link is down */
536 err = chip->info->ops->port_set_link(chip, port, 0);
537 if (err)
538 return err;
539
540 if (chip->info->ops->port_set_speed) {
541 err = chip->info->ops->port_set_speed(chip, port, speed);
542 if (err && err != -EOPNOTSUPP)
543 goto restore_link;
544 }
545
546 if (chip->info->ops->port_set_duplex) {
547 err = chip->info->ops->port_set_duplex(chip, port, duplex);
548 if (err && err != -EOPNOTSUPP)
549 goto restore_link;
550 }
551
552 if (chip->info->ops->port_set_rgmii_delay) {
553 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
554 if (err && err != -EOPNOTSUPP)
555 goto restore_link;
556 }
557
Andrew Lunnf39908d2017-02-04 20:02:50 +0100558 if (chip->info->ops->port_set_cmode) {
559 err = chip->info->ops->port_set_cmode(chip, port, mode);
560 if (err && err != -EOPNOTSUPP)
561 goto restore_link;
562 }
563
Vivien Didelotd78343d2016-11-04 03:23:36 +0100564 err = 0;
565restore_link:
566 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400567 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100568
569 return err;
570}
571
Andrew Lunndea87022015-08-31 15:56:47 +0200572/* We expect the switch to perform auto negotiation if there is a real
573 * phy. However, in the case of a fixed link phy, we force the port
574 * settings from the fixed link settings.
575 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400576static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
577 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200578{
Vivien Didelot04bed142016-08-31 18:06:13 -0400579 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200580 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200581
582 if (!phy_is_pseudo_fixed_link(phydev))
583 return;
584
Vivien Didelotfad09c72016-06-21 12:28:20 -0400585 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100586 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
587 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100589
590 if (err && err != -EOPNOTSUPP)
Vivien Didelot774439e52017-06-08 18:34:08 -0400591 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
Andrew Lunndea87022015-08-31 15:56:47 +0200592}
593
Russell Kingc9a23562018-05-10 13:17:35 -0700594static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
595 unsigned long *supported,
596 struct phylink_link_state *state)
597{
598}
599
600static int mv88e6xxx_link_state(struct dsa_switch *ds, int port,
601 struct phylink_link_state *state)
602{
603 struct mv88e6xxx_chip *chip = ds->priv;
604 int err;
605
606 mutex_lock(&chip->reg_lock);
607 err = mv88e6xxx_port_link_state(chip, port, state);
608 mutex_unlock(&chip->reg_lock);
609
610 return err;
611}
612
613static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
614 unsigned int mode,
615 const struct phylink_link_state *state)
616{
617 struct mv88e6xxx_chip *chip = ds->priv;
618 int speed, duplex, link, err;
619
620 if (mode == MLO_AN_PHY)
621 return;
622
623 if (mode == MLO_AN_FIXED) {
624 link = LINK_FORCED_UP;
625 speed = state->speed;
626 duplex = state->duplex;
627 } else {
628 speed = SPEED_UNFORCED;
629 duplex = DUPLEX_UNFORCED;
630 link = LINK_UNFORCED;
631 }
632
633 mutex_lock(&chip->reg_lock);
634 err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex,
635 state->interface);
636 mutex_unlock(&chip->reg_lock);
637
638 if (err && err != -EOPNOTSUPP)
639 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
640}
641
642static void mv88e6xxx_mac_link_force(struct dsa_switch *ds, int port, int link)
643{
644 struct mv88e6xxx_chip *chip = ds->priv;
645 int err;
646
647 mutex_lock(&chip->reg_lock);
648 err = chip->info->ops->port_set_link(chip, port, link);
649 mutex_unlock(&chip->reg_lock);
650
651 if (err)
652 dev_err(chip->dev, "p%d: failed to force MAC link\n", port);
653}
654
655static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
656 unsigned int mode,
657 phy_interface_t interface)
658{
659 if (mode == MLO_AN_FIXED)
660 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_DOWN);
661}
662
663static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
664 unsigned int mode, phy_interface_t interface,
665 struct phy_device *phydev)
666{
667 if (mode == MLO_AN_FIXED)
668 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_UP);
669}
670
Andrew Lunna605a0f2016-11-21 23:26:58 +0100671static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000672{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100673 if (!chip->info->ops->stats_snapshot)
674 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000675
Andrew Lunna605a0f2016-11-21 23:26:58 +0100676 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000677}
678
Andrew Lunne413e7e2015-04-02 04:06:38 +0200679static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100680 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
681 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
682 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
683 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
684 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
685 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
686 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
687 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
688 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
689 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
690 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
691 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
692 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
693 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
694 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
695 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
696 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
697 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
698 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
699 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
700 { "single", 4, 0x14, STATS_TYPE_BANK0, },
701 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
702 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
703 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
704 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
705 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
706 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
707 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
708 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
709 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
710 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
711 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
712 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
713 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
714 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
715 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
716 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
717 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
718 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
719 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
720 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
721 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
722 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
723 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
724 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
725 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
726 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
727 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
728 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
729 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
730 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
731 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
732 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
733 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
734 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
735 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
736 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
737 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
738 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200739};
740
Vivien Didelotfad09c72016-06-21 12:28:20 -0400741static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100742 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100743 int port, u16 bank1_select,
744 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200745{
Andrew Lunn80c46272015-06-20 18:42:30 +0200746 u32 low;
747 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100748 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200749 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200750 u64 value;
751
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100752 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100753 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200754 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
755 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800756 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200757
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200758 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100759 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200760 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
761 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800762 return U64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200763 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200764 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100765 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100766 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100767 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100768 /* fall through */
769 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100770 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100771 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100772 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100773 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500774 break;
775 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800776 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200777 }
778 value = (((u64)high) << 16) | low;
779 return value;
780}
781
Andrew Lunn436fe172018-03-01 02:02:29 +0100782static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
783 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100784{
785 struct mv88e6xxx_hw_stat *stat;
786 int i, j;
787
788 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
789 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100790 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100791 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
792 ETH_GSTRING_LEN);
793 j++;
794 }
795 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100796
797 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100798}
799
Andrew Lunn436fe172018-03-01 02:02:29 +0100800static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
801 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100802{
Andrew Lunn436fe172018-03-01 02:02:29 +0100803 return mv88e6xxx_stats_get_strings(chip, data,
804 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100805}
806
Andrew Lunn436fe172018-03-01 02:02:29 +0100807static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
808 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100809{
Andrew Lunn436fe172018-03-01 02:02:29 +0100810 return mv88e6xxx_stats_get_strings(chip, data,
811 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100812}
813
Andrew Lunn65f60e42018-03-28 23:50:28 +0200814static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
815 "atu_member_violation",
816 "atu_miss_violation",
817 "atu_full_violation",
818 "vtu_member_violation",
819 "vtu_miss_violation",
820};
821
822static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
823{
824 unsigned int i;
825
826 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
827 strlcpy(data + i * ETH_GSTRING_LEN,
828 mv88e6xxx_atu_vtu_stats_strings[i],
829 ETH_GSTRING_LEN);
830}
831
Andrew Lunndfafe442016-11-21 23:27:02 +0100832static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700833 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100834{
Vivien Didelot04bed142016-08-31 18:06:13 -0400835 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100836 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100837
Florian Fainelli89f09042018-04-25 12:12:50 -0700838 if (stringset != ETH_SS_STATS)
839 return;
840
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100841 mutex_lock(&chip->reg_lock);
842
Andrew Lunndfafe442016-11-21 23:27:02 +0100843 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100844 count = chip->info->ops->stats_get_strings(chip, data);
845
846 if (chip->info->ops->serdes_get_strings) {
847 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200848 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100849 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100850
Andrew Lunn65f60e42018-03-28 23:50:28 +0200851 data += count * ETH_GSTRING_LEN;
852 mv88e6xxx_atu_vtu_get_strings(data);
853
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100854 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100855}
856
857static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
858 int types)
859{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100860 struct mv88e6xxx_hw_stat *stat;
861 int i, j;
862
863 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
864 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100865 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100866 j++;
867 }
868 return j;
869}
870
Andrew Lunndfafe442016-11-21 23:27:02 +0100871static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
872{
873 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
874 STATS_TYPE_PORT);
875}
876
877static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
878{
879 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
880 STATS_TYPE_BANK1);
881}
882
Florian Fainelli89f09042018-04-25 12:12:50 -0700883static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +0100884{
885 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100886 int serdes_count = 0;
887 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100888
Florian Fainelli89f09042018-04-25 12:12:50 -0700889 if (sset != ETH_SS_STATS)
890 return 0;
891
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100892 mutex_lock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100893 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100894 count = chip->info->ops->stats_get_sset_count(chip);
895 if (count < 0)
896 goto out;
897
898 if (chip->info->ops->serdes_get_sset_count)
899 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
900 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +0200901 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +0100902 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200903 goto out;
904 }
905 count += serdes_count;
906 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
907
Andrew Lunn436fe172018-03-01 02:02:29 +0100908out:
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100909 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100910
Andrew Lunn436fe172018-03-01 02:02:29 +0100911 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +0100912}
913
Andrew Lunn436fe172018-03-01 02:02:29 +0100914static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
915 uint64_t *data, int types,
916 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100917{
918 struct mv88e6xxx_hw_stat *stat;
919 int i, j;
920
921 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
922 stat = &mv88e6xxx_hw_stats[i];
923 if (stat->type & types) {
Andrew Lunn377cda12018-02-15 14:38:34 +0100924 mutex_lock(&chip->reg_lock);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100925 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
926 bank1_select,
927 histogram);
Andrew Lunn377cda12018-02-15 14:38:34 +0100928 mutex_unlock(&chip->reg_lock);
929
Andrew Lunn052f9472016-11-21 23:27:03 +0100930 j++;
931 }
932 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100933 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +0100934}
935
Andrew Lunn436fe172018-03-01 02:02:29 +0100936static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
937 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100938{
939 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100940 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400941 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100942}
943
Andrew Lunn436fe172018-03-01 02:02:29 +0100944static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
945 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100946{
947 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100948 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400949 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
950 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100951}
952
Andrew Lunn436fe172018-03-01 02:02:29 +0100953static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
954 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +0100955{
956 return mv88e6xxx_stats_get_stats(chip, port, data,
957 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400958 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
959 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100960}
961
Andrew Lunn65f60e42018-03-28 23:50:28 +0200962static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
963 uint64_t *data)
964{
965 *data++ = chip->ports[port].atu_member_violation;
966 *data++ = chip->ports[port].atu_miss_violation;
967 *data++ = chip->ports[port].atu_full_violation;
968 *data++ = chip->ports[port].vtu_member_violation;
969 *data++ = chip->ports[port].vtu_miss_violation;
970}
971
Andrew Lunn052f9472016-11-21 23:27:03 +0100972static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
973 uint64_t *data)
974{
Andrew Lunn436fe172018-03-01 02:02:29 +0100975 int count = 0;
976
Andrew Lunn052f9472016-11-21 23:27:03 +0100977 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +0100978 count = chip->info->ops->stats_get_stats(chip, port, data);
979
Andrew Lunn65f60e42018-03-28 23:50:28 +0200980 mutex_lock(&chip->reg_lock);
Andrew Lunn436fe172018-03-01 02:02:29 +0100981 if (chip->info->ops->serdes_get_stats) {
982 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200983 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100984 }
Andrew Lunn65f60e42018-03-28 23:50:28 +0200985 data += count;
986 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
987 mutex_unlock(&chip->reg_lock);
Andrew Lunn052f9472016-11-21 23:27:03 +0100988}
989
Vivien Didelotf81ec902016-05-09 13:22:58 -0400990static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
991 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000992{
Vivien Didelot04bed142016-08-31 18:06:13 -0400993 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000994 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000995
Vivien Didelotfad09c72016-06-21 12:28:20 -0400996 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000997
Andrew Lunna605a0f2016-11-21 23:26:58 +0100998 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +0100999 mutex_unlock(&chip->reg_lock);
1000
1001 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001002 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001003
1004 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001005
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001006}
Ben Hutchings98e67302011-11-25 14:36:19 +00001007
Vivien Didelotf81ec902016-05-09 13:22:58 -04001008static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001009{
1010 return 32 * sizeof(u16);
1011}
1012
Vivien Didelotf81ec902016-05-09 13:22:58 -04001013static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1014 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001015{
Vivien Didelot04bed142016-08-31 18:06:13 -04001016 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001017 int err;
1018 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001019 u16 *p = _p;
1020 int i;
1021
1022 regs->version = 0;
1023
1024 memset(p, 0xff, 32 * sizeof(u16));
1025
Vivien Didelotfad09c72016-06-21 12:28:20 -04001026 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001027
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001028 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001029
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001030 err = mv88e6xxx_port_read(chip, port, i, &reg);
1031 if (!err)
1032 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001033 }
Vivien Didelot23062512016-05-09 13:22:45 -04001034
Vivien Didelotfad09c72016-06-21 12:28:20 -04001035 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001036}
1037
Vivien Didelot08f50062017-08-01 16:32:41 -04001038static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1039 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001040{
Vivien Didelot5480db62017-08-01 16:32:40 -04001041 /* Nothing to do on the port's MAC */
1042 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001043}
1044
Vivien Didelot08f50062017-08-01 16:32:41 -04001045static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1046 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001047{
Vivien Didelot5480db62017-08-01 16:32:40 -04001048 /* Nothing to do on the port's MAC */
1049 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001050}
1051
Vivien Didelote5887a22017-03-30 17:37:11 -04001052static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001053{
Vivien Didelote5887a22017-03-30 17:37:11 -04001054 struct dsa_switch *ds = NULL;
1055 struct net_device *br;
1056 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001057 int i;
1058
Vivien Didelote5887a22017-03-30 17:37:11 -04001059 if (dev < DSA_MAX_SWITCHES)
1060 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001061
Vivien Didelote5887a22017-03-30 17:37:11 -04001062 /* Prevent frames from unknown switch or port */
1063 if (!ds || port >= ds->num_ports)
1064 return 0;
1065
1066 /* Frames from DSA links and CPU ports can egress any local port */
1067 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1068 return mv88e6xxx_port_mask(chip);
1069
1070 br = ds->ports[port].bridge_dev;
1071 pvlan = 0;
1072
1073 /* Frames from user ports can egress any local DSA links and CPU ports,
1074 * as well as any local member of their bridge group.
1075 */
1076 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1077 if (dsa_is_cpu_port(chip->ds, i) ||
1078 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -04001079 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -04001080 pvlan |= BIT(i);
1081
1082 return pvlan;
1083}
1084
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001085static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001086{
1087 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001088
1089 /* prevent frames from going back out of the port they came in on */
1090 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001091
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001092 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001093}
1094
Vivien Didelotf81ec902016-05-09 13:22:58 -04001095static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1096 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001097{
Vivien Didelot04bed142016-08-31 18:06:13 -04001098 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001099 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001100
Vivien Didelotfad09c72016-06-21 12:28:20 -04001101 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -04001102 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001103 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001104
1105 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001106 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001107}
1108
Vivien Didelot93e18d62018-05-11 17:16:35 -04001109static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1110{
1111 int err;
1112
1113 if (chip->info->ops->ieee_pri_map) {
1114 err = chip->info->ops->ieee_pri_map(chip);
1115 if (err)
1116 return err;
1117 }
1118
1119 if (chip->info->ops->ip_pri_map) {
1120 err = chip->info->ops->ip_pri_map(chip);
1121 if (err)
1122 return err;
1123 }
1124
1125 return 0;
1126}
1127
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001128static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1129{
1130 int target, port;
1131 int err;
1132
1133 if (!chip->info->global2_addr)
1134 return 0;
1135
1136 /* Initialize the routing port to the 32 possible target devices */
1137 for (target = 0; target < 32; target++) {
1138 port = 0x1f;
1139 if (target < DSA_MAX_SWITCHES)
1140 if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
1141 port = chip->ds->rtable[target];
1142
1143 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1144 if (err)
1145 return err;
1146 }
1147
Vivien Didelot02317e62018-05-09 11:38:49 -04001148 if (chip->info->ops->set_cascade_port) {
1149 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1150 err = chip->info->ops->set_cascade_port(chip, port);
1151 if (err)
1152 return err;
1153 }
1154
Vivien Didelot23c98912018-05-09 11:38:50 -04001155 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1156 if (err)
1157 return err;
1158
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001159 return 0;
1160}
1161
Vivien Didelotb28f8722018-04-26 21:56:44 -04001162static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1163{
1164 /* Clear all trunk masks and mapping */
1165 if (chip->info->global2_addr)
1166 return mv88e6xxx_g2_trunk_clear(chip);
1167
1168 return 0;
1169}
1170
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001171static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1172{
1173 if (chip->info->ops->rmu_disable)
1174 return chip->info->ops->rmu_disable(chip);
1175
1176 return 0;
1177}
1178
Vivien Didelot9e907d72017-07-17 13:03:43 -04001179static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1180{
1181 if (chip->info->ops->pot_clear)
1182 return chip->info->ops->pot_clear(chip);
1183
1184 return 0;
1185}
1186
Vivien Didelot51c901a2017-07-17 13:03:41 -04001187static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1188{
1189 if (chip->info->ops->mgmt_rsvd2cpu)
1190 return chip->info->ops->mgmt_rsvd2cpu(chip);
1191
1192 return 0;
1193}
1194
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001195static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1196{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001197 int err;
1198
Vivien Didelotdaefc942017-03-11 16:12:54 -05001199 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1200 if (err)
1201 return err;
1202
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001203 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1204 if (err)
1205 return err;
1206
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001207 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1208}
1209
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001210static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1211{
1212 int port;
1213 int err;
1214
1215 if (!chip->info->ops->irl_init_all)
1216 return 0;
1217
1218 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1219 /* Disable ingress rate limiting by resetting all per port
1220 * ingress rate limit resources to their initial state.
1221 */
1222 err = chip->info->ops->irl_init_all(chip, port);
1223 if (err)
1224 return err;
1225 }
1226
1227 return 0;
1228}
1229
Vivien Didelot04a69a12017-10-13 14:18:05 -04001230static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1231{
1232 if (chip->info->ops->set_switch_mac) {
1233 u8 addr[ETH_ALEN];
1234
1235 eth_random_addr(addr);
1236
1237 return chip->info->ops->set_switch_mac(chip, addr);
1238 }
1239
1240 return 0;
1241}
1242
Vivien Didelot17a15942017-03-30 17:37:09 -04001243static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1244{
1245 u16 pvlan = 0;
1246
1247 if (!mv88e6xxx_has_pvt(chip))
1248 return -EOPNOTSUPP;
1249
1250 /* Skip the local source device, which uses in-chip port VLAN */
1251 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001252 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001253
1254 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1255}
1256
Vivien Didelot81228992017-03-30 17:37:08 -04001257static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1258{
Vivien Didelot17a15942017-03-30 17:37:09 -04001259 int dev, port;
1260 int err;
1261
Vivien Didelot81228992017-03-30 17:37:08 -04001262 if (!mv88e6xxx_has_pvt(chip))
1263 return 0;
1264
1265 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1266 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1267 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001268 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1269 if (err)
1270 return err;
1271
1272 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1273 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1274 err = mv88e6xxx_pvt_map(chip, dev, port);
1275 if (err)
1276 return err;
1277 }
1278 }
1279
1280 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001281}
1282
Vivien Didelot749efcb2016-09-22 16:49:24 -04001283static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1284{
1285 struct mv88e6xxx_chip *chip = ds->priv;
1286 int err;
1287
1288 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001289 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001290 mutex_unlock(&chip->reg_lock);
1291
1292 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001293 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001294}
1295
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001296static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1297{
1298 if (!chip->info->max_vid)
1299 return 0;
1300
1301 return mv88e6xxx_g1_vtu_flush(chip);
1302}
1303
Vivien Didelotf1394b782017-05-01 14:05:22 -04001304static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1305 struct mv88e6xxx_vtu_entry *entry)
1306{
1307 if (!chip->info->ops->vtu_getnext)
1308 return -EOPNOTSUPP;
1309
1310 return chip->info->ops->vtu_getnext(chip, entry);
1311}
1312
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001313static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1314 struct mv88e6xxx_vtu_entry *entry)
1315{
1316 if (!chip->info->ops->vtu_loadpurge)
1317 return -EOPNOTSUPP;
1318
1319 return chip->info->ops->vtu_loadpurge(chip, entry);
1320}
1321
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001322static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001323{
1324 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001325 struct mv88e6xxx_vtu_entry vlan = {
1326 .vid = chip->info->max_vid,
1327 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001328 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001329
1330 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1331
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001332 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001333 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001334 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001335 if (err)
1336 return err;
1337
1338 set_bit(*fid, fid_bitmap);
1339 }
1340
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001341 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001342 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001343 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001344 if (err)
1345 return err;
1346
1347 if (!vlan.valid)
1348 break;
1349
1350 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001351 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001352
1353 /* The reset value 0x000 is used to indicate that multiple address
1354 * databases are not needed. Return the next positive available.
1355 */
1356 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001357 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001358 return -ENOSPC;
1359
1360 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001361 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001362}
1363
Vivien Didelot567aa592017-05-01 14:05:25 -04001364static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1365 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001366{
1367 int err;
1368
1369 if (!vid)
1370 return -EINVAL;
1371
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001372 entry->vid = vid - 1;
1373 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001374
Vivien Didelotf1394b782017-05-01 14:05:22 -04001375 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001376 if (err)
1377 return err;
1378
Vivien Didelot567aa592017-05-01 14:05:25 -04001379 if (entry->vid == vid && entry->valid)
1380 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001381
Vivien Didelot567aa592017-05-01 14:05:25 -04001382 if (new) {
1383 int i;
1384
1385 /* Initialize a fresh VLAN entry */
1386 memset(entry, 0, sizeof(*entry));
1387 entry->valid = true;
1388 entry->vid = vid;
1389
Vivien Didelot553a7682017-06-07 18:12:16 -04001390 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001391 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001392 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001393 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001394
1395 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001396 }
1397
Vivien Didelot567aa592017-05-01 14:05:25 -04001398 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1399 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001400}
1401
Vivien Didelotda9c3592016-02-12 12:09:40 -05001402static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1403 u16 vid_begin, u16 vid_end)
1404{
Vivien Didelot04bed142016-08-31 18:06:13 -04001405 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001406 struct mv88e6xxx_vtu_entry vlan = {
1407 .vid = vid_begin - 1,
1408 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001409 int i, err;
1410
Andrew Lunndb06ae412017-09-25 23:32:20 +02001411 /* DSA and CPU ports have to be members of multiple vlans */
1412 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1413 return 0;
1414
Vivien Didelotda9c3592016-02-12 12:09:40 -05001415 if (!vid_begin)
1416 return -EOPNOTSUPP;
1417
Vivien Didelotfad09c72016-06-21 12:28:20 -04001418 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001419
Vivien Didelotda9c3592016-02-12 12:09:40 -05001420 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001421 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001422 if (err)
1423 goto unlock;
1424
1425 if (!vlan.valid)
1426 break;
1427
1428 if (vlan.vid > vid_end)
1429 break;
1430
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001431 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001432 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1433 continue;
1434
Andrew Lunncd886462017-11-09 22:29:53 +01001435 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001436 continue;
1437
Vivien Didelotbd00e052017-05-01 14:05:11 -04001438 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001439 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001440 continue;
1441
Vivien Didelotc8652c82017-10-16 11:12:19 -04001442 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001443 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001444 break; /* same bridge, check next VLAN */
1445
Vivien Didelotc8652c82017-10-16 11:12:19 -04001446 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001447 continue;
1448
Andrew Lunn743fcc22017-11-09 22:29:54 +01001449 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1450 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001451 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001452 err = -EOPNOTSUPP;
1453 goto unlock;
1454 }
1455 } while (vlan.vid < vid_end);
1456
1457unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001458 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001459
1460 return err;
1461}
1462
Vivien Didelotf81ec902016-05-09 13:22:58 -04001463static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1464 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001465{
Vivien Didelot04bed142016-08-31 18:06:13 -04001466 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001467 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1468 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001469 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001470
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001471 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001472 return -EOPNOTSUPP;
1473
Vivien Didelotfad09c72016-06-21 12:28:20 -04001474 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001475 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001476 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001477
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001478 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001479}
1480
Vivien Didelot57d32312016-06-20 13:13:58 -04001481static int
1482mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001483 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001484{
Vivien Didelot04bed142016-08-31 18:06:13 -04001485 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001486 int err;
1487
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001488 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001489 return -EOPNOTSUPP;
1490
Vivien Didelotda9c3592016-02-12 12:09:40 -05001491 /* If the requested port doesn't belong to the same bridge as the VLAN
1492 * members, do not support it (yet) and fallback to software VLAN.
1493 */
1494 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1495 vlan->vid_end);
1496 if (err)
1497 return err;
1498
Vivien Didelot76e398a2015-11-01 12:33:55 -05001499 /* We don't need any dynamic resource from the kernel (yet),
1500 * so skip the prepare phase.
1501 */
1502 return 0;
1503}
1504
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001505static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1506 const unsigned char *addr, u16 vid,
1507 u8 state)
1508{
1509 struct mv88e6xxx_vtu_entry vlan;
1510 struct mv88e6xxx_atu_entry entry;
1511 int err;
1512
1513 /* Null VLAN ID corresponds to the port private database */
1514 if (vid == 0)
1515 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1516 else
1517 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1518 if (err)
1519 return err;
1520
1521 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1522 ether_addr_copy(entry.mac, addr);
1523 eth_addr_dec(entry.mac);
1524
1525 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1526 if (err)
1527 return err;
1528
1529 /* Initialize a fresh ATU entry if it isn't found */
1530 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1531 !ether_addr_equal(entry.mac, addr)) {
1532 memset(&entry, 0, sizeof(entry));
1533 ether_addr_copy(entry.mac, addr);
1534 }
1535
1536 /* Purge the ATU entry only if no port is using it anymore */
1537 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1538 entry.portvec &= ~BIT(port);
1539 if (!entry.portvec)
1540 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1541 } else {
1542 entry.portvec |= BIT(port);
1543 entry.state = state;
1544 }
1545
1546 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1547}
1548
Andrew Lunn87fa8862017-11-09 22:29:56 +01001549static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1550 u16 vid)
1551{
1552 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1553 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1554
1555 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1556}
1557
1558static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1559{
1560 int port;
1561 int err;
1562
1563 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1564 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1565 if (err)
1566 return err;
1567 }
1568
1569 return 0;
1570}
1571
Vivien Didelotfad09c72016-06-21 12:28:20 -04001572static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001573 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001574{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001575 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001576 int err;
1577
Vivien Didelot567aa592017-05-01 14:05:25 -04001578 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001579 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001580 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001581
Vivien Didelotc91498e2017-06-07 18:12:13 -04001582 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001583
Andrew Lunn87fa8862017-11-09 22:29:56 +01001584 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1585 if (err)
1586 return err;
1587
1588 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001589}
1590
Vivien Didelotf81ec902016-05-09 13:22:58 -04001591static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001592 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001593{
Vivien Didelot04bed142016-08-31 18:06:13 -04001594 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001595 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1596 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001597 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001598 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001599
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001600 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001601 return;
1602
Vivien Didelotc91498e2017-06-07 18:12:13 -04001603 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001604 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001605 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001606 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001607 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001608 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001609
Vivien Didelotfad09c72016-06-21 12:28:20 -04001610 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001611
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001612 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001613 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001614 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1615 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001616
Vivien Didelot77064f32016-11-04 03:23:30 +01001617 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001618 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1619 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001620
Vivien Didelotfad09c72016-06-21 12:28:20 -04001621 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001622}
1623
Vivien Didelotfad09c72016-06-21 12:28:20 -04001624static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001625 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001626{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001627 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001628 int i, err;
1629
Vivien Didelot567aa592017-05-01 14:05:25 -04001630 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001631 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001632 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001633
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001634 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001635 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001636 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001637
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001638 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001639
1640 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001641 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001642 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001643 if (vlan.member[i] !=
1644 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001645 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001646 break;
1647 }
1648 }
1649
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001650 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001651 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001652 return err;
1653
Vivien Didelote606ca32017-03-11 16:12:55 -05001654 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001655}
1656
Vivien Didelotf81ec902016-05-09 13:22:58 -04001657static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1658 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001659{
Vivien Didelot04bed142016-08-31 18:06:13 -04001660 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001661 u16 pvid, vid;
1662 int err = 0;
1663
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001664 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001665 return -EOPNOTSUPP;
1666
Vivien Didelotfad09c72016-06-21 12:28:20 -04001667 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001668
Vivien Didelot77064f32016-11-04 03:23:30 +01001669 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001670 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001671 goto unlock;
1672
Vivien Didelot76e398a2015-11-01 12:33:55 -05001673 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001674 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001675 if (err)
1676 goto unlock;
1677
1678 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001679 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001680 if (err)
1681 goto unlock;
1682 }
1683 }
1684
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001685unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001686 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001687
1688 return err;
1689}
1690
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001691static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1692 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001693{
Vivien Didelot04bed142016-08-31 18:06:13 -04001694 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001695 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001696
Vivien Didelotfad09c72016-06-21 12:28:20 -04001697 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001698 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1699 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001700 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001701
1702 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001703}
1704
Vivien Didelotf81ec902016-05-09 13:22:58 -04001705static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001706 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001707{
Vivien Didelot04bed142016-08-31 18:06:13 -04001708 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001709 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001710
Vivien Didelotfad09c72016-06-21 12:28:20 -04001711 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001712 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001713 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001714 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001715
Vivien Didelot83dabd12016-08-31 11:50:04 -04001716 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001717}
1718
Vivien Didelot83dabd12016-08-31 11:50:04 -04001719static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1720 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001721 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001722{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001723 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001724 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001725 int err;
1726
Vivien Didelot27c0e602017-06-15 12:14:01 -04001727 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001728 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001729
1730 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001731 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001732 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001733 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001734 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001735 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001736
Vivien Didelot27c0e602017-06-15 12:14:01 -04001737 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001738 break;
1739
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001740 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001741 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001742
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001743 if (!is_unicast_ether_addr(addr.mac))
1744 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001745
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001746 is_static = (addr.state ==
1747 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1748 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001749 if (err)
1750 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001751 } while (!is_broadcast_ether_addr(addr.mac));
1752
1753 return err;
1754}
1755
Vivien Didelot83dabd12016-08-31 11:50:04 -04001756static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001757 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001758{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001759 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001760 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001761 };
1762 u16 fid;
1763 int err;
1764
1765 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001766 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001767 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001768 mutex_unlock(&chip->reg_lock);
1769
Vivien Didelot83dabd12016-08-31 11:50:04 -04001770 if (err)
1771 return err;
1772
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001773 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001774 if (err)
1775 return err;
1776
1777 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001778 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001779 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001780 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001781 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001782 if (err)
1783 return err;
1784
1785 if (!vlan.valid)
1786 break;
1787
1788 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001789 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001790 if (err)
1791 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001792 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001793
1794 return err;
1795}
1796
Vivien Didelotf81ec902016-05-09 13:22:58 -04001797static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001798 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001799{
Vivien Didelot04bed142016-08-31 18:06:13 -04001800 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001801
Andrew Lunna61e5402018-02-15 14:38:35 +01001802 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001803}
1804
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001805static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1806 struct net_device *br)
1807{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001808 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001809 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001810 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001811 int err;
1812
1813 /* Remap the Port VLAN of each local bridge group member */
1814 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1815 if (chip->ds->ports[port].bridge_dev == br) {
1816 err = mv88e6xxx_port_vlan_map(chip, port);
1817 if (err)
1818 return err;
1819 }
1820 }
1821
Vivien Didelote96a6e02017-03-30 17:37:13 -04001822 if (!mv88e6xxx_has_pvt(chip))
1823 return 0;
1824
1825 /* Remap the Port VLAN of each cross-chip bridge group member */
1826 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1827 ds = chip->ds->dst->ds[dev];
1828 if (!ds)
1829 break;
1830
1831 for (port = 0; port < ds->num_ports; ++port) {
1832 if (ds->ports[port].bridge_dev == br) {
1833 err = mv88e6xxx_pvt_map(chip, dev, port);
1834 if (err)
1835 return err;
1836 }
1837 }
1838 }
1839
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001840 return 0;
1841}
1842
Vivien Didelotf81ec902016-05-09 13:22:58 -04001843static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001844 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001845{
Vivien Didelot04bed142016-08-31 18:06:13 -04001846 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001847 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001848
Vivien Didelotfad09c72016-06-21 12:28:20 -04001849 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001850 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001851 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001852
Vivien Didelot466dfa02016-02-26 13:16:05 -05001853 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001854}
1855
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001856static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1857 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001858{
Vivien Didelot04bed142016-08-31 18:06:13 -04001859 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001860
Vivien Didelotfad09c72016-06-21 12:28:20 -04001861 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001862 if (mv88e6xxx_bridge_map(chip, br) ||
1863 mv88e6xxx_port_vlan_map(chip, port))
1864 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001865 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001866}
1867
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001868static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1869 int port, struct net_device *br)
1870{
1871 struct mv88e6xxx_chip *chip = ds->priv;
1872 int err;
1873
1874 if (!mv88e6xxx_has_pvt(chip))
1875 return 0;
1876
1877 mutex_lock(&chip->reg_lock);
1878 err = mv88e6xxx_pvt_map(chip, dev, port);
1879 mutex_unlock(&chip->reg_lock);
1880
1881 return err;
1882}
1883
1884static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1885 int port, struct net_device *br)
1886{
1887 struct mv88e6xxx_chip *chip = ds->priv;
1888
1889 if (!mv88e6xxx_has_pvt(chip))
1890 return;
1891
1892 mutex_lock(&chip->reg_lock);
1893 if (mv88e6xxx_pvt_map(chip, dev, port))
1894 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1895 mutex_unlock(&chip->reg_lock);
1896}
1897
Vivien Didelot17e708b2016-12-05 17:30:27 -05001898static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1899{
1900 if (chip->info->ops->reset)
1901 return chip->info->ops->reset(chip);
1902
1903 return 0;
1904}
1905
Vivien Didelot309eca62016-12-05 17:30:26 -05001906static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1907{
1908 struct gpio_desc *gpiod = chip->reset;
1909
1910 /* If there is a GPIO connected to the reset pin, toggle it */
1911 if (gpiod) {
1912 gpiod_set_value_cansleep(gpiod, 1);
1913 usleep_range(10000, 20000);
1914 gpiod_set_value_cansleep(gpiod, 0);
1915 usleep_range(10000, 20000);
1916 }
1917}
1918
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001919static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1920{
1921 int i, err;
1922
1923 /* Set all ports to the Disabled state */
1924 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001925 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001926 if (err)
1927 return err;
1928 }
1929
1930 /* Wait for transmit queues to drain,
1931 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1932 */
1933 usleep_range(2000, 4000);
1934
1935 return 0;
1936}
1937
Vivien Didelotfad09c72016-06-21 12:28:20 -04001938static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001939{
Vivien Didelota935c052016-09-29 12:21:53 -04001940 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001941
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001942 err = mv88e6xxx_disable_ports(chip);
1943 if (err)
1944 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001945
Vivien Didelot309eca62016-12-05 17:30:26 -05001946 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001947
Vivien Didelot17e708b2016-12-05 17:30:27 -05001948 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001949}
1950
Vivien Didelot43145572017-03-11 16:12:59 -05001951static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001952 enum mv88e6xxx_frame_mode frame,
1953 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001954{
1955 int err;
1956
Vivien Didelot43145572017-03-11 16:12:59 -05001957 if (!chip->info->ops->port_set_frame_mode)
1958 return -EOPNOTSUPP;
1959
1960 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001961 if (err)
1962 return err;
1963
Vivien Didelot43145572017-03-11 16:12:59 -05001964 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1965 if (err)
1966 return err;
1967
1968 if (chip->info->ops->port_set_ether_type)
1969 return chip->info->ops->port_set_ether_type(chip, port, etype);
1970
1971 return 0;
1972}
1973
1974static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1975{
1976 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001977 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001978 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001979}
1980
1981static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1982{
1983 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001984 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001985 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001986}
1987
1988static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1989{
1990 return mv88e6xxx_set_port_mode(chip, port,
1991 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001992 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1993 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001994}
1995
1996static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1997{
1998 if (dsa_is_dsa_port(chip->ds, port))
1999 return mv88e6xxx_set_port_mode_dsa(chip, port);
2000
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002001 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002002 return mv88e6xxx_set_port_mode_normal(chip, port);
2003
2004 /* Setup CPU port mode depending on its supported tag format */
2005 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2006 return mv88e6xxx_set_port_mode_dsa(chip, port);
2007
2008 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2009 return mv88e6xxx_set_port_mode_edsa(chip, port);
2010
2011 return -EINVAL;
2012}
2013
Vivien Didelotea698f42017-03-11 16:12:50 -05002014static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2015{
2016 bool message = dsa_is_dsa_port(chip->ds, port);
2017
2018 return mv88e6xxx_port_set_message_port(chip, port, message);
2019}
2020
Vivien Didelot601aeed2017-03-11 16:13:00 -05002021static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2022{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002023 struct dsa_switch *ds = chip->ds;
2024 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002025
2026 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002027 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002028 if (chip->info->ops->port_set_egress_floods)
2029 return chip->info->ops->port_set_egress_floods(chip, port,
2030 flood, flood);
2031
2032 return 0;
2033}
2034
Andrew Lunn6d917822017-05-26 01:03:21 +02002035static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2036 bool on)
2037{
Vivien Didelot523a8902017-05-26 18:02:42 -04002038 if (chip->info->ops->serdes_power)
2039 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02002040
Vivien Didelot523a8902017-05-26 18:02:42 -04002041 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02002042}
2043
Vivien Didelotfa371c82017-12-05 15:34:10 -05002044static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2045{
2046 struct dsa_switch *ds = chip->ds;
2047 int upstream_port;
2048 int err;
2049
Vivien Didelot07073c72017-12-05 15:34:13 -05002050 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002051 if (chip->info->ops->port_set_upstream_port) {
2052 err = chip->info->ops->port_set_upstream_port(chip, port,
2053 upstream_port);
2054 if (err)
2055 return err;
2056 }
2057
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002058 if (port == upstream_port) {
2059 if (chip->info->ops->set_cpu_port) {
2060 err = chip->info->ops->set_cpu_port(chip,
2061 upstream_port);
2062 if (err)
2063 return err;
2064 }
2065
2066 if (chip->info->ops->set_egress_port) {
2067 err = chip->info->ops->set_egress_port(chip,
2068 upstream_port);
2069 if (err)
2070 return err;
2071 }
2072 }
2073
Vivien Didelotfa371c82017-12-05 15:34:10 -05002074 return 0;
2075}
2076
Vivien Didelotfad09c72016-06-21 12:28:20 -04002077static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002078{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002079 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002080 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002081 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002082
Vivien Didelotd78343d2016-11-04 03:23:36 +01002083 /* MAC Forcing register: don't force link, speed, duplex or flow control
2084 * state to any particular values on physical ports, but force the CPU
2085 * port and all DSA ports to their maximum bandwidth and full duplex.
2086 */
2087 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2088 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2089 SPEED_MAX, DUPLEX_FULL,
2090 PHY_INTERFACE_MODE_NA);
2091 else
2092 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2093 SPEED_UNFORCED, DUPLEX_UNFORCED,
2094 PHY_INTERFACE_MODE_NA);
2095 if (err)
2096 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002097
2098 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2099 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2100 * tunneling, determine priority by looking at 802.1p and IP
2101 * priority fields (IP prio has precedence), and set STP state
2102 * to Forwarding.
2103 *
2104 * If this is the CPU link, use DSA or EDSA tagging depending
2105 * on which tagging mode was configured.
2106 *
2107 * If this is a link to another switch, use DSA tagging mode.
2108 *
2109 * If this is the upstream port for this switch, enable
2110 * forwarding of unknown unicasts and multicasts.
2111 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002112 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2113 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2114 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2115 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002116 if (err)
2117 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002118
Vivien Didelot601aeed2017-03-11 16:13:00 -05002119 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002120 if (err)
2121 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002122
Vivien Didelot601aeed2017-03-11 16:13:00 -05002123 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002124 if (err)
2125 return err;
2126
Andrew Lunn04aca992017-05-26 01:03:24 +02002127 /* Enable the SERDES interface for DSA and CPU ports. Normal
2128 * ports SERDES are enabled when the port is enabled, thus
2129 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002130 */
Andrew Lunn04aca992017-05-26 01:03:24 +02002131 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
2132 err = mv88e6xxx_serdes_power(chip, port, true);
2133 if (err)
2134 return err;
2135 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002136
Vivien Didelot8efdda42015-08-13 12:52:23 -04002137 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002138 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002139 * untagged frames on this port, do a destination address lookup on all
2140 * received packets as usual, disable ARP mirroring and don't send a
2141 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002142 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002143 err = mv88e6xxx_port_set_map_da(chip, port);
2144 if (err)
2145 return err;
2146
Vivien Didelotfa371c82017-12-05 15:34:10 -05002147 err = mv88e6xxx_setup_upstream_port(chip, port);
2148 if (err)
2149 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002150
Andrew Lunna23b2962017-02-04 20:15:28 +01002151 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002152 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002153 if (err)
2154 return err;
2155
Vivien Didelotcd782652017-06-08 18:34:13 -04002156 if (chip->info->ops->port_set_jumbo_size) {
2157 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002158 if (err)
2159 return err;
2160 }
2161
Andrew Lunn54d792f2015-05-06 01:09:47 +02002162 /* Port Association Vector: when learning source addresses
2163 * of packets, add the address to the address database using
2164 * a port bitmap that has only the bit for this port set and
2165 * the other bits clear.
2166 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002167 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002168 /* Disable learning for CPU port */
2169 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002170 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002171
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002172 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2173 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002174 if (err)
2175 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002176
2177 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002178 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2179 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002180 if (err)
2181 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002182
Vivien Didelot08984322017-06-08 18:34:12 -04002183 if (chip->info->ops->port_pause_limit) {
2184 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002185 if (err)
2186 return err;
2187 }
2188
Vivien Didelotc8c94892017-03-11 16:13:01 -05002189 if (chip->info->ops->port_disable_learn_limit) {
2190 err = chip->info->ops->port_disable_learn_limit(chip, port);
2191 if (err)
2192 return err;
2193 }
2194
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002195 if (chip->info->ops->port_disable_pri_override) {
2196 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002197 if (err)
2198 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002199 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002200
Andrew Lunnef0a7312016-12-03 04:35:16 +01002201 if (chip->info->ops->port_tag_remap) {
2202 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002203 if (err)
2204 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002205 }
2206
Andrew Lunnef70b112016-12-03 04:45:18 +01002207 if (chip->info->ops->port_egress_rate_limiting) {
2208 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002209 if (err)
2210 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002211 }
2212
Vivien Didelotea698f42017-03-11 16:12:50 -05002213 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002214 if (err)
2215 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002216
Vivien Didelot207afda2016-04-14 14:42:09 -04002217 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002218 * database, and allow bidirectional communication between the
2219 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002220 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002221 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002222 if (err)
2223 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002224
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002225 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002226 if (err)
2227 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002228
2229 /* Default VLAN ID and priority: don't set a default VLAN
2230 * ID, and set the default packet priority to zero.
2231 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002232 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002233}
2234
Andrew Lunn04aca992017-05-26 01:03:24 +02002235static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2236 struct phy_device *phydev)
2237{
2238 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002239 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002240
2241 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002242 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002243 mutex_unlock(&chip->reg_lock);
2244
2245 return err;
2246}
2247
2248static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2249 struct phy_device *phydev)
2250{
2251 struct mv88e6xxx_chip *chip = ds->priv;
2252
2253 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002254 if (mv88e6xxx_serdes_power(chip, port, false))
2255 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002256 mutex_unlock(&chip->reg_lock);
2257}
2258
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002259static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2260 unsigned int ageing_time)
2261{
Vivien Didelot04bed142016-08-31 18:06:13 -04002262 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002263 int err;
2264
2265 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002266 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002267 mutex_unlock(&chip->reg_lock);
2268
2269 return err;
2270}
2271
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002272static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002273{
2274 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002275
Andrew Lunnde2273872016-11-21 23:27:01 +01002276 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002277 if (chip->info->ops->stats_set_histogram) {
2278 err = chip->info->ops->stats_set_histogram(chip);
2279 if (err)
2280 return err;
2281 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002282
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002283 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002284}
2285
Vivien Didelotf81ec902016-05-09 13:22:58 -04002286static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002287{
Vivien Didelot04bed142016-08-31 18:06:13 -04002288 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002289 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002290 int i;
2291
Vivien Didelotfad09c72016-06-21 12:28:20 -04002292 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002293 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002294
Vivien Didelotfad09c72016-06-21 12:28:20 -04002295 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002296
Vivien Didelot97299342016-07-18 20:45:30 -04002297 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002298 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002299 if (dsa_is_unused_port(ds, i))
2300 continue;
2301
Vivien Didelot97299342016-07-18 20:45:30 -04002302 err = mv88e6xxx_setup_port(chip, i);
2303 if (err)
2304 goto unlock;
2305 }
2306
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002307 err = mv88e6xxx_irl_setup(chip);
2308 if (err)
2309 goto unlock;
2310
Vivien Didelot04a69a12017-10-13 14:18:05 -04002311 err = mv88e6xxx_mac_setup(chip);
2312 if (err)
2313 goto unlock;
2314
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002315 err = mv88e6xxx_phy_setup(chip);
2316 if (err)
2317 goto unlock;
2318
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002319 err = mv88e6xxx_vtu_setup(chip);
2320 if (err)
2321 goto unlock;
2322
Vivien Didelot81228992017-03-30 17:37:08 -04002323 err = mv88e6xxx_pvt_setup(chip);
2324 if (err)
2325 goto unlock;
2326
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002327 err = mv88e6xxx_atu_setup(chip);
2328 if (err)
2329 goto unlock;
2330
Andrew Lunn87fa8862017-11-09 22:29:56 +01002331 err = mv88e6xxx_broadcast_setup(chip, 0);
2332 if (err)
2333 goto unlock;
2334
Vivien Didelot9e907d72017-07-17 13:03:43 -04002335 err = mv88e6xxx_pot_setup(chip);
2336 if (err)
2337 goto unlock;
2338
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002339 err = mv88e6xxx_rmu_setup(chip);
2340 if (err)
2341 goto unlock;
2342
Vivien Didelot51c901a2017-07-17 13:03:41 -04002343 err = mv88e6xxx_rsvd2cpu_setup(chip);
2344 if (err)
2345 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002346
Vivien Didelotb28f8722018-04-26 21:56:44 -04002347 err = mv88e6xxx_trunk_setup(chip);
2348 if (err)
2349 goto unlock;
2350
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002351 err = mv88e6xxx_devmap_setup(chip);
2352 if (err)
2353 goto unlock;
2354
Vivien Didelot93e18d62018-05-11 17:16:35 -04002355 err = mv88e6xxx_pri_setup(chip);
2356 if (err)
2357 goto unlock;
2358
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002359 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002360 if (chip->info->ptp_support) {
2361 err = mv88e6xxx_ptp_setup(chip);
2362 if (err)
2363 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002364
2365 err = mv88e6xxx_hwtstamp_setup(chip);
2366 if (err)
2367 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002368 }
2369
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002370 err = mv88e6xxx_stats_setup(chip);
2371 if (err)
2372 goto unlock;
2373
Vivien Didelot6b17e862015-08-13 12:52:18 -04002374unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002375 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002376
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002377 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002378}
2379
Vivien Didelote57e5e72016-08-15 17:19:00 -04002380static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002381{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002382 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2383 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002384 u16 val;
2385 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002386
Andrew Lunnee26a222017-01-24 14:53:48 +01002387 if (!chip->info->ops->phy_read)
2388 return -EOPNOTSUPP;
2389
Vivien Didelotfad09c72016-06-21 12:28:20 -04002390 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002391 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002392 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002393
Andrew Lunnda9f3302017-02-01 03:40:05 +01002394 if (reg == MII_PHYSID2) {
2395 /* Some internal PHYS don't have a model number. Use
2396 * the mv88e6390 family model number instead.
2397 */
2398 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002399 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002400 }
2401
Vivien Didelote57e5e72016-08-15 17:19:00 -04002402 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002403}
2404
Vivien Didelote57e5e72016-08-15 17:19:00 -04002405static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002406{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002407 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2408 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002409 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002410
Andrew Lunnee26a222017-01-24 14:53:48 +01002411 if (!chip->info->ops->phy_write)
2412 return -EOPNOTSUPP;
2413
Vivien Didelotfad09c72016-06-21 12:28:20 -04002414 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002415 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002416 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002417
2418 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002419}
2420
Vivien Didelotfad09c72016-06-21 12:28:20 -04002421static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002422 struct device_node *np,
2423 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002424{
2425 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002426 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002427 struct mii_bus *bus;
2428 int err;
2429
Andrew Lunn2510bab2018-02-22 01:51:49 +01002430 if (external) {
2431 mutex_lock(&chip->reg_lock);
2432 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2433 mutex_unlock(&chip->reg_lock);
2434
2435 if (err)
2436 return err;
2437 }
2438
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002439 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002440 if (!bus)
2441 return -ENOMEM;
2442
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002443 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002444 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002445 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002446 INIT_LIST_HEAD(&mdio_bus->list);
2447 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002448
Andrew Lunnb516d452016-06-04 21:17:06 +02002449 if (np) {
2450 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002451 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002452 } else {
2453 bus->name = "mv88e6xxx SMI";
2454 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2455 }
2456
2457 bus->read = mv88e6xxx_mdio_read;
2458 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002459 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002460
Andrew Lunn6f882842018-03-17 20:32:05 +01002461 if (!external) {
2462 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2463 if (err)
2464 return err;
2465 }
2466
Florian Fainelli00e798c2018-05-15 16:56:19 -07002467 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002468 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002469 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002470 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002471 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002472 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002473
2474 if (external)
2475 list_add_tail(&mdio_bus->list, &chip->mdios);
2476 else
2477 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002478
2479 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002480}
2481
Andrew Lunna3c53be52017-01-24 14:53:50 +01002482static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2483 { .compatible = "marvell,mv88e6xxx-mdio-external",
2484 .data = (void *)true },
2485 { },
2486};
2487
Andrew Lunn3126aee2017-12-07 01:05:57 +01002488static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2489
2490{
2491 struct mv88e6xxx_mdio_bus *mdio_bus;
2492 struct mii_bus *bus;
2493
2494 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2495 bus = mdio_bus->bus;
2496
Andrew Lunn6f882842018-03-17 20:32:05 +01002497 if (!mdio_bus->external)
2498 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2499
Andrew Lunn3126aee2017-12-07 01:05:57 +01002500 mdiobus_unregister(bus);
2501 }
2502}
2503
Andrew Lunna3c53be52017-01-24 14:53:50 +01002504static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2505 struct device_node *np)
2506{
2507 const struct of_device_id *match;
2508 struct device_node *child;
2509 int err;
2510
2511 /* Always register one mdio bus for the internal/default mdio
2512 * bus. This maybe represented in the device tree, but is
2513 * optional.
2514 */
2515 child = of_get_child_by_name(np, "mdio");
2516 err = mv88e6xxx_mdio_register(chip, child, false);
2517 if (err)
2518 return err;
2519
2520 /* Walk the device tree, and see if there are any other nodes
2521 * which say they are compatible with the external mdio
2522 * bus.
2523 */
2524 for_each_available_child_of_node(np, child) {
2525 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2526 if (match) {
2527 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002528 if (err) {
2529 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002530 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002531 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002532 }
2533 }
2534
2535 return 0;
2536}
2537
Vivien Didelot855b1932016-07-20 18:18:35 -04002538static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2539{
Vivien Didelot04bed142016-08-31 18:06:13 -04002540 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002541
2542 return chip->eeprom_len;
2543}
2544
Vivien Didelot855b1932016-07-20 18:18:35 -04002545static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2546 struct ethtool_eeprom *eeprom, u8 *data)
2547{
Vivien Didelot04bed142016-08-31 18:06:13 -04002548 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002549 int err;
2550
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002551 if (!chip->info->ops->get_eeprom)
2552 return -EOPNOTSUPP;
2553
Vivien Didelot855b1932016-07-20 18:18:35 -04002554 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002555 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002556 mutex_unlock(&chip->reg_lock);
2557
2558 if (err)
2559 return err;
2560
2561 eeprom->magic = 0xc3ec4951;
2562
2563 return 0;
2564}
2565
Vivien Didelot855b1932016-07-20 18:18:35 -04002566static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2567 struct ethtool_eeprom *eeprom, u8 *data)
2568{
Vivien Didelot04bed142016-08-31 18:06:13 -04002569 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002570 int err;
2571
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002572 if (!chip->info->ops->set_eeprom)
2573 return -EOPNOTSUPP;
2574
Vivien Didelot855b1932016-07-20 18:18:35 -04002575 if (eeprom->magic != 0xc3ec4951)
2576 return -EINVAL;
2577
2578 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002579 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002580 mutex_unlock(&chip->reg_lock);
2581
2582 return err;
2583}
2584
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002585static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002586 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002587 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2588 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002589 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002590 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002591 .phy_read = mv88e6185_phy_ppu_read,
2592 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002593 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002594 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002595 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002596 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002597 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002598 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002599 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002600 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002601 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002602 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002603 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002604 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002605 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002606 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2607 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002608 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002609 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2610 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002611 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002612 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002613 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002614 .ppu_enable = mv88e6185_g1_ppu_enable,
2615 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002616 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002617 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002618 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002619 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behún5bafeb6e2018-05-04 19:26:10 +02002620 .serdes_power = mv88e6341_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002621};
2622
2623static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002624 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002625 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2626 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002627 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002628 .phy_read = mv88e6185_phy_ppu_read,
2629 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002630 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002631 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002632 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002633 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002634 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002635 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002636 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002637 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002638 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2639 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002640 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002641 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002642 .ppu_enable = mv88e6185_g1_ppu_enable,
2643 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002644 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002645 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002646 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002647};
2648
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002649static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002650 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002651 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2652 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002653 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002654 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2655 .phy_read = mv88e6xxx_g2_smi_phy_read,
2656 .phy_write = mv88e6xxx_g2_smi_phy_write,
2657 .port_set_link = mv88e6xxx_port_set_link,
2658 .port_set_duplex = mv88e6xxx_port_set_duplex,
2659 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002660 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002661 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002662 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002663 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002664 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002665 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002666 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002667 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002668 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002669 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002670 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002671 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2672 .stats_get_strings = mv88e6095_stats_get_strings,
2673 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002674 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2675 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002676 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002677 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002678 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002679 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002680 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002681 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002682 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002683};
2684
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002685static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002686 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002687 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2688 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002689 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002690 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002691 .phy_read = mv88e6xxx_g2_smi_phy_read,
2692 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002693 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002694 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002695 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002696 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002697 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002698 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002699 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002700 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002701 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002702 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2703 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002704 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002705 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2706 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002707 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002708 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002709 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002710 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002711 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002712 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002713};
2714
2715static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002716 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002717 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2718 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002719 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002720 .phy_read = mv88e6185_phy_ppu_read,
2721 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002722 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002723 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002724 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002725 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002726 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002727 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002728 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002729 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002730 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002731 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002732 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002733 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002734 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002735 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2736 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002737 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002738 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2739 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002740 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002741 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002742 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04002743 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002744 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002745 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002746 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002747 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002748};
2749
Vivien Didelot990e27b2017-03-28 13:50:32 -04002750static const struct mv88e6xxx_ops mv88e6141_ops = {
2751 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002752 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2753 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002754 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002755 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2756 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2757 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2758 .phy_read = mv88e6xxx_g2_smi_phy_read,
2759 .phy_write = mv88e6xxx_g2_smi_phy_write,
2760 .port_set_link = mv88e6xxx_port_set_link,
2761 .port_set_duplex = mv88e6xxx_port_set_duplex,
2762 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2763 .port_set_speed = mv88e6390_port_set_speed,
2764 .port_tag_remap = mv88e6095_port_tag_remap,
2765 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2766 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2767 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002768 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002769 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002770 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002771 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2772 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2773 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002774 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002775 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2776 .stats_get_strings = mv88e6320_stats_get_strings,
2777 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002778 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2779 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002780 .watchdog_ops = &mv88e6390_watchdog_ops,
2781 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002782 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002783 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002784 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002785 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002786 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002787};
2788
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002789static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002790 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002791 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2792 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002793 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002794 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002795 .phy_read = mv88e6xxx_g2_smi_phy_read,
2796 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002797 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002798 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002799 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002800 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002801 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002802 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002803 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002804 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002805 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002806 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002807 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002808 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002809 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002810 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002811 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2812 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002813 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002814 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2815 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002816 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002817 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002818 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002819 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002820 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002821 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002822};
2823
2824static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002825 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002826 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2827 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002828 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002829 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002830 .phy_read = mv88e6165_phy_read,
2831 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002832 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002833 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002834 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002835 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002836 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002837 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002838 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002839 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2840 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002841 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002842 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2843 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002844 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002845 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002846 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002847 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002848 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002849 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002850};
2851
2852static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002853 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002854 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2855 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002856 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002857 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002858 .phy_read = mv88e6xxx_g2_smi_phy_read,
2859 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002860 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002861 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002862 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002863 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002864 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002865 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002866 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002867 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002868 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002869 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002870 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002871 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002872 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002873 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002874 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002875 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2876 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002877 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002878 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2879 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002880 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002881 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002882 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002883 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002884 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002885 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002886};
2887
2888static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002889 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002890 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2891 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002892 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002893 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2894 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002895 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002896 .phy_read = mv88e6xxx_g2_smi_phy_read,
2897 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002898 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002899 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002900 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002901 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002902 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002903 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002904 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002905 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002906 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002907 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002908 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002909 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002910 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002911 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002912 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002913 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2914 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002915 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002916 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2917 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002918 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002919 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002920 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002921 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002922 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002923 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002924 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002925 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002926 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002927};
2928
2929static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002930 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002931 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2932 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002933 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002934 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002935 .phy_read = mv88e6xxx_g2_smi_phy_read,
2936 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002937 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002938 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002939 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002940 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002941 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002942 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002943 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002944 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002945 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002946 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002947 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002948 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002949 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002950 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002951 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002952 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2953 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002954 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002955 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2956 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002957 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002958 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002959 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002960 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002961 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002962 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behún5bafeb6e2018-05-04 19:26:10 +02002963 .serdes_power = mv88e6341_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002964};
2965
2966static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002967 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002968 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2969 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002970 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002971 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2972 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002973 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002974 .phy_read = mv88e6xxx_g2_smi_phy_read,
2975 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002976 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002977 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002978 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002979 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002980 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002981 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002982 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002983 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002984 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002985 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002986 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002987 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002988 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002989 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002990 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002991 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2992 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002993 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002994 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2995 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002996 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002997 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002998 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002999 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003000 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003001 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003002 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003003 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003004 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003005};
3006
3007static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003008 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003009 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3010 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003011 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003012 .phy_read = mv88e6185_phy_ppu_read,
3013 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003014 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003015 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003016 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003017 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003018 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003019 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003020 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003021 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003022 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003023 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3024 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003025 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003026 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3027 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003028 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003029 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003030 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003031 .ppu_enable = mv88e6185_g1_ppu_enable,
3032 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003033 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003034 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003035 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003036};
3037
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003038static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003039 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003040 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003041 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3042 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003043 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3044 .phy_read = mv88e6xxx_g2_smi_phy_read,
3045 .phy_write = mv88e6xxx_g2_smi_phy_write,
3046 .port_set_link = mv88e6xxx_port_set_link,
3047 .port_set_duplex = mv88e6xxx_port_set_duplex,
3048 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3049 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003050 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003051 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003052 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003053 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003054 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003055 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003056 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003057 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003058 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003059 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3060 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003061 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003062 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3063 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003064 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003065 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003066 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003067 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003068 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003069 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3070 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003071 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003072 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003073};
3074
3075static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003076 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003077 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003078 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3079 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003080 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3081 .phy_read = mv88e6xxx_g2_smi_phy_read,
3082 .phy_write = mv88e6xxx_g2_smi_phy_write,
3083 .port_set_link = mv88e6xxx_port_set_link,
3084 .port_set_duplex = mv88e6xxx_port_set_duplex,
3085 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3086 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003087 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003088 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003089 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003090 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003091 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003092 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003093 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003094 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003095 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003096 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3097 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003098 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003099 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3100 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003101 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003102 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003103 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003104 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003105 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003106 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3107 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003108 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003109 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003110};
3111
3112static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003113 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003114 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003115 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3116 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003117 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3118 .phy_read = mv88e6xxx_g2_smi_phy_read,
3119 .phy_write = mv88e6xxx_g2_smi_phy_write,
3120 .port_set_link = mv88e6xxx_port_set_link,
3121 .port_set_duplex = mv88e6xxx_port_set_duplex,
3122 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3123 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003124 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003125 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003126 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003127 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003128 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003129 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003130 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003131 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003132 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003133 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3134 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003135 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003136 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3137 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003138 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003139 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003140 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003141 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003142 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003143 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3144 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003145 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003146};
3147
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003148static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003149 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003150 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3151 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003152 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003153 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3154 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003155 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003156 .phy_read = mv88e6xxx_g2_smi_phy_read,
3157 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003158 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003159 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003160 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003161 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003162 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003163 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003164 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003165 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003166 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003167 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003168 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003169 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003170 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003171 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003172 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003173 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3174 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003175 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003176 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3177 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003178 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003179 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003180 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003181 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003182 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003183 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003184 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003185 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003186 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003187 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003188};
3189
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003190static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003191 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003192 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003193 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3194 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003195 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3196 .phy_read = mv88e6xxx_g2_smi_phy_read,
3197 .phy_write = mv88e6xxx_g2_smi_phy_write,
3198 .port_set_link = mv88e6xxx_port_set_link,
3199 .port_set_duplex = mv88e6xxx_port_set_duplex,
3200 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3201 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003202 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003203 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003204 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003205 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003206 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003207 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003208 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003209 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003210 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003211 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003212 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3213 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003214 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003215 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3216 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003217 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003218 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003219 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003220 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003221 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003222 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3223 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003224 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003225 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003226 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003227};
3228
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003229static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003230 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003231 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3232 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003233 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003234 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3235 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003236 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003237 .phy_read = mv88e6xxx_g2_smi_phy_read,
3238 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003239 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003240 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003241 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003242 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003243 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003244 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003245 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003246 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003247 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003248 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003249 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003250 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003251 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003252 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003253 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3254 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003255 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003256 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3257 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003258 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003259 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003260 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003261 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003262 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003263 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003264 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003265};
3266
3267static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003268 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003269 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3270 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003271 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003272 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3273 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003274 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003275 .phy_read = mv88e6xxx_g2_smi_phy_read,
3276 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003277 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003278 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003279 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003280 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003281 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003282 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003283 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003284 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003285 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003286 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003287 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003288 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003289 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003290 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003291 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3292 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003293 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003294 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3295 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003296 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003297 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003298 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003299 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003300 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003301};
3302
Vivien Didelot16e329a2017-03-28 13:50:33 -04003303static const struct mv88e6xxx_ops mv88e6341_ops = {
3304 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003305 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3306 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003307 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003308 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3309 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3310 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3311 .phy_read = mv88e6xxx_g2_smi_phy_read,
3312 .phy_write = mv88e6xxx_g2_smi_phy_write,
3313 .port_set_link = mv88e6xxx_port_set_link,
3314 .port_set_duplex = mv88e6xxx_port_set_duplex,
3315 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3316 .port_set_speed = mv88e6390_port_set_speed,
3317 .port_tag_remap = mv88e6095_port_tag_remap,
3318 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3319 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3320 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003321 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003322 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003323 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003324 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3325 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3326 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003327 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003328 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3329 .stats_get_strings = mv88e6320_stats_get_strings,
3330 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003331 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3332 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003333 .watchdog_ops = &mv88e6390_watchdog_ops,
3334 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003335 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003336 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003337 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003338 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003339 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003340 .avb_ops = &mv88e6390_avb_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003341};
3342
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003343static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003344 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003345 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3346 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003347 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003348 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003349 .phy_read = mv88e6xxx_g2_smi_phy_read,
3350 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003351 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003352 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003353 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003354 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003355 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003356 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003357 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003358 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003359 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003360 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003361 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003362 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003363 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003364 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003365 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003366 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3367 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003368 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003369 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3370 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003371 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003372 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003373 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003374 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003375 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003376 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003377};
3378
3379static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003380 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003381 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3382 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003383 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003384 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003385 .phy_read = mv88e6xxx_g2_smi_phy_read,
3386 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003387 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003388 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003389 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003390 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003391 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003392 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003393 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003394 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003395 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003396 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003397 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003398 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003399 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003400 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003401 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003402 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3403 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003404 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003405 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3406 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003407 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003408 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003409 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003410 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003411 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003412 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003413 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003414};
3415
3416static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003417 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003418 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3419 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003420 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003421 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3422 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003423 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003424 .phy_read = mv88e6xxx_g2_smi_phy_read,
3425 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003426 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003427 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003428 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003429 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003430 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003431 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003432 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003433 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003434 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003435 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003436 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003437 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003438 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003439 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003440 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003441 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3442 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003443 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003444 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3445 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003446 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003447 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003448 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003449 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003450 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003451 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003452 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003453 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003454 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003455 .avb_ops = &mv88e6352_avb_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 Lunn1a3b39e2016-11-21 23:26:57 +01003500};
3501
3502static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003503 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003504 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003505 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3506 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003507 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3508 .phy_read = mv88e6xxx_g2_smi_phy_read,
3509 .phy_write = mv88e6xxx_g2_smi_phy_write,
3510 .port_set_link = mv88e6xxx_port_set_link,
3511 .port_set_duplex = mv88e6xxx_port_set_duplex,
3512 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3513 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003514 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003515 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003516 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003517 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003518 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003519 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003520 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003521 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003522 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003523 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003524 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003525 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003526 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3527 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003528 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003529 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3530 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003531 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003532 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003533 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003534 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003535 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003536 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3537 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003538 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003539 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003540 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003541};
3542
Vivien Didelotf81ec902016-05-09 13:22:58 -04003543static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3544 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003545 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003546 .family = MV88E6XXX_FAMILY_6097,
3547 .name = "Marvell 88E6085",
3548 .num_databases = 4096,
3549 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003550 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003551 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003552 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003553 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003554 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003555 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003556 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003557 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003558 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003559 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003560 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003561 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003562 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003563 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003564 },
3565
3566 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003567 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003568 .family = MV88E6XXX_FAMILY_6095,
3569 .name = "Marvell 88E6095/88E6095F",
3570 .num_databases = 256,
3571 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003572 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003573 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003574 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003575 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003576 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003577 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003578 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003579 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003580 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003581 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003582 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003583 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003584 },
3585
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003586 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003587 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003588 .family = MV88E6XXX_FAMILY_6097,
3589 .name = "Marvell 88E6097/88E6097F",
3590 .num_databases = 4096,
3591 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003592 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003593 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003594 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003595 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003596 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003597 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003598 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003599 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003600 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003601 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003602 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003603 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003604 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003605 .ops = &mv88e6097_ops,
3606 },
3607
Vivien Didelotf81ec902016-05-09 13:22:58 -04003608 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003609 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003610 .family = MV88E6XXX_FAMILY_6165,
3611 .name = "Marvell 88E6123",
3612 .num_databases = 4096,
3613 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01003614 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003615 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003616 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003617 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003618 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003619 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003620 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003621 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003622 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003623 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003624 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003625 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003626 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003627 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003628 },
3629
3630 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003631 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003632 .family = MV88E6XXX_FAMILY_6185,
3633 .name = "Marvell 88E6131",
3634 .num_databases = 256,
3635 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003636 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003637 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003638 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003639 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003640 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003641 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003642 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003643 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003644 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003645 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003646 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003647 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003648 },
3649
Vivien Didelot990e27b2017-03-28 13:50:32 -04003650 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003651 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003652 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01003653 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04003654 .num_databases = 4096,
3655 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003656 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003657 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003658 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003659 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003660 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003661 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003662 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003663 .age_time_coeff = 3750,
3664 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003665 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003666 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003667 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003668 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003669 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003670 .ops = &mv88e6141_ops,
3671 },
3672
Vivien Didelotf81ec902016-05-09 13:22:58 -04003673 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003674 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003675 .family = MV88E6XXX_FAMILY_6165,
3676 .name = "Marvell 88E6161",
3677 .num_databases = 4096,
3678 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003679 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003680 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003681 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003682 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003683 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003684 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003685 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003686 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003687 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003688 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003689 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003690 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003691 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003692 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003693 },
3694
3695 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003696 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003697 .family = MV88E6XXX_FAMILY_6165,
3698 .name = "Marvell 88E6165",
3699 .num_databases = 4096,
3700 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003701 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003702 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003703 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003704 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003705 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003706 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003707 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003708 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003709 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003710 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003711 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003712 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003713 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003714 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003715 },
3716
3717 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003718 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003719 .family = MV88E6XXX_FAMILY_6351,
3720 .name = "Marvell 88E6171",
3721 .num_databases = 4096,
3722 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003723 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003724 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003725 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003726 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003727 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003728 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003729 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003730 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003731 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003732 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003733 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003734 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003735 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003736 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003737 },
3738
3739 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003740 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003741 .family = MV88E6XXX_FAMILY_6352,
3742 .name = "Marvell 88E6172",
3743 .num_databases = 4096,
3744 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003745 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003746 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003747 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003748 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003749 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003750 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003751 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003752 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003753 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003754 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003755 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003756 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003757 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003758 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003759 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003760 },
3761
3762 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003763 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003764 .family = MV88E6XXX_FAMILY_6351,
3765 .name = "Marvell 88E6175",
3766 .num_databases = 4096,
3767 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003768 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003769 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003770 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003771 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003772 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003773 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003774 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003775 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003776 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003777 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003778 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003779 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003780 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003781 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003782 },
3783
3784 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003785 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003786 .family = MV88E6XXX_FAMILY_6352,
3787 .name = "Marvell 88E6176",
3788 .num_databases = 4096,
3789 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003790 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003791 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003792 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003793 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003794 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003795 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003796 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003797 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003798 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003799 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003800 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003801 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003802 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003803 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003804 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003805 },
3806
3807 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003808 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003809 .family = MV88E6XXX_FAMILY_6185,
3810 .name = "Marvell 88E6185",
3811 .num_databases = 256,
3812 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003813 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003814 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003815 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003816 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003817 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003818 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003819 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003820 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003821 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003822 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003823 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003824 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003825 },
3826
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003827 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003828 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003829 .family = MV88E6XXX_FAMILY_6390,
3830 .name = "Marvell 88E6190",
3831 .num_databases = 4096,
3832 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003833 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003834 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003835 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003836 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003837 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003838 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003839 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003840 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003841 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003842 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003843 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003844 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003845 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003846 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003847 .ops = &mv88e6190_ops,
3848 },
3849
3850 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003851 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003852 .family = MV88E6XXX_FAMILY_6390,
3853 .name = "Marvell 88E6190X",
3854 .num_databases = 4096,
3855 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003856 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003857 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003858 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003859 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003860 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003861 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003862 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003863 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003864 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003865 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003866 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003867 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003868 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003869 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003870 .ops = &mv88e6190x_ops,
3871 },
3872
3873 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003874 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003875 .family = MV88E6XXX_FAMILY_6390,
3876 .name = "Marvell 88E6191",
3877 .num_databases = 4096,
3878 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003879 .num_internal_phys = 11,
Vivien Didelot931d1822017-05-01 14:05:27 -04003880 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003881 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003882 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003883 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003884 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003885 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003886 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003887 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003888 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003889 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003890 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003891 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003892 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003893 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003894 },
3895
Vivien Didelotf81ec902016-05-09 13:22:58 -04003896 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003897 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003898 .family = MV88E6XXX_FAMILY_6352,
3899 .name = "Marvell 88E6240",
3900 .num_databases = 4096,
3901 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003902 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003903 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003904 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003905 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003906 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003907 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003908 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003909 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003910 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003911 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003912 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003913 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003914 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003915 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003916 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003917 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003918 },
3919
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003920 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003921 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003922 .family = MV88E6XXX_FAMILY_6390,
3923 .name = "Marvell 88E6290",
3924 .num_databases = 4096,
3925 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003926 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003927 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003928 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003929 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003930 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003931 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003932 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003933 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003934 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003935 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003936 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003937 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003938 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003939 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003940 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003941 .ops = &mv88e6290_ops,
3942 },
3943
Vivien Didelotf81ec902016-05-09 13:22:58 -04003944 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003945 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003946 .family = MV88E6XXX_FAMILY_6320,
3947 .name = "Marvell 88E6320",
3948 .num_databases = 4096,
3949 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003950 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003951 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003952 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003953 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003954 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003955 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003956 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003957 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003958 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003959 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003960 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003961 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003962 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003963 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003964 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003965 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003966 },
3967
3968 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003969 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003970 .family = MV88E6XXX_FAMILY_6320,
3971 .name = "Marvell 88E6321",
3972 .num_databases = 4096,
3973 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003974 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003975 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003976 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003977 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003978 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003979 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003980 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003981 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003982 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003983 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003984 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003985 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003986 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003987 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003988 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003989 },
3990
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003991 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003992 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003993 .family = MV88E6XXX_FAMILY_6341,
3994 .name = "Marvell 88E6341",
3995 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01003996 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003997 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003998 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003999 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004000 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004001 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004002 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004003 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004004 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05004005 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004006 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004007 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004008 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004009 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004010 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004011 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004012 .ops = &mv88e6341_ops,
4013 },
4014
Vivien Didelotf81ec902016-05-09 13:22:58 -04004015 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004016 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004017 .family = MV88E6XXX_FAMILY_6351,
4018 .name = "Marvell 88E6350",
4019 .num_databases = 4096,
4020 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004021 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004022 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004023 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004024 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004025 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004026 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004027 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004028 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004029 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004030 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004031 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004032 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004033 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004034 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004035 },
4036
4037 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004038 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004039 .family = MV88E6XXX_FAMILY_6351,
4040 .name = "Marvell 88E6351",
4041 .num_databases = 4096,
4042 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004043 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004044 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004045 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004046 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004047 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004048 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004049 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004050 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004051 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004052 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004053 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004054 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004055 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004056 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004057 },
4058
4059 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004060 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004061 .family = MV88E6XXX_FAMILY_6352,
4062 .name = "Marvell 88E6352",
4063 .num_databases = 4096,
4064 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004065 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004066 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004067 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004068 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004069 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004070 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004071 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004072 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004073 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004074 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004075 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004076 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004077 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004078 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004079 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004080 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004081 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004082 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004083 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004084 .family = MV88E6XXX_FAMILY_6390,
4085 .name = "Marvell 88E6390",
4086 .num_databases = 4096,
4087 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01004088 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004089 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004090 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004091 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004092 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004093 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004094 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004095 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004096 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004097 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004098 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004099 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004100 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004101 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004102 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004103 .ops = &mv88e6390_ops,
4104 },
4105 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004106 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004107 .family = MV88E6XXX_FAMILY_6390,
4108 .name = "Marvell 88E6390X",
4109 .num_databases = 4096,
4110 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01004111 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004112 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004113 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004114 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004115 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004116 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004117 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004118 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004119 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004120 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004121 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004122 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004123 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004124 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004125 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004126 .ops = &mv88e6390x_ops,
4127 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004128};
4129
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004130static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004131{
Vivien Didelota439c062016-04-17 13:23:58 -04004132 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004133
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004134 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4135 if (mv88e6xxx_table[i].prod_num == prod_num)
4136 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004137
Vivien Didelotb9b37712015-10-30 19:39:48 -04004138 return NULL;
4139}
4140
Vivien Didelotfad09c72016-06-21 12:28:20 -04004141static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004142{
4143 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004144 unsigned int prod_num, rev;
4145 u16 id;
4146 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004147
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004148 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04004149 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004150 mutex_unlock(&chip->reg_lock);
4151 if (err)
4152 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004153
Vivien Didelot107fcc12017-06-12 12:37:36 -04004154 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
4155 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004156
4157 info = mv88e6xxx_lookup_info(prod_num);
4158 if (!info)
4159 return -ENODEV;
4160
Vivien Didelotcaac8542016-06-20 13:14:09 -04004161 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004162 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004163
Vivien Didelotca070c12016-09-02 14:45:34 -04004164 err = mv88e6xxx_g2_require(chip);
4165 if (err)
4166 return err;
4167
Vivien Didelotfad09c72016-06-21 12:28:20 -04004168 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4169 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004170
4171 return 0;
4172}
4173
Vivien Didelotfad09c72016-06-21 12:28:20 -04004174static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004175{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004176 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004177
Vivien Didelotfad09c72016-06-21 12:28:20 -04004178 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4179 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004180 return NULL;
4181
Vivien Didelotfad09c72016-06-21 12:28:20 -04004182 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004183
Vivien Didelotfad09c72016-06-21 12:28:20 -04004184 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004185 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004186
Vivien Didelotfad09c72016-06-21 12:28:20 -04004187 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004188}
4189
Vivien Didelotfad09c72016-06-21 12:28:20 -04004190static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004191 struct mii_bus *bus, int sw_addr)
4192{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004193 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004194 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004195 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004196 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004197 else
4198 return -EINVAL;
4199
Vivien Didelotfad09c72016-06-21 12:28:20 -04004200 chip->bus = bus;
4201 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004202
4203 return 0;
4204}
4205
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08004206static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4207 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02004208{
Vivien Didelot04bed142016-08-31 18:06:13 -04004209 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004210
Andrew Lunn443d5a12016-12-03 04:35:18 +01004211 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004212}
4213
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004214#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004215static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4216 struct device *host_dev, int sw_addr,
4217 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004218{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004219 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004220 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004221 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004222
Vivien Didelota439c062016-04-17 13:23:58 -04004223 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004224 if (!bus)
4225 return NULL;
4226
Vivien Didelotfad09c72016-06-21 12:28:20 -04004227 chip = mv88e6xxx_alloc_chip(dsa_dev);
4228 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004229 return NULL;
4230
Vivien Didelotcaac8542016-06-20 13:14:09 -04004231 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004232 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004233
Vivien Didelotfad09c72016-06-21 12:28:20 -04004234 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004235 if (err)
4236 goto free;
4237
Vivien Didelotfad09c72016-06-21 12:28:20 -04004238 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004239 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004240 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004241
Andrew Lunndc30c352016-10-16 19:56:49 +02004242 mutex_lock(&chip->reg_lock);
4243 err = mv88e6xxx_switch_reset(chip);
4244 mutex_unlock(&chip->reg_lock);
4245 if (err)
4246 goto free;
4247
Vivien Didelote57e5e72016-08-15 17:19:00 -04004248 mv88e6xxx_phy_init(chip);
4249
Andrew Lunna3c53be52017-01-24 14:53:50 +01004250 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004251 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004252 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004253
Vivien Didelotfad09c72016-06-21 12:28:20 -04004254 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004255
Vivien Didelotfad09c72016-06-21 12:28:20 -04004256 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004257free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004258 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004259
4260 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004261}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004262#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02004263
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004264static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004265 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004266{
4267 /* We don't need any dynamic resource from the kernel (yet),
4268 * so skip the prepare phase.
4269 */
4270
4271 return 0;
4272}
4273
4274static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004275 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004276{
Vivien Didelot04bed142016-08-31 18:06:13 -04004277 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004278
4279 mutex_lock(&chip->reg_lock);
4280 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004281 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004282 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4283 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004284 mutex_unlock(&chip->reg_lock);
4285}
4286
4287static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4288 const struct switchdev_obj_port_mdb *mdb)
4289{
Vivien Didelot04bed142016-08-31 18:06:13 -04004290 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004291 int err;
4292
4293 mutex_lock(&chip->reg_lock);
4294 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004295 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004296 mutex_unlock(&chip->reg_lock);
4297
4298 return err;
4299}
4300
Florian Fainellia82f67a2017-01-08 14:52:08 -08004301static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004302#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004303 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004304#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02004305 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004306 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004307 .adjust_link = mv88e6xxx_adjust_link,
Russell Kingc9a23562018-05-10 13:17:35 -07004308 .phylink_validate = mv88e6xxx_validate,
4309 .phylink_mac_link_state = mv88e6xxx_link_state,
4310 .phylink_mac_config = mv88e6xxx_mac_config,
4311 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
4312 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004313 .get_strings = mv88e6xxx_get_strings,
4314 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4315 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004316 .port_enable = mv88e6xxx_port_enable,
4317 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004318 .get_mac_eee = mv88e6xxx_get_mac_eee,
4319 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004320 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004321 .get_eeprom = mv88e6xxx_get_eeprom,
4322 .set_eeprom = mv88e6xxx_set_eeprom,
4323 .get_regs_len = mv88e6xxx_get_regs_len,
4324 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004325 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004326 .port_bridge_join = mv88e6xxx_port_bridge_join,
4327 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4328 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004329 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004330 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4331 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4332 .port_vlan_add = mv88e6xxx_port_vlan_add,
4333 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004334 .port_fdb_add = mv88e6xxx_port_fdb_add,
4335 .port_fdb_del = mv88e6xxx_port_fdb_del,
4336 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004337 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4338 .port_mdb_add = mv88e6xxx_port_mdb_add,
4339 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004340 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4341 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004342 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4343 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4344 .port_txtstamp = mv88e6xxx_port_txtstamp,
4345 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4346 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004347};
4348
Florian Fainelliab3d4082017-01-08 14:52:07 -08004349static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4350 .ops = &mv88e6xxx_switch_ops,
4351};
4352
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004353static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004354{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004355 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004356 struct dsa_switch *ds;
4357
Vivien Didelot73b12042017-03-30 17:37:10 -04004358 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004359 if (!ds)
4360 return -ENOMEM;
4361
Vivien Didelotfad09c72016-06-21 12:28:20 -04004362 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004363 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004364 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004365 ds->ageing_time_min = chip->info->age_time_coeff;
4366 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004367
4368 dev_set_drvdata(dev, ds);
4369
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004370 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004371}
4372
Vivien Didelotfad09c72016-06-21 12:28:20 -04004373static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004374{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004375 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004376}
4377
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004378static const void *pdata_device_get_match_data(struct device *dev)
4379{
4380 const struct of_device_id *matches = dev->driver->of_match_table;
4381 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
4382
4383 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
4384 matches++) {
4385 if (!strcmp(pdata->compatible, matches->compatible))
4386 return matches->data;
4387 }
4388 return NULL;
4389}
4390
Vivien Didelot57d32312016-06-20 13:13:58 -04004391static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004392{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004393 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04004394 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004395 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004396 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004397 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004398 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02004399 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004400
Andrew Lunn7bb8c992018-05-31 00:15:42 +02004401 if (!np && !pdata)
4402 return -EINVAL;
4403
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004404 if (np)
4405 compat_info = of_device_get_match_data(dev);
4406
4407 if (pdata) {
4408 compat_info = pdata_device_get_match_data(dev);
4409
4410 if (!pdata->netdev)
4411 return -EINVAL;
4412
4413 for (port = 0; port < DSA_MAX_PORTS; port++) {
4414 if (!(pdata->enabled_ports & (1 << port)))
4415 continue;
4416 if (strcmp(pdata->cd.port_names[port], "cpu"))
4417 continue;
4418 pdata->cd.netdev[port] = &pdata->netdev->dev;
4419 break;
4420 }
4421 }
4422
Vivien Didelotcaac8542016-06-20 13:14:09 -04004423 if (!compat_info)
4424 return -EINVAL;
4425
Vivien Didelotfad09c72016-06-21 12:28:20 -04004426 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004427 if (!chip) {
4428 err = -ENOMEM;
4429 goto out;
4430 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004431
Vivien Didelotfad09c72016-06-21 12:28:20 -04004432 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004433
Vivien Didelotfad09c72016-06-21 12:28:20 -04004434 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004435 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004436 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004437
Andrew Lunnb4308f02016-11-21 23:26:55 +01004438 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004439 if (IS_ERR(chip->reset)) {
4440 err = PTR_ERR(chip->reset);
4441 goto out;
4442 }
Andrew Lunnb4308f02016-11-21 23:26:55 +01004443
Vivien Didelotfad09c72016-06-21 12:28:20 -04004444 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004445 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004446 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004447
Vivien Didelote57e5e72016-08-15 17:19:00 -04004448 mv88e6xxx_phy_init(chip);
4449
Andrew Lunn00baabe2018-05-19 22:31:35 +02004450 if (chip->info->ops->get_eeprom) {
4451 if (np)
4452 of_property_read_u32(np, "eeprom-length",
4453 &chip->eeprom_len);
4454 else
4455 chip->eeprom_len = pdata->eeprom_len;
4456 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004457
Andrew Lunndc30c352016-10-16 19:56:49 +02004458 mutex_lock(&chip->reg_lock);
4459 err = mv88e6xxx_switch_reset(chip);
4460 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004461 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004462 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004463
Andrew Lunndc30c352016-10-16 19:56:49 +02004464 chip->irq = of_irq_get(np, 0);
4465 if (chip->irq == -EPROBE_DEFER) {
4466 err = chip->irq;
4467 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004468 }
4469
Andrew Lunn294d7112018-02-22 22:58:32 +01004470 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01004471 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01004472 * controllers
4473 */
4474 mutex_lock(&chip->reg_lock);
4475 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004476 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004477 else
4478 err = mv88e6xxx_irq_poll_setup(chip);
4479 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004480
Andrew Lunn294d7112018-02-22 22:58:32 +01004481 if (err)
4482 goto out;
4483
4484 if (chip->info->g2_irqs > 0) {
4485 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004486 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004487 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004488 }
4489
Andrew Lunn294d7112018-02-22 22:58:32 +01004490 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4491 if (err)
4492 goto out_g2_irq;
4493
4494 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4495 if (err)
4496 goto out_g1_atu_prob_irq;
4497
Andrew Lunna3c53be52017-01-24 14:53:50 +01004498 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004499 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004500 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004501
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004502 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004503 if (err)
4504 goto out_mdio;
4505
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004506 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004507
4508out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004509 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004510out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004511 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004512out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004513 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004514out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004515 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004516 mv88e6xxx_g2_irq_free(chip);
4517out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004518 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004519 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004520 else
4521 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004522out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004523 if (pdata)
4524 dev_put(pdata->netdev);
4525
Andrew Lunndc30c352016-10-16 19:56:49 +02004526 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004527}
4528
4529static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4530{
4531 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004532 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004533
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004534 if (chip->info->ptp_support) {
4535 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004536 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004537 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004538
Andrew Lunn930188c2016-08-22 16:01:03 +02004539 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004540 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004541 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004542
Andrew Lunn76f38f12018-03-17 20:21:09 +01004543 mv88e6xxx_g1_vtu_prob_irq_free(chip);
4544 mv88e6xxx_g1_atu_prob_irq_free(chip);
4545
4546 if (chip->info->g2_irqs > 0)
4547 mv88e6xxx_g2_irq_free(chip);
4548
Andrew Lunn76f38f12018-03-17 20:21:09 +01004549 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004550 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01004551 else
4552 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004553}
4554
4555static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004556 {
4557 .compatible = "marvell,mv88e6085",
4558 .data = &mv88e6xxx_table[MV88E6085],
4559 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004560 {
4561 .compatible = "marvell,mv88e6190",
4562 .data = &mv88e6xxx_table[MV88E6190],
4563 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004564 { /* sentinel */ },
4565};
4566
4567MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4568
4569static struct mdio_driver mv88e6xxx_driver = {
4570 .probe = mv88e6xxx_probe,
4571 .remove = mv88e6xxx_remove,
4572 .mdiodrv.driver = {
4573 .name = "mv88e6085",
4574 .of_match_table = mv88e6xxx_of_match,
4575 },
4576};
4577
Ben Hutchings98e67302011-11-25 14:36:19 +00004578static int __init mv88e6xxx_init(void)
4579{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004580 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004581 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004582}
4583module_init(mv88e6xxx_init);
4584
4585static void __exit mv88e6xxx_cleanup(void)
4586{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004587 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004588 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004589}
4590module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004591
4592MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4593MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4594MODULE_LICENSE("GPL");