blob: 5b4374f21d76b873bff94afd466cb2a797025692 [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)
Andrew Lunn80c46272015-06-20 18:42:30 +0200668 return UINT64_MAX;
669
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)
Andrew Lunn80c46272015-06-20 18:42:30 +0200674 return UINT64_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:
688 return UINT64_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,
745 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
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100750 mutex_lock(&chip->reg_lock);
751
Andrew Lunndfafe442016-11-21 23:27:02 +0100752 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100753 count = chip->info->ops->stats_get_strings(chip, data);
754
755 if (chip->info->ops->serdes_get_strings) {
756 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200757 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100758 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100759
Andrew Lunn65f60e42018-03-28 23:50:28 +0200760 data += count * ETH_GSTRING_LEN;
761 mv88e6xxx_atu_vtu_get_strings(data);
762
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100763 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100764}
765
766static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
767 int types)
768{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100769 struct mv88e6xxx_hw_stat *stat;
770 int i, j;
771
772 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
773 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100774 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100775 j++;
776 }
777 return j;
778}
779
Andrew Lunndfafe442016-11-21 23:27:02 +0100780static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
781{
782 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
783 STATS_TYPE_PORT);
784}
785
786static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
787{
788 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
789 STATS_TYPE_BANK1);
790}
791
Andrew Lunn88c06052018-03-01 02:02:27 +0100792static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port)
Andrew Lunndfafe442016-11-21 23:27:02 +0100793{
794 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100795 int serdes_count = 0;
796 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100797
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100798 mutex_lock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100799 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100800 count = chip->info->ops->stats_get_sset_count(chip);
801 if (count < 0)
802 goto out;
803
804 if (chip->info->ops->serdes_get_sset_count)
805 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
806 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +0200807 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +0100808 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200809 goto out;
810 }
811 count += serdes_count;
812 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
813
Andrew Lunn436fe172018-03-01 02:02:29 +0100814out:
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100815 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100816
Andrew Lunn436fe172018-03-01 02:02:29 +0100817 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +0100818}
819
Andrew Lunn436fe172018-03-01 02:02:29 +0100820static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
821 uint64_t *data, int types,
822 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100823{
824 struct mv88e6xxx_hw_stat *stat;
825 int i, j;
826
827 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
828 stat = &mv88e6xxx_hw_stats[i];
829 if (stat->type & types) {
Andrew Lunn377cda12018-02-15 14:38:34 +0100830 mutex_lock(&chip->reg_lock);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100831 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
832 bank1_select,
833 histogram);
Andrew Lunn377cda12018-02-15 14:38:34 +0100834 mutex_unlock(&chip->reg_lock);
835
Andrew Lunn052f9472016-11-21 23:27:03 +0100836 j++;
837 }
838 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100839 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +0100840}
841
Andrew Lunn436fe172018-03-01 02:02:29 +0100842static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
843 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100844{
845 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100846 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400847 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100848}
849
Andrew Lunn436fe172018-03-01 02:02:29 +0100850static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
851 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100852{
853 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100854 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400855 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
856 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100857}
858
Andrew Lunn436fe172018-03-01 02:02:29 +0100859static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
860 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +0100861{
862 return mv88e6xxx_stats_get_stats(chip, port, data,
863 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400864 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
865 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100866}
867
Andrew Lunn65f60e42018-03-28 23:50:28 +0200868static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
869 uint64_t *data)
870{
871 *data++ = chip->ports[port].atu_member_violation;
872 *data++ = chip->ports[port].atu_miss_violation;
873 *data++ = chip->ports[port].atu_full_violation;
874 *data++ = chip->ports[port].vtu_member_violation;
875 *data++ = chip->ports[port].vtu_miss_violation;
876}
877
Andrew Lunn052f9472016-11-21 23:27:03 +0100878static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
879 uint64_t *data)
880{
Andrew Lunn436fe172018-03-01 02:02:29 +0100881 int count = 0;
882
Andrew Lunn052f9472016-11-21 23:27:03 +0100883 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +0100884 count = chip->info->ops->stats_get_stats(chip, port, data);
885
Andrew Lunn65f60e42018-03-28 23:50:28 +0200886 mutex_lock(&chip->reg_lock);
Andrew Lunn436fe172018-03-01 02:02:29 +0100887 if (chip->info->ops->serdes_get_stats) {
888 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200889 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100890 }
Andrew Lunn65f60e42018-03-28 23:50:28 +0200891 data += count;
892 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
893 mutex_unlock(&chip->reg_lock);
Andrew Lunn052f9472016-11-21 23:27:03 +0100894}
895
Vivien Didelotf81ec902016-05-09 13:22:58 -0400896static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
897 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000898{
Vivien Didelot04bed142016-08-31 18:06:13 -0400899 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000900 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000901
Vivien Didelotfad09c72016-06-21 12:28:20 -0400902 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000903
Andrew Lunna605a0f2016-11-21 23:26:58 +0100904 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +0100905 mutex_unlock(&chip->reg_lock);
906
907 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000908 return;
Andrew Lunn052f9472016-11-21 23:27:03 +0100909
910 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000911
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000912}
Ben Hutchings98e67302011-11-25 14:36:19 +0000913
Andrew Lunnde2273872016-11-21 23:27:01 +0100914static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
915{
916 if (chip->info->ops->stats_set_histogram)
917 return chip->info->ops->stats_set_histogram(chip);
918
919 return 0;
920}
921
Vivien Didelotf81ec902016-05-09 13:22:58 -0400922static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700923{
924 return 32 * sizeof(u16);
925}
926
Vivien Didelotf81ec902016-05-09 13:22:58 -0400927static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
928 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700929{
Vivien Didelot04bed142016-08-31 18:06:13 -0400930 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200931 int err;
932 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700933 u16 *p = _p;
934 int i;
935
936 regs->version = 0;
937
938 memset(p, 0xff, 32 * sizeof(u16));
939
Vivien Didelotfad09c72016-06-21 12:28:20 -0400940 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400941
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700942 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700943
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200944 err = mv88e6xxx_port_read(chip, port, i, &reg);
945 if (!err)
946 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700947 }
Vivien Didelot23062512016-05-09 13:22:45 -0400948
Vivien Didelotfad09c72016-06-21 12:28:20 -0400949 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700950}
951
Vivien Didelot08f50062017-08-01 16:32:41 -0400952static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
953 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800954{
Vivien Didelot5480db62017-08-01 16:32:40 -0400955 /* Nothing to do on the port's MAC */
956 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800957}
958
Vivien Didelot08f50062017-08-01 16:32:41 -0400959static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
960 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800961{
Vivien Didelot5480db62017-08-01 16:32:40 -0400962 /* Nothing to do on the port's MAC */
963 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800964}
965
Vivien Didelote5887a22017-03-30 17:37:11 -0400966static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700967{
Vivien Didelote5887a22017-03-30 17:37:11 -0400968 struct dsa_switch *ds = NULL;
969 struct net_device *br;
970 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500971 int i;
972
Vivien Didelote5887a22017-03-30 17:37:11 -0400973 if (dev < DSA_MAX_SWITCHES)
974 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500975
Vivien Didelote5887a22017-03-30 17:37:11 -0400976 /* Prevent frames from unknown switch or port */
977 if (!ds || port >= ds->num_ports)
978 return 0;
979
980 /* Frames from DSA links and CPU ports can egress any local port */
981 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
982 return mv88e6xxx_port_mask(chip);
983
984 br = ds->ports[port].bridge_dev;
985 pvlan = 0;
986
987 /* Frames from user ports can egress any local DSA links and CPU ports,
988 * as well as any local member of their bridge group.
989 */
990 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
991 if (dsa_is_cpu_port(chip->ds, i) ||
992 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -0400993 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -0400994 pvlan |= BIT(i);
995
996 return pvlan;
997}
998
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400999static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001000{
1001 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001002
1003 /* prevent frames from going back out of the port they came in on */
1004 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001005
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001006 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001007}
1008
Vivien Didelotf81ec902016-05-09 13:22:58 -04001009static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1010 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001011{
Vivien Didelot04bed142016-08-31 18:06:13 -04001012 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001013 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001014
Vivien Didelotfad09c72016-06-21 12:28:20 -04001015 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -04001016 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001017 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001018
1019 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001020 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001021}
1022
Vivien Didelot9e907d72017-07-17 13:03:43 -04001023static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1024{
1025 if (chip->info->ops->pot_clear)
1026 return chip->info->ops->pot_clear(chip);
1027
1028 return 0;
1029}
1030
Vivien Didelot51c901a2017-07-17 13:03:41 -04001031static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1032{
1033 if (chip->info->ops->mgmt_rsvd2cpu)
1034 return chip->info->ops->mgmt_rsvd2cpu(chip);
1035
1036 return 0;
1037}
1038
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001039static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1040{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001041 int err;
1042
Vivien Didelotdaefc942017-03-11 16:12:54 -05001043 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1044 if (err)
1045 return err;
1046
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001047 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1048 if (err)
1049 return err;
1050
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001051 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1052}
1053
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001054static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1055{
1056 int port;
1057 int err;
1058
1059 if (!chip->info->ops->irl_init_all)
1060 return 0;
1061
1062 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1063 /* Disable ingress rate limiting by resetting all per port
1064 * ingress rate limit resources to their initial state.
1065 */
1066 err = chip->info->ops->irl_init_all(chip, port);
1067 if (err)
1068 return err;
1069 }
1070
1071 return 0;
1072}
1073
Vivien Didelot04a69a12017-10-13 14:18:05 -04001074static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1075{
1076 if (chip->info->ops->set_switch_mac) {
1077 u8 addr[ETH_ALEN];
1078
1079 eth_random_addr(addr);
1080
1081 return chip->info->ops->set_switch_mac(chip, addr);
1082 }
1083
1084 return 0;
1085}
1086
Vivien Didelot17a15942017-03-30 17:37:09 -04001087static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1088{
1089 u16 pvlan = 0;
1090
1091 if (!mv88e6xxx_has_pvt(chip))
1092 return -EOPNOTSUPP;
1093
1094 /* Skip the local source device, which uses in-chip port VLAN */
1095 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001096 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001097
1098 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1099}
1100
Vivien Didelot81228992017-03-30 17:37:08 -04001101static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1102{
Vivien Didelot17a15942017-03-30 17:37:09 -04001103 int dev, port;
1104 int err;
1105
Vivien Didelot81228992017-03-30 17:37:08 -04001106 if (!mv88e6xxx_has_pvt(chip))
1107 return 0;
1108
1109 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1110 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1111 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001112 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1113 if (err)
1114 return err;
1115
1116 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1117 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1118 err = mv88e6xxx_pvt_map(chip, dev, port);
1119 if (err)
1120 return err;
1121 }
1122 }
1123
1124 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001125}
1126
Vivien Didelot749efcb2016-09-22 16:49:24 -04001127static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1128{
1129 struct mv88e6xxx_chip *chip = ds->priv;
1130 int err;
1131
1132 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001133 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001134 mutex_unlock(&chip->reg_lock);
1135
1136 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001137 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001138}
1139
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001140static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1141{
1142 if (!chip->info->max_vid)
1143 return 0;
1144
1145 return mv88e6xxx_g1_vtu_flush(chip);
1146}
1147
Vivien Didelotf1394b782017-05-01 14:05:22 -04001148static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1149 struct mv88e6xxx_vtu_entry *entry)
1150{
1151 if (!chip->info->ops->vtu_getnext)
1152 return -EOPNOTSUPP;
1153
1154 return chip->info->ops->vtu_getnext(chip, entry);
1155}
1156
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001157static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1158 struct mv88e6xxx_vtu_entry *entry)
1159{
1160 if (!chip->info->ops->vtu_loadpurge)
1161 return -EOPNOTSUPP;
1162
1163 return chip->info->ops->vtu_loadpurge(chip, entry);
1164}
1165
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001166static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001167{
1168 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001169 struct mv88e6xxx_vtu_entry vlan = {
1170 .vid = chip->info->max_vid,
1171 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001172 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001173
1174 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1175
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001176 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001177 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001178 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001179 if (err)
1180 return err;
1181
1182 set_bit(*fid, fid_bitmap);
1183 }
1184
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001185 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001186 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001187 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001188 if (err)
1189 return err;
1190
1191 if (!vlan.valid)
1192 break;
1193
1194 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001195 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001196
1197 /* The reset value 0x000 is used to indicate that multiple address
1198 * databases are not needed. Return the next positive available.
1199 */
1200 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001201 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001202 return -ENOSPC;
1203
1204 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001205 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001206}
1207
Vivien Didelot567aa592017-05-01 14:05:25 -04001208static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1209 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001210{
1211 int err;
1212
1213 if (!vid)
1214 return -EINVAL;
1215
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001216 entry->vid = vid - 1;
1217 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001218
Vivien Didelotf1394b782017-05-01 14:05:22 -04001219 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001220 if (err)
1221 return err;
1222
Vivien Didelot567aa592017-05-01 14:05:25 -04001223 if (entry->vid == vid && entry->valid)
1224 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001225
Vivien Didelot567aa592017-05-01 14:05:25 -04001226 if (new) {
1227 int i;
1228
1229 /* Initialize a fresh VLAN entry */
1230 memset(entry, 0, sizeof(*entry));
1231 entry->valid = true;
1232 entry->vid = vid;
1233
Vivien Didelot553a7682017-06-07 18:12:16 -04001234 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001235 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001236 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001237 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001238
1239 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001240 }
1241
Vivien Didelot567aa592017-05-01 14:05:25 -04001242 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1243 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001244}
1245
Vivien Didelotda9c3592016-02-12 12:09:40 -05001246static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1247 u16 vid_begin, u16 vid_end)
1248{
Vivien Didelot04bed142016-08-31 18:06:13 -04001249 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001250 struct mv88e6xxx_vtu_entry vlan = {
1251 .vid = vid_begin - 1,
1252 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001253 int i, err;
1254
Andrew Lunndb06ae412017-09-25 23:32:20 +02001255 /* DSA and CPU ports have to be members of multiple vlans */
1256 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1257 return 0;
1258
Vivien Didelotda9c3592016-02-12 12:09:40 -05001259 if (!vid_begin)
1260 return -EOPNOTSUPP;
1261
Vivien Didelotfad09c72016-06-21 12:28:20 -04001262 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001263
Vivien Didelotda9c3592016-02-12 12:09:40 -05001264 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001265 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001266 if (err)
1267 goto unlock;
1268
1269 if (!vlan.valid)
1270 break;
1271
1272 if (vlan.vid > vid_end)
1273 break;
1274
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001275 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001276 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1277 continue;
1278
Andrew Lunncd886462017-11-09 22:29:53 +01001279 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001280 continue;
1281
Vivien Didelotbd00e052017-05-01 14:05:11 -04001282 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001283 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001284 continue;
1285
Vivien Didelotc8652c82017-10-16 11:12:19 -04001286 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001287 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001288 break; /* same bridge, check next VLAN */
1289
Vivien Didelotc8652c82017-10-16 11:12:19 -04001290 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001291 continue;
1292
Andrew Lunn743fcc22017-11-09 22:29:54 +01001293 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1294 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001295 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001296 err = -EOPNOTSUPP;
1297 goto unlock;
1298 }
1299 } while (vlan.vid < vid_end);
1300
1301unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001302 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001303
1304 return err;
1305}
1306
Vivien Didelotf81ec902016-05-09 13:22:58 -04001307static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1308 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001309{
Vivien Didelot04bed142016-08-31 18:06:13 -04001310 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001311 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1312 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001313 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001314
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001315 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001316 return -EOPNOTSUPP;
1317
Vivien Didelotfad09c72016-06-21 12:28:20 -04001318 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001319 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001320 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001321
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001322 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001323}
1324
Vivien Didelot57d32312016-06-20 13:13:58 -04001325static int
1326mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001327 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001328{
Vivien Didelot04bed142016-08-31 18:06:13 -04001329 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001330 int err;
1331
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001332 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001333 return -EOPNOTSUPP;
1334
Vivien Didelotda9c3592016-02-12 12:09:40 -05001335 /* If the requested port doesn't belong to the same bridge as the VLAN
1336 * members, do not support it (yet) and fallback to software VLAN.
1337 */
1338 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1339 vlan->vid_end);
1340 if (err)
1341 return err;
1342
Vivien Didelot76e398a2015-11-01 12:33:55 -05001343 /* We don't need any dynamic resource from the kernel (yet),
1344 * so skip the prepare phase.
1345 */
1346 return 0;
1347}
1348
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001349static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1350 const unsigned char *addr, u16 vid,
1351 u8 state)
1352{
1353 struct mv88e6xxx_vtu_entry vlan;
1354 struct mv88e6xxx_atu_entry entry;
1355 int err;
1356
1357 /* Null VLAN ID corresponds to the port private database */
1358 if (vid == 0)
1359 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1360 else
1361 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1362 if (err)
1363 return err;
1364
1365 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1366 ether_addr_copy(entry.mac, addr);
1367 eth_addr_dec(entry.mac);
1368
1369 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1370 if (err)
1371 return err;
1372
1373 /* Initialize a fresh ATU entry if it isn't found */
1374 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1375 !ether_addr_equal(entry.mac, addr)) {
1376 memset(&entry, 0, sizeof(entry));
1377 ether_addr_copy(entry.mac, addr);
1378 }
1379
1380 /* Purge the ATU entry only if no port is using it anymore */
1381 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1382 entry.portvec &= ~BIT(port);
1383 if (!entry.portvec)
1384 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1385 } else {
1386 entry.portvec |= BIT(port);
1387 entry.state = state;
1388 }
1389
1390 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1391}
1392
Andrew Lunn87fa8862017-11-09 22:29:56 +01001393static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1394 u16 vid)
1395{
1396 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1397 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1398
1399 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1400}
1401
1402static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1403{
1404 int port;
1405 int err;
1406
1407 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1408 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1409 if (err)
1410 return err;
1411 }
1412
1413 return 0;
1414}
1415
Vivien Didelotfad09c72016-06-21 12:28:20 -04001416static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001417 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001418{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001419 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001420 int err;
1421
Vivien Didelot567aa592017-05-01 14:05:25 -04001422 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001423 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001424 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001425
Vivien Didelotc91498e2017-06-07 18:12:13 -04001426 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001427
Andrew Lunn87fa8862017-11-09 22:29:56 +01001428 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1429 if (err)
1430 return err;
1431
1432 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001433}
1434
Vivien Didelotf81ec902016-05-09 13:22:58 -04001435static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001436 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001437{
Vivien Didelot04bed142016-08-31 18:06:13 -04001438 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001439 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1440 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001441 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001442 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001443
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001444 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001445 return;
1446
Vivien Didelotc91498e2017-06-07 18:12:13 -04001447 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001448 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001449 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001450 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001451 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001452 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001453
Vivien Didelotfad09c72016-06-21 12:28:20 -04001454 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001455
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001456 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001457 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001458 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1459 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001460
Vivien Didelot77064f32016-11-04 03:23:30 +01001461 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001462 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1463 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001464
Vivien Didelotfad09c72016-06-21 12:28:20 -04001465 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001466}
1467
Vivien Didelotfad09c72016-06-21 12:28:20 -04001468static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001469 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001470{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001471 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001472 int i, err;
1473
Vivien Didelot567aa592017-05-01 14:05:25 -04001474 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001475 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001476 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001477
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001478 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001479 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001480 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001481
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001482 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001483
1484 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001485 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001486 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001487 if (vlan.member[i] !=
1488 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001489 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001490 break;
1491 }
1492 }
1493
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001494 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001495 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001496 return err;
1497
Vivien Didelote606ca32017-03-11 16:12:55 -05001498 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001499}
1500
Vivien Didelotf81ec902016-05-09 13:22:58 -04001501static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1502 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001503{
Vivien Didelot04bed142016-08-31 18:06:13 -04001504 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001505 u16 pvid, vid;
1506 int err = 0;
1507
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001508 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001509 return -EOPNOTSUPP;
1510
Vivien Didelotfad09c72016-06-21 12:28:20 -04001511 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001512
Vivien Didelot77064f32016-11-04 03:23:30 +01001513 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001514 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001515 goto unlock;
1516
Vivien Didelot76e398a2015-11-01 12:33:55 -05001517 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001518 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001519 if (err)
1520 goto unlock;
1521
1522 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001523 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001524 if (err)
1525 goto unlock;
1526 }
1527 }
1528
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001529unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001530 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001531
1532 return err;
1533}
1534
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001535static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1536 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001537{
Vivien Didelot04bed142016-08-31 18:06:13 -04001538 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001539 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001540
Vivien Didelotfad09c72016-06-21 12:28:20 -04001541 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001542 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1543 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001544 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001545
1546 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001547}
1548
Vivien Didelotf81ec902016-05-09 13:22:58 -04001549static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001550 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001551{
Vivien Didelot04bed142016-08-31 18:06:13 -04001552 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001553 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001554
Vivien Didelotfad09c72016-06-21 12:28:20 -04001555 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001556 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001557 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001558 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001559
Vivien Didelot83dabd12016-08-31 11:50:04 -04001560 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001561}
1562
Vivien Didelot83dabd12016-08-31 11:50:04 -04001563static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1564 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001565 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001566{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001567 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001568 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001569 int err;
1570
Vivien Didelot27c0e602017-06-15 12:14:01 -04001571 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001572 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001573
1574 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001575 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001576 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001577 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001578 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001579 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001580
Vivien Didelot27c0e602017-06-15 12:14:01 -04001581 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001582 break;
1583
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001584 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001585 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001586
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001587 if (!is_unicast_ether_addr(addr.mac))
1588 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001589
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001590 is_static = (addr.state ==
1591 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1592 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001593 if (err)
1594 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001595 } while (!is_broadcast_ether_addr(addr.mac));
1596
1597 return err;
1598}
1599
Vivien Didelot83dabd12016-08-31 11:50:04 -04001600static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001601 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001602{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001603 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001604 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001605 };
1606 u16 fid;
1607 int err;
1608
1609 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001610 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001611 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001612 mutex_unlock(&chip->reg_lock);
1613
Vivien Didelot83dabd12016-08-31 11:50:04 -04001614 if (err)
1615 return err;
1616
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001617 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001618 if (err)
1619 return err;
1620
1621 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001622 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001623 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001624 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001625 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001626 if (err)
1627 return err;
1628
1629 if (!vlan.valid)
1630 break;
1631
1632 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001633 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001634 if (err)
1635 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001636 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001637
1638 return err;
1639}
1640
Vivien Didelotf81ec902016-05-09 13:22:58 -04001641static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001642 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001643{
Vivien Didelot04bed142016-08-31 18:06:13 -04001644 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001645
Andrew Lunna61e5402018-02-15 14:38:35 +01001646 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001647}
1648
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001649static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1650 struct net_device *br)
1651{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001652 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001653 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001654 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001655 int err;
1656
1657 /* Remap the Port VLAN of each local bridge group member */
1658 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1659 if (chip->ds->ports[port].bridge_dev == br) {
1660 err = mv88e6xxx_port_vlan_map(chip, port);
1661 if (err)
1662 return err;
1663 }
1664 }
1665
Vivien Didelote96a6e02017-03-30 17:37:13 -04001666 if (!mv88e6xxx_has_pvt(chip))
1667 return 0;
1668
1669 /* Remap the Port VLAN of each cross-chip bridge group member */
1670 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1671 ds = chip->ds->dst->ds[dev];
1672 if (!ds)
1673 break;
1674
1675 for (port = 0; port < ds->num_ports; ++port) {
1676 if (ds->ports[port].bridge_dev == br) {
1677 err = mv88e6xxx_pvt_map(chip, dev, port);
1678 if (err)
1679 return err;
1680 }
1681 }
1682 }
1683
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001684 return 0;
1685}
1686
Vivien Didelotf81ec902016-05-09 13:22:58 -04001687static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001688 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001689{
Vivien Didelot04bed142016-08-31 18:06:13 -04001690 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001691 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001692
Vivien Didelotfad09c72016-06-21 12:28:20 -04001693 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001694 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001695 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001696
Vivien Didelot466dfa02016-02-26 13:16:05 -05001697 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001698}
1699
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001700static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1701 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001702{
Vivien Didelot04bed142016-08-31 18:06:13 -04001703 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001704
Vivien Didelotfad09c72016-06-21 12:28:20 -04001705 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001706 if (mv88e6xxx_bridge_map(chip, br) ||
1707 mv88e6xxx_port_vlan_map(chip, port))
1708 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001709 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001710}
1711
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001712static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1713 int port, struct net_device *br)
1714{
1715 struct mv88e6xxx_chip *chip = ds->priv;
1716 int err;
1717
1718 if (!mv88e6xxx_has_pvt(chip))
1719 return 0;
1720
1721 mutex_lock(&chip->reg_lock);
1722 err = mv88e6xxx_pvt_map(chip, dev, port);
1723 mutex_unlock(&chip->reg_lock);
1724
1725 return err;
1726}
1727
1728static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1729 int port, struct net_device *br)
1730{
1731 struct mv88e6xxx_chip *chip = ds->priv;
1732
1733 if (!mv88e6xxx_has_pvt(chip))
1734 return;
1735
1736 mutex_lock(&chip->reg_lock);
1737 if (mv88e6xxx_pvt_map(chip, dev, port))
1738 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1739 mutex_unlock(&chip->reg_lock);
1740}
1741
Vivien Didelot17e708b2016-12-05 17:30:27 -05001742static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1743{
1744 if (chip->info->ops->reset)
1745 return chip->info->ops->reset(chip);
1746
1747 return 0;
1748}
1749
Vivien Didelot309eca62016-12-05 17:30:26 -05001750static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1751{
1752 struct gpio_desc *gpiod = chip->reset;
1753
1754 /* If there is a GPIO connected to the reset pin, toggle it */
1755 if (gpiod) {
1756 gpiod_set_value_cansleep(gpiod, 1);
1757 usleep_range(10000, 20000);
1758 gpiod_set_value_cansleep(gpiod, 0);
1759 usleep_range(10000, 20000);
1760 }
1761}
1762
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001763static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1764{
1765 int i, err;
1766
1767 /* Set all ports to the Disabled state */
1768 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001769 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001770 if (err)
1771 return err;
1772 }
1773
1774 /* Wait for transmit queues to drain,
1775 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1776 */
1777 usleep_range(2000, 4000);
1778
1779 return 0;
1780}
1781
Vivien Didelotfad09c72016-06-21 12:28:20 -04001782static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001783{
Vivien Didelota935c052016-09-29 12:21:53 -04001784 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001785
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001786 err = mv88e6xxx_disable_ports(chip);
1787 if (err)
1788 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001789
Vivien Didelot309eca62016-12-05 17:30:26 -05001790 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001791
Vivien Didelot17e708b2016-12-05 17:30:27 -05001792 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001793}
1794
Vivien Didelot43145572017-03-11 16:12:59 -05001795static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001796 enum mv88e6xxx_frame_mode frame,
1797 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001798{
1799 int err;
1800
Vivien Didelot43145572017-03-11 16:12:59 -05001801 if (!chip->info->ops->port_set_frame_mode)
1802 return -EOPNOTSUPP;
1803
1804 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001805 if (err)
1806 return err;
1807
Vivien Didelot43145572017-03-11 16:12:59 -05001808 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1809 if (err)
1810 return err;
1811
1812 if (chip->info->ops->port_set_ether_type)
1813 return chip->info->ops->port_set_ether_type(chip, port, etype);
1814
1815 return 0;
1816}
1817
1818static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1819{
1820 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001821 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001822 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001823}
1824
1825static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1826{
1827 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001828 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001829 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001830}
1831
1832static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1833{
1834 return mv88e6xxx_set_port_mode(chip, port,
1835 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001836 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1837 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001838}
1839
1840static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1841{
1842 if (dsa_is_dsa_port(chip->ds, port))
1843 return mv88e6xxx_set_port_mode_dsa(chip, port);
1844
Vivien Didelot2b3e9892017-10-26 11:22:54 -04001845 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05001846 return mv88e6xxx_set_port_mode_normal(chip, port);
1847
1848 /* Setup CPU port mode depending on its supported tag format */
1849 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1850 return mv88e6xxx_set_port_mode_dsa(chip, port);
1851
1852 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1853 return mv88e6xxx_set_port_mode_edsa(chip, port);
1854
1855 return -EINVAL;
1856}
1857
Vivien Didelotea698f42017-03-11 16:12:50 -05001858static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1859{
1860 bool message = dsa_is_dsa_port(chip->ds, port);
1861
1862 return mv88e6xxx_port_set_message_port(chip, port, message);
1863}
1864
Vivien Didelot601aeed2017-03-11 16:13:00 -05001865static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1866{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001867 struct dsa_switch *ds = chip->ds;
1868 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05001869
1870 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001871 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05001872 if (chip->info->ops->port_set_egress_floods)
1873 return chip->info->ops->port_set_egress_floods(chip, port,
1874 flood, flood);
1875
1876 return 0;
1877}
1878
Andrew Lunn6d917822017-05-26 01:03:21 +02001879static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1880 bool on)
1881{
Vivien Didelot523a8902017-05-26 18:02:42 -04001882 if (chip->info->ops->serdes_power)
1883 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001884
Vivien Didelot523a8902017-05-26 18:02:42 -04001885 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001886}
1887
Vivien Didelotfa371c82017-12-05 15:34:10 -05001888static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
1889{
1890 struct dsa_switch *ds = chip->ds;
1891 int upstream_port;
1892 int err;
1893
Vivien Didelot07073c72017-12-05 15:34:13 -05001894 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05001895 if (chip->info->ops->port_set_upstream_port) {
1896 err = chip->info->ops->port_set_upstream_port(chip, port,
1897 upstream_port);
1898 if (err)
1899 return err;
1900 }
1901
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05001902 if (port == upstream_port) {
1903 if (chip->info->ops->set_cpu_port) {
1904 err = chip->info->ops->set_cpu_port(chip,
1905 upstream_port);
1906 if (err)
1907 return err;
1908 }
1909
1910 if (chip->info->ops->set_egress_port) {
1911 err = chip->info->ops->set_egress_port(chip,
1912 upstream_port);
1913 if (err)
1914 return err;
1915 }
1916 }
1917
Vivien Didelotfa371c82017-12-05 15:34:10 -05001918 return 0;
1919}
1920
Vivien Didelotfad09c72016-06-21 12:28:20 -04001921static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001922{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001923 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001924 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001925 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001926
Vivien Didelotd78343d2016-11-04 03:23:36 +01001927 /* MAC Forcing register: don't force link, speed, duplex or flow control
1928 * state to any particular values on physical ports, but force the CPU
1929 * port and all DSA ports to their maximum bandwidth and full duplex.
1930 */
1931 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1932 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1933 SPEED_MAX, DUPLEX_FULL,
1934 PHY_INTERFACE_MODE_NA);
1935 else
1936 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1937 SPEED_UNFORCED, DUPLEX_UNFORCED,
1938 PHY_INTERFACE_MODE_NA);
1939 if (err)
1940 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001941
1942 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1943 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1944 * tunneling, determine priority by looking at 802.1p and IP
1945 * priority fields (IP prio has precedence), and set STP state
1946 * to Forwarding.
1947 *
1948 * If this is the CPU link, use DSA or EDSA tagging depending
1949 * on which tagging mode was configured.
1950 *
1951 * If this is a link to another switch, use DSA tagging mode.
1952 *
1953 * If this is the upstream port for this switch, enable
1954 * forwarding of unknown unicasts and multicasts.
1955 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04001956 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
1957 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
1958 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1959 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001960 if (err)
1961 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001962
Vivien Didelot601aeed2017-03-11 16:13:00 -05001963 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001964 if (err)
1965 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001966
Vivien Didelot601aeed2017-03-11 16:13:00 -05001967 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001968 if (err)
1969 return err;
1970
Andrew Lunn04aca992017-05-26 01:03:24 +02001971 /* Enable the SERDES interface for DSA and CPU ports. Normal
1972 * ports SERDES are enabled when the port is enabled, thus
1973 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001974 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001975 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1976 err = mv88e6xxx_serdes_power(chip, port, true);
1977 if (err)
1978 return err;
1979 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001980
Vivien Didelot8efdda42015-08-13 12:52:23 -04001981 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001982 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001983 * untagged frames on this port, do a destination address lookup on all
1984 * received packets as usual, disable ARP mirroring and don't send a
1985 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001986 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001987 err = mv88e6xxx_port_set_map_da(chip, port);
1988 if (err)
1989 return err;
1990
Vivien Didelotfa371c82017-12-05 15:34:10 -05001991 err = mv88e6xxx_setup_upstream_port(chip, port);
1992 if (err)
1993 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001994
Andrew Lunna23b2962017-02-04 20:15:28 +01001995 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001996 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01001997 if (err)
1998 return err;
1999
Vivien Didelotcd782652017-06-08 18:34:13 -04002000 if (chip->info->ops->port_set_jumbo_size) {
2001 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002002 if (err)
2003 return err;
2004 }
2005
Andrew Lunn54d792f2015-05-06 01:09:47 +02002006 /* Port Association Vector: when learning source addresses
2007 * of packets, add the address to the address database using
2008 * a port bitmap that has only the bit for this port set and
2009 * the other bits clear.
2010 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002011 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002012 /* Disable learning for CPU port */
2013 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002014 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002015
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002016 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2017 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002018 if (err)
2019 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002020
2021 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002022 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2023 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002024 if (err)
2025 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002026
Vivien Didelot08984322017-06-08 18:34:12 -04002027 if (chip->info->ops->port_pause_limit) {
2028 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002029 if (err)
2030 return err;
2031 }
2032
Vivien Didelotc8c94892017-03-11 16:13:01 -05002033 if (chip->info->ops->port_disable_learn_limit) {
2034 err = chip->info->ops->port_disable_learn_limit(chip, port);
2035 if (err)
2036 return err;
2037 }
2038
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002039 if (chip->info->ops->port_disable_pri_override) {
2040 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002041 if (err)
2042 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002043 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002044
Andrew Lunnef0a7312016-12-03 04:35:16 +01002045 if (chip->info->ops->port_tag_remap) {
2046 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002047 if (err)
2048 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002049 }
2050
Andrew Lunnef70b112016-12-03 04:45:18 +01002051 if (chip->info->ops->port_egress_rate_limiting) {
2052 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002053 if (err)
2054 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002055 }
2056
Vivien Didelotea698f42017-03-11 16:12:50 -05002057 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002058 if (err)
2059 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002060
Vivien Didelot207afda2016-04-14 14:42:09 -04002061 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002062 * database, and allow bidirectional communication between the
2063 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002064 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002065 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002066 if (err)
2067 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002068
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002069 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002070 if (err)
2071 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002072
2073 /* Default VLAN ID and priority: don't set a default VLAN
2074 * ID, and set the default packet priority to zero.
2075 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002076 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002077}
2078
Andrew Lunn04aca992017-05-26 01:03:24 +02002079static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2080 struct phy_device *phydev)
2081{
2082 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002083 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002084
2085 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002086 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002087 mutex_unlock(&chip->reg_lock);
2088
2089 return err;
2090}
2091
2092static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2093 struct phy_device *phydev)
2094{
2095 struct mv88e6xxx_chip *chip = ds->priv;
2096
2097 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002098 if (mv88e6xxx_serdes_power(chip, port, false))
2099 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002100 mutex_unlock(&chip->reg_lock);
2101}
2102
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002103static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2104 unsigned int ageing_time)
2105{
Vivien Didelot04bed142016-08-31 18:06:13 -04002106 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002107 int err;
2108
2109 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002110 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002111 mutex_unlock(&chip->reg_lock);
2112
2113 return err;
2114}
2115
Vivien Didelot97299342016-07-18 20:45:30 -04002116static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002117{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002118 struct dsa_switch *ds = chip->ds;
Vivien Didelot08a01262016-05-09 13:22:50 -04002119 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002120
Vivien Didelot50484ff2016-05-09 13:22:54 -04002121 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelotd77f4322017-06-15 12:14:03 -04002122 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2123 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
Vivien Didelota935c052016-09-29 12:21:53 -04002124 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002125 if (err)
2126 return err;
2127
Vivien Didelot08a01262016-05-09 13:22:50 -04002128 /* Configure the IP ToS mapping registers. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002129 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002130 if (err)
2131 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002132 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002133 if (err)
2134 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002135 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002136 if (err)
2137 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002138 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002139 if (err)
2140 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002141 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002142 if (err)
2143 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002144 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002145 if (err)
2146 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002147 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002148 if (err)
2149 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002150 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002151 if (err)
2152 return err;
2153
2154 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002155 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002156 if (err)
2157 return err;
2158
Andrew Lunnde2273872016-11-21 23:27:01 +01002159 /* Initialize the statistics unit */
2160 err = mv88e6xxx_stats_set_histogram(chip);
2161 if (err)
2162 return err;
2163
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002164 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002165}
2166
Vivien Didelotf81ec902016-05-09 13:22:58 -04002167static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002168{
Vivien Didelot04bed142016-08-31 18:06:13 -04002169 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002170 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002171 int i;
2172
Vivien Didelotfad09c72016-06-21 12:28:20 -04002173 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002174 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002175
Vivien Didelotfad09c72016-06-21 12:28:20 -04002176 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002177
Vivien Didelot97299342016-07-18 20:45:30 -04002178 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002179 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002180 if (dsa_is_unused_port(ds, i))
2181 continue;
2182
Vivien Didelot97299342016-07-18 20:45:30 -04002183 err = mv88e6xxx_setup_port(chip, i);
2184 if (err)
2185 goto unlock;
2186 }
2187
2188 /* Setup Switch Global 1 Registers */
2189 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002190 if (err)
2191 goto unlock;
2192
Vivien Didelot97299342016-07-18 20:45:30 -04002193 /* Setup Switch Global 2 Registers */
Vivien Didelot9069c132017-07-17 13:03:44 -04002194 if (chip->info->global2_addr) {
Vivien Didelot97299342016-07-18 20:45:30 -04002195 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002196 if (err)
2197 goto unlock;
2198 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002199
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002200 err = mv88e6xxx_irl_setup(chip);
2201 if (err)
2202 goto unlock;
2203
Vivien Didelot04a69a12017-10-13 14:18:05 -04002204 err = mv88e6xxx_mac_setup(chip);
2205 if (err)
2206 goto unlock;
2207
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002208 err = mv88e6xxx_phy_setup(chip);
2209 if (err)
2210 goto unlock;
2211
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002212 err = mv88e6xxx_vtu_setup(chip);
2213 if (err)
2214 goto unlock;
2215
Vivien Didelot81228992017-03-30 17:37:08 -04002216 err = mv88e6xxx_pvt_setup(chip);
2217 if (err)
2218 goto unlock;
2219
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002220 err = mv88e6xxx_atu_setup(chip);
2221 if (err)
2222 goto unlock;
2223
Andrew Lunn87fa8862017-11-09 22:29:56 +01002224 err = mv88e6xxx_broadcast_setup(chip, 0);
2225 if (err)
2226 goto unlock;
2227
Vivien Didelot9e907d72017-07-17 13:03:43 -04002228 err = mv88e6xxx_pot_setup(chip);
2229 if (err)
2230 goto unlock;
2231
Vivien Didelot51c901a2017-07-17 13:03:41 -04002232 err = mv88e6xxx_rsvd2cpu_setup(chip);
2233 if (err)
2234 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002235
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002236 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002237 if (chip->info->ptp_support) {
2238 err = mv88e6xxx_ptp_setup(chip);
2239 if (err)
2240 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002241
2242 err = mv88e6xxx_hwtstamp_setup(chip);
2243 if (err)
2244 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002245 }
2246
Vivien Didelot6b17e862015-08-13 12:52:18 -04002247unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002248 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002249
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002250 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002251}
2252
Vivien Didelote57e5e72016-08-15 17:19:00 -04002253static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002254{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002255 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2256 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002257 u16 val;
2258 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002259
Andrew Lunnee26a222017-01-24 14:53:48 +01002260 if (!chip->info->ops->phy_read)
2261 return -EOPNOTSUPP;
2262
Vivien Didelotfad09c72016-06-21 12:28:20 -04002263 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002264 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002265 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002266
Andrew Lunnda9f3302017-02-01 03:40:05 +01002267 if (reg == MII_PHYSID2) {
2268 /* Some internal PHYS don't have a model number. Use
2269 * the mv88e6390 family model number instead.
2270 */
2271 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002272 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002273 }
2274
Vivien Didelote57e5e72016-08-15 17:19:00 -04002275 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002276}
2277
Vivien Didelote57e5e72016-08-15 17:19:00 -04002278static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002279{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002280 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2281 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002282 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002283
Andrew Lunnee26a222017-01-24 14:53:48 +01002284 if (!chip->info->ops->phy_write)
2285 return -EOPNOTSUPP;
2286
Vivien Didelotfad09c72016-06-21 12:28:20 -04002287 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002288 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002289 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002290
2291 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002292}
2293
Vivien Didelotfad09c72016-06-21 12:28:20 -04002294static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002295 struct device_node *np,
2296 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002297{
2298 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002299 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002300 struct mii_bus *bus;
2301 int err;
2302
Andrew Lunn2510bab2018-02-22 01:51:49 +01002303 if (external) {
2304 mutex_lock(&chip->reg_lock);
2305 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2306 mutex_unlock(&chip->reg_lock);
2307
2308 if (err)
2309 return err;
2310 }
2311
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002312 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002313 if (!bus)
2314 return -ENOMEM;
2315
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002316 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002317 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002318 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002319 INIT_LIST_HEAD(&mdio_bus->list);
2320 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002321
Andrew Lunnb516d452016-06-04 21:17:06 +02002322 if (np) {
2323 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002324 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002325 } else {
2326 bus->name = "mv88e6xxx SMI";
2327 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2328 }
2329
2330 bus->read = mv88e6xxx_mdio_read;
2331 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002332 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002333
Andrew Lunn6f882842018-03-17 20:32:05 +01002334 if (!external) {
2335 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2336 if (err)
2337 return err;
2338 }
2339
Andrew Lunna3c53be52017-01-24 14:53:50 +01002340 if (np)
2341 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002342 else
2343 err = mdiobus_register(bus);
2344 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002345 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002346 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002347 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002348 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002349
2350 if (external)
2351 list_add_tail(&mdio_bus->list, &chip->mdios);
2352 else
2353 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002354
2355 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002356}
2357
Andrew Lunna3c53be52017-01-24 14:53:50 +01002358static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2359 { .compatible = "marvell,mv88e6xxx-mdio-external",
2360 .data = (void *)true },
2361 { },
2362};
2363
Andrew Lunn3126aee2017-12-07 01:05:57 +01002364static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2365
2366{
2367 struct mv88e6xxx_mdio_bus *mdio_bus;
2368 struct mii_bus *bus;
2369
2370 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2371 bus = mdio_bus->bus;
2372
Andrew Lunn6f882842018-03-17 20:32:05 +01002373 if (!mdio_bus->external)
2374 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2375
Andrew Lunn3126aee2017-12-07 01:05:57 +01002376 mdiobus_unregister(bus);
2377 }
2378}
2379
Andrew Lunna3c53be52017-01-24 14:53:50 +01002380static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2381 struct device_node *np)
2382{
2383 const struct of_device_id *match;
2384 struct device_node *child;
2385 int err;
2386
2387 /* Always register one mdio bus for the internal/default mdio
2388 * bus. This maybe represented in the device tree, but is
2389 * optional.
2390 */
2391 child = of_get_child_by_name(np, "mdio");
2392 err = mv88e6xxx_mdio_register(chip, child, false);
2393 if (err)
2394 return err;
2395
2396 /* Walk the device tree, and see if there are any other nodes
2397 * which say they are compatible with the external mdio
2398 * bus.
2399 */
2400 for_each_available_child_of_node(np, child) {
2401 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2402 if (match) {
2403 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002404 if (err) {
2405 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002406 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002407 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002408 }
2409 }
2410
2411 return 0;
2412}
2413
Vivien Didelot855b1932016-07-20 18:18:35 -04002414static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2415{
Vivien Didelot04bed142016-08-31 18:06:13 -04002416 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002417
2418 return chip->eeprom_len;
2419}
2420
Vivien Didelot855b1932016-07-20 18:18:35 -04002421static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2422 struct ethtool_eeprom *eeprom, u8 *data)
2423{
Vivien Didelot04bed142016-08-31 18:06:13 -04002424 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002425 int err;
2426
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002427 if (!chip->info->ops->get_eeprom)
2428 return -EOPNOTSUPP;
2429
Vivien Didelot855b1932016-07-20 18:18:35 -04002430 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002431 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002432 mutex_unlock(&chip->reg_lock);
2433
2434 if (err)
2435 return err;
2436
2437 eeprom->magic = 0xc3ec4951;
2438
2439 return 0;
2440}
2441
Vivien Didelot855b1932016-07-20 18:18:35 -04002442static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2443 struct ethtool_eeprom *eeprom, u8 *data)
2444{
Vivien Didelot04bed142016-08-31 18:06:13 -04002445 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002446 int err;
2447
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002448 if (!chip->info->ops->set_eeprom)
2449 return -EOPNOTSUPP;
2450
Vivien Didelot855b1932016-07-20 18:18:35 -04002451 if (eeprom->magic != 0xc3ec4951)
2452 return -EINVAL;
2453
2454 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002455 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002456 mutex_unlock(&chip->reg_lock);
2457
2458 return err;
2459}
2460
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002461static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002462 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002463 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002464 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002465 .phy_read = mv88e6185_phy_ppu_read,
2466 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002467 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002468 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002469 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002470 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002471 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002472 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002473 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002474 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002475 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002476 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002477 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002478 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002479 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002480 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2481 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002482 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002483 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2484 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002485 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002486 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002487 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002488 .ppu_enable = mv88e6185_g1_ppu_enable,
2489 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002490 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002491 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002492 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002493};
2494
2495static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002496 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002497 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002498 .phy_read = mv88e6185_phy_ppu_read,
2499 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002500 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002501 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002502 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002503 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002504 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002505 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002506 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002507 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002508 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2509 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002510 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002511 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002512 .ppu_enable = mv88e6185_g1_ppu_enable,
2513 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002514 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002515 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002516 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002517};
2518
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002519static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002520 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002521 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002522 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2523 .phy_read = mv88e6xxx_g2_smi_phy_read,
2524 .phy_write = mv88e6xxx_g2_smi_phy_write,
2525 .port_set_link = mv88e6xxx_port_set_link,
2526 .port_set_duplex = mv88e6xxx_port_set_duplex,
2527 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002528 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002529 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002530 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002531 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002532 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002533 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002534 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002535 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002536 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002537 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002538 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002539 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2540 .stats_get_strings = mv88e6095_stats_get_strings,
2541 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002542 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2543 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002544 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002545 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002546 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002547 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002548 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002549 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002550};
2551
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002552static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002553 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002554 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002555 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002556 .phy_read = mv88e6xxx_g2_smi_phy_read,
2557 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002558 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002559 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002560 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002561 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002562 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002563 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002564 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002565 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002566 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002567 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2568 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002569 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002570 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2571 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002572 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002573 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002574 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002575 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002576 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002577 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002578};
2579
2580static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002581 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002582 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002583 .phy_read = mv88e6185_phy_ppu_read,
2584 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002585 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002586 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002587 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002588 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002589 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002590 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002591 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002592 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002593 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002594 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002595 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002596 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002597 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002598 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2599 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002600 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002601 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2602 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002603 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002604 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002605 .ppu_enable = mv88e6185_g1_ppu_enable,
2606 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002607 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002608 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002609 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002610};
2611
Vivien Didelot990e27b2017-03-28 13:50:32 -04002612static const struct mv88e6xxx_ops mv88e6141_ops = {
2613 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002614 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002615 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2616 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2617 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2618 .phy_read = mv88e6xxx_g2_smi_phy_read,
2619 .phy_write = mv88e6xxx_g2_smi_phy_write,
2620 .port_set_link = mv88e6xxx_port_set_link,
2621 .port_set_duplex = mv88e6xxx_port_set_duplex,
2622 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2623 .port_set_speed = mv88e6390_port_set_speed,
2624 .port_tag_remap = mv88e6095_port_tag_remap,
2625 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2626 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2627 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002628 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002629 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002630 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002631 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2632 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2633 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002634 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002635 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2636 .stats_get_strings = mv88e6320_stats_get_strings,
2637 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002638 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2639 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002640 .watchdog_ops = &mv88e6390_watchdog_ops,
2641 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002642 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002643 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002644 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002645 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002646 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002647};
2648
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002649static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002650 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002651 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002652 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002653 .phy_read = mv88e6xxx_g2_smi_phy_read,
2654 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002655 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002656 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002657 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002658 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002659 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002660 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002661 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002662 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002663 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002664 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002665 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002666 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002667 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002668 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002669 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2670 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002671 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002672 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2673 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002674 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002675 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002676 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002677 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002678 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002679 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002680};
2681
2682static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002683 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002684 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002685 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002686 .phy_read = mv88e6165_phy_read,
2687 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002688 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002689 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002690 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002691 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002692 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002693 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002694 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002695 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2696 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002697 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002698 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2699 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002700 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002701 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002702 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002703 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002704 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002705 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002706};
2707
2708static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002709 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002710 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002711 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002712 .phy_read = mv88e6xxx_g2_smi_phy_read,
2713 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002714 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002715 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002716 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002717 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002718 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002719 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002720 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002721 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002722 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002723 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002724 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002725 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002726 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002727 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002728 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002729 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2730 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002731 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002732 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2733 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002734 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002735 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002736 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002737 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002738 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002739 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002740};
2741
2742static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002743 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002744 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002745 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2746 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002747 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002748 .phy_read = mv88e6xxx_g2_smi_phy_read,
2749 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002750 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002751 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002752 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002753 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002754 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002755 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002756 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002757 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002758 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002759 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002760 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002761 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002762 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002763 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002764 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002765 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2766 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002767 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002768 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2769 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002770 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002771 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002772 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002773 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002774 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002775 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002776 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002777 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002778};
2779
2780static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002781 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002782 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002783 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002784 .phy_read = mv88e6xxx_g2_smi_phy_read,
2785 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002786 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002787 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002788 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002789 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002790 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002791 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002792 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002793 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002794 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002795 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002796 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002797 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002798 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002799 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002800 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002801 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2802 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002803 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002804 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2805 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002806 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002807 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002808 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002809 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002810 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002811 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002812};
2813
2814static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002815 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002816 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002817 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2818 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002819 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002820 .phy_read = mv88e6xxx_g2_smi_phy_read,
2821 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002822 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002823 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002824 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002825 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002826 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002827 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002828 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002829 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002830 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002831 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002832 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002833 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002834 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002835 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002836 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002837 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2838 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002839 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002840 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2841 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002842 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002843 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002844 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002845 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002846 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002847 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002848 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002849 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002850};
2851
2852static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002853 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002854 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002855 .phy_read = mv88e6185_phy_ppu_read,
2856 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002857 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002858 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002859 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002860 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002861 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002862 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002863 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002864 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002865 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002866 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2867 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002868 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002869 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2870 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002871 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002872 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002873 .ppu_enable = mv88e6185_g1_ppu_enable,
2874 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002875 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002876 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002877 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002878};
2879
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002880static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002881 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002882 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002883 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2884 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002885 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2886 .phy_read = mv88e6xxx_g2_smi_phy_read,
2887 .phy_write = mv88e6xxx_g2_smi_phy_write,
2888 .port_set_link = mv88e6xxx_port_set_link,
2889 .port_set_duplex = mv88e6xxx_port_set_duplex,
2890 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2891 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002892 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002893 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002894 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002895 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002896 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002897 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002898 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002899 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002900 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002901 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2902 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002903 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002904 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2905 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002906 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002907 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002908 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002909 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002910 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2911 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002912 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002913 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002914};
2915
2916static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002917 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002918 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002919 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2920 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002921 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2922 .phy_read = mv88e6xxx_g2_smi_phy_read,
2923 .phy_write = mv88e6xxx_g2_smi_phy_write,
2924 .port_set_link = mv88e6xxx_port_set_link,
2925 .port_set_duplex = mv88e6xxx_port_set_duplex,
2926 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2927 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002928 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002929 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002930 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002931 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002932 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002933 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002934 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002935 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002936 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002937 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2938 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002939 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002940 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2941 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002942 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002943 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002944 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002945 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002946 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2947 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002948 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002949 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002950};
2951
2952static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002953 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002954 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002955 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2956 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002957 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2958 .phy_read = mv88e6xxx_g2_smi_phy_read,
2959 .phy_write = mv88e6xxx_g2_smi_phy_write,
2960 .port_set_link = mv88e6xxx_port_set_link,
2961 .port_set_duplex = mv88e6xxx_port_set_duplex,
2962 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2963 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002964 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002965 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002966 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002967 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002968 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002969 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002970 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002971 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002972 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002973 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2974 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002975 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002976 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2977 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002978 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002979 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002980 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002981 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002982 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2983 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002984 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002985};
2986
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002987static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002988 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002989 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002990 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2991 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002992 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002993 .phy_read = mv88e6xxx_g2_smi_phy_read,
2994 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002995 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002996 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002997 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002998 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002999 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003000 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003001 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003002 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003003 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003004 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003005 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003006 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003007 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003008 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003009 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003010 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3011 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003012 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003013 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3014 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003015 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003016 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003017 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003018 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003019 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003020 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003021 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003022 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003023 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003024};
3025
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003026static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003027 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003028 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003029 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3030 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003031 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3032 .phy_read = mv88e6xxx_g2_smi_phy_read,
3033 .phy_write = mv88e6xxx_g2_smi_phy_write,
3034 .port_set_link = mv88e6xxx_port_set_link,
3035 .port_set_duplex = mv88e6xxx_port_set_duplex,
3036 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3037 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003038 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003039 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003040 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003041 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003042 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003043 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003044 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003045 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003046 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003047 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003048 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3049 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003050 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003051 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3052 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003053 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003054 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003055 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003056 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003057 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3058 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003059 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003060 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003061 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003062};
3063
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003064static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003065 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003066 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003067 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3068 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003069 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003070 .phy_read = mv88e6xxx_g2_smi_phy_read,
3071 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003072 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003073 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003074 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003075 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003076 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003077 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003078 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003079 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003080 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003081 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003082 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003083 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003084 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003085 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003086 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3087 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003088 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003089 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3090 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003091 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003092 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003093 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003094 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003095 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003096 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003097 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003098};
3099
3100static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003101 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003102 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003103 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3104 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003105 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003106 .phy_read = mv88e6xxx_g2_smi_phy_read,
3107 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003108 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003109 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003110 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003111 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003112 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003113 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003114 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003115 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003116 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003117 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003118 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003119 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003120 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003121 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003122 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3123 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003124 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003125 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3126 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003127 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003128 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003129 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003130 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003131 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003132};
3133
Vivien Didelot16e329a2017-03-28 13:50:33 -04003134static const struct mv88e6xxx_ops mv88e6341_ops = {
3135 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003136 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003137 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3138 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3139 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3140 .phy_read = mv88e6xxx_g2_smi_phy_read,
3141 .phy_write = mv88e6xxx_g2_smi_phy_write,
3142 .port_set_link = mv88e6xxx_port_set_link,
3143 .port_set_duplex = mv88e6xxx_port_set_duplex,
3144 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3145 .port_set_speed = mv88e6390_port_set_speed,
3146 .port_tag_remap = mv88e6095_port_tag_remap,
3147 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3148 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3149 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003150 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003151 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003152 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003153 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3154 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3155 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003156 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003157 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3158 .stats_get_strings = mv88e6320_stats_get_strings,
3159 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003160 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3161 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003162 .watchdog_ops = &mv88e6390_watchdog_ops,
3163 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003164 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003165 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003166 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003167 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003168 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003169 .avb_ops = &mv88e6390_avb_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003170};
3171
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003172static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003173 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003174 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003175 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003176 .phy_read = mv88e6xxx_g2_smi_phy_read,
3177 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003178 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003179 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003180 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003181 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003182 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003183 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003184 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003185 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003186 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003187 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003188 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003189 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003190 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003191 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003192 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003193 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3194 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003195 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003196 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3197 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003198 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003199 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003200 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003201 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003202 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003203 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003204};
3205
3206static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003207 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003208 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003209 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003210 .phy_read = mv88e6xxx_g2_smi_phy_read,
3211 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003212 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003213 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003214 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003215 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003216 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003217 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003218 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003219 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003220 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003221 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003222 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003223 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003224 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003225 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003226 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003227 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3228 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003229 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003230 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3231 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003232 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003233 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003234 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003235 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003236 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003237 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003238 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003239};
3240
3241static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003242 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003243 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003244 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3245 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003246 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003247 .phy_read = mv88e6xxx_g2_smi_phy_read,
3248 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003249 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003250 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003251 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003252 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003253 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003254 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003255 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003256 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003257 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003258 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003259 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003260 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003261 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003262 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003263 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003264 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3265 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003266 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003267 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3268 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003269 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003270 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003271 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003272 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003273 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003274 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003275 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003276 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003277 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01003278 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
3279 .serdes_get_strings = mv88e6352_serdes_get_strings,
3280 .serdes_get_stats = mv88e6352_serdes_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003281};
3282
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003283static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003284 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003285 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003286 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3287 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003288 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3289 .phy_read = mv88e6xxx_g2_smi_phy_read,
3290 .phy_write = mv88e6xxx_g2_smi_phy_write,
3291 .port_set_link = mv88e6xxx_port_set_link,
3292 .port_set_duplex = mv88e6xxx_port_set_duplex,
3293 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3294 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003295 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003296 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003297 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003298 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003299 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003300 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003301 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003302 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003303 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003304 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003305 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003306 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003307 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3308 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003309 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003310 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3311 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003312 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003313 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003314 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003315 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003316 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3317 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003318 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003319 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003320 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003321};
3322
3323static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003324 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003325 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003326 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3327 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003328 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3329 .phy_read = mv88e6xxx_g2_smi_phy_read,
3330 .phy_write = mv88e6xxx_g2_smi_phy_write,
3331 .port_set_link = mv88e6xxx_port_set_link,
3332 .port_set_duplex = mv88e6xxx_port_set_duplex,
3333 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3334 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003335 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003336 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003337 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003338 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003339 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003340 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003341 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003342 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003343 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003344 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003345 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003346 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003347 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3348 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003349 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003350 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3351 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003352 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003353 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003354 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003355 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003356 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3357 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003358 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003359 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003360 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003361};
3362
Vivien Didelotf81ec902016-05-09 13:22:58 -04003363static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3364 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003365 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003366 .family = MV88E6XXX_FAMILY_6097,
3367 .name = "Marvell 88E6085",
3368 .num_databases = 4096,
3369 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003370 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003371 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003372 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003373 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003374 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003375 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003376 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003377 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003378 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003379 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003380 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003381 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003382 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003383 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003384 },
3385
3386 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003387 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003388 .family = MV88E6XXX_FAMILY_6095,
3389 .name = "Marvell 88E6095/88E6095F",
3390 .num_databases = 256,
3391 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003392 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003393 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003394 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003395 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003396 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003397 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003398 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003399 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003400 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003401 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003402 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003403 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003404 },
3405
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003406 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003407 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003408 .family = MV88E6XXX_FAMILY_6097,
3409 .name = "Marvell 88E6097/88E6097F",
3410 .num_databases = 4096,
3411 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003412 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003413 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003414 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003415 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003416 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003417 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003418 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003419 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003420 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003421 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003422 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003423 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003424 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003425 .ops = &mv88e6097_ops,
3426 },
3427
Vivien Didelotf81ec902016-05-09 13:22:58 -04003428 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003429 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003430 .family = MV88E6XXX_FAMILY_6165,
3431 .name = "Marvell 88E6123",
3432 .num_databases = 4096,
3433 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01003434 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003435 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003436 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003437 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003438 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003439 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003440 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003441 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003442 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003443 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003444 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003445 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003446 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003447 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003448 },
3449
3450 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003451 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003452 .family = MV88E6XXX_FAMILY_6185,
3453 .name = "Marvell 88E6131",
3454 .num_databases = 256,
3455 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003456 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003457 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003458 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003459 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003460 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003461 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003462 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003463 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003464 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003465 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003466 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003467 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003468 },
3469
Vivien Didelot990e27b2017-03-28 13:50:32 -04003470 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003471 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003472 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01003473 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04003474 .num_databases = 4096,
3475 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003476 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003477 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003478 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003479 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003480 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003481 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003482 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003483 .age_time_coeff = 3750,
3484 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003485 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003486 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003487 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003488 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003489 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003490 .ops = &mv88e6141_ops,
3491 },
3492
Vivien Didelotf81ec902016-05-09 13:22:58 -04003493 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003494 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003495 .family = MV88E6XXX_FAMILY_6165,
3496 .name = "Marvell 88E6161",
3497 .num_databases = 4096,
3498 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003499 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003500 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003501 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003502 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003503 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003504 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003505 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003506 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003507 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003508 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003509 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003510 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003511 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003512 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003513 },
3514
3515 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003516 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003517 .family = MV88E6XXX_FAMILY_6165,
3518 .name = "Marvell 88E6165",
3519 .num_databases = 4096,
3520 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003521 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003522 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003523 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003524 .phy_base_addr = 0x0,
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 Didelotd6c5e6a2017-07-17 13:03:40 -04003529 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003530 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003531 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003532 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003533 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003534 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003535 },
3536
3537 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003538 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003539 .family = MV88E6XXX_FAMILY_6351,
3540 .name = "Marvell 88E6171",
3541 .num_databases = 4096,
3542 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003543 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003544 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003545 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003546 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003547 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003548 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003549 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003550 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003551 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003552 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003553 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003554 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003555 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003556 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003557 },
3558
3559 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003560 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003561 .family = MV88E6XXX_FAMILY_6352,
3562 .name = "Marvell 88E6172",
3563 .num_databases = 4096,
3564 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003565 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003566 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003567 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003568 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003569 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003570 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003571 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003572 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003573 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003574 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003575 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003576 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003577 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003578 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003579 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003580 },
3581
3582 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003583 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003584 .family = MV88E6XXX_FAMILY_6351,
3585 .name = "Marvell 88E6175",
3586 .num_databases = 4096,
3587 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003588 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003589 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003590 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003591 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003592 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003593 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003594 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003595 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003596 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003597 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003598 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003599 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003600 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003601 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003602 },
3603
3604 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003605 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003606 .family = MV88E6XXX_FAMILY_6352,
3607 .name = "Marvell 88E6176",
3608 .num_databases = 4096,
3609 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003610 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003611 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003612 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003613 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003614 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003615 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003616 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003617 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003618 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003619 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003620 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003621 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003622 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003623 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003624 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003625 },
3626
3627 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003628 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003629 .family = MV88E6XXX_FAMILY_6185,
3630 .name = "Marvell 88E6185",
3631 .num_databases = 256,
3632 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003633 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003634 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003635 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003636 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003637 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003638 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003639 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003640 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003641 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003642 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003643 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003644 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003645 },
3646
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003647 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003648 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003649 .family = MV88E6XXX_FAMILY_6390,
3650 .name = "Marvell 88E6190",
3651 .num_databases = 4096,
3652 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003653 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003654 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003655 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003656 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003657 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003658 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003659 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003660 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003661 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003662 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003663 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003664 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003665 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003666 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003667 .ops = &mv88e6190_ops,
3668 },
3669
3670 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003671 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003672 .family = MV88E6XXX_FAMILY_6390,
3673 .name = "Marvell 88E6190X",
3674 .num_databases = 4096,
3675 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003676 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003677 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003678 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003679 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003680 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003681 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003682 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003683 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003684 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003685 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003686 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003687 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003688 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003689 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003690 .ops = &mv88e6190x_ops,
3691 },
3692
3693 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003694 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003695 .family = MV88E6XXX_FAMILY_6390,
3696 .name = "Marvell 88E6191",
3697 .num_databases = 4096,
3698 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003699 .num_internal_phys = 11,
Vivien Didelot931d1822017-05-01 14:05:27 -04003700 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003701 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003702 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003703 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003704 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003705 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003706 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003707 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003708 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003709 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003710 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003711 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003712 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003713 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003714 },
3715
Vivien Didelotf81ec902016-05-09 13:22:58 -04003716 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003717 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003718 .family = MV88E6XXX_FAMILY_6352,
3719 .name = "Marvell 88E6240",
3720 .num_databases = 4096,
3721 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003722 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003723 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003724 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003725 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003726 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003727 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003728 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003729 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003730 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003731 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003732 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003733 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003734 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003735 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003736 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003737 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003738 },
3739
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003740 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003741 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003742 .family = MV88E6XXX_FAMILY_6390,
3743 .name = "Marvell 88E6290",
3744 .num_databases = 4096,
3745 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003746 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003747 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003748 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003749 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003750 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003751 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003752 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003753 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003754 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003755 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003756 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003757 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003758 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003759 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003760 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003761 .ops = &mv88e6290_ops,
3762 },
3763
Vivien Didelotf81ec902016-05-09 13:22:58 -04003764 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003765 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003766 .family = MV88E6XXX_FAMILY_6320,
3767 .name = "Marvell 88E6320",
3768 .num_databases = 4096,
3769 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003770 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003771 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003772 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003773 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003774 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003775 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003776 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003777 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003778 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003779 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003780 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003781 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003782 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003783 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003784 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003785 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003786 },
3787
3788 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003789 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003790 .family = MV88E6XXX_FAMILY_6320,
3791 .name = "Marvell 88E6321",
3792 .num_databases = 4096,
3793 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003794 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003795 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003796 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003797 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003798 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003799 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003800 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003801 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003802 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003803 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003804 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003805 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003806 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003807 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003808 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003809 },
3810
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003811 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003812 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003813 .family = MV88E6XXX_FAMILY_6341,
3814 .name = "Marvell 88E6341",
3815 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01003816 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003817 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003818 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003819 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003820 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003821 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003822 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003823 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003824 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003825 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003826 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003827 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003828 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003829 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003830 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003831 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003832 .ops = &mv88e6341_ops,
3833 },
3834
Vivien Didelotf81ec902016-05-09 13:22:58 -04003835 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003836 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003837 .family = MV88E6XXX_FAMILY_6351,
3838 .name = "Marvell 88E6350",
3839 .num_databases = 4096,
3840 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003841 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003842 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003843 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003844 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003845 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003846 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003847 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003848 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003849 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003850 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003851 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003852 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003853 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003854 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003855 },
3856
3857 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003858 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003859 .family = MV88E6XXX_FAMILY_6351,
3860 .name = "Marvell 88E6351",
3861 .num_databases = 4096,
3862 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003863 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003864 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003865 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003866 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003867 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003868 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003869 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003870 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003871 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003872 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003873 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003874 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003875 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003876 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003877 },
3878
3879 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003880 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003881 .family = MV88E6XXX_FAMILY_6352,
3882 .name = "Marvell 88E6352",
3883 .num_databases = 4096,
3884 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003885 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003886 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003887 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003888 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003889 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04003890 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003891 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003892 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003893 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003894 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003895 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003896 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003897 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003898 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003899 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003900 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003901 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003902 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003903 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003904 .family = MV88E6XXX_FAMILY_6390,
3905 .name = "Marvell 88E6390",
3906 .num_databases = 4096,
3907 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003908 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003909 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003910 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003911 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003912 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003913 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003914 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003915 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003916 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003917 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003918 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003919 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003920 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003921 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003922 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003923 .ops = &mv88e6390_ops,
3924 },
3925 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003926 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003927 .family = MV88E6XXX_FAMILY_6390,
3928 .name = "Marvell 88E6390X",
3929 .num_databases = 4096,
3930 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003931 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003932 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003933 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003934 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02003935 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003936 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003937 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003938 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003939 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003940 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003941 .atu_move_port_mask = 0x1f,
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_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003945 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003946 .ops = &mv88e6390x_ops,
3947 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003948};
3949
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003950static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003951{
Vivien Didelota439c062016-04-17 13:23:58 -04003952 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003953
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003954 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3955 if (mv88e6xxx_table[i].prod_num == prod_num)
3956 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003957
Vivien Didelotb9b37712015-10-30 19:39:48 -04003958 return NULL;
3959}
3960
Vivien Didelotfad09c72016-06-21 12:28:20 -04003961static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003962{
3963 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003964 unsigned int prod_num, rev;
3965 u16 id;
3966 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003967
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003968 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04003969 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003970 mutex_unlock(&chip->reg_lock);
3971 if (err)
3972 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003973
Vivien Didelot107fcc12017-06-12 12:37:36 -04003974 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
3975 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003976
3977 info = mv88e6xxx_lookup_info(prod_num);
3978 if (!info)
3979 return -ENODEV;
3980
Vivien Didelotcaac8542016-06-20 13:14:09 -04003981 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003982 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003983
Vivien Didelotca070c12016-09-02 14:45:34 -04003984 err = mv88e6xxx_g2_require(chip);
3985 if (err)
3986 return err;
3987
Vivien Didelotfad09c72016-06-21 12:28:20 -04003988 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3989 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003990
3991 return 0;
3992}
3993
Vivien Didelotfad09c72016-06-21 12:28:20 -04003994static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003995{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003996 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003997
Vivien Didelotfad09c72016-06-21 12:28:20 -04003998 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3999 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004000 return NULL;
4001
Vivien Didelotfad09c72016-06-21 12:28:20 -04004002 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004003
Vivien Didelotfad09c72016-06-21 12:28:20 -04004004 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004005 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004006
Vivien Didelotfad09c72016-06-21 12:28:20 -04004007 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004008}
4009
Vivien Didelotfad09c72016-06-21 12:28:20 -04004010static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004011 struct mii_bus *bus, int sw_addr)
4012{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004013 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004014 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004015 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004016 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004017 else
4018 return -EINVAL;
4019
Vivien Didelotfad09c72016-06-21 12:28:20 -04004020 chip->bus = bus;
4021 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004022
4023 return 0;
4024}
4025
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08004026static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4027 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02004028{
Vivien Didelot04bed142016-08-31 18:06:13 -04004029 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004030
Andrew Lunn443d5a12016-12-03 04:35:18 +01004031 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004032}
4033
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004034#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004035static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4036 struct device *host_dev, int sw_addr,
4037 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004038{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004039 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004040 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004041 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004042
Vivien Didelota439c062016-04-17 13:23:58 -04004043 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004044 if (!bus)
4045 return NULL;
4046
Vivien Didelotfad09c72016-06-21 12:28:20 -04004047 chip = mv88e6xxx_alloc_chip(dsa_dev);
4048 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004049 return NULL;
4050
Vivien Didelotcaac8542016-06-20 13:14:09 -04004051 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004052 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004053
Vivien Didelotfad09c72016-06-21 12:28:20 -04004054 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004055 if (err)
4056 goto free;
4057
Vivien Didelotfad09c72016-06-21 12:28:20 -04004058 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004059 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004060 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004061
Andrew Lunndc30c352016-10-16 19:56:49 +02004062 mutex_lock(&chip->reg_lock);
4063 err = mv88e6xxx_switch_reset(chip);
4064 mutex_unlock(&chip->reg_lock);
4065 if (err)
4066 goto free;
4067
Vivien Didelote57e5e72016-08-15 17:19:00 -04004068 mv88e6xxx_phy_init(chip);
4069
Andrew Lunna3c53be52017-01-24 14:53:50 +01004070 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004071 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004072 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004073
Vivien Didelotfad09c72016-06-21 12:28:20 -04004074 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004075
Vivien Didelotfad09c72016-06-21 12:28:20 -04004076 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004077free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004078 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004079
4080 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004081}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004082#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02004083
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004084static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004085 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004086{
4087 /* We don't need any dynamic resource from the kernel (yet),
4088 * so skip the prepare phase.
4089 */
4090
4091 return 0;
4092}
4093
4094static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004095 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004096{
Vivien Didelot04bed142016-08-31 18:06:13 -04004097 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004098
4099 mutex_lock(&chip->reg_lock);
4100 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004101 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004102 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4103 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004104 mutex_unlock(&chip->reg_lock);
4105}
4106
4107static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4108 const struct switchdev_obj_port_mdb *mdb)
4109{
Vivien Didelot04bed142016-08-31 18:06:13 -04004110 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004111 int err;
4112
4113 mutex_lock(&chip->reg_lock);
4114 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004115 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004116 mutex_unlock(&chip->reg_lock);
4117
4118 return err;
4119}
4120
Florian Fainellia82f67a2017-01-08 14:52:08 -08004121static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004122#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004123 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004124#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02004125 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004126 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004127 .adjust_link = mv88e6xxx_adjust_link,
4128 .get_strings = mv88e6xxx_get_strings,
4129 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4130 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004131 .port_enable = mv88e6xxx_port_enable,
4132 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004133 .get_mac_eee = mv88e6xxx_get_mac_eee,
4134 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004135 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004136 .get_eeprom = mv88e6xxx_get_eeprom,
4137 .set_eeprom = mv88e6xxx_set_eeprom,
4138 .get_regs_len = mv88e6xxx_get_regs_len,
4139 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004140 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004141 .port_bridge_join = mv88e6xxx_port_bridge_join,
4142 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4143 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004144 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004145 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4146 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4147 .port_vlan_add = mv88e6xxx_port_vlan_add,
4148 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004149 .port_fdb_add = mv88e6xxx_port_fdb_add,
4150 .port_fdb_del = mv88e6xxx_port_fdb_del,
4151 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004152 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4153 .port_mdb_add = mv88e6xxx_port_mdb_add,
4154 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004155 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4156 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004157 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4158 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4159 .port_txtstamp = mv88e6xxx_port_txtstamp,
4160 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4161 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004162};
4163
Florian Fainelliab3d4082017-01-08 14:52:07 -08004164static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4165 .ops = &mv88e6xxx_switch_ops,
4166};
4167
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004168static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004169{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004170 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004171 struct dsa_switch *ds;
4172
Vivien Didelot73b12042017-03-30 17:37:10 -04004173 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004174 if (!ds)
4175 return -ENOMEM;
4176
Vivien Didelotfad09c72016-06-21 12:28:20 -04004177 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004178 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004179 ds->ageing_time_min = chip->info->age_time_coeff;
4180 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004181
4182 dev_set_drvdata(dev, ds);
4183
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004184 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004185}
4186
Vivien Didelotfad09c72016-06-21 12:28:20 -04004187static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004188{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004189 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004190}
4191
Vivien Didelot57d32312016-06-20 13:13:58 -04004192static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004193{
4194 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004195 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004196 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004197 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004198 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004199 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004200
Vivien Didelotcaac8542016-06-20 13:14:09 -04004201 compat_info = of_device_get_match_data(dev);
4202 if (!compat_info)
4203 return -EINVAL;
4204
Vivien Didelotfad09c72016-06-21 12:28:20 -04004205 chip = mv88e6xxx_alloc_chip(dev);
4206 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004207 return -ENOMEM;
4208
Vivien Didelotfad09c72016-06-21 12:28:20 -04004209 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004210
Vivien Didelotfad09c72016-06-21 12:28:20 -04004211 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004212 if (err)
4213 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004214
Andrew Lunnb4308f02016-11-21 23:26:55 +01004215 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4216 if (IS_ERR(chip->reset))
4217 return PTR_ERR(chip->reset);
4218
Vivien Didelotfad09c72016-06-21 12:28:20 -04004219 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004220 if (err)
4221 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004222
Vivien Didelote57e5e72016-08-15 17:19:00 -04004223 mv88e6xxx_phy_init(chip);
4224
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004225 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004226 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004227 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004228
Andrew Lunndc30c352016-10-16 19:56:49 +02004229 mutex_lock(&chip->reg_lock);
4230 err = mv88e6xxx_switch_reset(chip);
4231 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004232 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004233 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004234
Andrew Lunndc30c352016-10-16 19:56:49 +02004235 chip->irq = of_irq_get(np, 0);
4236 if (chip->irq == -EPROBE_DEFER) {
4237 err = chip->irq;
4238 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004239 }
4240
Andrew Lunn294d7112018-02-22 22:58:32 +01004241 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01004242 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01004243 * controllers
4244 */
4245 mutex_lock(&chip->reg_lock);
4246 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004247 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004248 else
4249 err = mv88e6xxx_irq_poll_setup(chip);
4250 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004251
Andrew Lunn294d7112018-02-22 22:58:32 +01004252 if (err)
4253 goto out;
4254
4255 if (chip->info->g2_irqs > 0) {
4256 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004257 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004258 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004259 }
4260
Andrew Lunn294d7112018-02-22 22:58:32 +01004261 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4262 if (err)
4263 goto out_g2_irq;
4264
4265 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4266 if (err)
4267 goto out_g1_atu_prob_irq;
4268
Andrew Lunna3c53be52017-01-24 14:53:50 +01004269 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004270 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004271 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004272
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004273 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004274 if (err)
4275 goto out_mdio;
4276
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004277 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004278
4279out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004280 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004281out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004282 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004283out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004284 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004285out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004286 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004287 mv88e6xxx_g2_irq_free(chip);
4288out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004289 mutex_lock(&chip->reg_lock);
4290 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004291 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004292 else
4293 mv88e6xxx_irq_poll_free(chip);
4294 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004295out:
4296 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004297}
4298
4299static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4300{
4301 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004302 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004303
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004304 if (chip->info->ptp_support) {
4305 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004306 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004307 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004308
Andrew Lunn930188c2016-08-22 16:01:03 +02004309 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004310 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004311 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004312
Andrew Lunn76f38f12018-03-17 20:21:09 +01004313 mv88e6xxx_g1_vtu_prob_irq_free(chip);
4314 mv88e6xxx_g1_atu_prob_irq_free(chip);
4315
4316 if (chip->info->g2_irqs > 0)
4317 mv88e6xxx_g2_irq_free(chip);
4318
4319 mutex_lock(&chip->reg_lock);
4320 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004321 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01004322 else
4323 mv88e6xxx_irq_poll_free(chip);
4324 mutex_unlock(&chip->reg_lock);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004325}
4326
4327static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004328 {
4329 .compatible = "marvell,mv88e6085",
4330 .data = &mv88e6xxx_table[MV88E6085],
4331 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004332 {
4333 .compatible = "marvell,mv88e6190",
4334 .data = &mv88e6xxx_table[MV88E6190],
4335 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004336 { /* sentinel */ },
4337};
4338
4339MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4340
4341static struct mdio_driver mv88e6xxx_driver = {
4342 .probe = mv88e6xxx_probe,
4343 .remove = mv88e6xxx_remove,
4344 .mdiodrv.driver = {
4345 .name = "mv88e6085",
4346 .of_match_table = mv88e6xxx_of_match,
4347 },
4348};
4349
Ben Hutchings98e67302011-11-25 14:36:19 +00004350static int __init mv88e6xxx_init(void)
4351{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004352 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004353 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004354}
4355module_init(mv88e6xxx_init);
4356
4357static void __exit mv88e6xxx_cleanup(void)
4358{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004359 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004360 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004361}
4362module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004363
4364MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4365MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4366MODULE_LICENSE("GPL");