blob: fd78378ad6b1017ce064ad3dc2c48ed89380d8f6 [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,
428 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
429 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{
470 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
471 kthread_destroy_worker(chip->kworker);
472}
473
Vivien Didelotec561272016-09-02 14:45:33 -0400474int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400475{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200476 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400477
Andrew Lunn6441e6692016-08-19 00:01:55 +0200478 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400479 u16 val;
480 int err;
481
482 err = mv88e6xxx_read(chip, addr, reg, &val);
483 if (err)
484 return err;
485
486 if (!(val & mask))
487 return 0;
488
489 usleep_range(1000, 2000);
490 }
491
Andrew Lunn30853552016-08-19 00:01:57 +0200492 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400493 return -ETIMEDOUT;
494}
495
Vivien Didelotf22ab642016-07-18 20:45:31 -0400496/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400497int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400498{
499 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200500 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400501
502 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200503 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
504 if (err)
505 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400506
507 /* Set the Update bit to trigger a write operation */
508 val = BIT(15) | update;
509
510 return mv88e6xxx_write(chip, addr, reg, val);
511}
512
Vivien Didelotd78343d2016-11-04 03:23:36 +0100513static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
514 int link, int speed, int duplex,
515 phy_interface_t mode)
516{
517 int err;
518
519 if (!chip->info->ops->port_set_link)
520 return 0;
521
522 /* Port's MAC control must not be changed unless the link is down */
523 err = chip->info->ops->port_set_link(chip, port, 0);
524 if (err)
525 return err;
526
527 if (chip->info->ops->port_set_speed) {
528 err = chip->info->ops->port_set_speed(chip, port, speed);
529 if (err && err != -EOPNOTSUPP)
530 goto restore_link;
531 }
532
533 if (chip->info->ops->port_set_duplex) {
534 err = chip->info->ops->port_set_duplex(chip, port, duplex);
535 if (err && err != -EOPNOTSUPP)
536 goto restore_link;
537 }
538
539 if (chip->info->ops->port_set_rgmii_delay) {
540 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
541 if (err && err != -EOPNOTSUPP)
542 goto restore_link;
543 }
544
Andrew Lunnf39908d2017-02-04 20:02:50 +0100545 if (chip->info->ops->port_set_cmode) {
546 err = chip->info->ops->port_set_cmode(chip, port, mode);
547 if (err && err != -EOPNOTSUPP)
548 goto restore_link;
549 }
550
Vivien Didelotd78343d2016-11-04 03:23:36 +0100551 err = 0;
552restore_link:
553 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400554 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100555
556 return err;
557}
558
Andrew Lunndea87022015-08-31 15:56:47 +0200559/* We expect the switch to perform auto negotiation if there is a real
560 * phy. However, in the case of a fixed link phy, we force the port
561 * settings from the fixed link settings.
562 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400563static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
564 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200565{
Vivien Didelot04bed142016-08-31 18:06:13 -0400566 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200567 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200568
569 if (!phy_is_pseudo_fixed_link(phydev))
570 return;
571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100573 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
574 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400575 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100576
577 if (err && err != -EOPNOTSUPP)
Vivien Didelot774439e52017-06-08 18:34:08 -0400578 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
Andrew Lunndea87022015-08-31 15:56:47 +0200579}
580
Andrew Lunna605a0f2016-11-21 23:26:58 +0100581static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000582{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100583 if (!chip->info->ops->stats_snapshot)
584 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000585
Andrew Lunna605a0f2016-11-21 23:26:58 +0100586 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000587}
588
Andrew Lunne413e7e2015-04-02 04:06:38 +0200589static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100590 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
591 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
592 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
593 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
594 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
595 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
596 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
597 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
598 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
599 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
600 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
601 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
602 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
603 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
604 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
605 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
606 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
607 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
608 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
609 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
610 { "single", 4, 0x14, STATS_TYPE_BANK0, },
611 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
612 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
613 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
614 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
615 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
616 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
617 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
618 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
619 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
620 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
621 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
622 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
623 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
624 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
625 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
626 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
627 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
628 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
629 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
630 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
631 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
632 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
633 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
634 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
635 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
636 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
637 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
638 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
639 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
640 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
641 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
642 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
643 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
644 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
645 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
646 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
647 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
648 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200649};
650
Vivien Didelotfad09c72016-06-21 12:28:20 -0400651static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100652 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100653 int port, u16 bank1_select,
654 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200655{
Andrew Lunn80c46272015-06-20 18:42:30 +0200656 u32 low;
657 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100658 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200659 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200660 u64 value;
661
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100662 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100663 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200664 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
665 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200666 return UINT64_MAX;
667
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200668 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100669 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200670 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
671 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200672 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200673 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200674 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100675 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100676 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100677 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100678 /* fall through */
679 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100680 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100681 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100682 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100683 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500684 break;
685 default:
686 return UINT64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200687 }
688 value = (((u64)high) << 16) | low;
689 return value;
690}
691
Andrew Lunn436fe172018-03-01 02:02:29 +0100692static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
693 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100694{
695 struct mv88e6xxx_hw_stat *stat;
696 int i, j;
697
698 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
699 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100700 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100701 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
702 ETH_GSTRING_LEN);
703 j++;
704 }
705 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100706
707 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100708}
709
Andrew Lunn436fe172018-03-01 02:02:29 +0100710static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
711 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100712{
Andrew Lunn436fe172018-03-01 02:02:29 +0100713 return mv88e6xxx_stats_get_strings(chip, data,
714 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100715}
716
Andrew Lunn436fe172018-03-01 02:02:29 +0100717static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
718 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100719{
Andrew Lunn436fe172018-03-01 02:02:29 +0100720 return mv88e6xxx_stats_get_strings(chip, data,
721 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100722}
723
724static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
725 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100726{
Vivien Didelot04bed142016-08-31 18:06:13 -0400727 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100728 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100729
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100730 mutex_lock(&chip->reg_lock);
731
Andrew Lunndfafe442016-11-21 23:27:02 +0100732 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100733 count = chip->info->ops->stats_get_strings(chip, data);
734
735 if (chip->info->ops->serdes_get_strings) {
736 data += count * ETH_GSTRING_LEN;
737 chip->info->ops->serdes_get_strings(chip, port, data);
738 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100739
740 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100741}
742
743static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
744 int types)
745{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100746 struct mv88e6xxx_hw_stat *stat;
747 int i, j;
748
749 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
750 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100751 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100752 j++;
753 }
754 return j;
755}
756
Andrew Lunndfafe442016-11-21 23:27:02 +0100757static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
758{
759 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
760 STATS_TYPE_PORT);
761}
762
763static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
764{
765 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
766 STATS_TYPE_BANK1);
767}
768
Andrew Lunn88c06052018-03-01 02:02:27 +0100769static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port)
Andrew Lunndfafe442016-11-21 23:27:02 +0100770{
771 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100772 int serdes_count = 0;
773 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100774
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100775 mutex_lock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100776 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100777 count = chip->info->ops->stats_get_sset_count(chip);
778 if (count < 0)
779 goto out;
780
781 if (chip->info->ops->serdes_get_sset_count)
782 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
783 port);
784 if (serdes_count < 0)
785 count = serdes_count;
786 else
787 count += serdes_count;
788out:
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100789 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100790
Andrew Lunn436fe172018-03-01 02:02:29 +0100791 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +0100792}
793
Andrew Lunn436fe172018-03-01 02:02:29 +0100794static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
795 uint64_t *data, int types,
796 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100797{
798 struct mv88e6xxx_hw_stat *stat;
799 int i, j;
800
801 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
802 stat = &mv88e6xxx_hw_stats[i];
803 if (stat->type & types) {
Andrew Lunn377cda12018-02-15 14:38:34 +0100804 mutex_lock(&chip->reg_lock);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100805 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
806 bank1_select,
807 histogram);
Andrew Lunn377cda12018-02-15 14:38:34 +0100808 mutex_unlock(&chip->reg_lock);
809
Andrew Lunn052f9472016-11-21 23:27:03 +0100810 j++;
811 }
812 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100813 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +0100814}
815
Andrew Lunn436fe172018-03-01 02:02:29 +0100816static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
817 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100818{
819 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100820 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400821 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100822}
823
Andrew Lunn436fe172018-03-01 02:02:29 +0100824static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
825 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100826{
827 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100828 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400829 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
830 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100831}
832
Andrew Lunn436fe172018-03-01 02:02:29 +0100833static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
834 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +0100835{
836 return mv88e6xxx_stats_get_stats(chip, port, data,
837 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400838 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
839 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100840}
841
842static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
843 uint64_t *data)
844{
Andrew Lunn436fe172018-03-01 02:02:29 +0100845 int count = 0;
846
Andrew Lunn052f9472016-11-21 23:27:03 +0100847 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +0100848 count = chip->info->ops->stats_get_stats(chip, port, data);
849
850 if (chip->info->ops->serdes_get_stats) {
851 data += count;
Florian Fainellief44d782018-03-18 11:23:05 -0700852 mutex_lock(&chip->reg_lock);
Andrew Lunn436fe172018-03-01 02:02:29 +0100853 chip->info->ops->serdes_get_stats(chip, port, data);
Florian Fainellief44d782018-03-18 11:23:05 -0700854 mutex_unlock(&chip->reg_lock);
Andrew Lunn436fe172018-03-01 02:02:29 +0100855 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100856}
857
Vivien Didelotf81ec902016-05-09 13:22:58 -0400858static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
859 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000860{
Vivien Didelot04bed142016-08-31 18:06:13 -0400861 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000862 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000863
Vivien Didelotfad09c72016-06-21 12:28:20 -0400864 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000865
Andrew Lunna605a0f2016-11-21 23:26:58 +0100866 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +0100867 mutex_unlock(&chip->reg_lock);
868
869 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000870 return;
Andrew Lunn052f9472016-11-21 23:27:03 +0100871
872 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000873
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000874}
Ben Hutchings98e67302011-11-25 14:36:19 +0000875
Andrew Lunnde2273872016-11-21 23:27:01 +0100876static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
877{
878 if (chip->info->ops->stats_set_histogram)
879 return chip->info->ops->stats_set_histogram(chip);
880
881 return 0;
882}
883
Vivien Didelotf81ec902016-05-09 13:22:58 -0400884static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700885{
886 return 32 * sizeof(u16);
887}
888
Vivien Didelotf81ec902016-05-09 13:22:58 -0400889static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
890 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700891{
Vivien Didelot04bed142016-08-31 18:06:13 -0400892 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200893 int err;
894 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700895 u16 *p = _p;
896 int i;
897
898 regs->version = 0;
899
900 memset(p, 0xff, 32 * sizeof(u16));
901
Vivien Didelotfad09c72016-06-21 12:28:20 -0400902 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400903
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700904 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700905
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200906 err = mv88e6xxx_port_read(chip, port, i, &reg);
907 if (!err)
908 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700909 }
Vivien Didelot23062512016-05-09 13:22:45 -0400910
Vivien Didelotfad09c72016-06-21 12:28:20 -0400911 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700912}
913
Vivien Didelot08f50062017-08-01 16:32:41 -0400914static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
915 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800916{
Vivien Didelot5480db62017-08-01 16:32:40 -0400917 /* Nothing to do on the port's MAC */
918 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800919}
920
Vivien Didelot08f50062017-08-01 16:32:41 -0400921static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
922 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800923{
Vivien Didelot5480db62017-08-01 16:32:40 -0400924 /* Nothing to do on the port's MAC */
925 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800926}
927
Vivien Didelote5887a22017-03-30 17:37:11 -0400928static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700929{
Vivien Didelote5887a22017-03-30 17:37:11 -0400930 struct dsa_switch *ds = NULL;
931 struct net_device *br;
932 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500933 int i;
934
Vivien Didelote5887a22017-03-30 17:37:11 -0400935 if (dev < DSA_MAX_SWITCHES)
936 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500937
Vivien Didelote5887a22017-03-30 17:37:11 -0400938 /* Prevent frames from unknown switch or port */
939 if (!ds || port >= ds->num_ports)
940 return 0;
941
942 /* Frames from DSA links and CPU ports can egress any local port */
943 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
944 return mv88e6xxx_port_mask(chip);
945
946 br = ds->ports[port].bridge_dev;
947 pvlan = 0;
948
949 /* Frames from user ports can egress any local DSA links and CPU ports,
950 * as well as any local member of their bridge group.
951 */
952 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
953 if (dsa_is_cpu_port(chip->ds, i) ||
954 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -0400955 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -0400956 pvlan |= BIT(i);
957
958 return pvlan;
959}
960
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400961static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400962{
963 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500964
965 /* prevent frames from going back out of the port they came in on */
966 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700967
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100968 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700969}
970
Vivien Didelotf81ec902016-05-09 13:22:58 -0400971static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
972 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700973{
Vivien Didelot04bed142016-08-31 18:06:13 -0400974 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -0400975 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700976
Vivien Didelotfad09c72016-06-21 12:28:20 -0400977 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -0400978 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400979 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400980
981 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400982 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700983}
984
Vivien Didelot9e907d72017-07-17 13:03:43 -0400985static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
986{
987 if (chip->info->ops->pot_clear)
988 return chip->info->ops->pot_clear(chip);
989
990 return 0;
991}
992
Vivien Didelot51c901a2017-07-17 13:03:41 -0400993static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
994{
995 if (chip->info->ops->mgmt_rsvd2cpu)
996 return chip->info->ops->mgmt_rsvd2cpu(chip);
997
998 return 0;
999}
1000
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001001static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1002{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001003 int err;
1004
Vivien Didelotdaefc942017-03-11 16:12:54 -05001005 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1006 if (err)
1007 return err;
1008
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001009 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1010 if (err)
1011 return err;
1012
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001013 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1014}
1015
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001016static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1017{
1018 int port;
1019 int err;
1020
1021 if (!chip->info->ops->irl_init_all)
1022 return 0;
1023
1024 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1025 /* Disable ingress rate limiting by resetting all per port
1026 * ingress rate limit resources to their initial state.
1027 */
1028 err = chip->info->ops->irl_init_all(chip, port);
1029 if (err)
1030 return err;
1031 }
1032
1033 return 0;
1034}
1035
Vivien Didelot04a69a12017-10-13 14:18:05 -04001036static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1037{
1038 if (chip->info->ops->set_switch_mac) {
1039 u8 addr[ETH_ALEN];
1040
1041 eth_random_addr(addr);
1042
1043 return chip->info->ops->set_switch_mac(chip, addr);
1044 }
1045
1046 return 0;
1047}
1048
Vivien Didelot17a15942017-03-30 17:37:09 -04001049static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1050{
1051 u16 pvlan = 0;
1052
1053 if (!mv88e6xxx_has_pvt(chip))
1054 return -EOPNOTSUPP;
1055
1056 /* Skip the local source device, which uses in-chip port VLAN */
1057 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001058 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001059
1060 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1061}
1062
Vivien Didelot81228992017-03-30 17:37:08 -04001063static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1064{
Vivien Didelot17a15942017-03-30 17:37:09 -04001065 int dev, port;
1066 int err;
1067
Vivien Didelot81228992017-03-30 17:37:08 -04001068 if (!mv88e6xxx_has_pvt(chip))
1069 return 0;
1070
1071 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1072 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1073 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001074 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1075 if (err)
1076 return err;
1077
1078 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1079 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1080 err = mv88e6xxx_pvt_map(chip, dev, port);
1081 if (err)
1082 return err;
1083 }
1084 }
1085
1086 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001087}
1088
Vivien Didelot749efcb2016-09-22 16:49:24 -04001089static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1090{
1091 struct mv88e6xxx_chip *chip = ds->priv;
1092 int err;
1093
1094 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001095 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001096 mutex_unlock(&chip->reg_lock);
1097
1098 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001099 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001100}
1101
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001102static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1103{
1104 if (!chip->info->max_vid)
1105 return 0;
1106
1107 return mv88e6xxx_g1_vtu_flush(chip);
1108}
1109
Vivien Didelotf1394b782017-05-01 14:05:22 -04001110static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1111 struct mv88e6xxx_vtu_entry *entry)
1112{
1113 if (!chip->info->ops->vtu_getnext)
1114 return -EOPNOTSUPP;
1115
1116 return chip->info->ops->vtu_getnext(chip, entry);
1117}
1118
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001119static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1120 struct mv88e6xxx_vtu_entry *entry)
1121{
1122 if (!chip->info->ops->vtu_loadpurge)
1123 return -EOPNOTSUPP;
1124
1125 return chip->info->ops->vtu_loadpurge(chip, entry);
1126}
1127
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001128static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001129{
1130 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001131 struct mv88e6xxx_vtu_entry vlan = {
1132 .vid = chip->info->max_vid,
1133 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001134 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001135
1136 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1137
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001138 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001139 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001140 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001141 if (err)
1142 return err;
1143
1144 set_bit(*fid, fid_bitmap);
1145 }
1146
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001147 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001148 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001149 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001150 if (err)
1151 return err;
1152
1153 if (!vlan.valid)
1154 break;
1155
1156 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001157 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001158
1159 /* The reset value 0x000 is used to indicate that multiple address
1160 * databases are not needed. Return the next positive available.
1161 */
1162 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001163 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001164 return -ENOSPC;
1165
1166 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001167 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001168}
1169
Vivien Didelot567aa592017-05-01 14:05:25 -04001170static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1171 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001172{
1173 int err;
1174
1175 if (!vid)
1176 return -EINVAL;
1177
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001178 entry->vid = vid - 1;
1179 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001180
Vivien Didelotf1394b782017-05-01 14:05:22 -04001181 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001182 if (err)
1183 return err;
1184
Vivien Didelot567aa592017-05-01 14:05:25 -04001185 if (entry->vid == vid && entry->valid)
1186 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001187
Vivien Didelot567aa592017-05-01 14:05:25 -04001188 if (new) {
1189 int i;
1190
1191 /* Initialize a fresh VLAN entry */
1192 memset(entry, 0, sizeof(*entry));
1193 entry->valid = true;
1194 entry->vid = vid;
1195
Vivien Didelot553a7682017-06-07 18:12:16 -04001196 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001197 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001198 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001199 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001200
1201 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001202 }
1203
Vivien Didelot567aa592017-05-01 14:05:25 -04001204 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1205 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001206}
1207
Vivien Didelotda9c3592016-02-12 12:09:40 -05001208static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1209 u16 vid_begin, u16 vid_end)
1210{
Vivien Didelot04bed142016-08-31 18:06:13 -04001211 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001212 struct mv88e6xxx_vtu_entry vlan = {
1213 .vid = vid_begin - 1,
1214 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001215 int i, err;
1216
Andrew Lunndb06ae412017-09-25 23:32:20 +02001217 /* DSA and CPU ports have to be members of multiple vlans */
1218 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1219 return 0;
1220
Vivien Didelotda9c3592016-02-12 12:09:40 -05001221 if (!vid_begin)
1222 return -EOPNOTSUPP;
1223
Vivien Didelotfad09c72016-06-21 12:28:20 -04001224 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001225
Vivien Didelotda9c3592016-02-12 12:09:40 -05001226 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001227 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001228 if (err)
1229 goto unlock;
1230
1231 if (!vlan.valid)
1232 break;
1233
1234 if (vlan.vid > vid_end)
1235 break;
1236
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001237 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001238 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1239 continue;
1240
Andrew Lunncd886462017-11-09 22:29:53 +01001241 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001242 continue;
1243
Vivien Didelotbd00e052017-05-01 14:05:11 -04001244 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001245 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001246 continue;
1247
Vivien Didelotc8652c82017-10-16 11:12:19 -04001248 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001249 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001250 break; /* same bridge, check next VLAN */
1251
Vivien Didelotc8652c82017-10-16 11:12:19 -04001252 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001253 continue;
1254
Andrew Lunn743fcc22017-11-09 22:29:54 +01001255 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1256 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001257 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001258 err = -EOPNOTSUPP;
1259 goto unlock;
1260 }
1261 } while (vlan.vid < vid_end);
1262
1263unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001264 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001265
1266 return err;
1267}
1268
Vivien Didelotf81ec902016-05-09 13:22:58 -04001269static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1270 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001271{
Vivien Didelot04bed142016-08-31 18:06:13 -04001272 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001273 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1274 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001275 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001276
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001277 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001278 return -EOPNOTSUPP;
1279
Vivien Didelotfad09c72016-06-21 12:28:20 -04001280 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001281 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001282 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001283
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001284 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001285}
1286
Vivien Didelot57d32312016-06-20 13:13:58 -04001287static int
1288mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001289 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001290{
Vivien Didelot04bed142016-08-31 18:06:13 -04001291 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001292 int err;
1293
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001294 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001295 return -EOPNOTSUPP;
1296
Vivien Didelotda9c3592016-02-12 12:09:40 -05001297 /* If the requested port doesn't belong to the same bridge as the VLAN
1298 * members, do not support it (yet) and fallback to software VLAN.
1299 */
1300 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1301 vlan->vid_end);
1302 if (err)
1303 return err;
1304
Vivien Didelot76e398a2015-11-01 12:33:55 -05001305 /* We don't need any dynamic resource from the kernel (yet),
1306 * so skip the prepare phase.
1307 */
1308 return 0;
1309}
1310
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001311static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1312 const unsigned char *addr, u16 vid,
1313 u8 state)
1314{
1315 struct mv88e6xxx_vtu_entry vlan;
1316 struct mv88e6xxx_atu_entry entry;
1317 int err;
1318
1319 /* Null VLAN ID corresponds to the port private database */
1320 if (vid == 0)
1321 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1322 else
1323 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1324 if (err)
1325 return err;
1326
1327 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1328 ether_addr_copy(entry.mac, addr);
1329 eth_addr_dec(entry.mac);
1330
1331 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1332 if (err)
1333 return err;
1334
1335 /* Initialize a fresh ATU entry if it isn't found */
1336 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1337 !ether_addr_equal(entry.mac, addr)) {
1338 memset(&entry, 0, sizeof(entry));
1339 ether_addr_copy(entry.mac, addr);
1340 }
1341
1342 /* Purge the ATU entry only if no port is using it anymore */
1343 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1344 entry.portvec &= ~BIT(port);
1345 if (!entry.portvec)
1346 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1347 } else {
1348 entry.portvec |= BIT(port);
1349 entry.state = state;
1350 }
1351
1352 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1353}
1354
Andrew Lunn87fa8862017-11-09 22:29:56 +01001355static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1356 u16 vid)
1357{
1358 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1359 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1360
1361 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1362}
1363
1364static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1365{
1366 int port;
1367 int err;
1368
1369 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1370 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1371 if (err)
1372 return err;
1373 }
1374
1375 return 0;
1376}
1377
Vivien Didelotfad09c72016-06-21 12:28:20 -04001378static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001379 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001380{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001381 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001382 int err;
1383
Vivien Didelot567aa592017-05-01 14:05:25 -04001384 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001385 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001386 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001387
Vivien Didelotc91498e2017-06-07 18:12:13 -04001388 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001389
Andrew Lunn87fa8862017-11-09 22:29:56 +01001390 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1391 if (err)
1392 return err;
1393
1394 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001395}
1396
Vivien Didelotf81ec902016-05-09 13:22:58 -04001397static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001398 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001399{
Vivien Didelot04bed142016-08-31 18:06:13 -04001400 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001401 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1402 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001403 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001404 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001405
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001406 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001407 return;
1408
Vivien Didelotc91498e2017-06-07 18:12:13 -04001409 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001410 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001411 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001412 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001413 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001414 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001415
Vivien Didelotfad09c72016-06-21 12:28:20 -04001416 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001417
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001418 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001419 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001420 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1421 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001422
Vivien Didelot77064f32016-11-04 03:23:30 +01001423 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001424 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1425 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001426
Vivien Didelotfad09c72016-06-21 12:28:20 -04001427 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001428}
1429
Vivien Didelotfad09c72016-06-21 12:28:20 -04001430static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001431 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001432{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001433 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001434 int i, err;
1435
Vivien Didelot567aa592017-05-01 14:05:25 -04001436 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001437 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001438 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001439
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001440 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001441 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001442 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001443
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001444 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001445
1446 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001447 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001448 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001449 if (vlan.member[i] !=
1450 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001451 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001452 break;
1453 }
1454 }
1455
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001456 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001457 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001458 return err;
1459
Vivien Didelote606ca32017-03-11 16:12:55 -05001460 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001461}
1462
Vivien Didelotf81ec902016-05-09 13:22:58 -04001463static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1464 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001465{
Vivien Didelot04bed142016-08-31 18:06:13 -04001466 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001467 u16 pvid, vid;
1468 int err = 0;
1469
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001470 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001471 return -EOPNOTSUPP;
1472
Vivien Didelotfad09c72016-06-21 12:28:20 -04001473 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001474
Vivien Didelot77064f32016-11-04 03:23:30 +01001475 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001476 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001477 goto unlock;
1478
Vivien Didelot76e398a2015-11-01 12:33:55 -05001479 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001480 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001481 if (err)
1482 goto unlock;
1483
1484 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001485 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001486 if (err)
1487 goto unlock;
1488 }
1489 }
1490
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001491unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001492 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001493
1494 return err;
1495}
1496
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001497static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1498 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001499{
Vivien Didelot04bed142016-08-31 18:06:13 -04001500 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001501 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001502
Vivien Didelotfad09c72016-06-21 12:28:20 -04001503 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001504 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1505 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001506 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001507
1508 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001509}
1510
Vivien Didelotf81ec902016-05-09 13:22:58 -04001511static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001512 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001513{
Vivien Didelot04bed142016-08-31 18:06:13 -04001514 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001515 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001516
Vivien Didelotfad09c72016-06-21 12:28:20 -04001517 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001518 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001519 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001520 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001521
Vivien Didelot83dabd12016-08-31 11:50:04 -04001522 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001523}
1524
Vivien Didelot83dabd12016-08-31 11:50:04 -04001525static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1526 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001527 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001528{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001529 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001530 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001531 int err;
1532
Vivien Didelot27c0e602017-06-15 12:14:01 -04001533 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001534 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001535
1536 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001537 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001538 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001539 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001540 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001541 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001542
Vivien Didelot27c0e602017-06-15 12:14:01 -04001543 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001544 break;
1545
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001546 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001547 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001548
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001549 if (!is_unicast_ether_addr(addr.mac))
1550 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001551
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001552 is_static = (addr.state ==
1553 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1554 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001555 if (err)
1556 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001557 } while (!is_broadcast_ether_addr(addr.mac));
1558
1559 return err;
1560}
1561
Vivien Didelot83dabd12016-08-31 11:50:04 -04001562static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001563 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001564{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001565 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001566 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001567 };
1568 u16 fid;
1569 int err;
1570
1571 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001572 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001573 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001574 mutex_unlock(&chip->reg_lock);
1575
Vivien Didelot83dabd12016-08-31 11:50:04 -04001576 if (err)
1577 return err;
1578
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001579 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001580 if (err)
1581 return err;
1582
1583 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001584 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001585 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001586 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001587 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001588 if (err)
1589 return err;
1590
1591 if (!vlan.valid)
1592 break;
1593
1594 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001595 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001596 if (err)
1597 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001598 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001599
1600 return err;
1601}
1602
Vivien Didelotf81ec902016-05-09 13:22:58 -04001603static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001604 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001605{
Vivien Didelot04bed142016-08-31 18:06:13 -04001606 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001607
Andrew Lunna61e5402018-02-15 14:38:35 +01001608 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001609}
1610
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001611static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1612 struct net_device *br)
1613{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001614 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001615 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001616 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001617 int err;
1618
1619 /* Remap the Port VLAN of each local bridge group member */
1620 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1621 if (chip->ds->ports[port].bridge_dev == br) {
1622 err = mv88e6xxx_port_vlan_map(chip, port);
1623 if (err)
1624 return err;
1625 }
1626 }
1627
Vivien Didelote96a6e02017-03-30 17:37:13 -04001628 if (!mv88e6xxx_has_pvt(chip))
1629 return 0;
1630
1631 /* Remap the Port VLAN of each cross-chip bridge group member */
1632 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1633 ds = chip->ds->dst->ds[dev];
1634 if (!ds)
1635 break;
1636
1637 for (port = 0; port < ds->num_ports; ++port) {
1638 if (ds->ports[port].bridge_dev == br) {
1639 err = mv88e6xxx_pvt_map(chip, dev, port);
1640 if (err)
1641 return err;
1642 }
1643 }
1644 }
1645
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001646 return 0;
1647}
1648
Vivien Didelotf81ec902016-05-09 13:22:58 -04001649static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001650 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001651{
Vivien Didelot04bed142016-08-31 18:06:13 -04001652 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001653 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001654
Vivien Didelotfad09c72016-06-21 12:28:20 -04001655 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001656 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001657 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001658
Vivien Didelot466dfa02016-02-26 13:16:05 -05001659 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001660}
1661
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001662static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1663 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001664{
Vivien Didelot04bed142016-08-31 18:06:13 -04001665 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001666
Vivien Didelotfad09c72016-06-21 12:28:20 -04001667 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001668 if (mv88e6xxx_bridge_map(chip, br) ||
1669 mv88e6xxx_port_vlan_map(chip, port))
1670 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001671 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001672}
1673
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001674static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1675 int port, struct net_device *br)
1676{
1677 struct mv88e6xxx_chip *chip = ds->priv;
1678 int err;
1679
1680 if (!mv88e6xxx_has_pvt(chip))
1681 return 0;
1682
1683 mutex_lock(&chip->reg_lock);
1684 err = mv88e6xxx_pvt_map(chip, dev, port);
1685 mutex_unlock(&chip->reg_lock);
1686
1687 return err;
1688}
1689
1690static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1691 int port, struct net_device *br)
1692{
1693 struct mv88e6xxx_chip *chip = ds->priv;
1694
1695 if (!mv88e6xxx_has_pvt(chip))
1696 return;
1697
1698 mutex_lock(&chip->reg_lock);
1699 if (mv88e6xxx_pvt_map(chip, dev, port))
1700 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1701 mutex_unlock(&chip->reg_lock);
1702}
1703
Vivien Didelot17e708b2016-12-05 17:30:27 -05001704static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1705{
1706 if (chip->info->ops->reset)
1707 return chip->info->ops->reset(chip);
1708
1709 return 0;
1710}
1711
Vivien Didelot309eca62016-12-05 17:30:26 -05001712static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1713{
1714 struct gpio_desc *gpiod = chip->reset;
1715
1716 /* If there is a GPIO connected to the reset pin, toggle it */
1717 if (gpiod) {
1718 gpiod_set_value_cansleep(gpiod, 1);
1719 usleep_range(10000, 20000);
1720 gpiod_set_value_cansleep(gpiod, 0);
1721 usleep_range(10000, 20000);
1722 }
1723}
1724
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001725static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1726{
1727 int i, err;
1728
1729 /* Set all ports to the Disabled state */
1730 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001731 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001732 if (err)
1733 return err;
1734 }
1735
1736 /* Wait for transmit queues to drain,
1737 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1738 */
1739 usleep_range(2000, 4000);
1740
1741 return 0;
1742}
1743
Vivien Didelotfad09c72016-06-21 12:28:20 -04001744static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001745{
Vivien Didelota935c052016-09-29 12:21:53 -04001746 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001747
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001748 err = mv88e6xxx_disable_ports(chip);
1749 if (err)
1750 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001751
Vivien Didelot309eca62016-12-05 17:30:26 -05001752 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001753
Vivien Didelot17e708b2016-12-05 17:30:27 -05001754 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001755}
1756
Vivien Didelot43145572017-03-11 16:12:59 -05001757static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001758 enum mv88e6xxx_frame_mode frame,
1759 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001760{
1761 int err;
1762
Vivien Didelot43145572017-03-11 16:12:59 -05001763 if (!chip->info->ops->port_set_frame_mode)
1764 return -EOPNOTSUPP;
1765
1766 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001767 if (err)
1768 return err;
1769
Vivien Didelot43145572017-03-11 16:12:59 -05001770 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1771 if (err)
1772 return err;
1773
1774 if (chip->info->ops->port_set_ether_type)
1775 return chip->info->ops->port_set_ether_type(chip, port, etype);
1776
1777 return 0;
1778}
1779
1780static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1781{
1782 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001783 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001784 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001785}
1786
1787static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1788{
1789 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001790 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001791 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001792}
1793
1794static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1795{
1796 return mv88e6xxx_set_port_mode(chip, port,
1797 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001798 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1799 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001800}
1801
1802static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1803{
1804 if (dsa_is_dsa_port(chip->ds, port))
1805 return mv88e6xxx_set_port_mode_dsa(chip, port);
1806
Vivien Didelot2b3e9892017-10-26 11:22:54 -04001807 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05001808 return mv88e6xxx_set_port_mode_normal(chip, port);
1809
1810 /* Setup CPU port mode depending on its supported tag format */
1811 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1812 return mv88e6xxx_set_port_mode_dsa(chip, port);
1813
1814 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1815 return mv88e6xxx_set_port_mode_edsa(chip, port);
1816
1817 return -EINVAL;
1818}
1819
Vivien Didelotea698f42017-03-11 16:12:50 -05001820static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1821{
1822 bool message = dsa_is_dsa_port(chip->ds, port);
1823
1824 return mv88e6xxx_port_set_message_port(chip, port, message);
1825}
1826
Vivien Didelot601aeed2017-03-11 16:13:00 -05001827static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1828{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001829 struct dsa_switch *ds = chip->ds;
1830 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05001831
1832 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001833 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05001834 if (chip->info->ops->port_set_egress_floods)
1835 return chip->info->ops->port_set_egress_floods(chip, port,
1836 flood, flood);
1837
1838 return 0;
1839}
1840
Andrew Lunn6d917822017-05-26 01:03:21 +02001841static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1842 bool on)
1843{
Vivien Didelot523a8902017-05-26 18:02:42 -04001844 if (chip->info->ops->serdes_power)
1845 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001846
Vivien Didelot523a8902017-05-26 18:02:42 -04001847 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001848}
1849
Vivien Didelotfa371c82017-12-05 15:34:10 -05001850static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
1851{
1852 struct dsa_switch *ds = chip->ds;
1853 int upstream_port;
1854 int err;
1855
Vivien Didelot07073c72017-12-05 15:34:13 -05001856 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05001857 if (chip->info->ops->port_set_upstream_port) {
1858 err = chip->info->ops->port_set_upstream_port(chip, port,
1859 upstream_port);
1860 if (err)
1861 return err;
1862 }
1863
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05001864 if (port == upstream_port) {
1865 if (chip->info->ops->set_cpu_port) {
1866 err = chip->info->ops->set_cpu_port(chip,
1867 upstream_port);
1868 if (err)
1869 return err;
1870 }
1871
1872 if (chip->info->ops->set_egress_port) {
1873 err = chip->info->ops->set_egress_port(chip,
1874 upstream_port);
1875 if (err)
1876 return err;
1877 }
1878 }
1879
Vivien Didelotfa371c82017-12-05 15:34:10 -05001880 return 0;
1881}
1882
Vivien Didelotfad09c72016-06-21 12:28:20 -04001883static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001884{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001885 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001886 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001887 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001888
Vivien Didelotd78343d2016-11-04 03:23:36 +01001889 /* MAC Forcing register: don't force link, speed, duplex or flow control
1890 * state to any particular values on physical ports, but force the CPU
1891 * port and all DSA ports to their maximum bandwidth and full duplex.
1892 */
1893 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1894 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1895 SPEED_MAX, DUPLEX_FULL,
1896 PHY_INTERFACE_MODE_NA);
1897 else
1898 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1899 SPEED_UNFORCED, DUPLEX_UNFORCED,
1900 PHY_INTERFACE_MODE_NA);
1901 if (err)
1902 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001903
1904 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1905 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1906 * tunneling, determine priority by looking at 802.1p and IP
1907 * priority fields (IP prio has precedence), and set STP state
1908 * to Forwarding.
1909 *
1910 * If this is the CPU link, use DSA or EDSA tagging depending
1911 * on which tagging mode was configured.
1912 *
1913 * If this is a link to another switch, use DSA tagging mode.
1914 *
1915 * If this is the upstream port for this switch, enable
1916 * forwarding of unknown unicasts and multicasts.
1917 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04001918 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
1919 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
1920 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1921 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001922 if (err)
1923 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001924
Vivien Didelot601aeed2017-03-11 16:13:00 -05001925 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001926 if (err)
1927 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001928
Vivien Didelot601aeed2017-03-11 16:13:00 -05001929 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001930 if (err)
1931 return err;
1932
Andrew Lunn04aca992017-05-26 01:03:24 +02001933 /* Enable the SERDES interface for DSA and CPU ports. Normal
1934 * ports SERDES are enabled when the port is enabled, thus
1935 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001936 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001937 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1938 err = mv88e6xxx_serdes_power(chip, port, true);
1939 if (err)
1940 return err;
1941 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001942
Vivien Didelot8efdda42015-08-13 12:52:23 -04001943 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001944 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001945 * untagged frames on this port, do a destination address lookup on all
1946 * received packets as usual, disable ARP mirroring and don't send a
1947 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001948 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001949 err = mv88e6xxx_port_set_map_da(chip, port);
1950 if (err)
1951 return err;
1952
Vivien Didelotfa371c82017-12-05 15:34:10 -05001953 err = mv88e6xxx_setup_upstream_port(chip, port);
1954 if (err)
1955 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001956
Andrew Lunna23b2962017-02-04 20:15:28 +01001957 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001958 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01001959 if (err)
1960 return err;
1961
Vivien Didelotcd782652017-06-08 18:34:13 -04001962 if (chip->info->ops->port_set_jumbo_size) {
1963 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01001964 if (err)
1965 return err;
1966 }
1967
Andrew Lunn54d792f2015-05-06 01:09:47 +02001968 /* Port Association Vector: when learning source addresses
1969 * of packets, add the address to the address database using
1970 * a port bitmap that has only the bit for this port set and
1971 * the other bits clear.
1972 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001973 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001974 /* Disable learning for CPU port */
1975 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001976 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001977
Vivien Didelot2a4614e2017-06-12 12:37:43 -04001978 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
1979 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001980 if (err)
1981 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001982
1983 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04001984 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
1985 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001986 if (err)
1987 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001988
Vivien Didelot08984322017-06-08 18:34:12 -04001989 if (chip->info->ops->port_pause_limit) {
1990 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001991 if (err)
1992 return err;
1993 }
1994
Vivien Didelotc8c94892017-03-11 16:13:01 -05001995 if (chip->info->ops->port_disable_learn_limit) {
1996 err = chip->info->ops->port_disable_learn_limit(chip, port);
1997 if (err)
1998 return err;
1999 }
2000
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002001 if (chip->info->ops->port_disable_pri_override) {
2002 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002003 if (err)
2004 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002005 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002006
Andrew Lunnef0a7312016-12-03 04:35:16 +01002007 if (chip->info->ops->port_tag_remap) {
2008 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002009 if (err)
2010 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002011 }
2012
Andrew Lunnef70b112016-12-03 04:45:18 +01002013 if (chip->info->ops->port_egress_rate_limiting) {
2014 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002015 if (err)
2016 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002017 }
2018
Vivien Didelotea698f42017-03-11 16:12:50 -05002019 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002020 if (err)
2021 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002022
Vivien Didelot207afda2016-04-14 14:42:09 -04002023 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002024 * database, and allow bidirectional communication between the
2025 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002026 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002027 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002028 if (err)
2029 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002030
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002031 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002032 if (err)
2033 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002034
2035 /* Default VLAN ID and priority: don't set a default VLAN
2036 * ID, and set the default packet priority to zero.
2037 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002038 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002039}
2040
Andrew Lunn04aca992017-05-26 01:03:24 +02002041static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2042 struct phy_device *phydev)
2043{
2044 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002045 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002046
2047 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002048 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002049 mutex_unlock(&chip->reg_lock);
2050
2051 return err;
2052}
2053
2054static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2055 struct phy_device *phydev)
2056{
2057 struct mv88e6xxx_chip *chip = ds->priv;
2058
2059 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002060 if (mv88e6xxx_serdes_power(chip, port, false))
2061 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002062 mutex_unlock(&chip->reg_lock);
2063}
2064
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002065static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2066 unsigned int ageing_time)
2067{
Vivien Didelot04bed142016-08-31 18:06:13 -04002068 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002069 int err;
2070
2071 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002072 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002073 mutex_unlock(&chip->reg_lock);
2074
2075 return err;
2076}
2077
Vivien Didelot97299342016-07-18 20:45:30 -04002078static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002079{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002080 struct dsa_switch *ds = chip->ds;
Vivien Didelot08a01262016-05-09 13:22:50 -04002081 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002082
Vivien Didelot50484ff2016-05-09 13:22:54 -04002083 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelotd77f4322017-06-15 12:14:03 -04002084 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2085 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
Vivien Didelota935c052016-09-29 12:21:53 -04002086 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002087 if (err)
2088 return err;
2089
Vivien Didelot08a01262016-05-09 13:22:50 -04002090 /* Configure the IP ToS mapping registers. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002091 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002092 if (err)
2093 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002094 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002095 if (err)
2096 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002097 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002098 if (err)
2099 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002100 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002101 if (err)
2102 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002103 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002104 if (err)
2105 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002106 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002107 if (err)
2108 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002109 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002110 if (err)
2111 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002112 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002113 if (err)
2114 return err;
2115
2116 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002117 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002118 if (err)
2119 return err;
2120
Andrew Lunnde2273872016-11-21 23:27:01 +01002121 /* Initialize the statistics unit */
2122 err = mv88e6xxx_stats_set_histogram(chip);
2123 if (err)
2124 return err;
2125
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002126 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002127}
2128
Vivien Didelotf81ec902016-05-09 13:22:58 -04002129static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002130{
Vivien Didelot04bed142016-08-31 18:06:13 -04002131 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002132 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002133 int i;
2134
Vivien Didelotfad09c72016-06-21 12:28:20 -04002135 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002136 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002137
Vivien Didelotfad09c72016-06-21 12:28:20 -04002138 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002139
Vivien Didelot97299342016-07-18 20:45:30 -04002140 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002141 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002142 if (dsa_is_unused_port(ds, i))
2143 continue;
2144
Vivien Didelot97299342016-07-18 20:45:30 -04002145 err = mv88e6xxx_setup_port(chip, i);
2146 if (err)
2147 goto unlock;
2148 }
2149
2150 /* Setup Switch Global 1 Registers */
2151 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002152 if (err)
2153 goto unlock;
2154
Vivien Didelot97299342016-07-18 20:45:30 -04002155 /* Setup Switch Global 2 Registers */
Vivien Didelot9069c132017-07-17 13:03:44 -04002156 if (chip->info->global2_addr) {
Vivien Didelot97299342016-07-18 20:45:30 -04002157 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002158 if (err)
2159 goto unlock;
2160 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002161
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002162 err = mv88e6xxx_irl_setup(chip);
2163 if (err)
2164 goto unlock;
2165
Vivien Didelot04a69a12017-10-13 14:18:05 -04002166 err = mv88e6xxx_mac_setup(chip);
2167 if (err)
2168 goto unlock;
2169
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002170 err = mv88e6xxx_phy_setup(chip);
2171 if (err)
2172 goto unlock;
2173
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002174 err = mv88e6xxx_vtu_setup(chip);
2175 if (err)
2176 goto unlock;
2177
Vivien Didelot81228992017-03-30 17:37:08 -04002178 err = mv88e6xxx_pvt_setup(chip);
2179 if (err)
2180 goto unlock;
2181
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002182 err = mv88e6xxx_atu_setup(chip);
2183 if (err)
2184 goto unlock;
2185
Andrew Lunn87fa8862017-11-09 22:29:56 +01002186 err = mv88e6xxx_broadcast_setup(chip, 0);
2187 if (err)
2188 goto unlock;
2189
Vivien Didelot9e907d72017-07-17 13:03:43 -04002190 err = mv88e6xxx_pot_setup(chip);
2191 if (err)
2192 goto unlock;
2193
Vivien Didelot51c901a2017-07-17 13:03:41 -04002194 err = mv88e6xxx_rsvd2cpu_setup(chip);
2195 if (err)
2196 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002197
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002198 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002199 if (chip->info->ptp_support) {
2200 err = mv88e6xxx_ptp_setup(chip);
2201 if (err)
2202 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002203
2204 err = mv88e6xxx_hwtstamp_setup(chip);
2205 if (err)
2206 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002207 }
2208
Vivien Didelot6b17e862015-08-13 12:52:18 -04002209unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002210 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002211
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002212 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002213}
2214
Vivien Didelote57e5e72016-08-15 17:19:00 -04002215static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002216{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002217 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2218 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002219 u16 val;
2220 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002221
Andrew Lunnee26a222017-01-24 14:53:48 +01002222 if (!chip->info->ops->phy_read)
2223 return -EOPNOTSUPP;
2224
Vivien Didelotfad09c72016-06-21 12:28:20 -04002225 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002226 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002227 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002228
Andrew Lunnda9f3302017-02-01 03:40:05 +01002229 if (reg == MII_PHYSID2) {
2230 /* Some internal PHYS don't have a model number. Use
2231 * the mv88e6390 family model number instead.
2232 */
2233 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002234 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002235 }
2236
Vivien Didelote57e5e72016-08-15 17:19:00 -04002237 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002238}
2239
Vivien Didelote57e5e72016-08-15 17:19:00 -04002240static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002241{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002242 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2243 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002244 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002245
Andrew Lunnee26a222017-01-24 14:53:48 +01002246 if (!chip->info->ops->phy_write)
2247 return -EOPNOTSUPP;
2248
Vivien Didelotfad09c72016-06-21 12:28:20 -04002249 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002250 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002251 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002252
2253 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002254}
2255
Vivien Didelotfad09c72016-06-21 12:28:20 -04002256static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002257 struct device_node *np,
2258 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002259{
2260 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002261 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002262 struct mii_bus *bus;
2263 int err;
2264
Andrew Lunn2510bab2018-02-22 01:51:49 +01002265 if (external) {
2266 mutex_lock(&chip->reg_lock);
2267 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2268 mutex_unlock(&chip->reg_lock);
2269
2270 if (err)
2271 return err;
2272 }
2273
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002274 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002275 if (!bus)
2276 return -ENOMEM;
2277
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002278 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002279 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002280 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002281 INIT_LIST_HEAD(&mdio_bus->list);
2282 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002283
Andrew Lunnb516d452016-06-04 21:17:06 +02002284 if (np) {
2285 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002286 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002287 } else {
2288 bus->name = "mv88e6xxx SMI";
2289 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2290 }
2291
2292 bus->read = mv88e6xxx_mdio_read;
2293 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002294 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002295
Andrew Lunn6f882842018-03-17 20:32:05 +01002296 if (!external) {
2297 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2298 if (err)
2299 return err;
2300 }
2301
Andrew Lunna3c53be52017-01-24 14:53:50 +01002302 if (np)
2303 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002304 else
2305 err = mdiobus_register(bus);
2306 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002307 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002308 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002309 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002310 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002311
2312 if (external)
2313 list_add_tail(&mdio_bus->list, &chip->mdios);
2314 else
2315 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002316
2317 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002318}
2319
Andrew Lunna3c53be52017-01-24 14:53:50 +01002320static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2321 { .compatible = "marvell,mv88e6xxx-mdio-external",
2322 .data = (void *)true },
2323 { },
2324};
2325
Andrew Lunn3126aee2017-12-07 01:05:57 +01002326static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2327
2328{
2329 struct mv88e6xxx_mdio_bus *mdio_bus;
2330 struct mii_bus *bus;
2331
2332 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2333 bus = mdio_bus->bus;
2334
Andrew Lunn6f882842018-03-17 20:32:05 +01002335 if (!mdio_bus->external)
2336 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2337
Andrew Lunn3126aee2017-12-07 01:05:57 +01002338 mdiobus_unregister(bus);
2339 }
2340}
2341
Andrew Lunna3c53be52017-01-24 14:53:50 +01002342static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2343 struct device_node *np)
2344{
2345 const struct of_device_id *match;
2346 struct device_node *child;
2347 int err;
2348
2349 /* Always register one mdio bus for the internal/default mdio
2350 * bus. This maybe represented in the device tree, but is
2351 * optional.
2352 */
2353 child = of_get_child_by_name(np, "mdio");
2354 err = mv88e6xxx_mdio_register(chip, child, false);
2355 if (err)
2356 return err;
2357
2358 /* Walk the device tree, and see if there are any other nodes
2359 * which say they are compatible with the external mdio
2360 * bus.
2361 */
2362 for_each_available_child_of_node(np, child) {
2363 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2364 if (match) {
2365 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002366 if (err) {
2367 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002368 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002369 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002370 }
2371 }
2372
2373 return 0;
2374}
2375
Vivien Didelot855b1932016-07-20 18:18:35 -04002376static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2377{
Vivien Didelot04bed142016-08-31 18:06:13 -04002378 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002379
2380 return chip->eeprom_len;
2381}
2382
Vivien Didelot855b1932016-07-20 18:18:35 -04002383static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2384 struct ethtool_eeprom *eeprom, u8 *data)
2385{
Vivien Didelot04bed142016-08-31 18:06:13 -04002386 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002387 int err;
2388
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002389 if (!chip->info->ops->get_eeprom)
2390 return -EOPNOTSUPP;
2391
Vivien Didelot855b1932016-07-20 18:18:35 -04002392 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002393 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002394 mutex_unlock(&chip->reg_lock);
2395
2396 if (err)
2397 return err;
2398
2399 eeprom->magic = 0xc3ec4951;
2400
2401 return 0;
2402}
2403
Vivien Didelot855b1932016-07-20 18:18:35 -04002404static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2405 struct ethtool_eeprom *eeprom, u8 *data)
2406{
Vivien Didelot04bed142016-08-31 18:06:13 -04002407 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002408 int err;
2409
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002410 if (!chip->info->ops->set_eeprom)
2411 return -EOPNOTSUPP;
2412
Vivien Didelot855b1932016-07-20 18:18:35 -04002413 if (eeprom->magic != 0xc3ec4951)
2414 return -EINVAL;
2415
2416 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002417 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002418 mutex_unlock(&chip->reg_lock);
2419
2420 return err;
2421}
2422
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002423static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002424 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002425 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002426 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002427 .phy_read = mv88e6185_phy_ppu_read,
2428 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002429 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002430 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002431 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002432 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002433 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002434 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002435 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002436 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002437 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002438 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002439 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002440 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002441 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002442 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2443 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002444 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002445 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2446 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002447 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002448 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002449 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002450 .ppu_enable = mv88e6185_g1_ppu_enable,
2451 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002452 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002453 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002454 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002455};
2456
2457static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002458 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002459 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002460 .phy_read = mv88e6185_phy_ppu_read,
2461 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002462 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002463 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002464 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002465 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002466 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002467 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002468 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002469 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002470 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2471 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002472 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002473 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002474 .ppu_enable = mv88e6185_g1_ppu_enable,
2475 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002476 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002477 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002478 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002479};
2480
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002481static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002482 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002483 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002484 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2485 .phy_read = mv88e6xxx_g2_smi_phy_read,
2486 .phy_write = mv88e6xxx_g2_smi_phy_write,
2487 .port_set_link = mv88e6xxx_port_set_link,
2488 .port_set_duplex = mv88e6xxx_port_set_duplex,
2489 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002490 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002491 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002492 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002493 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002494 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002495 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002496 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002497 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002498 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002499 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002500 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002501 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2502 .stats_get_strings = mv88e6095_stats_get_strings,
2503 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002504 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2505 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002506 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002507 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002508 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002509 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002510 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002511 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002512};
2513
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002514static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002515 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002516 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002517 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002518 .phy_read = mv88e6xxx_g2_smi_phy_read,
2519 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002520 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002521 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002522 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002523 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002524 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002525 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002526 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002527 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002528 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002529 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2530 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002531 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002532 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2533 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002534 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002535 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002536 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002537 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002538 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002539 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002540};
2541
2542static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002543 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002544 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002545 .phy_read = mv88e6185_phy_ppu_read,
2546 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002547 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002548 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002549 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002550 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002551 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002552 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002553 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002554 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002555 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002556 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002557 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002558 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002559 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002560 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2561 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002562 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002563 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2564 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002565 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002566 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002567 .ppu_enable = mv88e6185_g1_ppu_enable,
2568 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002569 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002570 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002571 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002572};
2573
Vivien Didelot990e27b2017-03-28 13:50:32 -04002574static const struct mv88e6xxx_ops mv88e6141_ops = {
2575 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002576 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002577 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2578 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2579 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2580 .phy_read = mv88e6xxx_g2_smi_phy_read,
2581 .phy_write = mv88e6xxx_g2_smi_phy_write,
2582 .port_set_link = mv88e6xxx_port_set_link,
2583 .port_set_duplex = mv88e6xxx_port_set_duplex,
2584 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2585 .port_set_speed = mv88e6390_port_set_speed,
2586 .port_tag_remap = mv88e6095_port_tag_remap,
2587 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2588 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2589 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002590 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002591 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002592 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002593 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2594 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2595 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002596 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002597 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2598 .stats_get_strings = mv88e6320_stats_get_strings,
2599 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002600 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2601 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002602 .watchdog_ops = &mv88e6390_watchdog_ops,
2603 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002604 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002605 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002606 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002607 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002608 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002609};
2610
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002611static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002612 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002613 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002614 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002615 .phy_read = mv88e6xxx_g2_smi_phy_read,
2616 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002617 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002618 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002619 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002620 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002621 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002622 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002623 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002624 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002625 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002626 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002627 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002628 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002629 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002630 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002631 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2632 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002633 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002634 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2635 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002636 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002637 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002638 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002639 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002640 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002641 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002642};
2643
2644static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002645 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002646 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002647 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002648 .phy_read = mv88e6165_phy_read,
2649 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002650 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002651 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002652 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002653 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002654 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002655 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002656 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002657 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2658 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002659 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002660 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2661 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002662 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002663 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002664 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002665 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002666 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002667 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002668};
2669
2670static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002671 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002672 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002673 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002674 .phy_read = mv88e6xxx_g2_smi_phy_read,
2675 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002676 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002677 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002678 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002679 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002680 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002681 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002682 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002683 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002684 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002685 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002686 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002687 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002688 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002689 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002690 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002691 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2692 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002693 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002694 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2695 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002696 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002697 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002698 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002699 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002700 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002701 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002702};
2703
2704static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002705 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002706 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002707 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2708 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002709 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002710 .phy_read = mv88e6xxx_g2_smi_phy_read,
2711 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002712 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002713 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002714 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002715 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002716 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002717 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002718 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002719 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002720 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002721 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002722 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002723 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002724 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002725 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002726 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002727 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2728 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002729 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002730 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2731 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002732 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002733 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002734 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002735 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002736 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002737 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002738 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002739 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002740};
2741
2742static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002743 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002744 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002745 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002746 .phy_read = mv88e6xxx_g2_smi_phy_read,
2747 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002748 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002749 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002750 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002751 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002752 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002753 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002754 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002755 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002756 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002757 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002758 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002759 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002760 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002761 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002762 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002763 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2764 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002765 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002766 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2767 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002768 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002769 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002770 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002771 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002772 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002773 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002774};
2775
2776static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002777 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002778 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002779 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2780 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002781 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002782 .phy_read = mv88e6xxx_g2_smi_phy_read,
2783 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002784 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002785 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002786 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002787 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002788 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002789 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002790 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002791 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002792 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002793 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002794 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002795 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002796 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002797 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002798 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002799 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2800 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002801 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002802 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2803 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002804 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002805 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002806 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002807 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002808 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002809 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002810 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002811 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002812};
2813
2814static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002815 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002816 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002817 .phy_read = mv88e6185_phy_ppu_read,
2818 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002819 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002820 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002821 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002822 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002823 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002824 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002825 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002826 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002827 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002828 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2829 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002830 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002831 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2832 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002833 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002834 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002835 .ppu_enable = mv88e6185_g1_ppu_enable,
2836 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002837 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002838 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002839 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002840};
2841
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002842static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002843 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002844 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002845 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2846 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002847 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2848 .phy_read = mv88e6xxx_g2_smi_phy_read,
2849 .phy_write = mv88e6xxx_g2_smi_phy_write,
2850 .port_set_link = mv88e6xxx_port_set_link,
2851 .port_set_duplex = mv88e6xxx_port_set_duplex,
2852 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2853 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002854 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002855 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002856 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002857 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002858 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002859 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002860 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002861 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002862 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002863 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2864 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002865 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002866 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2867 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002868 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002869 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002870 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002871 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002872 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2873 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002874 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002875 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002876};
2877
2878static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002879 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002880 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002881 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2882 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002883 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2884 .phy_read = mv88e6xxx_g2_smi_phy_read,
2885 .phy_write = mv88e6xxx_g2_smi_phy_write,
2886 .port_set_link = mv88e6xxx_port_set_link,
2887 .port_set_duplex = mv88e6xxx_port_set_duplex,
2888 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2889 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002890 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002891 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002892 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002893 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002894 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002895 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002896 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002897 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002898 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002899 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2900 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002901 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002902 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2903 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002904 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002905 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002906 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002907 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002908 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2909 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002910 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002911 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002912};
2913
2914static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002915 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002916 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002917 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2918 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002919 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2920 .phy_read = mv88e6xxx_g2_smi_phy_read,
2921 .phy_write = mv88e6xxx_g2_smi_phy_write,
2922 .port_set_link = mv88e6xxx_port_set_link,
2923 .port_set_duplex = mv88e6xxx_port_set_duplex,
2924 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2925 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002926 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002927 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002928 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002929 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002930 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002931 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002932 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002933 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002934 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002935 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2936 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002937 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002938 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2939 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002940 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002941 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002942 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002943 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002944 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2945 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002946 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002947};
2948
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002949static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002950 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002951 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002952 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2953 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002954 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002955 .phy_read = mv88e6xxx_g2_smi_phy_read,
2956 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002957 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002958 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002959 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002960 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002961 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002962 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002963 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002964 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002965 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002966 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002967 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002968 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002969 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002970 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002971 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002972 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2973 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002974 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002975 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2976 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002977 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002978 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002979 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002980 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002981 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002982 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002983 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002984 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01002985 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002986};
2987
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002988static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002989 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002990 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002991 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2992 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002993 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2994 .phy_read = mv88e6xxx_g2_smi_phy_read,
2995 .phy_write = mv88e6xxx_g2_smi_phy_write,
2996 .port_set_link = mv88e6xxx_port_set_link,
2997 .port_set_duplex = mv88e6xxx_port_set_duplex,
2998 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2999 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003000 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003001 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003002 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003003 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003004 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003005 .port_set_cmode = mv88e6390x_port_set_cmode,
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 Lunn79523472016-11-21 23:27:00 +01003008 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003009 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003010 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3011 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003012 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003013 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3014 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003015 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003016 .mgmt_rsvd2cpu = mv88e6390_g1_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 Didelot931d1822017-05-01 14:05:27 -04003019 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3020 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003021 .serdes_power = mv88e6390_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 = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003024};
3025
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003026static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003027 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003028 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003029 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3030 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003031 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003032 .phy_read = mv88e6xxx_g2_smi_phy_read,
3033 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003034 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003035 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003036 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003037 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003038 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003039 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003040 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003041 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003042 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003043 .port_pause_limit = mv88e6097_port_pause_limit,
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 Lunna605a0f2016-11-21 23:26:58 +01003046 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003047 .stats_set_histogram = mv88e6095_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 Lunn052f9472016-11-21 23:27:03 +01003050 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003051 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3052 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003053 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003054 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003055 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003056 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003057 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003058 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003059 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003060};
3061
3062static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003063 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003064 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003065 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3066 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003067 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003068 .phy_read = mv88e6xxx_g2_smi_phy_read,
3069 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003070 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003071 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003072 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003073 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003074 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003075 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003076 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003077 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003078 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003079 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003080 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003081 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003082 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003083 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003084 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3085 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003086 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003087 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3088 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003089 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003090 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003091 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003092 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003093 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003094};
3095
Vivien Didelot16e329a2017-03-28 13:50:33 -04003096static const struct mv88e6xxx_ops mv88e6341_ops = {
3097 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003098 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003099 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3100 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3101 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3102 .phy_read = mv88e6xxx_g2_smi_phy_read,
3103 .phy_write = mv88e6xxx_g2_smi_phy_write,
3104 .port_set_link = mv88e6xxx_port_set_link,
3105 .port_set_duplex = mv88e6xxx_port_set_duplex,
3106 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3107 .port_set_speed = mv88e6390_port_set_speed,
3108 .port_tag_remap = mv88e6095_port_tag_remap,
3109 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3110 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3111 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003112 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003113 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003114 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003115 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3116 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3117 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003118 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003119 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3120 .stats_get_strings = mv88e6320_stats_get_strings,
3121 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003122 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3123 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003124 .watchdog_ops = &mv88e6390_watchdog_ops,
3125 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003126 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003127 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003128 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003129 .vtu_loadpurge = mv88e6352_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 = &mv88e6390_avb_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003132};
3133
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003134static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003135 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003136 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003137 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003138 .phy_read = mv88e6xxx_g2_smi_phy_read,
3139 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003140 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003141 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003142 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003143 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003144 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003145 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003146 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003147 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003148 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003149 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003150 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003151 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003152 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003153 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003154 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003155 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3156 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003157 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003158 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3159 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003160 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003161 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003162 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003163 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003164 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003165 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003166};
3167
3168static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003169 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003170 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003171 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003172 .phy_read = mv88e6xxx_g2_smi_phy_read,
3173 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003174 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003175 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003176 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003177 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003178 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003179 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003180 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003181 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003182 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003183 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003184 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003185 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003186 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003187 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003188 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003189 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3190 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003191 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003192 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3193 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003194 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003195 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003196 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003197 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003198 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003199 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003200 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003201};
3202
3203static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003204 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003205 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003206 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3207 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003208 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003209 .phy_read = mv88e6xxx_g2_smi_phy_read,
3210 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003211 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003212 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003213 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003214 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003215 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003216 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003217 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003218 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003219 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003220 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003221 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003222 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003223 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003224 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003225 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003226 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3227 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003228 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003229 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3230 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003231 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003232 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003233 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003234 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003235 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003236 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003237 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003238 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003239 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01003240 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
3241 .serdes_get_strings = mv88e6352_serdes_get_strings,
3242 .serdes_get_stats = mv88e6352_serdes_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003243};
3244
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003245static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003246 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003247 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003248 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3249 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003250 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3251 .phy_read = mv88e6xxx_g2_smi_phy_read,
3252 .phy_write = mv88e6xxx_g2_smi_phy_write,
3253 .port_set_link = mv88e6xxx_port_set_link,
3254 .port_set_duplex = mv88e6xxx_port_set_duplex,
3255 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3256 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003257 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003258 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003259 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003260 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003261 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003262 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003263 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003264 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003265 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003266 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003267 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003268 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003269 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3270 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003271 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003272 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3273 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003274 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003275 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003276 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003277 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003278 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3279 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003280 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003281 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003282 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003283};
3284
3285static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003286 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003287 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003288 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3289 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003290 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3291 .phy_read = mv88e6xxx_g2_smi_phy_read,
3292 .phy_write = mv88e6xxx_g2_smi_phy_write,
3293 .port_set_link = mv88e6xxx_port_set_link,
3294 .port_set_duplex = mv88e6xxx_port_set_duplex,
3295 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3296 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003297 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003298 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003299 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003300 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003301 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003302 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003303 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003304 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003305 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003306 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003307 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003308 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003309 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3310 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003311 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003312 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3313 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003314 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003315 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003316 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003317 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003318 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3319 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003320 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003321 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003322 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003323};
3324
Vivien Didelotf81ec902016-05-09 13:22:58 -04003325static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3326 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003327 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003328 .family = MV88E6XXX_FAMILY_6097,
3329 .name = "Marvell 88E6085",
3330 .num_databases = 4096,
3331 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003332 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003333 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003334 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003335 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003336 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003337 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003338 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003339 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003340 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003341 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003342 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003343 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003344 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003345 },
3346
3347 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003348 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003349 .family = MV88E6XXX_FAMILY_6095,
3350 .name = "Marvell 88E6095/88E6095F",
3351 .num_databases = 256,
3352 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003353 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003354 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003355 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003356 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003357 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003358 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003359 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003360 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003361 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003362 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003363 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003364 },
3365
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003366 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003367 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003368 .family = MV88E6XXX_FAMILY_6097,
3369 .name = "Marvell 88E6097/88E6097F",
3370 .num_databases = 4096,
3371 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01003372 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003373 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003374 .port_base_addr = 0x10,
3375 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003376 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003377 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003378 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003379 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003380 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003381 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003382 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003383 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003384 .ops = &mv88e6097_ops,
3385 },
3386
Vivien Didelotf81ec902016-05-09 13:22:58 -04003387 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003388 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003389 .family = MV88E6XXX_FAMILY_6165,
3390 .name = "Marvell 88E6123",
3391 .num_databases = 4096,
3392 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01003393 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003394 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003395 .port_base_addr = 0x10,
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 = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003400 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003401 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003402 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003403 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003404 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003405 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003406 },
3407
3408 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003409 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003410 .family = MV88E6XXX_FAMILY_6185,
3411 .name = "Marvell 88E6131",
3412 .num_databases = 256,
3413 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003414 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003415 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003416 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003417 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003418 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003419 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003420 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003421 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003422 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003423 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003424 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003425 },
3426
Vivien Didelot990e27b2017-03-28 13:50:32 -04003427 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003428 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003429 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01003430 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04003431 .num_databases = 4096,
3432 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003433 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003434 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003435 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003436 .port_base_addr = 0x10,
3437 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003438 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003439 .age_time_coeff = 3750,
3440 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003441 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003442 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003443 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003444 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003445 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003446 .ops = &mv88e6141_ops,
3447 },
3448
Vivien Didelotf81ec902016-05-09 13:22:58 -04003449 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003450 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003451 .family = MV88E6XXX_FAMILY_6165,
3452 .name = "Marvell 88E6161",
3453 .num_databases = 4096,
3454 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003455 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003456 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003457 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003458 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003459 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003460 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003461 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003462 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003463 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003464 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003465 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003466 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003467 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003468 },
3469
3470 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003471 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003472 .family = MV88E6XXX_FAMILY_6165,
3473 .name = "Marvell 88E6165",
3474 .num_databases = 4096,
3475 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01003476 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003477 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003478 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003479 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003480 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003481 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003482 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003483 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003484 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003485 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003486 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003487 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003488 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003489 },
3490
3491 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003492 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003493 .family = MV88E6XXX_FAMILY_6351,
3494 .name = "Marvell 88E6171",
3495 .num_databases = 4096,
3496 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003497 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003498 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003499 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003500 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003501 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003502 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003503 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003504 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003505 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003506 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003507 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003508 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003509 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003510 },
3511
3512 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003513 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003514 .family = MV88E6XXX_FAMILY_6352,
3515 .name = "Marvell 88E6172",
3516 .num_databases = 4096,
3517 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003518 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003519 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003520 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003521 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003522 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003523 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003524 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003525 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003526 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003527 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003528 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003529 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003530 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003531 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003532 },
3533
3534 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003535 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003536 .family = MV88E6XXX_FAMILY_6351,
3537 .name = "Marvell 88E6175",
3538 .num_databases = 4096,
3539 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003540 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003541 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003542 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003543 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003544 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003545 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003546 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003547 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003548 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003549 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003550 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003551 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003552 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003553 },
3554
3555 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003556 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003557 .family = MV88E6XXX_FAMILY_6352,
3558 .name = "Marvell 88E6176",
3559 .num_databases = 4096,
3560 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003561 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003562 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003563 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003564 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003565 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003566 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003567 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003568 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003569 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003570 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003571 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003572 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003573 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003574 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003575 },
3576
3577 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003578 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003579 .family = MV88E6XXX_FAMILY_6185,
3580 .name = "Marvell 88E6185",
3581 .num_databases = 256,
3582 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01003583 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003584 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003585 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003586 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003587 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003588 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003589 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003590 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003591 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003592 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003593 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003594 },
3595
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003596 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003597 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003598 .family = MV88E6XXX_FAMILY_6390,
3599 .name = "Marvell 88E6190",
3600 .num_databases = 4096,
3601 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003602 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003603 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003604 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003605 .port_base_addr = 0x0,
3606 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003607 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003608 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003609 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003610 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003611 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003612 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003613 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003614 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003615 .ops = &mv88e6190_ops,
3616 },
3617
3618 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003619 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003620 .family = MV88E6XXX_FAMILY_6390,
3621 .name = "Marvell 88E6190X",
3622 .num_databases = 4096,
3623 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003624 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003625 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003626 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003627 .port_base_addr = 0x0,
3628 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003629 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003630 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003631 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003632 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003633 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003634 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003635 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003636 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003637 .ops = &mv88e6190x_ops,
3638 },
3639
3640 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003641 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003642 .family = MV88E6XXX_FAMILY_6390,
3643 .name = "Marvell 88E6191",
3644 .num_databases = 4096,
3645 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003646 .num_internal_phys = 11,
Vivien Didelot931d1822017-05-01 14:05:27 -04003647 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003648 .port_base_addr = 0x0,
3649 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003650 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003651 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003652 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003653 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003654 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003655 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003656 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003657 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003658 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003659 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003660 },
3661
Vivien Didelotf81ec902016-05-09 13:22:58 -04003662 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003663 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003664 .family = MV88E6XXX_FAMILY_6352,
3665 .name = "Marvell 88E6240",
3666 .num_databases = 4096,
3667 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003668 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003669 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003670 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003671 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003672 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003673 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003674 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003675 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003676 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003677 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003678 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003679 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003680 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003681 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003682 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003683 },
3684
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003685 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003686 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003687 .family = MV88E6XXX_FAMILY_6390,
3688 .name = "Marvell 88E6290",
3689 .num_databases = 4096,
3690 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003691 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003692 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003693 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003694 .port_base_addr = 0x0,
3695 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003696 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003697 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003698 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003699 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003700 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003701 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003702 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003703 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003704 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003705 .ops = &mv88e6290_ops,
3706 },
3707
Vivien Didelotf81ec902016-05-09 13:22:58 -04003708 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003709 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003710 .family = MV88E6XXX_FAMILY_6320,
3711 .name = "Marvell 88E6320",
3712 .num_databases = 4096,
3713 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003714 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003715 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003716 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003717 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003718 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003719 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003720 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003721 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003722 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003723 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003724 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003725 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003726 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003727 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003728 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003729 },
3730
3731 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003732 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003733 .family = MV88E6XXX_FAMILY_6320,
3734 .name = "Marvell 88E6321",
3735 .num_databases = 4096,
3736 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003737 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003738 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003739 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003740 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003741 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003742 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003743 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003744 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01003745 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003746 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003747 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003748 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003749 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003750 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003751 },
3752
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003753 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003754 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003755 .family = MV88E6XXX_FAMILY_6341,
3756 .name = "Marvell 88E6341",
3757 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01003758 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003759 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003760 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003761 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003762 .port_base_addr = 0x10,
3763 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003764 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003765 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003766 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01003767 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003768 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003769 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003770 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003771 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003772 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003773 .ops = &mv88e6341_ops,
3774 },
3775
Vivien Didelotf81ec902016-05-09 13:22:58 -04003776 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003777 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003778 .family = MV88E6XXX_FAMILY_6351,
3779 .name = "Marvell 88E6350",
3780 .num_databases = 4096,
3781 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003782 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003783 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003784 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003785 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003786 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003787 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003788 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003789 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003790 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003791 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003792 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003793 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003794 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003795 },
3796
3797 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003798 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003799 .family = MV88E6XXX_FAMILY_6351,
3800 .name = "Marvell 88E6351",
3801 .num_databases = 4096,
3802 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003803 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003804 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003805 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003806 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003807 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003808 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003809 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003810 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003811 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003812 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003813 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003814 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003815 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003816 },
3817
3818 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003819 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003820 .family = MV88E6XXX_FAMILY_6352,
3821 .name = "Marvell 88E6352",
3822 .num_databases = 4096,
3823 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01003824 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003825 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003826 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003827 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003828 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003829 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003830 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003831 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003832 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003833 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003834 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003835 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003836 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003837 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003838 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003839 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003840 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003841 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003842 .family = MV88E6XXX_FAMILY_6390,
3843 .name = "Marvell 88E6390",
3844 .num_databases = 4096,
3845 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003846 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003847 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003848 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003849 .port_base_addr = 0x0,
3850 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003851 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003852 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003853 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003854 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003855 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003856 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003857 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003858 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003859 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003860 .ops = &mv88e6390_ops,
3861 },
3862 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003863 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003864 .family = MV88E6XXX_FAMILY_6390,
3865 .name = "Marvell 88E6390X",
3866 .num_databases = 4096,
3867 .num_ports = 11, /* 10 + Z80 */
Andrew Lunnbc393152018-03-17 20:32:04 +01003868 .num_internal_phys = 11,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003869 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003870 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003871 .port_base_addr = 0x0,
3872 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003873 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003874 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003875 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003876 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003877 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003878 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003879 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003880 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003881 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003882 .ops = &mv88e6390x_ops,
3883 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003884};
3885
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003886static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003887{
Vivien Didelota439c062016-04-17 13:23:58 -04003888 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003889
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003890 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3891 if (mv88e6xxx_table[i].prod_num == prod_num)
3892 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003893
Vivien Didelotb9b37712015-10-30 19:39:48 -04003894 return NULL;
3895}
3896
Vivien Didelotfad09c72016-06-21 12:28:20 -04003897static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003898{
3899 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003900 unsigned int prod_num, rev;
3901 u16 id;
3902 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003903
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003904 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04003905 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003906 mutex_unlock(&chip->reg_lock);
3907 if (err)
3908 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003909
Vivien Didelot107fcc12017-06-12 12:37:36 -04003910 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
3911 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003912
3913 info = mv88e6xxx_lookup_info(prod_num);
3914 if (!info)
3915 return -ENODEV;
3916
Vivien Didelotcaac8542016-06-20 13:14:09 -04003917 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003918 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003919
Vivien Didelotca070c12016-09-02 14:45:34 -04003920 err = mv88e6xxx_g2_require(chip);
3921 if (err)
3922 return err;
3923
Vivien Didelotfad09c72016-06-21 12:28:20 -04003924 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3925 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003926
3927 return 0;
3928}
3929
Vivien Didelotfad09c72016-06-21 12:28:20 -04003930static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003931{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003932 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003933
Vivien Didelotfad09c72016-06-21 12:28:20 -04003934 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3935 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003936 return NULL;
3937
Vivien Didelotfad09c72016-06-21 12:28:20 -04003938 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003939
Vivien Didelotfad09c72016-06-21 12:28:20 -04003940 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003941 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003942
Vivien Didelotfad09c72016-06-21 12:28:20 -04003943 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003944}
3945
Vivien Didelotfad09c72016-06-21 12:28:20 -04003946static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003947 struct mii_bus *bus, int sw_addr)
3948{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003949 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003950 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003951 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003952 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003953 else
3954 return -EINVAL;
3955
Vivien Didelotfad09c72016-06-21 12:28:20 -04003956 chip->bus = bus;
3957 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003958
3959 return 0;
3960}
3961
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08003962static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
3963 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02003964{
Vivien Didelot04bed142016-08-31 18:06:13 -04003965 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003966
Andrew Lunn443d5a12016-12-03 04:35:18 +01003967 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003968}
3969
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08003970#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003971static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3972 struct device *host_dev, int sw_addr,
3973 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003974{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003975 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003976 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003977 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003978
Vivien Didelota439c062016-04-17 13:23:58 -04003979 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003980 if (!bus)
3981 return NULL;
3982
Vivien Didelotfad09c72016-06-21 12:28:20 -04003983 chip = mv88e6xxx_alloc_chip(dsa_dev);
3984 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003985 return NULL;
3986
Vivien Didelotcaac8542016-06-20 13:14:09 -04003987 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003988 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003989
Vivien Didelotfad09c72016-06-21 12:28:20 -04003990 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003991 if (err)
3992 goto free;
3993
Vivien Didelotfad09c72016-06-21 12:28:20 -04003994 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003995 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003996 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003997
Andrew Lunndc30c352016-10-16 19:56:49 +02003998 mutex_lock(&chip->reg_lock);
3999 err = mv88e6xxx_switch_reset(chip);
4000 mutex_unlock(&chip->reg_lock);
4001 if (err)
4002 goto free;
4003
Vivien Didelote57e5e72016-08-15 17:19:00 -04004004 mv88e6xxx_phy_init(chip);
4005
Andrew Lunna3c53be52017-01-24 14:53:50 +01004006 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004007 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004008 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004009
Vivien Didelotfad09c72016-06-21 12:28:20 -04004010 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004011
Vivien Didelotfad09c72016-06-21 12:28:20 -04004012 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004013free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004014 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004015
4016 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004017}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004018#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02004019
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004020static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004021 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004022{
4023 /* We don't need any dynamic resource from the kernel (yet),
4024 * so skip the prepare phase.
4025 */
4026
4027 return 0;
4028}
4029
4030static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004031 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004032{
Vivien Didelot04bed142016-08-31 18:06:13 -04004033 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004034
4035 mutex_lock(&chip->reg_lock);
4036 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004037 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004038 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4039 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004040 mutex_unlock(&chip->reg_lock);
4041}
4042
4043static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4044 const struct switchdev_obj_port_mdb *mdb)
4045{
Vivien Didelot04bed142016-08-31 18:06:13 -04004046 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004047 int err;
4048
4049 mutex_lock(&chip->reg_lock);
4050 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004051 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004052 mutex_unlock(&chip->reg_lock);
4053
4054 return err;
4055}
4056
Florian Fainellia82f67a2017-01-08 14:52:08 -08004057static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004058#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004059 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004060#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02004061 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004062 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004063 .adjust_link = mv88e6xxx_adjust_link,
4064 .get_strings = mv88e6xxx_get_strings,
4065 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4066 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004067 .port_enable = mv88e6xxx_port_enable,
4068 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004069 .get_mac_eee = mv88e6xxx_get_mac_eee,
4070 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004071 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004072 .get_eeprom = mv88e6xxx_get_eeprom,
4073 .set_eeprom = mv88e6xxx_set_eeprom,
4074 .get_regs_len = mv88e6xxx_get_regs_len,
4075 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004076 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004077 .port_bridge_join = mv88e6xxx_port_bridge_join,
4078 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4079 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004080 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004081 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4082 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4083 .port_vlan_add = mv88e6xxx_port_vlan_add,
4084 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004085 .port_fdb_add = mv88e6xxx_port_fdb_add,
4086 .port_fdb_del = mv88e6xxx_port_fdb_del,
4087 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004088 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4089 .port_mdb_add = mv88e6xxx_port_mdb_add,
4090 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004091 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4092 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004093 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4094 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4095 .port_txtstamp = mv88e6xxx_port_txtstamp,
4096 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4097 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004098};
4099
Florian Fainelliab3d4082017-01-08 14:52:07 -08004100static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4101 .ops = &mv88e6xxx_switch_ops,
4102};
4103
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004104static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004105{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004106 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004107 struct dsa_switch *ds;
4108
Vivien Didelot73b12042017-03-30 17:37:10 -04004109 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004110 if (!ds)
4111 return -ENOMEM;
4112
Vivien Didelotfad09c72016-06-21 12:28:20 -04004113 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004114 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004115 ds->ageing_time_min = chip->info->age_time_coeff;
4116 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004117
4118 dev_set_drvdata(dev, ds);
4119
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004120 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004121}
4122
Vivien Didelotfad09c72016-06-21 12:28:20 -04004123static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004124{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004125 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004126}
4127
Vivien Didelot57d32312016-06-20 13:13:58 -04004128static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004129{
4130 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004131 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004132 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004133 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004134 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004135 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004136
Vivien Didelotcaac8542016-06-20 13:14:09 -04004137 compat_info = of_device_get_match_data(dev);
4138 if (!compat_info)
4139 return -EINVAL;
4140
Vivien Didelotfad09c72016-06-21 12:28:20 -04004141 chip = mv88e6xxx_alloc_chip(dev);
4142 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004143 return -ENOMEM;
4144
Vivien Didelotfad09c72016-06-21 12:28:20 -04004145 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004146
Vivien Didelotfad09c72016-06-21 12:28:20 -04004147 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004148 if (err)
4149 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004150
Andrew Lunnb4308f02016-11-21 23:26:55 +01004151 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4152 if (IS_ERR(chip->reset))
4153 return PTR_ERR(chip->reset);
4154
Vivien Didelotfad09c72016-06-21 12:28:20 -04004155 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004156 if (err)
4157 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004158
Vivien Didelote57e5e72016-08-15 17:19:00 -04004159 mv88e6xxx_phy_init(chip);
4160
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004161 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004162 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004163 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004164
Andrew Lunndc30c352016-10-16 19:56:49 +02004165 mutex_lock(&chip->reg_lock);
4166 err = mv88e6xxx_switch_reset(chip);
4167 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004168 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004169 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004170
Andrew Lunndc30c352016-10-16 19:56:49 +02004171 chip->irq = of_irq_get(np, 0);
4172 if (chip->irq == -EPROBE_DEFER) {
4173 err = chip->irq;
4174 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004175 }
4176
Andrew Lunn294d7112018-02-22 22:58:32 +01004177 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01004178 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01004179 * controllers
4180 */
4181 mutex_lock(&chip->reg_lock);
4182 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004183 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004184 else
4185 err = mv88e6xxx_irq_poll_setup(chip);
4186 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004187
Andrew Lunn294d7112018-02-22 22:58:32 +01004188 if (err)
4189 goto out;
4190
4191 if (chip->info->g2_irqs > 0) {
4192 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004193 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004194 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004195 }
4196
Andrew Lunn294d7112018-02-22 22:58:32 +01004197 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4198 if (err)
4199 goto out_g2_irq;
4200
4201 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4202 if (err)
4203 goto out_g1_atu_prob_irq;
4204
Andrew Lunna3c53be52017-01-24 14:53:50 +01004205 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004206 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004207 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004208
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004209 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004210 if (err)
4211 goto out_mdio;
4212
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004213 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004214
4215out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004216 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004217out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004218 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004219out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004220 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004221out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004222 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004223 mv88e6xxx_g2_irq_free(chip);
4224out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004225 mutex_lock(&chip->reg_lock);
4226 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004227 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004228 else
4229 mv88e6xxx_irq_poll_free(chip);
4230 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004231out:
4232 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004233}
4234
4235static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4236{
4237 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004238 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004239
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004240 if (chip->info->ptp_support) {
4241 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004242 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004243 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004244
Andrew Lunn930188c2016-08-22 16:01:03 +02004245 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004246 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004247 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004248
Andrew Lunn76f38f12018-03-17 20:21:09 +01004249 mv88e6xxx_g1_vtu_prob_irq_free(chip);
4250 mv88e6xxx_g1_atu_prob_irq_free(chip);
4251
4252 if (chip->info->g2_irqs > 0)
4253 mv88e6xxx_g2_irq_free(chip);
4254
4255 mutex_lock(&chip->reg_lock);
4256 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004257 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01004258 else
4259 mv88e6xxx_irq_poll_free(chip);
4260 mutex_unlock(&chip->reg_lock);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004261}
4262
4263static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004264 {
4265 .compatible = "marvell,mv88e6085",
4266 .data = &mv88e6xxx_table[MV88E6085],
4267 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004268 {
4269 .compatible = "marvell,mv88e6190",
4270 .data = &mv88e6xxx_table[MV88E6190],
4271 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004272 { /* sentinel */ },
4273};
4274
4275MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4276
4277static struct mdio_driver mv88e6xxx_driver = {
4278 .probe = mv88e6xxx_probe,
4279 .remove = mv88e6xxx_remove,
4280 .mdiodrv.driver = {
4281 .name = "mv88e6085",
4282 .of_match_table = mv88e6xxx_of_match,
4283 },
4284};
4285
Ben Hutchings98e67302011-11-25 14:36:19 +00004286static int __init mv88e6xxx_init(void)
4287{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004288 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004289 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004290}
4291module_init(mv88e6xxx_init);
4292
4293static void __exit mv88e6xxx_cleanup(void)
4294{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004295 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004296 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004297}
4298module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004299
4300MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4301MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4302MODULE_LICENSE("GPL");