blob: f7522d001365423a6d3d32cc60cd23cb0fbc6de7 [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,
Andrew Lunn54186b92018-08-09 15:38:37 +0200527 int link, int speed, int duplex, int pause,
Vivien Didelotd78343d2016-11-04 03:23:36 +0100528 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
Andrew Lunn54186b92018-08-09 15:38:37 +0200546 if (chip->info->ops->port_set_pause) {
547 err = chip->info->ops->port_set_pause(chip, port, pause);
548 if (err)
549 goto restore_link;
550 }
551
Vivien Didelotd78343d2016-11-04 03:23:36 +0100552 if (chip->info->ops->port_set_duplex) {
553 err = chip->info->ops->port_set_duplex(chip, port, duplex);
554 if (err && err != -EOPNOTSUPP)
555 goto restore_link;
556 }
557
558 if (chip->info->ops->port_set_rgmii_delay) {
559 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
560 if (err && err != -EOPNOTSUPP)
561 goto restore_link;
562 }
563
Andrew Lunnf39908d2017-02-04 20:02:50 +0100564 if (chip->info->ops->port_set_cmode) {
565 err = chip->info->ops->port_set_cmode(chip, port, mode);
566 if (err && err != -EOPNOTSUPP)
567 goto restore_link;
568 }
569
Vivien Didelotd78343d2016-11-04 03:23:36 +0100570 err = 0;
571restore_link:
572 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400573 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100574
575 return err;
576}
577
Andrew Lunndea87022015-08-31 15:56:47 +0200578/* We expect the switch to perform auto negotiation if there is a real
579 * phy. However, in the case of a fixed link phy, we force the port
580 * settings from the fixed link settings.
581 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400582static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
583 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200584{
Vivien Didelot04bed142016-08-31 18:06:13 -0400585 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200586 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200587
588 if (!phy_is_pseudo_fixed_link(phydev))
589 return;
590
Vivien Didelotfad09c72016-06-21 12:28:20 -0400591 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100592 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
Andrew Lunn54186b92018-08-09 15:38:37 +0200593 phydev->duplex, phydev->pause,
594 phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400595 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100596
597 if (err && err != -EOPNOTSUPP)
Vivien Didelot774439e52017-06-08 18:34:08 -0400598 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
Andrew Lunndea87022015-08-31 15:56:47 +0200599}
600
Russell Kingc9a23562018-05-10 13:17:35 -0700601static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
602 unsigned long *supported,
603 struct phylink_link_state *state)
604{
605}
606
607static int mv88e6xxx_link_state(struct dsa_switch *ds, int port,
608 struct phylink_link_state *state)
609{
610 struct mv88e6xxx_chip *chip = ds->priv;
611 int err;
612
613 mutex_lock(&chip->reg_lock);
614 err = mv88e6xxx_port_link_state(chip, port, state);
615 mutex_unlock(&chip->reg_lock);
616
617 return err;
618}
619
620static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
621 unsigned int mode,
622 const struct phylink_link_state *state)
623{
624 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn54186b92018-08-09 15:38:37 +0200625 int speed, duplex, link, pause, err;
Russell Kingc9a23562018-05-10 13:17:35 -0700626
627 if (mode == MLO_AN_PHY)
628 return;
629
630 if (mode == MLO_AN_FIXED) {
631 link = LINK_FORCED_UP;
632 speed = state->speed;
633 duplex = state->duplex;
634 } else {
635 speed = SPEED_UNFORCED;
636 duplex = DUPLEX_UNFORCED;
637 link = LINK_UNFORCED;
638 }
Andrew Lunn54186b92018-08-09 15:38:37 +0200639 pause = !!phylink_test(state->advertising, Pause);
Russell Kingc9a23562018-05-10 13:17:35 -0700640
641 mutex_lock(&chip->reg_lock);
Andrew Lunn54186b92018-08-09 15:38:37 +0200642 err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
Russell Kingc9a23562018-05-10 13:17:35 -0700643 state->interface);
644 mutex_unlock(&chip->reg_lock);
645
646 if (err && err != -EOPNOTSUPP)
647 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
648}
649
650static void mv88e6xxx_mac_link_force(struct dsa_switch *ds, int port, int link)
651{
652 struct mv88e6xxx_chip *chip = ds->priv;
653 int err;
654
655 mutex_lock(&chip->reg_lock);
656 err = chip->info->ops->port_set_link(chip, port, link);
657 mutex_unlock(&chip->reg_lock);
658
659 if (err)
660 dev_err(chip->dev, "p%d: failed to force MAC link\n", port);
661}
662
663static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
664 unsigned int mode,
665 phy_interface_t interface)
666{
667 if (mode == MLO_AN_FIXED)
668 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_DOWN);
669}
670
671static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
672 unsigned int mode, phy_interface_t interface,
673 struct phy_device *phydev)
674{
675 if (mode == MLO_AN_FIXED)
676 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_UP);
677}
678
Andrew Lunna605a0f2016-11-21 23:26:58 +0100679static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000680{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100681 if (!chip->info->ops->stats_snapshot)
682 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000683
Andrew Lunna605a0f2016-11-21 23:26:58 +0100684 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000685}
686
Andrew Lunne413e7e2015-04-02 04:06:38 +0200687static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100688 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
689 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
690 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
691 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
692 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
693 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
694 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
695 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
696 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
697 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
698 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
699 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
700 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
701 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
702 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
703 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
704 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
705 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
706 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
707 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
708 { "single", 4, 0x14, STATS_TYPE_BANK0, },
709 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
710 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
711 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
712 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
713 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
714 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
715 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
716 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
717 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
718 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
719 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
720 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
721 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
722 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
723 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
724 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
725 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
726 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
727 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
728 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
729 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
730 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
731 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
732 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
733 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
734 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
735 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
736 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
737 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
738 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
739 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
740 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
741 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
742 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
743 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
744 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
745 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
746 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200747};
748
Vivien Didelotfad09c72016-06-21 12:28:20 -0400749static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100750 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100751 int port, u16 bank1_select,
752 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200753{
Andrew Lunn80c46272015-06-20 18:42:30 +0200754 u32 low;
755 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100756 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200757 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200758 u64 value;
759
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100760 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100761 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200762 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
763 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800764 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200765
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200766 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100767 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200768 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
769 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800770 return U64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200771 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200772 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100773 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100774 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100775 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100776 /* fall through */
777 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100778 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100779 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100780 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100781 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500782 break;
783 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800784 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200785 }
786 value = (((u64)high) << 16) | low;
787 return value;
788}
789
Andrew Lunn436fe172018-03-01 02:02:29 +0100790static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
791 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100792{
793 struct mv88e6xxx_hw_stat *stat;
794 int i, j;
795
796 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
797 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100798 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100799 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
800 ETH_GSTRING_LEN);
801 j++;
802 }
803 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100804
805 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100806}
807
Andrew Lunn436fe172018-03-01 02:02:29 +0100808static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
809 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100810{
Andrew Lunn436fe172018-03-01 02:02:29 +0100811 return mv88e6xxx_stats_get_strings(chip, data,
812 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100813}
814
Andrew Lunn436fe172018-03-01 02:02:29 +0100815static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
816 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100817{
Andrew Lunn436fe172018-03-01 02:02:29 +0100818 return mv88e6xxx_stats_get_strings(chip, data,
819 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100820}
821
Andrew Lunn65f60e42018-03-28 23:50:28 +0200822static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
823 "atu_member_violation",
824 "atu_miss_violation",
825 "atu_full_violation",
826 "vtu_member_violation",
827 "vtu_miss_violation",
828};
829
830static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
831{
832 unsigned int i;
833
834 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
835 strlcpy(data + i * ETH_GSTRING_LEN,
836 mv88e6xxx_atu_vtu_stats_strings[i],
837 ETH_GSTRING_LEN);
838}
839
Andrew Lunndfafe442016-11-21 23:27:02 +0100840static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700841 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100842{
Vivien Didelot04bed142016-08-31 18:06:13 -0400843 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100844 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100845
Florian Fainelli89f09042018-04-25 12:12:50 -0700846 if (stringset != ETH_SS_STATS)
847 return;
848
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100849 mutex_lock(&chip->reg_lock);
850
Andrew Lunndfafe442016-11-21 23:27:02 +0100851 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100852 count = chip->info->ops->stats_get_strings(chip, data);
853
854 if (chip->info->ops->serdes_get_strings) {
855 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200856 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100857 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100858
Andrew Lunn65f60e42018-03-28 23:50:28 +0200859 data += count * ETH_GSTRING_LEN;
860 mv88e6xxx_atu_vtu_get_strings(data);
861
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100862 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100863}
864
865static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
866 int types)
867{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100868 struct mv88e6xxx_hw_stat *stat;
869 int i, j;
870
871 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
872 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100873 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100874 j++;
875 }
876 return j;
877}
878
Andrew Lunndfafe442016-11-21 23:27:02 +0100879static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
880{
881 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
882 STATS_TYPE_PORT);
883}
884
885static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
886{
887 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
888 STATS_TYPE_BANK1);
889}
890
Florian Fainelli89f09042018-04-25 12:12:50 -0700891static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +0100892{
893 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100894 int serdes_count = 0;
895 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100896
Florian Fainelli89f09042018-04-25 12:12:50 -0700897 if (sset != ETH_SS_STATS)
898 return 0;
899
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100900 mutex_lock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100901 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100902 count = chip->info->ops->stats_get_sset_count(chip);
903 if (count < 0)
904 goto out;
905
906 if (chip->info->ops->serdes_get_sset_count)
907 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
908 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +0200909 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +0100910 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200911 goto out;
912 }
913 count += serdes_count;
914 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
915
Andrew Lunn436fe172018-03-01 02:02:29 +0100916out:
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100917 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100918
Andrew Lunn436fe172018-03-01 02:02:29 +0100919 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +0100920}
921
Andrew Lunn436fe172018-03-01 02:02:29 +0100922static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
923 uint64_t *data, int types,
924 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100925{
926 struct mv88e6xxx_hw_stat *stat;
927 int i, j;
928
929 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
930 stat = &mv88e6xxx_hw_stats[i];
931 if (stat->type & types) {
Andrew Lunn377cda12018-02-15 14:38:34 +0100932 mutex_lock(&chip->reg_lock);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100933 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
934 bank1_select,
935 histogram);
Andrew Lunn377cda12018-02-15 14:38:34 +0100936 mutex_unlock(&chip->reg_lock);
937
Andrew Lunn052f9472016-11-21 23:27:03 +0100938 j++;
939 }
940 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100941 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +0100942}
943
Andrew Lunn436fe172018-03-01 02:02:29 +0100944static int mv88e6095_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_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400949 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100950}
951
Andrew Lunn436fe172018-03-01 02:02:29 +0100952static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
953 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100954{
955 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100956 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400957 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
958 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100959}
960
Andrew Lunn436fe172018-03-01 02:02:29 +0100961static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
962 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +0100963{
964 return mv88e6xxx_stats_get_stats(chip, port, data,
965 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400966 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
967 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100968}
969
Andrew Lunn65f60e42018-03-28 23:50:28 +0200970static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
971 uint64_t *data)
972{
973 *data++ = chip->ports[port].atu_member_violation;
974 *data++ = chip->ports[port].atu_miss_violation;
975 *data++ = chip->ports[port].atu_full_violation;
976 *data++ = chip->ports[port].vtu_member_violation;
977 *data++ = chip->ports[port].vtu_miss_violation;
978}
979
Andrew Lunn052f9472016-11-21 23:27:03 +0100980static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
981 uint64_t *data)
982{
Andrew Lunn436fe172018-03-01 02:02:29 +0100983 int count = 0;
984
Andrew Lunn052f9472016-11-21 23:27:03 +0100985 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +0100986 count = chip->info->ops->stats_get_stats(chip, port, data);
987
Andrew Lunn65f60e42018-03-28 23:50:28 +0200988 mutex_lock(&chip->reg_lock);
Andrew Lunn436fe172018-03-01 02:02:29 +0100989 if (chip->info->ops->serdes_get_stats) {
990 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200991 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100992 }
Andrew Lunn65f60e42018-03-28 23:50:28 +0200993 data += count;
994 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
995 mutex_unlock(&chip->reg_lock);
Andrew Lunn052f9472016-11-21 23:27:03 +0100996}
997
Vivien Didelotf81ec902016-05-09 13:22:58 -0400998static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
999 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001000{
Vivien Didelot04bed142016-08-31 18:06:13 -04001001 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001002 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001003
Vivien Didelotfad09c72016-06-21 12:28:20 -04001004 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001005
Andrew Lunna605a0f2016-11-21 23:26:58 +01001006 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +01001007 mutex_unlock(&chip->reg_lock);
1008
1009 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001010 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001011
1012 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001013
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014}
Ben Hutchings98e67302011-11-25 14:36:19 +00001015
Vivien Didelotf81ec902016-05-09 13:22:58 -04001016static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001017{
1018 return 32 * sizeof(u16);
1019}
1020
Vivien Didelotf81ec902016-05-09 13:22:58 -04001021static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1022 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001023{
Vivien Didelot04bed142016-08-31 18:06:13 -04001024 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001025 int err;
1026 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001027 u16 *p = _p;
1028 int i;
1029
1030 regs->version = 0;
1031
1032 memset(p, 0xff, 32 * sizeof(u16));
1033
Vivien Didelotfad09c72016-06-21 12:28:20 -04001034 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001035
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001036 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001037
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001038 err = mv88e6xxx_port_read(chip, port, i, &reg);
1039 if (!err)
1040 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001041 }
Vivien Didelot23062512016-05-09 13:22:45 -04001042
Vivien Didelotfad09c72016-06-21 12:28:20 -04001043 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001044}
1045
Vivien Didelot08f50062017-08-01 16:32:41 -04001046static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1047 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001048{
Vivien Didelot5480db62017-08-01 16:32:40 -04001049 /* Nothing to do on the port's MAC */
1050 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001051}
1052
Vivien Didelot08f50062017-08-01 16:32:41 -04001053static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1054 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001055{
Vivien Didelot5480db62017-08-01 16:32:40 -04001056 /* Nothing to do on the port's MAC */
1057 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001058}
1059
Vivien Didelote5887a22017-03-30 17:37:11 -04001060static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001061{
Vivien Didelote5887a22017-03-30 17:37:11 -04001062 struct dsa_switch *ds = NULL;
1063 struct net_device *br;
1064 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001065 int i;
1066
Vivien Didelote5887a22017-03-30 17:37:11 -04001067 if (dev < DSA_MAX_SWITCHES)
1068 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001069
Vivien Didelote5887a22017-03-30 17:37:11 -04001070 /* Prevent frames from unknown switch or port */
1071 if (!ds || port >= ds->num_ports)
1072 return 0;
1073
1074 /* Frames from DSA links and CPU ports can egress any local port */
1075 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1076 return mv88e6xxx_port_mask(chip);
1077
1078 br = ds->ports[port].bridge_dev;
1079 pvlan = 0;
1080
1081 /* Frames from user ports can egress any local DSA links and CPU ports,
1082 * as well as any local member of their bridge group.
1083 */
1084 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1085 if (dsa_is_cpu_port(chip->ds, i) ||
1086 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -04001087 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -04001088 pvlan |= BIT(i);
1089
1090 return pvlan;
1091}
1092
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001093static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001094{
1095 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001096
1097 /* prevent frames from going back out of the port they came in on */
1098 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001099
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001100 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001101}
1102
Vivien Didelotf81ec902016-05-09 13:22:58 -04001103static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1104 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001105{
Vivien Didelot04bed142016-08-31 18:06:13 -04001106 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001107 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001108
Vivien Didelotfad09c72016-06-21 12:28:20 -04001109 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -04001110 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001111 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001112
1113 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001114 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001115}
1116
Vivien Didelot93e18d62018-05-11 17:16:35 -04001117static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1118{
1119 int err;
1120
1121 if (chip->info->ops->ieee_pri_map) {
1122 err = chip->info->ops->ieee_pri_map(chip);
1123 if (err)
1124 return err;
1125 }
1126
1127 if (chip->info->ops->ip_pri_map) {
1128 err = chip->info->ops->ip_pri_map(chip);
1129 if (err)
1130 return err;
1131 }
1132
1133 return 0;
1134}
1135
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001136static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1137{
1138 int target, port;
1139 int err;
1140
1141 if (!chip->info->global2_addr)
1142 return 0;
1143
1144 /* Initialize the routing port to the 32 possible target devices */
1145 for (target = 0; target < 32; target++) {
1146 port = 0x1f;
1147 if (target < DSA_MAX_SWITCHES)
1148 if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
1149 port = chip->ds->rtable[target];
1150
1151 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1152 if (err)
1153 return err;
1154 }
1155
Vivien Didelot02317e62018-05-09 11:38:49 -04001156 if (chip->info->ops->set_cascade_port) {
1157 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1158 err = chip->info->ops->set_cascade_port(chip, port);
1159 if (err)
1160 return err;
1161 }
1162
Vivien Didelot23c98912018-05-09 11:38:50 -04001163 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1164 if (err)
1165 return err;
1166
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001167 return 0;
1168}
1169
Vivien Didelotb28f8722018-04-26 21:56:44 -04001170static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1171{
1172 /* Clear all trunk masks and mapping */
1173 if (chip->info->global2_addr)
1174 return mv88e6xxx_g2_trunk_clear(chip);
1175
1176 return 0;
1177}
1178
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001179static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1180{
1181 if (chip->info->ops->rmu_disable)
1182 return chip->info->ops->rmu_disable(chip);
1183
1184 return 0;
1185}
1186
Vivien Didelot9e907d72017-07-17 13:03:43 -04001187static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1188{
1189 if (chip->info->ops->pot_clear)
1190 return chip->info->ops->pot_clear(chip);
1191
1192 return 0;
1193}
1194
Vivien Didelot51c901a2017-07-17 13:03:41 -04001195static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1196{
1197 if (chip->info->ops->mgmt_rsvd2cpu)
1198 return chip->info->ops->mgmt_rsvd2cpu(chip);
1199
1200 return 0;
1201}
1202
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001203static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1204{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001205 int err;
1206
Vivien Didelotdaefc942017-03-11 16:12:54 -05001207 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1208 if (err)
1209 return err;
1210
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001211 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1212 if (err)
1213 return err;
1214
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001215 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1216}
1217
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001218static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1219{
1220 int port;
1221 int err;
1222
1223 if (!chip->info->ops->irl_init_all)
1224 return 0;
1225
1226 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1227 /* Disable ingress rate limiting by resetting all per port
1228 * ingress rate limit resources to their initial state.
1229 */
1230 err = chip->info->ops->irl_init_all(chip, port);
1231 if (err)
1232 return err;
1233 }
1234
1235 return 0;
1236}
1237
Vivien Didelot04a69a12017-10-13 14:18:05 -04001238static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1239{
1240 if (chip->info->ops->set_switch_mac) {
1241 u8 addr[ETH_ALEN];
1242
1243 eth_random_addr(addr);
1244
1245 return chip->info->ops->set_switch_mac(chip, addr);
1246 }
1247
1248 return 0;
1249}
1250
Vivien Didelot17a15942017-03-30 17:37:09 -04001251static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1252{
1253 u16 pvlan = 0;
1254
1255 if (!mv88e6xxx_has_pvt(chip))
1256 return -EOPNOTSUPP;
1257
1258 /* Skip the local source device, which uses in-chip port VLAN */
1259 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001260 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001261
1262 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1263}
1264
Vivien Didelot81228992017-03-30 17:37:08 -04001265static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1266{
Vivien Didelot17a15942017-03-30 17:37:09 -04001267 int dev, port;
1268 int err;
1269
Vivien Didelot81228992017-03-30 17:37:08 -04001270 if (!mv88e6xxx_has_pvt(chip))
1271 return 0;
1272
1273 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1274 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1275 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001276 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1277 if (err)
1278 return err;
1279
1280 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1281 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1282 err = mv88e6xxx_pvt_map(chip, dev, port);
1283 if (err)
1284 return err;
1285 }
1286 }
1287
1288 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001289}
1290
Vivien Didelot749efcb2016-09-22 16:49:24 -04001291static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1292{
1293 struct mv88e6xxx_chip *chip = ds->priv;
1294 int err;
1295
1296 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001297 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001298 mutex_unlock(&chip->reg_lock);
1299
1300 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001301 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001302}
1303
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001304static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1305{
1306 if (!chip->info->max_vid)
1307 return 0;
1308
1309 return mv88e6xxx_g1_vtu_flush(chip);
1310}
1311
Vivien Didelotf1394b782017-05-01 14:05:22 -04001312static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1313 struct mv88e6xxx_vtu_entry *entry)
1314{
1315 if (!chip->info->ops->vtu_getnext)
1316 return -EOPNOTSUPP;
1317
1318 return chip->info->ops->vtu_getnext(chip, entry);
1319}
1320
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001321static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1322 struct mv88e6xxx_vtu_entry *entry)
1323{
1324 if (!chip->info->ops->vtu_loadpurge)
1325 return -EOPNOTSUPP;
1326
1327 return chip->info->ops->vtu_loadpurge(chip, entry);
1328}
1329
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001330static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001331{
1332 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001333 struct mv88e6xxx_vtu_entry vlan = {
1334 .vid = chip->info->max_vid,
1335 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001336 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001337
1338 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1339
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001340 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001341 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001342 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001343 if (err)
1344 return err;
1345
1346 set_bit(*fid, fid_bitmap);
1347 }
1348
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001349 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001350 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001351 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001352 if (err)
1353 return err;
1354
1355 if (!vlan.valid)
1356 break;
1357
1358 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001359 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001360
1361 /* The reset value 0x000 is used to indicate that multiple address
1362 * databases are not needed. Return the next positive available.
1363 */
1364 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001365 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001366 return -ENOSPC;
1367
1368 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001369 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001370}
1371
Vivien Didelot567aa592017-05-01 14:05:25 -04001372static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1373 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001374{
1375 int err;
1376
1377 if (!vid)
1378 return -EINVAL;
1379
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001380 entry->vid = vid - 1;
1381 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001382
Vivien Didelotf1394b782017-05-01 14:05:22 -04001383 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001384 if (err)
1385 return err;
1386
Vivien Didelot567aa592017-05-01 14:05:25 -04001387 if (entry->vid == vid && entry->valid)
1388 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001389
Vivien Didelot567aa592017-05-01 14:05:25 -04001390 if (new) {
1391 int i;
1392
1393 /* Initialize a fresh VLAN entry */
1394 memset(entry, 0, sizeof(*entry));
1395 entry->valid = true;
1396 entry->vid = vid;
1397
Vivien Didelot553a7682017-06-07 18:12:16 -04001398 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001399 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001400 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001401 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001402
1403 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001404 }
1405
Vivien Didelot567aa592017-05-01 14:05:25 -04001406 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1407 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001408}
1409
Vivien Didelotda9c3592016-02-12 12:09:40 -05001410static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1411 u16 vid_begin, u16 vid_end)
1412{
Vivien Didelot04bed142016-08-31 18:06:13 -04001413 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001414 struct mv88e6xxx_vtu_entry vlan = {
1415 .vid = vid_begin - 1,
1416 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001417 int i, err;
1418
Andrew Lunndb06ae412017-09-25 23:32:20 +02001419 /* DSA and CPU ports have to be members of multiple vlans */
1420 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1421 return 0;
1422
Vivien Didelotda9c3592016-02-12 12:09:40 -05001423 if (!vid_begin)
1424 return -EOPNOTSUPP;
1425
Vivien Didelotfad09c72016-06-21 12:28:20 -04001426 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001427
Vivien Didelotda9c3592016-02-12 12:09:40 -05001428 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001429 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001430 if (err)
1431 goto unlock;
1432
1433 if (!vlan.valid)
1434 break;
1435
1436 if (vlan.vid > vid_end)
1437 break;
1438
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001439 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001440 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1441 continue;
1442
Andrew Lunncd886462017-11-09 22:29:53 +01001443 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001444 continue;
1445
Vivien Didelotbd00e052017-05-01 14:05:11 -04001446 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001447 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001448 continue;
1449
Vivien Didelotc8652c82017-10-16 11:12:19 -04001450 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001451 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001452 break; /* same bridge, check next VLAN */
1453
Vivien Didelotc8652c82017-10-16 11:12:19 -04001454 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001455 continue;
1456
Andrew Lunn743fcc22017-11-09 22:29:54 +01001457 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1458 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001459 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001460 err = -EOPNOTSUPP;
1461 goto unlock;
1462 }
1463 } while (vlan.vid < vid_end);
1464
1465unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001466 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001467
1468 return err;
1469}
1470
Vivien Didelotf81ec902016-05-09 13:22:58 -04001471static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1472 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001473{
Vivien Didelot04bed142016-08-31 18:06:13 -04001474 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001475 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1476 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001477 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001478
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001479 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001480 return -EOPNOTSUPP;
1481
Vivien Didelotfad09c72016-06-21 12:28:20 -04001482 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001483 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001484 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001485
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001486 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001487}
1488
Vivien Didelot57d32312016-06-20 13:13:58 -04001489static int
1490mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001491 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001492{
Vivien Didelot04bed142016-08-31 18:06:13 -04001493 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001494 int err;
1495
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001496 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001497 return -EOPNOTSUPP;
1498
Vivien Didelotda9c3592016-02-12 12:09:40 -05001499 /* If the requested port doesn't belong to the same bridge as the VLAN
1500 * members, do not support it (yet) and fallback to software VLAN.
1501 */
1502 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1503 vlan->vid_end);
1504 if (err)
1505 return err;
1506
Vivien Didelot76e398a2015-11-01 12:33:55 -05001507 /* We don't need any dynamic resource from the kernel (yet),
1508 * so skip the prepare phase.
1509 */
1510 return 0;
1511}
1512
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001513static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1514 const unsigned char *addr, u16 vid,
1515 u8 state)
1516{
1517 struct mv88e6xxx_vtu_entry vlan;
1518 struct mv88e6xxx_atu_entry entry;
1519 int err;
1520
1521 /* Null VLAN ID corresponds to the port private database */
1522 if (vid == 0)
1523 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1524 else
1525 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1526 if (err)
1527 return err;
1528
1529 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1530 ether_addr_copy(entry.mac, addr);
1531 eth_addr_dec(entry.mac);
1532
1533 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1534 if (err)
1535 return err;
1536
1537 /* Initialize a fresh ATU entry if it isn't found */
1538 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1539 !ether_addr_equal(entry.mac, addr)) {
1540 memset(&entry, 0, sizeof(entry));
1541 ether_addr_copy(entry.mac, addr);
1542 }
1543
1544 /* Purge the ATU entry only if no port is using it anymore */
1545 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1546 entry.portvec &= ~BIT(port);
1547 if (!entry.portvec)
1548 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1549 } else {
1550 entry.portvec |= BIT(port);
1551 entry.state = state;
1552 }
1553
1554 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1555}
1556
Andrew Lunn87fa8862017-11-09 22:29:56 +01001557static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1558 u16 vid)
1559{
1560 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1561 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1562
1563 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1564}
1565
1566static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1567{
1568 int port;
1569 int err;
1570
1571 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1572 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1573 if (err)
1574 return err;
1575 }
1576
1577 return 0;
1578}
1579
Vivien Didelotfad09c72016-06-21 12:28:20 -04001580static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001581 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001582{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001583 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001584 int err;
1585
Vivien Didelot567aa592017-05-01 14:05:25 -04001586 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001587 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001588 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001589
Vivien Didelotc91498e2017-06-07 18:12:13 -04001590 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001591
Andrew Lunn87fa8862017-11-09 22:29:56 +01001592 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1593 if (err)
1594 return err;
1595
1596 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001597}
1598
Vivien Didelotf81ec902016-05-09 13:22:58 -04001599static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001600 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001601{
Vivien Didelot04bed142016-08-31 18:06:13 -04001602 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001603 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1604 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001605 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001606 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001607
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001608 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001609 return;
1610
Vivien Didelotc91498e2017-06-07 18:12:13 -04001611 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001612 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001613 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001614 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001615 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001616 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001617
Vivien Didelotfad09c72016-06-21 12:28:20 -04001618 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001619
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001620 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001621 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001622 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1623 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001624
Vivien Didelot77064f32016-11-04 03:23:30 +01001625 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001626 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1627 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001628
Vivien Didelotfad09c72016-06-21 12:28:20 -04001629 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001630}
1631
Vivien Didelotfad09c72016-06-21 12:28:20 -04001632static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001633 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001634{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001635 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001636 int i, err;
1637
Vivien Didelot567aa592017-05-01 14:05:25 -04001638 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001639 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001640 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001641
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001642 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001643 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001644 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001645
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001646 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001647
1648 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001649 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001650 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001651 if (vlan.member[i] !=
1652 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001653 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001654 break;
1655 }
1656 }
1657
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001658 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001659 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001660 return err;
1661
Vivien Didelote606ca32017-03-11 16:12:55 -05001662 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001663}
1664
Vivien Didelotf81ec902016-05-09 13:22:58 -04001665static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1666 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001667{
Vivien Didelot04bed142016-08-31 18:06:13 -04001668 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001669 u16 pvid, vid;
1670 int err = 0;
1671
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001672 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001673 return -EOPNOTSUPP;
1674
Vivien Didelotfad09c72016-06-21 12:28:20 -04001675 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001676
Vivien Didelot77064f32016-11-04 03:23:30 +01001677 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001678 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001679 goto unlock;
1680
Vivien Didelot76e398a2015-11-01 12:33:55 -05001681 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001682 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001683 if (err)
1684 goto unlock;
1685
1686 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001687 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001688 if (err)
1689 goto unlock;
1690 }
1691 }
1692
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001693unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001694 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001695
1696 return err;
1697}
1698
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001699static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1700 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001701{
Vivien Didelot04bed142016-08-31 18:06:13 -04001702 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001703 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001704
Vivien Didelotfad09c72016-06-21 12:28:20 -04001705 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001706 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1707 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001708 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001709
1710 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001711}
1712
Vivien Didelotf81ec902016-05-09 13:22:58 -04001713static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001714 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001715{
Vivien Didelot04bed142016-08-31 18:06:13 -04001716 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001717 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001718
Vivien Didelotfad09c72016-06-21 12:28:20 -04001719 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001720 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001721 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001722 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001723
Vivien Didelot83dabd12016-08-31 11:50:04 -04001724 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001725}
1726
Vivien Didelot83dabd12016-08-31 11:50:04 -04001727static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1728 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001729 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001730{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001731 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001732 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001733 int err;
1734
Vivien Didelot27c0e602017-06-15 12:14:01 -04001735 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001736 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001737
1738 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001739 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001740 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001741 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001742 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001743 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001744
Vivien Didelot27c0e602017-06-15 12:14:01 -04001745 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001746 break;
1747
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001748 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001749 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001750
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001751 if (!is_unicast_ether_addr(addr.mac))
1752 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001753
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001754 is_static = (addr.state ==
1755 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1756 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001757 if (err)
1758 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001759 } while (!is_broadcast_ether_addr(addr.mac));
1760
1761 return err;
1762}
1763
Vivien Didelot83dabd12016-08-31 11:50:04 -04001764static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001765 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001766{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001767 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001768 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001769 };
1770 u16 fid;
1771 int err;
1772
1773 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001774 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001775 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001776 mutex_unlock(&chip->reg_lock);
1777
Vivien Didelot83dabd12016-08-31 11:50:04 -04001778 if (err)
1779 return err;
1780
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001781 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001782 if (err)
1783 return err;
1784
1785 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001786 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001787 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001788 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001789 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001790 if (err)
1791 return err;
1792
1793 if (!vlan.valid)
1794 break;
1795
1796 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001797 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001798 if (err)
1799 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001800 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001801
1802 return err;
1803}
1804
Vivien Didelotf81ec902016-05-09 13:22:58 -04001805static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001806 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001807{
Vivien Didelot04bed142016-08-31 18:06:13 -04001808 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001809
Andrew Lunna61e5402018-02-15 14:38:35 +01001810 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001811}
1812
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001813static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1814 struct net_device *br)
1815{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001816 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001817 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001818 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001819 int err;
1820
1821 /* Remap the Port VLAN of each local bridge group member */
1822 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1823 if (chip->ds->ports[port].bridge_dev == br) {
1824 err = mv88e6xxx_port_vlan_map(chip, port);
1825 if (err)
1826 return err;
1827 }
1828 }
1829
Vivien Didelote96a6e02017-03-30 17:37:13 -04001830 if (!mv88e6xxx_has_pvt(chip))
1831 return 0;
1832
1833 /* Remap the Port VLAN of each cross-chip bridge group member */
1834 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1835 ds = chip->ds->dst->ds[dev];
1836 if (!ds)
1837 break;
1838
1839 for (port = 0; port < ds->num_ports; ++port) {
1840 if (ds->ports[port].bridge_dev == br) {
1841 err = mv88e6xxx_pvt_map(chip, dev, port);
1842 if (err)
1843 return err;
1844 }
1845 }
1846 }
1847
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001848 return 0;
1849}
1850
Vivien Didelotf81ec902016-05-09 13:22:58 -04001851static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001852 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001853{
Vivien Didelot04bed142016-08-31 18:06:13 -04001854 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001855 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001856
Vivien Didelotfad09c72016-06-21 12:28:20 -04001857 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001858 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001859 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001860
Vivien Didelot466dfa02016-02-26 13:16:05 -05001861 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001862}
1863
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001864static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1865 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001866{
Vivien Didelot04bed142016-08-31 18:06:13 -04001867 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001868
Vivien Didelotfad09c72016-06-21 12:28:20 -04001869 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001870 if (mv88e6xxx_bridge_map(chip, br) ||
1871 mv88e6xxx_port_vlan_map(chip, port))
1872 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001873 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001874}
1875
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001876static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1877 int port, struct net_device *br)
1878{
1879 struct mv88e6xxx_chip *chip = ds->priv;
1880 int err;
1881
1882 if (!mv88e6xxx_has_pvt(chip))
1883 return 0;
1884
1885 mutex_lock(&chip->reg_lock);
1886 err = mv88e6xxx_pvt_map(chip, dev, port);
1887 mutex_unlock(&chip->reg_lock);
1888
1889 return err;
1890}
1891
1892static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1893 int port, struct net_device *br)
1894{
1895 struct mv88e6xxx_chip *chip = ds->priv;
1896
1897 if (!mv88e6xxx_has_pvt(chip))
1898 return;
1899
1900 mutex_lock(&chip->reg_lock);
1901 if (mv88e6xxx_pvt_map(chip, dev, port))
1902 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1903 mutex_unlock(&chip->reg_lock);
1904}
1905
Vivien Didelot17e708b2016-12-05 17:30:27 -05001906static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1907{
1908 if (chip->info->ops->reset)
1909 return chip->info->ops->reset(chip);
1910
1911 return 0;
1912}
1913
Vivien Didelot309eca62016-12-05 17:30:26 -05001914static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1915{
1916 struct gpio_desc *gpiod = chip->reset;
1917
1918 /* If there is a GPIO connected to the reset pin, toggle it */
1919 if (gpiod) {
1920 gpiod_set_value_cansleep(gpiod, 1);
1921 usleep_range(10000, 20000);
1922 gpiod_set_value_cansleep(gpiod, 0);
1923 usleep_range(10000, 20000);
1924 }
1925}
1926
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001927static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1928{
1929 int i, err;
1930
1931 /* Set all ports to the Disabled state */
1932 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001933 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001934 if (err)
1935 return err;
1936 }
1937
1938 /* Wait for transmit queues to drain,
1939 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1940 */
1941 usleep_range(2000, 4000);
1942
1943 return 0;
1944}
1945
Vivien Didelotfad09c72016-06-21 12:28:20 -04001946static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001947{
Vivien Didelota935c052016-09-29 12:21:53 -04001948 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001949
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001950 err = mv88e6xxx_disable_ports(chip);
1951 if (err)
1952 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001953
Vivien Didelot309eca62016-12-05 17:30:26 -05001954 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001955
Vivien Didelot17e708b2016-12-05 17:30:27 -05001956 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001957}
1958
Vivien Didelot43145572017-03-11 16:12:59 -05001959static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001960 enum mv88e6xxx_frame_mode frame,
1961 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001962{
1963 int err;
1964
Vivien Didelot43145572017-03-11 16:12:59 -05001965 if (!chip->info->ops->port_set_frame_mode)
1966 return -EOPNOTSUPP;
1967
1968 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001969 if (err)
1970 return err;
1971
Vivien Didelot43145572017-03-11 16:12:59 -05001972 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1973 if (err)
1974 return err;
1975
1976 if (chip->info->ops->port_set_ether_type)
1977 return chip->info->ops->port_set_ether_type(chip, port, etype);
1978
1979 return 0;
1980}
1981
1982static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1983{
1984 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001985 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001986 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001987}
1988
1989static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1990{
1991 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001992 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001993 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001994}
1995
1996static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1997{
1998 return mv88e6xxx_set_port_mode(chip, port,
1999 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002000 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2001 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002002}
2003
2004static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2005{
2006 if (dsa_is_dsa_port(chip->ds, port))
2007 return mv88e6xxx_set_port_mode_dsa(chip, port);
2008
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002009 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002010 return mv88e6xxx_set_port_mode_normal(chip, port);
2011
2012 /* Setup CPU port mode depending on its supported tag format */
2013 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2014 return mv88e6xxx_set_port_mode_dsa(chip, port);
2015
2016 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2017 return mv88e6xxx_set_port_mode_edsa(chip, port);
2018
2019 return -EINVAL;
2020}
2021
Vivien Didelotea698f42017-03-11 16:12:50 -05002022static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2023{
2024 bool message = dsa_is_dsa_port(chip->ds, port);
2025
2026 return mv88e6xxx_port_set_message_port(chip, port, message);
2027}
2028
Vivien Didelot601aeed2017-03-11 16:13:00 -05002029static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2030{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002031 struct dsa_switch *ds = chip->ds;
2032 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002033
2034 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002035 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002036 if (chip->info->ops->port_set_egress_floods)
2037 return chip->info->ops->port_set_egress_floods(chip, port,
2038 flood, flood);
2039
2040 return 0;
2041}
2042
Andrew Lunn6d917822017-05-26 01:03:21 +02002043static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2044 bool on)
2045{
Vivien Didelot523a8902017-05-26 18:02:42 -04002046 if (chip->info->ops->serdes_power)
2047 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02002048
Vivien Didelot523a8902017-05-26 18:02:42 -04002049 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02002050}
2051
Vivien Didelotfa371c82017-12-05 15:34:10 -05002052static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2053{
2054 struct dsa_switch *ds = chip->ds;
2055 int upstream_port;
2056 int err;
2057
Vivien Didelot07073c72017-12-05 15:34:13 -05002058 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002059 if (chip->info->ops->port_set_upstream_port) {
2060 err = chip->info->ops->port_set_upstream_port(chip, port,
2061 upstream_port);
2062 if (err)
2063 return err;
2064 }
2065
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002066 if (port == upstream_port) {
2067 if (chip->info->ops->set_cpu_port) {
2068 err = chip->info->ops->set_cpu_port(chip,
2069 upstream_port);
2070 if (err)
2071 return err;
2072 }
2073
2074 if (chip->info->ops->set_egress_port) {
2075 err = chip->info->ops->set_egress_port(chip,
2076 upstream_port);
2077 if (err)
2078 return err;
2079 }
2080 }
2081
Vivien Didelotfa371c82017-12-05 15:34:10 -05002082 return 0;
2083}
2084
Vivien Didelotfad09c72016-06-21 12:28:20 -04002085static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002086{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002087 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002088 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002089 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002090
Vivien Didelotd78343d2016-11-04 03:23:36 +01002091 /* MAC Forcing register: don't force link, speed, duplex or flow control
2092 * state to any particular values on physical ports, but force the CPU
2093 * port and all DSA ports to their maximum bandwidth and full duplex.
2094 */
2095 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2096 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2097 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002098 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002099 PHY_INTERFACE_MODE_NA);
2100 else
2101 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2102 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002103 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002104 PHY_INTERFACE_MODE_NA);
2105 if (err)
2106 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002107
2108 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2109 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2110 * tunneling, determine priority by looking at 802.1p and IP
2111 * priority fields (IP prio has precedence), and set STP state
2112 * to Forwarding.
2113 *
2114 * If this is the CPU link, use DSA or EDSA tagging depending
2115 * on which tagging mode was configured.
2116 *
2117 * If this is a link to another switch, use DSA tagging mode.
2118 *
2119 * If this is the upstream port for this switch, enable
2120 * forwarding of unknown unicasts and multicasts.
2121 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002122 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2123 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2124 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2125 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002126 if (err)
2127 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002128
Vivien Didelot601aeed2017-03-11 16:13:00 -05002129 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002130 if (err)
2131 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002132
Vivien Didelot601aeed2017-03-11 16:13:00 -05002133 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002134 if (err)
2135 return err;
2136
Andrew Lunn04aca992017-05-26 01:03:24 +02002137 /* Enable the SERDES interface for DSA and CPU ports. Normal
2138 * ports SERDES are enabled when the port is enabled, thus
2139 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002140 */
Andrew Lunn04aca992017-05-26 01:03:24 +02002141 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
2142 err = mv88e6xxx_serdes_power(chip, port, true);
2143 if (err)
2144 return err;
2145 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002146
Vivien Didelot8efdda42015-08-13 12:52:23 -04002147 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002148 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002149 * untagged frames on this port, do a destination address lookup on all
2150 * received packets as usual, disable ARP mirroring and don't send a
2151 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002152 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002153 err = mv88e6xxx_port_set_map_da(chip, port);
2154 if (err)
2155 return err;
2156
Vivien Didelotfa371c82017-12-05 15:34:10 -05002157 err = mv88e6xxx_setup_upstream_port(chip, port);
2158 if (err)
2159 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002160
Andrew Lunna23b2962017-02-04 20:15:28 +01002161 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002162 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002163 if (err)
2164 return err;
2165
Vivien Didelotcd782652017-06-08 18:34:13 -04002166 if (chip->info->ops->port_set_jumbo_size) {
2167 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002168 if (err)
2169 return err;
2170 }
2171
Andrew Lunn54d792f2015-05-06 01:09:47 +02002172 /* Port Association Vector: when learning source addresses
2173 * of packets, add the address to the address database using
2174 * a port bitmap that has only the bit for this port set and
2175 * the other bits clear.
2176 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002177 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002178 /* Disable learning for CPU port */
2179 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002180 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002181
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002182 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2183 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002184 if (err)
2185 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002186
2187 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002188 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2189 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002190 if (err)
2191 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002192
Vivien Didelot08984322017-06-08 18:34:12 -04002193 if (chip->info->ops->port_pause_limit) {
2194 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002195 if (err)
2196 return err;
2197 }
2198
Vivien Didelotc8c94892017-03-11 16:13:01 -05002199 if (chip->info->ops->port_disable_learn_limit) {
2200 err = chip->info->ops->port_disable_learn_limit(chip, port);
2201 if (err)
2202 return err;
2203 }
2204
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002205 if (chip->info->ops->port_disable_pri_override) {
2206 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002207 if (err)
2208 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002209 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002210
Andrew Lunnef0a7312016-12-03 04:35:16 +01002211 if (chip->info->ops->port_tag_remap) {
2212 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002213 if (err)
2214 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002215 }
2216
Andrew Lunnef70b112016-12-03 04:45:18 +01002217 if (chip->info->ops->port_egress_rate_limiting) {
2218 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002219 if (err)
2220 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002221 }
2222
Vivien Didelotea698f42017-03-11 16:12:50 -05002223 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002224 if (err)
2225 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002226
Vivien Didelot207afda2016-04-14 14:42:09 -04002227 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002228 * database, and allow bidirectional communication between the
2229 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002230 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002231 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002232 if (err)
2233 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002234
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002235 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002236 if (err)
2237 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002238
2239 /* Default VLAN ID and priority: don't set a default VLAN
2240 * ID, and set the default packet priority to zero.
2241 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002242 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002243}
2244
Andrew Lunn04aca992017-05-26 01:03:24 +02002245static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2246 struct phy_device *phydev)
2247{
2248 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002249 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002250
2251 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002252 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002253 mutex_unlock(&chip->reg_lock);
2254
2255 return err;
2256}
2257
2258static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2259 struct phy_device *phydev)
2260{
2261 struct mv88e6xxx_chip *chip = ds->priv;
2262
2263 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002264 if (mv88e6xxx_serdes_power(chip, port, false))
2265 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002266 mutex_unlock(&chip->reg_lock);
2267}
2268
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002269static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2270 unsigned int ageing_time)
2271{
Vivien Didelot04bed142016-08-31 18:06:13 -04002272 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002273 int err;
2274
2275 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002276 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002277 mutex_unlock(&chip->reg_lock);
2278
2279 return err;
2280}
2281
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002282static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002283{
2284 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002285
Andrew Lunnde2273872016-11-21 23:27:01 +01002286 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002287 if (chip->info->ops->stats_set_histogram) {
2288 err = chip->info->ops->stats_set_histogram(chip);
2289 if (err)
2290 return err;
2291 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002292
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002293 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002294}
2295
Vivien Didelotf81ec902016-05-09 13:22:58 -04002296static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002297{
Vivien Didelot04bed142016-08-31 18:06:13 -04002298 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002299 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002300 int i;
2301
Vivien Didelotfad09c72016-06-21 12:28:20 -04002302 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002303 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002304
Vivien Didelotfad09c72016-06-21 12:28:20 -04002305 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002306
Vivien Didelot97299342016-07-18 20:45:30 -04002307 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002308 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002309 if (dsa_is_unused_port(ds, i))
2310 continue;
2311
Vivien Didelot97299342016-07-18 20:45:30 -04002312 err = mv88e6xxx_setup_port(chip, i);
2313 if (err)
2314 goto unlock;
2315 }
2316
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002317 err = mv88e6xxx_irl_setup(chip);
2318 if (err)
2319 goto unlock;
2320
Vivien Didelot04a69a12017-10-13 14:18:05 -04002321 err = mv88e6xxx_mac_setup(chip);
2322 if (err)
2323 goto unlock;
2324
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002325 err = mv88e6xxx_phy_setup(chip);
2326 if (err)
2327 goto unlock;
2328
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002329 err = mv88e6xxx_vtu_setup(chip);
2330 if (err)
2331 goto unlock;
2332
Vivien Didelot81228992017-03-30 17:37:08 -04002333 err = mv88e6xxx_pvt_setup(chip);
2334 if (err)
2335 goto unlock;
2336
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002337 err = mv88e6xxx_atu_setup(chip);
2338 if (err)
2339 goto unlock;
2340
Andrew Lunn87fa8862017-11-09 22:29:56 +01002341 err = mv88e6xxx_broadcast_setup(chip, 0);
2342 if (err)
2343 goto unlock;
2344
Vivien Didelot9e907d72017-07-17 13:03:43 -04002345 err = mv88e6xxx_pot_setup(chip);
2346 if (err)
2347 goto unlock;
2348
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002349 err = mv88e6xxx_rmu_setup(chip);
2350 if (err)
2351 goto unlock;
2352
Vivien Didelot51c901a2017-07-17 13:03:41 -04002353 err = mv88e6xxx_rsvd2cpu_setup(chip);
2354 if (err)
2355 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002356
Vivien Didelotb28f8722018-04-26 21:56:44 -04002357 err = mv88e6xxx_trunk_setup(chip);
2358 if (err)
2359 goto unlock;
2360
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002361 err = mv88e6xxx_devmap_setup(chip);
2362 if (err)
2363 goto unlock;
2364
Vivien Didelot93e18d62018-05-11 17:16:35 -04002365 err = mv88e6xxx_pri_setup(chip);
2366 if (err)
2367 goto unlock;
2368
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002369 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002370 if (chip->info->ptp_support) {
2371 err = mv88e6xxx_ptp_setup(chip);
2372 if (err)
2373 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002374
2375 err = mv88e6xxx_hwtstamp_setup(chip);
2376 if (err)
2377 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002378 }
2379
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002380 err = mv88e6xxx_stats_setup(chip);
2381 if (err)
2382 goto unlock;
2383
Vivien Didelot6b17e862015-08-13 12:52:18 -04002384unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002385 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002386
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002387 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002388}
2389
Vivien Didelote57e5e72016-08-15 17:19:00 -04002390static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002391{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002392 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2393 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002394 u16 val;
2395 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002396
Andrew Lunnee26a222017-01-24 14:53:48 +01002397 if (!chip->info->ops->phy_read)
2398 return -EOPNOTSUPP;
2399
Vivien Didelotfad09c72016-06-21 12:28:20 -04002400 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002401 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002402 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002403
Andrew Lunnda9f3302017-02-01 03:40:05 +01002404 if (reg == MII_PHYSID2) {
2405 /* Some internal PHYS don't have a model number. Use
2406 * the mv88e6390 family model number instead.
2407 */
2408 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002409 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002410 }
2411
Vivien Didelote57e5e72016-08-15 17:19:00 -04002412 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002413}
2414
Vivien Didelote57e5e72016-08-15 17:19:00 -04002415static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002416{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002417 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2418 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002419 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002420
Andrew Lunnee26a222017-01-24 14:53:48 +01002421 if (!chip->info->ops->phy_write)
2422 return -EOPNOTSUPP;
2423
Vivien Didelotfad09c72016-06-21 12:28:20 -04002424 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002425 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002426 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002427
2428 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002429}
2430
Vivien Didelotfad09c72016-06-21 12:28:20 -04002431static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002432 struct device_node *np,
2433 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002434{
2435 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002436 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002437 struct mii_bus *bus;
2438 int err;
2439
Andrew Lunn2510bab2018-02-22 01:51:49 +01002440 if (external) {
2441 mutex_lock(&chip->reg_lock);
2442 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2443 mutex_unlock(&chip->reg_lock);
2444
2445 if (err)
2446 return err;
2447 }
2448
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002449 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002450 if (!bus)
2451 return -ENOMEM;
2452
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002453 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002454 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002455 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002456 INIT_LIST_HEAD(&mdio_bus->list);
2457 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002458
Andrew Lunnb516d452016-06-04 21:17:06 +02002459 if (np) {
2460 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002461 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002462 } else {
2463 bus->name = "mv88e6xxx SMI";
2464 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2465 }
2466
2467 bus->read = mv88e6xxx_mdio_read;
2468 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002469 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002470
Andrew Lunn6f882842018-03-17 20:32:05 +01002471 if (!external) {
2472 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2473 if (err)
2474 return err;
2475 }
2476
Florian Fainelli00e798c2018-05-15 16:56:19 -07002477 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002478 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002479 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002480 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002481 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002482 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002483
2484 if (external)
2485 list_add_tail(&mdio_bus->list, &chip->mdios);
2486 else
2487 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002488
2489 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002490}
2491
Andrew Lunna3c53be52017-01-24 14:53:50 +01002492static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2493 { .compatible = "marvell,mv88e6xxx-mdio-external",
2494 .data = (void *)true },
2495 { },
2496};
2497
Andrew Lunn3126aee2017-12-07 01:05:57 +01002498static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2499
2500{
2501 struct mv88e6xxx_mdio_bus *mdio_bus;
2502 struct mii_bus *bus;
2503
2504 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2505 bus = mdio_bus->bus;
2506
Andrew Lunn6f882842018-03-17 20:32:05 +01002507 if (!mdio_bus->external)
2508 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2509
Andrew Lunn3126aee2017-12-07 01:05:57 +01002510 mdiobus_unregister(bus);
2511 }
2512}
2513
Andrew Lunna3c53be52017-01-24 14:53:50 +01002514static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2515 struct device_node *np)
2516{
2517 const struct of_device_id *match;
2518 struct device_node *child;
2519 int err;
2520
2521 /* Always register one mdio bus for the internal/default mdio
2522 * bus. This maybe represented in the device tree, but is
2523 * optional.
2524 */
2525 child = of_get_child_by_name(np, "mdio");
2526 err = mv88e6xxx_mdio_register(chip, child, false);
2527 if (err)
2528 return err;
2529
2530 /* Walk the device tree, and see if there are any other nodes
2531 * which say they are compatible with the external mdio
2532 * bus.
2533 */
2534 for_each_available_child_of_node(np, child) {
2535 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2536 if (match) {
2537 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002538 if (err) {
2539 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002540 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002541 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002542 }
2543 }
2544
2545 return 0;
2546}
2547
Vivien Didelot855b1932016-07-20 18:18:35 -04002548static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2549{
Vivien Didelot04bed142016-08-31 18:06:13 -04002550 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002551
2552 return chip->eeprom_len;
2553}
2554
Vivien Didelot855b1932016-07-20 18:18:35 -04002555static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2556 struct ethtool_eeprom *eeprom, u8 *data)
2557{
Vivien Didelot04bed142016-08-31 18:06:13 -04002558 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002559 int err;
2560
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002561 if (!chip->info->ops->get_eeprom)
2562 return -EOPNOTSUPP;
2563
Vivien Didelot855b1932016-07-20 18:18:35 -04002564 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002565 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002566 mutex_unlock(&chip->reg_lock);
2567
2568 if (err)
2569 return err;
2570
2571 eeprom->magic = 0xc3ec4951;
2572
2573 return 0;
2574}
2575
Vivien Didelot855b1932016-07-20 18:18:35 -04002576static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2577 struct ethtool_eeprom *eeprom, u8 *data)
2578{
Vivien Didelot04bed142016-08-31 18:06:13 -04002579 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002580 int err;
2581
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002582 if (!chip->info->ops->set_eeprom)
2583 return -EOPNOTSUPP;
2584
Vivien Didelot855b1932016-07-20 18:18:35 -04002585 if (eeprom->magic != 0xc3ec4951)
2586 return -EINVAL;
2587
2588 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002589 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002590 mutex_unlock(&chip->reg_lock);
2591
2592 return err;
2593}
2594
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002595static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002596 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002597 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2598 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002599 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002600 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002601 .phy_read = mv88e6185_phy_ppu_read,
2602 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002603 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002604 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002605 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002606 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002607 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002608 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002609 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002610 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002611 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002612 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002613 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002614 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002615 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002616 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2617 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002618 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002619 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2620 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002621 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002622 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002623 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002624 .ppu_enable = mv88e6185_g1_ppu_enable,
2625 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002626 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002627 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002628 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002629 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002630};
2631
2632static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002633 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002634 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2635 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002636 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002637 .phy_read = mv88e6185_phy_ppu_read,
2638 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002639 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002640 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002641 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002642 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002643 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002644 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002645 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002646 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002647 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2648 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002649 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002650 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002651 .ppu_enable = mv88e6185_g1_ppu_enable,
2652 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002653 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002654 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002655 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002656};
2657
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002658static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002659 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002660 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2661 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002662 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002663 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2664 .phy_read = mv88e6xxx_g2_smi_phy_read,
2665 .phy_write = mv88e6xxx_g2_smi_phy_write,
2666 .port_set_link = mv88e6xxx_port_set_link,
2667 .port_set_duplex = mv88e6xxx_port_set_duplex,
2668 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002669 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002670 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002671 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002672 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002673 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002674 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002675 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002676 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002677 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002678 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002679 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002680 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2681 .stats_get_strings = mv88e6095_stats_get_strings,
2682 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002683 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2684 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002685 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002686 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002687 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002688 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002689 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002690 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002691 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002692};
2693
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002694static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002695 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002696 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2697 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002698 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002699 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002700 .phy_read = mv88e6xxx_g2_smi_phy_read,
2701 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002702 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002703 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002704 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002705 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002706 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002707 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002708 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002709 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002710 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002711 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2712 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002713 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002714 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2715 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002716 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002717 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002718 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002719 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002720 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002721 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002722};
2723
2724static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002725 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002726 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2727 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002728 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002729 .phy_read = mv88e6185_phy_ppu_read,
2730 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002731 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002732 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002733 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002734 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002735 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002736 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002737 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002738 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002739 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002740 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002741 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02002742 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002743 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002744 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002745 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2746 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002747 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002748 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2749 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002750 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002751 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002752 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04002753 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002754 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002755 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002756 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002757 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002758};
2759
Vivien Didelot990e27b2017-03-28 13:50:32 -04002760static const struct mv88e6xxx_ops mv88e6141_ops = {
2761 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002762 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2763 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002764 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002765 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2766 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2767 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2768 .phy_read = mv88e6xxx_g2_smi_phy_read,
2769 .phy_write = mv88e6xxx_g2_smi_phy_write,
2770 .port_set_link = mv88e6xxx_port_set_link,
2771 .port_set_duplex = mv88e6xxx_port_set_duplex,
2772 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2773 .port_set_speed = mv88e6390_port_set_speed,
2774 .port_tag_remap = mv88e6095_port_tag_remap,
2775 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2776 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2777 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002778 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002779 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002780 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002781 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2782 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2783 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002784 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002785 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2786 .stats_get_strings = mv88e6320_stats_get_strings,
2787 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002788 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2789 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002790 .watchdog_ops = &mv88e6390_watchdog_ops,
2791 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002792 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002793 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002794 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002795 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6751e7c2018-07-31 19:19:50 +02002796 .serdes_power = mv88e6341_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002797 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002798};
2799
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002800static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002801 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002802 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2803 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002804 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002805 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002806 .phy_read = mv88e6xxx_g2_smi_phy_read,
2807 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002808 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002809 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002810 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002811 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002812 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002813 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002814 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002815 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002816 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002817 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002818 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002819 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002820 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002821 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002822 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2823 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002824 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002825 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2826 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002827 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002828 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002829 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002830 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002831 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002832 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02002833 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02002834 .ptp_ops = &mv88e6165_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002835};
2836
2837static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002838 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002839 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2840 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002841 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002842 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002843 .phy_read = mv88e6165_phy_read,
2844 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002845 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002846 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002847 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002848 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002849 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002850 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002851 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002852 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2853 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002854 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002855 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2856 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002857 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002858 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002859 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002860 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002861 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002862 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02002863 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02002864 .ptp_ops = &mv88e6165_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002865};
2866
2867static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002868 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002869 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2870 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002871 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002872 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002873 .phy_read = mv88e6xxx_g2_smi_phy_read,
2874 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002875 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002876 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002877 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002878 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002879 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002880 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002881 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002882 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002883 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002884 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002885 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002886 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002887 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002888 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002889 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002890 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2891 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002892 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002893 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2894 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002895 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002896 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002897 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002898 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002899 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002900 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002901};
2902
2903static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002904 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002905 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2906 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002907 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002908 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2909 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002910 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002911 .phy_read = mv88e6xxx_g2_smi_phy_read,
2912 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002913 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002914 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002915 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002916 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002917 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002918 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002919 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002920 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002921 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002922 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002923 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002924 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002925 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002926 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002927 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002928 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2929 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002930 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002931 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2932 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002933 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002934 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002935 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002936 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002937 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002938 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002939 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002940 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002941 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002942};
2943
2944static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002945 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002946 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2947 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002948 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002949 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002950 .phy_read = mv88e6xxx_g2_smi_phy_read,
2951 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002952 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002953 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002954 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002955 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002956 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002957 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002958 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002959 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002960 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002961 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002962 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002963 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002964 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002965 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002966 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002967 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2968 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002969 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002970 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2971 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002972 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002973 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002974 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002975 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002976 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002977 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002978};
2979
2980static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002981 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002982 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2983 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002984 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002985 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2986 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002987 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002988 .phy_read = mv88e6xxx_g2_smi_phy_read,
2989 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002990 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002991 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002992 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002993 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002994 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002995 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002996 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002997 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002998 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002999 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003000 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003001 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003002 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003003 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003004 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003005 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3006 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003007 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003008 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3009 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003010 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003011 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003012 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003013 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003014 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003015 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003016 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003017 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003018 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003019};
3020
3021static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003022 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003023 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3024 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003025 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003026 .phy_read = mv88e6185_phy_ppu_read,
3027 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003028 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003029 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003030 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003031 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003032 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003033 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003034 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003035 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003036 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003037 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003038 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3039 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003040 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003041 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3042 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003043 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003044 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003045 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003046 .ppu_enable = mv88e6185_g1_ppu_enable,
3047 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003048 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003049 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003050 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003051};
3052
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003053static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003054 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003055 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003056 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3057 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003058 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3059 .phy_read = mv88e6xxx_g2_smi_phy_read,
3060 .phy_write = mv88e6xxx_g2_smi_phy_write,
3061 .port_set_link = mv88e6xxx_port_set_link,
3062 .port_set_duplex = mv88e6xxx_port_set_duplex,
3063 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3064 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003065 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003066 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003067 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003068 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003069 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003070 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003071 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003072 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003073 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003074 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3075 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003076 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003077 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3078 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003079 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003080 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003081 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003082 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003083 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003084 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3085 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003086 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003087 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003088};
3089
3090static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003091 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003092 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003093 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3094 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003095 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3096 .phy_read = mv88e6xxx_g2_smi_phy_read,
3097 .phy_write = mv88e6xxx_g2_smi_phy_write,
3098 .port_set_link = mv88e6xxx_port_set_link,
3099 .port_set_duplex = mv88e6xxx_port_set_duplex,
3100 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3101 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003102 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003103 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003104 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003105 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003106 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003107 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003108 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003109 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003110 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003111 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3112 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003113 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003114 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3115 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003116 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003117 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003118 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003119 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003120 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003121 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3122 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003123 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003124 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003125};
3126
3127static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003128 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003129 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003130 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3131 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003132 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3133 .phy_read = mv88e6xxx_g2_smi_phy_read,
3134 .phy_write = mv88e6xxx_g2_smi_phy_write,
3135 .port_set_link = mv88e6xxx_port_set_link,
3136 .port_set_duplex = mv88e6xxx_port_set_duplex,
3137 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3138 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003139 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003140 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003141 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003142 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003143 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003144 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003145 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003146 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003147 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003148 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3149 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003150 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003151 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3152 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003153 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003154 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003155 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003156 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003157 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003158 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3159 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003160 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003161 .avb_ops = &mv88e6390_avb_ops,
3162 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003163};
3164
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003165static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003166 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003167 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3168 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003169 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003170 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3171 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003172 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003173 .phy_read = mv88e6xxx_g2_smi_phy_read,
3174 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003175 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003176 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003177 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003178 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003179 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003180 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003181 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003182 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003183 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003184 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003185 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003186 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003187 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003188 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003189 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003190 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3191 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003192 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003193 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3194 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003195 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003196 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003197 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003198 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003199 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003200 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003201 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003202 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003203 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003204 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003205 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003206};
3207
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003208static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003209 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003210 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003211 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3212 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003213 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3214 .phy_read = mv88e6xxx_g2_smi_phy_read,
3215 .phy_write = mv88e6xxx_g2_smi_phy_write,
3216 .port_set_link = mv88e6xxx_port_set_link,
3217 .port_set_duplex = mv88e6xxx_port_set_duplex,
3218 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3219 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003220 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003221 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003222 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003223 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003224 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003225 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003226 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003227 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003228 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003229 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003230 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3231 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003232 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003233 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3234 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003235 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003236 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003237 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003238 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003239 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003240 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3241 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003242 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003243 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003244 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003245 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003246};
3247
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003248static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003249 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003250 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3251 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003252 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003253 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3254 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003255 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003256 .phy_read = mv88e6xxx_g2_smi_phy_read,
3257 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003258 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003259 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003260 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003261 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003262 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003263 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003264 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003265 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003266 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003267 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003268 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003269 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003270 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003271 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003272 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3273 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003274 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003275 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3276 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003277 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003278 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003279 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003280 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003281 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003282 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003283 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003284 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003285};
3286
3287static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003288 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003289 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3290 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003291 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003292 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3293 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003294 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003295 .phy_read = mv88e6xxx_g2_smi_phy_read,
3296 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003297 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003298 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003299 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003300 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003301 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003302 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003303 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003304 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003305 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003306 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003307 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003308 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003309 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003310 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003311 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3312 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003313 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003314 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3315 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003316 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003317 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003318 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003319 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003320 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003321 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003322};
3323
Vivien Didelot16e329a2017-03-28 13:50:33 -04003324static const struct mv88e6xxx_ops mv88e6341_ops = {
3325 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003326 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3327 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003328 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003329 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3330 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3331 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3332 .phy_read = mv88e6xxx_g2_smi_phy_read,
3333 .phy_write = mv88e6xxx_g2_smi_phy_write,
3334 .port_set_link = mv88e6xxx_port_set_link,
3335 .port_set_duplex = mv88e6xxx_port_set_duplex,
3336 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3337 .port_set_speed = mv88e6390_port_set_speed,
3338 .port_tag_remap = mv88e6095_port_tag_remap,
3339 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3340 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3341 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003342 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003343 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003344 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003345 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3346 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3347 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003348 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003349 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3350 .stats_get_strings = mv88e6320_stats_get_strings,
3351 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003352 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3353 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003354 .watchdog_ops = &mv88e6390_watchdog_ops,
3355 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003356 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003357 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003358 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003359 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6751e7c2018-07-31 19:19:50 +02003360 .serdes_power = mv88e6341_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003361 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003362 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003363 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003364};
3365
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003366static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003367 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003368 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3369 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003370 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003371 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003372 .phy_read = mv88e6xxx_g2_smi_phy_read,
3373 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003374 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003375 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003376 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003377 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003378 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003379 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003380 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003381 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003382 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003383 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003384 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003385 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003386 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003387 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003388 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003389 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3390 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003391 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003392 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3393 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003394 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003395 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003396 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003397 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003398 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003399 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003400};
3401
3402static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003403 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003404 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3405 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003406 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003407 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003408 .phy_read = mv88e6xxx_g2_smi_phy_read,
3409 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003410 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003411 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003412 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003413 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003414 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003415 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003416 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003417 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003418 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003419 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003420 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003421 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003422 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003423 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003424 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003425 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3426 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003427 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003428 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3429 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003430 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003431 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003432 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003433 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003434 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003435 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003436 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003437 .ptp_ops = &mv88e6352_ptp_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003438};
3439
3440static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003441 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003442 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3443 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003444 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003445 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3446 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003447 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003448 .phy_read = mv88e6xxx_g2_smi_phy_read,
3449 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003450 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003451 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003452 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003453 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003454 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003455 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003456 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003457 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003458 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003459 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003460 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003461 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003462 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003463 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003464 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003465 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3466 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003467 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003468 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3469 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003470 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003471 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003472 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003473 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003474 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003475 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003476 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003477 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003478 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003479 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003480 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01003481 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
3482 .serdes_get_strings = mv88e6352_serdes_get_strings,
3483 .serdes_get_stats = mv88e6352_serdes_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003484};
3485
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003486static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003487 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003488 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003489 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3490 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003491 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3492 .phy_read = mv88e6xxx_g2_smi_phy_read,
3493 .phy_write = mv88e6xxx_g2_smi_phy_write,
3494 .port_set_link = mv88e6xxx_port_set_link,
3495 .port_set_duplex = mv88e6xxx_port_set_duplex,
3496 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3497 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003498 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003499 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003500 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003501 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003502 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003503 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003504 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003505 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003506 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003507 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003508 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003509 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003510 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3511 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003512 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003513 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3514 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003515 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003516 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003517 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003518 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003519 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003520 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3521 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003522 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003523 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003524 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003525 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003526};
3527
3528static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003529 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003530 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003531 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3532 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003533 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3534 .phy_read = mv88e6xxx_g2_smi_phy_read,
3535 .phy_write = mv88e6xxx_g2_smi_phy_write,
3536 .port_set_link = mv88e6xxx_port_set_link,
3537 .port_set_duplex = mv88e6xxx_port_set_duplex,
3538 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3539 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003540 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003541 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003542 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003543 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003544 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003545 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003546 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003547 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003548 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003549 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003550 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003551 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003552 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3553 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003554 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003555 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3556 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003557 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003558 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003559 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003560 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003561 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003562 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3563 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003564 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003565 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003566 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003567 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003568};
3569
Vivien Didelotf81ec902016-05-09 13:22:58 -04003570static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3571 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003572 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003573 .family = MV88E6XXX_FAMILY_6097,
3574 .name = "Marvell 88E6085",
3575 .num_databases = 4096,
3576 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003577 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003578 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003579 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003580 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003581 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003582 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003583 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003584 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003585 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003586 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003587 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003588 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003589 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003590 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003591 },
3592
3593 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003594 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003595 .family = MV88E6XXX_FAMILY_6095,
3596 .name = "Marvell 88E6095/88E6095F",
3597 .num_databases = 256,
3598 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003599 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003600 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003601 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003602 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003603 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003604 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003605 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003606 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003607 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003608 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003609 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003610 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003611 },
3612
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003613 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003614 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003615 .family = MV88E6XXX_FAMILY_6097,
3616 .name = "Marvell 88E6097/88E6097F",
3617 .num_databases = 4096,
3618 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003619 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003620 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003621 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003622 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003623 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003624 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003625 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003626 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003627 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003628 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003629 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003630 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003631 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003632 .ops = &mv88e6097_ops,
3633 },
3634
Vivien Didelotf81ec902016-05-09 13:22:58 -04003635 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003636 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003637 .family = MV88E6XXX_FAMILY_6165,
3638 .name = "Marvell 88E6123",
3639 .num_databases = 4096,
3640 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01003641 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003642 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003643 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003644 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003645 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003646 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003647 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003648 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003649 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003650 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003651 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003652 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003653 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003654 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003655 },
3656
3657 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003658 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003659 .family = MV88E6XXX_FAMILY_6185,
3660 .name = "Marvell 88E6131",
3661 .num_databases = 256,
3662 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003663 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003664 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003665 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003666 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003667 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003668 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003669 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003670 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003671 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003672 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003673 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003674 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003675 },
3676
Vivien Didelot990e27b2017-03-28 13:50:32 -04003677 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003678 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003679 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01003680 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04003681 .num_databases = 4096,
3682 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003683 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003684 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003685 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003686 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003687 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003688 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003689 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003690 .age_time_coeff = 3750,
3691 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003692 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003693 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003694 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003695 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003696 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003697 .ops = &mv88e6141_ops,
3698 },
3699
Vivien Didelotf81ec902016-05-09 13:22:58 -04003700 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003701 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003702 .family = MV88E6XXX_FAMILY_6165,
3703 .name = "Marvell 88E6161",
3704 .num_databases = 4096,
3705 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003706 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003707 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003708 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003709 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003710 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003711 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003712 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003713 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003714 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003715 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003716 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003717 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003718 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02003719 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003720 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003721 },
3722
3723 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003724 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003725 .family = MV88E6XXX_FAMILY_6165,
3726 .name = "Marvell 88E6165",
3727 .num_databases = 4096,
3728 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003729 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003730 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003731 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003732 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003733 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003734 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003735 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003736 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003737 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003738 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003739 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003740 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003741 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02003742 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003743 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003744 },
3745
3746 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003747 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003748 .family = MV88E6XXX_FAMILY_6351,
3749 .name = "Marvell 88E6171",
3750 .num_databases = 4096,
3751 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003752 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003753 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003754 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003755 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003756 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003757 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003758 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003759 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003760 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003761 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003762 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003763 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003764 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003765 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003766 },
3767
3768 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003769 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003770 .family = MV88E6XXX_FAMILY_6352,
3771 .name = "Marvell 88E6172",
3772 .num_databases = 4096,
3773 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003774 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003775 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003776 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003777 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003778 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003779 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003780 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003781 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003782 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003783 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003784 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003785 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003786 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003787 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003788 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003789 },
3790
3791 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003792 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003793 .family = MV88E6XXX_FAMILY_6351,
3794 .name = "Marvell 88E6175",
3795 .num_databases = 4096,
3796 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003797 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003798 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003799 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003800 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003801 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003802 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003803 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003804 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003805 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003806 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003807 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003808 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003809 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003810 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003811 },
3812
3813 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003814 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003815 .family = MV88E6XXX_FAMILY_6352,
3816 .name = "Marvell 88E6176",
3817 .num_databases = 4096,
3818 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003819 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003820 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003821 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003822 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003823 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003824 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003825 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003826 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003827 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003828 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003829 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003830 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003831 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003832 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003833 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003834 },
3835
3836 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003837 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003838 .family = MV88E6XXX_FAMILY_6185,
3839 .name = "Marvell 88E6185",
3840 .num_databases = 256,
3841 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003842 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003843 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003844 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003845 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003846 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003847 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003848 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003849 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003850 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003851 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003852 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003853 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003854 },
3855
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003856 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003857 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003858 .family = MV88E6XXX_FAMILY_6390,
3859 .name = "Marvell 88E6190",
3860 .num_databases = 4096,
3861 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003862 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003863 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003864 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003865 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003866 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003867 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003868 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003869 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003870 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003871 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003872 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003873 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003874 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003875 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003876 .ops = &mv88e6190_ops,
3877 },
3878
3879 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003880 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003881 .family = MV88E6XXX_FAMILY_6390,
3882 .name = "Marvell 88E6190X",
3883 .num_databases = 4096,
3884 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003885 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003886 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003887 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003888 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003889 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003890 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003891 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003892 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003893 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003894 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003895 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003896 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003897 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003898 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003899 .ops = &mv88e6190x_ops,
3900 },
3901
3902 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003903 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003904 .family = MV88E6XXX_FAMILY_6390,
3905 .name = "Marvell 88E6191",
3906 .num_databases = 4096,
3907 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003908 .num_internal_phys = 11,
Vivien Didelot931d1822017-05-01 14:05:27 -04003909 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003910 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003911 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003912 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003913 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003914 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003915 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003916 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003917 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003918 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003919 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003920 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003921 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003922 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003923 },
3924
Vivien Didelotf81ec902016-05-09 13:22:58 -04003925 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003926 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003927 .family = MV88E6XXX_FAMILY_6352,
3928 .name = "Marvell 88E6240",
3929 .num_databases = 4096,
3930 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003931 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003932 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003933 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003934 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003935 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003936 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003937 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003938 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003939 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003940 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003941 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003942 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003943 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003944 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003945 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003946 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003947 },
3948
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003949 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003950 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003951 .family = MV88E6XXX_FAMILY_6390,
3952 .name = "Marvell 88E6290",
3953 .num_databases = 4096,
3954 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003955 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003956 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003957 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003958 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003959 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003960 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003961 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003962 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003963 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003964 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003965 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003966 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003967 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003968 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003969 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003970 .ops = &mv88e6290_ops,
3971 },
3972
Vivien Didelotf81ec902016-05-09 13:22:58 -04003973 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003974 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003975 .family = MV88E6XXX_FAMILY_6320,
3976 .name = "Marvell 88E6320",
3977 .num_databases = 4096,
3978 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003979 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003980 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003981 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003982 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003983 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003984 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003985 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003986 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003987 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003988 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003989 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003990 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003991 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003992 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003993 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003994 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003995 },
3996
3997 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003998 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003999 .family = MV88E6XXX_FAMILY_6320,
4000 .name = "Marvell 88E6321",
4001 .num_databases = 4096,
4002 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004003 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004004 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004005 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004006 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004007 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004008 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004009 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004010 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004011 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004012 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004013 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004014 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004015 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004016 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004017 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004018 },
4019
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004020 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004021 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004022 .family = MV88E6XXX_FAMILY_6341,
4023 .name = "Marvell 88E6341",
4024 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01004025 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004026 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004027 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004028 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004029 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004030 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004031 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004032 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004033 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05004034 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004035 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004036 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004037 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004038 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004039 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004040 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004041 .ops = &mv88e6341_ops,
4042 },
4043
Vivien Didelotf81ec902016-05-09 13:22:58 -04004044 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004045 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004046 .family = MV88E6XXX_FAMILY_6351,
4047 .name = "Marvell 88E6350",
4048 .num_databases = 4096,
4049 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004050 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004051 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004052 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004053 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004054 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004055 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004056 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004057 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004058 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004059 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004060 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004061 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004062 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004063 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004064 },
4065
4066 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004067 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004068 .family = MV88E6XXX_FAMILY_6351,
4069 .name = "Marvell 88E6351",
4070 .num_databases = 4096,
4071 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004072 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004073 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004074 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004075 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004076 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004077 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004078 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004079 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004080 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004081 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004082 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004083 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004084 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004085 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004086 },
4087
4088 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004089 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004090 .family = MV88E6XXX_FAMILY_6352,
4091 .name = "Marvell 88E6352",
4092 .num_databases = 4096,
4093 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004094 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004095 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004096 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004097 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004098 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004099 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004100 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004101 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004102 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004103 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004104 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004105 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004106 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004107 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004108 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004109 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004110 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004111 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004112 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004113 .family = MV88E6XXX_FAMILY_6390,
4114 .name = "Marvell 88E6390",
4115 .num_databases = 4096,
4116 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01004117 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004118 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004119 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004120 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004121 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004122 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004123 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004124 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004125 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004126 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004127 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004128 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004129 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004130 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004131 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004132 .ops = &mv88e6390_ops,
4133 },
4134 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004135 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004136 .family = MV88E6XXX_FAMILY_6390,
4137 .name = "Marvell 88E6390X",
4138 .num_databases = 4096,
4139 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01004140 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004141 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004142 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004143 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004144 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004145 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004146 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004147 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004148 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004149 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004150 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004151 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004152 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004153 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004154 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004155 .ops = &mv88e6390x_ops,
4156 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004157};
4158
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004159static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004160{
Vivien Didelota439c062016-04-17 13:23:58 -04004161 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004162
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004163 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4164 if (mv88e6xxx_table[i].prod_num == prod_num)
4165 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004166
Vivien Didelotb9b37712015-10-30 19:39:48 -04004167 return NULL;
4168}
4169
Vivien Didelotfad09c72016-06-21 12:28:20 -04004170static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004171{
4172 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004173 unsigned int prod_num, rev;
4174 u16 id;
4175 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004176
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004177 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04004178 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004179 mutex_unlock(&chip->reg_lock);
4180 if (err)
4181 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004182
Vivien Didelot107fcc12017-06-12 12:37:36 -04004183 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
4184 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004185
4186 info = mv88e6xxx_lookup_info(prod_num);
4187 if (!info)
4188 return -ENODEV;
4189
Vivien Didelotcaac8542016-06-20 13:14:09 -04004190 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004191 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004192
Vivien Didelotca070c12016-09-02 14:45:34 -04004193 err = mv88e6xxx_g2_require(chip);
4194 if (err)
4195 return err;
4196
Vivien Didelotfad09c72016-06-21 12:28:20 -04004197 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4198 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004199
4200 return 0;
4201}
4202
Vivien Didelotfad09c72016-06-21 12:28:20 -04004203static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004204{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004205 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004206
Vivien Didelotfad09c72016-06-21 12:28:20 -04004207 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4208 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004209 return NULL;
4210
Vivien Didelotfad09c72016-06-21 12:28:20 -04004211 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004212
Vivien Didelotfad09c72016-06-21 12:28:20 -04004213 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004214 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004215
Vivien Didelotfad09c72016-06-21 12:28:20 -04004216 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004217}
4218
Vivien Didelotfad09c72016-06-21 12:28:20 -04004219static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004220 struct mii_bus *bus, int sw_addr)
4221{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004222 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004223 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004224 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004225 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004226 else
4227 return -EINVAL;
4228
Vivien Didelotfad09c72016-06-21 12:28:20 -04004229 chip->bus = bus;
4230 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004231
4232 return 0;
4233}
4234
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08004235static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4236 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02004237{
Vivien Didelot04bed142016-08-31 18:06:13 -04004238 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004239
Andrew Lunn443d5a12016-12-03 04:35:18 +01004240 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004241}
4242
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004243#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004244static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4245 struct device *host_dev, int sw_addr,
4246 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004247{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004248 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004249 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004250 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004251
Vivien Didelota439c062016-04-17 13:23:58 -04004252 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004253 if (!bus)
4254 return NULL;
4255
Vivien Didelotfad09c72016-06-21 12:28:20 -04004256 chip = mv88e6xxx_alloc_chip(dsa_dev);
4257 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004258 return NULL;
4259
Vivien Didelotcaac8542016-06-20 13:14:09 -04004260 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004261 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004262
Vivien Didelotfad09c72016-06-21 12:28:20 -04004263 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004264 if (err)
4265 goto free;
4266
Vivien Didelotfad09c72016-06-21 12:28:20 -04004267 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004268 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004269 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004270
Andrew Lunndc30c352016-10-16 19:56:49 +02004271 mutex_lock(&chip->reg_lock);
4272 err = mv88e6xxx_switch_reset(chip);
4273 mutex_unlock(&chip->reg_lock);
4274 if (err)
4275 goto free;
4276
Vivien Didelote57e5e72016-08-15 17:19:00 -04004277 mv88e6xxx_phy_init(chip);
4278
Andrew Lunna3c53be52017-01-24 14:53:50 +01004279 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004280 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004281 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004282
Vivien Didelotfad09c72016-06-21 12:28:20 -04004283 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004284
Vivien Didelotfad09c72016-06-21 12:28:20 -04004285 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004286free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004287 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004288
4289 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004290}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004291#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02004292
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004293static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004294 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004295{
4296 /* We don't need any dynamic resource from the kernel (yet),
4297 * so skip the prepare phase.
4298 */
4299
4300 return 0;
4301}
4302
4303static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004304 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004305{
Vivien Didelot04bed142016-08-31 18:06:13 -04004306 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004307
4308 mutex_lock(&chip->reg_lock);
4309 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004310 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004311 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4312 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004313 mutex_unlock(&chip->reg_lock);
4314}
4315
4316static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4317 const struct switchdev_obj_port_mdb *mdb)
4318{
Vivien Didelot04bed142016-08-31 18:06:13 -04004319 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004320 int err;
4321
4322 mutex_lock(&chip->reg_lock);
4323 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004324 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004325 mutex_unlock(&chip->reg_lock);
4326
4327 return err;
4328}
4329
Florian Fainellia82f67a2017-01-08 14:52:08 -08004330static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004331#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004332 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004333#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02004334 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004335 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004336 .adjust_link = mv88e6xxx_adjust_link,
Russell Kingc9a23562018-05-10 13:17:35 -07004337 .phylink_validate = mv88e6xxx_validate,
4338 .phylink_mac_link_state = mv88e6xxx_link_state,
4339 .phylink_mac_config = mv88e6xxx_mac_config,
4340 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
4341 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004342 .get_strings = mv88e6xxx_get_strings,
4343 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4344 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004345 .port_enable = mv88e6xxx_port_enable,
4346 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004347 .get_mac_eee = mv88e6xxx_get_mac_eee,
4348 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004349 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004350 .get_eeprom = mv88e6xxx_get_eeprom,
4351 .set_eeprom = mv88e6xxx_set_eeprom,
4352 .get_regs_len = mv88e6xxx_get_regs_len,
4353 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004354 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004355 .port_bridge_join = mv88e6xxx_port_bridge_join,
4356 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4357 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004358 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004359 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4360 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4361 .port_vlan_add = mv88e6xxx_port_vlan_add,
4362 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004363 .port_fdb_add = mv88e6xxx_port_fdb_add,
4364 .port_fdb_del = mv88e6xxx_port_fdb_del,
4365 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004366 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4367 .port_mdb_add = mv88e6xxx_port_mdb_add,
4368 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004369 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4370 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004371 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4372 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4373 .port_txtstamp = mv88e6xxx_port_txtstamp,
4374 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4375 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004376};
4377
Florian Fainelliab3d4082017-01-08 14:52:07 -08004378static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4379 .ops = &mv88e6xxx_switch_ops,
4380};
4381
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004382static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004383{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004384 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004385 struct dsa_switch *ds;
4386
Vivien Didelot73b12042017-03-30 17:37:10 -04004387 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004388 if (!ds)
4389 return -ENOMEM;
4390
Vivien Didelotfad09c72016-06-21 12:28:20 -04004391 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004392 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004393 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004394 ds->ageing_time_min = chip->info->age_time_coeff;
4395 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004396
4397 dev_set_drvdata(dev, ds);
4398
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004399 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004400}
4401
Vivien Didelotfad09c72016-06-21 12:28:20 -04004402static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004403{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004404 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004405}
4406
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004407static const void *pdata_device_get_match_data(struct device *dev)
4408{
4409 const struct of_device_id *matches = dev->driver->of_match_table;
4410 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
4411
4412 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
4413 matches++) {
4414 if (!strcmp(pdata->compatible, matches->compatible))
4415 return matches->data;
4416 }
4417 return NULL;
4418}
4419
Vivien Didelot57d32312016-06-20 13:13:58 -04004420static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004421{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004422 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04004423 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004424 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004425 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004426 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004427 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02004428 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004429
Andrew Lunn7bb8c992018-05-31 00:15:42 +02004430 if (!np && !pdata)
4431 return -EINVAL;
4432
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004433 if (np)
4434 compat_info = of_device_get_match_data(dev);
4435
4436 if (pdata) {
4437 compat_info = pdata_device_get_match_data(dev);
4438
4439 if (!pdata->netdev)
4440 return -EINVAL;
4441
4442 for (port = 0; port < DSA_MAX_PORTS; port++) {
4443 if (!(pdata->enabled_ports & (1 << port)))
4444 continue;
4445 if (strcmp(pdata->cd.port_names[port], "cpu"))
4446 continue;
4447 pdata->cd.netdev[port] = &pdata->netdev->dev;
4448 break;
4449 }
4450 }
4451
Vivien Didelotcaac8542016-06-20 13:14:09 -04004452 if (!compat_info)
4453 return -EINVAL;
4454
Vivien Didelotfad09c72016-06-21 12:28:20 -04004455 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004456 if (!chip) {
4457 err = -ENOMEM;
4458 goto out;
4459 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004460
Vivien Didelotfad09c72016-06-21 12:28:20 -04004461 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004462
Vivien Didelotfad09c72016-06-21 12:28:20 -04004463 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004464 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004465 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004466
Andrew Lunnb4308f02016-11-21 23:26:55 +01004467 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004468 if (IS_ERR(chip->reset)) {
4469 err = PTR_ERR(chip->reset);
4470 goto out;
4471 }
Andrew Lunnb4308f02016-11-21 23:26:55 +01004472
Vivien Didelotfad09c72016-06-21 12:28:20 -04004473 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004474 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004475 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004476
Vivien Didelote57e5e72016-08-15 17:19:00 -04004477 mv88e6xxx_phy_init(chip);
4478
Andrew Lunn00baabe2018-05-19 22:31:35 +02004479 if (chip->info->ops->get_eeprom) {
4480 if (np)
4481 of_property_read_u32(np, "eeprom-length",
4482 &chip->eeprom_len);
4483 else
4484 chip->eeprom_len = pdata->eeprom_len;
4485 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004486
Andrew Lunndc30c352016-10-16 19:56:49 +02004487 mutex_lock(&chip->reg_lock);
4488 err = mv88e6xxx_switch_reset(chip);
4489 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004490 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004491 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004492
Andrew Lunndc30c352016-10-16 19:56:49 +02004493 chip->irq = of_irq_get(np, 0);
4494 if (chip->irq == -EPROBE_DEFER) {
4495 err = chip->irq;
4496 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004497 }
4498
Andrew Lunn294d7112018-02-22 22:58:32 +01004499 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01004500 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01004501 * controllers
4502 */
4503 mutex_lock(&chip->reg_lock);
4504 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004505 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004506 else
4507 err = mv88e6xxx_irq_poll_setup(chip);
4508 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004509
Andrew Lunn294d7112018-02-22 22:58:32 +01004510 if (err)
4511 goto out;
4512
4513 if (chip->info->g2_irqs > 0) {
4514 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004515 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004516 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004517 }
4518
Andrew Lunn294d7112018-02-22 22:58:32 +01004519 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4520 if (err)
4521 goto out_g2_irq;
4522
4523 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4524 if (err)
4525 goto out_g1_atu_prob_irq;
4526
Andrew Lunna3c53be52017-01-24 14:53:50 +01004527 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004528 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004529 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004530
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004531 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004532 if (err)
4533 goto out_mdio;
4534
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004535 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004536
4537out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004538 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004539out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004540 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004541out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004542 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004543out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004544 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004545 mv88e6xxx_g2_irq_free(chip);
4546out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004547 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004548 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004549 else
4550 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004551out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004552 if (pdata)
4553 dev_put(pdata->netdev);
4554
Andrew Lunndc30c352016-10-16 19:56:49 +02004555 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004556}
4557
4558static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4559{
4560 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004561 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004562
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004563 if (chip->info->ptp_support) {
4564 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004565 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004566 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004567
Andrew Lunn930188c2016-08-22 16:01:03 +02004568 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004569 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004570 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004571
Andrew Lunn76f38f12018-03-17 20:21:09 +01004572 mv88e6xxx_g1_vtu_prob_irq_free(chip);
4573 mv88e6xxx_g1_atu_prob_irq_free(chip);
4574
4575 if (chip->info->g2_irqs > 0)
4576 mv88e6xxx_g2_irq_free(chip);
4577
Andrew Lunn76f38f12018-03-17 20:21:09 +01004578 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004579 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01004580 else
4581 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004582}
4583
4584static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004585 {
4586 .compatible = "marvell,mv88e6085",
4587 .data = &mv88e6xxx_table[MV88E6085],
4588 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004589 {
4590 .compatible = "marvell,mv88e6190",
4591 .data = &mv88e6xxx_table[MV88E6190],
4592 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004593 { /* sentinel */ },
4594};
4595
4596MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4597
4598static struct mdio_driver mv88e6xxx_driver = {
4599 .probe = mv88e6xxx_probe,
4600 .remove = mv88e6xxx_remove,
4601 .mdiodrv.driver = {
4602 .name = "mv88e6085",
4603 .of_match_table = mv88e6xxx_of_match,
4604 },
4605};
4606
Ben Hutchings98e67302011-11-25 14:36:19 +00004607static int __init mv88e6xxx_init(void)
4608{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004609 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004610 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004611}
4612module_init(mv88e6xxx_init);
4613
4614static void __exit mv88e6xxx_cleanup(void)
4615{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004616 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004617 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004618}
4619module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004620
4621MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4622MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4623MODULE_LICENSE("GPL");