blob: d034d8cd7d22dcde187f0becb24afd45480271f3 [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);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500852 break;
853 default:
854 return UINT64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200855 }
856 value = (((u64)high) << 16) | low;
857 return value;
858}
859
Andrew Lunndfafe442016-11-21 23:27:02 +0100860static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
861 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100862{
863 struct mv88e6xxx_hw_stat *stat;
864 int i, j;
865
866 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
867 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100868 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100869 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
870 ETH_GSTRING_LEN);
871 j++;
872 }
873 }
874}
875
Andrew Lunndfafe442016-11-21 23:27:02 +0100876static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
877 uint8_t *data)
878{
879 mv88e6xxx_stats_get_strings(chip, data,
880 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
881}
882
883static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
884 uint8_t *data)
885{
886 mv88e6xxx_stats_get_strings(chip, data,
887 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
888}
889
890static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
891 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100892{
Vivien Didelot04bed142016-08-31 18:06:13 -0400893 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100894
895 if (chip->info->ops->stats_get_strings)
896 chip->info->ops->stats_get_strings(chip, data);
897}
898
899static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
900 int types)
901{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100902 struct mv88e6xxx_hw_stat *stat;
903 int i, j;
904
905 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
906 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100907 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100908 j++;
909 }
910 return j;
911}
912
Andrew Lunndfafe442016-11-21 23:27:02 +0100913static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
914{
915 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
916 STATS_TYPE_PORT);
917}
918
919static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
920{
921 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
922 STATS_TYPE_BANK1);
923}
924
925static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
926{
927 struct mv88e6xxx_chip *chip = ds->priv;
928
929 if (chip->info->ops->stats_get_sset_count)
930 return chip->info->ops->stats_get_sset_count(chip);
931
932 return 0;
933}
934
Andrew Lunn052f9472016-11-21 23:27:03 +0100935static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100936 uint64_t *data, int types,
937 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100938{
939 struct mv88e6xxx_hw_stat *stat;
940 int i, j;
941
942 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
943 stat = &mv88e6xxx_hw_stats[i];
944 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100945 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
946 bank1_select,
947 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100948 j++;
949 }
950 }
951}
952
953static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
954 uint64_t *data)
955{
956 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100957 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
958 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100959}
960
961static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
962 uint64_t *data)
963{
964 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100965 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
966 GLOBAL_STATS_OP_BANK_1_BIT_9,
967 GLOBAL_STATS_OP_HIST_RX_TX);
968}
969
970static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
971 uint64_t *data)
972{
973 return mv88e6xxx_stats_get_stats(chip, port, data,
974 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
975 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100976}
977
978static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
979 uint64_t *data)
980{
981 if (chip->info->ops->stats_get_stats)
982 chip->info->ops->stats_get_stats(chip, port, data);
983}
984
Vivien Didelotf81ec902016-05-09 13:22:58 -0400985static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
986 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000987{
Vivien Didelot04bed142016-08-31 18:06:13 -0400988 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000989 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000990
Vivien Didelotfad09c72016-06-21 12:28:20 -0400991 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000992
Andrew Lunna605a0f2016-11-21 23:26:58 +0100993 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000994 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400995 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000996 return;
997 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100998
999 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001000
Vivien Didelotfad09c72016-06-21 12:28:20 -04001001 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001002}
Ben Hutchings98e67302011-11-25 14:36:19 +00001003
Andrew Lunnde2273872016-11-21 23:27:01 +01001004static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1005{
1006 if (chip->info->ops->stats_set_histogram)
1007 return chip->info->ops->stats_set_histogram(chip);
1008
1009 return 0;
1010}
1011
Vivien Didelotf81ec902016-05-09 13:22:58 -04001012static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001013{
1014 return 32 * sizeof(u16);
1015}
1016
Vivien Didelotf81ec902016-05-09 13:22:58 -04001017static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1018 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001019{
Vivien Didelot04bed142016-08-31 18:06:13 -04001020 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001021 int err;
1022 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001023 u16 *p = _p;
1024 int i;
1025
1026 regs->version = 0;
1027
1028 memset(p, 0xff, 32 * sizeof(u16));
1029
Vivien Didelotfad09c72016-06-21 12:28:20 -04001030 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001031
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001032 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001033
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001034 err = mv88e6xxx_port_read(chip, port, i, &reg);
1035 if (!err)
1036 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001037 }
Vivien Didelot23062512016-05-09 13:22:45 -04001038
Vivien Didelotfad09c72016-06-21 12:28:20 -04001039 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001040}
1041
Vivien Didelotf81ec902016-05-09 13:22:58 -04001042static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1043 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001044{
Vivien Didelot04bed142016-08-31 18:06:13 -04001045 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001046 u16 reg;
1047 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001048
Vivien Didelotfad09c72016-06-21 12:28:20 -04001049 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001050 return -EOPNOTSUPP;
1051
Vivien Didelotfad09c72016-06-21 12:28:20 -04001052 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001053
Vivien Didelot9c938292016-08-15 17:19:02 -04001054 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1055 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001056 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001057
1058 e->eee_enabled = !!(reg & 0x0200);
1059 e->tx_lpi_enabled = !!(reg & 0x0100);
1060
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001061 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001062 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001063 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001064
Andrew Lunncca8b132015-04-02 04:06:39 +02001065 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001066out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001067 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001068
1069 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001070}
1071
Vivien Didelotf81ec902016-05-09 13:22:58 -04001072static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1073 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001074{
Vivien Didelot04bed142016-08-31 18:06:13 -04001075 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001076 u16 reg;
1077 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001078
Vivien Didelotfad09c72016-06-21 12:28:20 -04001079 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001080 return -EOPNOTSUPP;
1081
Vivien Didelotfad09c72016-06-21 12:28:20 -04001082 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001083
Vivien Didelot9c938292016-08-15 17:19:02 -04001084 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1085 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001086 goto out;
1087
Vivien Didelot9c938292016-08-15 17:19:02 -04001088 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001089 if (e->eee_enabled)
1090 reg |= 0x0200;
1091 if (e->tx_lpi_enabled)
1092 reg |= 0x0100;
1093
Vivien Didelot9c938292016-08-15 17:19:02 -04001094 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001095out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001096 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001097
Vivien Didelot9c938292016-08-15 17:19:02 -04001098 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001099}
1100
Vivien Didelote5887a22017-03-30 17:37:11 -04001101static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001102{
Vivien Didelote5887a22017-03-30 17:37:11 -04001103 struct dsa_switch *ds = NULL;
1104 struct net_device *br;
1105 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001106 int i;
1107
Vivien Didelote5887a22017-03-30 17:37:11 -04001108 if (dev < DSA_MAX_SWITCHES)
1109 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001110
Vivien Didelote5887a22017-03-30 17:37:11 -04001111 /* Prevent frames from unknown switch or port */
1112 if (!ds || port >= ds->num_ports)
1113 return 0;
1114
1115 /* Frames from DSA links and CPU ports can egress any local port */
1116 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1117 return mv88e6xxx_port_mask(chip);
1118
1119 br = ds->ports[port].bridge_dev;
1120 pvlan = 0;
1121
1122 /* Frames from user ports can egress any local DSA links and CPU ports,
1123 * as well as any local member of their bridge group.
1124 */
1125 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1126 if (dsa_is_cpu_port(chip->ds, i) ||
1127 dsa_is_dsa_port(chip->ds, i) ||
1128 (br && chip->ds->ports[i].bridge_dev == br))
1129 pvlan |= BIT(i);
1130
1131 return pvlan;
1132}
1133
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001134static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001135{
1136 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001137
1138 /* prevent frames from going back out of the port they came in on */
1139 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001140
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001141 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001142}
1143
Vivien Didelotf81ec902016-05-09 13:22:58 -04001144static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1145 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001146{
Vivien Didelot04bed142016-08-31 18:06:13 -04001147 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001148 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001149 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001150
1151 switch (state) {
1152 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001153 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001154 break;
1155 case BR_STATE_BLOCKING:
1156 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001157 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001158 break;
1159 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001160 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001161 break;
1162 case BR_STATE_FORWARDING:
1163 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001164 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001165 break;
1166 }
1167
Vivien Didelotfad09c72016-06-21 12:28:20 -04001168 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001169 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001170 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001171
1172 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001173 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001174}
1175
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001176static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1177{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001178 int err;
1179
Vivien Didelotdaefc942017-03-11 16:12:54 -05001180 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1181 if (err)
1182 return err;
1183
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001184 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1185 if (err)
1186 return err;
1187
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001188 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1189}
1190
Vivien Didelot17a15942017-03-30 17:37:09 -04001191static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1192{
1193 u16 pvlan = 0;
1194
1195 if (!mv88e6xxx_has_pvt(chip))
1196 return -EOPNOTSUPP;
1197
1198 /* Skip the local source device, which uses in-chip port VLAN */
1199 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001200 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001201
1202 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1203}
1204
Vivien Didelot81228992017-03-30 17:37:08 -04001205static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1206{
Vivien Didelot17a15942017-03-30 17:37:09 -04001207 int dev, port;
1208 int err;
1209
Vivien Didelot81228992017-03-30 17:37:08 -04001210 if (!mv88e6xxx_has_pvt(chip))
1211 return 0;
1212
1213 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1214 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1215 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001216 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1217 if (err)
1218 return err;
1219
1220 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1221 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1222 err = mv88e6xxx_pvt_map(chip, dev, port);
1223 if (err)
1224 return err;
1225 }
1226 }
1227
1228 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001229}
1230
Vivien Didelot749efcb2016-09-22 16:49:24 -04001231static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1232{
1233 struct mv88e6xxx_chip *chip = ds->priv;
1234 int err;
1235
1236 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001237 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001238 mutex_unlock(&chip->reg_lock);
1239
1240 if (err)
1241 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1242}
1243
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001244static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1245{
1246 if (!chip->info->max_vid)
1247 return 0;
1248
1249 return mv88e6xxx_g1_vtu_flush(chip);
1250}
1251
Vivien Didelotf1394b782017-05-01 14:05:22 -04001252static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1253 struct mv88e6xxx_vtu_entry *entry)
1254{
1255 if (!chip->info->ops->vtu_getnext)
1256 return -EOPNOTSUPP;
1257
1258 return chip->info->ops->vtu_getnext(chip, entry);
1259}
1260
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001261static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1262 struct mv88e6xxx_vtu_entry *entry)
1263{
1264 if (!chip->info->ops->vtu_loadpurge)
1265 return -EOPNOTSUPP;
1266
1267 return chip->info->ops->vtu_loadpurge(chip, entry);
1268}
1269
Vivien Didelotf81ec902016-05-09 13:22:58 -04001270static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1271 struct switchdev_obj_port_vlan *vlan,
1272 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001273{
Vivien Didelot04bed142016-08-31 18:06:13 -04001274 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001275 struct mv88e6xxx_vtu_entry next = {
1276 .vid = chip->info->max_vid,
1277 };
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001278 u16 pvid;
1279 int err;
1280
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001281 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001282 return -EOPNOTSUPP;
1283
Vivien Didelotfad09c72016-06-21 12:28:20 -04001284 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001285
Vivien Didelot77064f32016-11-04 03:23:30 +01001286 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001287 if (err)
1288 goto unlock;
1289
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001290 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001291 err = mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001292 if (err)
1293 break;
1294
1295 if (!next.valid)
1296 break;
1297
Vivien Didelotbd00e052017-05-01 14:05:11 -04001298 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001299 continue;
1300
1301 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001302 vlan->vid_begin = next.vid;
1303 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001304 vlan->flags = 0;
1305
Vivien Didelotbd00e052017-05-01 14:05:11 -04001306 if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001307 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1308
1309 if (next.vid == pvid)
1310 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1311
1312 err = cb(&vlan->obj);
1313 if (err)
1314 break;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001315 } while (next.vid < chip->info->max_vid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001316
1317unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001318 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001319
1320 return err;
1321}
1322
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001323static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001324{
1325 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001326 struct mv88e6xxx_vtu_entry vlan = {
1327 .vid = chip->info->max_vid,
1328 };
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001329 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001330
1331 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1332
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001333 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001334 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001335 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001336 if (err)
1337 return err;
1338
1339 set_bit(*fid, fid_bitmap);
1340 }
1341
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001342 /* Set every FID bit used by the VLAN entries */
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001343 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001344 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001345 if (err)
1346 return err;
1347
1348 if (!vlan.valid)
1349 break;
1350
1351 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001352 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001353
1354 /* The reset value 0x000 is used to indicate that multiple address
1355 * databases are not needed. Return the next positive available.
1356 */
1357 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001358 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001359 return -ENOSPC;
1360
1361 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001362 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001363}
1364
Vivien Didelot567aa592017-05-01 14:05:25 -04001365static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1366 struct mv88e6xxx_vtu_entry *entry, bool new)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001367{
1368 int err;
1369
1370 if (!vid)
1371 return -EINVAL;
1372
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001373 entry->vid = vid - 1;
1374 entry->valid = false;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001375
Vivien Didelotf1394b782017-05-01 14:05:22 -04001376 err = mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001377 if (err)
1378 return err;
1379
Vivien Didelot567aa592017-05-01 14:05:25 -04001380 if (entry->vid == vid && entry->valid)
1381 return 0;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001382
Vivien Didelot567aa592017-05-01 14:05:25 -04001383 if (new) {
1384 int i;
1385
1386 /* Initialize a fresh VLAN entry */
1387 memset(entry, 0, sizeof(*entry));
1388 entry->valid = true;
1389 entry->vid = vid;
1390
1391 /* Include only CPU and DSA ports */
1392 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1393 entry->member[i] = dsa_is_normal_port(chip->ds, i) ?
1394 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER :
1395 GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1396
1397 return mv88e6xxx_atu_new(chip, &entry->fid);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001398 }
1399
Vivien Didelot567aa592017-05-01 14:05:25 -04001400 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1401 return -EOPNOTSUPP;
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001402}
1403
Vivien Didelotda9c3592016-02-12 12:09:40 -05001404static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1405 u16 vid_begin, u16 vid_end)
1406{
Vivien Didelot04bed142016-08-31 18:06:13 -04001407 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3afb4bd2017-05-01 14:05:16 -04001408 struct mv88e6xxx_vtu_entry vlan = {
1409 .vid = vid_begin - 1,
1410 };
Vivien Didelotda9c3592016-02-12 12:09:40 -05001411 int i, err;
1412
1413 if (!vid_begin)
1414 return -EOPNOTSUPP;
1415
Vivien Didelotfad09c72016-06-21 12:28:20 -04001416 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001417
Vivien Didelotda9c3592016-02-12 12:09:40 -05001418 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001419 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001420 if (err)
1421 goto unlock;
1422
1423 if (!vlan.valid)
1424 break;
1425
1426 if (vlan.vid > vid_end)
1427 break;
1428
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001429 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001430 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1431 continue;
1432
Andrew Lunn66e28092016-12-11 21:07:19 +01001433 if (!ds->ports[port].netdev)
1434 continue;
1435
Vivien Didelotbd00e052017-05-01 14:05:11 -04001436 if (vlan.member[i] ==
Vivien Didelotda9c3592016-02-12 12:09:40 -05001437 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1438 continue;
1439
Vivien Didelotfae8a252017-01-27 15:29:42 -05001440 if (ds->ports[i].bridge_dev ==
1441 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001442 break; /* same bridge, check next VLAN */
1443
Vivien Didelotfae8a252017-01-27 15:29:42 -05001444 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001445 continue;
1446
Andrew Lunnc8b09802016-06-04 21:16:57 +02001447 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001448 "hardware VLAN %d already used by %s\n",
1449 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001450 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001451 err = -EOPNOTSUPP;
1452 goto unlock;
1453 }
1454 } while (vlan.vid < vid_end);
1455
1456unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001457 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001458
1459 return err;
1460}
1461
Vivien Didelotf81ec902016-05-09 13:22:58 -04001462static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1463 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001464{
Vivien Didelot04bed142016-08-31 18:06:13 -04001465 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001466 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001467 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001468 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001469
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001470 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001471 return -EOPNOTSUPP;
1472
Vivien Didelotfad09c72016-06-21 12:28:20 -04001473 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001474 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001475 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001476
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001477 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001478}
1479
Vivien Didelot57d32312016-06-20 13:13:58 -04001480static int
1481mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1482 const struct switchdev_obj_port_vlan *vlan,
1483 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001484{
Vivien Didelot04bed142016-08-31 18:06:13 -04001485 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001486 int err;
1487
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001488 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001489 return -EOPNOTSUPP;
1490
Vivien Didelotda9c3592016-02-12 12:09:40 -05001491 /* If the requested port doesn't belong to the same bridge as the VLAN
1492 * members, do not support it (yet) and fallback to software VLAN.
1493 */
1494 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1495 vlan->vid_end);
1496 if (err)
1497 return err;
1498
Vivien Didelot76e398a2015-11-01 12:33:55 -05001499 /* We don't need any dynamic resource from the kernel (yet),
1500 * so skip the prepare phase.
1501 */
1502 return 0;
1503}
1504
Vivien Didelotfad09c72016-06-21 12:28:20 -04001505static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001506 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001507{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001508 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001509 int err;
1510
Vivien Didelot567aa592017-05-01 14:05:25 -04001511 err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001512 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001513 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001514
Vivien Didelotbd00e052017-05-01 14:05:11 -04001515 vlan.member[port] = untagged ?
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001516 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1517 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1518
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001519 return mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001520}
1521
Vivien Didelotf81ec902016-05-09 13:22:58 -04001522static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1523 const struct switchdev_obj_port_vlan *vlan,
1524 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001525{
Vivien Didelot04bed142016-08-31 18:06:13 -04001526 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001527 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1528 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1529 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001530
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001531 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001532 return;
1533
Vivien Didelotfad09c72016-06-21 12:28:20 -04001534 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001535
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001536 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001537 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001538 netdev_err(ds->ports[port].netdev,
1539 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001540 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001541
Vivien Didelot77064f32016-11-04 03:23:30 +01001542 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001543 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001544 vlan->vid_end);
1545
Vivien Didelotfad09c72016-06-21 12:28:20 -04001546 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001547}
1548
Vivien Didelotfad09c72016-06-21 12:28:20 -04001549static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001550 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001551{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001552 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001553 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001554 int i, err;
1555
Vivien Didelot567aa592017-05-01 14:05:25 -04001556 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001557 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001558 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001559
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001560 /* Tell switchdev if this VLAN is handled in software */
Vivien Didelotbd00e052017-05-01 14:05:11 -04001561 if (vlan.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001562 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001563
Vivien Didelotbd00e052017-05-01 14:05:11 -04001564 vlan.member[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001565
1566 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001567 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001568 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001569 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001570 continue;
1571
Vivien Didelotbd00e052017-05-01 14:05:11 -04001572 if (vlan.member[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001573 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001574 break;
1575 }
1576 }
1577
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001578 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001579 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001580 return err;
1581
Vivien Didelote606ca32017-03-11 16:12:55 -05001582 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001583}
1584
Vivien Didelotf81ec902016-05-09 13:22:58 -04001585static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1586 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001587{
Vivien Didelot04bed142016-08-31 18:06:13 -04001588 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001589 u16 pvid, vid;
1590 int err = 0;
1591
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001592 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001593 return -EOPNOTSUPP;
1594
Vivien Didelotfad09c72016-06-21 12:28:20 -04001595 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001596
Vivien Didelot77064f32016-11-04 03:23:30 +01001597 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001598 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001599 goto unlock;
1600
Vivien Didelot76e398a2015-11-01 12:33:55 -05001601 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001602 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001603 if (err)
1604 goto unlock;
1605
1606 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001607 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001608 if (err)
1609 goto unlock;
1610 }
1611 }
1612
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001613unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001614 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001615
1616 return err;
1617}
1618
Vivien Didelot83dabd12016-08-31 11:50:04 -04001619static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1620 const unsigned char *addr, u16 vid,
1621 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001622{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001623 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001624 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001625 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001626
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001627 /* Null VLAN ID corresponds to the port private database */
1628 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001629 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001630 else
Vivien Didelot567aa592017-05-01 14:05:25 -04001631 err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001632 if (err)
1633 return err;
1634
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001635 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1636 ether_addr_copy(entry.mac, addr);
1637 eth_addr_dec(entry.mac);
1638
1639 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001640 if (err)
1641 return err;
1642
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001643 /* Initialize a fresh ATU entry if it isn't found */
1644 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1645 !ether_addr_equal(entry.mac, addr)) {
1646 memset(&entry, 0, sizeof(entry));
1647 ether_addr_copy(entry.mac, addr);
1648 }
1649
Vivien Didelot88472932016-09-19 19:56:11 -04001650 /* Purge the ATU entry only if no port is using it anymore */
1651 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001652 entry.portvec &= ~BIT(port);
1653 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001654 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1655 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001656 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001657 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001658 }
1659
Vivien Didelot9c13c022017-03-11 16:12:52 -05001660 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001661}
1662
Vivien Didelotf81ec902016-05-09 13:22:58 -04001663static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1664 const struct switchdev_obj_port_fdb *fdb,
1665 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001666{
1667 /* We don't need any dynamic resource from the kernel (yet),
1668 * so skip the prepare phase.
1669 */
1670 return 0;
1671}
1672
Vivien Didelotf81ec902016-05-09 13:22:58 -04001673static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1674 const struct switchdev_obj_port_fdb *fdb,
1675 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001676{
Vivien Didelot04bed142016-08-31 18:06:13 -04001677 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001678
Vivien Didelotfad09c72016-06-21 12:28:20 -04001679 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001680 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1681 GLOBAL_ATU_DATA_STATE_UC_STATIC))
1682 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001683 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001684}
1685
Vivien Didelotf81ec902016-05-09 13:22:58 -04001686static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1687 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001688{
Vivien Didelot04bed142016-08-31 18:06:13 -04001689 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001690 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001691
Vivien Didelotfad09c72016-06-21 12:28:20 -04001692 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001693 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1694 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001695 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001696
Vivien Didelot83dabd12016-08-31 11:50:04 -04001697 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001698}
1699
Vivien Didelot83dabd12016-08-31 11:50:04 -04001700static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1701 u16 fid, u16 vid, int port,
1702 struct switchdev_obj *obj,
1703 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001704{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001705 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001706 int err;
1707
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001708 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1709 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001710
1711 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001712 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001713 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001714 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001715
1716 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1717 break;
1718
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001719 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001720 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001721
Vivien Didelot83dabd12016-08-31 11:50:04 -04001722 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1723 struct switchdev_obj_port_fdb *fdb;
1724
1725 if (!is_unicast_ether_addr(addr.mac))
1726 continue;
1727
1728 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001729 fdb->vid = vid;
1730 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001731 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
1732 fdb->ndm_state = NUD_NOARP;
1733 else
1734 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04001735 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
1736 struct switchdev_obj_port_mdb *mdb;
1737
1738 if (!is_multicast_ether_addr(addr.mac))
1739 continue;
1740
1741 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
1742 mdb->vid = vid;
1743 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001744 } else {
1745 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001746 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04001747
1748 err = cb(obj);
1749 if (err)
1750 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001751 } while (!is_broadcast_ether_addr(addr.mac));
1752
1753 return err;
1754}
1755
Vivien Didelot83dabd12016-08-31 11:50:04 -04001756static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1757 struct switchdev_obj *obj,
1758 int (*cb)(struct switchdev_obj *obj))
1759{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001760 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001761 .vid = chip->info->max_vid,
Vivien Didelot83dabd12016-08-31 11:50:04 -04001762 };
1763 u16 fid;
1764 int err;
1765
1766 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001767 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001768 if (err)
1769 return err;
1770
1771 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1772 if (err)
1773 return err;
1774
1775 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot83dabd12016-08-31 11:50:04 -04001776 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001777 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001778 if (err)
1779 return err;
1780
1781 if (!vlan.valid)
1782 break;
1783
1784 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1785 obj, cb);
1786 if (err)
1787 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001788 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001789
1790 return err;
1791}
1792
Vivien Didelotf81ec902016-05-09 13:22:58 -04001793static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1794 struct switchdev_obj_port_fdb *fdb,
1795 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04001796{
Vivien Didelot04bed142016-08-31 18:06:13 -04001797 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04001798 int err;
1799
Vivien Didelotfad09c72016-06-21 12:28:20 -04001800 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001801 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001802 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04001803
1804 return err;
1805}
1806
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001807static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1808 struct net_device *br)
1809{
Vivien Didelote96a6e02017-03-30 17:37:13 -04001810 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001811 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04001812 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001813 int err;
1814
1815 /* Remap the Port VLAN of each local bridge group member */
1816 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1817 if (chip->ds->ports[port].bridge_dev == br) {
1818 err = mv88e6xxx_port_vlan_map(chip, port);
1819 if (err)
1820 return err;
1821 }
1822 }
1823
Vivien Didelote96a6e02017-03-30 17:37:13 -04001824 if (!mv88e6xxx_has_pvt(chip))
1825 return 0;
1826
1827 /* Remap the Port VLAN of each cross-chip bridge group member */
1828 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1829 ds = chip->ds->dst->ds[dev];
1830 if (!ds)
1831 break;
1832
1833 for (port = 0; port < ds->num_ports; ++port) {
1834 if (ds->ports[port].bridge_dev == br) {
1835 err = mv88e6xxx_pvt_map(chip, dev, port);
1836 if (err)
1837 return err;
1838 }
1839 }
1840 }
1841
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001842 return 0;
1843}
1844
Vivien Didelotf81ec902016-05-09 13:22:58 -04001845static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001846 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001847{
Vivien Didelot04bed142016-08-31 18:06:13 -04001848 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001849 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001850
Vivien Didelotfad09c72016-06-21 12:28:20 -04001851 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001852 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001853 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05001854
Vivien Didelot466dfa02016-02-26 13:16:05 -05001855 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001856}
1857
Vivien Didelotf123f2f2017-01-27 15:29:41 -05001858static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1859 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05001860{
Vivien Didelot04bed142016-08-31 18:06:13 -04001861 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05001862
Vivien Didelotfad09c72016-06-21 12:28:20 -04001863 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001864 if (mv88e6xxx_bridge_map(chip, br) ||
1865 mv88e6xxx_port_vlan_map(chip, port))
1866 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001867 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05001868}
1869
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001870static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1871 int port, struct net_device *br)
1872{
1873 struct mv88e6xxx_chip *chip = ds->priv;
1874 int err;
1875
1876 if (!mv88e6xxx_has_pvt(chip))
1877 return 0;
1878
1879 mutex_lock(&chip->reg_lock);
1880 err = mv88e6xxx_pvt_map(chip, dev, port);
1881 mutex_unlock(&chip->reg_lock);
1882
1883 return err;
1884}
1885
1886static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1887 int port, struct net_device *br)
1888{
1889 struct mv88e6xxx_chip *chip = ds->priv;
1890
1891 if (!mv88e6xxx_has_pvt(chip))
1892 return;
1893
1894 mutex_lock(&chip->reg_lock);
1895 if (mv88e6xxx_pvt_map(chip, dev, port))
1896 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1897 mutex_unlock(&chip->reg_lock);
1898}
1899
Vivien Didelot17e708b2016-12-05 17:30:27 -05001900static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
1901{
1902 if (chip->info->ops->reset)
1903 return chip->info->ops->reset(chip);
1904
1905 return 0;
1906}
1907
Vivien Didelot309eca62016-12-05 17:30:26 -05001908static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
1909{
1910 struct gpio_desc *gpiod = chip->reset;
1911
1912 /* If there is a GPIO connected to the reset pin, toggle it */
1913 if (gpiod) {
1914 gpiod_set_value_cansleep(gpiod, 1);
1915 usleep_range(10000, 20000);
1916 gpiod_set_value_cansleep(gpiod, 0);
1917 usleep_range(10000, 20000);
1918 }
1919}
1920
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001921static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1922{
1923 int i, err;
1924
1925 /* Set all ports to the Disabled state */
1926 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1927 err = mv88e6xxx_port_set_state(chip, i,
1928 PORT_CONTROL_STATE_DISABLED);
1929 if (err)
1930 return err;
1931 }
1932
1933 /* Wait for transmit queues to drain,
1934 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
1935 */
1936 usleep_range(2000, 4000);
1937
1938 return 0;
1939}
1940
Vivien Didelotfad09c72016-06-21 12:28:20 -04001941static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04001942{
Vivien Didelota935c052016-09-29 12:21:53 -04001943 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001944
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05001945 err = mv88e6xxx_disable_ports(chip);
1946 if (err)
1947 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04001948
Vivien Didelot309eca62016-12-05 17:30:26 -05001949 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001950
Vivien Didelot17e708b2016-12-05 17:30:27 -05001951 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04001952}
1953
Vivien Didelot09cb7df2016-08-15 17:19:01 -04001954static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001955{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04001956 u16 val;
1957 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001958
Vivien Didelot09cb7df2016-08-15 17:19:01 -04001959 /* Clear Power Down bit */
1960 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
1961 if (err)
1962 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001963
Vivien Didelot09cb7df2016-08-15 17:19:01 -04001964 if (val & BMCR_PDOWN) {
1965 val &= ~BMCR_PDOWN;
1966 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001967 }
1968
Vivien Didelot09cb7df2016-08-15 17:19:01 -04001969 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00001970}
1971
Vivien Didelot43145572017-03-11 16:12:59 -05001972static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1973 enum mv88e6xxx_frame_mode frame, u16 egress,
1974 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01001975{
1976 int err;
1977
Vivien Didelot43145572017-03-11 16:12:59 -05001978 if (!chip->info->ops->port_set_frame_mode)
1979 return -EOPNOTSUPP;
1980
1981 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01001982 if (err)
1983 return err;
1984
Vivien Didelot43145572017-03-11 16:12:59 -05001985 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
1986 if (err)
1987 return err;
1988
1989 if (chip->info->ops->port_set_ether_type)
1990 return chip->info->ops->port_set_ether_type(chip, port, etype);
1991
1992 return 0;
1993}
1994
1995static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1996{
1997 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1998 PORT_CONTROL_EGRESS_UNMODIFIED,
1999 PORT_ETH_TYPE_DEFAULT);
2000}
2001
2002static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2003{
2004 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2005 PORT_CONTROL_EGRESS_UNMODIFIED,
2006 PORT_ETH_TYPE_DEFAULT);
2007}
2008
2009static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2010{
2011 return mv88e6xxx_set_port_mode(chip, port,
2012 MV88E6XXX_FRAME_MODE_ETHERTYPE,
2013 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
2014}
2015
2016static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2017{
2018 if (dsa_is_dsa_port(chip->ds, port))
2019 return mv88e6xxx_set_port_mode_dsa(chip, port);
2020
2021 if (dsa_is_normal_port(chip->ds, port))
2022 return mv88e6xxx_set_port_mode_normal(chip, port);
2023
2024 /* Setup CPU port mode depending on its supported tag format */
2025 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2026 return mv88e6xxx_set_port_mode_dsa(chip, port);
2027
2028 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2029 return mv88e6xxx_set_port_mode_edsa(chip, port);
2030
2031 return -EINVAL;
2032}
2033
Vivien Didelotea698f42017-03-11 16:12:50 -05002034static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2035{
2036 bool message = dsa_is_dsa_port(chip->ds, port);
2037
2038 return mv88e6xxx_port_set_message_port(chip, port, message);
2039}
2040
Vivien Didelot601aeed2017-03-11 16:13:00 -05002041static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2042{
2043 bool flood = port == dsa_upstream_port(chip->ds);
2044
2045 /* Upstream ports flood frames with unknown unicast or multicast DA */
2046 if (chip->info->ops->port_set_egress_floods)
2047 return chip->info->ops->port_set_egress_floods(chip, port,
2048 flood, flood);
2049
2050 return 0;
2051}
2052
Vivien Didelotfad09c72016-06-21 12:28:20 -04002053static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002054{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002055 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002056 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002057 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002058
Vivien Didelotd78343d2016-11-04 03:23:36 +01002059 /* MAC Forcing register: don't force link, speed, duplex or flow control
2060 * state to any particular values on physical ports, but force the CPU
2061 * port and all DSA ports to their maximum bandwidth and full duplex.
2062 */
2063 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2064 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2065 SPEED_MAX, DUPLEX_FULL,
2066 PHY_INTERFACE_MODE_NA);
2067 else
2068 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2069 SPEED_UNFORCED, DUPLEX_UNFORCED,
2070 PHY_INTERFACE_MODE_NA);
2071 if (err)
2072 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002073
2074 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2075 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2076 * tunneling, determine priority by looking at 802.1p and IP
2077 * priority fields (IP prio has precedence), and set STP state
2078 * to Forwarding.
2079 *
2080 * If this is the CPU link, use DSA or EDSA tagging depending
2081 * on which tagging mode was configured.
2082 *
2083 * If this is a link to another switch, use DSA tagging mode.
2084 *
2085 * If this is the upstream port for this switch, enable
2086 * forwarding of unknown unicasts and multicasts.
2087 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002088 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002089 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2090 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002091 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2092 if (err)
2093 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002094
Vivien Didelot601aeed2017-03-11 16:13:00 -05002095 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002096 if (err)
2097 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002098
Vivien Didelot601aeed2017-03-11 16:13:00 -05002099 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002100 if (err)
2101 return err;
2102
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002103 /* If this port is connected to a SerDes, make sure the SerDes is not
2104 * powered down.
2105 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002106 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002107 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2108 if (err)
2109 return err;
2110 reg &= PORT_STATUS_CMODE_MASK;
2111 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2112 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2113 (reg == PORT_STATUS_CMODE_SGMII)) {
2114 err = mv88e6xxx_serdes_power_on(chip);
2115 if (err < 0)
2116 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002117 }
2118 }
2119
Vivien Didelot8efdda42015-08-13 12:52:23 -04002120 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002121 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002122 * untagged frames on this port, do a destination address lookup on all
2123 * received packets as usual, disable ARP mirroring and don't send a
2124 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002125 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002126 err = mv88e6xxx_port_set_map_da(chip, port);
2127 if (err)
2128 return err;
2129
Andrew Lunn54d792f2015-05-06 01:09:47 +02002130 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002131 if (chip->info->ops->port_set_upstream_port) {
2132 err = chip->info->ops->port_set_upstream_port(
2133 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002134 if (err)
2135 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002136 }
2137
Andrew Lunna23b2962017-02-04 20:15:28 +01002138 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2139 PORT_CONTROL_2_8021Q_DISABLED);
2140 if (err)
2141 return err;
2142
Andrew Lunn5f436662016-12-03 04:45:17 +01002143 if (chip->info->ops->port_jumbo_config) {
2144 err = chip->info->ops->port_jumbo_config(chip, port);
2145 if (err)
2146 return err;
2147 }
2148
Andrew Lunn54d792f2015-05-06 01:09:47 +02002149 /* Port Association Vector: when learning source addresses
2150 * of packets, add the address to the address database using
2151 * a port bitmap that has only the bit for this port set and
2152 * the other bits clear.
2153 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002154 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002155 /* Disable learning for CPU port */
2156 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002157 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002158
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002159 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2160 if (err)
2161 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002162
2163 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002164 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2165 if (err)
2166 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002167
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002168 if (chip->info->ops->port_pause_config) {
2169 err = chip->info->ops->port_pause_config(chip, port);
2170 if (err)
2171 return err;
2172 }
2173
Vivien Didelotc8c94892017-03-11 16:13:01 -05002174 if (chip->info->ops->port_disable_learn_limit) {
2175 err = chip->info->ops->port_disable_learn_limit(chip, port);
2176 if (err)
2177 return err;
2178 }
2179
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002180 if (chip->info->ops->port_disable_pri_override) {
2181 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002182 if (err)
2183 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002184 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002185
Andrew Lunnef0a7312016-12-03 04:35:16 +01002186 if (chip->info->ops->port_tag_remap) {
2187 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002188 if (err)
2189 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002190 }
2191
Andrew Lunnef70b112016-12-03 04:45:18 +01002192 if (chip->info->ops->port_egress_rate_limiting) {
2193 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002194 if (err)
2195 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002196 }
2197
Vivien Didelotea698f42017-03-11 16:12:50 -05002198 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002199 if (err)
2200 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002201
Vivien Didelot207afda2016-04-14 14:42:09 -04002202 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002203 * database, and allow bidirectional communication between the
2204 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002205 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002206 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002207 if (err)
2208 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002209
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002210 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002211 if (err)
2212 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002213
2214 /* Default VLAN ID and priority: don't set a default VLAN
2215 * ID, and set the default packet priority to zero.
2216 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002217 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002218}
2219
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002220static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002221{
2222 int err;
2223
Vivien Didelota935c052016-09-29 12:21:53 -04002224 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002225 if (err)
2226 return err;
2227
Vivien Didelota935c052016-09-29 12:21:53 -04002228 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002229 if (err)
2230 return err;
2231
Vivien Didelota935c052016-09-29 12:21:53 -04002232 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2233 if (err)
2234 return err;
2235
2236 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002237}
2238
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002239static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2240 unsigned int ageing_time)
2241{
Vivien Didelot04bed142016-08-31 18:06:13 -04002242 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002243 int err;
2244
2245 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002246 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002247 mutex_unlock(&chip->reg_lock);
2248
2249 return err;
2250}
2251
Vivien Didelot97299342016-07-18 20:45:30 -04002252static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002253{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002254 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002255 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002256 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002257
Vivien Didelot119477b2016-05-09 13:22:51 -04002258 /* Enable the PHY Polling Unit if present, don't discard any packets,
2259 * and mask all interrupt sources.
2260 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002261 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002262 if (err)
2263 return err;
2264
Andrew Lunn33641992016-12-03 04:35:17 +01002265 if (chip->info->ops->g1_set_cpu_port) {
2266 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2267 if (err)
2268 return err;
2269 }
2270
2271 if (chip->info->ops->g1_set_egress_port) {
2272 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2273 if (err)
2274 return err;
2275 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002276
Vivien Didelot50484ff2016-05-09 13:22:54 -04002277 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002278 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2279 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2280 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002281 if (err)
2282 return err;
2283
Vivien Didelot08a01262016-05-09 13:22:50 -04002284 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002285 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002286 if (err)
2287 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002288 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002289 if (err)
2290 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002291 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002292 if (err)
2293 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002294 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002295 if (err)
2296 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002297 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002298 if (err)
2299 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002300 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002301 if (err)
2302 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002303 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002304 if (err)
2305 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002306 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002307 if (err)
2308 return err;
2309
2310 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002311 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002312 if (err)
2313 return err;
2314
Andrew Lunnde2273872016-11-21 23:27:01 +01002315 /* Initialize the statistics unit */
2316 err = mv88e6xxx_stats_set_histogram(chip);
2317 if (err)
2318 return err;
2319
Vivien Didelot97299342016-07-18 20:45:30 -04002320 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002321 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2322 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002323 if (err)
2324 return err;
2325
2326 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002327 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002328 if (err)
2329 return err;
2330
2331 return 0;
2332}
2333
Vivien Didelotf81ec902016-05-09 13:22:58 -04002334static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002335{
Vivien Didelot04bed142016-08-31 18:06:13 -04002336 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002337 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002338 int i;
2339
Vivien Didelotfad09c72016-06-21 12:28:20 -04002340 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002341 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002342
Vivien Didelotfad09c72016-06-21 12:28:20 -04002343 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002344
Vivien Didelot97299342016-07-18 20:45:30 -04002345 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002346 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002347 err = mv88e6xxx_setup_port(chip, i);
2348 if (err)
2349 goto unlock;
2350 }
2351
2352 /* Setup Switch Global 1 Registers */
2353 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002354 if (err)
2355 goto unlock;
2356
Vivien Didelot97299342016-07-18 20:45:30 -04002357 /* Setup Switch Global 2 Registers */
2358 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2359 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002360 if (err)
2361 goto unlock;
2362 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002363
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002364 err = mv88e6xxx_vtu_setup(chip);
2365 if (err)
2366 goto unlock;
2367
Vivien Didelot81228992017-03-30 17:37:08 -04002368 err = mv88e6xxx_pvt_setup(chip);
2369 if (err)
2370 goto unlock;
2371
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002372 err = mv88e6xxx_atu_setup(chip);
2373 if (err)
2374 goto unlock;
2375
Andrew Lunn6e55f692016-12-03 04:45:16 +01002376 /* Some generations have the configuration of sending reserved
2377 * management frames to the CPU in global2, others in
2378 * global1. Hence it does not fit the two setup functions
2379 * above.
2380 */
2381 if (chip->info->ops->mgmt_rsvd2cpu) {
2382 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2383 if (err)
2384 goto unlock;
2385 }
2386
Vivien Didelot6b17e862015-08-13 12:52:18 -04002387unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002388 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002389
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002390 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002391}
2392
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002393static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2394{
Vivien Didelot04bed142016-08-31 18:06:13 -04002395 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002396 int err;
2397
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002398 if (!chip->info->ops->set_switch_mac)
2399 return -EOPNOTSUPP;
2400
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002401 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002402 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002403 mutex_unlock(&chip->reg_lock);
2404
2405 return err;
2406}
2407
Vivien Didelote57e5e72016-08-15 17:19:00 -04002408static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002409{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002410 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2411 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002412 u16 val;
2413 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002414
Andrew Lunnee26a222017-01-24 14:53:48 +01002415 if (!chip->info->ops->phy_read)
2416 return -EOPNOTSUPP;
2417
Vivien Didelotfad09c72016-06-21 12:28:20 -04002418 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002419 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002420 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002421
Andrew Lunnda9f3302017-02-01 03:40:05 +01002422 if (reg == MII_PHYSID2) {
2423 /* Some internal PHYS don't have a model number. Use
2424 * the mv88e6390 family model number instead.
2425 */
2426 if (!(val & 0x3f0))
2427 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2428 }
2429
Vivien Didelote57e5e72016-08-15 17:19:00 -04002430 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002431}
2432
Vivien Didelote57e5e72016-08-15 17:19:00 -04002433static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002434{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002435 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2436 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002437 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002438
Andrew Lunnee26a222017-01-24 14:53:48 +01002439 if (!chip->info->ops->phy_write)
2440 return -EOPNOTSUPP;
2441
Vivien Didelotfad09c72016-06-21 12:28:20 -04002442 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002443 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002444 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002445
2446 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002447}
2448
Vivien Didelotfad09c72016-06-21 12:28:20 -04002449static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002450 struct device_node *np,
2451 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002452{
2453 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002454 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002455 struct mii_bus *bus;
2456 int err;
2457
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002458 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002459 if (!bus)
2460 return -ENOMEM;
2461
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002462 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002463 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002464 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002465 INIT_LIST_HEAD(&mdio_bus->list);
2466 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002467
Andrew Lunnb516d452016-06-04 21:17:06 +02002468 if (np) {
2469 bus->name = np->full_name;
2470 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2471 } else {
2472 bus->name = "mv88e6xxx SMI";
2473 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2474 }
2475
2476 bus->read = mv88e6xxx_mdio_read;
2477 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002478 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002479
Andrew Lunna3c53be52017-01-24 14:53:50 +01002480 if (np)
2481 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002482 else
2483 err = mdiobus_register(bus);
2484 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002485 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002486 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002487 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002488
2489 if (external)
2490 list_add_tail(&mdio_bus->list, &chip->mdios);
2491 else
2492 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002493
2494 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002495}
2496
Andrew Lunna3c53be52017-01-24 14:53:50 +01002497static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2498 { .compatible = "marvell,mv88e6xxx-mdio-external",
2499 .data = (void *)true },
2500 { },
2501};
2502
2503static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2504 struct device_node *np)
2505{
2506 const struct of_device_id *match;
2507 struct device_node *child;
2508 int err;
2509
2510 /* Always register one mdio bus for the internal/default mdio
2511 * bus. This maybe represented in the device tree, but is
2512 * optional.
2513 */
2514 child = of_get_child_by_name(np, "mdio");
2515 err = mv88e6xxx_mdio_register(chip, child, false);
2516 if (err)
2517 return err;
2518
2519 /* Walk the device tree, and see if there are any other nodes
2520 * which say they are compatible with the external mdio
2521 * bus.
2522 */
2523 for_each_available_child_of_node(np, child) {
2524 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2525 if (match) {
2526 err = mv88e6xxx_mdio_register(chip, child, true);
2527 if (err)
2528 return err;
2529 }
2530 }
2531
2532 return 0;
2533}
2534
2535static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002536
2537{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002538 struct mv88e6xxx_mdio_bus *mdio_bus;
2539 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002540
Andrew Lunna3c53be52017-01-24 14:53:50 +01002541 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2542 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002543
Andrew Lunna3c53be52017-01-24 14:53:50 +01002544 mdiobus_unregister(bus);
2545 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002546}
2547
Vivien Didelot855b1932016-07-20 18:18:35 -04002548static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2549{
Vivien Didelot04bed142016-08-31 18:06:13 -04002550 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002551
2552 return chip->eeprom_len;
2553}
2554
Vivien Didelot855b1932016-07-20 18:18:35 -04002555static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2556 struct ethtool_eeprom *eeprom, u8 *data)
2557{
Vivien Didelot04bed142016-08-31 18:06:13 -04002558 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002559 int err;
2560
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002561 if (!chip->info->ops->get_eeprom)
2562 return -EOPNOTSUPP;
2563
Vivien Didelot855b1932016-07-20 18:18:35 -04002564 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002565 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002566 mutex_unlock(&chip->reg_lock);
2567
2568 if (err)
2569 return err;
2570
2571 eeprom->magic = 0xc3ec4951;
2572
2573 return 0;
2574}
2575
Vivien Didelot855b1932016-07-20 18:18:35 -04002576static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2577 struct ethtool_eeprom *eeprom, u8 *data)
2578{
Vivien Didelot04bed142016-08-31 18:06:13 -04002579 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002580 int err;
2581
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002582 if (!chip->info->ops->set_eeprom)
2583 return -EOPNOTSUPP;
2584
Vivien Didelot855b1932016-07-20 18:18:35 -04002585 if (eeprom->magic != 0xc3ec4951)
2586 return -EINVAL;
2587
2588 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002589 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002590 mutex_unlock(&chip->reg_lock);
2591
2592 return err;
2593}
2594
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002595static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002596 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002597 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002598 .phy_read = mv88e6xxx_phy_ppu_read,
2599 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002600 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002601 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002602 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002603 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002604 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002605 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002606 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002607 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002608 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002609 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002610 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002611 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002612 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2613 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002614 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002615 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2616 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002617 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002618 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002619 .ppu_enable = mv88e6185_g1_ppu_enable,
2620 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002621 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002622 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002623 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002624};
2625
2626static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002627 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002628 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002629 .phy_read = mv88e6xxx_phy_ppu_read,
2630 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002631 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002632 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002633 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002634 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002635 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002636 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002637 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002638 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2639 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002640 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002641 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002642 .ppu_enable = mv88e6185_g1_ppu_enable,
2643 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002644 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002645 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002646 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002647};
2648
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002649static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002650 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002651 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2652 .phy_read = mv88e6xxx_g2_smi_phy_read,
2653 .phy_write = mv88e6xxx_g2_smi_phy_write,
2654 .port_set_link = mv88e6xxx_port_set_link,
2655 .port_set_duplex = mv88e6xxx_port_set_duplex,
2656 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002657 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002658 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002659 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002660 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002661 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002662 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002663 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002664 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002665 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002666 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2667 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2668 .stats_get_strings = mv88e6095_stats_get_strings,
2669 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002670 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2671 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002672 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002673 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002674 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002675 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002676 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002677};
2678
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002679static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002680 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002681 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002682 .phy_read = mv88e6165_phy_read,
2683 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002684 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002685 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002686 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002687 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002688 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002689 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002690 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002691 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002692 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2693 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002694 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002695 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2696 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002697 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002698 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002699 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002700 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002701 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002702};
2703
2704static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002705 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002706 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002707 .phy_read = mv88e6xxx_phy_ppu_read,
2708 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002709 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002710 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002711 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002712 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002713 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002714 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002715 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002716 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002717 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002718 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002719 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002720 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002721 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2722 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002723 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002724 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2725 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002726 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002727 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002728 .ppu_enable = mv88e6185_g1_ppu_enable,
2729 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002730 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002731 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002732 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002733};
2734
Vivien Didelot990e27b2017-03-28 13:50:32 -04002735static const struct mv88e6xxx_ops mv88e6141_ops = {
2736 /* MV88E6XXX_FAMILY_6341 */
2737 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2738 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2739 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2740 .phy_read = mv88e6xxx_g2_smi_phy_read,
2741 .phy_write = mv88e6xxx_g2_smi_phy_write,
2742 .port_set_link = mv88e6xxx_port_set_link,
2743 .port_set_duplex = mv88e6xxx_port_set_duplex,
2744 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2745 .port_set_speed = mv88e6390_port_set_speed,
2746 .port_tag_remap = mv88e6095_port_tag_remap,
2747 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2748 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2749 .port_set_ether_type = mv88e6351_port_set_ether_type,
2750 .port_jumbo_config = mv88e6165_port_jumbo_config,
2751 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2752 .port_pause_config = mv88e6097_port_pause_config,
2753 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2754 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2755 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2756 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2757 .stats_get_strings = mv88e6320_stats_get_strings,
2758 .stats_get_stats = mv88e6390_stats_get_stats,
2759 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2760 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2761 .watchdog_ops = &mv88e6390_watchdog_ops,
2762 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2763 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002764 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002765 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot990e27b2017-03-28 13:50:32 -04002766};
2767
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002768static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002769 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002770 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002771 .phy_read = mv88e6165_phy_read,
2772 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002773 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002774 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002775 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002776 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002777 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002778 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002779 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002780 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002781 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002782 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002783 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002784 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002785 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002786 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2787 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002788 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002789 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2790 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002791 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002792 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002793 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002794 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002795 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002796};
2797
2798static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002799 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002800 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002801 .phy_read = mv88e6165_phy_read,
2802 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002803 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002804 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002805 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002806 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002807 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002808 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002809 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2810 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002811 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002812 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2813 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002814 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002815 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002816 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002817 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002818 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002819};
2820
2821static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002822 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002823 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002824 .phy_read = mv88e6xxx_g2_smi_phy_read,
2825 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002826 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002827 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002828 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002829 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002830 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002831 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002832 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002833 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002834 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002835 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002836 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002837 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002838 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002839 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002840 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2841 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002842 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002843 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2844 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002845 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002846 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002847 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002848 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002849 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002850};
2851
2852static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002853 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002854 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2855 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002856 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002857 .phy_read = mv88e6xxx_g2_smi_phy_read,
2858 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002859 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002860 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002861 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002862 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002863 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002864 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002865 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002866 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002867 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002868 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002869 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002870 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002871 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002872 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002873 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2874 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002875 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002876 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2877 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002878 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002879 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002880 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002881 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002882 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002883};
2884
2885static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002886 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002887 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002888 .phy_read = mv88e6xxx_g2_smi_phy_read,
2889 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002890 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002891 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002892 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002893 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002894 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002895 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002896 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002897 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002898 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002899 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002900 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002901 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002902 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002903 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002904 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2905 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002906 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002907 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2908 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002909 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002910 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002911 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002912 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002913 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002914};
2915
2916static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002917 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002918 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
2919 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002920 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002921 .phy_read = mv88e6xxx_g2_smi_phy_read,
2922 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002923 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002924 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01002925 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002926 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002927 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002928 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002929 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002930 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002931 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002932 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002933 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002934 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002935 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002936 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002937 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2938 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002939 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002940 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2941 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002942 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002943 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002944 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002945 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002946 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002947};
2948
2949static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002950 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002951 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002952 .phy_read = mv88e6xxx_phy_ppu_read,
2953 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002954 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002955 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002956 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002957 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002958 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01002959 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01002960 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002961 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002962 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2963 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002964 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002965 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2966 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002967 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002968 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002969 .ppu_enable = mv88e6185_g1_ppu_enable,
2970 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002971 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04002972 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002973 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002974};
2975
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002976static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002977 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05002978 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2979 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01002980 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2981 .phy_read = mv88e6xxx_g2_smi_phy_read,
2982 .phy_write = mv88e6xxx_g2_smi_phy_write,
2983 .port_set_link = mv88e6xxx_port_set_link,
2984 .port_set_duplex = mv88e6xxx_port_set_duplex,
2985 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2986 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002987 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002988 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002989 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002990 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01002991 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002992 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002993 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01002994 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01002995 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002996 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2997 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01002998 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002999 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3000 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003001 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003002 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003003 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003004 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3005 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003006};
3007
3008static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003009 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003010 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3011 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003012 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3013 .phy_read = mv88e6xxx_g2_smi_phy_read,
3014 .phy_write = mv88e6xxx_g2_smi_phy_write,
3015 .port_set_link = mv88e6xxx_port_set_link,
3016 .port_set_duplex = mv88e6xxx_port_set_duplex,
3017 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3018 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003019 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003020 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003021 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003022 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003023 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003024 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003025 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003026 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003027 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003028 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3029 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003030 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003031 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3032 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003033 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003034 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003035 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003036 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3037 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003038};
3039
3040static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003041 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003042 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3043 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003044 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3045 .phy_read = mv88e6xxx_g2_smi_phy_read,
3046 .phy_write = mv88e6xxx_g2_smi_phy_write,
3047 .port_set_link = mv88e6xxx_port_set_link,
3048 .port_set_duplex = mv88e6xxx_port_set_duplex,
3049 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3050 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003051 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003052 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003053 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003054 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003055 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003056 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003057 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003058 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003059 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003060 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3061 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003062 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003063 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3064 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003065 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003066 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003067 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003068 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3069 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003070};
3071
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003072static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003073 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003074 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3075 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003076 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003077 .phy_read = mv88e6xxx_g2_smi_phy_read,
3078 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003079 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003080 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003081 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003082 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003083 .port_tag_remap = mv88e6095_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 Lunn5f436662016-12-03 04:45:17 +01003087 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003088 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003089 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003090 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003091 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003092 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003093 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3094 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003095 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003096 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3097 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003098 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003099 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003100 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003101 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003102 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003103};
3104
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003105static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003106 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003107 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3108 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003109 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3110 .phy_read = mv88e6xxx_g2_smi_phy_read,
3111 .phy_write = mv88e6xxx_g2_smi_phy_write,
3112 .port_set_link = mv88e6xxx_port_set_link,
3113 .port_set_duplex = mv88e6xxx_port_set_duplex,
3114 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3115 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003116 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003117 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003118 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003119 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003120 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003121 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003122 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003123 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003124 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003125 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003126 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3127 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003128 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003129 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3130 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003131 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003132 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003133 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003134 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3135 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003136};
3137
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003138static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003139 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003140 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3141 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003142 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003143 .phy_read = mv88e6xxx_g2_smi_phy_read,
3144 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003145 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003146 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003147 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003148 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003149 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003150 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003151 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003152 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003153 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003154 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003155 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003156 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003157 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003158 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3159 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003160 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003161 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3162 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003163 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003164 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003165 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003166 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003167};
3168
3169static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003170 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003171 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3172 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003173 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003174 .phy_read = mv88e6xxx_g2_smi_phy_read,
3175 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003176 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003177 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003178 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003179 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003180 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003181 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003182 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003183 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003184 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003185 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003186 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003187 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003188 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003189 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3190 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003191 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003192 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3193 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003194 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003195 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003196 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003197};
3198
Vivien Didelot16e329a2017-03-28 13:50:33 -04003199static const struct mv88e6xxx_ops mv88e6341_ops = {
3200 /* MV88E6XXX_FAMILY_6341 */
3201 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3202 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3203 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3204 .phy_read = mv88e6xxx_g2_smi_phy_read,
3205 .phy_write = mv88e6xxx_g2_smi_phy_write,
3206 .port_set_link = mv88e6xxx_port_set_link,
3207 .port_set_duplex = mv88e6xxx_port_set_duplex,
3208 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3209 .port_set_speed = mv88e6390_port_set_speed,
3210 .port_tag_remap = mv88e6095_port_tag_remap,
3211 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3212 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3213 .port_set_ether_type = mv88e6351_port_set_ether_type,
3214 .port_jumbo_config = mv88e6165_port_jumbo_config,
3215 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3216 .port_pause_config = mv88e6097_port_pause_config,
3217 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3218 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3219 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3220 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3221 .stats_get_strings = mv88e6320_stats_get_strings,
3222 .stats_get_stats = mv88e6390_stats_get_stats,
3223 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3224 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3225 .watchdog_ops = &mv88e6390_watchdog_ops,
3226 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3227 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003228 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003229 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003230};
3231
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003232static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003233 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003234 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003235 .phy_read = mv88e6xxx_g2_smi_phy_read,
3236 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003237 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003238 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003239 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003240 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003241 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003242 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003243 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003244 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003245 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003246 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003247 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003248 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003249 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003250 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003251 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3252 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003253 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003254 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3255 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003256 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003257 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003258 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003259 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003260 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003261};
3262
3263static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003264 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003265 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003266 .phy_read = mv88e6xxx_g2_smi_phy_read,
3267 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003268 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003269 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003270 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003271 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003272 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003273 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003274 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003275 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003276 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003277 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003278 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003279 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003280 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003281 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003282 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3283 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003284 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003285 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3286 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003287 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003288 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003289 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003290 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003291 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003292};
3293
3294static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003295 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003296 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3297 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003298 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003299 .phy_read = mv88e6xxx_g2_smi_phy_read,
3300 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003301 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003302 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003303 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003304 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003305 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003306 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003307 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003308 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003309 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003310 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003311 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003312 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003313 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003314 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003315 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3316 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003317 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003318 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3319 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003320 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003321 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003322 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003323 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003324 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003325};
3326
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003327static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003328 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003329 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3330 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003331 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3332 .phy_read = mv88e6xxx_g2_smi_phy_read,
3333 .phy_write = mv88e6xxx_g2_smi_phy_write,
3334 .port_set_link = mv88e6xxx_port_set_link,
3335 .port_set_duplex = mv88e6xxx_port_set_duplex,
3336 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3337 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003338 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003339 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003340 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003341 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003342 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003343 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003344 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003345 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003346 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003347 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003348 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003349 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003350 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3351 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003352 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003353 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3354 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003355 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003356 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003357 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003358 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3359 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003360};
3361
3362static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003363 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003364 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3365 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003366 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3367 .phy_read = mv88e6xxx_g2_smi_phy_read,
3368 .phy_write = mv88e6xxx_g2_smi_phy_write,
3369 .port_set_link = mv88e6xxx_port_set_link,
3370 .port_set_duplex = mv88e6xxx_port_set_duplex,
3371 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3372 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003373 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003374 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003375 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003376 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003377 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003378 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003379 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003380 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003381 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003382 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003383 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003384 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3385 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003386 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003387 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3388 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003389 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003390 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003391 .reset = mv88e6352_g1_reset,
Vivien Didelot931d1822017-05-01 14:05:27 -04003392 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3393 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003394};
3395
Vivien Didelotf81ec902016-05-09 13:22:58 -04003396static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3397 [MV88E6085] = {
3398 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3399 .family = MV88E6XXX_FAMILY_6097,
3400 .name = "Marvell 88E6085",
3401 .num_databases = 4096,
3402 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003403 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003404 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003405 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003406 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003407 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003408 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003409 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003410 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003411 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003412 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003413 },
3414
3415 [MV88E6095] = {
3416 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3417 .family = MV88E6XXX_FAMILY_6095,
3418 .name = "Marvell 88E6095/88E6095F",
3419 .num_databases = 256,
3420 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003421 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003422 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003423 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003424 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003425 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003426 .atu_move_port_mask = 0xf,
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_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003429 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003430 },
3431
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003432 [MV88E6097] = {
3433 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3434 .family = MV88E6XXX_FAMILY_6097,
3435 .name = "Marvell 88E6097/88E6097F",
3436 .num_databases = 4096,
3437 .num_ports = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003438 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003439 .port_base_addr = 0x10,
3440 .global1_addr = 0x1b,
3441 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003442 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003443 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003444 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003445 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003446 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3447 .ops = &mv88e6097_ops,
3448 },
3449
Vivien Didelotf81ec902016-05-09 13:22:58 -04003450 [MV88E6123] = {
3451 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3452 .family = MV88E6XXX_FAMILY_6165,
3453 .name = "Marvell 88E6123",
3454 .num_databases = 4096,
3455 .num_ports = 3,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003456 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003457 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003458 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003459 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003460 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003461 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003462 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003463 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003464 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003465 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003466 },
3467
3468 [MV88E6131] = {
3469 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3470 .family = MV88E6XXX_FAMILY_6185,
3471 .name = "Marvell 88E6131",
3472 .num_databases = 256,
3473 .num_ports = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003474 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003475 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003476 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003477 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003478 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003479 .atu_move_port_mask = 0xf,
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_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003482 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003483 },
3484
Vivien Didelot990e27b2017-03-28 13:50:32 -04003485 [MV88E6141] = {
3486 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3487 .family = MV88E6XXX_FAMILY_6341,
3488 .name = "Marvell 88E6341",
3489 .num_databases = 4096,
3490 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003491 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003492 .port_base_addr = 0x10,
3493 .global1_addr = 0x1b,
3494 .age_time_coeff = 3750,
3495 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003496 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003497 .tag_protocol = DSA_TAG_PROTO_EDSA,
3498 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3499 .ops = &mv88e6141_ops,
3500 },
3501
Vivien Didelotf81ec902016-05-09 13:22:58 -04003502 [MV88E6161] = {
3503 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3504 .family = MV88E6XXX_FAMILY_6165,
3505 .name = "Marvell 88E6161",
3506 .num_databases = 4096,
3507 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003508 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003509 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003510 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003511 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003512 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003513 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003514 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003515 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003516 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003517 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003518 },
3519
3520 [MV88E6165] = {
3521 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3522 .family = MV88E6XXX_FAMILY_6165,
3523 .name = "Marvell 88E6165",
3524 .num_databases = 4096,
3525 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003526 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003527 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003528 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003529 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003530 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003531 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003532 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003533 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003534 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003535 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003536 },
3537
3538 [MV88E6171] = {
3539 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3540 .family = MV88E6XXX_FAMILY_6351,
3541 .name = "Marvell 88E6171",
3542 .num_databases = 4096,
3543 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003544 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003545 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003546 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003547 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003548 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003549 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003550 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003551 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003552 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003553 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003554 },
3555
3556 [MV88E6172] = {
3557 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3558 .family = MV88E6XXX_FAMILY_6352,
3559 .name = "Marvell 88E6172",
3560 .num_databases = 4096,
3561 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003562 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003563 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003564 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003565 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003566 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003567 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003568 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003569 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003570 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003571 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003572 },
3573
3574 [MV88E6175] = {
3575 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3576 .family = MV88E6XXX_FAMILY_6351,
3577 .name = "Marvell 88E6175",
3578 .num_databases = 4096,
3579 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003580 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003581 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003582 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003583 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003584 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003585 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003586 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003587 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003588 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003589 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003590 },
3591
3592 [MV88E6176] = {
3593 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3594 .family = MV88E6XXX_FAMILY_6352,
3595 .name = "Marvell 88E6176",
3596 .num_databases = 4096,
3597 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003598 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003599 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003600 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003601 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003602 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003603 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003604 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003605 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003606 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003607 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003608 },
3609
3610 [MV88E6185] = {
3611 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3612 .family = MV88E6XXX_FAMILY_6185,
3613 .name = "Marvell 88E6185",
3614 .num_databases = 256,
3615 .num_ports = 10,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003616 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003617 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003618 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003619 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003620 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003621 .atu_move_port_mask = 0xf,
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_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003624 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003625 },
3626
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003627 [MV88E6190] = {
3628 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3629 .family = MV88E6XXX_FAMILY_6390,
3630 .name = "Marvell 88E6190",
3631 .num_databases = 4096,
3632 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003633 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003634 .port_base_addr = 0x0,
3635 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003636 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003637 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003638 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003639 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003640 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003641 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3642 .ops = &mv88e6190_ops,
3643 },
3644
3645 [MV88E6190X] = {
3646 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3647 .family = MV88E6XXX_FAMILY_6390,
3648 .name = "Marvell 88E6190X",
3649 .num_databases = 4096,
3650 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003651 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003652 .port_base_addr = 0x0,
3653 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003654 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003655 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003656 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003657 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003658 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003659 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3660 .ops = &mv88e6190x_ops,
3661 },
3662
3663 [MV88E6191] = {
3664 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3665 .family = MV88E6XXX_FAMILY_6390,
3666 .name = "Marvell 88E6191",
3667 .num_databases = 4096,
3668 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003669 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003670 .port_base_addr = 0x0,
3671 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003672 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003673 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003674 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003675 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003676 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003677 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003678 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003679 },
3680
Vivien Didelotf81ec902016-05-09 13:22:58 -04003681 [MV88E6240] = {
3682 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3683 .family = MV88E6XXX_FAMILY_6352,
3684 .name = "Marvell 88E6240",
3685 .num_databases = 4096,
3686 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003687 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003688 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003689 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003690 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003691 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003692 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003693 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003694 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003695 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003696 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003697 },
3698
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003699 [MV88E6290] = {
3700 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3701 .family = MV88E6XXX_FAMILY_6390,
3702 .name = "Marvell 88E6290",
3703 .num_databases = 4096,
3704 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003705 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003706 .port_base_addr = 0x0,
3707 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003708 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003709 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003710 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003711 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003712 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003713 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3714 .ops = &mv88e6290_ops,
3715 },
3716
Vivien Didelotf81ec902016-05-09 13:22:58 -04003717 [MV88E6320] = {
3718 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3719 .family = MV88E6XXX_FAMILY_6320,
3720 .name = "Marvell 88E6320",
3721 .num_databases = 4096,
3722 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003723 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003724 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003725 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003726 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003727 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003728 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003729 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003730 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003731 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003732 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003733 },
3734
3735 [MV88E6321] = {
3736 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3737 .family = MV88E6XXX_FAMILY_6320,
3738 .name = "Marvell 88E6321",
3739 .num_databases = 4096,
3740 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003741 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003742 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003743 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003744 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003745 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003746 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003747 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003748 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003749 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003750 },
3751
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003752 [MV88E6341] = {
3753 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3754 .family = MV88E6XXX_FAMILY_6341,
3755 .name = "Marvell 88E6341",
3756 .num_databases = 4096,
3757 .num_ports = 6,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003758 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003759 .port_base_addr = 0x10,
3760 .global1_addr = 0x1b,
3761 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003762 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003763 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003764 .tag_protocol = DSA_TAG_PROTO_EDSA,
3765 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3766 .ops = &mv88e6341_ops,
3767 },
3768
Vivien Didelotf81ec902016-05-09 13:22:58 -04003769 [MV88E6350] = {
3770 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3771 .family = MV88E6XXX_FAMILY_6351,
3772 .name = "Marvell 88E6350",
3773 .num_databases = 4096,
3774 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003775 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003776 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003777 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003778 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003779 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003780 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003781 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003782 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003783 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003784 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003785 },
3786
3787 [MV88E6351] = {
3788 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3789 .family = MV88E6XXX_FAMILY_6351,
3790 .name = "Marvell 88E6351",
3791 .num_databases = 4096,
3792 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003793 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003794 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003795 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003796 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003797 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003798 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003799 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003800 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003801 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003802 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003803 },
3804
3805 [MV88E6352] = {
3806 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3807 .family = MV88E6XXX_FAMILY_6352,
3808 .name = "Marvell 88E6352",
3809 .num_databases = 4096,
3810 .num_ports = 7,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04003811 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003812 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003813 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003814 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003815 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003816 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003817 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003818 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003819 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003820 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003821 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003822 [MV88E6390] = {
3823 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3824 .family = MV88E6XXX_FAMILY_6390,
3825 .name = "Marvell 88E6390",
3826 .num_databases = 4096,
3827 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003828 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003829 .port_base_addr = 0x0,
3830 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003831 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003832 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003833 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003834 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003835 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003836 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3837 .ops = &mv88e6390_ops,
3838 },
3839 [MV88E6390X] = {
3840 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3841 .family = MV88E6XXX_FAMILY_6390,
3842 .name = "Marvell 88E6390X",
3843 .num_databases = 4096,
3844 .num_ports = 11, /* 10 + Z80 */
Vivien Didelot931d1822017-05-01 14:05:27 -04003845 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003846 .port_base_addr = 0x0,
3847 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003848 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003849 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003850 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003851 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003852 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003853 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3854 .ops = &mv88e6390x_ops,
3855 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003856};
3857
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003858static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003859{
Vivien Didelota439c062016-04-17 13:23:58 -04003860 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003861
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003862 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3863 if (mv88e6xxx_table[i].prod_num == prod_num)
3864 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003865
Vivien Didelotb9b37712015-10-30 19:39:48 -04003866 return NULL;
3867}
3868
Vivien Didelotfad09c72016-06-21 12:28:20 -04003869static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003870{
3871 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003872 unsigned int prod_num, rev;
3873 u16 id;
3874 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003875
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003876 mutex_lock(&chip->reg_lock);
3877 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3878 mutex_unlock(&chip->reg_lock);
3879 if (err)
3880 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003881
3882 prod_num = (id & 0xfff0) >> 4;
3883 rev = id & 0x000f;
3884
3885 info = mv88e6xxx_lookup_info(prod_num);
3886 if (!info)
3887 return -ENODEV;
3888
Vivien Didelotcaac8542016-06-20 13:14:09 -04003889 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003890 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003891
Vivien Didelotca070c12016-09-02 14:45:34 -04003892 err = mv88e6xxx_g2_require(chip);
3893 if (err)
3894 return err;
3895
Vivien Didelotfad09c72016-06-21 12:28:20 -04003896 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3897 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003898
3899 return 0;
3900}
3901
Vivien Didelotfad09c72016-06-21 12:28:20 -04003902static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003903{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003904 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003905
Vivien Didelotfad09c72016-06-21 12:28:20 -04003906 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3907 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003908 return NULL;
3909
Vivien Didelotfad09c72016-06-21 12:28:20 -04003910 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003911
Vivien Didelotfad09c72016-06-21 12:28:20 -04003912 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003913 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04003914
Vivien Didelotfad09c72016-06-21 12:28:20 -04003915 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003916}
3917
Vivien Didelote57e5e72016-08-15 17:19:00 -04003918static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
3919{
Vivien Didelota199d8b2016-12-05 17:30:28 -05003920 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04003921 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003922}
3923
Andrew Lunn930188c2016-08-22 16:01:03 +02003924static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
3925{
Vivien Didelota199d8b2016-12-05 17:30:28 -05003926 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02003927 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02003928}
3929
Vivien Didelotfad09c72016-06-21 12:28:20 -04003930static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003931 struct mii_bus *bus, int sw_addr)
3932{
Vivien Didelot914b32f2016-06-20 13:14:11 -04003933 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003934 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003935 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003936 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003937 else
3938 return -EINVAL;
3939
Vivien Didelotfad09c72016-06-21 12:28:20 -04003940 chip->bus = bus;
3941 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003942
3943 return 0;
3944}
3945
Andrew Lunn7b314362016-08-22 16:01:01 +02003946static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3947{
Vivien Didelot04bed142016-08-31 18:06:13 -04003948 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003949
Andrew Lunn443d5a12016-12-03 04:35:18 +01003950 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02003951}
3952
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003953static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3954 struct device *host_dev, int sw_addr,
3955 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003956{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003957 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003958 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003959 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003960
Vivien Didelota439c062016-04-17 13:23:58 -04003961 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003962 if (!bus)
3963 return NULL;
3964
Vivien Didelotfad09c72016-06-21 12:28:20 -04003965 chip = mv88e6xxx_alloc_chip(dsa_dev);
3966 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003967 return NULL;
3968
Vivien Didelotcaac8542016-06-20 13:14:09 -04003969 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003970 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003971
Vivien Didelotfad09c72016-06-21 12:28:20 -04003972 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003973 if (err)
3974 goto free;
3975
Vivien Didelotfad09c72016-06-21 12:28:20 -04003976 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003977 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003978 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003979
Andrew Lunndc30c352016-10-16 19:56:49 +02003980 mutex_lock(&chip->reg_lock);
3981 err = mv88e6xxx_switch_reset(chip);
3982 mutex_unlock(&chip->reg_lock);
3983 if (err)
3984 goto free;
3985
Vivien Didelote57e5e72016-08-15 17:19:00 -04003986 mv88e6xxx_phy_init(chip);
3987
Andrew Lunna3c53be52017-01-24 14:53:50 +01003988 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003989 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003990 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003991
Vivien Didelotfad09c72016-06-21 12:28:20 -04003992 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003993
Vivien Didelotfad09c72016-06-21 12:28:20 -04003994 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003995free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003996 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003997
3998 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003999}
4000
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004001static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4002 const struct switchdev_obj_port_mdb *mdb,
4003 struct switchdev_trans *trans)
4004{
4005 /* We don't need any dynamic resource from the kernel (yet),
4006 * so skip the prepare phase.
4007 */
4008
4009 return 0;
4010}
4011
4012static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4013 const struct switchdev_obj_port_mdb *mdb,
4014 struct switchdev_trans *trans)
4015{
Vivien Didelot04bed142016-08-31 18:06:13 -04004016 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004017
4018 mutex_lock(&chip->reg_lock);
4019 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4020 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4021 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4022 mutex_unlock(&chip->reg_lock);
4023}
4024
4025static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4026 const struct switchdev_obj_port_mdb *mdb)
4027{
Vivien Didelot04bed142016-08-31 18:06:13 -04004028 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004029 int err;
4030
4031 mutex_lock(&chip->reg_lock);
4032 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4033 GLOBAL_ATU_DATA_STATE_UNUSED);
4034 mutex_unlock(&chip->reg_lock);
4035
4036 return err;
4037}
4038
4039static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4040 struct switchdev_obj_port_mdb *mdb,
4041 int (*cb)(struct switchdev_obj *obj))
4042{
Vivien Didelot04bed142016-08-31 18:06:13 -04004043 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004044 int err;
4045
4046 mutex_lock(&chip->reg_lock);
4047 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4048 mutex_unlock(&chip->reg_lock);
4049
4050 return err;
4051}
4052
Florian Fainellia82f67a2017-01-08 14:52:08 -08004053static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004054 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004055 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004056 .setup = mv88e6xxx_setup,
4057 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004058 .adjust_link = mv88e6xxx_adjust_link,
4059 .get_strings = mv88e6xxx_get_strings,
4060 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4061 .get_sset_count = mv88e6xxx_get_sset_count,
4062 .set_eee = mv88e6xxx_set_eee,
4063 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004064 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004065 .get_eeprom = mv88e6xxx_get_eeprom,
4066 .set_eeprom = mv88e6xxx_set_eeprom,
4067 .get_regs_len = mv88e6xxx_get_regs_len,
4068 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004069 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004070 .port_bridge_join = mv88e6xxx_port_bridge_join,
4071 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4072 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004073 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004074 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4075 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4076 .port_vlan_add = mv88e6xxx_port_vlan_add,
4077 .port_vlan_del = mv88e6xxx_port_vlan_del,
4078 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4079 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4080 .port_fdb_add = mv88e6xxx_port_fdb_add,
4081 .port_fdb_del = mv88e6xxx_port_fdb_del,
4082 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004083 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4084 .port_mdb_add = mv88e6xxx_port_mdb_add,
4085 .port_mdb_del = mv88e6xxx_port_mdb_del,
4086 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004087 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4088 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004089};
4090
Florian Fainelliab3d4082017-01-08 14:52:07 -08004091static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4092 .ops = &mv88e6xxx_switch_ops,
4093};
4094
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004095static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004096{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004097 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004098 struct dsa_switch *ds;
4099
Vivien Didelot73b12042017-03-30 17:37:10 -04004100 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004101 if (!ds)
4102 return -ENOMEM;
4103
Vivien Didelotfad09c72016-06-21 12:28:20 -04004104 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004105 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004106 ds->ageing_time_min = chip->info->age_time_coeff;
4107 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004108
4109 dev_set_drvdata(dev, ds);
4110
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004111 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004112}
4113
Vivien Didelotfad09c72016-06-21 12:28:20 -04004114static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004115{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004116 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004117}
4118
Vivien Didelot57d32312016-06-20 13:13:58 -04004119static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004120{
4121 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004122 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004123 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004124 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004125 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004126 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004127
Vivien Didelotcaac8542016-06-20 13:14:09 -04004128 compat_info = of_device_get_match_data(dev);
4129 if (!compat_info)
4130 return -EINVAL;
4131
Vivien Didelotfad09c72016-06-21 12:28:20 -04004132 chip = mv88e6xxx_alloc_chip(dev);
4133 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004134 return -ENOMEM;
4135
Vivien Didelotfad09c72016-06-21 12:28:20 -04004136 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004137
Vivien Didelotfad09c72016-06-21 12:28:20 -04004138 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004139 if (err)
4140 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004141
Andrew Lunnb4308f02016-11-21 23:26:55 +01004142 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4143 if (IS_ERR(chip->reset))
4144 return PTR_ERR(chip->reset);
4145
Vivien Didelotfad09c72016-06-21 12:28:20 -04004146 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004147 if (err)
4148 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004149
Vivien Didelote57e5e72016-08-15 17:19:00 -04004150 mv88e6xxx_phy_init(chip);
4151
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004152 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004153 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004154 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004155
Andrew Lunndc30c352016-10-16 19:56:49 +02004156 mutex_lock(&chip->reg_lock);
4157 err = mv88e6xxx_switch_reset(chip);
4158 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004159 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004160 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004161
Andrew Lunndc30c352016-10-16 19:56:49 +02004162 chip->irq = of_irq_get(np, 0);
4163 if (chip->irq == -EPROBE_DEFER) {
4164 err = chip->irq;
4165 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004166 }
4167
Andrew Lunndc30c352016-10-16 19:56:49 +02004168 if (chip->irq > 0) {
4169 /* Has to be performed before the MDIO bus is created,
4170 * because the PHYs will link there interrupts to these
4171 * interrupt controllers
4172 */
4173 mutex_lock(&chip->reg_lock);
4174 err = mv88e6xxx_g1_irq_setup(chip);
4175 mutex_unlock(&chip->reg_lock);
4176
4177 if (err)
4178 goto out;
4179
4180 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4181 err = mv88e6xxx_g2_irq_setup(chip);
4182 if (err)
4183 goto out_g1_irq;
4184 }
4185 }
4186
Andrew Lunna3c53be52017-01-24 14:53:50 +01004187 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004188 if (err)
4189 goto out_g2_irq;
4190
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004191 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004192 if (err)
4193 goto out_mdio;
4194
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004195 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004196
4197out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004198 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004199out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004200 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004201 mv88e6xxx_g2_irq_free(chip);
4202out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004203 if (chip->irq > 0) {
4204 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004205 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004206 mutex_unlock(&chip->reg_lock);
4207 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004208out:
4209 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004210}
4211
4212static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4213{
4214 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004215 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004216
Andrew Lunn930188c2016-08-22 16:01:03 +02004217 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004218 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004219 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004220
Andrew Lunn467126442016-11-20 20:14:15 +01004221 if (chip->irq > 0) {
4222 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4223 mv88e6xxx_g2_irq_free(chip);
4224 mv88e6xxx_g1_irq_free(chip);
4225 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004226}
4227
4228static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004229 {
4230 .compatible = "marvell,mv88e6085",
4231 .data = &mv88e6xxx_table[MV88E6085],
4232 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004233 {
4234 .compatible = "marvell,mv88e6190",
4235 .data = &mv88e6xxx_table[MV88E6190],
4236 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004237 { /* sentinel */ },
4238};
4239
4240MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4241
4242static struct mdio_driver mv88e6xxx_driver = {
4243 .probe = mv88e6xxx_probe,
4244 .remove = mv88e6xxx_remove,
4245 .mdiodrv.driver = {
4246 .name = "mv88e6085",
4247 .of_match_table = mv88e6xxx_of_match,
4248 },
4249};
4250
Ben Hutchings98e67302011-11-25 14:36:19 +00004251static int __init mv88e6xxx_init(void)
4252{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004253 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004254 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004255}
4256module_init(mv88e6xxx_init);
4257
4258static void __exit mv88e6xxx_cleanup(void)
4259{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004260 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004261 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004262}
4263module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004264
4265MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4266MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4267MODULE_LICENSE("GPL");