blob: 27ca0fcb1040d3a1db58ac67ebf55d7a9884aa23 [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{
363 mv88e6xxx_g1_irq_free(chip);
364
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 Lunn80c46272015-06-20 18:42:30 +0200669 if (s->sizeof_stat == 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 Lunn80c46272015-06-20 18:42:30 +0200682 if (s->sizeof_stat == 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 Lunndfafe442016-11-21 23:27:02 +0100692static void 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 }
706}
707
Andrew Lunndfafe442016-11-21 23:27:02 +0100708static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
709 uint8_t *data)
710{
711 mv88e6xxx_stats_get_strings(chip, data,
712 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
713}
714
715static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
716 uint8_t *data)
717{
718 mv88e6xxx_stats_get_strings(chip, data,
719 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
720}
721
722static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
723 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100724{
Vivien Didelot04bed142016-08-31 18:06:13 -0400725 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100726
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100727 mutex_lock(&chip->reg_lock);
728
Andrew Lunndfafe442016-11-21 23:27:02 +0100729 if (chip->info->ops->stats_get_strings)
730 chip->info->ops->stats_get_strings(chip, data);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100731
732 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100733}
734
735static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
736 int types)
737{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100738 struct mv88e6xxx_hw_stat *stat;
739 int i, j;
740
741 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
742 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100743 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100744 j++;
745 }
746 return j;
747}
748
Andrew Lunndfafe442016-11-21 23:27:02 +0100749static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
750{
751 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
752 STATS_TYPE_PORT);
753}
754
755static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
756{
757 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
758 STATS_TYPE_BANK1);
759}
760
Andrew Lunn88c06052018-03-01 02:02:27 +0100761static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port)
Andrew Lunndfafe442016-11-21 23:27:02 +0100762{
763 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100764 int ret = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100765
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100766 mutex_lock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100767 if (chip->info->ops->stats_get_sset_count)
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100768 ret = chip->info->ops->stats_get_sset_count(chip);
769 mutex_unlock(&chip->reg_lock);
Andrew Lunndfafe442016-11-21 23:27:02 +0100770
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100771 return ret;
Andrew Lunndfafe442016-11-21 23:27:02 +0100772}
773
Andrew Lunn052f9472016-11-21 23:27:03 +0100774static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100775 uint64_t *data, int types,
776 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100777{
778 struct mv88e6xxx_hw_stat *stat;
779 int i, j;
780
781 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
782 stat = &mv88e6xxx_hw_stats[i];
783 if (stat->type & types) {
Andrew Lunn377cda12018-02-15 14:38:34 +0100784 mutex_lock(&chip->reg_lock);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100785 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
786 bank1_select,
787 histogram);
Andrew Lunn377cda12018-02-15 14:38:34 +0100788 mutex_unlock(&chip->reg_lock);
789
Andrew Lunn052f9472016-11-21 23:27:03 +0100790 j++;
791 }
792 }
793}
794
795static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
796 uint64_t *data)
797{
798 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100799 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400800 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100801}
802
803static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
804 uint64_t *data)
805{
806 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100807 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400808 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
809 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100810}
811
812static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
813 uint64_t *data)
814{
815 return mv88e6xxx_stats_get_stats(chip, port, data,
816 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400817 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
818 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100819}
820
821static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
822 uint64_t *data)
823{
824 if (chip->info->ops->stats_get_stats)
825 chip->info->ops->stats_get_stats(chip, port, data);
826}
827
Vivien Didelotf81ec902016-05-09 13:22:58 -0400828static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
829 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000830{
Vivien Didelot04bed142016-08-31 18:06:13 -0400831 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000832 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000833
Vivien Didelotfad09c72016-06-21 12:28:20 -0400834 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000835
Andrew Lunna605a0f2016-11-21 23:26:58 +0100836 ret = mv88e6xxx_stats_snapshot(chip, port);
Andrew Lunn377cda12018-02-15 14:38:34 +0100837 mutex_unlock(&chip->reg_lock);
838
839 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000840 return;
Andrew Lunn052f9472016-11-21 23:27:03 +0100841
842 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000843
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000844}
Ben Hutchings98e67302011-11-25 14:36:19 +0000845
Andrew Lunnde2273872016-11-21 23:27:01 +0100846static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
847{
848 if (chip->info->ops->stats_set_histogram)
849 return chip->info->ops->stats_set_histogram(chip);
850
851 return 0;
852}
853
Vivien Didelotf81ec902016-05-09 13:22:58 -0400854static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700855{
856 return 32 * sizeof(u16);
857}
858
Vivien Didelotf81ec902016-05-09 13:22:58 -0400859static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
860 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700861{
Vivien Didelot04bed142016-08-31 18:06:13 -0400862 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200863 int err;
864 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700865 u16 *p = _p;
866 int i;
867
868 regs->version = 0;
869
870 memset(p, 0xff, 32 * sizeof(u16));
871
Vivien Didelotfad09c72016-06-21 12:28:20 -0400872 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -0400873
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700874 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700875
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200876 err = mv88e6xxx_port_read(chip, port, i, &reg);
877 if (!err)
878 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700879 }
Vivien Didelot23062512016-05-09 13:22:45 -0400880
Vivien Didelotfad09c72016-06-21 12:28:20 -0400881 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700882}
883
Vivien Didelot08f50062017-08-01 16:32:41 -0400884static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
885 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800886{
Vivien Didelot5480db62017-08-01 16:32:40 -0400887 /* Nothing to do on the port's MAC */
888 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800889}
890
Vivien Didelot08f50062017-08-01 16:32:41 -0400891static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
892 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -0800893{
Vivien Didelot5480db62017-08-01 16:32:40 -0400894 /* Nothing to do on the port's MAC */
895 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800896}
897
Vivien Didelote5887a22017-03-30 17:37:11 -0400898static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700899{
Vivien Didelote5887a22017-03-30 17:37:11 -0400900 struct dsa_switch *ds = NULL;
901 struct net_device *br;
902 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500903 int i;
904
Vivien Didelote5887a22017-03-30 17:37:11 -0400905 if (dev < DSA_MAX_SWITCHES)
906 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500907
Vivien Didelote5887a22017-03-30 17:37:11 -0400908 /* Prevent frames from unknown switch or port */
909 if (!ds || port >= ds->num_ports)
910 return 0;
911
912 /* Frames from DSA links and CPU ports can egress any local port */
913 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
914 return mv88e6xxx_port_mask(chip);
915
916 br = ds->ports[port].bridge_dev;
917 pvlan = 0;
918
919 /* Frames from user ports can egress any local DSA links and CPU ports,
920 * as well as any local member of their bridge group.
921 */
922 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
923 if (dsa_is_cpu_port(chip->ds, i) ||
924 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -0400925 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -0400926 pvlan |= BIT(i);
927
928 return pvlan;
929}
930
Vivien Didelot240ea3e2017-03-30 17:37:12 -0400931static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -0400932{
933 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -0500934
935 /* prevent frames from going back out of the port they came in on */
936 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700937
Vivien Didelot5a7921f2016-11-04 03:23:28 +0100938 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700939}
940
Vivien Didelotf81ec902016-05-09 13:22:58 -0400941static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
942 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700943{
Vivien Didelot04bed142016-08-31 18:06:13 -0400944 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -0400945 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700946
Vivien Didelotfad09c72016-06-21 12:28:20 -0400947 mutex_lock(&chip->reg_lock);
Vivien Didelotf894c292017-06-08 18:34:10 -0400948 err = mv88e6xxx_port_set_state(chip, port, state);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400949 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -0400950
951 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -0400952 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700953}
954
Vivien Didelot9e907d72017-07-17 13:03:43 -0400955static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
956{
957 if (chip->info->ops->pot_clear)
958 return chip->info->ops->pot_clear(chip);
959
960 return 0;
961}
962
Vivien Didelot51c901a2017-07-17 13:03:41 -0400963static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
964{
965 if (chip->info->ops->mgmt_rsvd2cpu)
966 return chip->info->ops->mgmt_rsvd2cpu(chip);
967
968 return 0;
969}
970
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500971static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
972{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500973 int err;
974
Vivien Didelotdaefc942017-03-11 16:12:54 -0500975 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
976 if (err)
977 return err;
978
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -0500979 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
980 if (err)
981 return err;
982
Vivien Didelota2ac29d2017-03-11 16:12:49 -0500983 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
984}
985
Vivien Didelotcd8da8b2017-06-19 10:55:36 -0400986static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
987{
988 int port;
989 int err;
990
991 if (!chip->info->ops->irl_init_all)
992 return 0;
993
994 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
995 /* Disable ingress rate limiting by resetting all per port
996 * ingress rate limit resources to their initial state.
997 */
998 err = chip->info->ops->irl_init_all(chip, port);
999 if (err)
1000 return err;
1001 }
1002
1003 return 0;
1004}
1005
Vivien Didelot04a69a12017-10-13 14:18:05 -04001006static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1007{
1008 if (chip->info->ops->set_switch_mac) {
1009 u8 addr[ETH_ALEN];
1010
1011 eth_random_addr(addr);
1012
1013 return chip->info->ops->set_switch_mac(chip, addr);
1014 }
1015
1016 return 0;
1017}
1018
Vivien Didelot17a15942017-03-30 17:37:09 -04001019static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1020{
1021 u16 pvlan = 0;
1022
1023 if (!mv88e6xxx_has_pvt(chip))
1024 return -EOPNOTSUPP;
1025
1026 /* Skip the local source device, which uses in-chip port VLAN */
1027 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001028 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001029
1030 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1031}
1032
Vivien Didelot81228992017-03-30 17:37:08 -04001033static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1034{
Vivien Didelot17a15942017-03-30 17:37:09 -04001035 int dev, port;
1036 int err;
1037
Vivien Didelot81228992017-03-30 17:37:08 -04001038 if (!mv88e6xxx_has_pvt(chip))
1039 return 0;
1040
1041 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1042 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1043 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001044 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1045 if (err)
1046 return err;
1047
1048 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1049 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1050 err = mv88e6xxx_pvt_map(chip, dev, port);
1051 if (err)
1052 return err;
1053 }
1054 }
1055
1056 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001057}
1058
Vivien Didelot749efcb2016-09-22 16:49:24 -04001059static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1060{
1061 struct mv88e6xxx_chip *chip = ds->priv;
1062 int err;
1063
1064 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001065 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001066 mutex_unlock(&chip->reg_lock);
1067
1068 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001069 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001070}
1071
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001072static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1073{
1074 if (!chip->info->max_vid)
1075 return 0;
1076
1077 return mv88e6xxx_g1_vtu_flush(chip);
1078}
1079
Vivien Didelotf1394b782017-05-01 14:05:22 -04001080static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1081 struct mv88e6xxx_vtu_entry *entry)
1082{
1083 if (!chip->info->ops->vtu_getnext)
1084 return -EOPNOTSUPP;
1085
1086 return chip->info->ops->vtu_getnext(chip, entry);
1087}
1088
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001089static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1090 struct mv88e6xxx_vtu_entry *entry)
1091{
1092 if (!chip->info->ops->vtu_loadpurge)
1093 return -EOPNOTSUPP;
1094
1095 return chip->info->ops->vtu_loadpurge(chip, entry);
1096}
1097
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001098static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001099{
1100 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001101 struct mv88e6xxx_vtu_entry vlan = {
1102 .vid = chip->info->max_vid,
1103 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001104 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001105
1106 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1107
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001108 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001109 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001110 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001111 if (err)
1112 return err;
1113
1114 set_bit(*fid, fid_bitmap);
1115 }
1116
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001117 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001118 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001119 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001120 if (err)
1121 return err;
1122
1123 if (!vlan.valid)
1124 break;
1125
1126 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001127 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001128
1129 /* The reset value 0x000 is used to indicate that multiple address
1130 * databases are not needed. Return the next positive available.
1131 */
1132 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001133 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001134 return -ENOSPC;
1135
1136 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001137 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001138}
1139
Vivien Didelot567aa592017-05-01 14:05:25 -04001140static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1141 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001142{
1143 int err;
1144
1145 if (!vid)
1146 return -EINVAL;
1147
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001148 entry->vid = vid - 1;
1149 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001150
Vivien Didelotf1394b782017-05-01 14:05:22 -04001151 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001152 if (err)
1153 return err;
1154
Vivien Didelot567aa592017-05-01 14:05:25 -04001155 if (entry->vid == vid && entry->valid)
1156 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001157
Vivien Didelot567aa592017-05-01 14:05:25 -04001158 if (new) {
1159 int i;
1160
1161 /* Initialize a fresh VLAN entry */
1162 memset(entry, 0, sizeof(*entry));
1163 entry->valid = true;
1164 entry->vid = vid;
1165
Vivien Didelot553a7682017-06-07 18:12:16 -04001166 /* Exclude all ports */
Vivien Didelot567aa592017-05-01 14:05:25 -04001167 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot553a7682017-06-07 18:12:16 -04001168 entry->member[i] =
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001169 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot567aa592017-05-01 14:05:25 -04001170
1171 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001172 }
1173
Vivien Didelot567aa592017-05-01 14:05:25 -04001174 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1175 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001176}
1177
Vivien Didelotda9c3592016-02-12 12:09:40 -05001178static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1179 u16 vid_begin, u16 vid_end)
1180{
Vivien Didelot04bed142016-08-31 18:06:13 -04001181 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001182 struct mv88e6xxx_vtu_entry vlan = {
1183 .vid = vid_begin - 1,
1184 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001185 int i, err;
1186
Andrew Lunndb06ae412017-09-25 23:32:20 +02001187 /* DSA and CPU ports have to be members of multiple vlans */
1188 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1189 return 0;
1190
Vivien Didelotda9c3592016-02-12 12:09:40 -05001191 if (!vid_begin)
1192 return -EOPNOTSUPP;
1193
Vivien Didelotfad09c72016-06-21 12:28:20 -04001194 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001195
Vivien Didelotda9c3592016-02-12 12:09:40 -05001196 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001197 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001198 if (err)
1199 goto unlock;
1200
1201 if (!vlan.valid)
1202 break;
1203
1204 if (vlan.vid > vid_end)
1205 break;
1206
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001207 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001208 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1209 continue;
1210
Andrew Lunncd886462017-11-09 22:29:53 +01001211 if (!ds->ports[i].slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001212 continue;
1213
Vivien Didelotbd00e052017-05-01 14:05:11 -04001214 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001215 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001216 continue;
1217
Vivien Didelotc8652c82017-10-16 11:12:19 -04001218 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelotfae8a252017-01-27 15:29:42 -05001219 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001220 break; /* same bridge, check next VLAN */
1221
Vivien Didelotc8652c82017-10-16 11:12:19 -04001222 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001223 continue;
1224
Andrew Lunn743fcc22017-11-09 22:29:54 +01001225 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1226 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001227 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001228 err = -EOPNOTSUPP;
1229 goto unlock;
1230 }
1231 } while (vlan.vid < vid_end);
1232
1233unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001234 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001235
1236 return err;
1237}
1238
Vivien Didelotf81ec902016-05-09 13:22:58 -04001239static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1240 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001241{
Vivien Didelot04bed142016-08-31 18:06:13 -04001242 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001243 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1244 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001245 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001246
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001247 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001248 return -EOPNOTSUPP;
1249
Vivien Didelotfad09c72016-06-21 12:28:20 -04001250 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001251 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001252 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001253
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001254 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001255}
1256
Vivien Didelot57d32312016-06-20 13:13:58 -04001257static int
1258mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001259 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001260{
Vivien Didelot04bed142016-08-31 18:06:13 -04001261 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001262 int err;
1263
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001264 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001265 return -EOPNOTSUPP;
1266
Vivien Didelotda9c3592016-02-12 12:09:40 -05001267 /* If the requested port doesn't belong to the same bridge as the VLAN
1268 * members, do not support it (yet) and fallback to software VLAN.
1269 */
1270 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1271 vlan->vid_end);
1272 if (err)
1273 return err;
1274
Vivien Didelot76e398a2015-11-01 12:33:55 -05001275 /* We don't need any dynamic resource from the kernel (yet),
1276 * so skip the prepare phase.
1277 */
1278 return 0;
1279}
1280
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001281static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1282 const unsigned char *addr, u16 vid,
1283 u8 state)
1284{
1285 struct mv88e6xxx_vtu_entry vlan;
1286 struct mv88e6xxx_atu_entry entry;
1287 int err;
1288
1289 /* Null VLAN ID corresponds to the port private database */
1290 if (vid == 0)
1291 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1292 else
1293 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1294 if (err)
1295 return err;
1296
1297 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1298 ether_addr_copy(entry.mac, addr);
1299 eth_addr_dec(entry.mac);
1300
1301 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1302 if (err)
1303 return err;
1304
1305 /* Initialize a fresh ATU entry if it isn't found */
1306 if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1307 !ether_addr_equal(entry.mac, addr)) {
1308 memset(&entry, 0, sizeof(entry));
1309 ether_addr_copy(entry.mac, addr);
1310 }
1311
1312 /* Purge the ATU entry only if no port is using it anymore */
1313 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1314 entry.portvec &= ~BIT(port);
1315 if (!entry.portvec)
1316 entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1317 } else {
1318 entry.portvec |= BIT(port);
1319 entry.state = state;
1320 }
1321
1322 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1323}
1324
Andrew Lunn87fa8862017-11-09 22:29:56 +01001325static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1326 u16 vid)
1327{
1328 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1329 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1330
1331 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1332}
1333
1334static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1335{
1336 int port;
1337 int err;
1338
1339 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1340 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1341 if (err)
1342 return err;
1343 }
1344
1345 return 0;
1346}
1347
Vivien Didelotfad09c72016-06-21 12:28:20 -04001348static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001349 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001350{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001351 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001352 int err;
1353
Vivien Didelot567aa592017-05-01 14:05:25 -04001354 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001355 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001356 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001357
Vivien Didelotc91498e2017-06-07 18:12:13 -04001358 vlan.member[port] = member;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001359
Andrew Lunn87fa8862017-11-09 22:29:56 +01001360 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1361 if (err)
1362 return err;
1363
1364 return mv88e6xxx_broadcast_setup(chip, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001365}
1366
Vivien Didelotf81ec902016-05-09 13:22:58 -04001367static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001368 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001369{
Vivien Didelot04bed142016-08-31 18:06:13 -04001370 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001371 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1372 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001373 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001374 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001375
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001376 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001377 return;
1378
Vivien Didelotc91498e2017-06-07 18:12:13 -04001379 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001380 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001381 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001382 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001383 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001384 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001385
Vivien Didelotfad09c72016-06-21 12:28:20 -04001386 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001387
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001388 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotc91498e2017-06-07 18:12:13 -04001389 if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001390 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1391 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001392
Vivien Didelot77064f32016-11-04 03:23:30 +01001393 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001394 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1395 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001396
Vivien Didelotfad09c72016-06-21 12:28:20 -04001397 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001398}
1399
Vivien Didelotfad09c72016-06-21 12:28:20 -04001400static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001401 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001402{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001403 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001404 int i, err;
1405
Vivien Didelot567aa592017-05-01 14:05:25 -04001406 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001407 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001408 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001409
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001410 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001411 if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001412 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001413
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001414 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001415
1416 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001417 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001418 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001419 if (vlan.member[i] !=
1420 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001421 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001422 break;
1423 }
1424 }
1425
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001426 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001427 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001428 return err;
1429
Vivien Didelote606ca32017-03-11 16:12:55 -05001430 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001431}
1432
Vivien Didelotf81ec902016-05-09 13:22:58 -04001433static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1434 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001435{
Vivien Didelot04bed142016-08-31 18:06:13 -04001436 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001437 u16 pvid, vid;
1438 int err = 0;
1439
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001440 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001441 return -EOPNOTSUPP;
1442
Vivien Didelotfad09c72016-06-21 12:28:20 -04001443 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001444
Vivien Didelot77064f32016-11-04 03:23:30 +01001445 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001446 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001447 goto unlock;
1448
Vivien Didelot76e398a2015-11-01 12:33:55 -05001449 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001450 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001451 if (err)
1452 goto unlock;
1453
1454 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001455 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001456 if (err)
1457 goto unlock;
1458 }
1459 }
1460
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001461unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001462 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001463
1464 return err;
1465}
1466
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001467static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1468 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001469{
Vivien Didelot04bed142016-08-31 18:06:13 -04001470 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001471 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001472
Vivien Didelotfad09c72016-06-21 12:28:20 -04001473 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001474 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1475 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001476 mutex_unlock(&chip->reg_lock);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001477
1478 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001479}
1480
Vivien Didelotf81ec902016-05-09 13:22:58 -04001481static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001482 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001483{
Vivien Didelot04bed142016-08-31 18:06:13 -04001484 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001485 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001486
Vivien Didelotfad09c72016-06-21 12:28:20 -04001487 mutex_lock(&chip->reg_lock);
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001488 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04001489 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001490 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001491
Vivien Didelot83dabd12016-08-31 11:50:04 -04001492 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001493}
1494
Vivien Didelot83dabd12016-08-31 11:50:04 -04001495static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1496 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001497 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001498{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001499 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001500 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001501 int err;
1502
Vivien Didelot27c0e602017-06-15 12:14:01 -04001503 addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001504 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001505
1506 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001507 mutex_lock(&chip->reg_lock);
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001508 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Andrew Lunna61e5402018-02-15 14:38:35 +01001509 mutex_unlock(&chip->reg_lock);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001510 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001511 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001512
Vivien Didelot27c0e602017-06-15 12:14:01 -04001513 if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001514 break;
1515
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001516 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001517 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001518
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001519 if (!is_unicast_ether_addr(addr.mac))
1520 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001521
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001522 is_static = (addr.state ==
1523 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1524 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001525 if (err)
1526 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001527 } while (!is_broadcast_ether_addr(addr.mac));
1528
1529 return err;
1530}
1531
Vivien Didelot83dabd12016-08-31 11:50:04 -04001532static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001533 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001534{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001535 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001536 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001537 };
1538 u16 fid;
1539 int err;
1540
1541 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Andrew Lunna61e5402018-02-15 14:38:35 +01001542 mutex_lock(&chip->reg_lock);
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001543 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Andrew Lunna61e5402018-02-15 14:38:35 +01001544 mutex_unlock(&chip->reg_lock);
1545
Vivien Didelot83dabd12016-08-31 11:50:04 -04001546 if (err)
1547 return err;
1548
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001549 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001550 if (err)
1551 return err;
1552
1553 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001554 do {
Andrew Lunna61e5402018-02-15 14:38:35 +01001555 mutex_lock(&chip->reg_lock);
Vivien Didelotf1394b782017-05-01 14:05:22 -04001556 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Andrew Lunna61e5402018-02-15 14:38:35 +01001557 mutex_unlock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001558 if (err)
1559 return err;
1560
1561 if (!vlan.valid)
1562 break;
1563
1564 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001565 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001566 if (err)
1567 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001568 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001569
1570 return err;
1571}
1572
Vivien Didelotf81ec902016-05-09 13:22:58 -04001573static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001574 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04001575{
Vivien Didelot04bed142016-08-31 18:06:13 -04001576 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001577
Andrew Lunna61e5402018-02-15 14:38:35 +01001578 return mv88e6xxx_port_db_dump(chip, port, cb, data);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001579}
1580
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001581static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1582 struct net_device *br)
1583{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001584 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001585 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001586 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001587 int err;
1588
1589 /* Remap the Port VLAN of each local bridge group member */
1590 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1591 if (chip->ds->ports[port].bridge_dev == br) {
1592 err = mv88e6xxx_port_vlan_map(chip, port);
1593 if (err)
1594 return err;
1595 }
1596 }
1597
Vivien Didelote96a6e02017-03-30 17:37:13 -04001598 if (!mv88e6xxx_has_pvt(chip))
1599 return 0;
1600
1601 /* Remap the Port VLAN of each cross-chip bridge group member */
1602 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1603 ds = chip->ds->dst->ds[dev];
1604 if (!ds)
1605 break;
1606
1607 for (port = 0; port < ds->num_ports; ++port) {
1608 if (ds->ports[port].bridge_dev == br) {
1609 err = mv88e6xxx_pvt_map(chip, dev, port);
1610 if (err)
1611 return err;
1612 }
1613 }
1614 }
1615
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001616 return 0;
1617}
1618
Vivien Didelotf81ec902016-05-09 13:22:58 -04001619static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001620 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001621{
Vivien Didelot04bed142016-08-31 18:06:13 -04001622 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001623 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001624
Vivien Didelotfad09c72016-06-21 12:28:20 -04001625 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001626 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001627 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001628
Vivien Didelot466dfa02016-02-26 13:16:05 -05001629 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001630}
1631
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001632static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1633 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001634{
Vivien Didelot04bed142016-08-31 18:06:13 -04001635 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001636
Vivien Didelotfad09c72016-06-21 12:28:20 -04001637 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001638 if (mv88e6xxx_bridge_map(chip, br) ||
1639 mv88e6xxx_port_vlan_map(chip, port))
1640 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001641 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001642}
1643
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001644static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1645 int port, struct net_device *br)
1646{
1647 struct mv88e6xxx_chip *chip = ds->priv;
1648 int err;
1649
1650 if (!mv88e6xxx_has_pvt(chip))
1651 return 0;
1652
1653 mutex_lock(&chip->reg_lock);
1654 err = mv88e6xxx_pvt_map(chip, dev, port);
1655 mutex_unlock(&chip->reg_lock);
1656
1657 return err;
1658}
1659
1660static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1661 int port, struct net_device *br)
1662{
1663 struct mv88e6xxx_chip *chip = ds->priv;
1664
1665 if (!mv88e6xxx_has_pvt(chip))
1666 return;
1667
1668 mutex_lock(&chip->reg_lock);
1669 if (mv88e6xxx_pvt_map(chip, dev, port))
1670 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1671 mutex_unlock(&chip->reg_lock);
1672}
1673
Vivien Didelot17e708b2016-12-05 17:30:27 -05001674static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1675{
1676 if (chip->info->ops->reset)
1677 return chip->info->ops->reset(chip);
1678
1679 return 0;
1680}
1681
Vivien Didelot309eca62016-12-05 17:30:26 -05001682static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1683{
1684 struct gpio_desc *gpiod = chip->reset;
1685
1686 /* If there is a GPIO connected to the reset pin, toggle it */
1687 if (gpiod) {
1688 gpiod_set_value_cansleep(gpiod, 1);
1689 usleep_range(10000, 20000);
1690 gpiod_set_value_cansleep(gpiod, 0);
1691 usleep_range(10000, 20000);
1692 }
1693}
1694
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001695static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1696{
1697 int i, err;
1698
1699 /* Set all ports to the Disabled state */
1700 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04001701 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001702 if (err)
1703 return err;
1704 }
1705
1706 /* Wait for transmit queues to drain,
1707 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1708 */
1709 usleep_range(2000, 4000);
1710
1711 return 0;
1712}
1713
Vivien Didelotfad09c72016-06-21 12:28:20 -04001714static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001715{
Vivien Didelota935c052016-09-29 12:21:53 -04001716 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001717
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001718 err = mv88e6xxx_disable_ports(chip);
1719 if (err)
1720 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001721
Vivien Didelot309eca62016-12-05 17:30:26 -05001722 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001723
Vivien Didelot17e708b2016-12-05 17:30:27 -05001724 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001725}
1726
Vivien Didelot43145572017-03-11 16:12:59 -05001727static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001728 enum mv88e6xxx_frame_mode frame,
1729 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001730{
1731 int err;
1732
Vivien Didelot43145572017-03-11 16:12:59 -05001733 if (!chip->info->ops->port_set_frame_mode)
1734 return -EOPNOTSUPP;
1735
1736 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001737 if (err)
1738 return err;
1739
Vivien Didelot43145572017-03-11 16:12:59 -05001740 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1741 if (err)
1742 return err;
1743
1744 if (chip->info->ops->port_set_ether_type)
1745 return chip->info->ops->port_set_ether_type(chip, port, etype);
1746
1747 return 0;
1748}
1749
1750static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1751{
1752 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001753 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001754 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001755}
1756
1757static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
1758{
1759 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001760 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04001761 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05001762}
1763
1764static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
1765{
1766 return mv88e6xxx_set_port_mode(chip, port,
1767 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04001768 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
1769 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05001770}
1771
1772static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
1773{
1774 if (dsa_is_dsa_port(chip->ds, port))
1775 return mv88e6xxx_set_port_mode_dsa(chip, port);
1776
Vivien Didelot2b3e9892017-10-26 11:22:54 -04001777 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05001778 return mv88e6xxx_set_port_mode_normal(chip, port);
1779
1780 /* Setup CPU port mode depending on its supported tag format */
1781 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
1782 return mv88e6xxx_set_port_mode_dsa(chip, port);
1783
1784 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
1785 return mv88e6xxx_set_port_mode_edsa(chip, port);
1786
1787 return -EINVAL;
1788}
1789
Vivien Didelotea698f42017-03-11 16:12:50 -05001790static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1791{
1792 bool message = dsa_is_dsa_port(chip->ds, port);
1793
1794 return mv88e6xxx_port_set_message_port(chip, port, message);
1795}
1796
Vivien Didelot601aeed2017-03-11 16:13:00 -05001797static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1798{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001799 struct dsa_switch *ds = chip->ds;
1800 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05001801
1802 /* Upstream ports flood frames with unknown unicast or multicast DA */
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05001803 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vivien Didelot601aeed2017-03-11 16:13:00 -05001804 if (chip->info->ops->port_set_egress_floods)
1805 return chip->info->ops->port_set_egress_floods(chip, port,
1806 flood, flood);
1807
1808 return 0;
1809}
1810
Andrew Lunn6d917822017-05-26 01:03:21 +02001811static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
1812 bool on)
1813{
Vivien Didelot523a8902017-05-26 18:02:42 -04001814 if (chip->info->ops->serdes_power)
1815 return chip->info->ops->serdes_power(chip, port, on);
Andrew Lunn6d917822017-05-26 01:03:21 +02001816
Vivien Didelot523a8902017-05-26 18:02:42 -04001817 return 0;
Andrew Lunn6d917822017-05-26 01:03:21 +02001818}
1819
Vivien Didelotfa371c82017-12-05 15:34:10 -05001820static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
1821{
1822 struct dsa_switch *ds = chip->ds;
1823 int upstream_port;
1824 int err;
1825
Vivien Didelot07073c72017-12-05 15:34:13 -05001826 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05001827 if (chip->info->ops->port_set_upstream_port) {
1828 err = chip->info->ops->port_set_upstream_port(chip, port,
1829 upstream_port);
1830 if (err)
1831 return err;
1832 }
1833
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05001834 if (port == upstream_port) {
1835 if (chip->info->ops->set_cpu_port) {
1836 err = chip->info->ops->set_cpu_port(chip,
1837 upstream_port);
1838 if (err)
1839 return err;
1840 }
1841
1842 if (chip->info->ops->set_egress_port) {
1843 err = chip->info->ops->set_egress_port(chip,
1844 upstream_port);
1845 if (err)
1846 return err;
1847 }
1848 }
1849
Vivien Didelotfa371c82017-12-05 15:34:10 -05001850 return 0;
1851}
1852
Vivien Didelotfad09c72016-06-21 12:28:20 -04001853static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001854{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001855 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001856 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001857 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001858
Vivien Didelotd78343d2016-11-04 03:23:36 +01001859 /* MAC Forcing register: don't force link, speed, duplex or flow control
1860 * state to any particular values on physical ports, but force the CPU
1861 * port and all DSA ports to their maximum bandwidth and full duplex.
1862 */
1863 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1864 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
1865 SPEED_MAX, DUPLEX_FULL,
1866 PHY_INTERFACE_MODE_NA);
1867 else
1868 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
1869 SPEED_UNFORCED, DUPLEX_UNFORCED,
1870 PHY_INTERFACE_MODE_NA);
1871 if (err)
1872 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001873
1874 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1875 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1876 * tunneling, determine priority by looking at 802.1p and IP
1877 * priority fields (IP prio has precedence), and set STP state
1878 * to Forwarding.
1879 *
1880 * If this is the CPU link, use DSA or EDSA tagging depending
1881 * on which tagging mode was configured.
1882 *
1883 * If this is a link to another switch, use DSA tagging mode.
1884 *
1885 * If this is the upstream port for this switch, enable
1886 * forwarding of unknown unicasts and multicasts.
1887 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04001888 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
1889 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
1890 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1891 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001892 if (err)
1893 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02001894
Vivien Didelot601aeed2017-03-11 16:13:00 -05001895 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001896 if (err)
1897 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001898
Vivien Didelot601aeed2017-03-11 16:13:00 -05001899 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05001900 if (err)
1901 return err;
1902
Andrew Lunn04aca992017-05-26 01:03:24 +02001903 /* Enable the SERDES interface for DSA and CPU ports. Normal
1904 * ports SERDES are enabled when the port is enabled, thus
1905 * saving a bit of power.
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001906 */
Andrew Lunn04aca992017-05-26 01:03:24 +02001907 if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
1908 err = mv88e6xxx_serdes_power(chip, port, true);
1909 if (err)
1910 return err;
1911 }
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001912
Vivien Didelot8efdda42015-08-13 12:52:23 -04001913 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05001914 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04001915 * untagged frames on this port, do a destination address lookup on all
1916 * received packets as usual, disable ARP mirroring and don't send a
1917 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02001918 */
Andrew Lunna23b2962017-02-04 20:15:28 +01001919 err = mv88e6xxx_port_set_map_da(chip, port);
1920 if (err)
1921 return err;
1922
Vivien Didelotfa371c82017-12-05 15:34:10 -05001923 err = mv88e6xxx_setup_upstream_port(chip, port);
1924 if (err)
1925 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001926
Andrew Lunna23b2962017-02-04 20:15:28 +01001927 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001928 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01001929 if (err)
1930 return err;
1931
Vivien Didelotcd782652017-06-08 18:34:13 -04001932 if (chip->info->ops->port_set_jumbo_size) {
1933 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01001934 if (err)
1935 return err;
1936 }
1937
Andrew Lunn54d792f2015-05-06 01:09:47 +02001938 /* Port Association Vector: when learning source addresses
1939 * of packets, add the address to the address database using
1940 * a port bitmap that has only the bit for this port set and
1941 * the other bits clear.
1942 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001943 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04001944 /* Disable learning for CPU port */
1945 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04001946 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05001947
Vivien Didelot2a4614e2017-06-12 12:37:43 -04001948 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
1949 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001950 if (err)
1951 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001952
1953 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04001954 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
1955 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001956 if (err)
1957 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001958
Vivien Didelot08984322017-06-08 18:34:12 -04001959 if (chip->info->ops->port_pause_limit) {
1960 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01001961 if (err)
1962 return err;
1963 }
1964
Vivien Didelotc8c94892017-03-11 16:13:01 -05001965 if (chip->info->ops->port_disable_learn_limit) {
1966 err = chip->info->ops->port_disable_learn_limit(chip, port);
1967 if (err)
1968 return err;
1969 }
1970
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05001971 if (chip->info->ops->port_disable_pri_override) {
1972 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001973 if (err)
1974 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01001975 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02001976
Andrew Lunnef0a7312016-12-03 04:35:16 +01001977 if (chip->info->ops->port_tag_remap) {
1978 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001979 if (err)
1980 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001981 }
1982
Andrew Lunnef70b112016-12-03 04:45:18 +01001983 if (chip->info->ops->port_egress_rate_limiting) {
1984 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001985 if (err)
1986 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001987 }
1988
Vivien Didelotea698f42017-03-11 16:12:50 -05001989 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001990 if (err)
1991 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07001992
Vivien Didelot207afda2016-04-14 14:42:09 -04001993 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001994 * database, and allow bidirectional communication between the
1995 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07001996 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001997 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001998 if (err)
1999 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002000
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002001 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002002 if (err)
2003 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002004
2005 /* Default VLAN ID and priority: don't set a default VLAN
2006 * ID, and set the default packet priority to zero.
2007 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002008 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002009}
2010
Andrew Lunn04aca992017-05-26 01:03:24 +02002011static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2012 struct phy_device *phydev)
2013{
2014 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002015 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002016
2017 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002018 err = mv88e6xxx_serdes_power(chip, port, true);
Andrew Lunn04aca992017-05-26 01:03:24 +02002019 mutex_unlock(&chip->reg_lock);
2020
2021 return err;
2022}
2023
2024static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2025 struct phy_device *phydev)
2026{
2027 struct mv88e6xxx_chip *chip = ds->priv;
2028
2029 mutex_lock(&chip->reg_lock);
Vivien Didelot523a8902017-05-26 18:02:42 -04002030 if (mv88e6xxx_serdes_power(chip, port, false))
2031 dev_err(chip->dev, "failed to power off SERDES\n");
Andrew Lunn04aca992017-05-26 01:03:24 +02002032 mutex_unlock(&chip->reg_lock);
2033}
2034
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002035static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2036 unsigned int ageing_time)
2037{
Vivien Didelot04bed142016-08-31 18:06:13 -04002038 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002039 int err;
2040
2041 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002042 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002043 mutex_unlock(&chip->reg_lock);
2044
2045 return err;
2046}
2047
Vivien Didelot97299342016-07-18 20:45:30 -04002048static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002049{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002050 struct dsa_switch *ds = chip->ds;
Vivien Didelot08a01262016-05-09 13:22:50 -04002051 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002052
Vivien Didelot50484ff2016-05-09 13:22:54 -04002053 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelotd77f4322017-06-15 12:14:03 -04002054 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2055 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
Vivien Didelota935c052016-09-29 12:21:53 -04002056 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002057 if (err)
2058 return err;
2059
Vivien Didelot08a01262016-05-09 13:22:50 -04002060 /* Configure the IP ToS mapping registers. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002061 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002062 if (err)
2063 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002064 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002065 if (err)
2066 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002067 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002068 if (err)
2069 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002070 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002071 if (err)
2072 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002073 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002074 if (err)
2075 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002076 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002077 if (err)
2078 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002079 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002080 if (err)
2081 return err;
Vivien Didelotccba8f32017-06-15 12:14:06 -04002082 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002083 if (err)
2084 return err;
2085
2086 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelotccba8f32017-06-15 12:14:06 -04002087 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002088 if (err)
2089 return err;
2090
Andrew Lunnde2273872016-11-21 23:27:01 +01002091 /* Initialize the statistics unit */
2092 err = mv88e6xxx_stats_set_histogram(chip);
2093 if (err)
2094 return err;
2095
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002096 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002097}
2098
Vivien Didelotf81ec902016-05-09 13:22:58 -04002099static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002100{
Vivien Didelot04bed142016-08-31 18:06:13 -04002101 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002102 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002103 int i;
2104
Vivien Didelotfad09c72016-06-21 12:28:20 -04002105 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002106 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002107
Vivien Didelotfad09c72016-06-21 12:28:20 -04002108 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002109
Vivien Didelot97299342016-07-18 20:45:30 -04002110 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002111 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot91dee142017-10-26 11:22:52 -04002112 if (dsa_is_unused_port(ds, i))
2113 continue;
2114
Vivien Didelot97299342016-07-18 20:45:30 -04002115 err = mv88e6xxx_setup_port(chip, i);
2116 if (err)
2117 goto unlock;
2118 }
2119
2120 /* Setup Switch Global 1 Registers */
2121 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002122 if (err)
2123 goto unlock;
2124
Vivien Didelot97299342016-07-18 20:45:30 -04002125 /* Setup Switch Global 2 Registers */
Vivien Didelot9069c132017-07-17 13:03:44 -04002126 if (chip->info->global2_addr) {
Vivien Didelot97299342016-07-18 20:45:30 -04002127 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002128 if (err)
2129 goto unlock;
2130 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002131
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002132 err = mv88e6xxx_irl_setup(chip);
2133 if (err)
2134 goto unlock;
2135
Vivien Didelot04a69a12017-10-13 14:18:05 -04002136 err = mv88e6xxx_mac_setup(chip);
2137 if (err)
2138 goto unlock;
2139
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002140 err = mv88e6xxx_phy_setup(chip);
2141 if (err)
2142 goto unlock;
2143
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002144 err = mv88e6xxx_vtu_setup(chip);
2145 if (err)
2146 goto unlock;
2147
Vivien Didelot81228992017-03-30 17:37:08 -04002148 err = mv88e6xxx_pvt_setup(chip);
2149 if (err)
2150 goto unlock;
2151
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002152 err = mv88e6xxx_atu_setup(chip);
2153 if (err)
2154 goto unlock;
2155
Andrew Lunn87fa8862017-11-09 22:29:56 +01002156 err = mv88e6xxx_broadcast_setup(chip, 0);
2157 if (err)
2158 goto unlock;
2159
Vivien Didelot9e907d72017-07-17 13:03:43 -04002160 err = mv88e6xxx_pot_setup(chip);
2161 if (err)
2162 goto unlock;
2163
Vivien Didelot51c901a2017-07-17 13:03:41 -04002164 err = mv88e6xxx_rsvd2cpu_setup(chip);
2165 if (err)
2166 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002167
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002168 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002169 if (chip->info->ptp_support) {
2170 err = mv88e6xxx_ptp_setup(chip);
2171 if (err)
2172 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002173
2174 err = mv88e6xxx_hwtstamp_setup(chip);
2175 if (err)
2176 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002177 }
2178
Vivien Didelot6b17e862015-08-13 12:52:18 -04002179unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002180 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002181
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002182 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002183}
2184
Vivien Didelote57e5e72016-08-15 17:19:00 -04002185static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002186{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002187 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2188 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002189 u16 val;
2190 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002191
Andrew Lunnee26a222017-01-24 14:53:48 +01002192 if (!chip->info->ops->phy_read)
2193 return -EOPNOTSUPP;
2194
Vivien Didelotfad09c72016-06-21 12:28:20 -04002195 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002196 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002197 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002198
Andrew Lunnda9f3302017-02-01 03:40:05 +01002199 if (reg == MII_PHYSID2) {
2200 /* Some internal PHYS don't have a model number. Use
2201 * the mv88e6390 family model number instead.
2202 */
2203 if (!(val & 0x3f0))
Vivien Didelot107fcc12017-06-12 12:37:36 -04002204 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002205 }
2206
Vivien Didelote57e5e72016-08-15 17:19:00 -04002207 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002208}
2209
Vivien Didelote57e5e72016-08-15 17:19:00 -04002210static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002211{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002212 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2213 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002214 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002215
Andrew Lunnee26a222017-01-24 14:53:48 +01002216 if (!chip->info->ops->phy_write)
2217 return -EOPNOTSUPP;
2218
Vivien Didelotfad09c72016-06-21 12:28:20 -04002219 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002220 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002221 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002222
2223 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002224}
2225
Vivien Didelotfad09c72016-06-21 12:28:20 -04002226static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002227 struct device_node *np,
2228 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002229{
2230 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002231 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002232 struct mii_bus *bus;
2233 int err;
2234
Andrew Lunn2510bab2018-02-22 01:51:49 +01002235 if (external) {
2236 mutex_lock(&chip->reg_lock);
2237 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2238 mutex_unlock(&chip->reg_lock);
2239
2240 if (err)
2241 return err;
2242 }
2243
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002244 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002245 if (!bus)
2246 return -ENOMEM;
2247
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002248 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002249 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002250 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002251 INIT_LIST_HEAD(&mdio_bus->list);
2252 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002253
Andrew Lunnb516d452016-06-04 21:17:06 +02002254 if (np) {
2255 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002256 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002257 } else {
2258 bus->name = "mv88e6xxx SMI";
2259 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2260 }
2261
2262 bus->read = mv88e6xxx_mdio_read;
2263 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002264 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002265
Andrew Lunna3c53be52017-01-24 14:53:50 +01002266 if (np)
2267 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002268 else
2269 err = mdiobus_register(bus);
2270 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002271 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002272 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002273 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002274
2275 if (external)
2276 list_add_tail(&mdio_bus->list, &chip->mdios);
2277 else
2278 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002279
2280 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002281}
2282
Andrew Lunna3c53be52017-01-24 14:53:50 +01002283static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2284 { .compatible = "marvell,mv88e6xxx-mdio-external",
2285 .data = (void *)true },
2286 { },
2287};
2288
Andrew Lunn3126aee2017-12-07 01:05:57 +01002289static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2290
2291{
2292 struct mv88e6xxx_mdio_bus *mdio_bus;
2293 struct mii_bus *bus;
2294
2295 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2296 bus = mdio_bus->bus;
2297
2298 mdiobus_unregister(bus);
2299 }
2300}
2301
Andrew Lunna3c53be52017-01-24 14:53:50 +01002302static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2303 struct device_node *np)
2304{
2305 const struct of_device_id *match;
2306 struct device_node *child;
2307 int err;
2308
2309 /* Always register one mdio bus for the internal/default mdio
2310 * bus. This maybe represented in the device tree, but is
2311 * optional.
2312 */
2313 child = of_get_child_by_name(np, "mdio");
2314 err = mv88e6xxx_mdio_register(chip, child, false);
2315 if (err)
2316 return err;
2317
2318 /* Walk the device tree, and see if there are any other nodes
2319 * which say they are compatible with the external mdio
2320 * bus.
2321 */
2322 for_each_available_child_of_node(np, child) {
2323 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2324 if (match) {
2325 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002326 if (err) {
2327 mv88e6xxx_mdios_unregister(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002328 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002329 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002330 }
2331 }
2332
2333 return 0;
2334}
2335
Vivien Didelot855b1932016-07-20 18:18:35 -04002336static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2337{
Vivien Didelot04bed142016-08-31 18:06:13 -04002338 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002339
2340 return chip->eeprom_len;
2341}
2342
Vivien Didelot855b1932016-07-20 18:18:35 -04002343static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2344 struct ethtool_eeprom *eeprom, u8 *data)
2345{
Vivien Didelot04bed142016-08-31 18:06:13 -04002346 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002347 int err;
2348
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002349 if (!chip->info->ops->get_eeprom)
2350 return -EOPNOTSUPP;
2351
Vivien Didelot855b1932016-07-20 18:18:35 -04002352 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002353 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002354 mutex_unlock(&chip->reg_lock);
2355
2356 if (err)
2357 return err;
2358
2359 eeprom->magic = 0xc3ec4951;
2360
2361 return 0;
2362}
2363
Vivien Didelot855b1932016-07-20 18:18:35 -04002364static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2365 struct ethtool_eeprom *eeprom, u8 *data)
2366{
Vivien Didelot04bed142016-08-31 18:06:13 -04002367 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002368 int err;
2369
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002370 if (!chip->info->ops->set_eeprom)
2371 return -EOPNOTSUPP;
2372
Vivien Didelot855b1932016-07-20 18:18:35 -04002373 if (eeprom->magic != 0xc3ec4951)
2374 return -EINVAL;
2375
2376 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002377 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002378 mutex_unlock(&chip->reg_lock);
2379
2380 return err;
2381}
2382
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002383static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002384 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002385 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002386 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002387 .phy_read = mv88e6185_phy_ppu_read,
2388 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002389 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002390 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002391 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002392 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002393 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002394 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002395 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002396 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002397 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002398 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002399 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002400 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002401 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002402 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2403 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002404 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002405 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2406 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002407 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002408 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002409 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002410 .ppu_enable = mv88e6185_g1_ppu_enable,
2411 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002412 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002413 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002414 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002415};
2416
2417static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002418 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002419 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002420 .phy_read = mv88e6185_phy_ppu_read,
2421 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002422 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002423 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002424 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002425 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002426 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002427 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
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 Didelot51c901a2017-07-17 13:03:41 -04002433 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002434 .ppu_enable = mv88e6185_g1_ppu_enable,
2435 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002436 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002437 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002438 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002439};
2440
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002441static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002442 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002443 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002444 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2445 .phy_read = mv88e6xxx_g2_smi_phy_read,
2446 .phy_write = mv88e6xxx_g2_smi_phy_write,
2447 .port_set_link = mv88e6xxx_port_set_link,
2448 .port_set_duplex = mv88e6xxx_port_set_duplex,
2449 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002450 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002451 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002452 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002453 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002454 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002455 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002456 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002457 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002458 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002459 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002460 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002461 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2462 .stats_get_strings = mv88e6095_stats_get_strings,
2463 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002464 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2465 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002466 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002467 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002468 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002469 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002470 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002471 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002472};
2473
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002474static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002475 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002476 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002477 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002478 .phy_read = mv88e6xxx_g2_smi_phy_read,
2479 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002480 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002481 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002482 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002483 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002484 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
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,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002487 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002488 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002489 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2490 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002491 .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,
Andrew Lunnfcd25162017-02-09 00:03:42 +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,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002500};
2501
2502static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002503 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002504 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002505 .phy_read = mv88e6185_phy_ppu_read,
2506 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002507 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002508 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002509 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002510 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002511 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002512 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002513 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002514 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04002515 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002516 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002517 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002518 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002519 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002520 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2521 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002522 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002523 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2524 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002525 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002526 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002527 .ppu_enable = mv88e6185_g1_ppu_enable,
2528 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002529 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002530 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002531 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002532};
2533
Vivien Didelot990e27b2017-03-28 13:50:32 -04002534static const struct mv88e6xxx_ops mv88e6141_ops = {
2535 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002536 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002537 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2538 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2539 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2540 .phy_read = mv88e6xxx_g2_smi_phy_read,
2541 .phy_write = mv88e6xxx_g2_smi_phy_write,
2542 .port_set_link = mv88e6xxx_port_set_link,
2543 .port_set_duplex = mv88e6xxx_port_set_duplex,
2544 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2545 .port_set_speed = mv88e6390_port_set_speed,
2546 .port_tag_remap = mv88e6095_port_tag_remap,
2547 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2548 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2549 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002550 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002551 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002552 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002553 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2554 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2555 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002556 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002557 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2558 .stats_get_strings = mv88e6320_stats_get_strings,
2559 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002560 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2561 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002562 .watchdog_ops = &mv88e6390_watchdog_ops,
2563 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002564 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002565 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002566 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002567 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002568 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002569};
2570
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002571static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002572 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002573 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002574 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02002575 .phy_read = mv88e6xxx_g2_smi_phy_read,
2576 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002577 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002578 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002579 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002580 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002581 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002582 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002583 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002584 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002585 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002586 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002587 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002588 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02002589 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002590 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002591 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2592 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002593 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002594 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2595 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002596 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002597 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002598 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002599 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002600 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002601 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002602};
2603
2604static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002605 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002606 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002607 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002608 .phy_read = mv88e6165_phy_read,
2609 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002610 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002611 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002612 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002613 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002614 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002615 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002616 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002617 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2618 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002619 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002620 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2621 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002622 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002623 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002624 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002625 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002626 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002627 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002628};
2629
2630static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002631 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002632 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002633 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002634 .phy_read = mv88e6xxx_g2_smi_phy_read,
2635 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002636 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002637 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002638 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002639 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002640 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002641 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002642 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002643 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002644 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002645 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002646 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002647 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002648 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002649 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002650 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002651 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2652 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002653 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002654 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2655 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002656 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002657 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002658 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002659 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002660 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002661 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002662};
2663
2664static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002665 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002666 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002667 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2668 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002669 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002670 .phy_read = mv88e6xxx_g2_smi_phy_read,
2671 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002672 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002673 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002674 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002675 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002676 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002677 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002678 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002679 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002680 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002681 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002682 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002683 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002684 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002685 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002686 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002687 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2688 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002689 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002690 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2691 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002692 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002693 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002694 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002695 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002696 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002697 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002698 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002699 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002700};
2701
2702static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002703 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002704 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002705 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002706 .phy_read = mv88e6xxx_g2_smi_phy_read,
2707 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002708 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002709 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002710 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002711 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002712 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002713 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002714 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002715 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002716 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002717 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002718 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002719 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002720 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002721 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002722 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002723 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2724 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002725 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002726 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2727 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002728 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002729 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002730 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002731 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002732 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002733 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002734};
2735
2736static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002737 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002738 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002739 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2740 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002741 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002742 .phy_read = mv88e6xxx_g2_smi_phy_read,
2743 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002744 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002745 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002746 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002747 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002748 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002749 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002750 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002751 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002752 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002753 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002754 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002755 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002756 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002757 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002758 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002759 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2760 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002761 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002762 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2763 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002764 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002765 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002766 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002767 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002768 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002769 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002770 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002771 .gpio_ops = &mv88e6352_gpio_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002772};
2773
2774static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002775 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002776 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002777 .phy_read = mv88e6185_phy_ppu_read,
2778 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002779 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002780 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002781 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002782 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002783 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002784 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002785 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002786 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002787 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002788 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2789 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002790 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002791 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2792 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002793 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002794 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002795 .ppu_enable = mv88e6185_g1_ppu_enable,
2796 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002797 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002798 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002799 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002800};
2801
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002802static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002803 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002804 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002805 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2806 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002807 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2808 .phy_read = mv88e6xxx_g2_smi_phy_read,
2809 .phy_write = mv88e6xxx_g2_smi_phy_write,
2810 .port_set_link = mv88e6xxx_port_set_link,
2811 .port_set_duplex = mv88e6xxx_port_set_duplex,
2812 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2813 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002814 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002815 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002816 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002817 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002818 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002819 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002820 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002821 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002822 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002823 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2824 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002825 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002826 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2827 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002828 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002829 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002830 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002831 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002832 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2833 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002834 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002835 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002836};
2837
2838static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002839 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002840 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002841 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2842 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002843 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2844 .phy_read = mv88e6xxx_g2_smi_phy_read,
2845 .phy_write = mv88e6xxx_g2_smi_phy_write,
2846 .port_set_link = mv88e6xxx_port_set_link,
2847 .port_set_duplex = mv88e6xxx_port_set_duplex,
2848 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2849 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002850 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002851 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002852 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002853 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002854 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002855 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002856 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002857 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002858 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002859 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2860 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002861 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002862 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2863 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002864 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002865 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002866 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002867 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002868 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2869 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002870 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002871 .gpio_ops = &mv88e6352_gpio_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002872};
2873
2874static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002875 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002876 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002877 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2878 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002879 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2880 .phy_read = mv88e6xxx_g2_smi_phy_read,
2881 .phy_write = mv88e6xxx_g2_smi_phy_write,
2882 .port_set_link = mv88e6xxx_port_set_link,
2883 .port_set_duplex = mv88e6xxx_port_set_duplex,
2884 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2885 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002886 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002887 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002888 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002889 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002890 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002891 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002892 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002893 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002894 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002895 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2896 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002897 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002898 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2899 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002900 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002901 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002902 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002903 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002904 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2905 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002906 .serdes_power = mv88e6390_serdes_power,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002907};
2908
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002909static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002910 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002911 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002912 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2913 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002914 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002915 .phy_read = mv88e6xxx_g2_smi_phy_read,
2916 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002917 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002918 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002919 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002920 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002921 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002922 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002923 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002924 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04002925 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01002926 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002927 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002928 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002929 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002930 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002931 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002932 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2933 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002934 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002935 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2936 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002937 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04002938 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002939 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002940 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002941 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002942 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02002943 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002944 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01002945 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002946};
2947
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002948static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002949 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002950 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002951 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2952 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002953 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2954 .phy_read = mv88e6xxx_g2_smi_phy_read,
2955 .phy_write = mv88e6xxx_g2_smi_phy_write,
2956 .port_set_link = mv88e6xxx_port_set_link,
2957 .port_set_duplex = mv88e6xxx_port_set_duplex,
2958 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2959 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002960 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002961 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002962 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002963 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04002964 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01002965 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002966 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002967 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002968 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002969 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002970 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2971 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002972 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002973 .set_cpu_port = mv88e6390_g1_set_cpu_port,
2974 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01002975 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002976 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04002977 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002978 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04002979 .vtu_getnext = mv88e6390_g1_vtu_getnext,
2980 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02002981 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01002982 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01002983 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002984};
2985
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002986static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002987 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002988 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002989 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2990 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002991 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002992 .phy_read = mv88e6xxx_g2_smi_phy_read,
2993 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002994 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002995 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002996 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002997 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002998 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002999 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003000 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003001 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003002 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003003 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003004 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003005 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003006 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003007 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003008 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3009 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003010 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003011 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3012 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003013 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003014 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003015 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003016 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003017 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003018 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003019 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003020};
3021
3022static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003023 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003024 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003025 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3026 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003027 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003028 .phy_read = mv88e6xxx_g2_smi_phy_read,
3029 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003030 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003031 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003032 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003033 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003034 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003035 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003036 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003037 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003038 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003039 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003040 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003041 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003042 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003043 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003044 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3045 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003046 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003047 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3048 .set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003049 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003050 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003051 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003052 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003053 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003054};
3055
Vivien Didelot16e329a2017-03-28 13:50:33 -04003056static const struct mv88e6xxx_ops mv88e6341_ops = {
3057 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003058 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003059 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3060 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3061 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3062 .phy_read = mv88e6xxx_g2_smi_phy_read,
3063 .phy_write = mv88e6xxx_g2_smi_phy_write,
3064 .port_set_link = mv88e6xxx_port_set_link,
3065 .port_set_duplex = mv88e6xxx_port_set_duplex,
3066 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3067 .port_set_speed = mv88e6390_port_set_speed,
3068 .port_tag_remap = mv88e6095_port_tag_remap,
3069 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3070 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3071 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003072 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003073 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003074 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003075 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3076 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3077 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003078 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003079 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3080 .stats_get_strings = mv88e6320_stats_get_strings,
3081 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003082 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3083 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003084 .watchdog_ops = &mv88e6390_watchdog_ops,
3085 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003086 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003087 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003088 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003089 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003090 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003091 .avb_ops = &mv88e6390_avb_ops,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003092};
3093
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003094static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003095 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003096 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003097 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003098 .phy_read = mv88e6xxx_g2_smi_phy_read,
3099 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003100 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003101 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003102 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003103 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003104 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003105 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003106 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003107 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003108 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003109 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003110 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003111 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003112 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003113 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003114 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003115 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3116 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003117 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003118 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3119 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003120 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003121 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003122 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003123 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003124 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003125 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003126};
3127
3128static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003129 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003130 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003131 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003132 .phy_read = mv88e6xxx_g2_smi_phy_read,
3133 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003134 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003135 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003136 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003137 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003138 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003139 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003140 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003141 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003142 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003143 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003144 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003145 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003146 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003147 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003148 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003149 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3150 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003151 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003152 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3153 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003154 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003155 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003156 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003157 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003158 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003159 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003160 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003161};
3162
3163static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003164 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003165 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003166 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3167 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003168 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003169 .phy_read = mv88e6xxx_g2_smi_phy_read,
3170 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003171 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003172 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003173 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003174 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003175 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003176 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003177 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003178 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003179 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003180 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003181 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003182 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003183 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003184 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003185 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003186 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3187 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003188 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003189 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3190 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003191 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003192 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003193 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003194 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003195 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003196 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunn6d917822017-05-26 01:03:21 +02003197 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003198 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003199 .avb_ops = &mv88e6352_avb_ops,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003200};
3201
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003202static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003203 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003204 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003205 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3206 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003207 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3208 .phy_read = mv88e6xxx_g2_smi_phy_read,
3209 .phy_write = mv88e6xxx_g2_smi_phy_write,
3210 .port_set_link = mv88e6xxx_port_set_link,
3211 .port_set_duplex = mv88e6xxx_port_set_duplex,
3212 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3213 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003214 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003215 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003216 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003217 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003218 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003219 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003220 .port_pause_limit = mv88e6390_port_pause_limit,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003221 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003222 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003223 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003224 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003225 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003226 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3227 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003228 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003229 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3230 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003231 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003232 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003233 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003234 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003235 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3236 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003237 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003238 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003239 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003240};
3241
3242static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003243 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003244 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003245 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3246 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003247 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3248 .phy_read = mv88e6xxx_g2_smi_phy_read,
3249 .phy_write = mv88e6xxx_g2_smi_phy_write,
3250 .port_set_link = mv88e6xxx_port_set_link,
3251 .port_set_duplex = mv88e6xxx_port_set_duplex,
3252 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3253 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003254 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003255 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003256 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003257 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003258 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003259 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003260 .port_pause_limit = mv88e6390_port_pause_limit,
Martin Hundebøllbb0a2672017-07-19 08:17:02 +02003261 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003262 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003263 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003264 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003265 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003266 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3267 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003268 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003269 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3270 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003271 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003272 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003273 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003274 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003275 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3276 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003277 .serdes_power = mv88e6390_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003278 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003279 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003280};
3281
Vivien Didelotf81ec902016-05-09 13:22:58 -04003282static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3283 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003284 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003285 .family = MV88E6XXX_FAMILY_6097,
3286 .name = "Marvell 88E6085",
3287 .num_databases = 4096,
3288 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003289 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003290 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003291 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003292 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003293 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003294 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003295 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003296 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003297 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003298 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003299 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003300 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003301 },
3302
3303 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003304 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003305 .family = MV88E6XXX_FAMILY_6095,
3306 .name = "Marvell 88E6095/88E6095F",
3307 .num_databases = 256,
3308 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003309 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003310 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003311 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003312 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003313 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003314 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003315 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003316 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003317 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003318 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003319 },
3320
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003321 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003322 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003323 .family = MV88E6XXX_FAMILY_6097,
3324 .name = "Marvell 88E6097/88E6097F",
3325 .num_databases = 4096,
3326 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003327 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003328 .port_base_addr = 0x10,
3329 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003330 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003331 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003332 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003333 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003334 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003335 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003336 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003337 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003338 .ops = &mv88e6097_ops,
3339 },
3340
Vivien Didelotf81ec902016-05-09 13:22:58 -04003341 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003342 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003343 .family = MV88E6XXX_FAMILY_6165,
3344 .name = "Marvell 88E6123",
3345 .num_databases = 4096,
3346 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003347 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003348 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003349 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003350 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003351 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003352 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003353 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003354 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003355 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003356 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003357 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003358 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003359 },
3360
3361 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003362 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003363 .family = MV88E6XXX_FAMILY_6185,
3364 .name = "Marvell 88E6131",
3365 .num_databases = 256,
3366 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003367 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003368 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003369 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003370 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003371 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003372 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003373 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003374 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003375 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003376 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003377 },
3378
Vivien Didelot990e27b2017-03-28 13:50:32 -04003379 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003380 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003381 .family = MV88E6XXX_FAMILY_6341,
3382 .name = "Marvell 88E6341",
3383 .num_databases = 4096,
3384 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003385 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003386 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003387 .port_base_addr = 0x10,
3388 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003389 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003390 .age_time_coeff = 3750,
3391 .atu_move_port_mask = 0x1f,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003392 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003393 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003394 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003395 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003396 .ops = &mv88e6141_ops,
3397 },
3398
Vivien Didelotf81ec902016-05-09 13:22:58 -04003399 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003400 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003401 .family = MV88E6XXX_FAMILY_6165,
3402 .name = "Marvell 88E6161",
3403 .num_databases = 4096,
3404 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003405 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003406 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003407 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003408 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003409 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003410 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003411 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003412 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003413 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003414 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02003415 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003416 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003417 },
3418
3419 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003420 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003421 .family = MV88E6XXX_FAMILY_6165,
3422 .name = "Marvell 88E6165",
3423 .num_databases = 4096,
3424 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003425 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003426 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003427 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003428 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003429 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003430 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003431 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003432 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003433 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003434 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003435 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003436 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003437 },
3438
3439 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003440 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003441 .family = MV88E6XXX_FAMILY_6351,
3442 .name = "Marvell 88E6171",
3443 .num_databases = 4096,
3444 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003445 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003446 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003447 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003448 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003449 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003450 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003451 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003452 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003453 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003454 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003455 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003456 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003457 },
3458
3459 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003460 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003461 .family = MV88E6XXX_FAMILY_6352,
3462 .name = "Marvell 88E6172",
3463 .num_databases = 4096,
3464 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003465 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003466 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003467 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003468 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003469 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003470 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003471 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003472 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003473 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003474 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003475 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003476 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003477 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003478 },
3479
3480 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003481 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003482 .family = MV88E6XXX_FAMILY_6351,
3483 .name = "Marvell 88E6175",
3484 .num_databases = 4096,
3485 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003486 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003487 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003488 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003489 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003490 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003491 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003492 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003493 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003494 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003495 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003496 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003497 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003498 },
3499
3500 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003501 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003502 .family = MV88E6XXX_FAMILY_6352,
3503 .name = "Marvell 88E6176",
3504 .num_databases = 4096,
3505 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003506 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003507 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003508 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003509 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003510 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003511 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003512 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003513 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003514 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003515 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003516 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003517 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003518 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003519 },
3520
3521 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003522 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003523 .family = MV88E6XXX_FAMILY_6185,
3524 .name = "Marvell 88E6185",
3525 .num_databases = 256,
3526 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003527 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003528 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003529 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003530 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003531 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003532 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003533 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003534 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003535 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003536 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003537 },
3538
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003539 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003540 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003541 .family = MV88E6XXX_FAMILY_6390,
3542 .name = "Marvell 88E6190",
3543 .num_databases = 4096,
3544 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003545 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003546 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003547 .port_base_addr = 0x0,
3548 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003549 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003550 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003551 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003552 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003553 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04003554 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003555 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003556 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003557 .ops = &mv88e6190_ops,
3558 },
3559
3560 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003561 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003562 .family = MV88E6XXX_FAMILY_6390,
3563 .name = "Marvell 88E6190X",
3564 .num_databases = 4096,
3565 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003566 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003567 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003568 .port_base_addr = 0x0,
3569 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003570 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003571 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003572 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003573 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003574 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003575 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003576 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003577 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003578 .ops = &mv88e6190x_ops,
3579 },
3580
3581 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003582 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003583 .family = MV88E6XXX_FAMILY_6390,
3584 .name = "Marvell 88E6191",
3585 .num_databases = 4096,
3586 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003587 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003588 .port_base_addr = 0x0,
3589 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003590 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003591 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003592 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003593 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003594 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003595 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003596 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003597 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003598 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003599 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003600 },
3601
Vivien Didelotf81ec902016-05-09 13:22:58 -04003602 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003603 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003604 .family = MV88E6XXX_FAMILY_6352,
3605 .name = "Marvell 88E6240",
3606 .num_databases = 4096,
3607 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003608 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003609 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003610 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003611 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003612 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003613 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003614 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003615 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003616 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003617 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003618 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003619 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003620 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003621 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003622 },
3623
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003624 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003625 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003626 .family = MV88E6XXX_FAMILY_6390,
3627 .name = "Marvell 88E6290",
3628 .num_databases = 4096,
3629 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003630 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003631 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003632 .port_base_addr = 0x0,
3633 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003634 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003635 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003636 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003637 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003638 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003639 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003640 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003641 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003642 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003643 .ops = &mv88e6290_ops,
3644 },
3645
Vivien Didelotf81ec902016-05-09 13:22:58 -04003646 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003647 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003648 .family = MV88E6XXX_FAMILY_6320,
3649 .name = "Marvell 88E6320",
3650 .num_databases = 4096,
3651 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003652 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003653 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003654 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003655 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003656 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003657 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003658 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003659 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003660 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003661 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003662 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003663 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003664 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003665 },
3666
3667 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003668 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003669 .family = MV88E6XXX_FAMILY_6320,
3670 .name = "Marvell 88E6321",
3671 .num_databases = 4096,
3672 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003673 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003674 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003675 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003676 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003677 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003678 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003679 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003680 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003681 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003682 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003683 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003684 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003685 },
3686
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003687 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003688 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003689 .family = MV88E6XXX_FAMILY_6341,
3690 .name = "Marvell 88E6341",
3691 .num_databases = 4096,
3692 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003693 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003694 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003695 .port_base_addr = 0x10,
3696 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003697 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003698 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003699 .atu_move_port_mask = 0x1f,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003700 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04003701 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003702 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003703 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003704 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003705 .ops = &mv88e6341_ops,
3706 },
3707
Vivien Didelotf81ec902016-05-09 13:22:58 -04003708 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003709 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003710 .family = MV88E6XXX_FAMILY_6351,
3711 .name = "Marvell 88E6350",
3712 .num_databases = 4096,
3713 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003714 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003715 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003716 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003717 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003718 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003719 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003720 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003721 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003722 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003723 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003724 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003725 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003726 },
3727
3728 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003729 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003730 .family = MV88E6XXX_FAMILY_6351,
3731 .name = "Marvell 88E6351",
3732 .num_databases = 4096,
3733 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003734 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003735 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003736 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003737 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003738 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003739 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003740 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003741 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003742 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003743 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003744 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003745 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003746 },
3747
3748 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003749 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003750 .family = MV88E6XXX_FAMILY_6352,
3751 .name = "Marvell 88E6352",
3752 .num_databases = 4096,
3753 .num_ports = 7,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003754 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003755 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003756 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003757 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003758 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003759 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003760 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003761 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05003762 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003763 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003764 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003765 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003766 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003767 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003768 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003769 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003770 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003771 .family = MV88E6XXX_FAMILY_6390,
3772 .name = "Marvell 88E6390",
3773 .num_databases = 4096,
3774 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003775 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003776 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003777 .port_base_addr = 0x0,
3778 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003779 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003780 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003781 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003782 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003783 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003784 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003785 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003786 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003787 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003788 .ops = &mv88e6390_ops,
3789 },
3790 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04003791 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003792 .family = MV88E6XXX_FAMILY_6390,
3793 .name = "Marvell 88E6390X",
3794 .num_databases = 4096,
3795 .num_ports = 11, /* 10 + Z80 */
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003796 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04003797 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003798 .port_base_addr = 0x0,
3799 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04003800 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003801 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003802 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04003803 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05003804 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003805 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003806 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003807 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003808 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003809 .ops = &mv88e6390x_ops,
3810 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003811};
3812
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003813static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003814{
Vivien Didelota439c062016-04-17 13:23:58 -04003815 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003816
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003817 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3818 if (mv88e6xxx_table[i].prod_num == prod_num)
3819 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003820
Vivien Didelotb9b37712015-10-30 19:39:48 -04003821 return NULL;
3822}
3823
Vivien Didelotfad09c72016-06-21 12:28:20 -04003824static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003825{
3826 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003827 unsigned int prod_num, rev;
3828 u16 id;
3829 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003830
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003831 mutex_lock(&chip->reg_lock);
Vivien Didelot107fcc12017-06-12 12:37:36 -04003832 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003833 mutex_unlock(&chip->reg_lock);
3834 if (err)
3835 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003836
Vivien Didelot107fcc12017-06-12 12:37:36 -04003837 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
3838 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003839
3840 info = mv88e6xxx_lookup_info(prod_num);
3841 if (!info)
3842 return -ENODEV;
3843
Vivien Didelotcaac8542016-06-20 13:14:09 -04003844 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003845 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003846
Vivien Didelotca070c12016-09-02 14:45:34 -04003847 err = mv88e6xxx_g2_require(chip);
3848 if (err)
3849 return err;
3850
Vivien Didelotfad09c72016-06-21 12:28:20 -04003851 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3852 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003853
3854 return 0;
3855}
3856
Vivien Didelotfad09c72016-06-21 12:28:20 -04003857static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003858{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003859 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003860
Vivien Didelotfad09c72016-06-21 12:28:20 -04003861 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3862 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003863 return NULL;
3864
Vivien Didelotfad09c72016-06-21 12:28:20 -04003865 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003866
Vivien Didelotfad09c72016-06-21 12:28:20 -04003867 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003868 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003869
Vivien Didelotfad09c72016-06-21 12:28:20 -04003870 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003871}
3872
Vivien Didelotfad09c72016-06-21 12:28:20 -04003873static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003874 struct mii_bus *bus, int sw_addr)
3875{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003876 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003877 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04003878 else if (chip->info->multi_chip)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003879 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003880 else
3881 return -EINVAL;
3882
Vivien Didelotfad09c72016-06-21 12:28:20 -04003883 chip->bus = bus;
3884 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003885
3886 return 0;
3887}
3888
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08003889static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
3890 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02003891{
Vivien Didelot04bed142016-08-31 18:06:13 -04003892 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003893
Andrew Lunn443d5a12016-12-03 04:35:18 +01003894 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003895}
3896
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08003897#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003898static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3899 struct device *host_dev, int sw_addr,
3900 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003901{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003902 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003903 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003904 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003905
Vivien Didelota439c062016-04-17 13:23:58 -04003906 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003907 if (!bus)
3908 return NULL;
3909
Vivien Didelotfad09c72016-06-21 12:28:20 -04003910 chip = mv88e6xxx_alloc_chip(dsa_dev);
3911 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003912 return NULL;
3913
Vivien Didelotcaac8542016-06-20 13:14:09 -04003914 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003915 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003916
Vivien Didelotfad09c72016-06-21 12:28:20 -04003917 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003918 if (err)
3919 goto free;
3920
Vivien Didelotfad09c72016-06-21 12:28:20 -04003921 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003922 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003923 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003924
Andrew Lunndc30c352016-10-16 19:56:49 +02003925 mutex_lock(&chip->reg_lock);
3926 err = mv88e6xxx_switch_reset(chip);
3927 mutex_unlock(&chip->reg_lock);
3928 if (err)
3929 goto free;
3930
Vivien Didelote57e5e72016-08-15 17:19:00 -04003931 mv88e6xxx_phy_init(chip);
3932
Andrew Lunna3c53be52017-01-24 14:53:50 +01003933 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003934 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003935 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003936
Vivien Didelotfad09c72016-06-21 12:28:20 -04003937 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003938
Vivien Didelotfad09c72016-06-21 12:28:20 -04003939 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003940free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003941 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003942
3943 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003944}
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08003945#endif
Andrew Lunna77d43f2016-04-13 02:40:42 +02003946
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003947static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05003948 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003949{
3950 /* We don't need any dynamic resource from the kernel (yet),
3951 * so skip the prepare phase.
3952 */
3953
3954 return 0;
3955}
3956
3957static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05003958 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003959{
Vivien Didelot04bed142016-08-31 18:06:13 -04003960 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003961
3962 mutex_lock(&chip->reg_lock);
3963 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003964 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04003965 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
3966 port);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003967 mutex_unlock(&chip->reg_lock);
3968}
3969
3970static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3971 const struct switchdev_obj_port_mdb *mdb)
3972{
Vivien Didelot04bed142016-08-31 18:06:13 -04003973 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003974 int err;
3975
3976 mutex_lock(&chip->reg_lock);
3977 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04003978 MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003979 mutex_unlock(&chip->reg_lock);
3980
3981 return err;
3982}
3983
Florian Fainellia82f67a2017-01-08 14:52:08 -08003984static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08003985#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003986 .probe = mv88e6xxx_drv_probe,
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08003987#endif
Andrew Lunn7b314362016-08-22 16:01:01 +02003988 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003989 .setup = mv88e6xxx_setup,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003990 .adjust_link = mv88e6xxx_adjust_link,
3991 .get_strings = mv88e6xxx_get_strings,
3992 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3993 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02003994 .port_enable = mv88e6xxx_port_enable,
3995 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04003996 .get_mac_eee = mv88e6xxx_get_mac_eee,
3997 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003998 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003999 .get_eeprom = mv88e6xxx_get_eeprom,
4000 .set_eeprom = mv88e6xxx_set_eeprom,
4001 .get_regs_len = mv88e6xxx_get_regs_len,
4002 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004003 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004004 .port_bridge_join = mv88e6xxx_port_bridge_join,
4005 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4006 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004007 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004008 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4009 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4010 .port_vlan_add = mv88e6xxx_port_vlan_add,
4011 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004012 .port_fdb_add = mv88e6xxx_port_fdb_add,
4013 .port_fdb_del = mv88e6xxx_port_fdb_del,
4014 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004015 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4016 .port_mdb_add = mv88e6xxx_port_mdb_add,
4017 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004018 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4019 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004020 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4021 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4022 .port_txtstamp = mv88e6xxx_port_txtstamp,
4023 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4024 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004025};
4026
Florian Fainelliab3d4082017-01-08 14:52:07 -08004027static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4028 .ops = &mv88e6xxx_switch_ops,
4029};
4030
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004031static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004032{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004033 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004034 struct dsa_switch *ds;
4035
Vivien Didelot73b12042017-03-30 17:37:10 -04004036 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004037 if (!ds)
4038 return -ENOMEM;
4039
Vivien Didelotfad09c72016-06-21 12:28:20 -04004040 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004041 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004042 ds->ageing_time_min = chip->info->age_time_coeff;
4043 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004044
4045 dev_set_drvdata(dev, ds);
4046
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004047 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004048}
4049
Vivien Didelotfad09c72016-06-21 12:28:20 -04004050static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004051{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004052 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004053}
4054
Vivien Didelot57d32312016-06-20 13:13:58 -04004055static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004056{
4057 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004058 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004059 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004060 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004061 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004062 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004063
Vivien Didelotcaac8542016-06-20 13:14:09 -04004064 compat_info = of_device_get_match_data(dev);
4065 if (!compat_info)
4066 return -EINVAL;
4067
Vivien Didelotfad09c72016-06-21 12:28:20 -04004068 chip = mv88e6xxx_alloc_chip(dev);
4069 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004070 return -ENOMEM;
4071
Vivien Didelotfad09c72016-06-21 12:28:20 -04004072 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004073
Vivien Didelotfad09c72016-06-21 12:28:20 -04004074 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004075 if (err)
4076 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004077
Andrew Lunnb4308f02016-11-21 23:26:55 +01004078 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4079 if (IS_ERR(chip->reset))
4080 return PTR_ERR(chip->reset);
4081
Vivien Didelotfad09c72016-06-21 12:28:20 -04004082 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004083 if (err)
4084 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004085
Vivien Didelote57e5e72016-08-15 17:19:00 -04004086 mv88e6xxx_phy_init(chip);
4087
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004088 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004089 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004090 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004091
Andrew Lunndc30c352016-10-16 19:56:49 +02004092 mutex_lock(&chip->reg_lock);
4093 err = mv88e6xxx_switch_reset(chip);
4094 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004095 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004096 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004097
Andrew Lunndc30c352016-10-16 19:56:49 +02004098 chip->irq = of_irq_get(np, 0);
4099 if (chip->irq == -EPROBE_DEFER) {
4100 err = chip->irq;
4101 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004102 }
4103
Andrew Lunn294d7112018-02-22 22:58:32 +01004104 /* Has to be performed before the MDIO bus is created, because
4105 * the PHYs will link there interrupts to these interrupt
4106 * controllers
4107 */
4108 mutex_lock(&chip->reg_lock);
4109 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004110 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004111 else
4112 err = mv88e6xxx_irq_poll_setup(chip);
4113 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004114
Andrew Lunn294d7112018-02-22 22:58:32 +01004115 if (err)
4116 goto out;
4117
4118 if (chip->info->g2_irqs > 0) {
4119 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004120 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01004121 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004122 }
4123
Andrew Lunn294d7112018-02-22 22:58:32 +01004124 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4125 if (err)
4126 goto out_g2_irq;
4127
4128 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4129 if (err)
4130 goto out_g1_atu_prob_irq;
4131
Andrew Lunna3c53be52017-01-24 14:53:50 +01004132 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004133 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01004134 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02004135
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004136 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004137 if (err)
4138 goto out_mdio;
4139
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004140 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004141
4142out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004143 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01004144out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004145 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004146out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004147 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004148out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004149 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004150 mv88e6xxx_g2_irq_free(chip);
4151out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01004152 mutex_lock(&chip->reg_lock);
4153 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004154 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01004155 else
4156 mv88e6xxx_irq_poll_free(chip);
4157 mutex_unlock(&chip->reg_lock);
Andrew Lunndc30c352016-10-16 19:56:49 +02004158out:
4159 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004160}
4161
4162static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4163{
4164 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004165 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004166
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004167 if (chip->info->ptp_support) {
4168 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004169 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004170 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004171
Andrew Lunn930188c2016-08-22 16:01:03 +02004172 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004173 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004174 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004175
Andrew Lunn467126442016-11-20 20:14:15 +01004176 if (chip->irq > 0) {
Andrew Lunn62eb1162018-01-14 02:32:45 +01004177 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01004178 mv88e6xxx_g1_atu_prob_irq_free(chip);
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004179 if (chip->info->g2_irqs > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01004180 mv88e6xxx_g2_irq_free(chip);
Vivien Didelotb32ca442017-09-26 14:57:21 -04004181 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004182 mv88e6xxx_g1_irq_free(chip);
Vivien Didelotb32ca442017-09-26 14:57:21 -04004183 mutex_unlock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004184 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004185}
4186
4187static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004188 {
4189 .compatible = "marvell,mv88e6085",
4190 .data = &mv88e6xxx_table[MV88E6085],
4191 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004192 {
4193 .compatible = "marvell,mv88e6190",
4194 .data = &mv88e6xxx_table[MV88E6190],
4195 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004196 { /* sentinel */ },
4197};
4198
4199MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4200
4201static struct mdio_driver mv88e6xxx_driver = {
4202 .probe = mv88e6xxx_probe,
4203 .remove = mv88e6xxx_remove,
4204 .mdiodrv.driver = {
4205 .name = "mv88e6085",
4206 .of_match_table = mv88e6xxx_of_match,
4207 },
4208};
4209
Ben Hutchings98e67302011-11-25 14:36:19 +00004210static int __init mv88e6xxx_init(void)
4211{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004212 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004213 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004214}
4215module_init(mv88e6xxx_init);
4216
4217static void __exit mv88e6xxx_cleanup(void)
4218{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004219 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004220 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004221}
4222module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004223
4224MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4225MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4226MODULE_LICENSE("GPL");