blob: 5d933549dc49f89a630c4c699712c3d47464f3e8 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
7 *
Vivien Didelot4333d612017-03-28 15:10:36 -04008 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
9 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040035
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040036#include "chip.h"
Vivien Didelota935c052016-09-29 12:21:53 -040037#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040038#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010039#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020040#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010041#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010042#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020043#include "serdes.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000044
Vivien Didelotfad09c72016-06-21 12:28:20 -040045static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046{
Vivien Didelotfad09c72016-06-21 12:28:20 -040047 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
48 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040049 dump_stack();
50 }
51}
52
Vivien Didelot914b32f2016-06-20 13:14:11 -040053/* The switch ADDR[4:1] configuration pins define the chip SMI device address
54 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
55 *
56 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
57 * is the only device connected to the SMI master. In this mode it responds to
58 * all 32 possible SMI addresses, and thus maps directly the internal devices.
59 *
60 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
61 * multiple devices to share the SMI interface. In this mode it responds to only
62 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000063 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040064
Vivien Didelotfad09c72016-06-21 12:28:20 -040065static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 int addr, int reg, u16 *val)
67{
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040069 return -EOPNOTSUPP;
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040072}
73
Vivien Didelotfad09c72016-06-21 12:28:20 -040074static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 int addr, int reg, u16 val)
76{
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040078 return -EOPNOTSUPP;
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040081}
82
Vivien Didelotfad09c72016-06-21 12:28:20 -040083static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040084 int addr, int reg, u16 *val)
85{
86 int ret;
87
Vivien Didelotfad09c72016-06-21 12:28:20 -040088 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040089 if (ret < 0)
90 return ret;
91
92 *val = ret & 0xffff;
93
94 return 0;
95}
96
Vivien Didelotfad09c72016-06-21 12:28:20 -040097static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040098 int addr, int reg, u16 val)
99{
100 int ret;
101
Vivien Didelotfad09c72016-06-21 12:28:20 -0400102 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400103 if (ret < 0)
104 return ret;
105
106 return 0;
107}
108
Vivien Didelotc08026a2016-09-29 12:21:59 -0400109static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400110 .read = mv88e6xxx_smi_single_chip_read,
111 .write = mv88e6xxx_smi_single_chip_write,
112};
113
Vivien Didelotfad09c72016-06-21 12:28:20 -0400114static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000115{
116 int ret;
117 int i;
118
119 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400120 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000121 if (ret < 0)
122 return ret;
123
Andrew Lunncca8b132015-04-02 04:06:39 +0200124 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000125 return 0;
126 }
127
128 return -ETIMEDOUT;
129}
130
Vivien Didelotfad09c72016-06-21 12:28:20 -0400131static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400132 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000133{
134 int ret;
135
Barry Grussling3675c8d2013-01-08 16:05:53 +0000136 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400137 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000138 if (ret < 0)
139 return ret;
140
Barry Grussling3675c8d2013-01-08 16:05:53 +0000141 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400142 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200143 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000144 if (ret < 0)
145 return ret;
146
Barry Grussling3675c8d2013-01-08 16:05:53 +0000147 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400148 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000149 if (ret < 0)
150 return ret;
151
Barry Grussling3675c8d2013-01-08 16:05:53 +0000152 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400153 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000154 if (ret < 0)
155 return ret;
156
Vivien Didelot914b32f2016-06-20 13:14:11 -0400157 *val = ret & 0xffff;
158
159 return 0;
160}
161
Vivien Didelotfad09c72016-06-21 12:28:20 -0400162static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400163 int addr, int reg, u16 val)
164{
165 int ret;
166
167 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400168 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400169 if (ret < 0)
170 return ret;
171
172 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400173 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400174 if (ret < 0)
175 return ret;
176
177 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400178 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400179 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
180 if (ret < 0)
181 return ret;
182
183 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400184 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400185 if (ret < 0)
186 return ret;
187
188 return 0;
189}
190
Vivien Didelotc08026a2016-09-29 12:21:59 -0400191static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400192 .read = mv88e6xxx_smi_multi_chip_read,
193 .write = mv88e6xxx_smi_multi_chip_write,
194};
195
Vivien Didelotec561272016-09-02 14:45:33 -0400196int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400197{
198 int err;
199
Vivien Didelotfad09c72016-06-21 12:28:20 -0400200 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400201
Vivien Didelotfad09c72016-06-21 12:28:20 -0400202 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400203 if (err)
204 return err;
205
Vivien Didelotfad09c72016-06-21 12:28:20 -0400206 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400207 addr, reg, *val);
208
209 return 0;
210}
211
Vivien Didelotec561272016-09-02 14:45:33 -0400212int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400213{
214 int err;
215
Vivien Didelotfad09c72016-06-21 12:28:20 -0400216 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400217
Vivien Didelotfad09c72016-06-21 12:28:20 -0400218 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400219 if (err)
220 return err;
221
Vivien Didelotfad09c72016-06-21 12:28:20 -0400222 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400223 addr, reg, val);
224
225 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000226}
227
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200228struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100229{
230 struct mv88e6xxx_mdio_bus *mdio_bus;
231
232 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
233 list);
234 if (!mdio_bus)
235 return NULL;
236
237 return mdio_bus->bus;
238}
239
Andrew Lunndc30c352016-10-16 19:56:49 +0200240static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
241{
242 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
243 unsigned int n = d->hwirq;
244
245 chip->g1_irq.masked |= (1 << n);
246}
247
248static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
249{
250 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
251 unsigned int n = d->hwirq;
252
253 chip->g1_irq.masked &= ~(1 << n);
254}
255
Andrew Lunn294d7112018-02-22 22:58:32 +0100256static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200257{
Andrew Lunndc30c352016-10-16 19:56:49 +0200258 unsigned int nhandled = 0;
259 unsigned int sub_irq;
260 unsigned int n;
261 u16 reg;
262 int err;
263
264 mutex_lock(&chip->reg_lock);
Vivien Didelot82466922017-06-15 12:13:59 -0400265 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200266 mutex_unlock(&chip->reg_lock);
267
268 if (err)
269 goto out;
270
271 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
272 if (reg & (1 << n)) {
273 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
274 handle_nested_irq(sub_irq);
275 ++nhandled;
276 }
277 }
278out:
279 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
280}
281
Andrew Lunn294d7112018-02-22 22:58:32 +0100282static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
283{
284 struct mv88e6xxx_chip *chip = dev_id;
285
286 return mv88e6xxx_g1_irq_thread_work(chip);
287}
288
Andrew Lunndc30c352016-10-16 19:56:49 +0200289static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
290{
291 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
292
293 mutex_lock(&chip->reg_lock);
294}
295
296static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
297{
298 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
299 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
300 u16 reg;
301 int err;
302
Vivien Didelotd77f4322017-06-15 12:14:03 -0400303 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200304 if (err)
305 goto out;
306
307 reg &= ~mask;
308 reg |= (~chip->g1_irq.masked & mask);
309
Vivien Didelotd77f4322017-06-15 12:14:03 -0400310 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200311 if (err)
312 goto out;
313
314out:
315 mutex_unlock(&chip->reg_lock);
316}
317
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530318static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200319 .name = "mv88e6xxx-g1",
320 .irq_mask = mv88e6xxx_g1_irq_mask,
321 .irq_unmask = mv88e6xxx_g1_irq_unmask,
322 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
323 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
324};
325
326static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
327 unsigned int irq,
328 irq_hw_number_t hwirq)
329{
330 struct mv88e6xxx_chip *chip = d->host_data;
331
332 irq_set_chip_data(irq, d->host_data);
333 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
334 irq_set_noprobe(irq);
335
336 return 0;
337}
338
339static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
340 .map = mv88e6xxx_g1_irq_domain_map,
341 .xlate = irq_domain_xlate_twocell,
342};
343
Andrew Lunn294d7112018-02-22 22:58:32 +0100344static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200345{
346 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100347 u16 mask;
348
Vivien Didelotd77f4322017-06-15 12:14:03 -0400349 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100350 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400351 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100352
Andreas Färber5edef2f2016-11-27 23:26:28 +0100353 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100354 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200355 irq_dispose_mapping(virq);
356 }
357
Andrew Lunna3db3d32016-11-20 20:14:14 +0100358 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200359}
360
Andrew Lunn294d7112018-02-22 22:58:32 +0100361static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
362{
Andrew Lunnb19e5c12018-03-08 21:21:36 +0100363 mv88e6xxx_g1_irq_free_common(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100364
365 free_irq(chip->irq, chip);
366}
367
368static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200369{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100370 int err, irq, virq;
371 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200372
373 chip->g1_irq.nirqs = chip->info->g1_irqs;
374 chip->g1_irq.domain = irq_domain_add_simple(
375 NULL, chip->g1_irq.nirqs, 0,
376 &mv88e6xxx_g1_irq_domain_ops, chip);
377 if (!chip->g1_irq.domain)
378 return -ENOMEM;
379
380 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
381 irq_create_mapping(chip->g1_irq.domain, irq);
382
383 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
384 chip->g1_irq.masked = ~0;
385
Vivien Didelotd77f4322017-06-15 12:14:03 -0400386 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200387 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100388 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200389
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100390 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200391
Vivien Didelotd77f4322017-06-15 12:14:03 -0400392 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200393 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100394 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200395
396 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400397 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200398 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100399 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200400
Andrew Lunndc30c352016-10-16 19:56:49 +0200401 return 0;
402
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100403out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100404 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400405 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100406
407out_mapping:
408 for (irq = 0; irq < 16; irq++) {
409 virq = irq_find_mapping(chip->g1_irq.domain, irq);
410 irq_dispose_mapping(virq);
411 }
412
413 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200414
415 return err;
416}
417
Andrew Lunn294d7112018-02-22 22:58:32 +0100418static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
419{
420 int err;
421
422 err = mv88e6xxx_g1_irq_setup_common(chip);
423 if (err)
424 return err;
425
426 err = request_threaded_irq(chip->irq, NULL,
427 mv88e6xxx_g1_irq_thread_fn,
Andrew Lunn422a9fd62018-03-25 23:43:14 +0200428 IRQF_ONESHOT,
Andrew Lunn294d7112018-02-22 22:58:32 +0100429 dev_name(chip->dev), chip);
430 if (err)
431 mv88e6xxx_g1_irq_free_common(chip);
432
433 return err;
434}
435
436static void mv88e6xxx_irq_poll(struct kthread_work *work)
437{
438 struct mv88e6xxx_chip *chip = container_of(work,
439 struct mv88e6xxx_chip,
440 irq_poll_work.work);
441 mv88e6xxx_g1_irq_thread_work(chip);
442
443 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
444 msecs_to_jiffies(100));
445}
446
447static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
448{
449 int err;
450
451 err = mv88e6xxx_g1_irq_setup_common(chip);
452 if (err)
453 return err;
454
455 kthread_init_delayed_work(&chip->irq_poll_work,
456 mv88e6xxx_irq_poll);
457
458 chip->kworker = kthread_create_worker(0, dev_name(chip->dev));
459 if (IS_ERR(chip->kworker))
460 return PTR_ERR(chip->kworker);
461
462 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
463 msecs_to_jiffies(100));
464
465 return 0;
466}
467
468static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
469{
Andrew Lunn71f74ae2018-03-25 23:43:15 +0200470 mv88e6xxx_g1_irq_free_common(chip);
471
Andrew Lunn294d7112018-02-22 22:58:32 +0100472 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
473 kthread_destroy_worker(chip->kworker);
474}
475
Vivien Didelotec561272016-09-02 14:45:33 -0400476int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400477{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200478 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400479
Andrew Lunn6441e6692016-08-19 00:01:55 +0200480 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400481 u16 val;
482 int err;
483
484 err = mv88e6xxx_read(chip, addr, reg, &val);
485 if (err)
486 return err;
487
488 if (!(val & mask))
489 return 0;
490
491 usleep_range(1000, 2000);
492 }
493
Andrew Lunn30853552016-08-19 00:01:57 +0200494 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400495 return -ETIMEDOUT;
496}
497
Vivien Didelotf22ab642016-07-18 20:45:31 -0400498/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400499int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400500{
501 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200502 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400503
504 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200505 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
506 if (err)
507 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400508
509 /* Set the Update bit to trigger a write operation */
510 val = BIT(15) | update;
511
512 return mv88e6xxx_write(chip, addr, reg, val);
513}
514
Vivien Didelotd78343d2016-11-04 03:23:36 +0100515static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
516 int link, int speed, int duplex,
517 phy_interface_t mode)
518{
519 int err;
520
521 if (!chip->info->ops->port_set_link)
522 return 0;
523
524 /* Port's MAC control must not be changed unless the link is down */
525 err = chip->info->ops->port_set_link(chip, port, 0);
526 if (err)
527 return err;
528
529 if (chip->info->ops->port_set_speed) {
530 err = chip->info->ops->port_set_speed(chip, port, speed);
531 if (err && err != -EOPNOTSUPP)
532 goto restore_link;
533 }
534
535 if (chip->info->ops->port_set_duplex) {
536 err = chip->info->ops->port_set_duplex(chip, port, duplex);
537 if (err && err != -EOPNOTSUPP)
538 goto restore_link;
539 }
540
541 if (chip->info->ops->port_set_rgmii_delay) {
542 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
543 if (err && err != -EOPNOTSUPP)
544 goto restore_link;
545 }
546
Andrew Lunnf39908d2017-02-04 20:02:50 +0100547 if (chip->info->ops->port_set_cmode) {
548 err = chip->info->ops->port_set_cmode(chip, port, mode);
549 if (err && err != -EOPNOTSUPP)
550 goto restore_link;
551 }
552
Vivien Didelotd78343d2016-11-04 03:23:36 +0100553 err = 0;
554restore_link:
555 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400556 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100557
558 return err;
559}
560
Andrew Lunndea87022015-08-31 15:56:47 +0200561/* We expect the switch to perform auto negotiation if there is a real
562 * phy. However, in the case of a fixed link phy, we force the port
563 * settings from the fixed link settings.
564 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400565static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
566 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200567{
Vivien Didelot04bed142016-08-31 18:06:13 -0400568 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200569 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200570
571 if (!phy_is_pseudo_fixed_link(phydev))
572 return;
573
Vivien Didelotfad09c72016-06-21 12:28:20 -0400574 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100575 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
576 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400577 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100578
579 if (err && err != -EOPNOTSUPP)
Vivien Didelot774439e52017-06-08 18:34:08 -0400580 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
Andrew Lunndea87022015-08-31 15:56:47 +0200581}
582
Andrew Lunna605a0f2016-11-21 23:26:58 +0100583static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000584{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100585 if (!chip->info->ops->stats_snapshot)
586 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000587
Andrew Lunna605a0f2016-11-21 23:26:58 +0100588 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000589}
590
Andrew Lunne413e7e2015-04-02 04:06:38 +0200591static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100592 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
593 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
594 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
595 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
596 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
597 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
598 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
599 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
600 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
601 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
602 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
603 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
604 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
605 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
606 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
607 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
608 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
609 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
610 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
611 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
612 { "single", 4, 0x14, STATS_TYPE_BANK0, },
613 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
614 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
615 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
616 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
617 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
618 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
619 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
620 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
621 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
622 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
623 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
624 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
625 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
626 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
627 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
628 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
629 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
630 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
631 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
632 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
633 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
634 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
635 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
636 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
637 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
638 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
639 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
640 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
641 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
642 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
643 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
644 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
645 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
646 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
647 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
648 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
649 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
650 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200651};
652
Vivien Didelotfad09c72016-06-21 12:28:20 -0400653static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100654 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100655 int port, u16 bank1_select,
656 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200657{
Andrew Lunn80c46272015-06-20 18:42:30 +0200658 u32 low;
659 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100660 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200661 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200662 u64 value;
663
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100664 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100665 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200666 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
667 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800668 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200669
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200670 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100671 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200672 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
673 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800674 return U64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200675 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200676 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100677 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100678 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100679 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100680 /* fall through */
681 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100682 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100683 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100684 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100685 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500686 break;
687 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800688 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200689 }
690 value = (((u64)high) << 16) | low;
691 return value;
692}
693
Andrew Lunn436fe172018-03-01 02:02:29 +0100694static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
695 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100696{
697 struct mv88e6xxx_hw_stat *stat;
698 int i, j;
699
700 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
701 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100702 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100703 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
704 ETH_GSTRING_LEN);
705 j++;
706 }
707 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100708
709 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100710}
711
Andrew Lunn436fe172018-03-01 02:02:29 +0100712static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
713 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100714{
Andrew Lunn436fe172018-03-01 02:02:29 +0100715 return mv88e6xxx_stats_get_strings(chip, data,
716 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100717}
718
Andrew Lunn436fe172018-03-01 02:02:29 +0100719static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
720 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100721{
Andrew Lunn436fe172018-03-01 02:02:29 +0100722 return mv88e6xxx_stats_get_strings(chip, data,
723 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100724}
725
Andrew Lunn65f60e42018-03-28 23:50:28 +0200726static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
727 "atu_member_violation",
728 "atu_miss_violation",
729 "atu_full_violation",
730 "vtu_member_violation",
731 "vtu_miss_violation",
732};
733
734static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
735{
736 unsigned int i;
737
738 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
739 strlcpy(data + i * ETH_GSTRING_LEN,
740 mv88e6xxx_atu_vtu_stats_strings[i],
741 ETH_GSTRING_LEN);
742}
743
Andrew Lunndfafe442016-11-21 23:27:02 +0100744static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700745 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100746{
Vivien Didelot04bed142016-08-31 18:06:13 -0400747 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100748 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100749
Florian Fainelli89f09042018-04-25 12:12:50 -0700750 if (stringset != ETH_SS_STATS)
751 return;
752
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100753 mutex_lock(&chip->reg_lock);
754
Andrew Lunndfafe442016-11-21 23:27:02 +0100755 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100756 count = chip->info->ops->stats_get_strings(chip, data);
757
758 if (chip->info->ops->serdes_get_strings) {
759 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200760 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100761 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100762
Andrew Lunn65f60e42018-03-28 23:50:28 +0200763 data += count * ETH_GSTRING_LEN;
764 mv88e6xxx_atu_vtu_get_strings(data);
765
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100766 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100767}
768
769static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
770 int types)
771{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100772 struct mv88e6xxx_hw_stat *stat;
773 int i, j;
774
775 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
776 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100777 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100778 j++;
779 }
780 return j;
781}
782
Andrew Lunndfafe442016-11-21 23:27:02 +0100783static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
784{
785 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
786 STATS_TYPE_PORT);
787}
788
789static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
790{
791 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
792 STATS_TYPE_BANK1);
793}
794
Florian Fainelli89f09042018-04-25 12:12:50 -0700795static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +0100796{
797 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100798 int serdes_count = 0;
799 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100800
Florian Fainelli89f09042018-04-25 12:12:50 -0700801 if (sset != ETH_SS_STATS)
802 return 0;
803
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100804 mutex_lock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100805 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100806 count = chip->info->ops->stats_get_sset_count(chip);
807 if (count < 0)
808 goto out;
809
810 if (chip->info->ops->serdes_get_sset_count)
811 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
812 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +0200813 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +0100814 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200815 goto out;
816 }
817 count += serdes_count;
818 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
819
Andrew Lunn436fe172018-03-01 02:02:29 +0100820out:
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100821 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100822
Andrew Lunn436fe172018-03-01 02:02:29 +0100823 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +0100824}
825
Andrew Lunn436fe172018-03-01 02:02:29 +0100826static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
827 uint64_t *data, int types,
828 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100829{
830 struct mv88e6xxx_hw_stat *stat;
831 int i, j;
832
833 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
834 stat = &mv88e6xxx_hw_stats[i];
835 if (stat->type & types) {
Andrew Lunn377cda12018-02-15 14:38:34 +0100836 mutex_lock(&chip->reg_lock);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100837 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
838 bank1_select,
839 histogram);
Andrew Lunn377cda12018-02-15 14:38:34 +0100840 mutex_unlock(&chip->reg_lock);
841
Andrew Lunn052f9472016-11-21 23:27:03 +0100842 j++;
843 }
844 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100845 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +0100846}
847
Andrew Lunn436fe172018-03-01 02:02:29 +0100848static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
849 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100850{
851 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100852 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400853 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100854}
855
Andrew Lunn436fe172018-03-01 02:02:29 +0100856static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
857 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100858{
859 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100860 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400861 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
862 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100863}
864
Andrew Lunn436fe172018-03-01 02:02:29 +0100865static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
866 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +0100867{
868 return mv88e6xxx_stats_get_stats(chip, port, data,
869 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400870 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
871 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100872}
873
Andrew Lunn65f60e42018-03-28 23:50:28 +0200874static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
875 uint64_t *data)
876{
877 *data++ = chip->ports[port].atu_member_violation;
878 *data++ = chip->ports[port].atu_miss_violation;
879 *data++ = chip->ports[port].atu_full_violation;
880 *data++ = chip->ports[port].vtu_member_violation;
881 *data++ = chip->ports[port].vtu_miss_violation;
882}
883
Andrew Lunn052f9472016-11-21 23:27:03 +0100884static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
885 uint64_t *data)
886{
Andrew Lunn436fe172018-03-01 02:02:29 +0100887 int count = 0;
888
Andrew Lunn052f9472016-11-21 23:27:03 +0100889 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +0100890 count = chip->info->ops->stats_get_stats(chip, port, data);
891
Andrew Lunn65f60e42018-03-28 23:50:28 +0200892 mutex_lock(&chip->reg_lock);
Andrew Lunn436fe172018-03-01 02:02:29 +0100893 if (chip->info->ops->serdes_get_stats) {
894 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200895 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100896 }
Andrew Lunn65f60e42018-03-28 23:50:28 +0200897 data += count;
898 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
899 mutex_unlock(&chip->reg_lock);
Andrew Lunn052f9472016-11-21 23:27:03 +0100900}
901
Vivien Didelotf81ec902016-05-09 13:22:58 -0400902static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
903 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000904{
Vivien Didelot04bed142016-08-31 18:06:13 -0400905 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000906 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000907
Vivien Didelotfad09c72016-06-21 12:28:20 -0400908 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000909
Andrew Lunna605a0f2016-11-21 23:26:58 +0100910 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +0100911 mutex_unlock(&chip->reg_lock);
912
913 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000914 return;
Andrew Lunn052f9472016-11-21 23:27:03 +0100915
916 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000917
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000918}
Ben Hutchings98e67302011-11-25 14:36:19 +0000919
Andrew Lunnde2273872016-11-21 23:27:01 +0100920static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
921{
922 if (chip->info->ops->stats_set_histogram)
923 return chip->info->ops->stats_set_histogram(chip);
924
925 return 0;
926}
927
Vivien Didelotf81ec902016-05-09 13:22:58 -0400928static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700929{
930 return 32 * sizeof(u16);
931}
932
Vivien Didelotf81ec902016-05-09 13:22:58 -0400933static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
934 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700935{
Vivien Didelot04bed142016-08-31 18:06:13 -0400936 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200937 int err;
938 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700939 u16 *p = _p;
940 int i;
941
942 regs->version = 0;
943
944 memset(p, 0xff, 32 * sizeof(u16));
945
Vivien Didelotfad09c72016-06-21 12:28:20 -0400946 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400947
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700948 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700949
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200950 err = mv88e6xxx_port_read(chip, port, i, &reg);
951 if (!err)
952 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700953 }
Vivien Didelot23062512016-05-09 13:22:45 -0400954
Vivien Didelotfad09c72016-06-21 12:28:20 -0400955 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700956}
957
Vivien Didelot08f50062017-08-01 16:32:41 -0400958static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
959 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800960{
Vivien Didelot5480db62017-08-01 16:32:40 -0400961 /* Nothing to do on the port's MAC */
962 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800963}
964
Vivien Didelot08f50062017-08-01 16:32:41 -0400965static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
966 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800967{
Vivien Didelot5480db62017-08-01 16:32:40 -0400968 /* Nothing to do on the port's MAC */
969 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800970}
971
Vivien Didelote5887a22017-03-30 17:37:11 -0400972static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700973{
Vivien Didelote5887a22017-03-30 17:37:11 -0400974 struct dsa_switch *ds = NULL;
975 struct net_device *br;
976 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500977 int i;
978
Vivien Didelote5887a22017-03-30 17:37:11 -0400979 if (dev < DSA_MAX_SWITCHES)
980 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500981
Vivien Didelote5887a22017-03-30 17:37:11 -0400982 /* Prevent frames from unknown switch or port */
983 if (!ds || port >= ds->num_ports)
984 return 0;
985
986 /* Frames from DSA links and CPU ports can egress any local port */
987 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
988 return mv88e6xxx_port_mask(chip);
989
990 br = ds->ports[port].bridge_dev;
991 pvlan = 0;
992
993 /* Frames from user ports can egress any local DSA links and CPU ports,
994 * as well as any local member of their bridge group.
995 */
996 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
997 if (dsa_is_cpu_port(chip->ds, i) ||
998 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -0400999 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -04001000 pvlan |= BIT(i);
1001
1002 return pvlan;
1003}
1004
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001005static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001006{
1007 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001008
1009 /* prevent frames from going back out of the port they came in on */
1010 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001011
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001012 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001013}
1014
Vivien Didelotf81ec902016-05-09 13:22:58 -04001015static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1016 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001017{
Vivien Didelot04bed142016-08-31 18:06:13 -04001018 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001019 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001020
Vivien Didelotfad09c72016-06-21 12:28:20 -04001021 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -04001022 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001023 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001024
1025 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001026 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001027}
1028
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001029static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1030{
1031 int target, port;
1032 int err;
1033
1034 if (!chip->info->global2_addr)
1035 return 0;
1036
1037 /* Initialize the routing port to the 32 possible target devices */
1038 for (target = 0; target < 32; target++) {
1039 port = 0x1f;
1040 if (target < DSA_MAX_SWITCHES)
1041 if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
1042 port = chip->ds->rtable[target];
1043
1044 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1045 if (err)
1046 return err;
1047 }
1048
Vivien Didelot02317e62018-05-09 11:38:49 -04001049 if (chip->info->ops->set_cascade_port) {
1050 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1051 err = chip->info->ops->set_cascade_port(chip, port);
1052 if (err)
1053 return err;
1054 }
1055
Vivien Didelot23c98912018-05-09 11:38:50 -04001056 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1057 if (err)
1058 return err;
1059
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001060 return 0;
1061}
1062
Vivien Didelotb28f8722018-04-26 21:56:44 -04001063static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1064{
1065 /* Clear all trunk masks and mapping */
1066 if (chip->info->global2_addr)
1067 return mv88e6xxx_g2_trunk_clear(chip);
1068
1069 return 0;
1070}
1071
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001072static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1073{
1074 if (chip->info->ops->rmu_disable)
1075 return chip->info->ops->rmu_disable(chip);
1076
1077 return 0;
1078}
1079
Vivien Didelot9e907d72017-07-17 13:03:43 -04001080static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1081{
1082 if (chip->info->ops->pot_clear)
1083 return chip->info->ops->pot_clear(chip);
1084
1085 return 0;
1086}
1087
Vivien Didelot51c901a2017-07-17 13:03:41 -04001088static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1089{
1090 if (chip->info->ops->mgmt_rsvd2cpu)
1091 return chip->info->ops->mgmt_rsvd2cpu(chip);
1092
1093 return 0;
1094}
1095
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001096static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1097{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001098 int err;
1099
Vivien Didelotdaefc942017-03-11 16:12:54 -05001100 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1101 if (err)
1102 return err;
1103
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001104 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1105 if (err)
1106 return err;
1107
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001108 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1109}
1110
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001111static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1112{
1113 int port;
1114 int err;
1115
1116 if (!chip->info->ops->irl_init_all)
1117 return 0;
1118
1119 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1120 /* Disable ingress rate limiting by resetting all per port
1121 * ingress rate limit resources to their initial state.
1122 */
1123 err = chip->info->ops->irl_init_all(chip, port);
1124 if (err)
1125 return err;
1126 }
1127
1128 return 0;
1129}
1130
Vivien Didelot04a69a12017-10-13 14:18:05 -04001131static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1132{
1133 if (chip->info->ops->set_switch_mac) {
1134 u8 addr[ETH_ALEN];
1135
1136 eth_random_addr(addr);
1137
1138 return chip->info->ops->set_switch_mac(chip, addr);
1139 }
1140
1141 return 0;
1142}
1143
Vivien Didelot17a15942017-03-30 17:37:09 -04001144static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1145{
1146 u16 pvlan = 0;
1147
1148 if (!mv88e6xxx_has_pvt(chip))
1149 return -EOPNOTSUPP;
1150
1151 /* Skip the local source device, which uses in-chip port VLAN */
1152 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001153 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001154
1155 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1156}
1157
Vivien Didelot81228992017-03-30 17:37:08 -04001158static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1159{
Vivien Didelot17a15942017-03-30 17:37:09 -04001160 int dev, port;
1161 int err;
1162
Vivien Didelot81228992017-03-30 17:37:08 -04001163 if (!mv88e6xxx_has_pvt(chip))
1164 return 0;
1165
1166 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1167 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1168 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001169 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1170 if (err)
1171 return err;
1172
1173 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1174 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1175 err = mv88e6xxx_pvt_map(chip, dev, port);
1176 if (err)
1177 return err;
1178 }
1179 }
1180
1181 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001182}
1183
Vivien Didelot749efcb2016-09-22 16:49:24 -04001184static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1185{
1186 struct mv88e6xxx_chip *chip = ds->priv;
1187 int err;
1188
1189 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001190 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001191 mutex_unlock(&chip->reg_lock);
1192
1193 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001194 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001195}
1196
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001197static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1198{
1199 if (!chip->info->max_vid)
1200 return 0;
1201
1202 return mv88e6xxx_g1_vtu_flush(chip);
1203}
1204
Vivien Didelotf1394b782017-05-01 14:05:22 -04001205static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1206 struct mv88e6xxx_vtu_entry *entry)
1207{
1208 if (!chip->info->ops->vtu_getnext)
1209 return -EOPNOTSUPP;
1210
1211 return chip->info->ops->vtu_getnext(chip, entry);
1212}
1213
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001214static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1215 struct mv88e6xxx_vtu_entry *entry)
1216{
1217 if (!chip->info->ops->vtu_loadpurge)
1218 return -EOPNOTSUPP;
1219
1220 return chip->info->ops->vtu_loadpurge(chip, entry);
1221}
1222
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001223static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001224{
1225 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001226 struct mv88e6xxx_vtu_entry vlan = {
1227 .vid = chip->info->max_vid,
1228 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001229 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001230
1231 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1232
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001233 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001234 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001235 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001236 if (err)
1237 return err;
1238
1239 set_bit(*fid, fid_bitmap);
1240 }
1241
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001242 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001243 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001244 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001245 if (err)
1246 return err;
1247
1248 if (!vlan.valid)
1249 break;
1250
1251 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001252 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001253
1254 /* The reset value 0x000 is used to indicate that multiple address
1255 * databases are not needed. Return the next positive available.
1256 */
1257 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001258 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001259 return -ENOSPC;
1260
1261 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001262 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001263}
1264
Vivien Didelot567aa592017-05-01 14:05:25 -04001265static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1266 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001267{
1268 int err;
1269
1270 if (!vid)
1271 return -EINVAL;
1272
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001273 entry->vid = vid - 1;
1274 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001275
Vivien Didelotf1394b782017-05-01 14:05:22 -04001276 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001277 if (err)
1278 return err;
1279
Vivien Didelot567aa592017-05-01 14:05:25 -04001280 if (entry->vid == vid && entry->valid)
1281 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001282
Vivien Didelot567aa592017-05-01 14:05:25 -04001283 if (new) {
1284 int i;
1285
1286 /* Initialize a fresh VLAN entry */
1287 memset(entry, 0, sizeof(*entry));
1288 entry->valid = true;
1289 entry->vid = vid;
1290
Vivien Didelot553a7682017-06-07 18:12:16 -04001291 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001292 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001293 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001294 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001295
1296 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001297 }
1298
Vivien Didelot567aa592017-05-01 14:05:25 -04001299 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1300 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001301}
1302
Vivien Didelotda9c3592016-02-12 12:09:40 -05001303static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1304 u16 vid_begin, u16 vid_end)
1305{
Vivien Didelot04bed142016-08-31 18:06:13 -04001306 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001307 struct mv88e6xxx_vtu_entry vlan = {
1308 .vid = vid_begin - 1,
1309 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001310 int i, err;
1311
Andrew Lunndb06ae412017-09-25 23:32:20 +02001312 /* DSA and CPU ports have to be members of multiple vlans */
1313 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1314 return 0;
1315
Vivien Didelotda9c3592016-02-12 12:09:40 -05001316 if (!vid_begin)
1317 return -EOPNOTSUPP;
1318
Vivien Didelotfad09c72016-06-21 12:28:20 -04001319 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001320
Vivien Didelotda9c3592016-02-12 12:09:40 -05001321 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001322 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001323 if (err)
1324 goto unlock;
1325
1326 if (!vlan.valid)
1327 break;
1328
1329 if (vlan.vid > vid_end)
1330 break;
1331
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001332 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001333 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1334 continue;
1335
Andrew Lunncd886462017-11-09 22:29:53 +01001336 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001337 continue;
1338
Vivien Didelotbd00e052017-05-01 14:05:11 -04001339 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001340 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001341 continue;
1342
Vivien Didelotc8652c82017-10-16 11:12:19 -04001343 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001344 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001345 break; /* same bridge, check next VLAN */
1346
Vivien Didelotc8652c82017-10-16 11:12:19 -04001347 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001348 continue;
1349
Andrew Lunn743fcc22017-11-09 22:29:54 +01001350 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1351 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001352 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001353 err = -EOPNOTSUPP;
1354 goto unlock;
1355 }
1356 } while (vlan.vid < vid_end);
1357
1358unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001359 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001360
1361 return err;
1362}
1363
Vivien Didelotf81ec902016-05-09 13:22:58 -04001364static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1365 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001366{
Vivien Didelot04bed142016-08-31 18:06:13 -04001367 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001368 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1369 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001370 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001371
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001372 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001373 return -EOPNOTSUPP;
1374
Vivien Didelotfad09c72016-06-21 12:28:20 -04001375 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001376 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001377 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001378
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001379 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001380}
1381
Vivien Didelot57d32312016-06-20 13:13:58 -04001382static int
1383mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001384 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001385{
Vivien Didelot04bed142016-08-31 18:06:13 -04001386 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001387 int err;
1388
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001389 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001390 return -EOPNOTSUPP;
1391
Vivien Didelotda9c3592016-02-12 12:09:40 -05001392 /* If the requested port doesn't belong to the same bridge as the VLAN
1393 * members, do not support it (yet) and fallback to software VLAN.
1394 */
1395 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1396 vlan->vid_end);
1397 if (err)
1398 return err;
1399
Vivien Didelot76e398a2015-11-01 12:33:55 -05001400 /* We don't need any dynamic resource from the kernel (yet),
1401 * so skip the prepare phase.
1402 */
1403 return 0;
1404}
1405
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001406static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1407 const unsigned char *addr, u16 vid,
1408 u8 state)
1409{
1410 struct mv88e6xxx_vtu_entry vlan;
1411 struct mv88e6xxx_atu_entry entry;
1412 int err;
1413
1414 /* Null VLAN ID corresponds to the port private database */
1415 if (vid == 0)
1416 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1417 else
1418 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1419 if (err)
1420 return err;
1421
1422 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1423 ether_addr_copy(entry.mac, addr);
1424 eth_addr_dec(entry.mac);
1425
1426 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1427 if (err)
1428 return err;
1429
1430 /* Initialize a fresh ATU entry if it isn't found */
1431 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1432 !ether_addr_equal(entry.mac, addr)) {
1433 memset(&entry, 0, sizeof(entry));
1434 ether_addr_copy(entry.mac, addr);
1435 }
1436
1437 /* Purge the ATU entry only if no port is using it anymore */
1438 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1439 entry.portvec &= ~BIT(port);
1440 if (!entry.portvec)
1441 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1442 } else {
1443 entry.portvec |= BIT(port);
1444 entry.state = state;
1445 }
1446
1447 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1448}
1449
Andrew Lunn87fa8862017-11-09 22:29:56 +01001450static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1451 u16 vid)
1452{
1453 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1454 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1455
1456 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1457}
1458
1459static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1460{
1461 int port;
1462 int err;
1463
1464 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1465 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1466 if (err)
1467 return err;
1468 }
1469
1470 return 0;
1471}
1472
Vivien Didelotfad09c72016-06-21 12:28:20 -04001473static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001474 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001475{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001476 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001477 int err;
1478
Vivien Didelot567aa592017-05-01 14:05:25 -04001479 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001480 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001481 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001482
Vivien Didelotc91498e2017-06-07 18:12:13 -04001483 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001484
Andrew Lunn87fa8862017-11-09 22:29:56 +01001485 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1486 if (err)
1487 return err;
1488
1489 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001490}
1491
Vivien Didelotf81ec902016-05-09 13:22:58 -04001492static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001493 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001494{
Vivien Didelot04bed142016-08-31 18:06:13 -04001495 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001496 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1497 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001498 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001499 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001500
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001501 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001502 return;
1503
Vivien Didelotc91498e2017-06-07 18:12:13 -04001504 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001505 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001506 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001507 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001508 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001509 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001510
Vivien Didelotfad09c72016-06-21 12:28:20 -04001511 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001512
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001513 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001514 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001515 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1516 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001517
Vivien Didelot77064f32016-11-04 03:23:30 +01001518 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001519 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1520 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001521
Vivien Didelotfad09c72016-06-21 12:28:20 -04001522 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001523}
1524
Vivien Didelotfad09c72016-06-21 12:28:20 -04001525static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001526 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001527{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001528 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001529 int i, err;
1530
Vivien Didelot567aa592017-05-01 14:05:25 -04001531 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001532 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001533 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001534
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001535 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001536 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001537 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001538
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001539 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001540
1541 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001542 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001543 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001544 if (vlan.member[i] !=
1545 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001546 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001547 break;
1548 }
1549 }
1550
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001551 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001552 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001553 return err;
1554
Vivien Didelote606ca32017-03-11 16:12:55 -05001555 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001556}
1557
Vivien Didelotf81ec902016-05-09 13:22:58 -04001558static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1559 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001560{
Vivien Didelot04bed142016-08-31 18:06:13 -04001561 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001562 u16 pvid, vid;
1563 int err = 0;
1564
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001565 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001566 return -EOPNOTSUPP;
1567
Vivien Didelotfad09c72016-06-21 12:28:20 -04001568 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001569
Vivien Didelot77064f32016-11-04 03:23:30 +01001570 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001571 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001572 goto unlock;
1573
Vivien Didelot76e398a2015-11-01 12:33:55 -05001574 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001575 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001576 if (err)
1577 goto unlock;
1578
1579 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001580 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001581 if (err)
1582 goto unlock;
1583 }
1584 }
1585
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001586unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001587 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001588
1589 return err;
1590}
1591
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001592static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1593 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001594{
Vivien Didelot04bed142016-08-31 18:06:13 -04001595 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001596 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001597
Vivien Didelotfad09c72016-06-21 12:28:20 -04001598 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001599 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1600 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001601 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001602
1603 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001604}
1605
Vivien Didelotf81ec902016-05-09 13:22:58 -04001606static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001607 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001608{
Vivien Didelot04bed142016-08-31 18:06:13 -04001609 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001610 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001611
Vivien Didelotfad09c72016-06-21 12:28:20 -04001612 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001613 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001614 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001615 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001616
Vivien Didelot83dabd12016-08-31 11:50:04 -04001617 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001618}
1619
Vivien Didelot83dabd12016-08-31 11:50:04 -04001620static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1621 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001622 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001623{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001624 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001625 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001626 int err;
1627
Vivien Didelot27c0e602017-06-15 12:14:01 -04001628 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001629 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001630
1631 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001632 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001633 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001634 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001635 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001636 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001637
Vivien Didelot27c0e602017-06-15 12:14:01 -04001638 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001639 break;
1640
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001641 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001642 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001643
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001644 if (!is_unicast_ether_addr(addr.mac))
1645 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001646
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001647 is_static = (addr.state ==
1648 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1649 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001650 if (err)
1651 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001652 } while (!is_broadcast_ether_addr(addr.mac));
1653
1654 return err;
1655}
1656
Vivien Didelot83dabd12016-08-31 11:50:04 -04001657static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001658 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001659{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001660 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001661 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001662 };
1663 u16 fid;
1664 int err;
1665
1666 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001667 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001668 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001669 mutex_unlock(&chip->reg_lock);
1670
Vivien Didelot83dabd12016-08-31 11:50:04 -04001671 if (err)
1672 return err;
1673
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001674 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001675 if (err)
1676 return err;
1677
1678 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001679 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001680 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001681 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001682 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001683 if (err)
1684 return err;
1685
1686 if (!vlan.valid)
1687 break;
1688
1689 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001690 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001691 if (err)
1692 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001693 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001694
1695 return err;
1696}
1697
Vivien Didelotf81ec902016-05-09 13:22:58 -04001698static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001699 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001700{
Vivien Didelot04bed142016-08-31 18:06:13 -04001701 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001702
Andrew Lunna61e5402018-02-15 14:38:35 +01001703 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001704}
1705
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001706static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1707 struct net_device *br)
1708{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001709 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001710 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001711 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001712 int err;
1713
1714 /* Remap the Port VLAN of each local bridge group member */
1715 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1716 if (chip->ds->ports[port].bridge_dev == br) {
1717 err = mv88e6xxx_port_vlan_map(chip, port);
1718 if (err)
1719 return err;
1720 }
1721 }
1722
Vivien Didelote96a6e02017-03-30 17:37:13 -04001723 if (!mv88e6xxx_has_pvt(chip))
1724 return 0;
1725
1726 /* Remap the Port VLAN of each cross-chip bridge group member */
1727 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1728 ds = chip->ds->dst->ds[dev];
1729 if (!ds)
1730 break;
1731
1732 for (port = 0; port < ds->num_ports; ++port) {
1733 if (ds->ports[port].bridge_dev == br) {
1734 err = mv88e6xxx_pvt_map(chip, dev, port);
1735 if (err)
1736 return err;
1737 }
1738 }
1739 }
1740
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001741 return 0;
1742}
1743
Vivien Didelotf81ec902016-05-09 13:22:58 -04001744static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001745 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001746{
Vivien Didelot04bed142016-08-31 18:06:13 -04001747 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001748 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001749
Vivien Didelotfad09c72016-06-21 12:28:20 -04001750 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001751 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001752 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001753
Vivien Didelot466dfa02016-02-26 13:16:05 -05001754 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001755}
1756
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001757static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1758 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001759{
Vivien Didelot04bed142016-08-31 18:06:13 -04001760 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001761
Vivien Didelotfad09c72016-06-21 12:28:20 -04001762 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001763 if (mv88e6xxx_bridge_map(chip, br) ||
1764 mv88e6xxx_port_vlan_map(chip, port))
1765 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001766 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001767}
1768
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001769static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1770 int port, struct net_device *br)
1771{
1772 struct mv88e6xxx_chip *chip = ds->priv;
1773 int err;
1774
1775 if (!mv88e6xxx_has_pvt(chip))
1776 return 0;
1777
1778 mutex_lock(&chip->reg_lock);
1779 err = mv88e6xxx_pvt_map(chip, dev, port);
1780 mutex_unlock(&chip->reg_lock);
1781
1782 return err;
1783}
1784
1785static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1786 int port, struct net_device *br)
1787{
1788 struct mv88e6xxx_chip *chip = ds->priv;
1789
1790 if (!mv88e6xxx_has_pvt(chip))
1791 return;
1792
1793 mutex_lock(&chip->reg_lock);
1794 if (mv88e6xxx_pvt_map(chip, dev, port))
1795 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1796 mutex_unlock(&chip->reg_lock);
1797}
1798
Vivien Didelot17e708b2016-12-05 17:30:27 -05001799static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1800{
1801 if (chip->info->ops->reset)
1802 return chip->info->ops->reset(chip);
1803
1804 return 0;
1805}
1806
Vivien Didelot309eca62016-12-05 17:30:26 -05001807static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1808{
1809 struct gpio_desc *gpiod = chip->reset;
1810
1811 /* If there is a GPIO connected to the reset pin, toggle it */
1812 if (gpiod) {
1813 gpiod_set_value_cansleep(gpiod, 1);
1814 usleep_range(10000, 20000);
1815 gpiod_set_value_cansleep(gpiod, 0);
1816 usleep_range(10000, 20000);
1817 }
1818}
1819
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001820static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1821{
1822 int i, err;
1823
1824 /* Set all ports to the Disabled state */
1825 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001826 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001827 if (err)
1828 return err;
1829 }
1830
1831 /* Wait for transmit queues to drain,
1832 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1833 */
1834 usleep_range(2000, 4000);
1835
1836 return 0;
1837}
1838
Vivien Didelotfad09c72016-06-21 12:28:20 -04001839static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001840{
Vivien Didelota935c052016-09-29 12:21:53 -04001841 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001842
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001843 err = mv88e6xxx_disable_ports(chip);
1844 if (err)
1845 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001846
Vivien Didelot309eca62016-12-05 17:30:26 -05001847 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001848
Vivien Didelot17e708b2016-12-05 17:30:27 -05001849 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001850}
1851
Vivien Didelot43145572017-03-11 16:12:59 -05001852static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001853 enum mv88e6xxx_frame_mode frame,
1854 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001855{
1856 int err;
1857
Vivien Didelot43145572017-03-11 16:12:59 -05001858 if (!chip->info->ops->port_set_frame_mode)
1859 return -EOPNOTSUPP;
1860
1861 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001862 if (err)
1863 return err;
1864
Vivien Didelot43145572017-03-11 16:12:59 -05001865 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1866 if (err)
1867 return err;
1868
1869 if (chip->info->ops->port_set_ether_type)
1870 return chip->info->ops->port_set_ether_type(chip, port, etype);
1871
1872 return 0;
1873}
1874
1875static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1876{
1877 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001878 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001879 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001880}
1881
1882static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1883{
1884 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001885 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001886 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001887}
1888
1889static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1890{
1891 return mv88e6xxx_set_port_mode(chip, port,
1892 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001893 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1894 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001895}
1896
1897static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1898{
1899 if (dsa_is_dsa_port(chip->ds, port))
1900 return mv88e6xxx_set_port_mode_dsa(chip, port);
1901
Vivien Didelot2b3e9892017-10-26 11:22:54 -04001902 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05001903 return mv88e6xxx_set_port_mode_normal(chip, port);
1904
1905 /* Setup CPU port mode depending on its supported tag format */
1906 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1907 return mv88e6xxx_set_port_mode_dsa(chip, port);
1908
1909 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1910 return mv88e6xxx_set_port_mode_edsa(chip, port);
1911
1912 return -EINVAL;
1913}
1914
Vivien Didelotea698f42017-03-11 16:12:50 -05001915static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1916{
1917 bool message = dsa_is_dsa_port(chip->ds, port);
1918
1919 return mv88e6xxx_port_set_message_port(chip, port, message);
1920}
1921
Vivien Didelot601aeed2017-03-11 16:13:00 -05001922static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1923{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001924 struct dsa_switch *ds = chip->ds;
1925 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05001926
1927 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001928 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05001929 if (chip->info->ops->port_set_egress_floods)
1930 return chip->info->ops->port_set_egress_floods(chip, port,
1931 flood, flood);
1932
1933 return 0;
1934}
1935
Andrew Lunn6d917822017-05-26 01:03:21 +02001936static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1937 bool on)
1938{
Vivien Didelot523a8902017-05-26 18:02:42 -04001939 if (chip->info->ops->serdes_power)
1940 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001941
Vivien Didelot523a8902017-05-26 18:02:42 -04001942 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001943}
1944
Vivien Didelotfa371c82017-12-05 15:34:10 -05001945static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
1946{
1947 struct dsa_switch *ds = chip->ds;
1948 int upstream_port;
1949 int err;
1950
Vivien Didelot07073c72017-12-05 15:34:13 -05001951 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05001952 if (chip->info->ops->port_set_upstream_port) {
1953 err = chip->info->ops->port_set_upstream_port(chip, port,
1954 upstream_port);
1955 if (err)
1956 return err;
1957 }
1958
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05001959 if (port == upstream_port) {
1960 if (chip->info->ops->set_cpu_port) {
1961 err = chip->info->ops->set_cpu_port(chip,
1962 upstream_port);
1963 if (err)
1964 return err;
1965 }
1966
1967 if (chip->info->ops->set_egress_port) {
1968 err = chip->info->ops->set_egress_port(chip,
1969 upstream_port);
1970 if (err)
1971 return err;
1972 }
1973 }
1974
Vivien Didelotfa371c82017-12-05 15:34:10 -05001975 return 0;
1976}
1977
Vivien Didelotfad09c72016-06-21 12:28:20 -04001978static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001979{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001980 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001981 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001982 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001983
Vivien Didelotd78343d2016-11-04 03:23:36 +01001984 /* MAC Forcing register: don't force link, speed, duplex or flow control
1985 * state to any particular values on physical ports, but force the CPU
1986 * port and all DSA ports to their maximum bandwidth and full duplex.
1987 */
1988 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1989 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1990 SPEED_MAX, DUPLEX_FULL,
1991 PHY_INTERFACE_MODE_NA);
1992 else
1993 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1994 SPEED_UNFORCED, DUPLEX_UNFORCED,
1995 PHY_INTERFACE_MODE_NA);
1996 if (err)
1997 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001998
1999 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2000 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2001 * tunneling, determine priority by looking at 802.1p and IP
2002 * priority fields (IP prio has precedence), and set STP state
2003 * to Forwarding.
2004 *
2005 * If this is the CPU link, use DSA or EDSA tagging depending
2006 * on which tagging mode was configured.
2007 *
2008 * If this is a link to another switch, use DSA tagging mode.
2009 *
2010 * If this is the upstream port for this switch, enable
2011 * forwarding of unknown unicasts and multicasts.
2012 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002013 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2014 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2015 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2016 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002017 if (err)
2018 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002019
Vivien Didelot601aeed2017-03-11 16:13:00 -05002020 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002021 if (err)
2022 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002023
Vivien Didelot601aeed2017-03-11 16:13:00 -05002024 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002025 if (err)
2026 return err;
2027
Andrew Lunn04aca992017-05-26 01:03:24 +02002028 /* Enable the SERDES interface for DSA and CPU ports. Normal
2029 * ports SERDES are enabled when the port is enabled, thus
2030 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002031 */
Andrew Lunn04aca992017-05-26 01:03:24 +02002032 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
2033 err = mv88e6xxx_serdes_power(chip, port, true);
2034 if (err)
2035 return err;
2036 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002037
Vivien Didelot8efdda42015-08-13 12:52:23 -04002038 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002039 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002040 * untagged frames on this port, do a destination address lookup on all
2041 * received packets as usual, disable ARP mirroring and don't send a
2042 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002043 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002044 err = mv88e6xxx_port_set_map_da(chip, port);
2045 if (err)
2046 return err;
2047
Vivien Didelotfa371c82017-12-05 15:34:10 -05002048 err = mv88e6xxx_setup_upstream_port(chip, port);
2049 if (err)
2050 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002051
Andrew Lunna23b2962017-02-04 20:15:28 +01002052 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002053 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002054 if (err)
2055 return err;
2056
Vivien Didelotcd782652017-06-08 18:34:13 -04002057 if (chip->info->ops->port_set_jumbo_size) {
2058 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002059 if (err)
2060 return err;
2061 }
2062
Andrew Lunn54d792f2015-05-06 01:09:47 +02002063 /* Port Association Vector: when learning source addresses
2064 * of packets, add the address to the address database using
2065 * a port bitmap that has only the bit for this port set and
2066 * the other bits clear.
2067 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002068 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002069 /* Disable learning for CPU port */
2070 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002071 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002072
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002073 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2074 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002075 if (err)
2076 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002077
2078 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002079 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2080 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002081 if (err)
2082 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002083
Vivien Didelot08984322017-06-08 18:34:12 -04002084 if (chip->info->ops->port_pause_limit) {
2085 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002086 if (err)
2087 return err;
2088 }
2089
Vivien Didelotc8c94892017-03-11 16:13:01 -05002090 if (chip->info->ops->port_disable_learn_limit) {
2091 err = chip->info->ops->port_disable_learn_limit(chip, port);
2092 if (err)
2093 return err;
2094 }
2095
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002096 if (chip->info->ops->port_disable_pri_override) {
2097 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002098 if (err)
2099 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002100 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002101
Andrew Lunnef0a7312016-12-03 04:35:16 +01002102 if (chip->info->ops->port_tag_remap) {
2103 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002104 if (err)
2105 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002106 }
2107
Andrew Lunnef70b112016-12-03 04:45:18 +01002108 if (chip->info->ops->port_egress_rate_limiting) {
2109 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002110 if (err)
2111 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002112 }
2113
Vivien Didelotea698f42017-03-11 16:12:50 -05002114 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002115 if (err)
2116 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002117
Vivien Didelot207afda2016-04-14 14:42:09 -04002118 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002119 * database, and allow bidirectional communication between the
2120 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002121 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002122 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002123 if (err)
2124 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002125
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002126 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002127 if (err)
2128 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002129
2130 /* Default VLAN ID and priority: don't set a default VLAN
2131 * ID, and set the default packet priority to zero.
2132 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002133 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002134}
2135
Andrew Lunn04aca992017-05-26 01:03:24 +02002136static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2137 struct phy_device *phydev)
2138{
2139 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002140 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002141
2142 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002143 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002144 mutex_unlock(&chip->reg_lock);
2145
2146 return err;
2147}
2148
2149static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2150 struct phy_device *phydev)
2151{
2152 struct mv88e6xxx_chip *chip = ds->priv;
2153
2154 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002155 if (mv88e6xxx_serdes_power(chip, port, false))
2156 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002157 mutex_unlock(&chip->reg_lock);
2158}
2159
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002160static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2161 unsigned int ageing_time)
2162{
Vivien Didelot04bed142016-08-31 18:06:13 -04002163 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002164 int err;
2165
2166 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002167 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002168 mutex_unlock(&chip->reg_lock);
2169
2170 return err;
2171}
2172
Vivien Didelot97299342016-07-18 20:45:30 -04002173static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002174{
2175 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002176
Vivien Didelot08a01262016-05-09 13:22:50 -04002177 /* Configure the IP ToS mapping registers. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002178 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002179 if (err)
2180 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002181 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002182 if (err)
2183 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002184 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002185 if (err)
2186 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002187 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002188 if (err)
2189 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002190 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002191 if (err)
2192 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002193 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002194 if (err)
2195 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002196 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002197 if (err)
2198 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002199 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002200 if (err)
2201 return err;
2202
2203 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002204 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002205 if (err)
2206 return err;
2207
Andrew Lunnde2273872016-11-21 23:27:01 +01002208 /* Initialize the statistics unit */
2209 err = mv88e6xxx_stats_set_histogram(chip);
2210 if (err)
2211 return err;
2212
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002213 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002214}
2215
Vivien Didelotf81ec902016-05-09 13:22:58 -04002216static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002217{
Vivien Didelot04bed142016-08-31 18:06:13 -04002218 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002219 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002220 int i;
2221
Vivien Didelotfad09c72016-06-21 12:28:20 -04002222 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002223 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002224
Vivien Didelotfad09c72016-06-21 12:28:20 -04002225 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002226
Vivien Didelot97299342016-07-18 20:45:30 -04002227 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002228 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002229 if (dsa_is_unused_port(ds, i))
2230 continue;
2231
Vivien Didelot97299342016-07-18 20:45:30 -04002232 err = mv88e6xxx_setup_port(chip, i);
2233 if (err)
2234 goto unlock;
2235 }
2236
2237 /* Setup Switch Global 1 Registers */
2238 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002239 if (err)
2240 goto unlock;
2241
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002242 err = mv88e6xxx_irl_setup(chip);
2243 if (err)
2244 goto unlock;
2245
Vivien Didelot04a69a12017-10-13 14:18:05 -04002246 err = mv88e6xxx_mac_setup(chip);
2247 if (err)
2248 goto unlock;
2249
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002250 err = mv88e6xxx_phy_setup(chip);
2251 if (err)
2252 goto unlock;
2253
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002254 err = mv88e6xxx_vtu_setup(chip);
2255 if (err)
2256 goto unlock;
2257
Vivien Didelot81228992017-03-30 17:37:08 -04002258 err = mv88e6xxx_pvt_setup(chip);
2259 if (err)
2260 goto unlock;
2261
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002262 err = mv88e6xxx_atu_setup(chip);
2263 if (err)
2264 goto unlock;
2265
Andrew Lunn87fa8862017-11-09 22:29:56 +01002266 err = mv88e6xxx_broadcast_setup(chip, 0);
2267 if (err)
2268 goto unlock;
2269
Vivien Didelot9e907d72017-07-17 13:03:43 -04002270 err = mv88e6xxx_pot_setup(chip);
2271 if (err)
2272 goto unlock;
2273
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002274 err = mv88e6xxx_rmu_setup(chip);
2275 if (err)
2276 goto unlock;
2277
Vivien Didelot51c901a2017-07-17 13:03:41 -04002278 err = mv88e6xxx_rsvd2cpu_setup(chip);
2279 if (err)
2280 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002281
Vivien Didelotb28f8722018-04-26 21:56:44 -04002282 err = mv88e6xxx_trunk_setup(chip);
2283 if (err)
2284 goto unlock;
2285
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002286 err = mv88e6xxx_devmap_setup(chip);
2287 if (err)
2288 goto unlock;
2289
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002290 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002291 if (chip->info->ptp_support) {
2292 err = mv88e6xxx_ptp_setup(chip);
2293 if (err)
2294 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002295
2296 err = mv88e6xxx_hwtstamp_setup(chip);
2297 if (err)
2298 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002299 }
2300
Vivien Didelot6b17e862015-08-13 12:52:18 -04002301unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002302 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002303
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002304 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002305}
2306
Vivien Didelote57e5e72016-08-15 17:19:00 -04002307static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002308{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002309 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2310 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002311 u16 val;
2312 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002313
Andrew Lunnee26a222017-01-24 14:53:48 +01002314 if (!chip->info->ops->phy_read)
2315 return -EOPNOTSUPP;
2316
Vivien Didelotfad09c72016-06-21 12:28:20 -04002317 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002318 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002319 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002320
Andrew Lunnda9f3302017-02-01 03:40:05 +01002321 if (reg == MII_PHYSID2) {
2322 /* Some internal PHYS don't have a model number. Use
2323 * the mv88e6390 family model number instead.
2324 */
2325 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002326 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002327 }
2328
Vivien Didelote57e5e72016-08-15 17:19:00 -04002329 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002330}
2331
Vivien Didelote57e5e72016-08-15 17:19:00 -04002332static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002333{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002334 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2335 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002336 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002337
Andrew Lunnee26a222017-01-24 14:53:48 +01002338 if (!chip->info->ops->phy_write)
2339 return -EOPNOTSUPP;
2340
Vivien Didelotfad09c72016-06-21 12:28:20 -04002341 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002342 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002343 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002344
2345 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002346}
2347
Vivien Didelotfad09c72016-06-21 12:28:20 -04002348static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002349 struct device_node *np,
2350 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002351{
2352 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002353 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002354 struct mii_bus *bus;
2355 int err;
2356
Andrew Lunn2510bab2018-02-22 01:51:49 +01002357 if (external) {
2358 mutex_lock(&chip->reg_lock);
2359 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2360 mutex_unlock(&chip->reg_lock);
2361
2362 if (err)
2363 return err;
2364 }
2365
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002366 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002367 if (!bus)
2368 return -ENOMEM;
2369
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002370 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002371 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002372 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002373 INIT_LIST_HEAD(&mdio_bus->list);
2374 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002375
Andrew Lunnb516d452016-06-04 21:17:06 +02002376 if (np) {
2377 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002378 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002379 } else {
2380 bus->name = "mv88e6xxx SMI";
2381 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2382 }
2383
2384 bus->read = mv88e6xxx_mdio_read;
2385 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002386 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002387
Andrew Lunn6f882842018-03-17 20:32:05 +01002388 if (!external) {
2389 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2390 if (err)
2391 return err;
2392 }
2393
Andrew Lunna3c53be52017-01-24 14:53:50 +01002394 if (np)
2395 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002396 else
2397 err = mdiobus_register(bus);
2398 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002399 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002400 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002401 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002402 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002403
2404 if (external)
2405 list_add_tail(&mdio_bus->list, &chip->mdios);
2406 else
2407 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002408
2409 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002410}
2411
Andrew Lunna3c53be52017-01-24 14:53:50 +01002412static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2413 { .compatible = "marvell,mv88e6xxx-mdio-external",
2414 .data = (void *)true },
2415 { },
2416};
2417
Andrew Lunn3126aee2017-12-07 01:05:57 +01002418static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2419
2420{
2421 struct mv88e6xxx_mdio_bus *mdio_bus;
2422 struct mii_bus *bus;
2423
2424 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2425 bus = mdio_bus->bus;
2426
Andrew Lunn6f882842018-03-17 20:32:05 +01002427 if (!mdio_bus->external)
2428 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2429
Andrew Lunn3126aee2017-12-07 01:05:57 +01002430 mdiobus_unregister(bus);
2431 }
2432}
2433
Andrew Lunna3c53be52017-01-24 14:53:50 +01002434static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2435 struct device_node *np)
2436{
2437 const struct of_device_id *match;
2438 struct device_node *child;
2439 int err;
2440
2441 /* Always register one mdio bus for the internal/default mdio
2442 * bus. This maybe represented in the device tree, but is
2443 * optional.
2444 */
2445 child = of_get_child_by_name(np, "mdio");
2446 err = mv88e6xxx_mdio_register(chip, child, false);
2447 if (err)
2448 return err;
2449
2450 /* Walk the device tree, and see if there are any other nodes
2451 * which say they are compatible with the external mdio
2452 * bus.
2453 */
2454 for_each_available_child_of_node(np, child) {
2455 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2456 if (match) {
2457 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002458 if (err) {
2459 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002460 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002461 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002462 }
2463 }
2464
2465 return 0;
2466}
2467
Vivien Didelot855b1932016-07-20 18:18:35 -04002468static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2469{
Vivien Didelot04bed142016-08-31 18:06:13 -04002470 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002471
2472 return chip->eeprom_len;
2473}
2474
Vivien Didelot855b1932016-07-20 18:18:35 -04002475static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2476 struct ethtool_eeprom *eeprom, u8 *data)
2477{
Vivien Didelot04bed142016-08-31 18:06:13 -04002478 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002479 int err;
2480
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002481 if (!chip->info->ops->get_eeprom)
2482 return -EOPNOTSUPP;
2483
Vivien Didelot855b1932016-07-20 18:18:35 -04002484 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002485 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002486 mutex_unlock(&chip->reg_lock);
2487
2488 if (err)
2489 return err;
2490
2491 eeprom->magic = 0xc3ec4951;
2492
2493 return 0;
2494}
2495
Vivien Didelot855b1932016-07-20 18:18:35 -04002496static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2497 struct ethtool_eeprom *eeprom, u8 *data)
2498{
Vivien Didelot04bed142016-08-31 18:06:13 -04002499 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002500 int err;
2501
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002502 if (!chip->info->ops->set_eeprom)
2503 return -EOPNOTSUPP;
2504
Vivien Didelot855b1932016-07-20 18:18:35 -04002505 if (eeprom->magic != 0xc3ec4951)
2506 return -EINVAL;
2507
2508 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002509 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002510 mutex_unlock(&chip->reg_lock);
2511
2512 return err;
2513}
2514
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002515static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002516 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002517 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002518 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002519 .phy_read = mv88e6185_phy_ppu_read,
2520 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002521 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002522 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002523 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002524 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002525 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002526 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002527 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002528 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002529 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002530 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002531 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002532 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002533 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002534 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2535 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002536 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002537 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2538 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002539 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002540 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002541 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002542 .ppu_enable = mv88e6185_g1_ppu_enable,
2543 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002544 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002545 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002546 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002547 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behún5bafeb6e2018-05-04 19:26:10 +02002548 .serdes_power = mv88e6341_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002549};
2550
2551static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002552 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002553 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002554 .phy_read = mv88e6185_phy_ppu_read,
2555 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002556 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002557 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002558 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002559 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002560 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002561 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002562 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002563 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002564 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2565 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002566 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002567 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002568 .ppu_enable = mv88e6185_g1_ppu_enable,
2569 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002570 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002571 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002572 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002573};
2574
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002575static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002576 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002577 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002578 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2579 .phy_read = mv88e6xxx_g2_smi_phy_read,
2580 .phy_write = mv88e6xxx_g2_smi_phy_write,
2581 .port_set_link = mv88e6xxx_port_set_link,
2582 .port_set_duplex = mv88e6xxx_port_set_duplex,
2583 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002584 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002585 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002586 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002587 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002588 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002589 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002590 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002591 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002592 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002593 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002594 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002595 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2596 .stats_get_strings = mv88e6095_stats_get_strings,
2597 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002598 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2599 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002600 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002601 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002602 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002603 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002604 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002605 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002606 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002607};
2608
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002609static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002610 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002611 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002612 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002613 .phy_read = mv88e6xxx_g2_smi_phy_read,
2614 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002615 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002616 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002617 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002618 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002619 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002620 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002621 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002622 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002623 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002624 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2625 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002626 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002627 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2628 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002629 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002630 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002631 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002632 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002633 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002634 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002635};
2636
2637static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002638 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002639 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002640 .phy_read = mv88e6185_phy_ppu_read,
2641 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002642 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002643 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002644 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002645 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002646 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002647 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002648 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002649 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002650 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002651 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002652 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002653 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002654 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002655 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2656 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002657 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002658 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2659 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002660 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002661 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002662 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04002663 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002664 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002665 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002666 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002667 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002668};
2669
Vivien Didelot990e27b2017-03-28 13:50:32 -04002670static const struct mv88e6xxx_ops mv88e6141_ops = {
2671 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002672 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002673 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2674 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2675 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2676 .phy_read = mv88e6xxx_g2_smi_phy_read,
2677 .phy_write = mv88e6xxx_g2_smi_phy_write,
2678 .port_set_link = mv88e6xxx_port_set_link,
2679 .port_set_duplex = mv88e6xxx_port_set_duplex,
2680 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2681 .port_set_speed = mv88e6390_port_set_speed,
2682 .port_tag_remap = mv88e6095_port_tag_remap,
2683 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2684 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2685 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002686 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002687 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002688 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002689 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2690 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2691 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002692 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002693 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2694 .stats_get_strings = mv88e6320_stats_get_strings,
2695 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002696 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2697 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002698 .watchdog_ops = &mv88e6390_watchdog_ops,
2699 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002700 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002701 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002702 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002703 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002704 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002705};
2706
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002707static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002708 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002709 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002710 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002711 .phy_read = mv88e6xxx_g2_smi_phy_read,
2712 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002713 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002714 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002715 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002716 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002717 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002718 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002719 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002720 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002721 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002722 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002723 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002724 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002725 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002726 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002727 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2728 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002729 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002730 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2731 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002732 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002733 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002734 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002735 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002736 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002737 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002738};
2739
2740static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002741 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002742 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002743 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002744 .phy_read = mv88e6165_phy_read,
2745 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002746 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002747 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002748 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002749 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002750 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002751 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002752 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002753 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2754 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002755 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002756 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2757 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002758 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002759 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002760 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002761 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002762 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002763 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002764};
2765
2766static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002767 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002768 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002769 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002770 .phy_read = mv88e6xxx_g2_smi_phy_read,
2771 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002772 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002773 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002774 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002775 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002776 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002777 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002778 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002779 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002780 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002781 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002782 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002783 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002784 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002785 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002786 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002787 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2788 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002789 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002790 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2791 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002792 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002793 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002794 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002795 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002796 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002797 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002798};
2799
2800static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002801 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002802 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002803 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2804 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002805 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002806 .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 Didelota0a0f622016-11-04 03:23:34 +01002810 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002811 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002812 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002813 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002814 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002815 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002816 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002817 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002818 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002819 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002820 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002821 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002822 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002823 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2824 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002825 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002826 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2827 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002828 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002829 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002830 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002831 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002832 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002833 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002834 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002835 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002836 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002837};
2838
2839static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002840 /* MV88E6XXX_FAMILY_6351 */
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,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002843 .phy_read = mv88e6xxx_g2_smi_phy_read,
2844 .phy_write = mv88e6xxx_g2_smi_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,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002847 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002848 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002849 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002850 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002851 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002852 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002853 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002854 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002855 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002856 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002857 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002858 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002859 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002860 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2861 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002862 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002863 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2864 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002865 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002866 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002867 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002868 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002869 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002870 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behún5bafeb6e2018-05-04 19:26:10 +02002871 .serdes_power = mv88e6341_serdes_power,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002872};
2873
2874static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002875 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002876 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002877 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2878 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002879 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002880 .phy_read = mv88e6xxx_g2_smi_phy_read,
2881 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002882 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002883 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002884 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002885 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002886 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002887 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002888 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002889 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002890 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002891 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002892 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002893 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002894 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002895 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002896 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002897 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2898 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002899 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002900 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2901 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002902 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002903 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002904 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002905 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002906 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002907 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002908 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002909 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002910 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002911};
2912
2913static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002914 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002915 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002916 .phy_read = mv88e6185_phy_ppu_read,
2917 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002918 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002919 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002920 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002921 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002922 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002923 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002924 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002925 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002926 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002927 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2928 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002929 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002930 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2931 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002932 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002933 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04002934 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002935 .ppu_enable = mv88e6185_g1_ppu_enable,
2936 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002937 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002938 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002939 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002940};
2941
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002942static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002943 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002944 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002945 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2946 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002947 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2948 .phy_read = mv88e6xxx_g2_smi_phy_read,
2949 .phy_write = mv88e6xxx_g2_smi_phy_write,
2950 .port_set_link = mv88e6xxx_port_set_link,
2951 .port_set_duplex = mv88e6xxx_port_set_duplex,
2952 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2953 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002954 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002955 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002956 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002957 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002958 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002959 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002960 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002961 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002962 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002963 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2964 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002965 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002966 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2967 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002968 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002969 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002970 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002971 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002972 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04002973 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2974 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002975 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002976 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002977};
2978
2979static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002980 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002981 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002982 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2983 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002984 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2985 .phy_read = mv88e6xxx_g2_smi_phy_read,
2986 .phy_write = mv88e6xxx_g2_smi_phy_write,
2987 .port_set_link = mv88e6xxx_port_set_link,
2988 .port_set_duplex = mv88e6xxx_port_set_duplex,
2989 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2990 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002991 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002992 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002993 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002994 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002995 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002996 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002997 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002998 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002999 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003000 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3001 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003002 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003003 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3004 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003005 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003006 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003007 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003008 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003009 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003010 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3011 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003012 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003013 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003014};
3015
3016static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003017 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003018 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003019 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3020 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003021 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3022 .phy_read = mv88e6xxx_g2_smi_phy_read,
3023 .phy_write = mv88e6xxx_g2_smi_phy_write,
3024 .port_set_link = mv88e6xxx_port_set_link,
3025 .port_set_duplex = mv88e6xxx_port_set_duplex,
3026 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3027 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003028 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003029 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003030 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003031 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003032 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003033 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003034 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003035 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003036 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003037 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3038 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003039 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003040 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3041 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003042 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003043 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003044 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003045 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003046 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003047 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3048 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003049 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003050};
3051
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003052static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003053 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003054 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003055 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3056 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003057 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003058 .phy_read = mv88e6xxx_g2_smi_phy_read,
3059 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003060 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003061 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003062 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003063 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003064 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003065 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003066 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003067 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003068 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003069 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003070 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003071 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003072 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003073 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003074 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003075 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3076 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003077 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003078 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3079 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003080 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003081 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003082 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003083 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003084 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003085 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003086 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003087 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003088 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003089 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003090};
3091
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003092static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003093 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003094 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003095 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3096 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003097 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3098 .phy_read = mv88e6xxx_g2_smi_phy_read,
3099 .phy_write = mv88e6xxx_g2_smi_phy_write,
3100 .port_set_link = mv88e6xxx_port_set_link,
3101 .port_set_duplex = mv88e6xxx_port_set_duplex,
3102 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3103 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003104 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003105 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003106 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003107 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003108 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003109 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003110 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003111 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003112 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003113 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003114 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3115 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003116 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003117 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3118 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003119 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003120 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003121 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003122 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003123 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003124 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3125 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003126 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003127 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003128 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003129};
3130
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003131static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003132 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003133 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003134 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3135 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003136 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003137 .phy_read = mv88e6xxx_g2_smi_phy_read,
3138 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003139 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003140 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003141 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003142 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003143 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003144 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003145 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003146 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003147 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003148 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003149 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003150 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003151 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003152 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003153 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3154 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003155 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003156 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3157 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003158 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003159 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003160 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003161 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003162 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003163 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003164 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003165};
3166
3167static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003168 /* MV88E6XXX_FAMILY_6320 */
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 Didelot96a2b402016-11-04 03:23:35 +01003177 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003178 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003179 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003180 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003181 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003182 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003183 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003184 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003185 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003186 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003187 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003188 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003189 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3190 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003191 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003192 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3193 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003194 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003195 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003196 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003197 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003198 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003199};
3200
Vivien Didelot16e329a2017-03-28 13:50:33 -04003201static const struct mv88e6xxx_ops mv88e6341_ops = {
3202 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003203 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003204 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3205 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3206 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3207 .phy_read = mv88e6xxx_g2_smi_phy_read,
3208 .phy_write = mv88e6xxx_g2_smi_phy_write,
3209 .port_set_link = mv88e6xxx_port_set_link,
3210 .port_set_duplex = mv88e6xxx_port_set_duplex,
3211 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3212 .port_set_speed = mv88e6390_port_set_speed,
3213 .port_tag_remap = mv88e6095_port_tag_remap,
3214 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3215 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3216 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003217 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003218 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003219 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003220 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3221 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3222 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003223 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003224 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3225 .stats_get_strings = mv88e6320_stats_get_strings,
3226 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003227 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3228 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003229 .watchdog_ops = &mv88e6390_watchdog_ops,
3230 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003231 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003232 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003233 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003234 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003235 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003236 .avb_ops = &mv88e6390_avb_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003237};
3238
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003239static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003240 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003241 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003242 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003243 .phy_read = mv88e6xxx_g2_smi_phy_read,
3244 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003245 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003246 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003247 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003248 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003249 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003250 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003251 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003252 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003253 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003254 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003255 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003256 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003257 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003258 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003259 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003260 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3261 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003262 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003263 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3264 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003265 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003266 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003267 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003268 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003269 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003270 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003271};
3272
3273static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003274 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003275 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003276 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003277 .phy_read = mv88e6xxx_g2_smi_phy_read,
3278 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003279 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003280 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003281 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003282 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003283 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003284 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003285 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003286 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003287 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003288 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003289 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003290 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003291 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003292 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003293 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003294 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3295 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003296 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003297 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3298 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003299 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003300 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003301 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003302 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003303 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003304 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003305 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003306};
3307
3308static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003309 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003310 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003311 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3312 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003313 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003314 .phy_read = mv88e6xxx_g2_smi_phy_read,
3315 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003316 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003317 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003318 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003319 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003320 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003321 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003322 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003323 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003324 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003325 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003326 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003327 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003328 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003329 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003330 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003331 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3332 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003333 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003334 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3335 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003336 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003337 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003338 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003339 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003340 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003341 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003342 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003343 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003344 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003345 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01003346 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
3347 .serdes_get_strings = mv88e6352_serdes_get_strings,
3348 .serdes_get_stats = mv88e6352_serdes_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003349};
3350
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003351static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003352 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003353 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003354 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3355 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003356 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3357 .phy_read = mv88e6xxx_g2_smi_phy_read,
3358 .phy_write = mv88e6xxx_g2_smi_phy_write,
3359 .port_set_link = mv88e6xxx_port_set_link,
3360 .port_set_duplex = mv88e6xxx_port_set_duplex,
3361 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3362 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003363 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003364 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003365 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003366 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003367 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003368 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003369 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003370 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003371 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003372 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003373 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003374 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003375 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3376 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003377 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003378 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3379 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003380 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003381 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003382 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003383 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003384 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003385 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3386 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003387 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003388 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003389 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003390};
3391
3392static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003393 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003394 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003395 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3396 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003397 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3398 .phy_read = mv88e6xxx_g2_smi_phy_read,
3399 .phy_write = mv88e6xxx_g2_smi_phy_write,
3400 .port_set_link = mv88e6xxx_port_set_link,
3401 .port_set_duplex = mv88e6xxx_port_set_duplex,
3402 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3403 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003404 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003405 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003406 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003407 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003408 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003409 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003410 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003411 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003412 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003413 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003414 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003415 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003416 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3417 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003418 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003419 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3420 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003421 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003422 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003423 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003424 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003425 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003426 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3427 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003428 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003429 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003430 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003431};
3432
Vivien Didelotf81ec902016-05-09 13:22:58 -04003433static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3434 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003435 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003436 .family = MV88E6XXX_FAMILY_6097,
3437 .name = "Marvell 88E6085",
3438 .num_databases = 4096,
3439 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003440 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003441 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003442 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003443 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003444 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003445 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003446 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003447 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003448 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003449 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003450 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003451 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003452 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003453 },
3454
3455 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003456 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003457 .family = MV88E6XXX_FAMILY_6095,
3458 .name = "Marvell 88E6095/88E6095F",
3459 .num_databases = 256,
3460 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003461 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003462 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003463 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003464 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003465 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003466 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003467 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003468 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003469 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003470 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003471 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003472 },
3473
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003474 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003475 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003476 .family = MV88E6XXX_FAMILY_6097,
3477 .name = "Marvell 88E6097/88E6097F",
3478 .num_databases = 4096,
3479 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003480 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003481 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003482 .port_base_addr = 0x10,
3483 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003484 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003485 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003486 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003487 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003488 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003489 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003490 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003491 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003492 .ops = &mv88e6097_ops,
3493 },
3494
Vivien Didelotf81ec902016-05-09 13:22:58 -04003495 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003496 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003497 .family = MV88E6XXX_FAMILY_6165,
3498 .name = "Marvell 88E6123",
3499 .num_databases = 4096,
3500 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01003501 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003502 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003503 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003504 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003505 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003506 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003507 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003508 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003509 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003510 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003511 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003512 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003513 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003514 },
3515
3516 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003517 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003518 .family = MV88E6XXX_FAMILY_6185,
3519 .name = "Marvell 88E6131",
3520 .num_databases = 256,
3521 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003522 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003523 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003524 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003525 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003526 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003527 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003528 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003529 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003530 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003531 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003532 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003533 },
3534
Vivien Didelot990e27b2017-03-28 13:50:32 -04003535 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003536 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003537 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01003538 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04003539 .num_databases = 4096,
3540 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003541 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003542 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003543 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003544 .port_base_addr = 0x10,
3545 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003546 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003547 .age_time_coeff = 3750,
3548 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003549 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003550 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003551 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003552 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003553 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003554 .ops = &mv88e6141_ops,
3555 },
3556
Vivien Didelotf81ec902016-05-09 13:22:58 -04003557 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003558 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003559 .family = MV88E6XXX_FAMILY_6165,
3560 .name = "Marvell 88E6161",
3561 .num_databases = 4096,
3562 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003563 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003564 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003565 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003566 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003567 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003568 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003569 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003570 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003571 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003572 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003573 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003574 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003575 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003576 },
3577
3578 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003579 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003580 .family = MV88E6XXX_FAMILY_6165,
3581 .name = "Marvell 88E6165",
3582 .num_databases = 4096,
3583 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003584 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003585 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003586 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003587 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003588 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003589 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003590 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003591 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003592 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003593 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003594 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003595 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003596 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003597 },
3598
3599 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003600 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003601 .family = MV88E6XXX_FAMILY_6351,
3602 .name = "Marvell 88E6171",
3603 .num_databases = 4096,
3604 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003605 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003606 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003607 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003608 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003609 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003610 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003611 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003612 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003613 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003614 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003615 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003616 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003617 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003618 },
3619
3620 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003621 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003622 .family = MV88E6XXX_FAMILY_6352,
3623 .name = "Marvell 88E6172",
3624 .num_databases = 4096,
3625 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003626 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003627 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003628 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003629 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003630 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003631 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003632 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003633 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003634 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003635 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003636 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003637 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003638 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003639 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003640 },
3641
3642 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003643 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003644 .family = MV88E6XXX_FAMILY_6351,
3645 .name = "Marvell 88E6175",
3646 .num_databases = 4096,
3647 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003648 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003649 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003650 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003651 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003652 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003653 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003654 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003655 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003656 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003657 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003658 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003659 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003660 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003661 },
3662
3663 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003664 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003665 .family = MV88E6XXX_FAMILY_6352,
3666 .name = "Marvell 88E6176",
3667 .num_databases = 4096,
3668 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003669 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003670 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003671 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003672 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003673 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003674 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003675 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003676 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003677 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003678 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003679 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003680 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003681 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003682 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003683 },
3684
3685 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003686 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003687 .family = MV88E6XXX_FAMILY_6185,
3688 .name = "Marvell 88E6185",
3689 .num_databases = 256,
3690 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003691 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003692 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003693 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003694 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003695 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003696 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003697 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003698 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003699 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003700 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003701 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003702 },
3703
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003704 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003705 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003706 .family = MV88E6XXX_FAMILY_6390,
3707 .name = "Marvell 88E6190",
3708 .num_databases = 4096,
3709 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003710 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003711 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003712 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003713 .port_base_addr = 0x0,
3714 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003715 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003716 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003717 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003718 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003719 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003720 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003721 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003722 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003723 .ops = &mv88e6190_ops,
3724 },
3725
3726 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003727 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003728 .family = MV88E6XXX_FAMILY_6390,
3729 .name = "Marvell 88E6190X",
3730 .num_databases = 4096,
3731 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003732 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003733 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003734 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003735 .port_base_addr = 0x0,
3736 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003737 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003738 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003739 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003740 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003741 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003742 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003743 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003744 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003745 .ops = &mv88e6190x_ops,
3746 },
3747
3748 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003749 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003750 .family = MV88E6XXX_FAMILY_6390,
3751 .name = "Marvell 88E6191",
3752 .num_databases = 4096,
3753 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003754 .num_internal_phys = 11,
Vivien Didelot931d1822017-05-01 14:05:27 -04003755 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003756 .port_base_addr = 0x0,
3757 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003758 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003759 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003760 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003761 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003762 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003763 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003764 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003765 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003766 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003767 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003768 },
3769
Vivien Didelotf81ec902016-05-09 13:22:58 -04003770 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003771 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003772 .family = MV88E6XXX_FAMILY_6352,
3773 .name = "Marvell 88E6240",
3774 .num_databases = 4096,
3775 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003776 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003777 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003778 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003779 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003780 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003781 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003782 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003783 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003784 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003785 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003786 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003787 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003788 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003789 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003790 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003791 },
3792
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003793 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003794 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003795 .family = MV88E6XXX_FAMILY_6390,
3796 .name = "Marvell 88E6290",
3797 .num_databases = 4096,
3798 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003799 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003800 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003801 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003802 .port_base_addr = 0x0,
3803 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003804 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003805 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003806 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003807 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003808 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003809 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003810 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003811 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003812 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003813 .ops = &mv88e6290_ops,
3814 },
3815
Vivien Didelotf81ec902016-05-09 13:22:58 -04003816 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003817 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003818 .family = MV88E6XXX_FAMILY_6320,
3819 .name = "Marvell 88E6320",
3820 .num_databases = 4096,
3821 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003822 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003823 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003824 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003825 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003826 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003827 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003828 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003829 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003830 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003831 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003832 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003833 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003834 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003835 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003836 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003837 },
3838
3839 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003840 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003841 .family = MV88E6XXX_FAMILY_6320,
3842 .name = "Marvell 88E6321",
3843 .num_databases = 4096,
3844 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003845 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003846 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003847 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003848 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003849 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003850 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003851 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003852 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003853 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003854 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003855 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003856 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003857 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003858 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003859 },
3860
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003861 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003862 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003863 .family = MV88E6XXX_FAMILY_6341,
3864 .name = "Marvell 88E6341",
3865 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01003866 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003867 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003868 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003869 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003870 .port_base_addr = 0x10,
3871 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003872 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003873 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003874 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003875 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003876 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003877 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003878 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003879 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003880 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003881 .ops = &mv88e6341_ops,
3882 },
3883
Vivien Didelotf81ec902016-05-09 13:22:58 -04003884 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003885 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003886 .family = MV88E6XXX_FAMILY_6351,
3887 .name = "Marvell 88E6350",
3888 .num_databases = 4096,
3889 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003890 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003891 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003892 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003893 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003894 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003895 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003896 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003897 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003898 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003899 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003900 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003901 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003902 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003903 },
3904
3905 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003906 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003907 .family = MV88E6XXX_FAMILY_6351,
3908 .name = "Marvell 88E6351",
3909 .num_databases = 4096,
3910 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003911 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003912 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003913 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003914 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003915 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003916 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003917 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003918 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003919 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003920 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003921 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003922 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003923 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003924 },
3925
3926 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003927 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003928 .family = MV88E6XXX_FAMILY_6352,
3929 .name = "Marvell 88E6352",
3930 .num_databases = 4096,
3931 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003932 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003933 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003934 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003935 .port_base_addr = 0x10,
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 = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003947 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003948 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003949 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003950 .family = MV88E6XXX_FAMILY_6390,
3951 .name = "Marvell 88E6390",
3952 .num_databases = 4096,
3953 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003954 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003955 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003956 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003957 .port_base_addr = 0x0,
3958 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003959 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003960 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003961 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003962 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003963 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003964 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003965 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003966 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003967 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003968 .ops = &mv88e6390_ops,
3969 },
3970 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003971 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003972 .family = MV88E6XXX_FAMILY_6390,
3973 .name = "Marvell 88E6390X",
3974 .num_databases = 4096,
3975 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003976 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003977 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003978 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003979 .port_base_addr = 0x0,
3980 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003981 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003982 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003983 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003984 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003985 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003986 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003987 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003988 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003989 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003990 .ops = &mv88e6390x_ops,
3991 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003992};
3993
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003994static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003995{
Vivien Didelota439c062016-04-17 13:23:58 -04003996 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003997
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003998 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3999 if (mv88e6xxx_table[i].prod_num == prod_num)
4000 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004001
Vivien Didelotb9b37712015-10-30 19:39:48 -04004002 return NULL;
4003}
4004
Vivien Didelotfad09c72016-06-21 12:28:20 -04004005static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004006{
4007 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004008 unsigned int prod_num, rev;
4009 u16 id;
4010 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004011
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004012 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04004013 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004014 mutex_unlock(&chip->reg_lock);
4015 if (err)
4016 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004017
Vivien Didelot107fcc12017-06-12 12:37:36 -04004018 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
4019 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004020
4021 info = mv88e6xxx_lookup_info(prod_num);
4022 if (!info)
4023 return -ENODEV;
4024
Vivien Didelotcaac8542016-06-20 13:14:09 -04004025 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004026 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004027
Vivien Didelotca070c12016-09-02 14:45:34 -04004028 err = mv88e6xxx_g2_require(chip);
4029 if (err)
4030 return err;
4031
Vivien Didelotfad09c72016-06-21 12:28:20 -04004032 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4033 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004034
4035 return 0;
4036}
4037
Vivien Didelotfad09c72016-06-21 12:28:20 -04004038static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004039{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004040 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004041
Vivien Didelotfad09c72016-06-21 12:28:20 -04004042 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4043 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004044 return NULL;
4045
Vivien Didelotfad09c72016-06-21 12:28:20 -04004046 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004047
Vivien Didelotfad09c72016-06-21 12:28:20 -04004048 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004049 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004050
Vivien Didelotfad09c72016-06-21 12:28:20 -04004051 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004052}
4053
Vivien Didelotfad09c72016-06-21 12:28:20 -04004054static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004055 struct mii_bus *bus, int sw_addr)
4056{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004057 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004058 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004059 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004060 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004061 else
4062 return -EINVAL;
4063
Vivien Didelotfad09c72016-06-21 12:28:20 -04004064 chip->bus = bus;
4065 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004066
4067 return 0;
4068}
4069
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08004070static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4071 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02004072{
Vivien Didelot04bed142016-08-31 18:06:13 -04004073 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004074
Andrew Lunn443d5a12016-12-03 04:35:18 +01004075 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004076}
4077
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004078#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004079static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4080 struct device *host_dev, int sw_addr,
4081 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004082{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004083 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004084 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004085 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004086
Vivien Didelota439c062016-04-17 13:23:58 -04004087 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004088 if (!bus)
4089 return NULL;
4090
Vivien Didelotfad09c72016-06-21 12:28:20 -04004091 chip = mv88e6xxx_alloc_chip(dsa_dev);
4092 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004093 return NULL;
4094
Vivien Didelotcaac8542016-06-20 13:14:09 -04004095 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004096 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004097
Vivien Didelotfad09c72016-06-21 12:28:20 -04004098 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004099 if (err)
4100 goto free;
4101
Vivien Didelotfad09c72016-06-21 12:28:20 -04004102 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004103 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004104 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004105
Andrew Lunndc30c352016-10-16 19:56:49 +02004106 mutex_lock(&chip->reg_lock);
4107 err = mv88e6xxx_switch_reset(chip);
4108 mutex_unlock(&chip->reg_lock);
4109 if (err)
4110 goto free;
4111
Vivien Didelote57e5e72016-08-15 17:19:00 -04004112 mv88e6xxx_phy_init(chip);
4113
Andrew Lunna3c53be52017-01-24 14:53:50 +01004114 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004115 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004116 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004117
Vivien Didelotfad09c72016-06-21 12:28:20 -04004118 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004119
Vivien Didelotfad09c72016-06-21 12:28:20 -04004120 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004121free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004122 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004123
4124 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004125}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004126#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02004127
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004128static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004129 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004130{
4131 /* We don't need any dynamic resource from the kernel (yet),
4132 * so skip the prepare phase.
4133 */
4134
4135 return 0;
4136}
4137
4138static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004139 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004140{
Vivien Didelot04bed142016-08-31 18:06:13 -04004141 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004142
4143 mutex_lock(&chip->reg_lock);
4144 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004145 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004146 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4147 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004148 mutex_unlock(&chip->reg_lock);
4149}
4150
4151static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4152 const struct switchdev_obj_port_mdb *mdb)
4153{
Vivien Didelot04bed142016-08-31 18:06:13 -04004154 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004155 int err;
4156
4157 mutex_lock(&chip->reg_lock);
4158 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004159 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004160 mutex_unlock(&chip->reg_lock);
4161
4162 return err;
4163}
4164
Florian Fainellia82f67a2017-01-08 14:52:08 -08004165static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004166#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004167 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004168#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02004169 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004170 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004171 .adjust_link = mv88e6xxx_adjust_link,
4172 .get_strings = mv88e6xxx_get_strings,
4173 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4174 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004175 .port_enable = mv88e6xxx_port_enable,
4176 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004177 .get_mac_eee = mv88e6xxx_get_mac_eee,
4178 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004179 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004180 .get_eeprom = mv88e6xxx_get_eeprom,
4181 .set_eeprom = mv88e6xxx_set_eeprom,
4182 .get_regs_len = mv88e6xxx_get_regs_len,
4183 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004184 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004185 .port_bridge_join = mv88e6xxx_port_bridge_join,
4186 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4187 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004188 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004189 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4190 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4191 .port_vlan_add = mv88e6xxx_port_vlan_add,
4192 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004193 .port_fdb_add = mv88e6xxx_port_fdb_add,
4194 .port_fdb_del = mv88e6xxx_port_fdb_del,
4195 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004196 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4197 .port_mdb_add = mv88e6xxx_port_mdb_add,
4198 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004199 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4200 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004201 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4202 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4203 .port_txtstamp = mv88e6xxx_port_txtstamp,
4204 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4205 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004206};
4207
Florian Fainelliab3d4082017-01-08 14:52:07 -08004208static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4209 .ops = &mv88e6xxx_switch_ops,
4210};
4211
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004212static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004213{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004214 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004215 struct dsa_switch *ds;
4216
Vivien Didelot73b12042017-03-30 17:37:10 -04004217 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004218 if (!ds)
4219 return -ENOMEM;
4220
Vivien Didelotfad09c72016-06-21 12:28:20 -04004221 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004222 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004223 ds->ageing_time_min = chip->info->age_time_coeff;
4224 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004225
4226 dev_set_drvdata(dev, ds);
4227
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004228 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004229}
4230
Vivien Didelotfad09c72016-06-21 12:28:20 -04004231static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004232{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004233 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004234}
4235
Vivien Didelot57d32312016-06-20 13:13:58 -04004236static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004237{
4238 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004239 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004240 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004241 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004242 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004243 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004244
Vivien Didelotcaac8542016-06-20 13:14:09 -04004245 compat_info = of_device_get_match_data(dev);
4246 if (!compat_info)
4247 return -EINVAL;
4248
Vivien Didelotfad09c72016-06-21 12:28:20 -04004249 chip = mv88e6xxx_alloc_chip(dev);
4250 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004251 return -ENOMEM;
4252
Vivien Didelotfad09c72016-06-21 12:28:20 -04004253 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004254
Vivien Didelotfad09c72016-06-21 12:28:20 -04004255 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004256 if (err)
4257 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004258
Andrew Lunnb4308f02016-11-21 23:26:55 +01004259 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4260 if (IS_ERR(chip->reset))
4261 return PTR_ERR(chip->reset);
4262
Vivien Didelotfad09c72016-06-21 12:28:20 -04004263 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004264 if (err)
4265 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004266
Vivien Didelote57e5e72016-08-15 17:19:00 -04004267 mv88e6xxx_phy_init(chip);
4268
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004269 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004270 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004271 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004272
Andrew Lunndc30c352016-10-16 19:56:49 +02004273 mutex_lock(&chip->reg_lock);
4274 err = mv88e6xxx_switch_reset(chip);
4275 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004276 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004277 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004278
Andrew Lunndc30c352016-10-16 19:56:49 +02004279 chip->irq = of_irq_get(np, 0);
4280 if (chip->irq == -EPROBE_DEFER) {
4281 err = chip->irq;
4282 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004283 }
4284
Andrew Lunn294d7112018-02-22 22:58:32 +01004285 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01004286 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01004287 * controllers
4288 */
4289 mutex_lock(&chip->reg_lock);
4290 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004291 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004292 else
4293 err = mv88e6xxx_irq_poll_setup(chip);
4294 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004295
Andrew Lunn294d7112018-02-22 22:58:32 +01004296 if (err)
4297 goto out;
4298
4299 if (chip->info->g2_irqs > 0) {
4300 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004301 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004302 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004303 }
4304
Andrew Lunn294d7112018-02-22 22:58:32 +01004305 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4306 if (err)
4307 goto out_g2_irq;
4308
4309 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4310 if (err)
4311 goto out_g1_atu_prob_irq;
4312
Andrew Lunna3c53be52017-01-24 14:53:50 +01004313 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004314 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004315 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004316
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004317 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004318 if (err)
4319 goto out_mdio;
4320
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004321 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004322
4323out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004324 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004325out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004326 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004327out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004328 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004329out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004330 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004331 mv88e6xxx_g2_irq_free(chip);
4332out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004333 mutex_lock(&chip->reg_lock);
4334 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004335 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004336 else
4337 mv88e6xxx_irq_poll_free(chip);
4338 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004339out:
4340 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004341}
4342
4343static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4344{
4345 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004346 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004347
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004348 if (chip->info->ptp_support) {
4349 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004350 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004351 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004352
Andrew Lunn930188c2016-08-22 16:01:03 +02004353 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004354 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004355 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004356
Andrew Lunn76f38f12018-03-17 20:21:09 +01004357 mv88e6xxx_g1_vtu_prob_irq_free(chip);
4358 mv88e6xxx_g1_atu_prob_irq_free(chip);
4359
4360 if (chip->info->g2_irqs > 0)
4361 mv88e6xxx_g2_irq_free(chip);
4362
4363 mutex_lock(&chip->reg_lock);
4364 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004365 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01004366 else
4367 mv88e6xxx_irq_poll_free(chip);
4368 mutex_unlock(&chip->reg_lock);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004369}
4370
4371static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004372 {
4373 .compatible = "marvell,mv88e6085",
4374 .data = &mv88e6xxx_table[MV88E6085],
4375 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004376 {
4377 .compatible = "marvell,mv88e6190",
4378 .data = &mv88e6xxx_table[MV88E6190],
4379 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004380 { /* sentinel */ },
4381};
4382
4383MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4384
4385static struct mdio_driver mv88e6xxx_driver = {
4386 .probe = mv88e6xxx_probe,
4387 .remove = mv88e6xxx_remove,
4388 .mdiodrv.driver = {
4389 .name = "mv88e6085",
4390 .of_match_table = mv88e6xxx_of_match,
4391 },
4392};
4393
Ben Hutchings98e67302011-11-25 14:36:19 +00004394static int __init mv88e6xxx_init(void)
4395{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004396 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004397 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004398}
4399module_init(mv88e6xxx_init);
4400
4401static void __exit mv88e6xxx_cleanup(void)
4402{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004403 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004404 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004405}
4406module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004407
4408MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4409MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4410MODULE_LICENSE("GPL");