blob: 1e14edebc0c7fd1bae158fd91e3c2f9e4fbce9bf [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 Didelot1f36faf2015-10-08 11:35:13 -040035#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040036
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000037#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040038#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040039#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
Vivien Didelotfad09c72016-06-21 12:28:20 -040042static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040043{
Vivien Didelotfad09c72016-06-21 12:28:20 -040044 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
45 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046 dump_stack();
47 }
48}
49
Vivien Didelot914b32f2016-06-20 13:14:11 -040050/* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
52 *
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
56 *
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040061
Vivien Didelotfad09c72016-06-21 12:28:20 -040062static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 int addr, int reg, u16 *val)
64{
Vivien Didelotfad09c72016-06-21 12:28:20 -040065 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 return -EOPNOTSUPP;
67
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040069}
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040072 int addr, int reg, u16 val)
73{
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 return -EOPNOTSUPP;
76
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040078}
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 int addr, int reg, u16 *val)
82{
83 int ret;
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 if (ret < 0)
87 return ret;
88
89 *val = ret & 0xffff;
90
91 return 0;
92}
93
Vivien Didelotfad09c72016-06-21 12:28:20 -040094static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040095 int addr, int reg, u16 val)
96{
97 int ret;
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
Vivien Didelotc08026a2016-09-29 12:21:59 -0400106static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400107 .read = mv88e6xxx_smi_single_chip_read,
108 .write = mv88e6xxx_smi_single_chip_write,
109};
110
Vivien Didelotfad09c72016-06-21 12:28:20 -0400111static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112{
113 int ret;
114 int i;
115
116 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400117 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000118 if (ret < 0)
119 return ret;
120
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000122 return 0;
123 }
124
125 return -ETIMEDOUT;
126}
127
Vivien Didelotfad09c72016-06-21 12:28:20 -0400128static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400129 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130{
131 int ret;
132
Barry Grussling3675c8d2013-01-08 16:05:53 +0000133 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400134 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135 if (ret < 0)
136 return ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200140 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000141 if (ret < 0)
142 return ret;
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400145 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Vivien Didelot914b32f2016-06-20 13:14:11 -0400154 *val = ret & 0xffff;
155
156 return 0;
157}
158
Vivien Didelotfad09c72016-06-21 12:28:20 -0400159static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400160 int addr, int reg, u16 val)
161{
162 int ret;
163
164 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400165 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400166 if (ret < 0)
167 return ret;
168
169 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
177 if (ret < 0)
178 return ret;
179
180 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400181 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Vivien Didelotc08026a2016-09-29 12:21:59 -0400188static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400189 .read = mv88e6xxx_smi_multi_chip_read,
190 .write = mv88e6xxx_smi_multi_chip_write,
191};
192
Vivien Didelotec561272016-09-02 14:45:33 -0400193int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194{
195 int err;
196
Vivien Didelotfad09c72016-06-21 12:28:20 -0400197 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400198
Vivien Didelotfad09c72016-06-21 12:28:20 -0400199 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400200 if (err)
201 return err;
202
Vivien Didelotfad09c72016-06-21 12:28:20 -0400203 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400204 addr, reg, *val);
205
206 return 0;
207}
208
Vivien Didelotec561272016-09-02 14:45:33 -0400209int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400210{
211 int err;
212
Vivien Didelotfad09c72016-06-21 12:28:20 -0400213 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400214
Vivien Didelotfad09c72016-06-21 12:28:20 -0400215 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400216 if (err)
217 return err;
218
Vivien Didelotfad09c72016-06-21 12:28:20 -0400219 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400220 addr, reg, val);
221
222 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223}
224
Andrew Lunnee26a222017-01-24 14:53:48 +0100225static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip,
226 struct mii_bus *bus,
227 int addr, int reg, u16 *val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100228{
229 return mv88e6xxx_read(chip, addr, reg, val);
230}
231
Andrew Lunnee26a222017-01-24 14:53:48 +0100232static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip,
233 struct mii_bus *bus,
234 int addr, int reg, u16 val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100235{
236 return mv88e6xxx_write(chip, addr, reg, val);
237}
238
Andrew Lunna3c53be52017-01-24 14:53:50 +0100239static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
240{
241 struct mv88e6xxx_mdio_bus *mdio_bus;
242
243 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
244 list);
245 if (!mdio_bus)
246 return NULL;
247
248 return mdio_bus->bus;
249}
250
Vivien Didelote57e5e72016-08-15 17:19:00 -0400251static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
252 int reg, u16 *val)
253{
254 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100255 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400256
Andrew Lunna3c53be52017-01-24 14:53:50 +0100257 bus = mv88e6xxx_default_mdio_bus(chip);
258 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400259 return -EOPNOTSUPP;
260
Andrew Lunna3c53be52017-01-24 14:53:50 +0100261 if (!chip->info->ops->phy_read)
Andrew Lunnee26a222017-01-24 14:53:48 +0100262 return -EOPNOTSUPP;
263
264 return chip->info->ops->phy_read(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400265}
266
267static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
268 int reg, u16 val)
269{
270 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100271 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400272
Andrew Lunna3c53be52017-01-24 14:53:50 +0100273 bus = mv88e6xxx_default_mdio_bus(chip);
274 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400275 return -EOPNOTSUPP;
276
Andrew Lunna3c53be52017-01-24 14:53:50 +0100277 if (!chip->info->ops->phy_write)
Andrew Lunnee26a222017-01-24 14:53:48 +0100278 return -EOPNOTSUPP;
279
280 return chip->info->ops->phy_write(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400281}
282
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400283static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
284{
285 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
286 return -EOPNOTSUPP;
287
288 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
289}
290
291static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
292{
293 int err;
294
295 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
296 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
297 if (unlikely(err)) {
298 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
299 phy, err);
300 }
301}
302
303static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
304 u8 page, int reg, u16 *val)
305{
306 int err;
307
308 /* There is no paging for registers 22 */
309 if (reg == PHY_PAGE)
310 return -EINVAL;
311
312 err = mv88e6xxx_phy_page_get(chip, phy, page);
313 if (!err) {
314 err = mv88e6xxx_phy_read(chip, phy, reg, val);
315 mv88e6xxx_phy_page_put(chip, phy);
316 }
317
318 return err;
319}
320
321static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
322 u8 page, int reg, u16 val)
323{
324 int err;
325
326 /* There is no paging for registers 22 */
327 if (reg == PHY_PAGE)
328 return -EINVAL;
329
330 err = mv88e6xxx_phy_page_get(chip, phy, page);
331 if (!err) {
332 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
333 mv88e6xxx_phy_page_put(chip, phy);
334 }
335
336 return err;
337}
338
339static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
340{
341 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
342 reg, val);
343}
344
345static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
346{
347 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
348 reg, val);
349}
350
Andrew Lunndc30c352016-10-16 19:56:49 +0200351static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
352{
353 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
354 unsigned int n = d->hwirq;
355
356 chip->g1_irq.masked |= (1 << n);
357}
358
359static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
360{
361 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
362 unsigned int n = d->hwirq;
363
364 chip->g1_irq.masked &= ~(1 << n);
365}
366
367static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
368{
369 struct mv88e6xxx_chip *chip = dev_id;
370 unsigned int nhandled = 0;
371 unsigned int sub_irq;
372 unsigned int n;
373 u16 reg;
374 int err;
375
376 mutex_lock(&chip->reg_lock);
377 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
378 mutex_unlock(&chip->reg_lock);
379
380 if (err)
381 goto out;
382
383 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
384 if (reg & (1 << n)) {
385 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
386 handle_nested_irq(sub_irq);
387 ++nhandled;
388 }
389 }
390out:
391 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
392}
393
394static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
395{
396 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
397
398 mutex_lock(&chip->reg_lock);
399}
400
401static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
402{
403 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
404 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
405 u16 reg;
406 int err;
407
408 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
409 if (err)
410 goto out;
411
412 reg &= ~mask;
413 reg |= (~chip->g1_irq.masked & mask);
414
415 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
416 if (err)
417 goto out;
418
419out:
420 mutex_unlock(&chip->reg_lock);
421}
422
423static struct irq_chip mv88e6xxx_g1_irq_chip = {
424 .name = "mv88e6xxx-g1",
425 .irq_mask = mv88e6xxx_g1_irq_mask,
426 .irq_unmask = mv88e6xxx_g1_irq_unmask,
427 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
428 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
429};
430
431static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
432 unsigned int irq,
433 irq_hw_number_t hwirq)
434{
435 struct mv88e6xxx_chip *chip = d->host_data;
436
437 irq_set_chip_data(irq, d->host_data);
438 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
439 irq_set_noprobe(irq);
440
441 return 0;
442}
443
444static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
445 .map = mv88e6xxx_g1_irq_domain_map,
446 .xlate = irq_domain_xlate_twocell,
447};
448
449static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
450{
451 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100452 u16 mask;
453
454 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
455 mask |= GENMASK(chip->g1_irq.nirqs, 0);
456 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
457
458 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200459
Andreas Färber5edef2f2016-11-27 23:26:28 +0100460 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100461 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200462 irq_dispose_mapping(virq);
463 }
464
Andrew Lunna3db3d32016-11-20 20:14:14 +0100465 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200466}
467
468static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
469{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 int err, irq, virq;
471 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200472
473 chip->g1_irq.nirqs = chip->info->g1_irqs;
474 chip->g1_irq.domain = irq_domain_add_simple(
475 NULL, chip->g1_irq.nirqs, 0,
476 &mv88e6xxx_g1_irq_domain_ops, chip);
477 if (!chip->g1_irq.domain)
478 return -ENOMEM;
479
480 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
481 irq_create_mapping(chip->g1_irq.domain, irq);
482
483 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
484 chip->g1_irq.masked = ~0;
485
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100486 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200487 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100488 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200489
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100490 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200491
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100492 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200493 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100494 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200495
496 /* Reading the interrupt status clears (most of) them */
497 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
498 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100499 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200500
501 err = request_threaded_irq(chip->irq, NULL,
502 mv88e6xxx_g1_irq_thread_fn,
503 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
504 dev_name(chip->dev), chip);
505 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100506 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200507
508 return 0;
509
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100510out_disable:
511 mask |= GENMASK(chip->g1_irq.nirqs, 0);
512 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
513
514out_mapping:
515 for (irq = 0; irq < 16; irq++) {
516 virq = irq_find_mapping(chip->g1_irq.domain, irq);
517 irq_dispose_mapping(virq);
518 }
519
520 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200521
522 return err;
523}
524
Vivien Didelotec561272016-09-02 14:45:33 -0400525int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400526{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200527 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400528
Andrew Lunn6441e6692016-08-19 00:01:55 +0200529 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400530 u16 val;
531 int err;
532
533 err = mv88e6xxx_read(chip, addr, reg, &val);
534 if (err)
535 return err;
536
537 if (!(val & mask))
538 return 0;
539
540 usleep_range(1000, 2000);
541 }
542
Andrew Lunn30853552016-08-19 00:01:57 +0200543 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400544 return -ETIMEDOUT;
545}
546
Vivien Didelotf22ab642016-07-18 20:45:31 -0400547/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400548int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400549{
550 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200551 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400552
553 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200554 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
555 if (err)
556 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400557
558 /* Set the Update bit to trigger a write operation */
559 val = BIT(15) | update;
560
561 return mv88e6xxx_write(chip, addr, reg, val);
562}
563
Vivien Didelota935c052016-09-29 12:21:53 -0400564static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000565{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500566 if (!chip->info->ops->ppu_disable)
567 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000568
Vivien Didelota199d8b2016-12-05 17:30:28 -0500569 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000570}
571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000573{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500574 if (!chip->info->ops->ppu_enable)
575 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000576
Vivien Didelota199d8b2016-12-05 17:30:28 -0500577 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000578}
579
580static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
581{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400582 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000583
Vivien Didelotfad09c72016-06-21 12:28:20 -0400584 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200585
Vivien Didelotfad09c72016-06-21 12:28:20 -0400586 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200587
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 if (mutex_trylock(&chip->ppu_mutex)) {
589 if (mv88e6xxx_ppu_enable(chip) == 0)
590 chip->ppu_disabled = 0;
591 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000592 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595}
596
597static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
598{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400599 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000600
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602}
603
Vivien Didelotfad09c72016-06-21 12:28:20 -0400604static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000605{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000606 int ret;
607
Vivien Didelotfad09c72016-06-21 12:28:20 -0400608 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000609
Barry Grussling3675c8d2013-01-08 16:05:53 +0000610 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611 * we can access the PHY registers. If it was already
612 * disabled, cancel the timer that is going to re-enable
613 * it.
614 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400615 if (!chip->ppu_disabled) {
616 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000617 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400618 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000619 return ret;
620 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400621 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000622 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000624 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000625 }
626
627 return ret;
628}
629
Vivien Didelotfad09c72016-06-21 12:28:20 -0400630static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000631{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000632 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400633 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
634 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000635}
636
Vivien Didelotfad09c72016-06-21 12:28:20 -0400637static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000638{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400639 mutex_init(&chip->ppu_mutex);
640 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000641 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
642 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000643}
644
Andrew Lunn930188c2016-08-22 16:01:03 +0200645static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
646{
647 del_timer_sync(&chip->ppu_timer);
648}
649
Andrew Lunnee26a222017-01-24 14:53:48 +0100650static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
651 struct mii_bus *bus,
652 int addr, int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000653{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400654 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000655
Vivien Didelote57e5e72016-08-15 17:19:00 -0400656 err = mv88e6xxx_ppu_access_get(chip);
657 if (!err) {
658 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400659 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000660 }
661
Vivien Didelote57e5e72016-08-15 17:19:00 -0400662 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000663}
664
Andrew Lunnee26a222017-01-24 14:53:48 +0100665static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
666 struct mii_bus *bus,
667 int addr, int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000668{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400669 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000670
Vivien Didelote57e5e72016-08-15 17:19:00 -0400671 err = mv88e6xxx_ppu_access_get(chip);
672 if (!err) {
673 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000675 }
676
Vivien Didelote57e5e72016-08-15 17:19:00 -0400677 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000678}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000679
Vivien Didelotd78343d2016-11-04 03:23:36 +0100680static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
681 int link, int speed, int duplex,
682 phy_interface_t mode)
683{
684 int err;
685
686 if (!chip->info->ops->port_set_link)
687 return 0;
688
689 /* Port's MAC control must not be changed unless the link is down */
690 err = chip->info->ops->port_set_link(chip, port, 0);
691 if (err)
692 return err;
693
694 if (chip->info->ops->port_set_speed) {
695 err = chip->info->ops->port_set_speed(chip, port, speed);
696 if (err && err != -EOPNOTSUPP)
697 goto restore_link;
698 }
699
700 if (chip->info->ops->port_set_duplex) {
701 err = chip->info->ops->port_set_duplex(chip, port, duplex);
702 if (err && err != -EOPNOTSUPP)
703 goto restore_link;
704 }
705
706 if (chip->info->ops->port_set_rgmii_delay) {
707 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
708 if (err && err != -EOPNOTSUPP)
709 goto restore_link;
710 }
711
Andrew Lunnf39908d2017-02-04 20:02:50 +0100712 if (chip->info->ops->port_set_cmode) {
713 err = chip->info->ops->port_set_cmode(chip, port, mode);
714 if (err && err != -EOPNOTSUPP)
715 goto restore_link;
716 }
717
Vivien Didelotd78343d2016-11-04 03:23:36 +0100718 err = 0;
719restore_link:
720 if (chip->info->ops->port_set_link(chip, port, link))
721 netdev_err(chip->ds->ports[port].netdev,
722 "failed to restore MAC's link\n");
723
724 return err;
725}
726
Andrew Lunndea87022015-08-31 15:56:47 +0200727/* We expect the switch to perform auto negotiation if there is a real
728 * phy. However, in the case of a fixed link phy, we force the port
729 * settings from the fixed link settings.
730 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400731static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
732 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200733{
Vivien Didelot04bed142016-08-31 18:06:13 -0400734 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200735 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200736
737 if (!phy_is_pseudo_fixed_link(phydev))
738 return;
739
Vivien Didelotfad09c72016-06-21 12:28:20 -0400740 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100741 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
742 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400743 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100744
745 if (err && err != -EOPNOTSUPP)
746 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200747}
748
Andrew Lunna605a0f2016-11-21 23:26:58 +0100749static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000750{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100751 if (!chip->info->ops->stats_snapshot)
752 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000753
Andrew Lunna605a0f2016-11-21 23:26:58 +0100754 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000755}
756
Andrew Lunne413e7e2015-04-02 04:06:38 +0200757static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100758 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
759 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
760 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
761 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
762 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
763 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
764 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
765 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
766 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
767 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
768 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
769 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
770 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
771 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
772 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
773 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
774 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
775 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
776 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
777 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
778 { "single", 4, 0x14, STATS_TYPE_BANK0, },
779 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
780 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
781 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
782 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
783 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
784 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
785 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
786 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
787 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
788 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
789 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
790 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
791 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
792 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
793 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
794 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
795 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
796 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
797 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
798 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
799 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
800 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
801 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
802 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
803 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
804 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
805 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
806 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
807 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
808 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
809 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
810 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
811 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
812 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
813 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
814 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
815 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
816 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200817};
818
Vivien Didelotfad09c72016-06-21 12:28:20 -0400819static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100820 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100821 int port, u16 bank1_select,
822 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200823{
Andrew Lunn80c46272015-06-20 18:42:30 +0200824 u32 low;
825 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100826 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200827 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200828 u64 value;
829
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100830 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100831 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200832 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
833 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200834 return UINT64_MAX;
835
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200836 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200837 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200838 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
839 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200840 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200841 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200842 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100843 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100844 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100845 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100846 /* fall through */
847 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100848 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100849 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200850 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100851 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200852 }
853 value = (((u64)high) << 16) | low;
854 return value;
855}
856
Andrew Lunndfafe442016-11-21 23:27:02 +0100857static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
858 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100859{
860 struct mv88e6xxx_hw_stat *stat;
861 int i, j;
862
863 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
864 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100865 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100866 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
867 ETH_GSTRING_LEN);
868 j++;
869 }
870 }
871}
872
Andrew Lunndfafe442016-11-21 23:27:02 +0100873static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
874 uint8_t *data)
875{
876 mv88e6xxx_stats_get_strings(chip, data,
877 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
878}
879
880static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
881 uint8_t *data)
882{
883 mv88e6xxx_stats_get_strings(chip, data,
884 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
885}
886
887static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
888 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100889{
Vivien Didelot04bed142016-08-31 18:06:13 -0400890 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100891
892 if (chip->info->ops->stats_get_strings)
893 chip->info->ops->stats_get_strings(chip, data);
894}
895
896static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
897 int types)
898{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100899 struct mv88e6xxx_hw_stat *stat;
900 int i, j;
901
902 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
903 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100904 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100905 j++;
906 }
907 return j;
908}
909
Andrew Lunndfafe442016-11-21 23:27:02 +0100910static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
911{
912 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
913 STATS_TYPE_PORT);
914}
915
916static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
917{
918 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
919 STATS_TYPE_BANK1);
920}
921
922static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
923{
924 struct mv88e6xxx_chip *chip = ds->priv;
925
926 if (chip->info->ops->stats_get_sset_count)
927 return chip->info->ops->stats_get_sset_count(chip);
928
929 return 0;
930}
931
Andrew Lunn052f9472016-11-21 23:27:03 +0100932static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100933 uint64_t *data, int types,
934 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100935{
936 struct mv88e6xxx_hw_stat *stat;
937 int i, j;
938
939 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
940 stat = &mv88e6xxx_hw_stats[i];
941 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100942 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
943 bank1_select,
944 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100945 j++;
946 }
947 }
948}
949
950static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
951 uint64_t *data)
952{
953 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100954 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
955 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100956}
957
958static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
959 uint64_t *data)
960{
961 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100962 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
963 GLOBAL_STATS_OP_BANK_1_BIT_9,
964 GLOBAL_STATS_OP_HIST_RX_TX);
965}
966
967static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
968 uint64_t *data)
969{
970 return mv88e6xxx_stats_get_stats(chip, port, data,
971 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
972 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100973}
974
975static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
976 uint64_t *data)
977{
978 if (chip->info->ops->stats_get_stats)
979 chip->info->ops->stats_get_stats(chip, port, data);
980}
981
Vivien Didelotf81ec902016-05-09 13:22:58 -0400982static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
983 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000984{
Vivien Didelot04bed142016-08-31 18:06:13 -0400985 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000986 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000987
Vivien Didelotfad09c72016-06-21 12:28:20 -0400988 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000989
Andrew Lunna605a0f2016-11-21 23:26:58 +0100990 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000991 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400992 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000993 return;
994 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100995
996 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000997
Vivien Didelotfad09c72016-06-21 12:28:20 -0400998 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000999}
Ben Hutchings98e67302011-11-25 14:36:19 +00001000
Andrew Lunnde2273872016-11-21 23:27:01 +01001001static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1002{
1003 if (chip->info->ops->stats_set_histogram)
1004 return chip->info->ops->stats_set_histogram(chip);
1005
1006 return 0;
1007}
1008
Vivien Didelotf81ec902016-05-09 13:22:58 -04001009static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001010{
1011 return 32 * sizeof(u16);
1012}
1013
Vivien Didelotf81ec902016-05-09 13:22:58 -04001014static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1015 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001016{
Vivien Didelot04bed142016-08-31 18:06:13 -04001017 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001018 int err;
1019 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001020 u16 *p = _p;
1021 int i;
1022
1023 regs->version = 0;
1024
1025 memset(p, 0xff, 32 * sizeof(u16));
1026
Vivien Didelotfad09c72016-06-21 12:28:20 -04001027 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001028
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001029 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001030
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001031 err = mv88e6xxx_port_read(chip, port, i, &reg);
1032 if (!err)
1033 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001034 }
Vivien Didelot23062512016-05-09 13:22:45 -04001035
Vivien Didelotfad09c72016-06-21 12:28:20 -04001036 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001037}
1038
Vivien Didelotf81ec902016-05-09 13:22:58 -04001039static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1040 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001041{
Vivien Didelot04bed142016-08-31 18:06:13 -04001042 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001043 u16 reg;
1044 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001045
Vivien Didelotfad09c72016-06-21 12:28:20 -04001046 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001047 return -EOPNOTSUPP;
1048
Vivien Didelotfad09c72016-06-21 12:28:20 -04001049 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001050
Vivien Didelot9c938292016-08-15 17:19:02 -04001051 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1052 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001053 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001054
1055 e->eee_enabled = !!(reg & 0x0200);
1056 e->tx_lpi_enabled = !!(reg & 0x0100);
1057
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001058 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001059 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001060 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001061
Andrew Lunncca8b132015-04-02 04:06:39 +02001062 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001063out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001064 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001065
1066 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001067}
1068
Vivien Didelotf81ec902016-05-09 13:22:58 -04001069static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1070 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001071{
Vivien Didelot04bed142016-08-31 18:06:13 -04001072 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001073 u16 reg;
1074 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001075
Vivien Didelotfad09c72016-06-21 12:28:20 -04001076 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001077 return -EOPNOTSUPP;
1078
Vivien Didelotfad09c72016-06-21 12:28:20 -04001079 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001080
Vivien Didelot9c938292016-08-15 17:19:02 -04001081 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1082 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001083 goto out;
1084
Vivien Didelot9c938292016-08-15 17:19:02 -04001085 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001086 if (e->eee_enabled)
1087 reg |= 0x0200;
1088 if (e->tx_lpi_enabled)
1089 reg |= 0x0100;
1090
Vivien Didelot9c938292016-08-15 17:19:02 -04001091 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001092out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001093 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001094
Vivien Didelot9c938292016-08-15 17:19:02 -04001095 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001096}
1097
Vivien Didelote5887a22017-03-30 17:37:11 -04001098static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001099{
Vivien Didelote5887a22017-03-30 17:37:11 -04001100 struct dsa_switch *ds = NULL;
1101 struct net_device *br;
1102 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001103 int i;
1104
Vivien Didelote5887a22017-03-30 17:37:11 -04001105 if (dev < DSA_MAX_SWITCHES)
1106 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001107
Vivien Didelote5887a22017-03-30 17:37:11 -04001108 /* Prevent frames from unknown switch or port */
1109 if (!ds || port >= ds->num_ports)
1110 return 0;
1111
1112 /* Frames from DSA links and CPU ports can egress any local port */
1113 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1114 return mv88e6xxx_port_mask(chip);
1115
1116 br = ds->ports[port].bridge_dev;
1117 pvlan = 0;
1118
1119 /* Frames from user ports can egress any local DSA links and CPU ports,
1120 * as well as any local member of their bridge group.
1121 */
1122 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1123 if (dsa_is_cpu_port(chip->ds, i) ||
1124 dsa_is_dsa_port(chip->ds, i) ||
1125 (br && chip->ds->ports[i].bridge_dev == br))
1126 pvlan |= BIT(i);
1127
1128 return pvlan;
1129}
1130
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001131static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001132{
1133 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001134
1135 /* prevent frames from going back out of the port they came in on */
1136 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001137
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001138 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001139}
1140
Vivien Didelotf81ec902016-05-09 13:22:58 -04001141static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1142 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001143{
Vivien Didelot04bed142016-08-31 18:06:13 -04001144 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001145 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001146 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001147
1148 switch (state) {
1149 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001150 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001151 break;
1152 case BR_STATE_BLOCKING:
1153 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001154 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001155 break;
1156 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001157 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001158 break;
1159 case BR_STATE_FORWARDING:
1160 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001161 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001162 break;
1163 }
1164
Vivien Didelotfad09c72016-06-21 12:28:20 -04001165 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001166 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001167 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001168
1169 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001170 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001171}
1172
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001173static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1174{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001175 int err;
1176
Vivien Didelotdaefc942017-03-11 16:12:54 -05001177 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1178 if (err)
1179 return err;
1180
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001181 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1182 if (err)
1183 return err;
1184
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001185 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1186}
1187
Vivien Didelot17a15942017-03-30 17:37:09 -04001188static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1189{
1190 u16 pvlan = 0;
1191
1192 if (!mv88e6xxx_has_pvt(chip))
1193 return -EOPNOTSUPP;
1194
1195 /* Skip the local source device, which uses in-chip port VLAN */
1196 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001197 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001198
1199 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1200}
1201
Vivien Didelot81228992017-03-30 17:37:08 -04001202static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1203{
Vivien Didelot17a15942017-03-30 17:37:09 -04001204 int dev, port;
1205 int err;
1206
Vivien Didelot81228992017-03-30 17:37:08 -04001207 if (!mv88e6xxx_has_pvt(chip))
1208 return 0;
1209
1210 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1211 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1212 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001213 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1214 if (err)
1215 return err;
1216
1217 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1218 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1219 err = mv88e6xxx_pvt_map(chip, dev, port);
1220 if (err)
1221 return err;
1222 }
1223 }
1224
1225 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001226}
1227
Vivien Didelot749efcb2016-09-22 16:49:24 -04001228static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1229{
1230 struct mv88e6xxx_chip *chip = ds->priv;
1231 int err;
1232
1233 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001234 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001235 mutex_unlock(&chip->reg_lock);
1236
1237 if (err)
1238 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1239}
1240
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001241static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1242{
1243 if (!chip->info->max_vid)
1244 return 0;
1245
1246 return mv88e6xxx_g1_vtu_flush(chip);
1247}
1248
Vivien Didelotf1394b782017-05-01 14:05:22 -04001249static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1250 struct mv88e6xxx_vtu_entry *entry)
1251{
1252 if (!chip->info->ops->vtu_getnext)
1253 return -EOPNOTSUPP;
1254
1255 return chip->info->ops->vtu_getnext(chip, entry);
1256}
1257
Vivien Didelotf81ec902016-05-09 13:22:58 -04001258static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1259 struct switchdev_obj_port_vlan *vlan,
1260 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001261{
Vivien Didelot04bed142016-08-31 18:06:13 -04001262 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001263 struct mv88e6xxx_vtu_entry next = {
1264 .vid = chip->info->max_vid,
1265 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001266 u16 pvid;
1267 int err;
1268
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001269 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001270 return -EOPNOTSUPP;
1271
Vivien Didelotfad09c72016-06-21 12:28:20 -04001272 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001273
Vivien Didelot77064f32016-11-04 03:23:30 +01001274 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001275 if (err)
1276 goto unlock;
1277
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001278 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001279 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001280 if (err)
1281 break;
1282
1283 if (!next.valid)
1284 break;
1285
Vivien Didelotbd00e052017-05-01 14:05:11 -04001286 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001287 continue;
1288
1289 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001290 vlan->vid_begin = next.vid;
1291 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001292 vlan->flags = 0;
1293
Vivien Didelotbd00e052017-05-01 14:05:11 -04001294 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001295 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1296
1297 if (next.vid == pvid)
1298 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1299
1300 err = cb(&vlan->obj);
1301 if (err)
1302 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001303 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001304
1305unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001306 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001307
1308 return err;
1309}
1310
Vivien Didelotfad09c72016-06-21 12:28:20 -04001311static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001312 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001313{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001314 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelota935c052016-09-29 12:21:53 -04001315 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001316
Vivien Didelot332aa5c2017-05-01 14:05:12 -04001317 err = mv88e6xxx_g1_vtu_op_wait(chip);
Vivien Didelota935c052016-09-29 12:21:53 -04001318 if (err)
1319 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001320
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001321 err = mv88e6xxx_g1_vtu_vid_write(chip, entry);
1322 if (err)
1323 return err;
1324
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001325 if (!entry->valid)
1326 goto loadpurge;
1327
1328 /* Write port member tags */
Vivien Didelotc499a642017-05-01 14:05:18 -04001329 err = mv88e6185_g1_vtu_data_write(chip, entry);
Vivien Didelota935c052016-09-29 12:21:53 -04001330 if (err)
1331 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001332
Vivien Didelotfad09c72016-06-21 12:28:20 -04001333 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelotd2ca1ea2017-05-01 14:05:15 -04001334 err = mv88e6xxx_g1_vtu_sid_write(chip, entry);
Vivien Didelota935c052016-09-29 12:21:53 -04001335 if (err)
1336 return err;
Vivien Didelot021e64f2017-05-01 14:05:21 -04001337
1338 err = mv88e6xxx_g1_vtu_op(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
1339 if (err)
1340 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001341 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001342
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001343 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot8ee51f62017-05-01 14:05:14 -04001344 err = mv88e6xxx_g1_vtu_fid_write(chip, entry);
Vivien Didelota935c052016-09-29 12:21:53 -04001345 if (err)
1346 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001347 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001348 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1349 * VTU DBNum[3:0] are located in VTU Operation 3:0
1350 */
1351 op |= (entry->fid & 0xf0) << 8;
1352 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001353 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001354loadpurge:
Vivien Didelot332aa5c2017-05-01 14:05:12 -04001355 return mv88e6xxx_g1_vtu_op(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001356}
1357
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001358static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001359{
1360 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001361 struct mv88e6xxx_vtu_entry vlan = {
1362 .vid = chip->info->max_vid,
1363 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001364 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001365
1366 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1367
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001368 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001369 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001370 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001371 if (err)
1372 return err;
1373
1374 set_bit(*fid, fid_bitmap);
1375 }
1376
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001377 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001378 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001379 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001380 if (err)
1381 return err;
1382
1383 if (!vlan.valid)
1384 break;
1385
1386 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001387 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001388
1389 /* The reset value 0x000 is used to indicate that multiple address
1390 * databases are not needed. Return the next positive available.
1391 */
1392 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001393 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001394 return -ENOSPC;
1395
1396 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001397 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001398}
1399
Vivien Didelotfad09c72016-06-21 12:28:20 -04001400static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001401 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001402{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001403 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001404 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001405 .valid = true,
1406 .vid = vid,
1407 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001408 int i, err;
1409
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001410 err = mv88e6xxx_atu_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001411 if (err)
1412 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001413
Vivien Didelot3d131f02015-11-03 10:52:52 -05001414 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001415 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotbd00e052017-05-01 14:05:11 -04001416 vlan.member[i] = dsa_is_cpu_port(ds, i) ||
1417 dsa_is_dsa_port(ds, i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001418 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1419 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001420
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001421 *entry = vlan;
1422 return 0;
1423}
1424
Vivien Didelotfad09c72016-06-21 12:28:20 -04001425static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001426 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001427{
1428 int err;
1429
1430 if (!vid)
1431 return -EINVAL;
1432
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001433 entry->vid = vid - 1;
1434 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001435
Vivien Didelotf1394b782017-05-01 14:05:22 -04001436 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001437 if (err)
1438 return err;
1439
1440 if (entry->vid != vid || !entry->valid) {
1441 if (!creat)
1442 return -EOPNOTSUPP;
1443 /* -ENOENT would've been more appropriate, but switchdev expects
1444 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1445 */
1446
Vivien Didelotfad09c72016-06-21 12:28:20 -04001447 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001448 }
1449
1450 return err;
1451}
1452
Vivien Didelotda9c3592016-02-12 12:09:40 -05001453static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1454 u16 vid_begin, u16 vid_end)
1455{
Vivien Didelot04bed142016-08-31 18:06:13 -04001456 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001457 struct mv88e6xxx_vtu_entry vlan = {
1458 .vid = vid_begin - 1,
1459 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001460 int i, err;
1461
1462 if (!vid_begin)
1463 return -EOPNOTSUPP;
1464
Vivien Didelotfad09c72016-06-21 12:28:20 -04001465 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001466
Vivien Didelotda9c3592016-02-12 12:09:40 -05001467 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001468 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001469 if (err)
1470 goto unlock;
1471
1472 if (!vlan.valid)
1473 break;
1474
1475 if (vlan.vid > vid_end)
1476 break;
1477
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001478 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001479 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1480 continue;
1481
Andrew Lunn66e28092016-12-11 21:07:19 +01001482 if (!ds->ports[port].netdev)
1483 continue;
1484
Vivien Didelotbd00e052017-05-01 14:05:11 -04001485 if (vlan.member[i] ==
Vivien Didelotda9c3592016-02-12 12:09:40 -05001486 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1487 continue;
1488
Vivien Didelotfae8a252017-01-27 15:29:42 -05001489 if (ds->ports[i].bridge_dev ==
1490 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001491 break; /* same bridge, check next VLAN */
1492
Vivien Didelotfae8a252017-01-27 15:29:42 -05001493 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001494 continue;
1495
Andrew Lunnc8b09802016-06-04 21:16:57 +02001496 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001497 "hardware VLAN %d already used by %s\n",
1498 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001499 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001500 err = -EOPNOTSUPP;
1501 goto unlock;
1502 }
1503 } while (vlan.vid < vid_end);
1504
1505unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001506 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001507
1508 return err;
1509}
1510
Vivien Didelotf81ec902016-05-09 13:22:58 -04001511static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1512 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001513{
Vivien Didelot04bed142016-08-31 18:06:13 -04001514 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001515 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001516 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001517 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001518
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001519 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001520 return -EOPNOTSUPP;
1521
Vivien Didelotfad09c72016-06-21 12:28:20 -04001522 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001523 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001524 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001525
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001526 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001527}
1528
Vivien Didelot57d32312016-06-20 13:13:58 -04001529static int
1530mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1531 const struct switchdev_obj_port_vlan *vlan,
1532 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001533{
Vivien Didelot04bed142016-08-31 18:06:13 -04001534 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001535 int err;
1536
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001537 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001538 return -EOPNOTSUPP;
1539
Vivien Didelotda9c3592016-02-12 12:09:40 -05001540 /* If the requested port doesn't belong to the same bridge as the VLAN
1541 * members, do not support it (yet) and fallback to software VLAN.
1542 */
1543 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1544 vlan->vid_end);
1545 if (err)
1546 return err;
1547
Vivien Didelot76e398a2015-11-01 12:33:55 -05001548 /* We don't need any dynamic resource from the kernel (yet),
1549 * so skip the prepare phase.
1550 */
1551 return 0;
1552}
1553
Vivien Didelotfad09c72016-06-21 12:28:20 -04001554static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001555 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001556{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001557 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001558 int err;
1559
Vivien Didelotfad09c72016-06-21 12:28:20 -04001560 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001561 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001562 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001563
Vivien Didelotbd00e052017-05-01 14:05:11 -04001564 vlan.member[port] = untagged ?
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001565 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1566 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1567
Vivien Didelotfad09c72016-06-21 12:28:20 -04001568 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001569}
1570
Vivien Didelotf81ec902016-05-09 13:22:58 -04001571static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1572 const struct switchdev_obj_port_vlan *vlan,
1573 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001574{
Vivien Didelot04bed142016-08-31 18:06:13 -04001575 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001576 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1577 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1578 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001579
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001580 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001581 return;
1582
Vivien Didelotfad09c72016-06-21 12:28:20 -04001583 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001584
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001585 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001586 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001587 netdev_err(ds->ports[port].netdev,
1588 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001589 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001590
Vivien Didelot77064f32016-11-04 03:23:30 +01001591 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001592 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001593 vlan->vid_end);
1594
Vivien Didelotfad09c72016-06-21 12:28:20 -04001595 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001596}
1597
Vivien Didelotfad09c72016-06-21 12:28:20 -04001598static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001599 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001600{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001601 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001602 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001603 int i, err;
1604
Vivien Didelotfad09c72016-06-21 12:28:20 -04001605 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001606 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001607 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001608
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001609 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelotbd00e052017-05-01 14:05:11 -04001610 if (vlan.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001611 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001612
Vivien Didelotbd00e052017-05-01 14:05:11 -04001613 vlan.member[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001614
1615 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001616 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001617 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001618 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001619 continue;
1620
Vivien Didelotbd00e052017-05-01 14:05:11 -04001621 if (vlan.member[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001622 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001623 break;
1624 }
1625 }
1626
Vivien Didelotfad09c72016-06-21 12:28:20 -04001627 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001628 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001629 return err;
1630
Vivien Didelote606ca32017-03-11 16:12:55 -05001631 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001632}
1633
Vivien Didelotf81ec902016-05-09 13:22:58 -04001634static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1635 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001636{
Vivien Didelot04bed142016-08-31 18:06:13 -04001637 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001638 u16 pvid, vid;
1639 int err = 0;
1640
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001641 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001642 return -EOPNOTSUPP;
1643
Vivien Didelotfad09c72016-06-21 12:28:20 -04001644 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001645
Vivien Didelot77064f32016-11-04 03:23:30 +01001646 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001647 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001648 goto unlock;
1649
Vivien Didelot76e398a2015-11-01 12:33:55 -05001650 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001651 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001652 if (err)
1653 goto unlock;
1654
1655 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001656 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001657 if (err)
1658 goto unlock;
1659 }
1660 }
1661
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001662unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001663 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001664
1665 return err;
1666}
1667
Vivien Didelot83dabd12016-08-31 11:50:04 -04001668static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1669 const unsigned char *addr, u16 vid,
1670 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001671{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001672 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001673 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001674 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001675
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001676 /* Null VLAN ID corresponds to the port private database */
1677 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001678 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001679 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04001680 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001681 if (err)
1682 return err;
1683
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001684 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1685 ether_addr_copy(entry.mac, addr);
1686 eth_addr_dec(entry.mac);
1687
1688 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001689 if (err)
1690 return err;
1691
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001692 /* Initialize a fresh ATU entry if it isn't found */
1693 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1694 !ether_addr_equal(entry.mac, addr)) {
1695 memset(&entry, 0, sizeof(entry));
1696 ether_addr_copy(entry.mac, addr);
1697 }
1698
Vivien Didelot88472932016-09-19 19:56:11 -04001699 /* Purge the ATU entry only if no port is using it anymore */
1700 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001701 entry.portvec &= ~BIT(port);
1702 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001703 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1704 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001705 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001706 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001707 }
1708
Vivien Didelot9c13c022017-03-11 16:12:52 -05001709 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001710}
1711
Vivien Didelotf81ec902016-05-09 13:22:58 -04001712static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1713 const struct switchdev_obj_port_fdb *fdb,
1714 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001715{
1716 /* We don't need any dynamic resource from the kernel (yet),
1717 * so skip the prepare phase.
1718 */
1719 return 0;
1720}
1721
Vivien Didelotf81ec902016-05-09 13:22:58 -04001722static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1723 const struct switchdev_obj_port_fdb *fdb,
1724 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001725{
Vivien Didelot04bed142016-08-31 18:06:13 -04001726 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001727
Vivien Didelotfad09c72016-06-21 12:28:20 -04001728 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001729 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1730 GLOBAL_ATU_DATA_STATE_UC_STATIC))
1731 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001732 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001733}
1734
Vivien Didelotf81ec902016-05-09 13:22:58 -04001735static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1736 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001737{
Vivien Didelot04bed142016-08-31 18:06:13 -04001738 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001739 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001740
Vivien Didelotfad09c72016-06-21 12:28:20 -04001741 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001742 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1743 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001744 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001745
Vivien Didelot83dabd12016-08-31 11:50:04 -04001746 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001747}
1748
Vivien Didelot83dabd12016-08-31 11:50:04 -04001749static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1750 u16 fid, u16 vid, int port,
1751 struct switchdev_obj *obj,
1752 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001753{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001754 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001755 int err;
1756
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001757 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1758 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001759
1760 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001761 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001762 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001763 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001764
1765 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1766 break;
1767
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001768 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001769 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001770
Vivien Didelot83dabd12016-08-31 11:50:04 -04001771 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1772 struct switchdev_obj_port_fdb *fdb;
1773
1774 if (!is_unicast_ether_addr(addr.mac))
1775 continue;
1776
1777 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001778 fdb->vid = vid;
1779 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001780 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
1781 fdb->ndm_state = NUD_NOARP;
1782 else
1783 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001784 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1785 struct switchdev_obj_port_mdb *mdb;
1786
1787 if (!is_multicast_ether_addr(addr.mac))
1788 continue;
1789
1790 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1791 mdb->vid = vid;
1792 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001793 } else {
1794 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001795 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001796
1797 err = cb(obj);
1798 if (err)
1799 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001800 } while (!is_broadcast_ether_addr(addr.mac));
1801
1802 return err;
1803}
1804
Vivien Didelot83dabd12016-08-31 11:50:04 -04001805static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1806 struct switchdev_obj *obj,
1807 int (*cb)(struct switchdev_obj *obj))
1808{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001809 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001810 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001811 };
1812 u16 fid;
1813 int err;
1814
1815 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001816 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001817 if (err)
1818 return err;
1819
1820 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1821 if (err)
1822 return err;
1823
1824 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001825 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001826 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001827 if (err)
1828 return err;
1829
1830 if (!vlan.valid)
1831 break;
1832
1833 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1834 obj, cb);
1835 if (err)
1836 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001837 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001838
1839 return err;
1840}
1841
Vivien Didelotf81ec902016-05-09 13:22:58 -04001842static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1843 struct switchdev_obj_port_fdb *fdb,
1844 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04001845{
Vivien Didelot04bed142016-08-31 18:06:13 -04001846 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001847 int err;
1848
Vivien Didelotfad09c72016-06-21 12:28:20 -04001849 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001850 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001851 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001852
1853 return err;
1854}
1855
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001856static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1857 struct net_device *br)
1858{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001859 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001860 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001861 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001862 int err;
1863
1864 /* Remap the Port VLAN of each local bridge group member */
1865 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1866 if (chip->ds->ports[port].bridge_dev == br) {
1867 err = mv88e6xxx_port_vlan_map(chip, port);
1868 if (err)
1869 return err;
1870 }
1871 }
1872
Vivien Didelote96a6e02017-03-30 17:37:13 -04001873 if (!mv88e6xxx_has_pvt(chip))
1874 return 0;
1875
1876 /* Remap the Port VLAN of each cross-chip bridge group member */
1877 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1878 ds = chip->ds->dst->ds[dev];
1879 if (!ds)
1880 break;
1881
1882 for (port = 0; port < ds->num_ports; ++port) {
1883 if (ds->ports[port].bridge_dev == br) {
1884 err = mv88e6xxx_pvt_map(chip, dev, port);
1885 if (err)
1886 return err;
1887 }
1888 }
1889 }
1890
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001891 return 0;
1892}
1893
Vivien Didelotf81ec902016-05-09 13:22:58 -04001894static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001895 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001896{
Vivien Didelot04bed142016-08-31 18:06:13 -04001897 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001898 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001899
Vivien Didelotfad09c72016-06-21 12:28:20 -04001900 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001901 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001902 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001903
Vivien Didelot466dfa02016-02-26 13:16:05 -05001904 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001905}
1906
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001907static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1908 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001909{
Vivien Didelot04bed142016-08-31 18:06:13 -04001910 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001911
Vivien Didelotfad09c72016-06-21 12:28:20 -04001912 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001913 if (mv88e6xxx_bridge_map(chip, br) ||
1914 mv88e6xxx_port_vlan_map(chip, port))
1915 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001916 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001917}
1918
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001919static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1920 int port, struct net_device *br)
1921{
1922 struct mv88e6xxx_chip *chip = ds->priv;
1923 int err;
1924
1925 if (!mv88e6xxx_has_pvt(chip))
1926 return 0;
1927
1928 mutex_lock(&chip->reg_lock);
1929 err = mv88e6xxx_pvt_map(chip, dev, port);
1930 mutex_unlock(&chip->reg_lock);
1931
1932 return err;
1933}
1934
1935static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1936 int port, struct net_device *br)
1937{
1938 struct mv88e6xxx_chip *chip = ds->priv;
1939
1940 if (!mv88e6xxx_has_pvt(chip))
1941 return;
1942
1943 mutex_lock(&chip->reg_lock);
1944 if (mv88e6xxx_pvt_map(chip, dev, port))
1945 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1946 mutex_unlock(&chip->reg_lock);
1947}
1948
Vivien Didelot17e708b2016-12-05 17:30:27 -05001949static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1950{
1951 if (chip->info->ops->reset)
1952 return chip->info->ops->reset(chip);
1953
1954 return 0;
1955}
1956
Vivien Didelot309eca62016-12-05 17:30:26 -05001957static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1958{
1959 struct gpio_desc *gpiod = chip->reset;
1960
1961 /* If there is a GPIO connected to the reset pin, toggle it */
1962 if (gpiod) {
1963 gpiod_set_value_cansleep(gpiod, 1);
1964 usleep_range(10000, 20000);
1965 gpiod_set_value_cansleep(gpiod, 0);
1966 usleep_range(10000, 20000);
1967 }
1968}
1969
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001970static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1971{
1972 int i, err;
1973
1974 /* Set all ports to the Disabled state */
1975 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1976 err = mv88e6xxx_port_set_state(chip, i,
1977 PORT_CONTROL_STATE_DISABLED);
1978 if (err)
1979 return err;
1980 }
1981
1982 /* Wait for transmit queues to drain,
1983 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1984 */
1985 usleep_range(2000, 4000);
1986
1987 return 0;
1988}
1989
Vivien Didelotfad09c72016-06-21 12:28:20 -04001990static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001991{
Vivien Didelota935c052016-09-29 12:21:53 -04001992 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001993
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001994 err = mv88e6xxx_disable_ports(chip);
1995 if (err)
1996 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001997
Vivien Didelot309eca62016-12-05 17:30:26 -05001998 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001999
Vivien Didelot17e708b2016-12-05 17:30:27 -05002000 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002001}
2002
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002003static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002004{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002005 u16 val;
2006 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002007
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002008 /* Clear Power Down bit */
2009 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2010 if (err)
2011 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002012
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002013 if (val & BMCR_PDOWN) {
2014 val &= ~BMCR_PDOWN;
2015 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002016 }
2017
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002018 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002019}
2020
Vivien Didelot43145572017-03-11 16:12:59 -05002021static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2022 enum mv88e6xxx_frame_mode frame, u16 egress,
2023 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002024{
2025 int err;
2026
Vivien Didelot43145572017-03-11 16:12:59 -05002027 if (!chip->info->ops->port_set_frame_mode)
2028 return -EOPNOTSUPP;
2029
2030 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002031 if (err)
2032 return err;
2033
Vivien Didelot43145572017-03-11 16:12:59 -05002034 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2035 if (err)
2036 return err;
2037
2038 if (chip->info->ops->port_set_ether_type)
2039 return chip->info->ops->port_set_ether_type(chip, port, etype);
2040
2041 return 0;
2042}
2043
2044static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2045{
2046 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2047 PORT_CONTROL_EGRESS_UNMODIFIED,
2048 PORT_ETH_TYPE_DEFAULT);
2049}
2050
2051static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2052{
2053 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2054 PORT_CONTROL_EGRESS_UNMODIFIED,
2055 PORT_ETH_TYPE_DEFAULT);
2056}
2057
2058static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2059{
2060 return mv88e6xxx_set_port_mode(chip, port,
2061 MV88E6XXX_FRAME_MODE_ETHERTYPE,
2062 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
2063}
2064
2065static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2066{
2067 if (dsa_is_dsa_port(chip->ds, port))
2068 return mv88e6xxx_set_port_mode_dsa(chip, port);
2069
2070 if (dsa_is_normal_port(chip->ds, port))
2071 return mv88e6xxx_set_port_mode_normal(chip, port);
2072
2073 /* Setup CPU port mode depending on its supported tag format */
2074 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2075 return mv88e6xxx_set_port_mode_dsa(chip, port);
2076
2077 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2078 return mv88e6xxx_set_port_mode_edsa(chip, port);
2079
2080 return -EINVAL;
2081}
2082
Vivien Didelotea698f42017-03-11 16:12:50 -05002083static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2084{
2085 bool message = dsa_is_dsa_port(chip->ds, port);
2086
2087 return mv88e6xxx_port_set_message_port(chip, port, message);
2088}
2089
Vivien Didelot601aeed2017-03-11 16:13:00 -05002090static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2091{
2092 bool flood = port == dsa_upstream_port(chip->ds);
2093
2094 /* Upstream ports flood frames with unknown unicast or multicast DA */
2095 if (chip->info->ops->port_set_egress_floods)
2096 return chip->info->ops->port_set_egress_floods(chip, port,
2097 flood, flood);
2098
2099 return 0;
2100}
2101
Vivien Didelotfad09c72016-06-21 12:28:20 -04002102static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002103{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002104 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002105 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002106 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002107
Vivien Didelotd78343d2016-11-04 03:23:36 +01002108 /* MAC Forcing register: don't force link, speed, duplex or flow control
2109 * state to any particular values on physical ports, but force the CPU
2110 * port and all DSA ports to their maximum bandwidth and full duplex.
2111 */
2112 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2113 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2114 SPEED_MAX, DUPLEX_FULL,
2115 PHY_INTERFACE_MODE_NA);
2116 else
2117 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2118 SPEED_UNFORCED, DUPLEX_UNFORCED,
2119 PHY_INTERFACE_MODE_NA);
2120 if (err)
2121 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002122
2123 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2124 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2125 * tunneling, determine priority by looking at 802.1p and IP
2126 * priority fields (IP prio has precedence), and set STP state
2127 * to Forwarding.
2128 *
2129 * If this is the CPU link, use DSA or EDSA tagging depending
2130 * on which tagging mode was configured.
2131 *
2132 * If this is a link to another switch, use DSA tagging mode.
2133 *
2134 * If this is the upstream port for this switch, enable
2135 * forwarding of unknown unicasts and multicasts.
2136 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002137 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002138 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2139 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002140 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2141 if (err)
2142 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002143
Vivien Didelot601aeed2017-03-11 16:13:00 -05002144 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002145 if (err)
2146 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002147
Vivien Didelot601aeed2017-03-11 16:13:00 -05002148 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002149 if (err)
2150 return err;
2151
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002152 /* If this port is connected to a SerDes, make sure the SerDes is not
2153 * powered down.
2154 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002155 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002156 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2157 if (err)
2158 return err;
2159 reg &= PORT_STATUS_CMODE_MASK;
2160 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2161 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2162 (reg == PORT_STATUS_CMODE_SGMII)) {
2163 err = mv88e6xxx_serdes_power_on(chip);
2164 if (err < 0)
2165 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002166 }
2167 }
2168
Vivien Didelot8efdda42015-08-13 12:52:23 -04002169 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002170 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002171 * untagged frames on this port, do a destination address lookup on all
2172 * received packets as usual, disable ARP mirroring and don't send a
2173 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002174 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002175 err = mv88e6xxx_port_set_map_da(chip, port);
2176 if (err)
2177 return err;
2178
Andrew Lunn54d792f2015-05-06 01:09:47 +02002179 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002180 if (chip->info->ops->port_set_upstream_port) {
2181 err = chip->info->ops->port_set_upstream_port(
2182 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002183 if (err)
2184 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002185 }
2186
Andrew Lunna23b2962017-02-04 20:15:28 +01002187 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2188 PORT_CONTROL_2_8021Q_DISABLED);
2189 if (err)
2190 return err;
2191
Andrew Lunn5f436662016-12-03 04:45:17 +01002192 if (chip->info->ops->port_jumbo_config) {
2193 err = chip->info->ops->port_jumbo_config(chip, port);
2194 if (err)
2195 return err;
2196 }
2197
Andrew Lunn54d792f2015-05-06 01:09:47 +02002198 /* Port Association Vector: when learning source addresses
2199 * of packets, add the address to the address database using
2200 * a port bitmap that has only the bit for this port set and
2201 * the other bits clear.
2202 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002203 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002204 /* Disable learning for CPU port */
2205 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002206 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002207
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002208 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2209 if (err)
2210 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002211
2212 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002213 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2214 if (err)
2215 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002216
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002217 if (chip->info->ops->port_pause_config) {
2218 err = chip->info->ops->port_pause_config(chip, port);
2219 if (err)
2220 return err;
2221 }
2222
Vivien Didelotc8c94892017-03-11 16:13:01 -05002223 if (chip->info->ops->port_disable_learn_limit) {
2224 err = chip->info->ops->port_disable_learn_limit(chip, port);
2225 if (err)
2226 return err;
2227 }
2228
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002229 if (chip->info->ops->port_disable_pri_override) {
2230 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002231 if (err)
2232 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002233 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002234
Andrew Lunnef0a7312016-12-03 04:35:16 +01002235 if (chip->info->ops->port_tag_remap) {
2236 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002237 if (err)
2238 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002239 }
2240
Andrew Lunnef70b112016-12-03 04:45:18 +01002241 if (chip->info->ops->port_egress_rate_limiting) {
2242 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002243 if (err)
2244 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002245 }
2246
Vivien Didelotea698f42017-03-11 16:12:50 -05002247 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002248 if (err)
2249 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002250
Vivien Didelot207afda2016-04-14 14:42:09 -04002251 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002252 * database, and allow bidirectional communication between the
2253 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002254 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002255 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002256 if (err)
2257 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002258
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002259 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002260 if (err)
2261 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002262
2263 /* Default VLAN ID and priority: don't set a default VLAN
2264 * ID, and set the default packet priority to zero.
2265 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002266 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002267}
2268
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002269static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002270{
2271 int err;
2272
Vivien Didelota935c052016-09-29 12:21:53 -04002273 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002274 if (err)
2275 return err;
2276
Vivien Didelota935c052016-09-29 12:21:53 -04002277 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002278 if (err)
2279 return err;
2280
Vivien Didelota935c052016-09-29 12:21:53 -04002281 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2282 if (err)
2283 return err;
2284
2285 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002286}
2287
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002288static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2289 unsigned int ageing_time)
2290{
Vivien Didelot04bed142016-08-31 18:06:13 -04002291 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002292 int err;
2293
2294 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002295 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002296 mutex_unlock(&chip->reg_lock);
2297
2298 return err;
2299}
2300
Vivien Didelot97299342016-07-18 20:45:30 -04002301static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002302{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002303 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002304 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002305 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002306
Vivien Didelot119477b2016-05-09 13:22:51 -04002307 /* Enable the PHY Polling Unit if present, don't discard any packets,
2308 * and mask all interrupt sources.
2309 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002310 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002311 if (err)
2312 return err;
2313
Andrew Lunn33641992016-12-03 04:35:17 +01002314 if (chip->info->ops->g1_set_cpu_port) {
2315 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2316 if (err)
2317 return err;
2318 }
2319
2320 if (chip->info->ops->g1_set_egress_port) {
2321 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2322 if (err)
2323 return err;
2324 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002325
Vivien Didelot50484ff2016-05-09 13:22:54 -04002326 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002327 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2328 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2329 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002330 if (err)
2331 return err;
2332
Vivien Didelot08a01262016-05-09 13:22:50 -04002333 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002334 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002335 if (err)
2336 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002337 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002338 if (err)
2339 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002340 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002341 if (err)
2342 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002343 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002344 if (err)
2345 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002346 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002347 if (err)
2348 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002349 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002350 if (err)
2351 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002352 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002353 if (err)
2354 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002355 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002356 if (err)
2357 return err;
2358
2359 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002360 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002361 if (err)
2362 return err;
2363
Andrew Lunnde2273872016-11-21 23:27:01 +01002364 /* Initialize the statistics unit */
2365 err = mv88e6xxx_stats_set_histogram(chip);
2366 if (err)
2367 return err;
2368
Vivien Didelot97299342016-07-18 20:45:30 -04002369 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002370 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2371 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002372 if (err)
2373 return err;
2374
2375 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002376 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002377 if (err)
2378 return err;
2379
2380 return 0;
2381}
2382
Vivien Didelotf81ec902016-05-09 13:22:58 -04002383static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002384{
Vivien Didelot04bed142016-08-31 18:06:13 -04002385 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002386 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002387 int i;
2388
Vivien Didelotfad09c72016-06-21 12:28:20 -04002389 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002390 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002391
Vivien Didelotfad09c72016-06-21 12:28:20 -04002392 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002393
Vivien Didelot97299342016-07-18 20:45:30 -04002394 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002395 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002396 err = mv88e6xxx_setup_port(chip, i);
2397 if (err)
2398 goto unlock;
2399 }
2400
2401 /* Setup Switch Global 1 Registers */
2402 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002403 if (err)
2404 goto unlock;
2405
Vivien Didelot97299342016-07-18 20:45:30 -04002406 /* Setup Switch Global 2 Registers */
2407 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2408 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002409 if (err)
2410 goto unlock;
2411 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002412
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002413 err = mv88e6xxx_vtu_setup(chip);
2414 if (err)
2415 goto unlock;
2416
Vivien Didelot81228992017-03-30 17:37:08 -04002417 err = mv88e6xxx_pvt_setup(chip);
2418 if (err)
2419 goto unlock;
2420
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002421 err = mv88e6xxx_atu_setup(chip);
2422 if (err)
2423 goto unlock;
2424
Andrew Lunn6e55f692016-12-03 04:45:16 +01002425 /* Some generations have the configuration of sending reserved
2426 * management frames to the CPU in global2, others in
2427 * global1. Hence it does not fit the two setup functions
2428 * above.
2429 */
2430 if (chip->info->ops->mgmt_rsvd2cpu) {
2431 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2432 if (err)
2433 goto unlock;
2434 }
2435
Vivien Didelot6b17e862015-08-13 12:52:18 -04002436unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002437 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002438
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002439 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002440}
2441
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002442static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2443{
Vivien Didelot04bed142016-08-31 18:06:13 -04002444 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002445 int err;
2446
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002447 if (!chip->info->ops->set_switch_mac)
2448 return -EOPNOTSUPP;
2449
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002450 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002451 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002452 mutex_unlock(&chip->reg_lock);
2453
2454 return err;
2455}
2456
Vivien Didelote57e5e72016-08-15 17:19:00 -04002457static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002458{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002459 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2460 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002461 u16 val;
2462 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002463
Andrew Lunnee26a222017-01-24 14:53:48 +01002464 if (!chip->info->ops->phy_read)
2465 return -EOPNOTSUPP;
2466
Vivien Didelotfad09c72016-06-21 12:28:20 -04002467 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002468 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002469 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002470
Andrew Lunnda9f3302017-02-01 03:40:05 +01002471 if (reg == MII_PHYSID2) {
2472 /* Some internal PHYS don't have a model number. Use
2473 * the mv88e6390 family model number instead.
2474 */
2475 if (!(val & 0x3f0))
2476 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2477 }
2478
Vivien Didelote57e5e72016-08-15 17:19:00 -04002479 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002480}
2481
Vivien Didelote57e5e72016-08-15 17:19:00 -04002482static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002483{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002484 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2485 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002486 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002487
Andrew Lunnee26a222017-01-24 14:53:48 +01002488 if (!chip->info->ops->phy_write)
2489 return -EOPNOTSUPP;
2490
Vivien Didelotfad09c72016-06-21 12:28:20 -04002491 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002492 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002493 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002494
2495 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002496}
2497
Vivien Didelotfad09c72016-06-21 12:28:20 -04002498static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002499 struct device_node *np,
2500 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002501{
2502 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002503 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002504 struct mii_bus *bus;
2505 int err;
2506
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002507 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002508 if (!bus)
2509 return -ENOMEM;
2510
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002511 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002512 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002513 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002514 INIT_LIST_HEAD(&mdio_bus->list);
2515 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002516
Andrew Lunnb516d452016-06-04 21:17:06 +02002517 if (np) {
2518 bus->name = np->full_name;
2519 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2520 } else {
2521 bus->name = "mv88e6xxx SMI";
2522 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2523 }
2524
2525 bus->read = mv88e6xxx_mdio_read;
2526 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002527 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002528
Andrew Lunna3c53be52017-01-24 14:53:50 +01002529 if (np)
2530 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002531 else
2532 err = mdiobus_register(bus);
2533 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002534 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002535 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002536 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002537
2538 if (external)
2539 list_add_tail(&mdio_bus->list, &chip->mdios);
2540 else
2541 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002542
2543 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002544}
2545
Andrew Lunna3c53be52017-01-24 14:53:50 +01002546static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2547 { .compatible = "marvell,mv88e6xxx-mdio-external",
2548 .data = (void *)true },
2549 { },
2550};
2551
2552static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2553 struct device_node *np)
2554{
2555 const struct of_device_id *match;
2556 struct device_node *child;
2557 int err;
2558
2559 /* Always register one mdio bus for the internal/default mdio
2560 * bus. This maybe represented in the device tree, but is
2561 * optional.
2562 */
2563 child = of_get_child_by_name(np, "mdio");
2564 err = mv88e6xxx_mdio_register(chip, child, false);
2565 if (err)
2566 return err;
2567
2568 /* Walk the device tree, and see if there are any other nodes
2569 * which say they are compatible with the external mdio
2570 * bus.
2571 */
2572 for_each_available_child_of_node(np, child) {
2573 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2574 if (match) {
2575 err = mv88e6xxx_mdio_register(chip, child, true);
2576 if (err)
2577 return err;
2578 }
2579 }
2580
2581 return 0;
2582}
2583
2584static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002585
2586{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002587 struct mv88e6xxx_mdio_bus *mdio_bus;
2588 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002589
Andrew Lunna3c53be52017-01-24 14:53:50 +01002590 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2591 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002592
Andrew Lunna3c53be52017-01-24 14:53:50 +01002593 mdiobus_unregister(bus);
2594 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002595}
2596
Vivien Didelot855b1932016-07-20 18:18:35 -04002597static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2598{
Vivien Didelot04bed142016-08-31 18:06:13 -04002599 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002600
2601 return chip->eeprom_len;
2602}
2603
Vivien Didelot855b1932016-07-20 18:18:35 -04002604static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2605 struct ethtool_eeprom *eeprom, u8 *data)
2606{
Vivien Didelot04bed142016-08-31 18:06:13 -04002607 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002608 int err;
2609
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002610 if (!chip->info->ops->get_eeprom)
2611 return -EOPNOTSUPP;
2612
Vivien Didelot855b1932016-07-20 18:18:35 -04002613 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002614 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002615 mutex_unlock(&chip->reg_lock);
2616
2617 if (err)
2618 return err;
2619
2620 eeprom->magic = 0xc3ec4951;
2621
2622 return 0;
2623}
2624
Vivien Didelot855b1932016-07-20 18:18:35 -04002625static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2626 struct ethtool_eeprom *eeprom, u8 *data)
2627{
Vivien Didelot04bed142016-08-31 18:06:13 -04002628 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002629 int err;
2630
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002631 if (!chip->info->ops->set_eeprom)
2632 return -EOPNOTSUPP;
2633
Vivien Didelot855b1932016-07-20 18:18:35 -04002634 if (eeprom->magic != 0xc3ec4951)
2635 return -EINVAL;
2636
2637 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002638 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002639 mutex_unlock(&chip->reg_lock);
2640
2641 return err;
2642}
2643
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002644static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002645 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002646 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002647 .phy_read = mv88e6xxx_phy_ppu_read,
2648 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002649 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002650 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002651 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002652 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002653 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002654 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002655 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002656 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002657 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002658 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002659 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002660 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002661 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2662 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002663 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002664 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2665 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002666 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002667 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002668 .ppu_enable = mv88e6185_g1_ppu_enable,
2669 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002670 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002671 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002672};
2673
2674static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002675 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002676 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002677 .phy_read = mv88e6xxx_phy_ppu_read,
2678 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002679 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002680 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002681 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002682 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002683 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002684 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002685 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002686 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2687 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002688 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002689 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002690 .ppu_enable = mv88e6185_g1_ppu_enable,
2691 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002692 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002693 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002694};
2695
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002696static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002697 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002698 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2699 .phy_read = mv88e6xxx_g2_smi_phy_read,
2700 .phy_write = mv88e6xxx_g2_smi_phy_write,
2701 .port_set_link = mv88e6xxx_port_set_link,
2702 .port_set_duplex = mv88e6xxx_port_set_duplex,
2703 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002704 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002705 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002706 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002707 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002708 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002709 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002710 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002711 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002712 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002713 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2714 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2715 .stats_get_strings = mv88e6095_stats_get_strings,
2716 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002717 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2718 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002719 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002720 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002721 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002722 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002723};
2724
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002725static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002726 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002727 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002728 .phy_read = mv88e6165_phy_read,
2729 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002730 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002731 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002732 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002733 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002734 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002735 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002736 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002737 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002738 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2739 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002740 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002741 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2742 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002743 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002744 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002745 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002746 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002747};
2748
2749static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002750 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002751 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002752 .phy_read = mv88e6xxx_phy_ppu_read,
2753 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002754 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002755 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002756 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002757 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002758 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002759 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002760 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002761 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002762 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002763 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002764 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002765 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002766 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2767 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002768 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002769 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2770 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002771 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002772 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002773 .ppu_enable = mv88e6185_g1_ppu_enable,
2774 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002775 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002776 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002777};
2778
Vivien Didelot990e27b2017-03-28 13:50:32 -04002779static const struct mv88e6xxx_ops mv88e6141_ops = {
2780 /* MV88E6XXX_FAMILY_6341 */
2781 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2782 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2783 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2784 .phy_read = mv88e6xxx_g2_smi_phy_read,
2785 .phy_write = mv88e6xxx_g2_smi_phy_write,
2786 .port_set_link = mv88e6xxx_port_set_link,
2787 .port_set_duplex = mv88e6xxx_port_set_duplex,
2788 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2789 .port_set_speed = mv88e6390_port_set_speed,
2790 .port_tag_remap = mv88e6095_port_tag_remap,
2791 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2792 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2793 .port_set_ether_type = mv88e6351_port_set_ether_type,
2794 .port_jumbo_config = mv88e6165_port_jumbo_config,
2795 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2796 .port_pause_config = mv88e6097_port_pause_config,
2797 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2798 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2799 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2800 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2801 .stats_get_strings = mv88e6320_stats_get_strings,
2802 .stats_get_stats = mv88e6390_stats_get_stats,
2803 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2804 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2805 .watchdog_ops = &mv88e6390_watchdog_ops,
2806 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2807 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002808 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002809};
2810
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002811static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002812 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002813 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002814 .phy_read = mv88e6165_phy_read,
2815 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002816 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002817 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002818 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002819 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002820 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002821 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002822 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002823 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002824 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002825 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002826 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002827 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002828 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002829 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2830 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002831 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002832 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2833 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002834 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002835 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002836 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002837 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002838};
2839
2840static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002841 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002842 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002843 .phy_read = mv88e6165_phy_read,
2844 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002845 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002846 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002847 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002848 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002849 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002850 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002851 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2852 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002853 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002854 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2855 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002856 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002857 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002858 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002859 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002860};
2861
2862static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002863 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002864 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002865 .phy_read = mv88e6xxx_g2_smi_phy_read,
2866 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002867 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002868 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002869 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002870 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002871 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002872 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002873 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002874 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002875 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002876 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002877 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002878 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002879 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002880 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002881 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2882 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002883 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002884 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2885 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002886 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002887 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002888 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002889 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002890};
2891
2892static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002893 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002894 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2895 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002896 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002897 .phy_read = mv88e6xxx_g2_smi_phy_read,
2898 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002899 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002900 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002901 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002902 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002903 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002904 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002905 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002906 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002907 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002908 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002909 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002910 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002911 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002912 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002913 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2914 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002915 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002916 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2917 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002918 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002919 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002920 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002921 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002922};
2923
2924static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002925 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002926 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002927 .phy_read = mv88e6xxx_g2_smi_phy_read,
2928 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002929 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002930 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002931 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002932 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002933 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002934 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002935 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002936 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002937 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002938 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002939 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002940 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002941 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002942 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002943 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2944 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002945 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002946 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2947 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002948 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002949 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002950 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002951 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002952};
2953
2954static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002955 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002956 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2957 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002958 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002959 .phy_read = mv88e6xxx_g2_smi_phy_read,
2960 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002961 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002962 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002963 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002964 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002965 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002966 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002967 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002968 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002969 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002970 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002971 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002972 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002973 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002974 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002975 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2976 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002977 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002978 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2979 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002980 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002981 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002982 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002983 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002984};
2985
2986static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002987 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002988 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002989 .phy_read = mv88e6xxx_phy_ppu_read,
2990 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002991 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002992 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002993 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002994 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002995 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002996 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002997 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002998 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002999 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3000 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003001 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003002 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3003 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003004 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003005 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003006 .ppu_enable = mv88e6185_g1_ppu_enable,
3007 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003008 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003009 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003010};
3011
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003012static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003013 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003014 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3015 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003016 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3017 .phy_read = mv88e6xxx_g2_smi_phy_read,
3018 .phy_write = mv88e6xxx_g2_smi_phy_write,
3019 .port_set_link = mv88e6xxx_port_set_link,
3020 .port_set_duplex = mv88e6xxx_port_set_duplex,
3021 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3022 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003023 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003024 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003025 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003026 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003027 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003028 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003029 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003030 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003031 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003032 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3033 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003034 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003035 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3036 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003037 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003038 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003039 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003040};
3041
3042static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003043 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003044 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3045 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003046 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3047 .phy_read = mv88e6xxx_g2_smi_phy_read,
3048 .phy_write = mv88e6xxx_g2_smi_phy_write,
3049 .port_set_link = mv88e6xxx_port_set_link,
3050 .port_set_duplex = mv88e6xxx_port_set_duplex,
3051 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3052 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003053 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003054 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003055 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003056 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003057 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003058 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003059 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003060 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003061 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003062 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3063 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003064 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003065 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3066 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003067 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003068 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003069 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003070};
3071
3072static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003073 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003074 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3075 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003076 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3077 .phy_read = mv88e6xxx_g2_smi_phy_read,
3078 .phy_write = mv88e6xxx_g2_smi_phy_write,
3079 .port_set_link = mv88e6xxx_port_set_link,
3080 .port_set_duplex = mv88e6xxx_port_set_duplex,
3081 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3082 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003083 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003084 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003085 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003086 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003087 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003088 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003089 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003090 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003091 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003092 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3093 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003094 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003095 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3096 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003097 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003098 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003099 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003100};
3101
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003102static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003103 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003104 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3105 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003106 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003107 .phy_read = mv88e6xxx_g2_smi_phy_read,
3108 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003109 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003110 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003111 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003112 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003113 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003114 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003115 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003116 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003117 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003118 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003119 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003120 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003121 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003122 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003123 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3124 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003125 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003126 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3127 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003128 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003129 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003130 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003131 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003132};
3133
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003134static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003135 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003136 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3137 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003138 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3139 .phy_read = mv88e6xxx_g2_smi_phy_read,
3140 .phy_write = mv88e6xxx_g2_smi_phy_write,
3141 .port_set_link = mv88e6xxx_port_set_link,
3142 .port_set_duplex = mv88e6xxx_port_set_duplex,
3143 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3144 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003145 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003146 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003147 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003148 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003149 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003150 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003151 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003152 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003153 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003154 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003155 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3156 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003157 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003158 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3159 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003160 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003161 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003162 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003163};
3164
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003165static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003166 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003167 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3168 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003169 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003170 .phy_read = mv88e6xxx_g2_smi_phy_read,
3171 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003172 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003173 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003174 .port_set_speed = mv88e6185_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,
Andrew Lunn5f436662016-12-03 04:45:17 +01003179 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003180 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003181 .port_pause_config = mv88e6097_port_pause_config,
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 Lunndfafe442016-11-21 23:27:02 +01003185 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3186 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003187 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003188 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3189 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003190 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003191 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003192 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003193};
3194
3195static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003196 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003197 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3198 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003199 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003200 .phy_read = mv88e6xxx_g2_smi_phy_read,
3201 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003202 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003203 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003204 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003205 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003206 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003207 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003208 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003209 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003210 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003211 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003212 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003213 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003214 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003215 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3216 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003217 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003218 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3219 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003220 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003221 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003222};
3223
Vivien Didelot16e329a2017-03-28 13:50:33 -04003224static const struct mv88e6xxx_ops mv88e6341_ops = {
3225 /* MV88E6XXX_FAMILY_6341 */
3226 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3227 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3228 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3229 .phy_read = mv88e6xxx_g2_smi_phy_read,
3230 .phy_write = mv88e6xxx_g2_smi_phy_write,
3231 .port_set_link = mv88e6xxx_port_set_link,
3232 .port_set_duplex = mv88e6xxx_port_set_duplex,
3233 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3234 .port_set_speed = mv88e6390_port_set_speed,
3235 .port_tag_remap = mv88e6095_port_tag_remap,
3236 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3237 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3238 .port_set_ether_type = mv88e6351_port_set_ether_type,
3239 .port_jumbo_config = mv88e6165_port_jumbo_config,
3240 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3241 .port_pause_config = mv88e6097_port_pause_config,
3242 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3243 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3244 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3245 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3246 .stats_get_strings = mv88e6320_stats_get_strings,
3247 .stats_get_stats = mv88e6390_stats_get_stats,
3248 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3249 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3250 .watchdog_ops = &mv88e6390_watchdog_ops,
3251 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3252 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003253 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003254};
3255
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003256static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003257 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003258 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003259 .phy_read = mv88e6xxx_g2_smi_phy_read,
3260 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003261 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003262 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003263 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003264 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003265 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003266 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003267 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003268 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003269 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003270 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003271 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003272 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003273 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003274 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003275 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3276 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003277 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003278 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3279 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003280 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003281 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003282 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003283 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003284};
3285
3286static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003287 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003288 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003289 .phy_read = mv88e6xxx_g2_smi_phy_read,
3290 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003291 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003292 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003293 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003294 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003295 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003296 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003297 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003298 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003299 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003300 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003301 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003302 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003303 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003304 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003305 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3306 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003307 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003308 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3309 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003310 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003311 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003312 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003313 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003314};
3315
3316static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003317 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003318 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3319 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003320 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003321 .phy_read = mv88e6xxx_g2_smi_phy_read,
3322 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003323 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003324 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003325 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003326 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003327 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003328 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003329 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003330 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003331 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003332 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003333 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003334 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003335 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003336 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003337 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3338 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003339 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003340 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3341 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003342 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003343 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003344 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003345 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003346};
3347
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003348static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003349 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003350 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3351 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003352 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3353 .phy_read = mv88e6xxx_g2_smi_phy_read,
3354 .phy_write = mv88e6xxx_g2_smi_phy_write,
3355 .port_set_link = mv88e6xxx_port_set_link,
3356 .port_set_duplex = mv88e6xxx_port_set_duplex,
3357 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3358 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003359 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003360 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003361 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003362 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003363 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003364 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003365 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003366 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003367 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003368 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003369 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003370 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003371 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3372 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003373 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003374 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3375 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003376 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003377 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003378 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003379};
3380
3381static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003382 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003383 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3384 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003385 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3386 .phy_read = mv88e6xxx_g2_smi_phy_read,
3387 .phy_write = mv88e6xxx_g2_smi_phy_write,
3388 .port_set_link = mv88e6xxx_port_set_link,
3389 .port_set_duplex = mv88e6xxx_port_set_duplex,
3390 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3391 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003392 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003393 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003394 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003395 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003396 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003397 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003398 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003399 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003400 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003401 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003402 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003403 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3404 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003405 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003406 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3407 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003408 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003409 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003410 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003411};
3412
Vivien Didelotf81ec902016-05-09 13:22:58 -04003413static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3414 [MV88E6085] = {
3415 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3416 .family = MV88E6XXX_FAMILY_6097,
3417 .name = "Marvell 88E6085",
3418 .num_databases = 4096,
3419 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003420 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003421 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003422 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003423 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003424 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003425 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003426 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003427 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003428 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003429 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003430 },
3431
3432 [MV88E6095] = {
3433 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3434 .family = MV88E6XXX_FAMILY_6095,
3435 .name = "Marvell 88E6095/88E6095F",
3436 .num_databases = 256,
3437 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003438 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003439 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003440 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003441 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003442 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003443 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003444 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003445 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003446 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003447 },
3448
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003449 [MV88E6097] = {
3450 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3451 .family = MV88E6XXX_FAMILY_6097,
3452 .name = "Marvell 88E6097/88E6097F",
3453 .num_databases = 4096,
3454 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003455 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003456 .port_base_addr = 0x10,
3457 .global1_addr = 0x1b,
3458 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003459 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003460 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003461 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003462 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003463 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3464 .ops = &mv88e6097_ops,
3465 },
3466
Vivien Didelotf81ec902016-05-09 13:22:58 -04003467 [MV88E6123] = {
3468 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3469 .family = MV88E6XXX_FAMILY_6165,
3470 .name = "Marvell 88E6123",
3471 .num_databases = 4096,
3472 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003473 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003474 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003475 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003476 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003477 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003478 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003479 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003480 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003481 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003482 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003483 },
3484
3485 [MV88E6131] = {
3486 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3487 .family = MV88E6XXX_FAMILY_6185,
3488 .name = "Marvell 88E6131",
3489 .num_databases = 256,
3490 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003491 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003492 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003493 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003494 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003495 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003496 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003497 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003498 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003499 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003500 },
3501
Vivien Didelot990e27b2017-03-28 13:50:32 -04003502 [MV88E6141] = {
3503 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3504 .family = MV88E6XXX_FAMILY_6341,
3505 .name = "Marvell 88E6341",
3506 .num_databases = 4096,
3507 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003508 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003509 .port_base_addr = 0x10,
3510 .global1_addr = 0x1b,
3511 .age_time_coeff = 3750,
3512 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003513 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003514 .tag_protocol = DSA_TAG_PROTO_EDSA,
3515 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3516 .ops = &mv88e6141_ops,
3517 },
3518
Vivien Didelotf81ec902016-05-09 13:22:58 -04003519 [MV88E6161] = {
3520 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3521 .family = MV88E6XXX_FAMILY_6165,
3522 .name = "Marvell 88E6161",
3523 .num_databases = 4096,
3524 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003525 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003526 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003527 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003528 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003529 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003530 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003531 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003532 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003533 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003534 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003535 },
3536
3537 [MV88E6165] = {
3538 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3539 .family = MV88E6XXX_FAMILY_6165,
3540 .name = "Marvell 88E6165",
3541 .num_databases = 4096,
3542 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003543 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003544 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003545 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003546 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003547 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003548 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003549 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003550 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003551 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003552 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003553 },
3554
3555 [MV88E6171] = {
3556 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3557 .family = MV88E6XXX_FAMILY_6351,
3558 .name = "Marvell 88E6171",
3559 .num_databases = 4096,
3560 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003561 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003562 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003563 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003564 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003565 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003566 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003567 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003568 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003569 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003570 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003571 },
3572
3573 [MV88E6172] = {
3574 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3575 .family = MV88E6XXX_FAMILY_6352,
3576 .name = "Marvell 88E6172",
3577 .num_databases = 4096,
3578 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003579 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003580 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003581 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003582 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003583 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003584 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003585 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003586 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003587 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003588 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003589 },
3590
3591 [MV88E6175] = {
3592 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3593 .family = MV88E6XXX_FAMILY_6351,
3594 .name = "Marvell 88E6175",
3595 .num_databases = 4096,
3596 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003597 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003598 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003599 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003600 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003601 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003602 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003603 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003604 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003605 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003606 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003607 },
3608
3609 [MV88E6176] = {
3610 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3611 .family = MV88E6XXX_FAMILY_6352,
3612 .name = "Marvell 88E6176",
3613 .num_databases = 4096,
3614 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003615 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003616 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003617 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003618 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003619 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003620 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003621 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003622 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003623 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003624 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003625 },
3626
3627 [MV88E6185] = {
3628 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3629 .family = MV88E6XXX_FAMILY_6185,
3630 .name = "Marvell 88E6185",
3631 .num_databases = 256,
3632 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003633 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003634 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003635 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003636 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003637 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003638 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003639 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003640 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003641 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003642 },
3643
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003644 [MV88E6190] = {
3645 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3646 .family = MV88E6XXX_FAMILY_6390,
3647 .name = "Marvell 88E6190",
3648 .num_databases = 4096,
3649 .num_ports = 11, /* 10 + Z80 */
3650 .port_base_addr = 0x0,
3651 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003652 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003653 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003654 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003655 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003656 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003657 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3658 .ops = &mv88e6190_ops,
3659 },
3660
3661 [MV88E6190X] = {
3662 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3663 .family = MV88E6XXX_FAMILY_6390,
3664 .name = "Marvell 88E6190X",
3665 .num_databases = 4096,
3666 .num_ports = 11, /* 10 + Z80 */
3667 .port_base_addr = 0x0,
3668 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003669 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003670 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003671 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003672 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003673 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003674 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3675 .ops = &mv88e6190x_ops,
3676 },
3677
3678 [MV88E6191] = {
3679 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3680 .family = MV88E6XXX_FAMILY_6390,
3681 .name = "Marvell 88E6191",
3682 .num_databases = 4096,
3683 .num_ports = 11, /* 10 + Z80 */
3684 .port_base_addr = 0x0,
3685 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003686 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003687 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003688 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003689 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003690 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003691 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003692 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003693 },
3694
Vivien Didelotf81ec902016-05-09 13:22:58 -04003695 [MV88E6240] = {
3696 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3697 .family = MV88E6XXX_FAMILY_6352,
3698 .name = "Marvell 88E6240",
3699 .num_databases = 4096,
3700 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003701 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003702 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003703 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003704 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003705 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003706 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003707 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003708 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003709 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003710 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003711 },
3712
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003713 [MV88E6290] = {
3714 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3715 .family = MV88E6XXX_FAMILY_6390,
3716 .name = "Marvell 88E6290",
3717 .num_databases = 4096,
3718 .num_ports = 11, /* 10 + Z80 */
3719 .port_base_addr = 0x0,
3720 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003721 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003722 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003723 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003724 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003725 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003726 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3727 .ops = &mv88e6290_ops,
3728 },
3729
Vivien Didelotf81ec902016-05-09 13:22:58 -04003730 [MV88E6320] = {
3731 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3732 .family = MV88E6XXX_FAMILY_6320,
3733 .name = "Marvell 88E6320",
3734 .num_databases = 4096,
3735 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003736 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003737 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003738 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003739 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003740 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003741 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003742 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003743 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003744 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003745 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003746 },
3747
3748 [MV88E6321] = {
3749 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3750 .family = MV88E6XXX_FAMILY_6320,
3751 .name = "Marvell 88E6321",
3752 .num_databases = 4096,
3753 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003754 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003755 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003756 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003757 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003758 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003759 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003760 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003761 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003762 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003763 },
3764
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003765 [MV88E6341] = {
3766 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3767 .family = MV88E6XXX_FAMILY_6341,
3768 .name = "Marvell 88E6341",
3769 .num_databases = 4096,
3770 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003771 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003772 .port_base_addr = 0x10,
3773 .global1_addr = 0x1b,
3774 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003775 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003776 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003777 .tag_protocol = DSA_TAG_PROTO_EDSA,
3778 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3779 .ops = &mv88e6341_ops,
3780 },
3781
Vivien Didelotf81ec902016-05-09 13:22:58 -04003782 [MV88E6350] = {
3783 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3784 .family = MV88E6XXX_FAMILY_6351,
3785 .name = "Marvell 88E6350",
3786 .num_databases = 4096,
3787 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003788 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003789 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003790 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003791 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003792 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003793 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003794 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003795 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003796 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003797 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003798 },
3799
3800 [MV88E6351] = {
3801 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3802 .family = MV88E6XXX_FAMILY_6351,
3803 .name = "Marvell 88E6351",
3804 .num_databases = 4096,
3805 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003806 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003807 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003808 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003809 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003810 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003811 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003812 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003813 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003814 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003815 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003816 },
3817
3818 [MV88E6352] = {
3819 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3820 .family = MV88E6XXX_FAMILY_6352,
3821 .name = "Marvell 88E6352",
3822 .num_databases = 4096,
3823 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003824 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003825 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003826 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003827 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003828 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003829 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003830 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003831 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003832 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003833 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003834 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003835 [MV88E6390] = {
3836 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3837 .family = MV88E6XXX_FAMILY_6390,
3838 .name = "Marvell 88E6390",
3839 .num_databases = 4096,
3840 .num_ports = 11, /* 10 + Z80 */
3841 .port_base_addr = 0x0,
3842 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003843 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003844 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003845 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003846 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003847 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003848 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3849 .ops = &mv88e6390_ops,
3850 },
3851 [MV88E6390X] = {
3852 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3853 .family = MV88E6XXX_FAMILY_6390,
3854 .name = "Marvell 88E6390X",
3855 .num_databases = 4096,
3856 .num_ports = 11, /* 10 + Z80 */
3857 .port_base_addr = 0x0,
3858 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003859 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003860 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003861 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003862 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003863 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003864 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3865 .ops = &mv88e6390x_ops,
3866 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003867};
3868
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003869static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003870{
Vivien Didelota439c062016-04-17 13:23:58 -04003871 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003872
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003873 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3874 if (mv88e6xxx_table[i].prod_num == prod_num)
3875 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003876
Vivien Didelotb9b37712015-10-30 19:39:48 -04003877 return NULL;
3878}
3879
Vivien Didelotfad09c72016-06-21 12:28:20 -04003880static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003881{
3882 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003883 unsigned int prod_num, rev;
3884 u16 id;
3885 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003886
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003887 mutex_lock(&chip->reg_lock);
3888 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3889 mutex_unlock(&chip->reg_lock);
3890 if (err)
3891 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003892
3893 prod_num = (id & 0xfff0) >> 4;
3894 rev = id & 0x000f;
3895
3896 info = mv88e6xxx_lookup_info(prod_num);
3897 if (!info)
3898 return -ENODEV;
3899
Vivien Didelotcaac8542016-06-20 13:14:09 -04003900 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003901 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003902
Vivien Didelotca070c12016-09-02 14:45:34 -04003903 err = mv88e6xxx_g2_require(chip);
3904 if (err)
3905 return err;
3906
Vivien Didelotfad09c72016-06-21 12:28:20 -04003907 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3908 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003909
3910 return 0;
3911}
3912
Vivien Didelotfad09c72016-06-21 12:28:20 -04003913static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003914{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003915 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003916
Vivien Didelotfad09c72016-06-21 12:28:20 -04003917 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3918 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003919 return NULL;
3920
Vivien Didelotfad09c72016-06-21 12:28:20 -04003921 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003922
Vivien Didelotfad09c72016-06-21 12:28:20 -04003923 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003924 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003925
Vivien Didelotfad09c72016-06-21 12:28:20 -04003926 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003927}
3928
Vivien Didelote57e5e72016-08-15 17:19:00 -04003929static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
3930{
Vivien Didelota199d8b2016-12-05 17:30:28 -05003931 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04003932 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003933}
3934
Andrew Lunn930188c2016-08-22 16:01:03 +02003935static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
3936{
Vivien Didelota199d8b2016-12-05 17:30:28 -05003937 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02003938 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02003939}
3940
Vivien Didelotfad09c72016-06-21 12:28:20 -04003941static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003942 struct mii_bus *bus, int sw_addr)
3943{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003944 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003945 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003946 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003947 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003948 else
3949 return -EINVAL;
3950
Vivien Didelotfad09c72016-06-21 12:28:20 -04003951 chip->bus = bus;
3952 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003953
3954 return 0;
3955}
3956
Andrew Lunn7b314362016-08-22 16:01:01 +02003957static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3958{
Vivien Didelot04bed142016-08-31 18:06:13 -04003959 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003960
Andrew Lunn443d5a12016-12-03 04:35:18 +01003961 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003962}
3963
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003964static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3965 struct device *host_dev, int sw_addr,
3966 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003967{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003968 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003969 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003970 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003971
Vivien Didelota439c062016-04-17 13:23:58 -04003972 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003973 if (!bus)
3974 return NULL;
3975
Vivien Didelotfad09c72016-06-21 12:28:20 -04003976 chip = mv88e6xxx_alloc_chip(dsa_dev);
3977 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003978 return NULL;
3979
Vivien Didelotcaac8542016-06-20 13:14:09 -04003980 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003981 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003982
Vivien Didelotfad09c72016-06-21 12:28:20 -04003983 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003984 if (err)
3985 goto free;
3986
Vivien Didelotfad09c72016-06-21 12:28:20 -04003987 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003988 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003989 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003990
Andrew Lunndc30c352016-10-16 19:56:49 +02003991 mutex_lock(&chip->reg_lock);
3992 err = mv88e6xxx_switch_reset(chip);
3993 mutex_unlock(&chip->reg_lock);
3994 if (err)
3995 goto free;
3996
Vivien Didelote57e5e72016-08-15 17:19:00 -04003997 mv88e6xxx_phy_init(chip);
3998
Andrew Lunna3c53be52017-01-24 14:53:50 +01003999 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004000 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004001 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004002
Vivien Didelotfad09c72016-06-21 12:28:20 -04004003 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004004
Vivien Didelotfad09c72016-06-21 12:28:20 -04004005 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004006free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004007 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004008
4009 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004010}
4011
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004012static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4013 const struct switchdev_obj_port_mdb *mdb,
4014 struct switchdev_trans *trans)
4015{
4016 /* We don't need any dynamic resource from the kernel (yet),
4017 * so skip the prepare phase.
4018 */
4019
4020 return 0;
4021}
4022
4023static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4024 const struct switchdev_obj_port_mdb *mdb,
4025 struct switchdev_trans *trans)
4026{
Vivien Didelot04bed142016-08-31 18:06:13 -04004027 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004028
4029 mutex_lock(&chip->reg_lock);
4030 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4031 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4032 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4033 mutex_unlock(&chip->reg_lock);
4034}
4035
4036static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4037 const struct switchdev_obj_port_mdb *mdb)
4038{
Vivien Didelot04bed142016-08-31 18:06:13 -04004039 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004040 int err;
4041
4042 mutex_lock(&chip->reg_lock);
4043 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4044 GLOBAL_ATU_DATA_STATE_UNUSED);
4045 mutex_unlock(&chip->reg_lock);
4046
4047 return err;
4048}
4049
4050static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4051 struct switchdev_obj_port_mdb *mdb,
4052 int (*cb)(struct switchdev_obj *obj))
4053{
Vivien Didelot04bed142016-08-31 18:06:13 -04004054 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004055 int err;
4056
4057 mutex_lock(&chip->reg_lock);
4058 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4059 mutex_unlock(&chip->reg_lock);
4060
4061 return err;
4062}
4063
Florian Fainellia82f67a2017-01-08 14:52:08 -08004064static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004065 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004066 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004067 .setup = mv88e6xxx_setup,
4068 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004069 .adjust_link = mv88e6xxx_adjust_link,
4070 .get_strings = mv88e6xxx_get_strings,
4071 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4072 .get_sset_count = mv88e6xxx_get_sset_count,
4073 .set_eee = mv88e6xxx_set_eee,
4074 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004075 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004076 .get_eeprom = mv88e6xxx_get_eeprom,
4077 .set_eeprom = mv88e6xxx_set_eeprom,
4078 .get_regs_len = mv88e6xxx_get_regs_len,
4079 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004080 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004081 .port_bridge_join = mv88e6xxx_port_bridge_join,
4082 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4083 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004084 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004085 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4086 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4087 .port_vlan_add = mv88e6xxx_port_vlan_add,
4088 .port_vlan_del = mv88e6xxx_port_vlan_del,
4089 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4090 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4091 .port_fdb_add = mv88e6xxx_port_fdb_add,
4092 .port_fdb_del = mv88e6xxx_port_fdb_del,
4093 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004094 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4095 .port_mdb_add = mv88e6xxx_port_mdb_add,
4096 .port_mdb_del = mv88e6xxx_port_mdb_del,
4097 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004098 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4099 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004100};
4101
Florian Fainelliab3d4082017-01-08 14:52:07 -08004102static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4103 .ops = &mv88e6xxx_switch_ops,
4104};
4105
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004106static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004107{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004108 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004109 struct dsa_switch *ds;
4110
Vivien Didelot73b12042017-03-30 17:37:10 -04004111 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004112 if (!ds)
4113 return -ENOMEM;
4114
Vivien Didelotfad09c72016-06-21 12:28:20 -04004115 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004116 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004117 ds->ageing_time_min = chip->info->age_time_coeff;
4118 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004119
4120 dev_set_drvdata(dev, ds);
4121
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004122 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004123}
4124
Vivien Didelotfad09c72016-06-21 12:28:20 -04004125static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004126{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004127 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004128}
4129
Vivien Didelot57d32312016-06-20 13:13:58 -04004130static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004131{
4132 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004133 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004134 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004135 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004136 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004137 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004138
Vivien Didelotcaac8542016-06-20 13:14:09 -04004139 compat_info = of_device_get_match_data(dev);
4140 if (!compat_info)
4141 return -EINVAL;
4142
Vivien Didelotfad09c72016-06-21 12:28:20 -04004143 chip = mv88e6xxx_alloc_chip(dev);
4144 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004145 return -ENOMEM;
4146
Vivien Didelotfad09c72016-06-21 12:28:20 -04004147 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004148
Vivien Didelotfad09c72016-06-21 12:28:20 -04004149 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004150 if (err)
4151 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004152
Andrew Lunnb4308f02016-11-21 23:26:55 +01004153 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4154 if (IS_ERR(chip->reset))
4155 return PTR_ERR(chip->reset);
4156
Vivien Didelotfad09c72016-06-21 12:28:20 -04004157 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004158 if (err)
4159 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004160
Vivien Didelote57e5e72016-08-15 17:19:00 -04004161 mv88e6xxx_phy_init(chip);
4162
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004163 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004164 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004165 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004166
Andrew Lunndc30c352016-10-16 19:56:49 +02004167 mutex_lock(&chip->reg_lock);
4168 err = mv88e6xxx_switch_reset(chip);
4169 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004170 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004171 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004172
Andrew Lunndc30c352016-10-16 19:56:49 +02004173 chip->irq = of_irq_get(np, 0);
4174 if (chip->irq == -EPROBE_DEFER) {
4175 err = chip->irq;
4176 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004177 }
4178
Andrew Lunndc30c352016-10-16 19:56:49 +02004179 if (chip->irq > 0) {
4180 /* Has to be performed before the MDIO bus is created,
4181 * because the PHYs will link there interrupts to these
4182 * interrupt controllers
4183 */
4184 mutex_lock(&chip->reg_lock);
4185 err = mv88e6xxx_g1_irq_setup(chip);
4186 mutex_unlock(&chip->reg_lock);
4187
4188 if (err)
4189 goto out;
4190
4191 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4192 err = mv88e6xxx_g2_irq_setup(chip);
4193 if (err)
4194 goto out_g1_irq;
4195 }
4196 }
4197
Andrew Lunna3c53be52017-01-24 14:53:50 +01004198 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004199 if (err)
4200 goto out_g2_irq;
4201
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004202 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004203 if (err)
4204 goto out_mdio;
4205
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004206 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004207
4208out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004209 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004210out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004211 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004212 mv88e6xxx_g2_irq_free(chip);
4213out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004214 if (chip->irq > 0) {
4215 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004216 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004217 mutex_unlock(&chip->reg_lock);
4218 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004219out:
4220 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004221}
4222
4223static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4224{
4225 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004226 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004227
Andrew Lunn930188c2016-08-22 16:01:03 +02004228 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004229 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004230 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004231
Andrew Lunn467126442016-11-20 20:14:15 +01004232 if (chip->irq > 0) {
4233 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4234 mv88e6xxx_g2_irq_free(chip);
4235 mv88e6xxx_g1_irq_free(chip);
4236 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004237}
4238
4239static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004240 {
4241 .compatible = "marvell,mv88e6085",
4242 .data = &mv88e6xxx_table[MV88E6085],
4243 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004244 {
4245 .compatible = "marvell,mv88e6190",
4246 .data = &mv88e6xxx_table[MV88E6190],
4247 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004248 { /* sentinel */ },
4249};
4250
4251MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4252
4253static struct mdio_driver mv88e6xxx_driver = {
4254 .probe = mv88e6xxx_probe,
4255 .remove = mv88e6xxx_remove,
4256 .mdiodrv.driver = {
4257 .name = "mv88e6085",
4258 .of_match_table = mv88e6xxx_of_match,
4259 },
4260};
4261
Ben Hutchings98e67302011-11-25 14:36:19 +00004262static int __init mv88e6xxx_init(void)
4263{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004264 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004265 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004266}
4267module_init(mv88e6xxx_init);
4268
4269static void __exit mv88e6xxx_cleanup(void)
4270{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004271 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004272 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004273}
4274module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004275
4276MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4277MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4278MODULE_LICENSE("GPL");