blob: bd3ee84770c750ea289af014550071a0a8475e52 [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;
852 chip->info->ops->serdes_get_stats(chip, port, data);
853 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100854}
855
Vivien Didelotf81ec902016-05-09 13:22:58 -0400856static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
857 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000858{
Vivien Didelot04bed142016-08-31 18:06:13 -0400859 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000860 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000861
Vivien Didelotfad09c72016-06-21 12:28:20 -0400862 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000863
Andrew Lunna605a0f2016-11-21 23:26:58 +0100864 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +0100865 mutex_unlock(&chip->reg_lock);
866
867 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000868 return;
Andrew Lunn052f9472016-11-21 23:27:03 +0100869
870 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000871
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000872}
Ben Hutchings98e67302011-11-25 14:36:19 +0000873
Andrew Lunnde2273872016-11-21 23:27:01 +0100874static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
875{
876 if (chip->info->ops->stats_set_histogram)
877 return chip->info->ops->stats_set_histogram(chip);
878
879 return 0;
880}
881
Vivien Didelotf81ec902016-05-09 13:22:58 -0400882static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700883{
884 return 32 * sizeof(u16);
885}
886
Vivien Didelotf81ec902016-05-09 13:22:58 -0400887static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
888 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700889{
Vivien Didelot04bed142016-08-31 18:06:13 -0400890 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200891 int err;
892 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700893 u16 *p = _p;
894 int i;
895
896 regs->version = 0;
897
898 memset(p, 0xff, 32 * sizeof(u16));
899
Vivien Didelotfad09c72016-06-21 12:28:20 -0400900 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400901
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700902 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700903
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200904 err = mv88e6xxx_port_read(chip, port, i, &reg);
905 if (!err)
906 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700907 }
Vivien Didelot23062512016-05-09 13:22:45 -0400908
Vivien Didelotfad09c72016-06-21 12:28:20 -0400909 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700910}
911
Vivien Didelot08f50062017-08-01 16:32:41 -0400912static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
913 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800914{
Vivien Didelot5480db62017-08-01 16:32:40 -0400915 /* Nothing to do on the port's MAC */
916 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800917}
918
Vivien Didelot08f50062017-08-01 16:32:41 -0400919static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
920 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800921{
Vivien Didelot5480db62017-08-01 16:32:40 -0400922 /* Nothing to do on the port's MAC */
923 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800924}
925
Vivien Didelote5887a22017-03-30 17:37:11 -0400926static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700927{
Vivien Didelote5887a22017-03-30 17:37:11 -0400928 struct dsa_switch *ds = NULL;
929 struct net_device *br;
930 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500931 int i;
932
Vivien Didelote5887a22017-03-30 17:37:11 -0400933 if (dev < DSA_MAX_SWITCHES)
934 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500935
Vivien Didelote5887a22017-03-30 17:37:11 -0400936 /* Prevent frames from unknown switch or port */
937 if (!ds || port >= ds->num_ports)
938 return 0;
939
940 /* Frames from DSA links and CPU ports can egress any local port */
941 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
942 return mv88e6xxx_port_mask(chip);
943
944 br = ds->ports[port].bridge_dev;
945 pvlan = 0;
946
947 /* Frames from user ports can egress any local DSA links and CPU ports,
948 * as well as any local member of their bridge group.
949 */
950 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
951 if (dsa_is_cpu_port(chip->ds, i) ||
952 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -0400953 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -0400954 pvlan |= BIT(i);
955
956 return pvlan;
957}
958
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400959static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400960{
961 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500962
963 /* prevent frames from going back out of the port they came in on */
964 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700965
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100966 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700967}
968
Vivien Didelotf81ec902016-05-09 13:22:58 -0400969static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
970 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700971{
Vivien Didelot04bed142016-08-31 18:06:13 -0400972 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -0400973 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700974
Vivien Didelotfad09c72016-06-21 12:28:20 -0400975 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -0400976 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400977 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400978
979 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400980 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700981}
982
Vivien Didelot9e907d72017-07-17 13:03:43 -0400983static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
984{
985 if (chip->info->ops->pot_clear)
986 return chip->info->ops->pot_clear(chip);
987
988 return 0;
989}
990
Vivien Didelot51c901a2017-07-17 13:03:41 -0400991static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
992{
993 if (chip->info->ops->mgmt_rsvd2cpu)
994 return chip->info->ops->mgmt_rsvd2cpu(chip);
995
996 return 0;
997}
998
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500999static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1000{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001001 int err;
1002
Vivien Didelotdaefc942017-03-11 16:12:54 -05001003 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1004 if (err)
1005 return err;
1006
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001007 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1008 if (err)
1009 return err;
1010
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001011 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1012}
1013
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001014static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1015{
1016 int port;
1017 int err;
1018
1019 if (!chip->info->ops->irl_init_all)
1020 return 0;
1021
1022 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1023 /* Disable ingress rate limiting by resetting all per port
1024 * ingress rate limit resources to their initial state.
1025 */
1026 err = chip->info->ops->irl_init_all(chip, port);
1027 if (err)
1028 return err;
1029 }
1030
1031 return 0;
1032}
1033
Vivien Didelot04a69a12017-10-13 14:18:05 -04001034static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1035{
1036 if (chip->info->ops->set_switch_mac) {
1037 u8 addr[ETH_ALEN];
1038
1039 eth_random_addr(addr);
1040
1041 return chip->info->ops->set_switch_mac(chip, addr);
1042 }
1043
1044 return 0;
1045}
1046
Vivien Didelot17a15942017-03-30 17:37:09 -04001047static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1048{
1049 u16 pvlan = 0;
1050
1051 if (!mv88e6xxx_has_pvt(chip))
1052 return -EOPNOTSUPP;
1053
1054 /* Skip the local source device, which uses in-chip port VLAN */
1055 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001056 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001057
1058 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1059}
1060
Vivien Didelot81228992017-03-30 17:37:08 -04001061static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1062{
Vivien Didelot17a15942017-03-30 17:37:09 -04001063 int dev, port;
1064 int err;
1065
Vivien Didelot81228992017-03-30 17:37:08 -04001066 if (!mv88e6xxx_has_pvt(chip))
1067 return 0;
1068
1069 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1070 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1071 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001072 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1073 if (err)
1074 return err;
1075
1076 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1077 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1078 err = mv88e6xxx_pvt_map(chip, dev, port);
1079 if (err)
1080 return err;
1081 }
1082 }
1083
1084 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001085}
1086
Vivien Didelot749efcb2016-09-22 16:49:24 -04001087static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1088{
1089 struct mv88e6xxx_chip *chip = ds->priv;
1090 int err;
1091
1092 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001093 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001094 mutex_unlock(&chip->reg_lock);
1095
1096 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001097 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001098}
1099
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001100static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1101{
1102 if (!chip->info->max_vid)
1103 return 0;
1104
1105 return mv88e6xxx_g1_vtu_flush(chip);
1106}
1107
Vivien Didelotf1394b782017-05-01 14:05:22 -04001108static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1109 struct mv88e6xxx_vtu_entry *entry)
1110{
1111 if (!chip->info->ops->vtu_getnext)
1112 return -EOPNOTSUPP;
1113
1114 return chip->info->ops->vtu_getnext(chip, entry);
1115}
1116
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001117static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1118 struct mv88e6xxx_vtu_entry *entry)
1119{
1120 if (!chip->info->ops->vtu_loadpurge)
1121 return -EOPNOTSUPP;
1122
1123 return chip->info->ops->vtu_loadpurge(chip, entry);
1124}
1125
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001126static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001127{
1128 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001129 struct mv88e6xxx_vtu_entry vlan = {
1130 .vid = chip->info->max_vid,
1131 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001132 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001133
1134 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1135
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001136 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001137 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001138 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001139 if (err)
1140 return err;
1141
1142 set_bit(*fid, fid_bitmap);
1143 }
1144
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001145 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001146 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001147 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001148 if (err)
1149 return err;
1150
1151 if (!vlan.valid)
1152 break;
1153
1154 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001155 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001156
1157 /* The reset value 0x000 is used to indicate that multiple address
1158 * databases are not needed. Return the next positive available.
1159 */
1160 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001161 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001162 return -ENOSPC;
1163
1164 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001165 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001166}
1167
Vivien Didelot567aa592017-05-01 14:05:25 -04001168static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1169 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001170{
1171 int err;
1172
1173 if (!vid)
1174 return -EINVAL;
1175
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001176 entry->vid = vid - 1;
1177 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001178
Vivien Didelotf1394b782017-05-01 14:05:22 -04001179 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001180 if (err)
1181 return err;
1182
Vivien Didelot567aa592017-05-01 14:05:25 -04001183 if (entry->vid == vid && entry->valid)
1184 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001185
Vivien Didelot567aa592017-05-01 14:05:25 -04001186 if (new) {
1187 int i;
1188
1189 /* Initialize a fresh VLAN entry */
1190 memset(entry, 0, sizeof(*entry));
1191 entry->valid = true;
1192 entry->vid = vid;
1193
Vivien Didelot553a7682017-06-07 18:12:16 -04001194 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001195 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001196 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001197 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001198
1199 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001200 }
1201
Vivien Didelot567aa592017-05-01 14:05:25 -04001202 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1203 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001204}
1205
Vivien Didelotda9c3592016-02-12 12:09:40 -05001206static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1207 u16 vid_begin, u16 vid_end)
1208{
Vivien Didelot04bed142016-08-31 18:06:13 -04001209 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001210 struct mv88e6xxx_vtu_entry vlan = {
1211 .vid = vid_begin - 1,
1212 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001213 int i, err;
1214
Andrew Lunndb06ae412017-09-25 23:32:20 +02001215 /* DSA and CPU ports have to be members of multiple vlans */
1216 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1217 return 0;
1218
Vivien Didelotda9c3592016-02-12 12:09:40 -05001219 if (!vid_begin)
1220 return -EOPNOTSUPP;
1221
Vivien Didelotfad09c72016-06-21 12:28:20 -04001222 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001223
Vivien Didelotda9c3592016-02-12 12:09:40 -05001224 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001225 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001226 if (err)
1227 goto unlock;
1228
1229 if (!vlan.valid)
1230 break;
1231
1232 if (vlan.vid > vid_end)
1233 break;
1234
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001235 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001236 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1237 continue;
1238
Andrew Lunncd886462017-11-09 22:29:53 +01001239 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001240 continue;
1241
Vivien Didelotbd00e052017-05-01 14:05:11 -04001242 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001243 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001244 continue;
1245
Vivien Didelotc8652c82017-10-16 11:12:19 -04001246 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001247 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001248 break; /* same bridge, check next VLAN */
1249
Vivien Didelotc8652c82017-10-16 11:12:19 -04001250 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001251 continue;
1252
Andrew Lunn743fcc22017-11-09 22:29:54 +01001253 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1254 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001255 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001256 err = -EOPNOTSUPP;
1257 goto unlock;
1258 }
1259 } while (vlan.vid < vid_end);
1260
1261unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001262 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001263
1264 return err;
1265}
1266
Vivien Didelotf81ec902016-05-09 13:22:58 -04001267static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1268 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001269{
Vivien Didelot04bed142016-08-31 18:06:13 -04001270 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001271 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1272 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001273 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001274
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001275 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001276 return -EOPNOTSUPP;
1277
Vivien Didelotfad09c72016-06-21 12:28:20 -04001278 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001279 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001280 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001281
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001282 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001283}
1284
Vivien Didelot57d32312016-06-20 13:13:58 -04001285static int
1286mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001287 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001288{
Vivien Didelot04bed142016-08-31 18:06:13 -04001289 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001290 int err;
1291
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001292 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001293 return -EOPNOTSUPP;
1294
Vivien Didelotda9c3592016-02-12 12:09:40 -05001295 /* If the requested port doesn't belong to the same bridge as the VLAN
1296 * members, do not support it (yet) and fallback to software VLAN.
1297 */
1298 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1299 vlan->vid_end);
1300 if (err)
1301 return err;
1302
Vivien Didelot76e398a2015-11-01 12:33:55 -05001303 /* We don't need any dynamic resource from the kernel (yet),
1304 * so skip the prepare phase.
1305 */
1306 return 0;
1307}
1308
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001309static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1310 const unsigned char *addr, u16 vid,
1311 u8 state)
1312{
1313 struct mv88e6xxx_vtu_entry vlan;
1314 struct mv88e6xxx_atu_entry entry;
1315 int err;
1316
1317 /* Null VLAN ID corresponds to the port private database */
1318 if (vid == 0)
1319 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1320 else
1321 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1322 if (err)
1323 return err;
1324
1325 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1326 ether_addr_copy(entry.mac, addr);
1327 eth_addr_dec(entry.mac);
1328
1329 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1330 if (err)
1331 return err;
1332
1333 /* Initialize a fresh ATU entry if it isn't found */
1334 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1335 !ether_addr_equal(entry.mac, addr)) {
1336 memset(&entry, 0, sizeof(entry));
1337 ether_addr_copy(entry.mac, addr);
1338 }
1339
1340 /* Purge the ATU entry only if no port is using it anymore */
1341 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1342 entry.portvec &= ~BIT(port);
1343 if (!entry.portvec)
1344 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1345 } else {
1346 entry.portvec |= BIT(port);
1347 entry.state = state;
1348 }
1349
1350 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1351}
1352
Andrew Lunn87fa8862017-11-09 22:29:56 +01001353static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1354 u16 vid)
1355{
1356 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1357 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1358
1359 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1360}
1361
1362static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1363{
1364 int port;
1365 int err;
1366
1367 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1368 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1369 if (err)
1370 return err;
1371 }
1372
1373 return 0;
1374}
1375
Vivien Didelotfad09c72016-06-21 12:28:20 -04001376static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001377 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001378{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001379 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001380 int err;
1381
Vivien Didelot567aa592017-05-01 14:05:25 -04001382 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001383 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001384 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001385
Vivien Didelotc91498e2017-06-07 18:12:13 -04001386 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001387
Andrew Lunn87fa8862017-11-09 22:29:56 +01001388 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1389 if (err)
1390 return err;
1391
1392 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001393}
1394
Vivien Didelotf81ec902016-05-09 13:22:58 -04001395static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001396 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001397{
Vivien Didelot04bed142016-08-31 18:06:13 -04001398 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001399 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1400 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001401 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001402 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001403
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001404 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001405 return;
1406
Vivien Didelotc91498e2017-06-07 18:12:13 -04001407 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001408 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001409 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001410 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001411 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001412 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001413
Vivien Didelotfad09c72016-06-21 12:28:20 -04001414 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001415
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001416 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001417 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001418 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1419 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001420
Vivien Didelot77064f32016-11-04 03:23:30 +01001421 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001422 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1423 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001424
Vivien Didelotfad09c72016-06-21 12:28:20 -04001425 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001426}
1427
Vivien Didelotfad09c72016-06-21 12:28:20 -04001428static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001429 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001430{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001431 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001432 int i, err;
1433
Vivien Didelot567aa592017-05-01 14:05:25 -04001434 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001435 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001436 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001437
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001438 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001439 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001440 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001441
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001442 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001443
1444 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001445 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001446 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001447 if (vlan.member[i] !=
1448 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001449 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001450 break;
1451 }
1452 }
1453
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001454 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001455 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001456 return err;
1457
Vivien Didelote606ca32017-03-11 16:12:55 -05001458 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001459}
1460
Vivien Didelotf81ec902016-05-09 13:22:58 -04001461static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1462 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001463{
Vivien Didelot04bed142016-08-31 18:06:13 -04001464 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001465 u16 pvid, vid;
1466 int err = 0;
1467
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001468 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001469 return -EOPNOTSUPP;
1470
Vivien Didelotfad09c72016-06-21 12:28:20 -04001471 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001472
Vivien Didelot77064f32016-11-04 03:23:30 +01001473 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001474 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001475 goto unlock;
1476
Vivien Didelot76e398a2015-11-01 12:33:55 -05001477 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001478 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001479 if (err)
1480 goto unlock;
1481
1482 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001483 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001484 if (err)
1485 goto unlock;
1486 }
1487 }
1488
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001489unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001490 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001491
1492 return err;
1493}
1494
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001495static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1496 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001497{
Vivien Didelot04bed142016-08-31 18:06:13 -04001498 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001499 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001500
Vivien Didelotfad09c72016-06-21 12:28:20 -04001501 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001502 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1503 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001504 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001505
1506 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001507}
1508
Vivien Didelotf81ec902016-05-09 13:22:58 -04001509static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001510 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001511{
Vivien Didelot04bed142016-08-31 18:06:13 -04001512 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001513 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001514
Vivien Didelotfad09c72016-06-21 12:28:20 -04001515 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001516 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001517 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001518 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001519
Vivien Didelot83dabd12016-08-31 11:50:04 -04001520 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001521}
1522
Vivien Didelot83dabd12016-08-31 11:50:04 -04001523static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1524 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001525 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001526{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001527 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001528 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001529 int err;
1530
Vivien Didelot27c0e602017-06-15 12:14:01 -04001531 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001532 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001533
1534 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001535 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001536 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001537 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001538 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001539 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001540
Vivien Didelot27c0e602017-06-15 12:14:01 -04001541 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001542 break;
1543
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001544 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001545 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001546
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001547 if (!is_unicast_ether_addr(addr.mac))
1548 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001549
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001550 is_static = (addr.state ==
1551 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1552 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001553 if (err)
1554 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001555 } while (!is_broadcast_ether_addr(addr.mac));
1556
1557 return err;
1558}
1559
Vivien Didelot83dabd12016-08-31 11:50:04 -04001560static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001561 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001562{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001563 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001564 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001565 };
1566 u16 fid;
1567 int err;
1568
1569 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001570 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001571 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001572 mutex_unlock(&chip->reg_lock);
1573
Vivien Didelot83dabd12016-08-31 11:50:04 -04001574 if (err)
1575 return err;
1576
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001577 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001578 if (err)
1579 return err;
1580
1581 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001582 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001583 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001584 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001585 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001586 if (err)
1587 return err;
1588
1589 if (!vlan.valid)
1590 break;
1591
1592 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001593 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001594 if (err)
1595 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001596 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001597
1598 return err;
1599}
1600
Vivien Didelotf81ec902016-05-09 13:22:58 -04001601static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001602 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001603{
Vivien Didelot04bed142016-08-31 18:06:13 -04001604 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001605
Andrew Lunna61e5402018-02-15 14:38:35 +01001606 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001607}
1608
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001609static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1610 struct net_device *br)
1611{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001612 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001613 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001614 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001615 int err;
1616
1617 /* Remap the Port VLAN of each local bridge group member */
1618 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1619 if (chip->ds->ports[port].bridge_dev == br) {
1620 err = mv88e6xxx_port_vlan_map(chip, port);
1621 if (err)
1622 return err;
1623 }
1624 }
1625
Vivien Didelote96a6e02017-03-30 17:37:13 -04001626 if (!mv88e6xxx_has_pvt(chip))
1627 return 0;
1628
1629 /* Remap the Port VLAN of each cross-chip bridge group member */
1630 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1631 ds = chip->ds->dst->ds[dev];
1632 if (!ds)
1633 break;
1634
1635 for (port = 0; port < ds->num_ports; ++port) {
1636 if (ds->ports[port].bridge_dev == br) {
1637 err = mv88e6xxx_pvt_map(chip, dev, port);
1638 if (err)
1639 return err;
1640 }
1641 }
1642 }
1643
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001644 return 0;
1645}
1646
Vivien Didelotf81ec902016-05-09 13:22:58 -04001647static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001648 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001649{
Vivien Didelot04bed142016-08-31 18:06:13 -04001650 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001651 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001652
Vivien Didelotfad09c72016-06-21 12:28:20 -04001653 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001654 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001655 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001656
Vivien Didelot466dfa02016-02-26 13:16:05 -05001657 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001658}
1659
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001660static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1661 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001662{
Vivien Didelot04bed142016-08-31 18:06:13 -04001663 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001664
Vivien Didelotfad09c72016-06-21 12:28:20 -04001665 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001666 if (mv88e6xxx_bridge_map(chip, br) ||
1667 mv88e6xxx_port_vlan_map(chip, port))
1668 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001669 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001670}
1671
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001672static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1673 int port, struct net_device *br)
1674{
1675 struct mv88e6xxx_chip *chip = ds->priv;
1676 int err;
1677
1678 if (!mv88e6xxx_has_pvt(chip))
1679 return 0;
1680
1681 mutex_lock(&chip->reg_lock);
1682 err = mv88e6xxx_pvt_map(chip, dev, port);
1683 mutex_unlock(&chip->reg_lock);
1684
1685 return err;
1686}
1687
1688static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1689 int port, struct net_device *br)
1690{
1691 struct mv88e6xxx_chip *chip = ds->priv;
1692
1693 if (!mv88e6xxx_has_pvt(chip))
1694 return;
1695
1696 mutex_lock(&chip->reg_lock);
1697 if (mv88e6xxx_pvt_map(chip, dev, port))
1698 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1699 mutex_unlock(&chip->reg_lock);
1700}
1701
Vivien Didelot17e708b2016-12-05 17:30:27 -05001702static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1703{
1704 if (chip->info->ops->reset)
1705 return chip->info->ops->reset(chip);
1706
1707 return 0;
1708}
1709
Vivien Didelot309eca62016-12-05 17:30:26 -05001710static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1711{
1712 struct gpio_desc *gpiod = chip->reset;
1713
1714 /* If there is a GPIO connected to the reset pin, toggle it */
1715 if (gpiod) {
1716 gpiod_set_value_cansleep(gpiod, 1);
1717 usleep_range(10000, 20000);
1718 gpiod_set_value_cansleep(gpiod, 0);
1719 usleep_range(10000, 20000);
1720 }
1721}
1722
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001723static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1724{
1725 int i, err;
1726
1727 /* Set all ports to the Disabled state */
1728 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001729 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001730 if (err)
1731 return err;
1732 }
1733
1734 /* Wait for transmit queues to drain,
1735 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1736 */
1737 usleep_range(2000, 4000);
1738
1739 return 0;
1740}
1741
Vivien Didelotfad09c72016-06-21 12:28:20 -04001742static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001743{
Vivien Didelota935c052016-09-29 12:21:53 -04001744 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001745
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001746 err = mv88e6xxx_disable_ports(chip);
1747 if (err)
1748 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001749
Vivien Didelot309eca62016-12-05 17:30:26 -05001750 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001751
Vivien Didelot17e708b2016-12-05 17:30:27 -05001752 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001753}
1754
Vivien Didelot43145572017-03-11 16:12:59 -05001755static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001756 enum mv88e6xxx_frame_mode frame,
1757 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001758{
1759 int err;
1760
Vivien Didelot43145572017-03-11 16:12:59 -05001761 if (!chip->info->ops->port_set_frame_mode)
1762 return -EOPNOTSUPP;
1763
1764 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001765 if (err)
1766 return err;
1767
Vivien Didelot43145572017-03-11 16:12:59 -05001768 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1769 if (err)
1770 return err;
1771
1772 if (chip->info->ops->port_set_ether_type)
1773 return chip->info->ops->port_set_ether_type(chip, port, etype);
1774
1775 return 0;
1776}
1777
1778static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1779{
1780 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001781 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001782 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001783}
1784
1785static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1786{
1787 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001788 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001789 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001790}
1791
1792static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1793{
1794 return mv88e6xxx_set_port_mode(chip, port,
1795 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001796 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1797 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001798}
1799
1800static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1801{
1802 if (dsa_is_dsa_port(chip->ds, port))
1803 return mv88e6xxx_set_port_mode_dsa(chip, port);
1804
Vivien Didelot2b3e9892017-10-26 11:22:54 -04001805 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05001806 return mv88e6xxx_set_port_mode_normal(chip, port);
1807
1808 /* Setup CPU port mode depending on its supported tag format */
1809 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1810 return mv88e6xxx_set_port_mode_dsa(chip, port);
1811
1812 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1813 return mv88e6xxx_set_port_mode_edsa(chip, port);
1814
1815 return -EINVAL;
1816}
1817
Vivien Didelotea698f42017-03-11 16:12:50 -05001818static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1819{
1820 bool message = dsa_is_dsa_port(chip->ds, port);
1821
1822 return mv88e6xxx_port_set_message_port(chip, port, message);
1823}
1824
Vivien Didelot601aeed2017-03-11 16:13:00 -05001825static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1826{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001827 struct dsa_switch *ds = chip->ds;
1828 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05001829
1830 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001831 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05001832 if (chip->info->ops->port_set_egress_floods)
1833 return chip->info->ops->port_set_egress_floods(chip, port,
1834 flood, flood);
1835
1836 return 0;
1837}
1838
Andrew Lunn6d917822017-05-26 01:03:21 +02001839static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1840 bool on)
1841{
Vivien Didelot523a8902017-05-26 18:02:42 -04001842 if (chip->info->ops->serdes_power)
1843 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001844
Vivien Didelot523a8902017-05-26 18:02:42 -04001845 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001846}
1847
Vivien Didelotfa371c82017-12-05 15:34:10 -05001848static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
1849{
1850 struct dsa_switch *ds = chip->ds;
1851 int upstream_port;
1852 int err;
1853
Vivien Didelot07073c72017-12-05 15:34:13 -05001854 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05001855 if (chip->info->ops->port_set_upstream_port) {
1856 err = chip->info->ops->port_set_upstream_port(chip, port,
1857 upstream_port);
1858 if (err)
1859 return err;
1860 }
1861
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05001862 if (port == upstream_port) {
1863 if (chip->info->ops->set_cpu_port) {
1864 err = chip->info->ops->set_cpu_port(chip,
1865 upstream_port);
1866 if (err)
1867 return err;
1868 }
1869
1870 if (chip->info->ops->set_egress_port) {
1871 err = chip->info->ops->set_egress_port(chip,
1872 upstream_port);
1873 if (err)
1874 return err;
1875 }
1876 }
1877
Vivien Didelotfa371c82017-12-05 15:34:10 -05001878 return 0;
1879}
1880
Vivien Didelotfad09c72016-06-21 12:28:20 -04001881static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001882{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001883 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001884 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001885 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001886
Vivien Didelotd78343d2016-11-04 03:23:36 +01001887 /* MAC Forcing register: don't force link, speed, duplex or flow control
1888 * state to any particular values on physical ports, but force the CPU
1889 * port and all DSA ports to their maximum bandwidth and full duplex.
1890 */
1891 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1892 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1893 SPEED_MAX, DUPLEX_FULL,
1894 PHY_INTERFACE_MODE_NA);
1895 else
1896 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1897 SPEED_UNFORCED, DUPLEX_UNFORCED,
1898 PHY_INTERFACE_MODE_NA);
1899 if (err)
1900 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001901
1902 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1903 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1904 * tunneling, determine priority by looking at 802.1p and IP
1905 * priority fields (IP prio has precedence), and set STP state
1906 * to Forwarding.
1907 *
1908 * If this is the CPU link, use DSA or EDSA tagging depending
1909 * on which tagging mode was configured.
1910 *
1911 * If this is a link to another switch, use DSA tagging mode.
1912 *
1913 * If this is the upstream port for this switch, enable
1914 * forwarding of unknown unicasts and multicasts.
1915 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04001916 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
1917 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
1918 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1919 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001920 if (err)
1921 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001922
Vivien Didelot601aeed2017-03-11 16:13:00 -05001923 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001924 if (err)
1925 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001926
Vivien Didelot601aeed2017-03-11 16:13:00 -05001927 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001928 if (err)
1929 return err;
1930
Andrew Lunn04aca992017-05-26 01:03:24 +02001931 /* Enable the SERDES interface for DSA and CPU ports. Normal
1932 * ports SERDES are enabled when the port is enabled, thus
1933 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001934 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001935 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1936 err = mv88e6xxx_serdes_power(chip, port, true);
1937 if (err)
1938 return err;
1939 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001940
Vivien Didelot8efdda42015-08-13 12:52:23 -04001941 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001942 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001943 * untagged frames on this port, do a destination address lookup on all
1944 * received packets as usual, disable ARP mirroring and don't send a
1945 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001946 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001947 err = mv88e6xxx_port_set_map_da(chip, port);
1948 if (err)
1949 return err;
1950
Vivien Didelotfa371c82017-12-05 15:34:10 -05001951 err = mv88e6xxx_setup_upstream_port(chip, port);
1952 if (err)
1953 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001954
Andrew Lunna23b2962017-02-04 20:15:28 +01001955 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001956 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01001957 if (err)
1958 return err;
1959
Vivien Didelotcd782652017-06-08 18:34:13 -04001960 if (chip->info->ops->port_set_jumbo_size) {
1961 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01001962 if (err)
1963 return err;
1964 }
1965
Andrew Lunn54d792f2015-05-06 01:09:47 +02001966 /* Port Association Vector: when learning source addresses
1967 * of packets, add the address to the address database using
1968 * a port bitmap that has only the bit for this port set and
1969 * the other bits clear.
1970 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001971 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001972 /* Disable learning for CPU port */
1973 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001974 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001975
Vivien Didelot2a4614e2017-06-12 12:37:43 -04001976 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
1977 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001978 if (err)
1979 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001980
1981 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04001982 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
1983 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001984 if (err)
1985 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001986
Vivien Didelot08984322017-06-08 18:34:12 -04001987 if (chip->info->ops->port_pause_limit) {
1988 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001989 if (err)
1990 return err;
1991 }
1992
Vivien Didelotc8c94892017-03-11 16:13:01 -05001993 if (chip->info->ops->port_disable_learn_limit) {
1994 err = chip->info->ops->port_disable_learn_limit(chip, port);
1995 if (err)
1996 return err;
1997 }
1998
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001999 if (chip->info->ops->port_disable_pri_override) {
2000 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002001 if (err)
2002 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002003 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002004
Andrew Lunnef0a7312016-12-03 04:35:16 +01002005 if (chip->info->ops->port_tag_remap) {
2006 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002007 if (err)
2008 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002009 }
2010
Andrew Lunnef70b112016-12-03 04:45:18 +01002011 if (chip->info->ops->port_egress_rate_limiting) {
2012 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002013 if (err)
2014 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002015 }
2016
Vivien Didelotea698f42017-03-11 16:12:50 -05002017 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002018 if (err)
2019 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002020
Vivien Didelot207afda2016-04-14 14:42:09 -04002021 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002022 * database, and allow bidirectional communication between the
2023 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002024 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002025 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002026 if (err)
2027 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002028
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002029 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002030 if (err)
2031 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002032
2033 /* Default VLAN ID and priority: don't set a default VLAN
2034 * ID, and set the default packet priority to zero.
2035 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002036 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002037}
2038
Andrew Lunn04aca992017-05-26 01:03:24 +02002039static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2040 struct phy_device *phydev)
2041{
2042 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002043 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002044
2045 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002046 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002047 mutex_unlock(&chip->reg_lock);
2048
2049 return err;
2050}
2051
2052static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2053 struct phy_device *phydev)
2054{
2055 struct mv88e6xxx_chip *chip = ds->priv;
2056
2057 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002058 if (mv88e6xxx_serdes_power(chip, port, false))
2059 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002060 mutex_unlock(&chip->reg_lock);
2061}
2062
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002063static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2064 unsigned int ageing_time)
2065{
Vivien Didelot04bed142016-08-31 18:06:13 -04002066 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002067 int err;
2068
2069 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002070 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002071 mutex_unlock(&chip->reg_lock);
2072
2073 return err;
2074}
2075
Vivien Didelot97299342016-07-18 20:45:30 -04002076static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002077{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002078 struct dsa_switch *ds = chip->ds;
Vivien Didelot08a01262016-05-09 13:22:50 -04002079 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002080
Vivien Didelot50484ff2016-05-09 13:22:54 -04002081 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelotd77f4322017-06-15 12:14:03 -04002082 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2083 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
Vivien Didelota935c052016-09-29 12:21:53 -04002084 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002085 if (err)
2086 return err;
2087
Vivien Didelot08a01262016-05-09 13:22:50 -04002088 /* Configure the IP ToS mapping registers. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002089 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002090 if (err)
2091 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002092 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002093 if (err)
2094 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002095 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002096 if (err)
2097 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002098 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002099 if (err)
2100 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002101 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002102 if (err)
2103 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002104 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002105 if (err)
2106 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002107 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002108 if (err)
2109 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002110 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002111 if (err)
2112 return err;
2113
2114 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002115 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002116 if (err)
2117 return err;
2118
Andrew Lunnde2273872016-11-21 23:27:01 +01002119 /* Initialize the statistics unit */
2120 err = mv88e6xxx_stats_set_histogram(chip);
2121 if (err)
2122 return err;
2123
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002124 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002125}
2126
Vivien Didelotf81ec902016-05-09 13:22:58 -04002127static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002128{
Vivien Didelot04bed142016-08-31 18:06:13 -04002129 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002130 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002131 int i;
2132
Vivien Didelotfad09c72016-06-21 12:28:20 -04002133 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002134 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002135
Vivien Didelotfad09c72016-06-21 12:28:20 -04002136 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002137
Vivien Didelot97299342016-07-18 20:45:30 -04002138 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002139 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002140 if (dsa_is_unused_port(ds, i))
2141 continue;
2142
Vivien Didelot97299342016-07-18 20:45:30 -04002143 err = mv88e6xxx_setup_port(chip, i);
2144 if (err)
2145 goto unlock;
2146 }
2147
2148 /* Setup Switch Global 1 Registers */
2149 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002150 if (err)
2151 goto unlock;
2152
Vivien Didelot97299342016-07-18 20:45:30 -04002153 /* Setup Switch Global 2 Registers */
Vivien Didelot9069c132017-07-17 13:03:44 -04002154 if (chip->info->global2_addr) {
Vivien Didelot97299342016-07-18 20:45:30 -04002155 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002156 if (err)
2157 goto unlock;
2158 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002159
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002160 err = mv88e6xxx_irl_setup(chip);
2161 if (err)
2162 goto unlock;
2163
Vivien Didelot04a69a12017-10-13 14:18:05 -04002164 err = mv88e6xxx_mac_setup(chip);
2165 if (err)
2166 goto unlock;
2167
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002168 err = mv88e6xxx_phy_setup(chip);
2169 if (err)
2170 goto unlock;
2171
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002172 err = mv88e6xxx_vtu_setup(chip);
2173 if (err)
2174 goto unlock;
2175
Vivien Didelot81228992017-03-30 17:37:08 -04002176 err = mv88e6xxx_pvt_setup(chip);
2177 if (err)
2178 goto unlock;
2179
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002180 err = mv88e6xxx_atu_setup(chip);
2181 if (err)
2182 goto unlock;
2183
Andrew Lunn87fa8862017-11-09 22:29:56 +01002184 err = mv88e6xxx_broadcast_setup(chip, 0);
2185 if (err)
2186 goto unlock;
2187
Vivien Didelot9e907d72017-07-17 13:03:43 -04002188 err = mv88e6xxx_pot_setup(chip);
2189 if (err)
2190 goto unlock;
2191
Vivien Didelot51c901a2017-07-17 13:03:41 -04002192 err = mv88e6xxx_rsvd2cpu_setup(chip);
2193 if (err)
2194 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002195
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002196 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002197 if (chip->info->ptp_support) {
2198 err = mv88e6xxx_ptp_setup(chip);
2199 if (err)
2200 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002201
2202 err = mv88e6xxx_hwtstamp_setup(chip);
2203 if (err)
2204 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002205 }
2206
Vivien Didelot6b17e862015-08-13 12:52:18 -04002207unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002208 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002209
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002210 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002211}
2212
Vivien Didelote57e5e72016-08-15 17:19:00 -04002213static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002214{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002215 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2216 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002217 u16 val;
2218 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002219
Andrew Lunnee26a222017-01-24 14:53:48 +01002220 if (!chip->info->ops->phy_read)
2221 return -EOPNOTSUPP;
2222
Vivien Didelotfad09c72016-06-21 12:28:20 -04002223 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002224 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002225 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002226
Andrew Lunnda9f3302017-02-01 03:40:05 +01002227 if (reg == MII_PHYSID2) {
2228 /* Some internal PHYS don't have a model number. Use
2229 * the mv88e6390 family model number instead.
2230 */
2231 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002232 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002233 }
2234
Vivien Didelote57e5e72016-08-15 17:19:00 -04002235 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002236}
2237
Vivien Didelote57e5e72016-08-15 17:19:00 -04002238static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002239{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002240 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2241 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002242 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002243
Andrew Lunnee26a222017-01-24 14:53:48 +01002244 if (!chip->info->ops->phy_write)
2245 return -EOPNOTSUPP;
2246
Vivien Didelotfad09c72016-06-21 12:28:20 -04002247 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002248 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002249 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002250
2251 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002252}
2253
Vivien Didelotfad09c72016-06-21 12:28:20 -04002254static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002255 struct device_node *np,
2256 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002257{
2258 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002259 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002260 struct mii_bus *bus;
2261 int err;
2262
Andrew Lunn2510bab2018-02-22 01:51:49 +01002263 if (external) {
2264 mutex_lock(&chip->reg_lock);
2265 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2266 mutex_unlock(&chip->reg_lock);
2267
2268 if (err)
2269 return err;
2270 }
2271
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002272 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002273 if (!bus)
2274 return -ENOMEM;
2275
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002276 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002277 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002278 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002279 INIT_LIST_HEAD(&mdio_bus->list);
2280 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002281
Andrew Lunnb516d452016-06-04 21:17:06 +02002282 if (np) {
2283 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002284 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002285 } else {
2286 bus->name = "mv88e6xxx SMI";
2287 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2288 }
2289
2290 bus->read = mv88e6xxx_mdio_read;
2291 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002292 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002293
Andrew Lunna3c53be52017-01-24 14:53:50 +01002294 if (np)
2295 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002296 else
2297 err = mdiobus_register(bus);
2298 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002299 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002300 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002301 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002302
2303 if (external)
2304 list_add_tail(&mdio_bus->list, &chip->mdios);
2305 else
2306 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002307
2308 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002309}
2310
Andrew Lunna3c53be52017-01-24 14:53:50 +01002311static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2312 { .compatible = "marvell,mv88e6xxx-mdio-external",
2313 .data = (void *)true },
2314 { },
2315};
2316
Andrew Lunn3126aee2017-12-07 01:05:57 +01002317static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2318
2319{
2320 struct mv88e6xxx_mdio_bus *mdio_bus;
2321 struct mii_bus *bus;
2322
2323 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2324 bus = mdio_bus->bus;
2325
2326 mdiobus_unregister(bus);
2327 }
2328}
2329
Andrew Lunna3c53be52017-01-24 14:53:50 +01002330static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2331 struct device_node *np)
2332{
2333 const struct of_device_id *match;
2334 struct device_node *child;
2335 int err;
2336
2337 /* Always register one mdio bus for the internal/default mdio
2338 * bus. This maybe represented in the device tree, but is
2339 * optional.
2340 */
2341 child = of_get_child_by_name(np, "mdio");
2342 err = mv88e6xxx_mdio_register(chip, child, false);
2343 if (err)
2344 return err;
2345
2346 /* Walk the device tree, and see if there are any other nodes
2347 * which say they are compatible with the external mdio
2348 * bus.
2349 */
2350 for_each_available_child_of_node(np, child) {
2351 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2352 if (match) {
2353 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002354 if (err) {
2355 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002356 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002357 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002358 }
2359 }
2360
2361 return 0;
2362}
2363
Vivien Didelot855b1932016-07-20 18:18:35 -04002364static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2365{
Vivien Didelot04bed142016-08-31 18:06:13 -04002366 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002367
2368 return chip->eeprom_len;
2369}
2370
Vivien Didelot855b1932016-07-20 18:18:35 -04002371static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2372 struct ethtool_eeprom *eeprom, u8 *data)
2373{
Vivien Didelot04bed142016-08-31 18:06:13 -04002374 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002375 int err;
2376
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002377 if (!chip->info->ops->get_eeprom)
2378 return -EOPNOTSUPP;
2379
Vivien Didelot855b1932016-07-20 18:18:35 -04002380 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002381 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002382 mutex_unlock(&chip->reg_lock);
2383
2384 if (err)
2385 return err;
2386
2387 eeprom->magic = 0xc3ec4951;
2388
2389 return 0;
2390}
2391
Vivien Didelot855b1932016-07-20 18:18:35 -04002392static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2393 struct ethtool_eeprom *eeprom, u8 *data)
2394{
Vivien Didelot04bed142016-08-31 18:06:13 -04002395 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002396 int err;
2397
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002398 if (!chip->info->ops->set_eeprom)
2399 return -EOPNOTSUPP;
2400
Vivien Didelot855b1932016-07-20 18:18:35 -04002401 if (eeprom->magic != 0xc3ec4951)
2402 return -EINVAL;
2403
2404 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002405 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002406 mutex_unlock(&chip->reg_lock);
2407
2408 return err;
2409}
2410
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002411static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002412 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002413 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002414 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002415 .phy_read = mv88e6185_phy_ppu_read,
2416 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002417 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002418 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002419 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002420 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002421 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002422 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002423 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002424 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002425 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002426 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002427 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002428 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002429 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002430 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2431 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002432 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002433 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2434 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002435 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002436 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002437 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002438 .ppu_enable = mv88e6185_g1_ppu_enable,
2439 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002440 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002441 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002442 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002443};
2444
2445static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002446 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002447 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002448 .phy_read = mv88e6185_phy_ppu_read,
2449 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002450 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002451 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002452 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002453 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002454 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002455 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002456 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002457 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002458 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2459 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002460 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002461 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002462 .ppu_enable = mv88e6185_g1_ppu_enable,
2463 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002464 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002465 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002466 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002467};
2468
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002469static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002470 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002471 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002472 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2473 .phy_read = mv88e6xxx_g2_smi_phy_read,
2474 .phy_write = mv88e6xxx_g2_smi_phy_write,
2475 .port_set_link = mv88e6xxx_port_set_link,
2476 .port_set_duplex = mv88e6xxx_port_set_duplex,
2477 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002478 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002479 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002480 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002481 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002482 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002483 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002484 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002485 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002486 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002487 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002488 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002489 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2490 .stats_get_strings = mv88e6095_stats_get_strings,
2491 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002492 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2493 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002494 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002495 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002496 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002497 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002498 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002499 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002500};
2501
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002502static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002503 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002504 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002505 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002506 .phy_read = mv88e6xxx_g2_smi_phy_read,
2507 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002508 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002509 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002510 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002511 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002512 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002513 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002514 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002515 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002516 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002517 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2518 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002519 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002520 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2521 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002522 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002523 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002524 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002525 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002526 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002527 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002528};
2529
2530static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002531 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002532 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002533 .phy_read = mv88e6185_phy_ppu_read,
2534 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002535 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002536 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002537 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002538 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002539 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002540 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002541 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002542 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002543 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002544 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002545 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002546 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002547 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002548 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2549 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002550 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002551 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2552 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002553 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002554 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002555 .ppu_enable = mv88e6185_g1_ppu_enable,
2556 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002557 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002558 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002559 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002560};
2561
Vivien Didelot990e27b2017-03-28 13:50:32 -04002562static const struct mv88e6xxx_ops mv88e6141_ops = {
2563 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002564 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002565 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2566 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2567 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2568 .phy_read = mv88e6xxx_g2_smi_phy_read,
2569 .phy_write = mv88e6xxx_g2_smi_phy_write,
2570 .port_set_link = mv88e6xxx_port_set_link,
2571 .port_set_duplex = mv88e6xxx_port_set_duplex,
2572 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2573 .port_set_speed = mv88e6390_port_set_speed,
2574 .port_tag_remap = mv88e6095_port_tag_remap,
2575 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2576 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2577 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002578 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002579 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002580 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002581 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2582 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2583 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002584 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002585 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2586 .stats_get_strings = mv88e6320_stats_get_strings,
2587 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002588 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2589 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002590 .watchdog_ops = &mv88e6390_watchdog_ops,
2591 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002592 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002593 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002594 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002595 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002596 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002597};
2598
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002599static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002600 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002601 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002602 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002603 .phy_read = mv88e6xxx_g2_smi_phy_read,
2604 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002605 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002606 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002607 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002608 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002609 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002610 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002611 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002612 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002613 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002614 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002615 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002616 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002617 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002618 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002619 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2620 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002621 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002622 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2623 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002624 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002625 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002626 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002627 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002628 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002629 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002630};
2631
2632static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002633 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002634 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002635 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002636 .phy_read = mv88e6165_phy_read,
2637 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002638 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002639 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002640 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002641 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002642 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002643 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002644 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002645 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2646 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002647 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002648 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2649 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002650 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002651 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002652 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002653 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002654 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002655 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002656};
2657
2658static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002659 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002660 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002661 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002662 .phy_read = mv88e6xxx_g2_smi_phy_read,
2663 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002664 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002665 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002666 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002667 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002668 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002669 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002670 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002671 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002672 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002673 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002674 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002675 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002676 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002677 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002678 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002679 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2680 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002681 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002682 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2683 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002684 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002685 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002686 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002687 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002688 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002689 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002690};
2691
2692static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002693 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002694 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002695 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2696 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002697 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002698 .phy_read = mv88e6xxx_g2_smi_phy_read,
2699 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002700 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002701 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002702 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002703 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002704 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002705 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002706 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002707 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002708 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002709 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002710 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002711 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002712 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002713 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002714 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002715 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2716 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002717 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002718 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2719 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002720 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002721 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002722 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002723 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002724 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002725 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002726 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002727 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002728};
2729
2730static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002731 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002732 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002733 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002734 .phy_read = mv88e6xxx_g2_smi_phy_read,
2735 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002736 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002737 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002738 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002739 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002740 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002741 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002742 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002743 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002744 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002745 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002746 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002747 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002748 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002749 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002750 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002751 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2752 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002753 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002754 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2755 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002756 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002757 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002758 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002759 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002760 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002761 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002762};
2763
2764static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002765 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002766 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002767 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2768 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002769 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002770 .phy_read = mv88e6xxx_g2_smi_phy_read,
2771 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002772 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002773 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002774 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002775 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002776 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002777 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002778 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002779 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002780 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002781 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002782 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002783 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002784 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002785 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002786 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002787 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2788 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002789 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002790 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2791 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002792 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002793 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002794 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002795 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002796 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002797 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002798 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002799 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002800};
2801
2802static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002803 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002804 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002805 .phy_read = mv88e6185_phy_ppu_read,
2806 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002807 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002808 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002809 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002810 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002811 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002812 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002813 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002814 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002815 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002816 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2817 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002818 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002819 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2820 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002821 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002822 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002823 .ppu_enable = mv88e6185_g1_ppu_enable,
2824 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002825 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002826 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002827 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002828};
2829
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002830static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002831 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002832 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002833 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2834 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002835 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2836 .phy_read = mv88e6xxx_g2_smi_phy_read,
2837 .phy_write = mv88e6xxx_g2_smi_phy_write,
2838 .port_set_link = mv88e6xxx_port_set_link,
2839 .port_set_duplex = mv88e6xxx_port_set_duplex,
2840 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2841 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002842 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002843 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002844 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002845 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002846 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002847 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002848 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002849 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002850 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002851 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2852 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002853 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002854 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2855 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002856 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002857 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002858 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002859 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002860 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2861 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002862 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002863 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002864};
2865
2866static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002867 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002868 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002869 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2870 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002871 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2872 .phy_read = mv88e6xxx_g2_smi_phy_read,
2873 .phy_write = mv88e6xxx_g2_smi_phy_write,
2874 .port_set_link = mv88e6xxx_port_set_link,
2875 .port_set_duplex = mv88e6xxx_port_set_duplex,
2876 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2877 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002878 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002879 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002880 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002881 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002882 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002883 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002884 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002885 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002886 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002887 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2888 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002889 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002890 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2891 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002892 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002893 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002894 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002895 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002896 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2897 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002898 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002899 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002900};
2901
2902static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002903 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002904 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002905 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2906 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002907 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2908 .phy_read = mv88e6xxx_g2_smi_phy_read,
2909 .phy_write = mv88e6xxx_g2_smi_phy_write,
2910 .port_set_link = mv88e6xxx_port_set_link,
2911 .port_set_duplex = mv88e6xxx_port_set_duplex,
2912 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2913 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002914 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002915 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002916 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002917 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002918 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002919 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002920 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002921 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002922 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002923 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2924 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002925 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002926 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2927 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002928 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002929 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002930 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002931 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002932 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2933 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002934 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002935};
2936
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002937static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002938 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002939 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002940 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2941 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002942 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002943 .phy_read = mv88e6xxx_g2_smi_phy_read,
2944 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002945 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002946 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002947 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002948 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002949 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002950 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002951 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002952 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002953 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002954 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002955 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002956 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002957 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002958 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002959 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002960 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2961 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002962 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002963 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2964 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002965 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002966 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002967 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002968 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002969 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002970 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002971 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002972 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01002973 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002974};
2975
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002976static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002977 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002978 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002979 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2980 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002981 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2982 .phy_read = mv88e6xxx_g2_smi_phy_read,
2983 .phy_write = mv88e6xxx_g2_smi_phy_write,
2984 .port_set_link = mv88e6xxx_port_set_link,
2985 .port_set_duplex = mv88e6xxx_port_set_duplex,
2986 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2987 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002988 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002989 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002990 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002991 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002992 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002993 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002994 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002995 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002996 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002997 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002998 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2999 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003000 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003001 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3002 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003003 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003004 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003005 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003006 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003007 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3008 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003009 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003010 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003011 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003012};
3013
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003014static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003015 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003016 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003017 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3018 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003019 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003020 .phy_read = mv88e6xxx_g2_smi_phy_read,
3021 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003022 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003023 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003024 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003025 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003026 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003027 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003028 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003029 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003030 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003031 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003032 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003033 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003034 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003035 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003036 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3037 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003038 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003039 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3040 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003041 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003042 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003043 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003044 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003045 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003046 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003047 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003048};
3049
3050static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003051 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003052 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003053 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3054 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003055 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003056 .phy_read = mv88e6xxx_g2_smi_phy_read,
3057 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003058 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003059 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003060 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003061 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003062 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003063 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003064 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003065 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003066 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003067 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003068 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003069 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003070 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003071 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003072 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3073 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003074 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003075 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3076 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003077 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003078 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003079 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003080 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003081 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003082};
3083
Vivien Didelot16e329a2017-03-28 13:50:33 -04003084static const struct mv88e6xxx_ops mv88e6341_ops = {
3085 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003086 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003087 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3088 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3089 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3090 .phy_read = mv88e6xxx_g2_smi_phy_read,
3091 .phy_write = mv88e6xxx_g2_smi_phy_write,
3092 .port_set_link = mv88e6xxx_port_set_link,
3093 .port_set_duplex = mv88e6xxx_port_set_duplex,
3094 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3095 .port_set_speed = mv88e6390_port_set_speed,
3096 .port_tag_remap = mv88e6095_port_tag_remap,
3097 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3098 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3099 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003100 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003101 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003102 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003103 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3104 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3105 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003106 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003107 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3108 .stats_get_strings = mv88e6320_stats_get_strings,
3109 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003110 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3111 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003112 .watchdog_ops = &mv88e6390_watchdog_ops,
3113 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003114 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003115 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003116 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003117 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003118 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003119 .avb_ops = &mv88e6390_avb_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003120};
3121
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003122static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003123 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003124 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003125 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003126 .phy_read = mv88e6xxx_g2_smi_phy_read,
3127 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003128 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003129 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003130 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003131 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003132 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003133 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003134 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003135 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003136 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003137 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003138 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003139 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003140 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003141 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003142 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003143 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3144 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003145 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003146 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3147 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003148 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003149 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003150 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003151 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003152 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003153 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003154};
3155
3156static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003157 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003158 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003159 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003160 .phy_read = mv88e6xxx_g2_smi_phy_read,
3161 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003162 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003163 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003164 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003165 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003166 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003167 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003168 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003169 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003170 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003171 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003172 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003173 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003174 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003175 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003176 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003177 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3178 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003179 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003180 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3181 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003182 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003183 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003184 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003185 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003186 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003187 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003188 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003189};
3190
3191static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003192 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003193 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003194 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3195 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003196 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003197 .phy_read = mv88e6xxx_g2_smi_phy_read,
3198 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003199 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003200 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003201 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003202 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003203 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003204 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003205 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003206 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003207 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003208 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003209 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003210 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003211 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003212 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003213 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003214 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3215 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003216 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003217 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3218 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003219 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003220 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003221 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003222 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003223 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003224 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003225 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003226 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003227 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01003228 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
3229 .serdes_get_strings = mv88e6352_serdes_get_strings,
3230 .serdes_get_stats = mv88e6352_serdes_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003231};
3232
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003233static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003234 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003235 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003236 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3237 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003238 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3239 .phy_read = mv88e6xxx_g2_smi_phy_read,
3240 .phy_write = mv88e6xxx_g2_smi_phy_write,
3241 .port_set_link = mv88e6xxx_port_set_link,
3242 .port_set_duplex = mv88e6xxx_port_set_duplex,
3243 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3244 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003245 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003246 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003247 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003248 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003249 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003250 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003251 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003252 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003253 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003254 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003255 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003256 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003257 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3258 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003259 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003260 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3261 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003262 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003263 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003264 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003265 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003266 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3267 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003268 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003269 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003270 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003271};
3272
3273static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003274 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003275 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003276 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3277 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003278 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3279 .phy_read = mv88e6xxx_g2_smi_phy_read,
3280 .phy_write = mv88e6xxx_g2_smi_phy_write,
3281 .port_set_link = mv88e6xxx_port_set_link,
3282 .port_set_duplex = mv88e6xxx_port_set_duplex,
3283 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3284 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003285 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003286 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003287 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003288 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003289 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003290 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003291 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003292 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003293 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003294 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003295 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003296 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003297 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3298 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003299 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003300 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3301 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003302 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003303 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003304 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003305 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003306 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3307 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003308 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003309 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003310 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003311};
3312
Vivien Didelotf81ec902016-05-09 13:22:58 -04003313static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3314 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003315 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003316 .family = MV88E6XXX_FAMILY_6097,
3317 .name = "Marvell 88E6085",
3318 .num_databases = 4096,
3319 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003320 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003321 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003322 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003323 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003324 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003325 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003326 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003327 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003328 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003329 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003330 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003331 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003332 },
3333
3334 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003335 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003336 .family = MV88E6XXX_FAMILY_6095,
3337 .name = "Marvell 88E6095/88E6095F",
3338 .num_databases = 256,
3339 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003340 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003341 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003342 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003343 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003344 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003345 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003346 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003347 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003348 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003349 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003350 },
3351
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003352 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003353 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003354 .family = MV88E6XXX_FAMILY_6097,
3355 .name = "Marvell 88E6097/88E6097F",
3356 .num_databases = 4096,
3357 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003358 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003359 .port_base_addr = 0x10,
3360 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003361 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003362 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003363 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003364 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003365 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003366 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003367 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003368 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003369 .ops = &mv88e6097_ops,
3370 },
3371
Vivien Didelotf81ec902016-05-09 13:22:58 -04003372 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003373 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003374 .family = MV88E6XXX_FAMILY_6165,
3375 .name = "Marvell 88E6123",
3376 .num_databases = 4096,
3377 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003378 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003379 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003380 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003381 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003382 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003383 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003384 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003385 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003386 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003387 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003388 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003389 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003390 },
3391
3392 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003393 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003394 .family = MV88E6XXX_FAMILY_6185,
3395 .name = "Marvell 88E6131",
3396 .num_databases = 256,
3397 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003398 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003399 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003400 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003401 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003402 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003403 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003404 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003405 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003406 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003407 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003408 },
3409
Vivien Didelot990e27b2017-03-28 13:50:32 -04003410 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003411 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003412 .family = MV88E6XXX_FAMILY_6341,
3413 .name = "Marvell 88E6341",
3414 .num_databases = 4096,
3415 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003416 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003417 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003418 .port_base_addr = 0x10,
3419 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003420 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003421 .age_time_coeff = 3750,
3422 .atu_move_port_mask = 0x1f,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003423 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003424 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003425 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003426 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003427 .ops = &mv88e6141_ops,
3428 },
3429
Vivien Didelotf81ec902016-05-09 13:22:58 -04003430 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003431 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003432 .family = MV88E6XXX_FAMILY_6165,
3433 .name = "Marvell 88E6161",
3434 .num_databases = 4096,
3435 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003436 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003437 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003438 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003439 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003440 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003441 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003442 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003443 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003444 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003445 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003446 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003447 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003448 },
3449
3450 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003451 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003452 .family = MV88E6XXX_FAMILY_6165,
3453 .name = "Marvell 88E6165",
3454 .num_databases = 4096,
3455 .num_ports = 6,
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 Lunn443d5a12016-12-03 04:35:18 +01003466 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003467 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003468 },
3469
3470 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003471 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003472 .family = MV88E6XXX_FAMILY_6351,
3473 .name = "Marvell 88E6171",
3474 .num_databases = 4096,
3475 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003476 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003477 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003478 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003479 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003480 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003481 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003482 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003483 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003484 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003485 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003486 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003487 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003488 },
3489
3490 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003491 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003492 .family = MV88E6XXX_FAMILY_6352,
3493 .name = "Marvell 88E6172",
3494 .num_databases = 4096,
3495 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003496 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003497 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003498 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003499 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003500 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003501 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003502 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003503 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003504 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003505 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003506 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003507 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003508 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003509 },
3510
3511 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003512 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003513 .family = MV88E6XXX_FAMILY_6351,
3514 .name = "Marvell 88E6175",
3515 .num_databases = 4096,
3516 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003517 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003518 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003519 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003520 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003521 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003522 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003523 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003524 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003525 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003526 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003527 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003528 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003529 },
3530
3531 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003532 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003533 .family = MV88E6XXX_FAMILY_6352,
3534 .name = "Marvell 88E6176",
3535 .num_databases = 4096,
3536 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003537 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003538 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003539 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003540 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003541 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003542 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003543 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003544 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003545 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003546 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003547 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003548 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003549 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003550 },
3551
3552 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003553 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003554 .family = MV88E6XXX_FAMILY_6185,
3555 .name = "Marvell 88E6185",
3556 .num_databases = 256,
3557 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003558 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003559 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003560 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003561 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003562 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003563 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003564 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003565 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003566 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003567 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003568 },
3569
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003570 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003571 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003572 .family = MV88E6XXX_FAMILY_6390,
3573 .name = "Marvell 88E6190",
3574 .num_databases = 4096,
3575 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003576 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003577 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003578 .port_base_addr = 0x0,
3579 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003580 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003581 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003582 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003583 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003584 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003585 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003586 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003587 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003588 .ops = &mv88e6190_ops,
3589 },
3590
3591 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003592 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003593 .family = MV88E6XXX_FAMILY_6390,
3594 .name = "Marvell 88E6190X",
3595 .num_databases = 4096,
3596 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003597 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003598 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003599 .port_base_addr = 0x0,
3600 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003601 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003602 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003603 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003604 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003605 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003606 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003607 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003608 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003609 .ops = &mv88e6190x_ops,
3610 },
3611
3612 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003613 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003614 .family = MV88E6XXX_FAMILY_6390,
3615 .name = "Marvell 88E6191",
3616 .num_databases = 4096,
3617 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003618 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003619 .port_base_addr = 0x0,
3620 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003621 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003622 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003623 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003624 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003625 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003626 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003627 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003628 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003629 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003630 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003631 },
3632
Vivien Didelotf81ec902016-05-09 13:22:58 -04003633 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003634 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003635 .family = MV88E6XXX_FAMILY_6352,
3636 .name = "Marvell 88E6240",
3637 .num_databases = 4096,
3638 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003639 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003640 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003641 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003642 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003643 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003644 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003645 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003646 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003647 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003648 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003649 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003650 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003651 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003652 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003653 },
3654
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003655 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003656 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003657 .family = MV88E6XXX_FAMILY_6390,
3658 .name = "Marvell 88E6290",
3659 .num_databases = 4096,
3660 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003661 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003662 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003663 .port_base_addr = 0x0,
3664 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003665 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003666 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003667 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003668 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003669 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003670 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003671 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003672 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003673 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003674 .ops = &mv88e6290_ops,
3675 },
3676
Vivien Didelotf81ec902016-05-09 13:22:58 -04003677 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003678 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003679 .family = MV88E6XXX_FAMILY_6320,
3680 .name = "Marvell 88E6320",
3681 .num_databases = 4096,
3682 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003683 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003684 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003685 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003686 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003687 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003688 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003689 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003690 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003691 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003692 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003693 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003694 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003695 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003696 },
3697
3698 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003699 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003700 .family = MV88E6XXX_FAMILY_6320,
3701 .name = "Marvell 88E6321",
3702 .num_databases = 4096,
3703 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003704 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003705 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003706 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003707 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003708 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003709 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003710 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003711 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003712 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003713 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003714 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003715 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003716 },
3717
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003718 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003719 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003720 .family = MV88E6XXX_FAMILY_6341,
3721 .name = "Marvell 88E6341",
3722 .num_databases = 4096,
3723 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003724 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003725 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003726 .port_base_addr = 0x10,
3727 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003728 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003729 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003730 .atu_move_port_mask = 0x1f,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003731 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003732 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003733 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003734 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003735 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003736 .ops = &mv88e6341_ops,
3737 },
3738
Vivien Didelotf81ec902016-05-09 13:22:58 -04003739 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003740 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003741 .family = MV88E6XXX_FAMILY_6351,
3742 .name = "Marvell 88E6350",
3743 .num_databases = 4096,
3744 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003745 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003746 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003747 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003748 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003749 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003750 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003751 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003752 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003753 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003754 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003755 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003756 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003757 },
3758
3759 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003760 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003761 .family = MV88E6XXX_FAMILY_6351,
3762 .name = "Marvell 88E6351",
3763 .num_databases = 4096,
3764 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003765 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003766 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003767 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003768 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003769 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003770 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003771 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003772 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003773 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003774 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003775 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003776 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003777 },
3778
3779 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003780 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003781 .family = MV88E6XXX_FAMILY_6352,
3782 .name = "Marvell 88E6352",
3783 .num_databases = 4096,
3784 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003785 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003786 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003787 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003788 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003789 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003790 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003791 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003792 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003793 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003794 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003795 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003796 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003797 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003798 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003799 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003800 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003801 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003802 .family = MV88E6XXX_FAMILY_6390,
3803 .name = "Marvell 88E6390",
3804 .num_databases = 4096,
3805 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003806 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003807 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003808 .port_base_addr = 0x0,
3809 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003810 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003811 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003812 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003813 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003814 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003815 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003816 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003817 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003818 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003819 .ops = &mv88e6390_ops,
3820 },
3821 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003822 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003823 .family = MV88E6XXX_FAMILY_6390,
3824 .name = "Marvell 88E6390X",
3825 .num_databases = 4096,
3826 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003827 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003828 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003829 .port_base_addr = 0x0,
3830 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003831 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003832 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003833 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003834 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003835 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003836 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003837 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003838 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003839 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003840 .ops = &mv88e6390x_ops,
3841 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003842};
3843
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003844static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003845{
Vivien Didelota439c062016-04-17 13:23:58 -04003846 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003847
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003848 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3849 if (mv88e6xxx_table[i].prod_num == prod_num)
3850 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003851
Vivien Didelotb9b37712015-10-30 19:39:48 -04003852 return NULL;
3853}
3854
Vivien Didelotfad09c72016-06-21 12:28:20 -04003855static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003856{
3857 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003858 unsigned int prod_num, rev;
3859 u16 id;
3860 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003861
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003862 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04003863 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003864 mutex_unlock(&chip->reg_lock);
3865 if (err)
3866 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003867
Vivien Didelot107fcc12017-06-12 12:37:36 -04003868 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
3869 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003870
3871 info = mv88e6xxx_lookup_info(prod_num);
3872 if (!info)
3873 return -ENODEV;
3874
Vivien Didelotcaac8542016-06-20 13:14:09 -04003875 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003876 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003877
Vivien Didelotca070c12016-09-02 14:45:34 -04003878 err = mv88e6xxx_g2_require(chip);
3879 if (err)
3880 return err;
3881
Vivien Didelotfad09c72016-06-21 12:28:20 -04003882 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3883 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003884
3885 return 0;
3886}
3887
Vivien Didelotfad09c72016-06-21 12:28:20 -04003888static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003889{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003890 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003891
Vivien Didelotfad09c72016-06-21 12:28:20 -04003892 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3893 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003894 return NULL;
3895
Vivien Didelotfad09c72016-06-21 12:28:20 -04003896 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003897
Vivien Didelotfad09c72016-06-21 12:28:20 -04003898 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003899 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003900
Vivien Didelotfad09c72016-06-21 12:28:20 -04003901 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003902}
3903
Vivien Didelotfad09c72016-06-21 12:28:20 -04003904static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003905 struct mii_bus *bus, int sw_addr)
3906{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003907 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003908 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003909 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003910 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003911 else
3912 return -EINVAL;
3913
Vivien Didelotfad09c72016-06-21 12:28:20 -04003914 chip->bus = bus;
3915 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003916
3917 return 0;
3918}
3919
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08003920static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
3921 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02003922{
Vivien Didelot04bed142016-08-31 18:06:13 -04003923 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003924
Andrew Lunn443d5a12016-12-03 04:35:18 +01003925 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003926}
3927
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08003928#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003929static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3930 struct device *host_dev, int sw_addr,
3931 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003932{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003933 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003934 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003935 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003936
Vivien Didelota439c062016-04-17 13:23:58 -04003937 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003938 if (!bus)
3939 return NULL;
3940
Vivien Didelotfad09c72016-06-21 12:28:20 -04003941 chip = mv88e6xxx_alloc_chip(dsa_dev);
3942 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003943 return NULL;
3944
Vivien Didelotcaac8542016-06-20 13:14:09 -04003945 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003946 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003947
Vivien Didelotfad09c72016-06-21 12:28:20 -04003948 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003949 if (err)
3950 goto free;
3951
Vivien Didelotfad09c72016-06-21 12:28:20 -04003952 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003953 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003954 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003955
Andrew Lunndc30c352016-10-16 19:56:49 +02003956 mutex_lock(&chip->reg_lock);
3957 err = mv88e6xxx_switch_reset(chip);
3958 mutex_unlock(&chip->reg_lock);
3959 if (err)
3960 goto free;
3961
Vivien Didelote57e5e72016-08-15 17:19:00 -04003962 mv88e6xxx_phy_init(chip);
3963
Andrew Lunna3c53be52017-01-24 14:53:50 +01003964 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003965 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003966 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003967
Vivien Didelotfad09c72016-06-21 12:28:20 -04003968 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003969
Vivien Didelotfad09c72016-06-21 12:28:20 -04003970 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003971free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003972 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003973
3974 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003975}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08003976#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02003977
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003978static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05003979 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003980{
3981 /* We don't need any dynamic resource from the kernel (yet),
3982 * so skip the prepare phase.
3983 */
3984
3985 return 0;
3986}
3987
3988static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05003989 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003990{
Vivien Didelot04bed142016-08-31 18:06:13 -04003991 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003992
3993 mutex_lock(&chip->reg_lock);
3994 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003995 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04003996 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
3997 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003998 mutex_unlock(&chip->reg_lock);
3999}
4000
4001static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4002 const struct switchdev_obj_port_mdb *mdb)
4003{
Vivien Didelot04bed142016-08-31 18:06:13 -04004004 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004005 int err;
4006
4007 mutex_lock(&chip->reg_lock);
4008 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004009 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004010 mutex_unlock(&chip->reg_lock);
4011
4012 return err;
4013}
4014
Florian Fainellia82f67a2017-01-08 14:52:08 -08004015static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004016#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004017 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08004018#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02004019 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004020 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004021 .adjust_link = mv88e6xxx_adjust_link,
4022 .get_strings = mv88e6xxx_get_strings,
4023 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4024 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004025 .port_enable = mv88e6xxx_port_enable,
4026 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004027 .get_mac_eee = mv88e6xxx_get_mac_eee,
4028 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004029 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004030 .get_eeprom = mv88e6xxx_get_eeprom,
4031 .set_eeprom = mv88e6xxx_set_eeprom,
4032 .get_regs_len = mv88e6xxx_get_regs_len,
4033 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004034 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004035 .port_bridge_join = mv88e6xxx_port_bridge_join,
4036 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4037 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004038 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004039 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4040 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4041 .port_vlan_add = mv88e6xxx_port_vlan_add,
4042 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004043 .port_fdb_add = mv88e6xxx_port_fdb_add,
4044 .port_fdb_del = mv88e6xxx_port_fdb_del,
4045 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004046 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4047 .port_mdb_add = mv88e6xxx_port_mdb_add,
4048 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004049 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4050 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004051 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4052 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4053 .port_txtstamp = mv88e6xxx_port_txtstamp,
4054 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4055 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004056};
4057
Florian Fainelliab3d4082017-01-08 14:52:07 -08004058static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4059 .ops = &mv88e6xxx_switch_ops,
4060};
4061
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004062static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004063{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004064 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004065 struct dsa_switch *ds;
4066
Vivien Didelot73b12042017-03-30 17:37:10 -04004067 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004068 if (!ds)
4069 return -ENOMEM;
4070
Vivien Didelotfad09c72016-06-21 12:28:20 -04004071 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004072 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004073 ds->ageing_time_min = chip->info->age_time_coeff;
4074 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004075
4076 dev_set_drvdata(dev, ds);
4077
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004078 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004079}
4080
Vivien Didelotfad09c72016-06-21 12:28:20 -04004081static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004082{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004083 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004084}
4085
Vivien Didelot57d32312016-06-20 13:13:58 -04004086static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004087{
4088 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004089 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004090 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004091 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004092 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004093 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004094
Vivien Didelotcaac8542016-06-20 13:14:09 -04004095 compat_info = of_device_get_match_data(dev);
4096 if (!compat_info)
4097 return -EINVAL;
4098
Vivien Didelotfad09c72016-06-21 12:28:20 -04004099 chip = mv88e6xxx_alloc_chip(dev);
4100 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004101 return -ENOMEM;
4102
Vivien Didelotfad09c72016-06-21 12:28:20 -04004103 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004104
Vivien Didelotfad09c72016-06-21 12:28:20 -04004105 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004106 if (err)
4107 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004108
Andrew Lunnb4308f02016-11-21 23:26:55 +01004109 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4110 if (IS_ERR(chip->reset))
4111 return PTR_ERR(chip->reset);
4112
Vivien Didelotfad09c72016-06-21 12:28:20 -04004113 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004114 if (err)
4115 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004116
Vivien Didelote57e5e72016-08-15 17:19:00 -04004117 mv88e6xxx_phy_init(chip);
4118
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004119 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004120 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004121 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004122
Andrew Lunndc30c352016-10-16 19:56:49 +02004123 mutex_lock(&chip->reg_lock);
4124 err = mv88e6xxx_switch_reset(chip);
4125 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004126 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004127 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004128
Andrew Lunndc30c352016-10-16 19:56:49 +02004129 chip->irq = of_irq_get(np, 0);
4130 if (chip->irq == -EPROBE_DEFER) {
4131 err = chip->irq;
4132 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004133 }
4134
Andrew Lunn294d7112018-02-22 22:58:32 +01004135 /* Has to be performed before the MDIO bus is created, because
4136 * the PHYs will link there interrupts to these interrupt
4137 * controllers
4138 */
4139 mutex_lock(&chip->reg_lock);
4140 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004141 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004142 else
4143 err = mv88e6xxx_irq_poll_setup(chip);
4144 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004145
Andrew Lunn294d7112018-02-22 22:58:32 +01004146 if (err)
4147 goto out;
4148
4149 if (chip->info->g2_irqs > 0) {
4150 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004151 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004152 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004153 }
4154
Andrew Lunn294d7112018-02-22 22:58:32 +01004155 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4156 if (err)
4157 goto out_g2_irq;
4158
4159 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4160 if (err)
4161 goto out_g1_atu_prob_irq;
4162
Andrew Lunna3c53be52017-01-24 14:53:50 +01004163 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004164 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004165 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004166
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004167 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004168 if (err)
4169 goto out_mdio;
4170
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004171 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004172
4173out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004174 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004175out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004176 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004177out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004178 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004179out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004180 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004181 mv88e6xxx_g2_irq_free(chip);
4182out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004183 mutex_lock(&chip->reg_lock);
4184 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004185 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004186 else
4187 mv88e6xxx_irq_poll_free(chip);
4188 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004189out:
4190 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004191}
4192
4193static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4194{
4195 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004196 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004197
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004198 if (chip->info->ptp_support) {
4199 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004200 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004201 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004202
Andrew Lunn930188c2016-08-22 16:01:03 +02004203 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004204 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004205 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004206
Andrew Lunn467126442016-11-20 20:14:15 +01004207 if (chip->irq > 0) {
Andrew Lunn62eb1162018-01-14 02:32:45 +01004208 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004209 mv88e6xxx_g1_atu_prob_irq_free(chip);
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004210 if (chip->info->g2_irqs > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004211 mv88e6xxx_g2_irq_free(chip);
Vivien Didelotb32ca442017-09-26 14:57:21 -04004212 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004213 mv88e6xxx_g1_irq_free(chip);
Vivien Didelotb32ca442017-09-26 14:57:21 -04004214 mutex_unlock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004215 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004216}
4217
4218static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004219 {
4220 .compatible = "marvell,mv88e6085",
4221 .data = &mv88e6xxx_table[MV88E6085],
4222 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004223 {
4224 .compatible = "marvell,mv88e6190",
4225 .data = &mv88e6xxx_table[MV88E6190],
4226 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004227 { /* sentinel */ },
4228};
4229
4230MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4231
4232static struct mdio_driver mv88e6xxx_driver = {
4233 .probe = mv88e6xxx_probe,
4234 .remove = mv88e6xxx_remove,
4235 .mdiodrv.driver = {
4236 .name = "mv88e6085",
4237 .of_match_table = mv88e6xxx_of_match,
4238 },
4239};
4240
Ben Hutchings98e67302011-11-25 14:36:19 +00004241static int __init mv88e6xxx_init(void)
4242{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004243 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004244 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004245}
4246module_init(mv88e6xxx_init);
4247
4248static void __exit mv88e6xxx_cleanup(void)
4249{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004250 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004251 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004252}
4253module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004254
4255MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4256MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4257MODULE_LICENSE("GPL");